# CLI-064 Tasks — Print-mode exit-code contract

Spec: `.agents/spec-docs/active/CLI-064-exit-code-contract.md`

- [x] T1 (TC-01): agent-core — `buildFinalResult` marks the result failed (`success: false`, typed `error`) when the final assistant message carries `providerError: true` metadata; history append-only preserved (exactly one `Request failed:` assistant message)
- [x] T2 (TC-02): agent-transport — headless runner surfaces provider failures: text format writes the error to stderr and exits 1; json/stream formats emit `subtype: "error"` + `error_code: "api_error"` (existing `onError` path, reached via agent-core's existing failed-result throw in `robotaRun`)
- [x] T3 (TC-03): agent-cli — print mode with no provider configuration → stderr guidance + exit 3 (`ProviderConfigError` mapping in `cli.ts` ensureConfig/provider-creation catch)
- [x] T4 (TC-04): agent-framework — `ProviderConfigError` exported; `readProviderSettings` throws it; agent-command `ensureProviderConfig` throws it (instanceof, no message matching)
- [x] T5 (TC-05): regression — TUI history rendering suites stay green (provider failure surfaces via the existing session `error` event/TUI error display)
- [x] T6 (TC-06): agent-cli SPEC — single exit-code table (0/1/3); error-handling table rows match real code paths; core/transport SPEC result-contract notes
- [x] T7: build/typecheck/lint/test green; PR to develop; backlog CLI-064 evidence recording

## Test Plan

Authoritative TC table lives in the spec document (`.agents/spec-docs/active/CLI-064-exit-code-contract.md` § Test Plan).
Summary: unit tests in agent-core (`buildFinalResult` provider-error marking, history append-only), integration tests in agent-transport (headless runner exit 1 + `subtype: error` + `error_code: api_error` with a 401-throwing stub provider, all output formats), unit tests in agent-framework (`ProviderConfigError` instanceof from `readProviderSettings`), integration test in agent-cli (print mode without provider config → exit 3), and regression runs of existing TUI/history suites. Verification: `pnpm --filter @robota-sdk/agent-core --filter @robota-sdk/agent-framework --filter @robota-sdk/agent-command --filter @robota-sdk/agent-transport --filter @robota-sdk/agent-cli test` plus workspace typecheck/lint.
