claw-code/rust/crates
YeonGyu-Kim 9362900b1b feat: #77 Phase 1 — machine-readable error classification in JSON error payloads
## Problem

All JSON error payloads had the same three-field envelope:
```json
{"type": "error", "error": "<prose with hint baked in>"}
```

Five distinct error classes were indistinguishable at the schema level:
- missing_credentials (no API key)
- missing_worker_state (no state file)
- session_not_found / session_load_failed
- cli_parse (unrecognized args)
- invalid_model_syntax

Downstream claws had to regex-scrape the prose to route failures.

## Fix

1. **Added `classify_error_kind()`** — prefix/keyword classifier that returns a
   snake_case discriminant token for 12 known error classes:
   `missing_credentials`, `missing_manifests`, `missing_worker_state`,
   `session_not_found`, `session_load_failed`, `no_managed_sessions`,
   `cli_parse`, `invalid_model_syntax`, `unsupported_command`,
   `unsupported_resumed_command`, `confirmation_required`, `api_http_error`,
   plus `unknown` fallback.

2. **Added `split_error_hint()`** — splits multi-line error messages into
   (short_reason, optional_hint) so the runbook prose stops being stuffed
   into the `error` field.

3. **Extended JSON envelope** at 4 emit sites:
   - Main error sink (line ~213)
   - Session load failure in resume_session
   - Stub command (unsupported_command)
   - Unknown resumed command (unsupported_resumed_command)

## New JSON shape

```json
{
  "type": "error",
  "error": "short reason (first line)",
  "kind": "missing_credentials",
  "hint": "Hint: export ANTHROPIC_API_KEY..."
}
```

`kind` is always present. `hint` is null when no runbook follows.
`error` now carries only the short reason, not the full multi-line prose.

## Tests

Added 2 new regression tests:
- `classify_error_kind_returns_correct_discriminants` — all 9 known classes + fallback
- `split_error_hint_separates_reason_from_runbook` — with and without hints

All 179 rusty-claude-cli tests pass. Full workspace green.

Closes ROADMAP #77 Phase 1.
2026-04-21 22:38:13 +09:00
..
api US-024: Add token limit metadata for kimi models 2026-04-17 04:15:38 +00:00
commands feat: #144 phase 1 + ROADMAP filing — claw mcp degrades gracefully on malformed config 2026-04-21 19:07:17 +09:00
compat-harness feat: ultraclaw droid batch — ROADMAP #41 test isolation + #50 PowerShell permissions 2026-04-12 03:06:24 +09:00
mock-anthropic-service feat(harness+usage): add auto_compact and token_cost parity scenarios 2026-04-03 22:41:42 +09:00
plugins Keep poisoned test locks from cascading across unrelated regressions 2026-04-12 13:52:41 +00:00
runtime fix: #80 — session-lookup error messages now show actual workspace-fingerprint directory 2026-04-21 22:18:12 +09:00
rusty-claude-cli feat: #77 Phase 1 — machine-readable error classification in JSON error payloads 2026-04-21 22:38:13 +09:00
telemetry feat: anthropic SDK header matching + request profile 2026-04-01 05:55:25 +00:00
tools ROADMAP #133: Blocked-state subphase contract — implement §6.5 2026-04-20 15:04:08 +09:00