Skip to content

Commit d02fa59

Browse files
Complete Librarian and RoboOMP workspaces
1 parent d3bae06 commit d02fa59

10 files changed

Lines changed: 459 additions & 9 deletions

‎routes/ulysses_routes.py‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,16 @@ class LibrarianChatRequest(BaseModel):
175175
model: str = ""
176176

177177

178+
class LibrarianOperationRequest(BaseModel):
179+
mode: str
180+
content: str = ""
181+
suggested_path: str = ""
182+
instruction: str = ""
183+
focus: str = ""
184+
bundle: dict[str, object] | None = None
185+
strategy: str = "merge"
186+
187+
178188
class PersephoneLifecyclePlanRequest(BaseModel):
179189
action: str
180190

@@ -574,6 +584,14 @@ async def get_librarian_dream(request: Request, proposal_id: str) -> dict:
574584
except LibrarianWorkspaceError as exc:
575585
raise _librarian_http_error(exc) from exc
576586

587+
@router.get("/library/export")
588+
async def export_librarian_bundle(request: Request) -> dict:
589+
require_admin(request)
590+
try:
591+
return await librarian_client_factory().export_bundle()
592+
except LibrarianWorkspaceError as exc:
593+
raise _librarian_http_error(exc) from exc
594+
577595
@router.post("/library/chat")
578596
async def chat_with_librarian(
579597
request: Request,
@@ -596,6 +614,25 @@ async def propose_librarian_dream(request: Request) -> dict:
596614
except LibrarianWorkspaceError as exc:
597615
raise _librarian_http_error(exc) from exc
598616

617+
@router.post("/library/operations/propose")
618+
async def propose_librarian_operation(
619+
request: Request,
620+
body: LibrarianOperationRequest,
621+
) -> dict:
622+
_require_operator_admin(request)
623+
try:
624+
return await librarian_client_factory().guided_proposal(
625+
body.mode,
626+
content=body.content,
627+
suggested_path=body.suggested_path,
628+
instruction=body.instruction,
629+
focus=body.focus,
630+
bundle=body.bundle,
631+
strategy=body.strategy,
632+
)
633+
except LibrarianWorkspaceError as exc:
634+
raise _librarian_http_error(exc) from exc
635+
599636
@router.post("/library/dreams/{proposal_id}/{action}")
600637
async def act_on_librarian_dream(
601638
request: Request,

‎src/diogenes_librarian_workspace.py‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
_PATH_RE = re.compile(r"^/[^\r\n\0]{1,1000}$")
2323
_ID_RE = re.compile(r"^[A-Za-z0-9._:-]{1,240}$")
2424
_QUERY_RE = re.compile(r"^[^\r\n\0]{1,1000}$")
25+
_GUIDED_MODES = {"add", "update", "maintain", "import"}
2526

2627

2728
class LibrarianWorkspaceError(RuntimeError):
@@ -232,6 +233,9 @@ async def dream(self, proposal_id: str) -> Any:
232233
raise LibrarianWorkspaceError("invalid proposal ID", status_code=400)
233234
return await self._request("GET", f"/dreams/{proposal_id}")
234235

236+
async def export_bundle(self) -> Any:
237+
return await self._request("GET", "/bundle/export")
238+
235239
async def chat(self, messages: list[dict[str, Any]], *, model: str = "") -> Any:
236240
if not messages or len(messages) > 200:
237241
raise LibrarianWorkspaceError(
@@ -264,6 +268,50 @@ async def propose_dream(self) -> Any:
264268
long_running=True,
265269
)
266270

271+
async def guided_proposal(
272+
self,
273+
mode: str,
274+
*,
275+
content: str = "",
276+
suggested_path: str = "",
277+
instruction: str = "",
278+
focus: str = "",
279+
bundle: dict[str, Any] | None = None,
280+
strategy: str = "merge",
281+
) -> Any:
282+
if mode not in _GUIDED_MODES:
283+
raise LibrarianWorkspaceError("invalid guided operation", status_code=400)
284+
payload: dict[str, Any] = {"mode": mode}
285+
if mode == "add":
286+
payload["content"] = _guided_text(content, "knowledge", required=True)
287+
if suggested_path:
288+
if not _PATH_RE.fullmatch(suggested_path):
289+
raise LibrarianWorkspaceError("invalid suggested path", status_code=400)
290+
payload["suggestedPath"] = suggested_path
291+
elif mode == "update":
292+
payload["instruction"] = _guided_text(
293+
instruction,
294+
"update instruction",
295+
required=True,
296+
)
297+
elif mode == "maintain":
298+
payload["focus"] = _guided_text(focus, "maintenance focus")
299+
else:
300+
if not isinstance(bundle, dict):
301+
raise LibrarianWorkspaceError(
302+
"import requires a Librarian JSON bundle",
303+
status_code=400,
304+
)
305+
if strategy not in {"merge", "replace"}:
306+
raise LibrarianWorkspaceError("invalid import strategy", status_code=400)
307+
payload.update(bundle=bundle, strategy=strategy)
308+
return await self._request(
309+
"POST",
310+
"/dreams/guided",
311+
payload=payload,
312+
long_running=True,
313+
)
314+
267315
async def dream_action(self, proposal_id: str, action: str) -> Any:
268316
if not _ID_RE.fullmatch(proposal_id):
269317
raise LibrarianWorkspaceError("invalid proposal ID", status_code=400)
@@ -274,3 +322,12 @@ async def dream_action(self, proposal_id: str, action: str) -> Any:
274322
f"/dreams/{proposal_id}/{action}",
275323
long_running=True,
276324
)
325+
326+
327+
def _guided_text(value: str, label: str, *, required: bool = False) -> str:
328+
if not isinstance(value, str) or len(value) > 250_000 or "\0" in value:
329+
raise LibrarianWorkspaceError(f"invalid {label}", status_code=400)
330+
cleaned = value.strip()
331+
if required and not cleaned:
332+
raise LibrarianWorkspaceError(f"{label} is required", status_code=400)
333+
return cleaned

‎src/diogenes_roboomp_workspace.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"timer.enable",
3636
"timer.disable",
3737
"version.sync",
38+
"review.open",
3839
}
3940
LIFECYCLE_ACTIONS = {
4041
"initialize",
@@ -349,6 +350,22 @@ def _mutation_identity(
349350
f"CLEAN ROBOMP WORKSPACE {short}",
350351
{"issue": issue},
351352
)
353+
if action == "review.open":
354+
repository_path = str(mutation.get("repositoryPath") or "host worktree")[:4000]
355+
pull_request = mutation.get("pullRequest")
356+
target = (
357+
f"{repository_path} pull request #{pull_request}"
358+
if pull_request not in {None, ""}
359+
else repository_path
360+
)
361+
return (
362+
f"Open the host worktree for review: {target}",
363+
f"OPEN ROBOMP REVIEW {short}",
364+
{
365+
"repository_path": repository_path,
366+
"pull_request": pull_request,
367+
},
368+
)
352369
repository = str(mutation.get("repository") or "repository")[:400]
353370
return (
354371
f"Run RoboOMP {action}: {repository}",

0 commit comments

Comments
 (0)