3.9 KiB
3.9 KiB
description, globs, trigger
| description | globs | trigger |
|---|---|---|
| CLI stdout/stderr stream contract, exit codes, SWR caching, and preview safety for seal-use commands | src/cli/**/*.ts | manual |
CLI Stream, Performance & Exit Code Protocol
When developing or refactoring CLI commands under src/cli/:
1. Dual Stream Protocol (stdout vs stderr)
- Machine Channel (
stdout):- Data commands MUST output pure, parseable JSON on
stdout. - NEVER output human text, logs, spinners, progress banners, or update notices to
stdout. The Agent Harness parsesstdoutdirectly into typed payloads. - Documented exceptions:
seal-use --help/seal-use help <area>(src/cli/printer.ts) andseal-use doctor guide(src/cli/commands/doctor.ts) intentionally output Markdown documents onstdoutbecause their output is the requested document payload. Never add new stdout-prose commands outside this list.
- Data commands MUST output pure, parseable JSON on
- Diagnostics & Guidance Channel (
stderr):- Use
stderrfor runtime logs, network probing status, self-healing notifications, and human tips. - Explicit Next-Step Command Suggestions MUST follow the format:
👉 Next action: seal-use <command>
- Use
2. Performance Contract & SWR Architecture
- Sub-10ms Local Execution:
- Read-only discovery commands (e.g.
seal-use version,seal-use doctor paths,seal-use corps list) MUST return instantaneously (<10ms). - Never trigger synchronous external HTTP requests during routine discovery or inspection invocations.
- Read-only discovery commands (e.g.
- Stale-While-Revalidate (SWR) Pattern:
- Synchronously read local cache from
~/.config/seal-use/*.json(<0.2ms). - Return the local cached state immediately on
stdout. - If cache is missing or older than TTL (e.g. 24 hours), trigger a background refresh:
const child = spawn(launcher.command, [...launcher.args, "subcommand", "--bg-save"], { detached: true, stdio: "ignore" }); child.unref(); // Detach completely so parent exits immediately - Always respect test/CI guards (
SEAL_DISABLE_BG_UPDATE=1,NODE_ENV=test,CI=true) to keep automated test suites deterministic.
- Synchronously read local cache from
3. High-Risk Mutation & Preview Contract (--dry-run)
- All potentially destructive or state-mutating commands (e.g.
rules push,rules clear,corps sync-test,preference update,webhook add/update/delete) MUST support--dry-run. - Preview Output:
- When
--dry-runis present, the command performs read-only discovery, simulates the mutation, and returns structured JSON with:{ "preview": true, "targetUrl": "...", "changesDiff": { "before": "...", "after": "..." }, "impactCount": 5 } - Live execution requires explicit
--yesor--confirm. If neither is provided on a live mutation, block execution with exit code10.
- When
4. Semantic Exit Codes
| Exit Code | Meaning | Example Scenario |
|---|---|---|
0 |
Success | Successful query, preview, or completed mutation |
1 |
Domain / Upstream Failure | Upstream HTTP 500, business logic rejection, quota insufficient |
2 |
Usage / Syntax Error | Unknown subcommand, invalid JSON payload, invalid argument format |
10 |
Confirmation Required | Mutating command invoked without --confirm or --yes |
Rule: Never call process.exit() deep in domain functions. Throw structured errors and let src/cli/runner.ts handle error classification, stream routing, and exit code assignment.
5. Argument Parsing Conventions
- Use helpers from
src/cli/parser.ts:booleanOption(args.options.flag)stringOption(args.options.param)numberOption(args.options.limit)
- Support kebab-case and camelCase options gracefully.
- Positional arguments should fall back to option flags when natural (e.g.
corps get <corpId>andcorps get --corp <corpId>).