Expand description
Core engine (issue #5261).
Move, don’t rewrite: the turn loop, session, thread manager, the TUI’s
run_event_loop, and the chat client’s request-building are all destined
for this crate. Only request-building and fragments have moved so far.
The turn loop still lives in crates/tui/src/core/engine/turn_loop.rs and
is what every interactive and headless turn runs today; this module is the
boundary that move lands against, not the current owner of turn execution.
The TUI crate depends on core, not the reverse.
Approved crates that the engine needs are already in crates/core’s
Cargo.toml: config, execpolicy, protocol, state, tools, mcp,
hooks, agent. Things that stay in the TUI (ratatui, crossterm,
prompt_zones rendering) are not imported here; the engine is
terminal-free so it can start a session with no TUI attached.
This module is intentionally small on this first cut: it formalizes the
ThreadId/SessionId boundary, the Op-in / EventMsg-out channels in
crates/protocol, the Journal leaf, and the Thread-owned headless
spawn that TUI and codewhale exec both go through. The full turn
loop, guards (StuckGuard, ReadRepeatGuard, ToolCallBudget), stream
retry budget, and the four-way RuntimeThreadManager split live in the
thread/ submodules so follow-ons (#5262, #5263, #5264) have a place to
land without another boundary move.
Back-compat: persisted state.json / threads shape is unchanged.
Modules§
- thread
RuntimeThreadManagersplit per #3313 (issue #5261).
Structs§
- Engine
- Engine
Config - Engine
Handle - Handle to communicate with the core engine via the
Op-in /EventMsg-out channels. The TUI’sEngineHandleand the headlessexecboth hold this type;handle.steer,cancel,approve_tool_calletc are the same code path in both modes socrates/execpolicystays the authority identically.
Enums§
- Cancel
Reason - Reason the active turn was cancelled.
Functions§
- spawn_
engine - Spawn the engine in a background task (mirrors
spawn_enginein the oldcrates/tui/src/core/engine.rs). Returns the handle that TUI, CLI exec, app-server, and tests all share — oneOp-in /EventMsg-out API. - spawn_
headless_ thread - Start a headless session and expose its shared operation channel.
- spawn_
supervised - Spawn with supervision (mirrors
spawn_supervised).