Skip to content

CLI contract on Effect cli: exit codes, --json, signals #60

Closed

Description

@allisonmahmood

Part of #54

Question

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.

Activity

  1. added
    wayfinder:grilling
    on Aug 28, 2026
  2. allisonmahmood commented on Aug 28, 2026

    @allisonmahmood
    OwnerAuthor

    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.

  3. allisonmahmood commented on Aug 28, 2026

    @allisonmahmood
    OwnerAuthor

    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 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
    2 rejected the instance answered and said no 401/403, 404 draft, 409, 413, 429, server-side 400
    3 unreachable no usable answer from the instance DNS/connect/timeout, 5xx, unparseable body
    130 interrupted SIGINT/SIGTERM → fiber interruption (Effect default)

    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, … }).
    • Success: stdout is exactly one JSON document in the wire shape from feat: --json on every command with shared Effect Schema wire types and docs/API.md #35; stderr is empty (upload warnings go in warnings: [], not stderr).
    • 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).

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

Metadata

Metadata

Labels

wayfinder:grilling

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions