docs: USAGE.md — clarify JSON v1.0 envelope shape + migration notice for #164

The JSON output section was misleading — it claimed the binary emits
exit_code, command, timestamp, output_format, schema_version, and nested
error objects. The binary actually emits v1.0 flat shape (kind at top-level,
error as string, no common metadata fields).

Updated section:
- Documents actual v1.0 success and error envelope shapes
- Lists known issues (missing fields, overloaded kind, flat error)
- Shows how to dispatch on v1.0 (check type=='error' before reading kind)
- Warns users NOT to rely on kind alone
- Links to FIX_LOCUS_164.md for migration plan
- Explains Phase 1/2/3 timeline for v2.0 adoption

This is a doc-only fix that makes USAGE.md truthful about the current behavior
while preparing users for the coming schema migration.
This commit is contained in:
YeonGyu-Kim 2026-04-23 04:52:17 +09:00
parent afc792f1a5
commit 98c675b33b

View File

@ -98,7 +98,57 @@ cd rust
### JSON output for scripting
All clawable commands support `--output-format json` for machine-readable output. Every invocation returns a consistent JSON envelope with `exit_code`, `command`, `timestamp`, and either `{success fields}` or `{error: {kind, message, ...}}`.
All clawable commands support `--output-format json` for machine-readable output.
**IMPORTANT SCHEMA VERSION NOTICE:**
The JSON envelope is currently in **v1.0 (flat shape)** and is scheduled to migrate to **v2.0 (nested schema)** in a future release. See [`FIX_LOCUS_164.md`](./FIX_LOCUS_164.md) for the full migration plan.
#### Current (v1.0) envelope shape
**Success envelope** — verb-specific fields + `kind: "<verb-name>"`:
```json
{
"kind": "doctor",
"checks": [...],
"summary": {...},
"has_failures": false,
"report": "...",
"message": "..."
}
```
**Error envelope** — flat error fields at top level:
```json
{
"error": "unrecognized argument `foo`",
"hint": "Run `claw --help` for usage.",
"kind": "cli_parse",
"type": "error"
}
```
**Known issues with v1.0:**
- Missing `exit_code`, `command`, `timestamp`, `output_format`, `schema_version` fields
- `error` is a string, not a structured object with operation/target/retryable/message/hint
- `kind` field is semantically overloaded (verb identity in success, error classification in error)
- See [`SCHEMAS.md`](./SCHEMAS.md) for documented (v2.0 target) schema and [`FIX_LOCUS_164.md`](./FIX_LOCUS_164.md) for migration details
#### Using v1.0 envelopes in your code
**Success path:** Check for absence of `type: "error"`, then access verb-specific fields:
```bash
cd rust
./target/debug/claw doctor --output-format json | jq '.kind, .has_failures'
```
**Error path:** Check for `type == "error"`, then access `error` (string) and `kind` (error classification):
```bash
cd rust
./target/debug/claw doctor invalid-arg --output-format json | jq '.error, .kind'
```
**Do NOT rely on `kind` alone for dispatching** — it has different meanings in success vs. error. Always check `type == "error"` first.
```bash
cd rust
@ -109,6 +159,8 @@ cd rust
**Building a dispatcher or orchestration script?** See [`ERROR_HANDLING.md`](./ERROR_HANDLING.md) for the unified error-handling pattern. One code example works for all 14 clawable commands: parse the exit code, classify by `error.kind`, apply recovery strategies (retry, timeout recovery, validation, logging). Use that pattern instead of reimplementing error handling per command.
**Migrating to v2.0?** Check back after [`FIX_LOCUS_164`](./FIX_LOCUS_164.md) is implemented. Phase 1 will add a `--envelope-version=2.0` flag for opt-in access to the structured envelope schema. Phase 2 will make v2.0 the default. Phase 3 will deprecate v1.0.
### Inspect worker state
The `claw state` command reads `.claw/worker-state.json`, which is written by the interactive REPL or a one-shot prompt when a worker executes a task. This file contains the worker ID, session reference, model, and permission mode.