Skip to main content

Module engine

Module engine 

Source
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 have been moved here from crates/tui/src/core/engine into crates/core. This file is the new owner. 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
RuntimeThreadManager split per #3313 (issue #5261).

Structs§

Engine
EngineConfig
EngineHandle
Handle to communicate with the core engine via the Op-in / EventMsg-out channels. The TUI’s EngineHandle and the headless exec both hold this type; handle.steer, cancel, approve_tool_call etc are the same code path in both modes so crates/execpolicy stays the authority identically.

Enums§

CancelReason
Reason the active turn was cancelled.

Functions§

spawn_engine
Spawn the engine in a background task (mirrors spawn_engine in the old crates/tui/src/core/engine.rs). Returns the handle that TUI, CLI exec, app-server, and tests all share — one Op-in / EventMsg-out API.
spawn_headless_thread
Start a headless session and send one message through it. Returns the handle so the caller can observe EventMsgs. This is the API the issue requires: “a session can start and run a turn with no TUI attached”.
spawn_supervised
Spawn with supervision (mirrors spawn_supervised).