feat(workers): the ai-agent CLI back on workers (any harness) + worker picks by name #33

Open
gabrielvidal wants to merge 0 commits from worker-names into main
pull from: worker-names
Owner

Summary

Agents on a worker can drive the hub with the ai-agent CLI again, in any harness, through the worker's outbox. Worker picks now take a name as well as an id.

On 2026-11-28 an agy run on the EVOX2 (2ca176fc) could not start a conversation. Since 2026-11-18 a worker's CLI only did past, and its replacement, the worker-bound MCP, only existed in Claude Code. So the run shelled out to three claude -p --model haiku relays to call start_conversation:

  • they passed worker='EVOX2' and got hub: unknown worker: 'EVOX2' (HTTP 400), because the hub took ids only;
  • they had no parent link, so they polled wait_for_conversation for more than 10 minutes.

A second agy run (25c32ca5) gave up on delegating. Gabriel's call was to bring the CLI back on workers and keep the MCP in core.

Key changes

  • backend/workers/picks.py (new) turns any pick into a runner:

    • local, lab and homelab mean the lab;
    • a worker id is used as is;
    • otherwise a worker name matches in any case or spacing;
    • a name shared by two workers is refused.

    An unknown pick is a 400 worker_unknown that lists the valid ids and names (plus choices). Used by route_new_run (spawns, cron fires, the plugin runs bridge), the cron routes (a job pinned by name stores the id), workers/bound.py pin_worker and plugins/hubruns.py.

  • The CLI through the outbox (the 2026-11-16 path, rebuilt on today's code):

    • cli/ai_agent.py sends WORKER_COMMANDS to the outbox as a cli item {argv, sessionId} and prints what the hub's run printed. That run sends X-AIA-As-Worker and X-AIA-As-Worker-Mode.
    • backend/workers/cli.py CliJobs runs the same CLI in a clean env: the host token, the worker id, its switch as the mode, and CLAUDE_SESSION_ID set to the sending session. That session becomes the parent of what it starts, so children nest under it and report back with no polling.
    • The narrowing is workers/bound.py worker_caller, the same caller a worker-bound MCP connection gets (worker.read / worker.run scopes).
  • The per-worker switch:

    • stored as workers.json cli: off, read or run; unset means run, and a guest's computer is always off;
    • set with PATCH /api/workers/{id} {cli};
    • shown as a new ai-agent CLI section on Machines → the worker → Details (WorkerCli.tsx), with French strings.
  • Sidecar and installer:

    • sidecar/outbox.py accepts the cli kind again and drops its output 10 min after it ends;
    • outbox_mirror answers it;
    • worker/install.sh writes the ai-agent terminal shim again.
  • The other changes:

    • The conv-ref hook now names the CLI on a worker.
    • past's lookup follows the switch.
    • The MCP worker argument and --on help say "id or name, or 'lab'".
    • The gate's refusal no longer says "connection" when the caller is the CLI.
  • Docs: CLAUDE.md, docs/mcp.md ("On a worker") and worker/README.md.

Key decisions

  • The CLI rather than the MCP for agents on workers (Gabriel, notify-ask "CLI back on workers"):

    • it works in every harness, so agy and opencode need no MCP auth;
    • the parent link and the automatic report-back come for free;
    • the worker never calls the hub.

    Removing the CLI everywhere was rejected: 16 skill and plugin folders call it, it is the guest broker, and pi has no MCP client. Moving the MCP into a plugin was mapped and dropped ("keep the mcp").

  • The bound MCP connection stays (Settings → AI apps → Acts as). It is optional and is the same narrowed caller as the CLI, so the two can't drift.

  • New runs stay pinned to the worker that sent them, as on 11-16. --on may name that worker by id or name.

  • Names resolve on the hub, not in each client. The CLI, the MCP, cron and plugins all get the same rule and the same helpful error.

  • No MCP parent argument. It was approved in the first form, but the CLI already sets the parent from CLAUDE_SESSION_ID.

Changelog

  • Added: the ai-agent CLI works in every conversation on a worker (Claude Code, agy, opencode) and in a terminal there, through the worker's outbox. What it starts appears inside the conversation and reports back to it.
  • Added: an ai-agent CLI switch on each worker's Details tab (Off / Read / Read + run here).
  • Fixed: starting a conversation on a worker by its name (EVOX2) instead of its id. An unknown worker now lists the valid ones.
  • Changed: lab (and homelab) work wherever a worker is picked, like local.

Test notes

  • Backend: all 167 test_*.py modules, each under bwrap with a throwaway /data, on this branch and on main. The only failure is test_typed_plugins.py::TestStore::test_records_carry_kind (a git clone in the test environment), and it fails on main too. New or updated suites: test_worker_cli.py (7, new), test_worker_bound.py (12), test_worker_routing.py (48, including names, ambiguity, lab aliases and cron by name).

  • Sidecar: test_outbox.py 12 passed. CLI: test_ai_agent.py, test_mcp_tools.py and test_conv_ref.py 94 passed.

  • Frontend:

    • tsc is clean and the i18n test passes;
    • vitest: 1086 of 1087 pass; the 1 failure is FreshContext.test.tsx, already listed as flaky in scripts/test-known-failures.txt.
  • Live check: I booted a local hub from this branch with an EVOX2 worker record. I ran the real CLI with the exact environment CliJobs gives it:

    • ls, search, past, workers, usage and scheduled all answered through the gate;
    • new --on EVOX2 resolved the name;
    • new --on lab got a 403 ("a run started from EVOX2 goes to EVOX2 only");
    • new in Read mode got a 403.

    budget and models answered the owner the same way, because that hub had no provider plugins.

  • Not tested: a real round trip from the EVOX2's outbox. It needs this branch on the hub, and the worker follows the hub's commit.

  • Deploy from the Homelab after review (the ai-agent-deploy skill), never from the EVOX2. The workers update themselves to the hub's commit, and their install.sh puts the ai-agent shim back. The companion homelab PR updates the ai-agent skill and services/ai-agent/CLAUDE.md: merge both.

  • Screenshots: the Details tab on desktop, and on a phone with Read picked (mock API).

🤖 Generated with Claude Code

Screenshots

worker-cli-switch.png
worker-cli-switch-mobile.png

## Summary Agents on a worker can drive the hub with the `ai-agent` CLI again, in any harness, through the worker's outbox. Worker picks now take a name as well as an id. On 2026-11-28 an agy run on the EVOX2 (2ca176fc) could not start a conversation. Since 2026-11-18 a worker's CLI only did `past`, and its replacement, the worker-bound MCP, only existed in Claude Code. So the run shelled out to three `claude -p --model haiku` relays to call `start_conversation`: - they passed `worker='EVOX2'` and got `hub: unknown worker: 'EVOX2' (HTTP 400)`, because the hub took ids only; - they had no parent link, so they polled `wait_for_conversation` for more than 10 minutes. A second agy run (25c32ca5) gave up on delegating. Gabriel's call was to bring the CLI back on workers and keep the MCP in core. ## Key changes - **`backend/workers/picks.py` (new)** turns any pick into a runner: - `local`, `lab` and `homelab` mean the lab; - a worker id is used as is; - otherwise a worker name matches in any case or spacing; - a name shared by two workers is refused. An unknown pick is a 400 `worker_unknown` that lists the valid ids and names (plus `choices`). Used by `route_new_run` (spawns, cron fires, the plugin runs bridge), the cron routes (a job pinned by name stores the id), `workers/bound.py` `pin_worker` and `plugins/hubruns.py`. - **The CLI through the outbox (the 2026-11-16 path, rebuilt on today's code):** - `cli/ai_agent.py` sends `WORKER_COMMANDS` to the outbox as a `cli` item `{argv, sessionId}` and prints what the hub's run printed. That run sends `X-AIA-As-Worker` and `X-AIA-As-Worker-Mode`. - `backend/workers/cli.py` `CliJobs` runs the same CLI in a clean env: the host token, the worker id, its switch as the mode, and `CLAUDE_SESSION_ID` set to the sending session. That session becomes the **parent** of what it starts, so children nest under it and report back with no polling. - The narrowing is `workers/bound.py` `worker_caller`, the same caller a worker-bound MCP connection gets (`worker.read` / `worker.run` scopes). - **The per-worker switch:** - stored as `workers.json` `cli`: `off`, `read` or `run`; unset means `run`, and a guest's computer is always `off`; - set with PATCH `/api/workers/{id}` `{cli}`; - shown as a new **ai-agent CLI** section on Machines → the worker → Details (`WorkerCli.tsx`), with French strings. - **Sidecar and installer:** - `sidecar/outbox.py` accepts the `cli` kind again and drops its output 10 min after it ends; - `outbox_mirror` answers it; - `worker/install.sh` writes the `ai-agent` terminal shim again. - **The other changes:** - The conv-ref hook now names the CLI on a worker. - `past`'s `lookup` follows the switch. - The MCP `worker` argument and `--on` help say "id or name, or 'lab'". - The gate's refusal no longer says "connection" when the caller is the CLI. - **Docs:** `CLAUDE.md`, `docs/mcp.md` ("On a worker") and `worker/README.md`. ## Key decisions - **The CLI rather than the MCP for agents on workers** (Gabriel, notify-ask "CLI back on workers"): - it works in every harness, so agy and opencode need no MCP auth; - the parent link and the automatic report-back come for free; - the worker never calls the hub. Removing the CLI everywhere was rejected: 16 skill and plugin folders call it, it is the guest broker, and pi has no MCP client. Moving the MCP into a plugin was mapped and dropped ("keep the mcp"). - **The bound MCP connection stays** (Settings → AI apps → *Acts as*). It is optional and is the same narrowed caller as the CLI, so the two can't drift. - **New runs stay pinned to the worker that sent them**, as on 11-16. `--on` may name that worker by id or name. - **Names resolve on the hub, not in each client.** The CLI, the MCP, cron and plugins all get the same rule and the same helpful error. - **No MCP `parent` argument.** It was approved in the first form, but the CLI already sets the parent from `CLAUDE_SESSION_ID`. ## Changelog - Added: the `ai-agent` CLI works in every conversation on a worker (Claude Code, agy, opencode) and in a terminal there, through the worker's outbox. What it starts appears inside the conversation and reports back to it. - Added: an **ai-agent CLI** switch on each worker's Details tab (Off / Read / Read + run here). - Fixed: starting a conversation on a worker by its name (`EVOX2`) instead of its id. An unknown worker now lists the valid ones. - Changed: `lab` (and `homelab`) work wherever a worker is picked, like `local`. ## Test notes - **Backend:** all 167 `test_*.py` modules, each under bwrap with a throwaway `/data`, on this branch and on main. The only failure is `test_typed_plugins.py::TestStore::test_records_carry_kind` (a `git clone` in the test environment), and it fails on main too. New or updated suites: `test_worker_cli.py` (7, new), `test_worker_bound.py` (12), `test_worker_routing.py` (48, including names, ambiguity, lab aliases and cron by name). - **Sidecar:** `test_outbox.py` 12 passed. **CLI:** `test_ai_agent.py`, `test_mcp_tools.py` and `test_conv_ref.py` 94 passed. - **Frontend:** - `tsc` is clean and the i18n test passes; - vitest: 1086 of 1087 pass; the 1 failure is `FreshContext.test.tsx`, already listed as flaky in `scripts/test-known-failures.txt`. - **Live check:** I booted a local hub from this branch with an `EVOX2` worker record. I ran the real CLI with the exact environment `CliJobs` gives it: - `ls`, `search`, `past`, `workers`, `usage` and `scheduled` all answered through the gate; - `new --on EVOX2` resolved the name; - `new --on lab` got a 403 ("a run started from EVOX2 goes to EVOX2 only"); - `new` in Read mode got a 403. `budget` and `models` answered the owner the same way, because that hub had no provider plugins. - **Not tested:** a real round trip from the EVOX2's outbox. It needs this branch on the hub, and the worker follows the hub's commit. - **Deploy from the Homelab** after review (the `ai-agent-deploy` skill), never from the EVOX2. The workers update themselves to the hub's commit, and their `install.sh` puts the `ai-agent` shim back. The companion homelab PR updates the `ai-agent` skill and `services/ai-agent/CLAUDE.md`: merge both. - Screenshots: the Details tab on desktop, and on a phone with Read picked (mock API). 🤖 Generated with [Claude Code](https://claude.com/claude-code) ## Screenshots ![worker-cli-switch.png](https://git.gabvdl.xyz/attachments/8c9b55a5-91d8-49ad-a193-b909d7ed2b8c) ![worker-cli-switch-mobile.png](https://git.gabvdl.xyz/attachments/5cbf0706-005f-4b98-a9ba-4b88cc15ca90)
gabrielvidal self-assigned this 2026-11-28 12:58:07 +01:00
gabrielvidal added 2 commits 2026-11-28 12:58:07 +01:00
The MCP start_conversation and the CLI's --on have always said "a worker
id or name", and browse / ai-agent workers print the name first, but the
hub looked workers up by id only: worker='EVOX2' was a 400 "unknown
worker" and agents guessed their way to the id (the three relays of
2ca176fc, 2026-11-28).

workers/picks.py resolves every pick: local / lab / homelab are the lab,
a worker's id as is, else its name in any case and spacing among the
owner's workers (a guest's own computers for a guest's run). A name two
workers share names none. An unknown pick is a 400 worker_unknown whose
message lists the valid ids and names (and `choices`), so the next try is
the right one. Used by route_new_run (spawns, cron fires, the plugin runs
bridge), the cron routes (a job pinned by name stores the id) and the
runs bridge's worker check (names with spaces pass, "lab" is the lab).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On 2026-11-28 an agy run on the EVOX2 (2ca176fc) had no way to start a
conversation: since 2026-11-18 a worker's CLI kept only `past`, and the
hub's MCP — its stand-in — existed in Claude Code only. It shelled out to
three `claude -p --model haiku` relays to call start_conversation, which
named the worker EVOX2 (refused), had no parent to report to and polled
wait_for_conversation for 10+ minutes. Another agy run (25c32ca5) gave up
delegating. Gabriel's call: the CLI back on workers, the MCP stays.

The 2026-11-16 path, on today's code:
- cli/ai_agent.py: on a worker (AI_AGENT_OUTBOX_URL) the WORKER_COMMANDS
  go into the outbox as a `cli` item {argv, sessionId}; what the hub's run
  printed comes back (≈ 2–4 s, a `wait` when the run ends). The hub's run
  sends X-AIA-As-Worker + X-AIA-As-Worker-Mode.
- backend/workers/cli.py: CliJobs runs the same CLI in a clean env (host
  token, AIA_AS_WORKER, its switch as the mode, CLAUDE_SESSION_ID = the
  sending session → the parent of what it starts: children nest and report
  back). The narrowing is workers/bound.py worker_caller — the same caller
  as a worker-bound MCP connection, worker.read / worker.run scopes.
- The per-worker switch: workers.json `cli` off | read | run (unset = run,
  a guest's computer always off), PATCH /api/workers/{id} {cli}, Machines →
  the worker → Details → "ai-agent CLI".
- sidecar/outbox.py: the `cli` kind (results dropped 10 min after they end);
  outbox_mirror answers it; worker/install.sh writes the `ai-agent` terminal
  shim again.
- The conv-ref hook names the CLI on a worker; `past`'s lookup follows the
  switch. The bound MCP connection stays, optional.
- Docs: CLAUDE.md, docs/mcp.md, worker/README.md.

Tests: test_worker_cli.py (new), test_worker_bound.py, test_worker_routing.py,
sidecar test_outbox.py, cli test_ai_agent.py / test_conv_ref.py; the whole
backend per module matches main (test_typed_plugins' git-clone case fails on
both). A live local hub answered every worker command through the gate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch is already included in the target branch. There is nothing to merge.
This branch is out-of-date with the base branch
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin worker-names:worker-names
git checkout worker-names
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: gabrielvidal/ai-agent#33