You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
CLI contract on Effect cli: exit codes, --json, signals #60
effect/unstable/cli owns argv, exit codes (0 / 130 on interrupt / 1 otherwise) and process lifecycle; today's CLI exits 128+n on signals, restores the terminal after the hidden-token prompt, and the packed-CLI e2e asserts process-group behaviour. Agents read exit codes. Decide the contract the ported CLI promises: exit codes per outcome (including --json error shapes), which signals do what, whether --json is a global flag on every command, how --api-url becomes a shared flag with .local/dev/env precedence (ADR), and what of the e2e's assertions is contract vs mechanism. Call grilling and domain-modeling (this is the Publishing context's language). HITL.
From the Effect 4 vertical slice (#55): Effect's CLI defaults are agent-hostile and the overrides are known — CliError.UserError for every actionable failure (one stderr line, exit 1, no stack), CliOutput.layer with a one-line formatError and bare formatVersion, CliConfig.layer({ builtIns: [Help, Version] }) to drop --wizard/--completions/--log-level. Copy packages/effect-slice/src/cli.ts on prototype/effect-slice; the e2e there asserts the contract. Still to decide here: exit codes beyond 1, --json via withGlobalFlags, signals, and the credential file.
The contract the ported CLI promises to whatever drives it — an agent first, a developer sometimes. Recorded as one ADR, CLI contract for agents, written by the cli port PR (it also carries the .local/dev/env precedence decided on #15).
Exit codes — a ladder keyed by who has to act
code
kind
meaning
examples
0
ok
1
local
fixable without touching the network
bad args, file missing, HTML fails validation, no token stored, malformed state dir
Nothing else. Chosen over Effect's 0/1/130 default because agents building patches need to know at a glance whether the mistake is theirs, the instance's policy, or the network. 5xx sits with unreachable: "retry later / tell the operator" is the same action.
In code: one CliError union, each tag carrying a kind; a single table maps kind → exit code. The prototype's src/cli.ts (prototype/effect-slice) is the starting point — CliError.UserError → one stderr line, no stack.
--json — a global flag on every command
GlobalFlag; every command honours it, including ones with little to say (auth set prints { ok: true, … }).
Failure: stderr gets { "ok": false, "error": "<the one-line message>", "kind": "local" | "rejected" | "unreachable" }, stdout empty, exit code derived from kind. Same shape as the server's 401 body pinned on Effect 4 vertical slice #55. No code field until an agent flow branches on one.
--api-url — a global flag feeding one Instance service
Resolution order is #15's: --api-url > .local/dev/env (walk up from cwd) > PATCHY_API_URL > ~/.patchy config > local default. The service exposes the resolved URL and its source; status --json and the mutating-command "target came from …" notice both read it. Kept even though a Patchy Cloud user is very unlikely to retarget.
Signals
Effect's mapping: SIGINT/SIGTERM interrupt the fiber, exit 130 for both. No 128+n. The hidden-token prompt's terminal restore becomes a scope finalizer (acquireRelease) so interruption restores the terminal by construction. The e2e's 130/143 signal probes test the harness's temp-root cleanup, not the CLI — they stay as harness tests and are not CLI contract.
Built-ins and defects
Effect's default built-ins stay: --help, --version (bare version string, as the e2e asserts), --completions, --wizard, --log-level. Humans are not the primary operator but developers do drive it; the conveniences stay as long as they never change what an agent sees.
Defects (bugs, unmodelled errors): one stderr line Unexpected error: <message>, exit 1, stack only at --log-level debug. No PATCHY_DEBUG.
Contract vs mechanism in the packed-CLI e2e
Contract (keep asserting): exit codes per the ladder, one-line stderr messages, bare --version, token never in argv/output, --json document shapes. Mechanism (harness-only or drop): the signal probes' 130/143, process-group behaviour, the readline/raw-mode listener choreography.
Glossary
packages/cli/CONTEXT.md's opening line now says agents are the primary operator and humans a real secondary one (uncommitted; rides with the cli port PR).
Activity
allisonmahmood commentedon Aug 28, 2026
From the Effect 4 vertical slice (#55): Effect's CLI defaults are agent-hostile and the overrides are known —
CliError.UserErrorfor every actionable failure (one stderr line, exit 1, no stack),CliOutput.layerwith a one-lineformatErrorand bareformatVersion,CliConfig.layer({ builtIns: [Help, Version] })to drop--wizard/--completions/--log-level. Copypackages/effect-slice/src/cli.tsonprototype/effect-slice; the e2e there asserts the contract. Still to decide here: exit codes beyond 1,--jsonviawithGlobalFlags, signals, and the credential file.allisonmahmood commentedon Aug 28, 2026
Resolution (grilled with Allison, 2026-08-28)
The contract the ported CLI promises to whatever drives it — an agent first, a developer sometimes. Recorded as one ADR, CLI contract for agents, written by the
cliport PR (it also carries the.local/dev/envprecedence decided on #15).Exit codes — a ladder keyed by who has to act
localrejectedunreachableNothing else. Chosen over Effect's 0/1/130 default because agents building patches need to know at a glance whether the mistake is theirs, the instance's policy, or the network. 5xx sits with unreachable: "retry later / tell the operator" is the same action.
In code: one
CliErrorunion, each tag carrying akind; a single table mapskind → exit code. The prototype'ssrc/cli.ts(prototype/effect-slice) is the starting point —CliError.UserError→ one stderr line, no stack.--json— a global flag on every commandGlobalFlag; every command honours it, including ones with little to say (auth setprints{ ok: true, … }).warnings: [], not stderr).{ "ok": false, "error": "<the one-line message>", "kind": "local" | "rejected" | "unreachable" }, stdout empty, exit code derived fromkind. Same shape as the server's 401 body pinned on Effect 4 vertical slice #55. Nocodefield until an agent flow branches on one.--api-url— a global flag feeding oneInstanceserviceResolution order is #15's:
--api-url>.local/dev/env(walk up from cwd) >PATCHY_API_URL>~/.patchyconfig > local default. The service exposes the resolved URL and its source;status --jsonand the mutating-command "target came from …" notice both read it. Kept even though a Patchy Cloud user is very unlikely to retarget.Signals
Effect's mapping: SIGINT/SIGTERM interrupt the fiber, exit 130 for both. No
128+n. The hidden-token prompt's terminal restore becomes a scope finalizer (acquireRelease) so interruption restores the terminal by construction. The e2e's 130/143 signal probes test the harness's temp-root cleanup, not the CLI — they stay as harness tests and are not CLI contract.Built-ins and defects
--help,--version(bare version string, as the e2e asserts),--completions,--wizard,--log-level. Humans are not the primary operator but developers do drive it; the conveniences stay as long as they never change what an agent sees.Unexpected error: <message>, exit 1, stack only at--log-level debug. NoPATCHY_DEBUG.Contract vs mechanism in the packed-CLI e2e
Contract (keep asserting): exit codes per the ladder, one-line stderr messages, bare
--version, token never in argv/output,--jsondocument shapes. Mechanism (harness-only or drop): the signal probes' 130/143, process-group behaviour, thereadline/raw-mode listener choreography.Glossary
packages/cli/CONTEXT.md's opening line now says agents are the primary operator and humans a real secondary one (uncommitted; rides with thecliport PR).