Skip to content

Coding-agent subagents A2: mocactl subagent commands (spawn, subagents, get, watch, approve, follow-up) over today's API #381

Open

Description

@pdettori

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). run streams /v1/turn (src/api/harness.ts:40-48), and /turn aborts 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 queued when there's no record (server.ts:678-680), then responded, done, solved, paused or failed.
    • solved carries 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); on deploy/k8s it's the sandbox count (SH_SANDBOX_COUNT, default 2).

Scope

  1. 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 /runs and records the HTTP outcome.
    • Prints {sessionId} straight away.
  2. Ledger at $XDG_STATE_HOME/mocactl/subagents.jsonl, mode 0600.
  3. mocactl subagents [--tag T] [--json]: the ledger joined with /runs/status, minting a session token per session.
  4. mocactl get <sessionId> [--out DIR]: writes the text, verdict or patch to files and prints a bounded summary (the first N lines plus sizes).
  5. 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.
  6. mocactl approve|reject <sessionId> [--feedback …]: resends the stored envelope with the decision.
  7. 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).
  8. Client-side concurrency cap, defaulting to 4, with a flag to change it.
  9. Honest states:
    • no record and the child is alive → running;
    • no record, the child is gone, and past a grace period → unknown, never queued.
  10. Transport seam: one client module owns "submit a leaf turn", "read state" and "watch", and names the bundle in one place. S3 moves configRef to session creation, and async turns replace sync /runs.

Acceptance

Out of scope

References

Working conventions (for a fresh session)

  • Workspace: git fetch, then create a worktree from rossoctl/main (never local main), under .worktrees/. Populate and build pi-fork (git submodule update --init --recursive && cd pi-fork && npm ci && npm run build), then pnpm install. A worktree without the pi-fork build does not typecheck.
  • Plans: write the plan with superpowers:writing-plans into docs/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 for Errors. Redirect long output to /tmp/kagenti/.... make lint skips untracked files.
  • Commits: git commit -s with Assisted-By: Claude (Anthropic AI) <[email protected]>, never Co-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.

Activity

  1. added
    enhancement
    on Sep 30, 2026
  2. changed the title [-]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[/+] on Oct 13, 2026
  3. pdettori commented on Oct 13, 2026

    @pdettori
    MemberAuthor

    Status (2026-10-13). Partly done.

  4. evaline-ju commented on Oct 26, 2026

    @evaline-ju
    Contributor

    End-to-end testing a chained diagnose→fix subagent flow on latest main surfaced a case that doesn't quite fit watch'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 spawn returns (so the parent can disconnect), then — in a later operator turn — collects the result and inlines it into the next spawn's prompt. The collect turn needs the result inline so the chained dispatch can run in the same turn.

    Today (upstream main):

    $ mocactl get adfbb437-a5dd-404b-9b02-3aa762b862b0
    session 'adfbb437-a5dd-404b-9b02-3aa762b862b0' has not finished yet
    $ echo $?
    1
    

    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 on get, e.g. mocactl get <sessionId> --wait [--timeout D]?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions