Expand description
AgentSession — the coding-agent product layer over the harness.
Mirrors the role of packages/coding-agent/src/core/agent-session.ts: one
object the CLI/TUI holds that unifies prompt/continue, queueing,
model/thinking mutation, scoped models, compaction + retry, export,
session switching / fork, usage + context stats, and name/label facts.
Design notes (deliberate, vs the TS original):
- Composition, not inheritance. TS
AgentSessionis the harness plus a pile of product concerns. HereAgentSessionowns anAgentHarnessand adds the product surface; the harness stays usable on its own for SDK consumers who do not want the product layer. This keeps therpi-harnesscrate free of CLI concerns (provider catalogs, settings paths, export formats). - Sync-friendly handles. The TUI key loop is a blocking thread, so the
mutating surface that the loop touches (
set_thinking_level,scoped_models) works off cached state or spawns onto the runtime; the async surface (prompt,compact,export) isasync fn. - Retry/compaction policy lives in the harness. The session exposes
retry()/compact()as intent, and the harness applies its ownRetryPolicy/CompactionSettings. TS keeps the auto-retry driver in the session; we keep it in the harness so non-CLI callers get it for free.
Structs§
- Agent
Session - The product-level session. Cheap to clone — the harness is behind an
Arc. - Scoped
Model - One scoped-model entry: the routing id plus its human label.
- Session
Descriptor - Where a session content lives — used by export naming and
--continue. - Session
Usage Stats - A snapshot of usage + context pressure for the footer/status line.
Functions§
- assistant_
text - The finalized text of an assistant message (text blocks only), joined with blank lines. Mirrors the TS print-mode/export concat.
- outcome_
is_ completed - Whether a run outcome is terminal (i.e. produced a final assistant message).