Repository navigation
docs: mocactl, HTTP API and leaf references, first-run guide (PR 5b of REORG-PLAN) - #497
Conversation
- reference/cli-mocactl.md: commands, flags, exit codes, endpoints, config and key bindings, from packages/mocactl and its --help output. - reference/http-api.md: how the control plane and data plane fit together, data-plane auth, /v1/turn (sync, SSE, attach, cancel), /v1/runs and the error mapping. - reference/leaf-and-envelope.md: the inline leaf envelope and result that replaced the volume envelope, idempotency and the human-gate flow. - get-started/first-run.md: send a turn, resume by sessionId and stream on the Compose trial path. - Fix the human-gate wording (status is 'paused'; no awaiting_approval status in the code) in the glossary and README. - Link the pages from docs/index.md, get-started and the README; update REORG-PLAN (PR 5b). Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Summary
I checked the new reference pages against the code on main (5f1fec8; the PR adds only docs on top of it). Most of the page content holds: routes, auth codes, SSE frames, detach/attach, the LeafResult union, the gate flow, mocactl's flags, exit codes, doctor checks, keybindings and paths. One thing needs to change before merge. configRef on /v1/runs is described as if it behaved like /turn, but /runs ignores the session's bound bundle and the verdict leaf ignores configRef entirely. An integrator following the page would run leaves without their skills, and nothing would tell them. Everything else is suggestions and nits.
The prompt-leaf session-id question from the PR body has an answer: the turn gets the raw env.sessionId, and the lease, promoted config and result record get the sanitized one (inline comment).
Author: pdettori (MEMBER — maintainer)
Areas reviewed: Docs (reference pages, first-run guide, index/README/glossary link and wording changes)
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: passing (all 14 checks, incl. docs and lint)
Not covered: the first-run commands weren't executed. As the page says, they're untested.
|
|
||
| `item` is `{item_id: string, file: string, pattern: string, require_approval?: boolean}`. | ||
|
|
||
| Optional fields on any envelope: `decision`, `model`, `provider`, `workspaceRef`, `repoUrl`, `ref`, |
There was a problem hiding this comment.
must-fix: configRef is not honoured on "any envelope", and /runs never inherits the session's bound bundle.
runLeafreadsenv.configRefonly for prompt (harness/src/run-leaf.ts:442) and solve (run-leaf.ts:565) leaves. The verdict leaf never reads it, so a verdict envelope withconfigRefsilently runs without the bundle's skills.handleRunLeafParsedcallsrunLeaf(body, buildConfig(auth)), andbuildConfig(packages/knative-server/src/server.ts:81-103) dropsauth.configRef. Only the/turnpaths passconfigRef: auth.configRef(server.ts:293,475,600). So an authenticated/runsgets a bundle only if the envelope names one.
Please say: configRef applies to prompt and solve leaves only, it must be in the envelope, and the session's bound bundle is not used on /runs.
| - A token for one session cannot drive another: a `sessionId` in the body that differs from the | ||
| token's session gives 400 `session_mismatch`; an `X-SH-Subject` that differs from the token's | ||
| subject gives 400 `subject_conflict`. | ||
| - For authenticated turns the harness exchanges the token with the control plane for the user's |
There was a problem hiding this comment.
must-fix (same root cause as the leaf-envelope comment): "These always come from the control plane, never from the request" holds for /turn only. On /v1/runs, buildConfig(auth) (packages/knative-server/src/server.ts:81-103) drops auth.configRef, and the leaf takes its bundle from the envelope's configRef (harness/src/run-leaf.ts:442,565). Please scope this sentence to turns and point /runs readers to the leaf page.
| - The [human-gate design](../specs/2026-06-28-human-gate-design.md) still describes the file-based | ||
| design (`decisionRef`, `gateRef`, an `awaiting_approval` marker). This page follows the code. | ||
| - The P1 spec lists failure reasons without `saturated`, and statuses without `solved` and `responded`. | ||
| - Which session id a prompt leaf passes to its turn (the raw or the sanitized one) should be checked |
There was a problem hiding this comment.
suggestion: this open question can be answered, so the reference doesn't need to send readers to the source. In a prompt leaf, the turn gets the raw env.sessionId (harness/src/run-leaf.ts:459-461, which opens or creates the Pi session under that id with no tenant prefix and no sanitising). The sandbox lease (run-leaf.ts:389), attachPromotedConfig (:446) and the result record (server.ts:894) all use the sanitized leafSessionId. Verdict and solve leaves use the sanitized id throughout. Either document this as is, or fix the code in a follow-up and link the issue.
|
|
||
| A `failed` result is returned as HTTP 200 on the sync path, not as a 4xx or 5xx, except `saturated`, | ||
| which becomes 503 with `Retry-After`. Every non-saturated outcome is stored at `leaf:result:<id>` with | ||
| a TTL of `LEAF_RESULT_TTL_SECONDS` (default 86400) and is readable with `GET /runs/status?sessionId=`; |
There was a problem hiding this comment.
suggestion: GET /runs/status returns a reduced view, not the stored result (handleLeafStatus, packages/knative-server/src/server.ts:902-940):
failedhas nomessage. The sync write also stores none:toResultRecordkeeps nomessage(harness/src/leaf-result-store.ts:62).solvedandrespondeddropusage.pausedreturnsgateIdboth at top level and insidegate.- A missing record is
200 {status:"queued"}. - The lookup takes
tenantas a query parameter (server.ts:908).
The same applies to line 73's "readable from /runs/status".
| gate decision are **inline** in the request, the result is the **response body**, and a copy is stored | ||
| in Redis for polling. The harness does no filesystem I/O of its own. | ||
|
|
||
| An envelope with the old fields is rejected with 400 `envelope_invalid`. Some scripts under |
There was a problem hiding this comment.
suggestion: nothing checks for the old fields by name. isRunEnvelope (packages/knative-server/src/server.ts:777-799) only checks for a valid inline shape. A file-ref envelope gets 400 envelope_invalid because it has no item, problemStatement or prompt. An envelope with the old fields plus a valid item is accepted, and the old fields are ignored. Suggested wording: "an envelope without the inline fields (the old file-ref shape) is rejected…"
| | `4` | `auth token`: the control plane is unreachable | | ||
|
|
||
| Output convention: stdout carries only the result, and all messages go to stderr. Times in tables are | ||
| UTC. Not logged in prints `not logged in — run mocactl login first` and exits 2. |
There was a problem hiding this comment.
suggestion: this message is not uniform:
- The text has backticks:
not logged in — run `mocactl login` first(headless.ts:164). - A failed refresh prints a different message instead ("the login could not be refreshed — is the control plane reachable?…",
headless.ts:162-163). auth tokenprints…run `mocactl login`and exits 3 (headless.ts:85-86).logoutwhile not logged in exits 0 (headless.ts:104-106).promote --dry-runskips the check.
Consider "most commands" plus these exceptions.
| same global usage. `mocactl --version` prints a release tag, `edge-<sha>` or `dev`. | ||
|
|
||
| All flags are accepted by one parser. An unknown flag, or a missing flag value, prints the usage and | ||
| exits 2. A flag a command does not use is not always rejected; it may be ignored. |
There was a problem hiding this comment.
nit: some flags are always rejected outside their command, with exit 2 (packages/mocactl/src/cli.ts:129-143): --kind/--consumer/--host/--endpoint outside credentials add, --config outside run, and --all outside logout.
| - The prompt is the positionals joined with spaces. Exit 2 for an empty prompt, `--new` with | ||
| `--session`, `--config` with `--session` (a session's bundle is fixed at creation), a blank | ||
| `--config`, or an `--option` without `=`. | ||
| - `--option` keys: `inferenceCredential=NAME` and `sandboxTier=NAME`. A choice that is ambiguous or |
There was a problem hiding this comment.
nit:
- With several
sandboxTierchoices and none given,runleaves it unset for the server default rather than exiting (core/session-options.ts:138). - A field with no choices but a given value exits 2 with the empty-hint text (
:129-131). - Unknown
--optionkeys are silently ignored, and=x(no key) exits 2 (:188).
| | `basic` | `username=…` and `password=…`, one per line | | ||
|
|
||
| Consumers are `inference`, `sandbox-egress` and `control-plane`. `basic` is not for inference; use it | ||
| with `--consumer sandbox-egress`. Anthropic `sk-ant-oat…` OAuth tokens are rejected, as is an |
There was a problem hiding this comment.
nit:
- The
sk-ant-oat…andsk-ant-api…-under-bearer rejections apply only to--consumer inference(core/credential-checks.ts:121). - "Bearer kind" means
beareroroauth2-token(:22). - There's also a pre-stdin rejection of an
api.anthropic.comendpoint with a bearer kind (:41-42).
| | `2` | Wrong argument count; not logged in (not checked with `--dry-run`); preflight errors | | ||
| | `3` | A structural credential match; nothing was uploaded | | ||
|
|
||
| `--json` prints the whole result: `{digest, configRoot, skills, dropped, prompts, report, warnings, uploaded}`. |
There was a problem hiding this comment.
nit: a dry run's --json also includes dryRun: true (core/promote.ts:168,238).
- configRef on /v1/runs: prompt and solve leaves only, from the envelope; the session's bound bundle is not used; scope the 'always from the control plane' sentence to /turn. - Prompt-leaf session ids are inconsistent (raw for the turn, sanitized elsewhere): document it. - /runs/status returns a reduced view; old-field handling, configRef format checks, tenant_not_allowed and workloadId ordering clarified. - HTTP API: token TTL defaults and /workloads API tokens, URL matching, error body extras and passthrough codes, ended-turn attach semantics, extra control-plane codes, narrowed known gap. - mocactl: always-rejected flags, login message variants, --option edge cases, credential-check scope, dry-run JSON, exit 3/4 wording. - First run: the control-plane profile does not close anonymous /turn. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
|
Addressed in 834fa2b: |
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Thanks. I re-checked 834fa2b against main (5f1fec8). All 20 items from the 19f457f review are addressed and the new wording matches the code: configRef is scoped to prompt/solve leaves and read from the envelope, the /runs/status reduced view, tenant_not_allowed on both /runs and /runs/status, the passthrough codes, token TTL defaults, attach-at-tail on a running turn, the mocactl flag, login and exit-code exceptions, and the first-run note on SH_REQUIRE_AUTH. One nit, inline.
Author: pdettori (MEMBER — maintainer)
Areas reviewed: Docs (incremental 19f457f..834fa2b: http-api, leaf-and-envelope, cli-mocactl, first-run)
Agent/IDE config (.claude/.vscode): none
Commits: 2, all signed-off: yes
CI status: passing (all 14 checks)
FYI: #496 makes --config valid on mocactl spawn and adds spawn/subagents/get. Whichever PR lands second should update cli-mocactl.md ("--config outside run") to match.
| | `POST /run-leaf`, `GET /run-leaf/status` | session token | **Deprecated** aliases of `/runs` and `/runs/status`; log a warning once per process | | ||
|
|
||
| Matching is by URL and not uniform. `/health`, `/turn`, `/v1/turn` (POST), `/v1/turn/cancel`, `/runs`, | ||
| `/v1/runs` and `/run-leaf` match the exact URL, so a query string defeats them. `GET /v1/turn` requires |
There was a problem hiding this comment.
nit: "GET /v1/turn requires and accepts a query string": a bare GET /v1/turn also routes (server.ts:1079-1080, url === '/v1/turn' || url.startsWith('/v1/turn?')) and answers 400 sessionId_required, not the empty 404. Maybe: "GET /v1/turn matches with or without a query string (a missing sessionId is 400)". Separately, this paragraph's line 59 is much longer than the surrounding wrap width.
Summary
PR 5b of
docs/REORG-PLAN.md: the reference pages for the CLI, the HTTP API and the leaf contract, plus a first-run guide. Docs only. Based onmainafter #493.docs/reference/cli-mocactl.md: every command with flags, exit codes, endpoints,config.jsonkeys and key bindings, frompackages/mocactland the built binary's--help.docs/reference/http-api.md: how the control plane and data plane fit together, data-plane auth,/v1/turn(sync, SSE frames, detach/attach, cancel),/v1/runs, the error mapping, and the supervisor's 429 overload answer.docs/reference/leaf-and-envelope.md: the inline leaf envelope and result that replaced the volume envelope, idempotency bysessionId, and the human-gate flow (re-POST with an inlinedecision).docs/get-started/first-run.md: send a turn, resume bysessionId, stream, tear down, on the Compose trial path.paused;awaiting_approvalappears only in the older file-based design. Glossary and README corrected.docs/index.md, the get-started page and the README; the plan file records 5b.Not done
The plan also listed
install-cliandbackend-*entry pages. I dropped them:docs/get-started/index.mdalready covers the CLI install and the backend choice, and per-path pages would duplicate the deploy READMEs. Concepts (5c) and operations pages are still to come.Please check
sessionId; the lease, promoted config and result record use the sanitized one. Documented as is (review confirmed); a code fix would be a follow-up.docs/specs/2026-06-28-human-gate-design.mdstill describes the file-based gate with no superseded banner. The reference follows the code.3and4(andpromote's exit 1 for a missing.claudetree) are not in the README; the reference lists them. The overlay keys (Sessions, Credentials, Palette) are not covered.Verification
scripts/check-doc-links.pyreports 0 broken links over 165 files; Prettier run on changed files; the key error codes were spot-checked against the source.make lintnot run locally; CI will.Assisted-By: Claude (Anthropic AI) [email protected]