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(cu): run-control REST API + CLI — start/list/inspect/cancel desktop goals
Ruben Lütke456fe1991eb8
diff --git a/docs/jarvis-cli-reference.md b/docs/jarvis-cli-reference.mdindex 167ae3989e..65548e1d51 100644--- a/docs/jarvis-cli-reference.md+++ b/docs/jarvis-cli-reference.md@@ -43,6 +43,14 @@ _Generated from the curated command tree by `scripts/ci/gen_cli_reference.py`- `jarvis commands list` — List every registry command (id, endpoint, params, danger, UI section).- `jarvis commands show <command_id>` — Show one command's full definition (params schema, voice aliases).+## computer-use++- `jarvis computer-use cancel <mission_id> --yes --dry-run` — Cancel one active run.+- `jarvis computer-use cancel-all --yes --dry-run` — Cancel every active run (queued and running).+- `jarvis computer-use list --limit` — List active and recent Computer-Use runs.+- `jarvis computer-use show <mission_id>` — Show one run: status, goal, exit code, final output.+- `jarvis computer-use start <goal> --timeout-s --yes --dry-run` — Start a desktop goal in the background; prints the mission id.+## conductor- `jarvis conductor add --def --yes --dry-run` — Add a job from a Job JSON document.diff --git a/jarvis/cli_ctl/__main__.py b/jarvis/cli_ctl/__main__.pyindex 5c374604b7..77c77d7f70 100644--- a/jarvis/cli_ctl/__main__.py+++ b/jarvis/cli_ctl/__main__.py@@ -23,6 +23,7 @@ from jarvis.cli_ctl.commands import board as board_cmdfrom jarvis.cli_ctl.commands import brain as brain_cmdfrom jarvis.cli_ctl.commands import clis as clis_cmdfrom jarvis.cli_ctl.commands import commands as commands_cmd+from jarvis.cli_ctl.commands import computer_use as computer_use_cmdfrom jarvis.cli_ctl.commands import conductor as conductor_cmdfrom jarvis.cli_ctl.commands import config as config_cmdfrom jarvis.cli_ctl.commands import contacts as contacts_cmd@@ -107,6 +108,7 @@ app.add_typer(system_cmd.app, name="system")app.add_typer(tasks_cmd.app, name="tasks")app.add_typer(brain_cmd.app, name="brain")app.add_typer(commands_cmd.app, name="commands")+app.add_typer(computer_use_cmd.app, name="computer-use")app.add_typer(config_cmd.app, name="config")app.add_typer(missions_cmd.app, name="missions")app.add_typer(wiki_cmd.app, name="wiki")diff --git a/jarvis/cli_ctl/commands/computer_use.py b/jarvis/cli_ctl/commands/computer_use.pynew file mode 100644index 0000000000..bce4f8c94f--- /dev/null+++ b/jarvis/cli_ctl/commands/computer_use.py@@ -0,0 +1,76 @@+"""computer-use: drive desktop-automation goals (/api/computer-use/goals)."""+from __future__ import annotations++import typer++from jarvis.cli_ctl import invoke, options++app = typer.Typer(+ no_args_is_help=True,+ help="Computer Use: start, watch, and cancel desktop-automation goals.",+)+++def start(+ goal: str = typer.Argument(..., help="What Jarvis should do on the desktop."),+ timeout_s: float = typer.Option(+ 120.0, "--timeout-s", help="Mission deadline in seconds (10-3600).",+ ),+ yes: bool = options.yes_opt(),+ dry_run: bool = options.dry_opt(),+) -> None:+ """Start a desktop goal in the background; prints the mission id."""+ invoke.run(+ "POST",+ "/api/computer-use/goals",+ body={"goal": goal, "timeout_s": timeout_s},+ assume_yes=yes,+ dry_run=dry_run,+ dangerous=True,+ )++[email protected]("list")+def list_runs(+ limit: int = typer.Option(20, "--limit", help="Newest-first run count."),+) -> None:+ """List active and recent Computer-Use runs."""+ invoke.run("GET", "/api/computer-use/goals", params={"limit": limit})+++def show(mission_id: str = typer.Argument(..., help="Mission id.")) -> None:+ """Show one run: status, goal, exit code, final output."""+ invoke.run("GET", f"/api/computer-use/goals/{mission_id}")+++def cancel(+ mission_id: str = typer.Argument(..., help="Mission id."),+ yes: bool = options.yes_opt(),+ dry_run: bool = options.dry_opt(),+) -> None:+ """Cancel one active run."""+ invoke.run(+ "POST",+ f"/api/computer-use/goals/{mission_id}/cancel",+ assume_yes=yes,+ dry_run=dry_run,+ dangerous=True,+ )++[email protected]("cancel-all")+def cancel_all(+ yes: bool = options.yes_opt(),+ dry_run: bool = options.dry_opt(),+) -> None:+ """Cancel every active run (queued and running)."""+ invoke.run(+ "POST",+ "/api/computer-use/goals/cancel-all",+ assume_yes=yes,+ dry_run=dry_run,+ dangerous=True,+ )diff --git a/jarvis/ui/web/computer_use_routes.py b/jarvis/ui/web/computer_use_routes.pynew file mode 100644index 0000000000..411f5721d1--- /dev/null+++ b/jarvis/ui/web/computer_use_routes.py@@ -0,0 +1,194 @@+"""Run-control REST surface for Computer-Use goals (deep-dive 2026-07-15, H-09).++Start / list / inspect / cancel desktop-automation missions over HTTP — which+makes each operation a ``jarvis api computer-use <op>`` CLI command+automatically (CLI-first contract). Before this module the feature was+reachable only through voice and the LLM tool; there was no uniform+automation/control API and no per-goal cancel.++The routes are a thin shell: run inventory and per-id cancel live in+``jarvis.harness.cu_run_registry`` (populated by the harness itself for EVERY+launch route), and a started goal runs the same ``ComputerUseHarness`` path as+voice/tool launches — same guards, same desktop lock, same registry lifecycle.+Platform-neutral: plain Python/FastAPI, no OS-specific code.+"""+from __future__ import annotations++import asyncio+import logging+import uuid+from typing import Any++from fastapi import APIRouter, HTTPException, Query+from pydantic import BaseModel, Field++from jarvis.harness import cu_run_registry++log = logging.getLogger(__name__)++router = APIRouter(prefix="/api/computer-use", tags=["computer-use"])++#: Matches the LLM tool's default mission timeout.+_DEFAULT_TIMEOUT_S = 120.0+_MIN_TIMEOUT_S = 10.0+_MAX_TIMEOUT_S = 3600.0++#: Strong refs so background missions are never garbage-collected mid-flight+#: (same pattern as ComputerUseTool._background_tasks).+_BACKGROUND_MISSIONS: set[asyncio.Task[None]] = set()+++class StartGoalBody(BaseModel):+ """Request body for starting a Computer-Use goal."""++ goal: str = Field(min_length=1, max_length=2000)+ timeout_s: float = Field(+ default=_DEFAULT_TIMEOUT_S, ge=_MIN_TIMEOUT_S, le=_MAX_TIMEOUT_S,+ )+++def _require_cu_wired() -> None:+ """503 with an honest, actionable message when Computer Use is not live."""+ from jarvis.harness.computer_use_context import ( # noqa: PLC0415+ peek_computer_use_context,+ )++ if peek_computer_use_context() is None:+ raise HTTPException(+ status_code=503,+ detail=(+ "computer-use is not active on this machine: "+ "[computer_use].enabled is false (the shipped default) or no "+ "vision engine could be built. Enable it with "+ "`jarvis config set computer_use.enabled true` and restart."+ ),+ )+++def _launch_mission(mission_id: str, goal: str, timeout_s: float) -> None:+ """Start the mission as a detached background task.++ The harness registers the run (queued -> running -> terminal) under the+ pre-assigned ``mission_id``; this function only owns the task lifetime.+ Split out so route tests can monkeypatch the actual desktop dispatch.+ """+ from jarvis.core.protocols import HarnessTask # noqa: PLC0415+ from jarvis.plugins.harness.computer_use import ( # noqa: PLC0415+ CU_MISSION_ID_ENV_KEY,+ CU_SOURCE_ENV_KEY,+ ComputerUseHarness,+ )++ task = HarnessTask(+ prompt=goal,+ timeout_s=int(timeout_s),+ env={CU_MISSION_ID_ENV_KEY: mission_id, CU_SOURCE_ENV_KEY: "api"},+ )+ harness = ComputerUseHarness()++ async def _drain() -> None:+ try:+ async for _chunk in harness.invoke(task):+ pass+ except Exception: # noqa: BLE001 — a crash must not kill the event loop+ log.exception("[cu] API-started mission %s crashed", mission_id)+ cu_run_registry.finish_run(mission_id, "error")++ bg = asyncio.create_task(_drain(), name=f"cu-api-mission-{mission_id}")+ _BACKGROUND_MISSIONS.add(bg)+ bg.add_done_callback(_BACKGROUND_MISSIONS.discard)+++ "/goals",+ status_code=201,+ summary="Start a Computer-Use goal",+ openapi_extra={"x-jarvis-dangerous": True},+)+async def start_cu_goal(body: StartGoalBody) -> dict[str, Any]:+ """Dispatch a desktop-automation goal in the background.++ Returns the mission id for status polling and cancel. Refuses honestly+ (503) when Computer Use is not wired, and absorbs a duplicate of an+ ALREADY-RUNNING identical goal (409) instead of racing the desktop.+ """+ _require_cu_wired()+ goal = body.goal.strip()+ if not goal:+ raise HTTPException(status_code=400, detail="goal must not be blank")+ goal_key = " ".join(goal.split()).casefold()+ for run in cu_run_registry.list_runs(limit=100):+ if (+ run["status"] in cu_run_registry.ACTIVE_STATUSES+ and " ".join(run["goal"].split()).casefold() == goal_key+ ):+ raise HTTPException(+ status_code=409,+ detail={+ "message": "an identical goal is already running",+ "mission_id": run["mission_id"],+ },+ )+ mission_id = uuid.uuid4().hex[:12]+ # Visible to GET immediately; the harness replaces this entry with the+ # live one (real cancel token) the moment the background task starts.+ cu_run_registry.register_run(mission_id, goal, token=None, source="api")+ _launch_mission(mission_id, goal, body.timeout_s)+ return {"mission_id": mission_id, "status": "queued", "goal": goal}++[email protected]("/goals", summary="List Computer-Use runs")+async def list_cu_goals(+ limit: int = Query(default=20, ge=1, le=100),+) -> dict[str, Any]:+ """Newest-first run snapshots (active and recent terminal runs)."""+ runs = cu_run_registry.list_runs(limit=limit)+ return {+ "runs": runs,+ "active": cu_run_registry.active_run_count(),+ "total": len(runs),+ }+++ "/goals/cancel-all",+ summary="Cancel every active Computer-Use run",+ openapi_extra={"x-jarvis-dangerous": True},+)+async def cancel_all_cu_goals() -> dict[str, Any]:+ """Fire the cancel token of every active mission (queued or running)."""+ return {"cancelled": cu_run_registry.cancel_all_runs(reason="api_cancel")}++[email protected]("/goals/{mission_id}", summary="Inspect one Computer-Use run")+async def get_cu_goal(mission_id: str) -> dict[str, Any]:+ run = cu_run_registry.get_run(mission_id)+ if run is None:+ raise HTTPException(status_code=404, detail="unknown mission id")+ return run+++ "/goals/{mission_id}/cancel",+ summary="Cancel one Computer-Use run",+ openapi_extra={"x-jarvis-dangerous": True},+)+async def cancel_cu_goal(mission_id: str) -> dict[str, Any]:+ """Cancel one active mission by id (404 unknown, 409 already finished)."""+ run = cu_run_registry.get_run(mission_id)+ if run is None:+ raise HTTPException(status_code=404, detail="unknown mission id")+ if run["status"] in cu_run_registry.TERMINAL_STATUSES:+ raise HTTPException(+ status_code=409,+ detail=f"run is already terminal ({run['status']})",+ )+ if not cu_run_registry.cancel_run(mission_id, reason="api_cancel"):+ raise HTTPException(+ status_code=409,+ detail="run has no live cancel token (it is about to start or end)",+ )+ return {"mission_id": mission_id, "cancel_requested": True}+++__all__ = ["router"]diff --git a/jarvis/ui/web/server.py b/jarvis/ui/web/server.pyindex 0f099ab921..77887694b3 100644--- a/jarvis/ui/web/server.py+++ b/jarvis/ui/web/server.py@@ -270,6 +270,7 @@ class WebServer:from .claude_routes import router as claude_routerfrom .cli_routes import router as cli_routerfrom .commands_routes import router as commands_router+ from .computer_use_routes import router as computer_use_routerfrom .contacts_routes import router as contacts_routerfrom .control_routes import router as control_routerfrom .diagnostics_routes import router as diagnostics_router@@ -413,6 +414,10 @@ class WebServer:app.include_router(missions_router)app.include_router(missions_ws_router)app.include_router(missions_pty_router)+ # Computer-Use run control (deep-dive 2026-07-15, H-09): start/list/+ # inspect/cancel desktop goals — auto-exposed as `jarvis api+ # computer-use <op>` by the dynamic CLI layer.+ app.include_router(computer_use_router)# Phase B9 — Obsidian Setup Wizard (detect install + register vault).app.include_router(setup_router)# First-time onboarding guide (/api/onboarding/*).diff --git a/tests/unit/cli_ctl/test_commands_computer_use.py b/tests/unit/cli_ctl/test_commands_computer_use.pynew file mode 100644index 0000000000..d9191e282b--- /dev/null+++ b/tests/unit/cli_ctl/test_commands_computer_use.py@@ -0,0 +1,70 @@+"""Tests for the curated computer-use commands (deep-dive H-09)."""+from __future__ import annotations++from typer.testing import CliRunner++from jarvis.cli_ctl.__main__ import app++runner = CliRunner()+++def test_start_requires_yes(capture_api):+ res = runner.invoke(app, ["computer-use", "start", "open the browser"])+ assert res.exit_code == 1+ assert capture_api["calls"] == []+++def test_start_with_yes(capture_api):+ res = runner.invoke(+ app, ["computer-use", "start", "open the browser", "--yes"],+ )+ assert res.exit_code == 0+ call = capture_api["calls"][-1]+ assert call["method"] == "POST"+ assert call["path"] == "/api/computer-use/goals"+ assert call["body"]["goal"] == "open the browser"+ assert call["body"]["timeout_s"] == 120.0+++def test_start_custom_timeout(capture_api):+ runner.invoke(+ app,+ ["computer-use", "start", "x", "--timeout-s", "300", "--yes"],+ )+ assert capture_api["calls"][-1]["body"]["timeout_s"] == 300.0+++def test_list(capture_api):+ runner.invoke(app, ["computer-use", "list", "--limit", "5"])+ call = capture_api["calls"][-1]+ assert call["method"] == "GET"+ assert call["path"] == "/api/computer-use/goals"+ assert int(call["query"]["limit"]) == 5+++def test_show(capture_api):+ runner.invoke(app, ["computer-use", "show", "abc123"])+ call = capture_api["calls"][-1]+ assert call["method"] == "GET"+ assert call["path"] == "/api/computer-use/goals/abc123"+++def test_cancel_requires_yes(capture_api):+ assert runner.invoke(app, ["computer-use", "cancel", "abc123"]).exit_code == 1+ assert capture_api["calls"] == []+++def test_cancel_with_yes(capture_api):+ res = runner.invoke(app, ["computer-use", "cancel", "abc123", "--yes"])+ assert res.exit_code == 0+ call = capture_api["calls"][-1]+ assert call["method"] == "POST"+ assert call["path"] == "/api/computer-use/goals/abc123/cancel"+++def test_cancel_all_with_yes(capture_api):+ res = runner.invoke(app, ["computer-use", "cancel-all", "--yes"])+ assert res.exit_code == 0+ call = capture_api["calls"][-1]+ assert call["method"] == "POST"+ assert call["path"] == "/api/computer-use/goals/cancel-all"diff --git a/tests/unit/ui/web/test_computer_use_routes.py b/tests/unit/ui/web/test_computer_use_routes.pynew file mode 100644index 0000000000..9ce1012bb5--- /dev/null+++ b/tests/unit/ui/web/test_computer_use_routes.py@@ -0,0 +1,198 @@+"""Run-control REST surface for Computer-Use goals (deep-dive H-09).++Pins the CLI-first contract for the new surface: an honest 503 when Computer+Use is not wired, start hands back a pollable mission id, duplicate active+goals are absorbed with 409, and cancel is per-id with honest 404/409.+"""+from __future__ import annotations++from typing import Any++import pytest+from fastapi import FastAPI+from fastapi.testclient import TestClient++from jarvis.control import CancelToken+from jarvis.harness import cu_run_registry as reg+from jarvis.ui.web import computer_use_routes as cu_routes+from jarvis.ui.web.computer_use_routes import router as computer_use_router++[email protected](autouse=True)+def _clean_registry():+ reg.clear_runs()+ yield+ reg.clear_runs()+++def app() -> FastAPI:+ app = FastAPI()+ app.include_router(computer_use_router)+ return app+++def wired(monkeypatch: pytest.MonkeyPatch):+ """Pretend the CU context is wired and capture launches (no desktop)."""+ from jarvis.harness import computer_use_context as ctx_mod++ monkeypatch.setattr(+ ctx_mod, "peek_computer_use_context", lambda: object(),+ )+ launches: list[tuple[str, str, float]] = []+ monkeypatch.setattr(+ cu_routes,+ "_launch_mission",+ lambda mission_id, goal, timeout_s: launches.append(+ (mission_id, goal, timeout_s)+ ),+ )+ return launches+++# ----------------------------------------------------------------------+# Start+# ----------------------------------------------------------------------++def test_start_refuses_honestly_when_cu_is_not_wired(app: FastAPI) -> None:+ with TestClient(app) as client:+ r = client.post("/api/computer-use/goals", json={"goal": "open the browser"})+ assert r.status_code == 503+ assert "computer_use.enabled" in r.json()["detail"]+++def test_start_returns_a_pollable_mission_id(app: FastAPI, wired: list) -> None:+ with TestClient(app) as client:+ r = client.post("/api/computer-use/goals", json={"goal": "open the browser"})+ assert r.status_code == 201+ body = r.json()+ assert body["status"] == "queued"+ mission_id = body["mission_id"]+ assert mission_id++ # Immediately visible to GET — no race window for the caller.+ got = client.get(f"/api/computer-use/goals/{mission_id}")+ assert got.status_code == 200+ assert got.json()["goal"] == "open the browser"+ assert got.json()["source"] == "api"+ assert wired == [(mission_id, "open the browser", 120.0)]+++def test_start_absorbs_a_duplicate_active_goal(app: FastAPI, wired: list) -> None:+ with TestClient(app) as client:+ first = client.post(+ "/api/computer-use/goals", json={"goal": "Open The Browser"}+ )+ dup = client.post(+ "/api/computer-use/goals", json={"goal": "open the browser"}+ )+ assert first.status_code == 201+ assert dup.status_code == 409+ assert dup.json()["detail"]["mission_id"] == first.json()["mission_id"]+ assert len(wired) == 1 # the duplicate never launched+++def test_start_validates_goal_and_timeout(app: FastAPI, wired: list) -> None:+ with TestClient(app) as client:+ blank = client.post("/api/computer-use/goals", json={"goal": " "})+ bad_timeout = client.post(+ "/api/computer-use/goals",+ json={"goal": "x", "timeout_s": 999999},+ )+ assert blank.status_code == 400+ assert bad_timeout.status_code == 422 # pydantic bound+ assert wired == []+++# ----------------------------------------------------------------------+# List / get+# ----------------------------------------------------------------------++def _seed(mission_id: str, goal: str, *, status: str = "queued") -> CancelToken:+ token = CancelToken()+ reg.register_run(mission_id, goal, token, source="voice")+ if status == "running":+ reg.mark_running(mission_id)+ elif status != "queued":+ reg.finish_run(mission_id, status, exit_code=0)+ return token+++def test_list_shows_runs_from_every_launch_route(app: FastAPI) -> None:+ _seed("v1", "voice goal", status="running")+ _seed("t1", "old goal", status="finished")+ with TestClient(app) as client:+ r = client.get("/api/computer-use/goals")+ assert r.status_code == 200+ body = r.json()+ assert body["active"] == 1+ assert {run["mission_id"] for run in body["runs"]} == {"v1", "t1"}+ assert all("token" not in run for run in body["runs"])+++def test_get_unknown_id_is_404(app: FastAPI) -> None:+ with TestClient(app) as client:+ r = client.get("/api/computer-use/goals/nope")+ assert r.status_code == 404+++# ----------------------------------------------------------------------+# Cancel+# ----------------------------------------------------------------------++def test_cancel_fires_the_run_token(app: FastAPI) -> None:+ token = _seed("r1", "goal", status="running")+ with TestClient(app) as client:+ r = client.post("/api/computer-use/goals/r1/cancel")+ assert r.status_code == 200+ assert r.json()["cancel_requested"] is True+ assert token.is_cancelled()+ assert token.reason == "api_cancel"+++def test_cancel_is_honest_about_unknown_and_terminal(app: FastAPI) -> None:+ _seed("done1", "goal", status="finished")+ with TestClient(app) as client:+ unknown = client.post("/api/computer-use/goals/nope/cancel")+ terminal = client.post("/api/computer-use/goals/done1/cancel")+ assert unknown.status_code == 404+ assert terminal.status_code == 409+++def test_cancel_all_hits_only_active_runs(app: FastAPI) -> None:+ t1 = _seed("a1", "goal one", status="running")+ t2 = _seed("a2", "goal two", status="queued")+ t3 = _seed("z1", "goal three", status="finished")+ with TestClient(app) as client:+ r = client.post("/api/computer-use/goals/cancel-all")+ assert r.status_code == 200+ assert r.json()["cancelled"] == 2+ assert t1.is_cancelled() and t2.is_cancelled()+ assert not t3.is_cancelled()+++# ----------------------------------------------------------------------+# CLI-first contract+# ----------------------------------------------------------------------++def test_danger_flag_is_declared_on_start_and_cancel(app: FastAPI) -> None:+ """The dynamic CLI derives --yes gating from x-jarvis-dangerous."""+ with TestClient(app) as client:+ spec: dict[str, Any] = client.get("/openapi.json").json()+ paths = spec["paths"]+ assert paths["/api/computer-use/goals"]["post"]["x-jarvis-dangerous"] is True+ assert (+ paths["/api/computer-use/goals/{mission_id}/cancel"]["post"][+ "x-jarvis-dangerous"+ ]+ is True+ )+ assert (+ paths["/api/computer-use/goals/cancel-all"]["post"]["x-jarvis-dangerous"]+ is True+ )+ # Every operation is tagged so `jarvis api computer-use` groups them.+ for item in paths.values():+ for op in item.values():+ assert op["tags"] == ["computer-use"]