kcode-k1-chat-codex-state 0.7.6

Deterministic open-format Codex K1 conversation state
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
# Open-format Codex conversation state 0.7.6

`ConversationState` is the concrete owner of open-format Codex K1 chat state. It reexports `BoxValue`, `Call`, canonical box and call IDs, chat boxes, provider-generated values, and the standard type constants. Its Cargo requirements use Adapter 0.5.0, Codec 0.7.3, and State 0.9.0 as compatible lower bounds.

Construct with `new(session)` or `recover(session, boxes, force)`. `boxes` exposes canonical history and `status` reports running, quiet, or stalled state. On a fresh same-thread turn, `begin` submits only the external canonical delta not previously submitted, followed by a synthetic Agent Response header that is not persisted. Recovery and restart instead replay full canonical history once, then resume delta-only submission.

External input enters through triggering `accept`, triggering Tool Result v1 `accept_tool_return`, triggering metadata-bearing Tool Result v2 `accept_tool_return_v2`, or non-triggering correlated `accept_tool_message`. `mailbox_flush` appends and returns the canonical FIFO snapshot without creating a mailbox-flush token.

`prepare_stage` converts dedicated Agent Message and Tool Call values to canonical boxes in input order. A preserved malformed native action is recorded as an ordinary Tool Call using its attempted Ktool name when known, otherwise its native-tool name, and returns a `PreparedCall` with an immediate local-error disposition. The error exposes all validation details and complete attempted arguments. Its Tool Result v2 metadata has the stable `k1.malformed-native-call.v1` type and the codec diagnostic JSON contents. Ordinary calls retain the external disposition. After a successful stage append, canonical Tool Call boxes, including malformed native calls preserved as Tool Calls, enter the existing normal-context unsubmitted FIFO. Agent Response and Agent Message provider-stage boxes remain excluded. `prepare_mailbox_flush` returns an opaque, repeatable process-local token containing the pending external prefix plus a synthetic unpersisted Agent Response header; `validate_mailbox_flush` checks it, and `commit_mailbox_flush` consumes only that exact external prefix after successful submission without independently scheduling another inference. Provider-generated stage boxes other than queued Tool Calls are excluded from mailbox-flush input. Triggering arrivals included in a committed mailbox flush are covered by the continuing provider generation, while triggering arrivals accepted afterward schedule the next inference.

`complete` accepts terminal text only: the canonical terminal Agent Response is persisted but excluded from future same-thread input; trailing external arrivals remain pending. `fail` preserves a stalled round, and `restart` is allowed only for restartable pre-launch failures before any provider action.

`Start`, `PreparedCall`, `PreparedCallDisposition`, `ImmediateToolError`, `PreparedMailboxFlush::values`, `Status`, and `RestartError` describe launch, tool disposition, active-turn mailbox flush, and lifecycle results. This crate owns deterministic in-memory conversion, ordering, recovery, and state transitions. It does not own I/O, persistence, migration, HTTP, provider or daemon process management, scheduling, tool execution, deployment, or publication.