Repository navigation
Open
Labels
enhancementNew feature or request
Description
Part of the Coding-agent subagents epic (#378). Item A2. Depends on A1 (#380).
Goal
Add mocactl commands that a script, and a coding agent through a plugin (Claude Code's is #383), can drive to spawn, watch, collect, approve and follow up on MOCA subagents. They work over today's API: control-plane sessions, data-plane sync /runs prompt and converge leaves, and /runs/status. A transport seam lets async turns (#387, #392) replace the backend later without changing the commands.
Current state (verified on main @ 24c6f5e)
- Existing commands:
login,doctor,run(packages/mocactl/src/cli.ts).runstreams/v1/turn(src/api/harness.ts:40-48), and/turnaborts on disconnect (packages/knative-server/src/server.ts:293-302). - State dir:
$XDG_STATE_HOME/mocactl(packages/mocactl/src/config.ts:24). - Status read:
/runs/status?sessionId=requires a session token (MI1 R7).- It returns
queuedwhen there's no record (server.ts:678-680), thenresponded,done,solved,pausedorfailed. solvedcarries the whole patch inline (:688-690).- Records last 24 h, one per session, and a later turn overwrites it.
- Gate resume: resend the envelope with an inline
decision: {gateId, action, feedback}(ADR-0020,harness/src/run-leaf.ts:104). - P6 admission ignores
/runs(packages/knative-server/src/worker.ts:117), and the pool cap is 4 on the VM (deploy/vm/env/supervisor.env.example:22); ondeploy/k8sit's the sandbox count (SH_SANDBOX_COUNT, default 2).
Scope
mocactl spawn "prompt" [--bundle sha256:…] [--kind prompt|converge] [--repo URL --ref REF] [--tag T] [--json]- Creates the session and mints the token.
- Writes a ledger record.
- Forks a detached child (
setsid) that holds the sync/runsand records the HTTP outcome. - Prints
{sessionId}straight away.
- Ledger at
$XDG_STATE_HOME/mocactl/subagents.jsonl, mode 0600.- Fields:
sessionId,tag,kind, the full envelope (needed to resume a gate),bundle,repo/ref,submittedAt, child pid, last known state. - The ledger is the caller-side batch record (Ambiguity between "run" and "session" — clarify or eliminate the term #279).
- Fields:
mocactl subagents [--tag T] [--json]: the ledger joined with/runs/status, minting a session token per session.mocactl get <sessionId> [--out DIR]: writes the text, verdict or patch to files and prints a bounded summary (the first N lines plus sizes).mocactl watch [--tag T] [--json]: one line per state change, exiting when every watched subagent is terminal. It's designed for a coding agent's background monitor (Claude Code's Monitor tool), where each stdout line becomes an event.mocactl approve|reject <sessionId> [--feedback …]: resends the stored envelope with the decision.mocactl follow-up <sessionId> "prompt": copies the current result out first (it would be overwritten), then sends a new prompt turn on the same session (create-or-resume, ADR-0028).- Client-side concurrency cap, defaulting to 4, with a flag to change it.
- Honest states:
- no record and the child is alive →
running; - no record, the child is gone, and past a grace period →
unknown, neverqueued.
- no record and the child is alive →
- Transport seam: one client module owns "submit a leaf turn", "read state" and "watch", and names the bundle in one place. S3 moves
configRefto session creation, and async turns replace sync/runs.
Acceptance
- Unit tests against a fake control plane and harness, covering ledger round-trips, state mapping, and the concurrency cap.
- A live smoke on the VM, and once on the Epic: P6 on Kubernetes — process manager, relay, Redis and control plane as K8s workloads; only P4 on a VM/bare metal #426 K8s stack (Kind is enough): spawn 3, kill the local children, and
watchreports all 3 as terminal with their results. The commands are substrate-neutral; the smoke proves the control-plane URL and port-forward/Route addressing work end to end. --jsonoutput is stable and documented inpackages/mocactl/README.md.
Out of scope
- The MCP server (Coding-agent subagents B11: coding-agent integration v1 (MCP server; Claude Code plugin first — hook, statusline, drift warning) #396), server-side events (Coding-agent subagents B6: owner-scoped event stream of session and turn state #392), cancel (Coding-agent subagents B13: budgets, per-subject quotas and cancel #391).
References
- ADR-0020, ADR-0028, ADR-0036 (the mocactl HTTP client)
- MI1 R7, Ambiguity between "run" and "session" — clarify or eliminate the term #279
Working conventions (for a fresh session)
- Workspace:
git fetch, then create a worktree fromrossoctl/main(never localmain), under.worktrees/. Populate and buildpi-fork(git submodule update --init --recursive && cd pi-fork && npm ci && npm run build), thenpnpm install. A worktree without the pi-fork build does not typecheck. - Plans: write the plan with
superpowers:writing-plansintodocs/plans/<date>-<slug>.md. Plans are gitignored and never committed. Write it in chunks, one append per task. - Pre-flight table: list every process entrypoint, systemd unit, env example and shell/Go launcher whose boot contract changes, not only TypeScript call sites.
- Tests: Redis on 6379 must be up. Use each package's own
node_modules/.bin/vitest. vitest can exit non-zero with every test green, so grep the log forErrors. Redirect long output to/tmp/kagenti/....make lintskips untracked files. - Commits:
git commit -swithAssisted-By: Claude (Anthropic AI) <[email protected]>, neverCo-Authored-By. - Shared KVM rig: alert the owner before using it, record a manifest of what you install, and verify cleanup.
- Don't push or open PRs without the owner's go-ahead.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or request
Activity
[-]Claude Code subagents A2: mocactl subagent commands (spawn, subagents, get, watch, approve, follow-up) over today's API[/-][+]Coding-agent subagents A2: mocactl subagent commands (spawn, subagents, get, watch, approve, follow-up) over today's API[/+]pdettori commentedon Oct 13, 2026
Status (2026-10-13). Partly done.
spawn,subagentsandget, with a local ledger and a leaf-turn transport module that keepsPOST /runsandGET /runs/statusin one place.watch,approve/reject,follow-up, a configurable concurrency cap and the async-turn backend (the feat: mocactl subagent commands - spawn, subagents, get #496 spec lists these as not included).mocactl spawn --workload <id>andmocactl workloads …. Its answer decides the shape of the remaining commands, so settle it before starting them.evaline-ju commentedon Oct 26, 2026
End-to-end testing a chained diagnose→fix subagent flow on latest
mainsurfaced a case that doesn't quite fitwatch's batch shape in item 5. Flagging in case it changes the design.Context. A local coding agent dispatches a subagent to MOCA, immediately ends its turn after
mocactl spawnreturns (so the parent can disconnect), then — in a later operator turn — collects the result and inlines it into the nextspawn's prompt. The collect turn needs the result inline so the chained dispatch can run in the same turn.Today (upstream
main):Observed on Claude Code 2.1.263 and OpenCode 1.19.4. The agent is forced into either a second "check again" turn or a hand-rolled polling loop.
watch [--tag T]is batch-shaped (one line per state change, terminal when all are done) — the collect-and-block case wants the opposite: one session, one blocking call, result on stdout.Question: fold into
watch, e.g.mocactl watch <sessionId> [--timeout D]? Or sibling flag onget, e.g.mocactl get <sessionId> --wait [--timeout D]?feat(mocactl): get --wait and spawn --max-concurrent (#381)
Merge pull request #918 from cwiklik/feat/381-get-wait-and-cap
fix(mocactl): have `get` record the terminal state it read on an asyn…
feat(mocactl): spawn --async, a subagent backed by a turn record
Merge pull request #922 from cwiklik/feat/381-spawn-async
fix(mocactl): watch exits 130 on a Ctrl-C mid-sweep, and drop a stray…
feat(mocactl): add `watch` to stream subagent state changes
feat(mocactl): approve and reject a subagent's gate (#381)
Merge pull request #1010 from cwiklik/feat/381-approve-reject
fix(mocactl): follow-up survives a crashed sync worker and keeps its …
feat(mocactl): follow-up sends a second turn on a subagent's session