Skip to content

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.

fix(agentic-ide): announce CLI/voice renames and closes to every open view

rubenluetke10-beep50f9cbe58bc4
diff --git a/jarvis/core/events.py b/jarvis/core/events.py
index 5372fb972a..3f2d07fe0a 100644
--- a/jarvis/core/events.py
+++ b/jarvis/core/events.py
@@ -666,10 +666,11 @@ class AgenticIdeWorkspaceChanged(Event):
no longer had, and the panes of that grid then knocked at a workspace that
was not there. Nothing recovered by itself; the user had to reload.
- ``reason`` is one of ``opened`` / ``restored`` / ``activated`` / ``closed``,
- so a client can tell "your tab was switched" from "everything is gone"
- without guessing from the payload. Clients re-read the authoritative state
- on any of them — the event is a trigger, never the source of truth.
+ ``reason`` is one of ``opened`` / ``restored`` / ``activated`` / ``closed``
+ / ``renamed``, so a client can tell "your tab was switched" from
+ "everything is gone" without guessing from the payload. Clients re-read the
+ authoritative state on any of them — the event is a trigger, never the
+ source of truth.
"""
session_id: str = ""
reason: str = ""
diff --git a/jarvis/ui/web/agentic_ide_routes.py b/jarvis/ui/web/agentic_ide_routes.py
index eced08b311..0c8f6fef5f 100644
--- a/jarvis/ui/web/agentic_ide_routes.py
+++ b/jarvis/ui/web/agentic_ide_routes.py
@@ -1331,7 +1331,9 @@ async def activate_workspace(request: Request, req: ActivateWorkspaceRequest) ->
@router.patch("/workspaces/{workspace_id}", summary="Rename a workspace")
-async def rename_workspace(workspace_id: str, req: RenameWorkspaceRequest) -> dict:
+async def rename_workspace(
+ request: Request, workspace_id: str, req: RenameWorkspaceRequest
+) -> dict:
"""Change only a workspace's tab label; its folder and agents keep running."""
registry = get_registry()
try:
@@ -1339,6 +1341,8 @@ async def rename_workspace(workspace_id: str, req: RenameWorkspaceRequest) -> di
except SessionError as exc:
status = 404 if registry.get(workspace_id) is None else 409
raise HTTPException(status_code=status, detail=str(exc)) from exc
+ # Other windows keep showing the old tab label until they re-fetch.
+ await _announce_workspace(request, session, "renamed")
return {
"ok": True,
"workspace": session.to_card(active=session.id == registry.active_id),
@@ -1695,13 +1699,25 @@ async def clear_notification(notification_id: str) -> NotificationsChangedRespon
summary="Close several terminals",
openapi_extra={"x-jarvis-dangerous": True},
)
-async def close_terminals(req: CloseTerminalsRequest) -> dict:
+async def close_terminals(request: Request, req: CloseTerminalsRequest) -> dict:
"""Stop selected coding agents in one locked batch and return canonical state."""
registry = get_registry()
+ session = registry.session
try:
closed, failed = await registry.close_terminals(req.names)
except SessionError as exc:
raise HTTPException(status_code=409, detail=str(exc)) from exc
+ # Voice and the CLI land here too: without the event, every OTHER client
+ # keeps rendering panes whose agents are already gone (the same contract as
+ # DELETE /terminals/agent/{agent} below).
+ bus = getattr(request.app.state, "bus", None)
+ if bus is not None and closed and session is not None:
+ try:
+ await bus.publish(
+ terminals_closed_event(session, closed, source_layer="agentic_ide_routes")
+ )
+ except Exception as exc: # noqa: BLE001 - the panes are already closed
+ log.debug("AgenticIdeTerminalsClosed publish failed: %s", exc)
return {
"ok": not failed,
"closed": [term.name for term in closed],
@@ -2003,7 +2019,7 @@ async def close_terminals_by_agent(request: Request, agent: str) -> dict:
@router.patch("/terminals/{terminal}", summary="Rename one terminal")
-async def rename_terminal(terminal: str, req: RenameTerminalRequest) -> dict:
+async def rename_terminal(request: Request, terminal: str, req: RenameTerminalRequest) -> dict:
"""Give the pane ``terminal`` another call-sign.
Nothing is started, stopped or restarted: the agent in the pane keeps
@@ -2025,6 +2041,11 @@ async def rename_terminal(terminal: str, req: RenameTerminalRequest) -> dict:
else:
status = 422
raise HTTPException(status_code=status, detail=message) from exc
+ # A rename made by voice or the CLI is invisible to every open view until
+ # it re-fetches — and a pane the UI addresses by its OLD call-sign routes
+ # prompts to a name the registry no longer answers to. Same trigger-only
+ # contract as the open/close announcements.
+ await _announce_workspace(request, session, "renamed")
return {
"ok": True,
"renamed": term.name,
@@ -2040,13 +2061,23 @@ async def rename_terminal(terminal: str, req: RenameTerminalRequest) -> dict:
summary="Close one terminal",
openapi_extra={"x-jarvis-dangerous": True},
)
-async def close_terminal(name: str) -> dict:
+async def close_terminal(request: Request, name: str) -> dict:
"""Stop the agent in the terminal called ``name`` and remove its pane."""
+ registry = get_registry()
+ session = registry.session
try:
- term = await get_registry().close_terminal(name)
+ term = await registry.close_terminal(name)
except SessionError as exc:
raise HTTPException(status_code=404, detail=str(exc)) from exc
- return {"ok": True, "closed": term.name, "state": get_registry().state()}
+ bus = getattr(request.app.state, "bus", None)
+ if bus is not None and session is not None:
+ try:
+ await bus.publish(
+ terminals_closed_event(session, [term], source_layer="agentic_ide_routes")
+ )
+ except Exception as exc: # noqa: BLE001 - the pane is already closed
+ log.debug("AgenticIdeTerminalsClosed publish failed: %s", exc)
+ return {"ok": True, "closed": term.name, "state": registry.state()}
@router.get("/recaps", response_model=RecapsResponse, summary="What every terminal is doing")
diff --git a/tests/unit/web/test_agentic_ide_batch_route.py b/tests/unit/web/test_agentic_ide_batch_route.py
index d40c1b670d..bb132ecf88 100644
--- a/tests/unit/web/test_agentic_ide_batch_route.py
+++ b/tests/unit/web/test_agentic_ide_batch_route.py
@@ -142,6 +142,7 @@ async def test_no_bus_still_opens_the_panes(
class FakeClosingRegistry:
def __init__(self) -> None:
self.calls: list[list[str]] = []
+ self.session = SimpleNamespace(id="ide_test", folder="/tmp/ws")
async def close_terminals(self, names: list[str]):
self.calls.append(names)
@@ -159,9 +160,10 @@ async def test_close_batch_returns_closed_failed_and_canonical_state(
) -> None:
registry = FakeClosingRegistry()
monkeypatch.setattr(routes, "get_registry", lambda: registry)
+ bus = FakeBus()
result = await routes.close_terminals(
- routes.CloseTerminalsRequest(names=["Juno", "Missing"])
+ _request(bus), routes.CloseTerminalsRequest(names=["Juno", "Missing"])
)
assert registry.calls == [["Juno", "Missing"]]
@@ -171,6 +173,23 @@ async def test_close_batch_returns_closed_failed_and_canonical_state(
"failed": [{"name": "Missing", "detail": "No terminal called 'Missing'."}],
"state": {"active": True, "session": {"terminals": [{"name": "Milo"}]}},
}
+ # A close made by voice or the CLI must reach every OTHER open view — the
+ # grid refetches on this event, exactly like the add-terminals batch above.
+ assert len(bus.published) == 1
+ assert type(bus.published[0]).__name__ == "AgenticIdeTerminalsClosed"
+ assert bus.published[0].names == ("Juno",)
+
+
+async def test_close_batch_without_a_bus_still_closes(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ registry = FakeClosingRegistry()
+ monkeypatch.setattr(routes, "get_registry", lambda: registry)
+
+ result = await routes.close_terminals(
+ _request(None), routes.CloseTerminalsRequest(names=["Juno", "Missing"])
+ )
+ assert result["closed"] == ["Juno"]
def test_close_batch_route_is_marked_dangerous() -> None:
diff --git a/tests/unit/web/test_agentic_ide_rename_terminal_route.py b/tests/unit/web/test_agentic_ide_rename_terminal_route.py
index 4d9d4bb0dd..028a0131f5 100644
--- a/tests/unit/web/test_agentic_ide_rename_terminal_route.py
+++ b/tests/unit/web/test_agentic_ide_rename_terminal_route.py
@@ -23,6 +23,19 @@ def _terminal(name: str) -> SimpleNamespace:
return SimpleNamespace(name=name, to_dict=lambda: {"name": name, "key": "t1"})
+class FakeBus:
+ def __init__(self) -> None:
+ self.published: list[object] = []
+
+ async def publish(self, event: object) -> None:
+ self.published.append(event)
+
+
+def _request(bus: object | None) -> SimpleNamespace:
+ """The one thing the route needs from a Request: ``app.state.bus``."""
+ return SimpleNamespace(app=SimpleNamespace(state=SimpleNamespace(bus=bus)))
+
+
class FakeRegistry:
"""Registry stand-in: records the call, returns or raises what was scripted."""
@@ -43,15 +56,21 @@ class FakeRegistry:
async def test_a_rename_answers_with_both_names(monkeypatch: pytest.MonkeyPatch) -> None:
"""Both, because the caller has UI filed under the OLD one to move across."""
- session = SimpleNamespace(id="ide_test")
+ session = SimpleNamespace(id="ide_test", folder="/tmp/ws", name="alpha")
registry = FakeRegistry(result=(session, _terminal("Frontend")))
monkeypatch.setattr(routes, "get_registry", lambda: registry)
+ bus = FakeBus()
result = await routes.rename_terminal(
- "T1", routes.RenameTerminalRequest(name="Frontend")
+ _request(bus), "T1", routes.RenameTerminalRequest(name="Frontend")
)
assert registry.calls == [("T1", "Frontend")]
+ # Every OTHER open view learns of the new call-sign through this trigger —
+ # without it a CLI/voice rename left the grid addressing a dead name.
+ assert len(bus.published) == 1
+ assert type(bus.published[0]).__name__ == "AgenticIdeWorkspaceChanged"
+ assert bus.published[0].reason == "renamed"
assert result["ok"] is True
assert result["renamed"] == "Frontend"
assert result["previous"] == "T1"
@@ -71,7 +90,9 @@ async def test_a_name_another_pane_carries_is_a_conflict(
monkeypatch.setattr(routes, "get_registry", lambda: registry)
with pytest.raises(HTTPException) as caught:
- await routes.rename_terminal("T2", routes.RenameTerminalRequest(name="Api"))
+ await routes.rename_terminal(
+ _request(None), "T2", routes.RenameTerminalRequest(name="Api")
+ )
assert caught.value.status_code == 409
assert "already called" in caught.value.detail
@@ -82,7 +103,9 @@ async def test_an_unknown_pane_is_a_not_found(monkeypatch: pytest.MonkeyPatch) -
monkeypatch.setattr(routes, "get_registry", lambda: registry)
with pytest.raises(HTTPException) as caught:
- await routes.rename_terminal("T7", routes.RenameTerminalRequest(name="Api"))
+ await routes.rename_terminal(
+ _request(None), "T7", routes.RenameTerminalRequest(name="Api")
+ )
assert caught.value.status_code == 404
# The panes that DO exist travel with it — the answer to the question asked.
@@ -98,6 +121,8 @@ async def test_an_invalid_call_sign_is_unprocessable(
monkeypatch.setattr(routes, "get_registry", lambda: registry)
with pytest.raises(HTTPException) as caught:
- await routes.rename_terminal("T1", routes.RenameTerminalRequest(name="---"))
+ await routes.rename_terminal(
+ _request(None), "T1", routes.RenameTerminalRequest(name="---")
+ )
assert caught.value.status_code == 422
diff --git a/tests/unit/web/test_agentic_ide_workspaces.py b/tests/unit/web/test_agentic_ide_workspaces.py
index a8dcef76b4..58e23d1241 100644
--- a/tests/unit/web/test_agentic_ide_workspaces.py
+++ b/tests/unit/web/test_agentic_ide_workspaces.py
@@ -282,6 +282,7 @@ async def test_renaming_a_workspace_changes_only_its_tab(
pty_id = pane.pty_id
result = await routes.rename_workspace(
+ _request(),
workspace_id,
routes.RenameWorkspaceRequest(name="Backend review"),
)