Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
feat(agentic-ide): offer, take and decline a workspace resume over REST
Ruben Lütke7c1eed1ecf1a
diff --git a/jarvis/ui/web/agentic_ide_routes.py b/jarvis/ui/web/agentic_ide_routes.pyindex 2f9e334284..d0560cddf6 100644--- a/jarvis/ui/web/agentic_ide_routes.py+++ b/jarvis/ui/web/agentic_ide_routes.py@@ -11,6 +11,9 @@ Endpoints (prefix ``/api/agentic-ide``):* ``GET /folders`` → browse folders (no path = start points)* ``POST /session`` → open a workspace (folder + terminals)* ``DELETE /session`` → close it and stop every agent+* ``GET /resume`` → the last workspace, offered back+* ``POST /resume`` → reopen it (same panes, same places)+* ``DELETE /resume`` → forget it and start fresh* ``PUT /mode`` → focused coding mode on/off* ``POST /terminals`` → open one more pane (split)* ``POST /terminals/batch`` → open N more panes at once@@ -41,7 +44,7 @@ from fastapi import ()from pydantic import BaseModel, Field-from jarvis.agentic_ide import recents+from jarvis.agentic_ide import recents, resume_storefrom jarvis.agentic_ide.device import device_namefrom jarvis.agentic_ide.folders import list_dir, search_folders, start_pointsfrom jarvis.agentic_ide.names import default_names@@ -213,6 +216,48 @@ class ResolveResponse(BaseModel):detail: str = ""+class ResumeTerminal(BaseModel):+ """One pane of the workspace being offered back."""++ key: str+ name: str+ agent: str+ display_name: str+ column: int+ slot: int+ available: bool = Field(+ description=(+ "Can this pane be opened at all? False when its coding CLI is no "+ "longer installed on this machine."+ )+ )+ resumable: bool = Field(+ description=(+ "Does its CONVERSATION come back, or only its call-sign? False "+ "means the pane reopens empty — say so before anyone clicks."+ )+ )+ prompts_sent: int = 0+++class ResumeOffer(BaseModel):+ """The last workspace, re-checked against this machine as it is now."""++ available: bool = Field(+ description="False when there is nothing to reopen, or nothing that could run."+ )+ folder: str = ""+ folder_name: str = ""+ folder_exists: bool = False+ saved_at: float = 0.0+ session_id: str = ""+ resumable_count: int = Field(+ default=0,+ description="How many panes bring their conversation back with them.",+ )+ terminals: list[ResumeTerminal] = Field(default_factory=list)++# --------------------------------------------------------------------------- ## REST ## --------------------------------------------------------------------------- #@@ -424,6 +469,115 @@ async def end_session() -> dict:return {"ok": True, "closed": closed}+async def _installed_agents() -> set[str]:+ """Coding CLIs this machine can actually launch, right now.++ The same two-step check ``GET /agents`` makes: detected AND resolvable the+ way the terminal will resolve it, because a GUI process starts with a+ minimal PATH and "installed" is not the same question as "launchable from+ here". A probe that fails answers "none installed" rather than raising —+ an offer screen must never 500.+ """+ try:+ from jarvis.workspace.agents import detect_agents++ return {+ info.name+ for info in await detect_agents()+ if info.installed and agent_argv(info.name) is not None+ }+ except Exception: # noqa: BLE001 - the offer is more useful than an error+ log.warning("Agentic IDE: could not detect coding agents", exc_info=True)+ return set()+++ "/resume",+ response_model=ResumeOffer,+ summary="The last Agentic-IDE workspace, offered back",+)+async def get_resume_offer() -> ResumeOffer:+ """What reopening the last workspace would bring back.++ Answered against the machine as it is NOW, not as it was when the workspace+ was saved: the folder may have been deleted, a coding CLI uninstalled, a+ pane may never have been given a prompt. Each pane therefore reports two+ different things — whether it can be opened at all, and whether its+ conversation comes back with it. Both belong on screen before the user+ clicks, because the alternative is finding out by asking a resumed agent a+ follow-up question and getting a blank stare.++ ``available: false`` is a normal answer, not an error: a fresh install has+ nothing to resume.+ """+ snapshot = await asyncio.to_thread(resume_store.load)+ installed = await _installed_agents()+ return ResumeOffer(**resume_store.offer(snapshot, installed=installed))++[email protected]("/resume", summary="Reopen the last Agentic-IDE workspace")+async def resume_workspace() -> dict:+ """Reopen the last workspace: same panes, same places, same coding CLIs.++ Wherever the coding CLI supports it, each pane also continues the+ conversation it was having. No agent is started here — the panes connect the+ way they always do, and that connection is what continues them, so a resumed+ workspace takes exactly the same path as a freshly opened one.++ ``409`` when there is nothing to resume, ``422`` when the folder is gone.+ """+ registry = get_registry()+ snapshot = await asyncio.to_thread(resume_store.load)+ if snapshot is None:+ raise HTTPException(+ status_code=409, detail="There is no previous workspace to reopen."+ )+ try:+ session = await registry.restore(snapshot)+ except SessionError as exc:+ raise HTTPException(status_code=422, detail=str(exc)) from exc++ split: dict[str, int] = {}+ for terminal in session.terminals:+ split[terminal.agent] = split.get(terminal.agent, 0) + 1+ try:+ await asyncio.to_thread(+ recents.remember,+ session.folder,+ terminals=len(session.terminals),+ agents=split,+ )+ except Exception: # noqa: BLE001 - history must never block reopening+ log.warning("Agentic IDE recent-folder history was not updated", exc_info=True)++ resumable = sum(1 for t in session.terminals if t.resume is not None)+ return {+ "ok": True,+ "session": session.to_dict(),+ # The honest part: the rest of the panes reopen empty, and a caller that+ # reports "everything is back" without checking this is lying.+ "resumable_count": resumable,+ "started_fresh": len(session.terminals) - resumable,+ }+++ "/resume",+ summary="Forget the last Agentic-IDE workspace",+ openapi_extra={"x-jarvis-dangerous": True},+)+async def forget_resume_offer() -> dict:+ """Discard the restore point, so the IDE opens to a clean wizard.++ Nothing on disk is touched and no agent is stopped — this only throws away+ the note saying which workspace could be reopened. It cannot be undone: the+ call-signs, the grid positions and the links to each pane's conversation are+ gone with it.+ """+ removed = await asyncio.to_thread(resume_store.clear)+ return {"ok": True, "removed": removed}++@router.put("/mode", summary="Toggle focused coding mode")async def set_mode(req: ModeRequest) -> dict:"""Turn the focused coding mode on or off.@@ -782,7 +936,16 @@ async def agentic_pty(ws: WebSocket, name: str) -> None:await ws.close(code=4404, reason="attach failed")return- await ws.send_json({"t": "ready", "name": term.name, "agent": term.agent})+ await ws.send_json(+ {+ "t": "ready",+ "name": term.name,+ "agent": term.agent,+ # Did this pane pick up its previous conversation, or start empty?+ # The pane looks identical either way, so it has to be told.+ "resumed": term.resumed,+ }+ )try:while True:diff --git a/tests/unit/agentic_ide/test_resume_routes.py b/tests/unit/agentic_ide/test_resume_routes.pynew file mode 100644index 0000000000..d55a7e74ba--- /dev/null+++ b/tests/unit/agentic_ide/test_resume_routes.py@@ -0,0 +1,209 @@+"""The resume offer, as the UI and the `jarvis` CLI both see it.++Nothing here may raise. This is the first screen of the Agentic IDE, so a fresh+install with no history, a deleted folder and a machine without either coding+CLI all have to produce a readable answer rather than a 500.+"""++from __future__ import annotations++from pathlib import Path++import pytest+from fastapi import FastAPI+from fastapi.testclient import TestClient++from jarvis.agentic_ide import resume_store+from jarvis.agentic_ide import session as ide+from jarvis.agentic_ide.agent_sessions import ResumeHandle+from jarvis.ui.web import agentic_ide_routes+++# The real probe, kept aside so one test can put it back and prove that IT, and+# not the test's own stand-in, is what survives a failing agent detection.+_real_probe = agentic_ide_routes._installed_agents+++def client(monkeypatch: pytest.MonkeyPatch) -> TestClient:+ monkeypatch.setattr(ide, "agent_argv", lambda name: (f"/usr/bin/{name}",))+ monkeypatch.setattr(agentic_ide_routes, "agent_argv", lambda name: (f"/usr/bin/{name}",))++ async def _both_installed() -> set[str]:+ return {"claude", "codex"}++ monkeypatch.setattr(agentic_ide_routes, "_installed_agents", _both_installed)+ ide.reset_registry()+ app = FastAPI()+ app.include_router(agentic_ide_routes.router)+ with TestClient(app) as client:+ yield client+ ide.reset_registry()+++def _store(folder: Path, *, with_conversation: bool = True) -> None:+ resume_store.save(+ resume_store.Snapshot(+ session_id="ide_old",+ folder=str(folder),+ saved_at=100.0,+ terminals=[+ resume_store.SnapshotTerminal(+ key="mika",+ name="Mika",+ agent="claude",+ column=0,+ slot=0,+ resume=(+ ResumeHandle(+ kind="claude_session", id="u", captured_at=1.0+ )+ if with_conversation+ else None+ ),+ prompts_sent=2,+ ),+ resume_store.SnapshotTerminal(+ key="nova", name="Nova", agent="codex", column=1, slot=0+ ),+ ],+ )+ )+++# ------------------------------------------------------------------- offer+def test_no_snapshot_means_no_offer(client: TestClient) -> None:+ """A fresh install: an empty answer, never an error."""+ body = client.get("/api/agentic-ide/resume").json()+ assert body["available"] is False+ assert body["terminals"] == []+++def test_the_offer_names_the_panes_and_where_they_sat(+ client: TestClient, tmp_path: Path+) -> None:+ _store(tmp_path)+ body = client.get("/api/agentic-ide/resume").json()+ assert body["available"] is True+ assert body["folder"] == str(tmp_path)+ assert body["folder_name"] == tmp_path.name+ assert [t["name"] for t in body["terminals"]] == ["Mika", "Nova"]+ assert [(t["column"], t["slot"]) for t in body["terminals"]] == [(0, 0), (1, 0)]+ assert [t["display_name"] for t in body["terminals"]] == ["Claude Code", "Codex"]+++def test_the_offer_says_which_conversations_come_back(+ client: TestClient, tmp_path: Path+) -> None:+ _store(tmp_path)+ body = client.get("/api/agentic-ide/resume").json()+ panes = {t["name"]: t for t in body["terminals"]}+ assert panes["Mika"]["resumable"] is True+ assert panes["Nova"]["resumable"] is False # never got a conversation id+ assert body["resumable_count"] == 1+++def test_the_offer_survives_a_machine_with_no_coding_cli(+ client: TestClient, tmp_path: Path, monkeypatch: pytest.MonkeyPatch+) -> None:+ async def _none() -> set[str]:+ return set()++ monkeypatch.setattr(agentic_ide_routes, "_installed_agents", _none)+ _store(tmp_path)+ body = client.get("/api/agentic-ide/resume").json()+ assert body["available"] is False+ assert all(t["available"] is False for t in body["terminals"])+++def test_a_broken_agent_probe_does_not_take_the_screen_down(+ client: TestClient, tmp_path: Path, monkeypatch: pytest.MonkeyPatch+) -> None:+ """This is the IDE's first screen — it must render even when a probe fails."""+ from jarvis.workspace import agents as workspace_agents++ async def _explode() -> list[object]:+ raise RuntimeError("the CLI prober fell over")++ monkeypatch.setattr(agentic_ide_routes, "_installed_agents", _real_probe)+ monkeypatch.setattr(workspace_agents, "detect_agents", _explode)+ _store(tmp_path)++ res = client.get("/api/agentic-ide/resume")+ assert res.status_code == 200+ body = res.json()+ # Honest rather than optimistic: nothing is promised that cannot be checked.+ assert body["available"] is False+ assert [t["name"] for t in body["terminals"]] == ["Mika", "Nova"]+++# ------------------------------------------------------------------ resume+def test_resuming_reopens_the_workspace(client: TestClient, tmp_path: Path) -> None:+ _store(tmp_path)+ res = client.post("/api/agentic-ide/resume")+ assert res.status_code == 200+ body = res.json()+ assert [t["name"] for t in body["session"]["terminals"]] == ["Mika", "Nova"]+ assert body["session"]["folder"] == str(tmp_path)+ # The running state agrees, so a client may read either.+ assert client.get("/api/agentic-ide/state").json()["active"] is True+++def test_resuming_reports_how_much_actually_came_back(+ client: TestClient, tmp_path: Path+) -> None:+ """One pane continues, one reopens empty — and the caller is told."""+ _store(tmp_path)+ body = client.post("/api/agentic-ide/resume").json()+ assert body["resumable_count"] == 1+ assert body["started_fresh"] == 1+++def test_resuming_without_a_snapshot_is_a_conflict_not_a_crash(+ client: TestClient,+) -> None:+ res = client.post("/api/agentic-ide/resume")+ assert res.status_code == 409+ assert "no previous workspace" in res.json()["detail"]+++def test_resuming_a_deleted_folder_says_so_plainly(+ client: TestClient, tmp_path: Path+) -> None:+ _store(tmp_path / "gone")+ res = client.post("/api/agentic-ide/resume")+ assert res.status_code == 422+ assert "no longer" in res.json()["detail"]+++def test_resuming_starts_no_agent_by_itself(+ client: TestClient, tmp_path: Path+) -> None:+ """The panes connect as they always do; that is what starts them."""+ _store(tmp_path)+ body = client.post("/api/agentic-ide/resume").json()+ assert all(t["status"] == "pending" for t in body["session"]["terminals"])+++# ------------------------------------------------------------- start fresh+def test_starting_fresh_withdraws_the_offer(+ client: TestClient, tmp_path: Path+) -> None:+ _store(tmp_path)+ assert client.delete("/api/agentic-ide/resume").json()["removed"] is True+ assert client.get("/api/agentic-ide/resume").json()["available"] is False+++def test_starting_fresh_twice_is_harmless(client: TestClient) -> None:+ assert client.delete("/api/agentic-ide/resume").json()["removed"] is False+++def test_discarding_a_restore_point_is_declared_dangerous() -> None:+ """It cannot be undone, so the CLI has to warn before running it."""+ route = next(+ r+ for r in agentic_ide_routes.router.routes+ if getattr(r, "path", "") == "/api/agentic-ide/resume"+ and "DELETE" in getattr(r, "methods", set())+ )+ assert route.openapi_extra == {"x-jarvis-dangerous": True}