zagens_core/engine/turn_loop/host.rs
1//! v3 turn-loop host adapter (Phase 3b batch 5 closure).
2
3use super::inner_step_host::InnerStepHost;
4use super::turn_loop_outer_host::TurnLoopOuterHost;
5
6/// The resolved output of `ContextCompiler` for one request.
7///
8/// Built once per request step in V2 mode; the turn loop consumes both fields
9/// so a single snapshot drive both system-prompt assembly and message injection.
10#[derive(Debug, Clone, Default)]
11pub struct CompilerRequestContext {
12 /// Compiler-assembled system prompt (replaces `session.system_prompt` in V2).
13 ///
14 /// `None` → fall back to the legacy `session.system_prompt`.
15 pub system_prompt: Option<crate::chat::SystemPrompt>,
16
17 /// Inner text for the `<turn_meta>` block in messages (without the XML wrapper).
18 ///
19 /// When `Some`, `messages_with_turn_metadata` uses this instead of computing
20 /// from `session.working_set` directly. `None` → legacy path.
21 pub turn_meta_text: Option<String>,
22}
23
24/// Config slices the turn loop reads each step (avoids pulling full `EngineConfig` into core yet).
25#[derive(Debug, Clone, Copy)]
26pub struct TurnLoopConfigView<'a> {
27 pub compaction: &'a crate::compaction::CompactionConfig,
28 pub strict_tool_mode: bool,
29 pub scratchpad: &'a crate::scratchpad::ScratchpadConfig,
30 pub workspace: &'a std::path::Path,
31}
32
33/// Opaque tool-registry type (TUI: `crate::tools::ToolRegistry`).
34pub trait TurnLoopToolRegistry: Send + Sync {}
35
36/// Deprecated alias for [`McpHost`](crate::engine::hosts::McpHost).
37///
38/// M4 (Engine-struct strangler) renamed this empty marker into the
39/// named [`McpHost`] trait with default-impl predicate / metadata
40/// methods. The blanket impl below keeps existing `impl
41/// TurnLoopMcpPool for McpPool` consumers compiling for one release;
42/// new code should impl `McpHost` directly. The alias and blanket
43/// impl will be removed in the next release.
44#[deprecated(
45 since = "0.8.16",
46 note = "use `zagens_core::engine::hosts::McpHost` instead; \
47 this alias will be removed in the next release"
48)]
49pub trait TurnLoopMcpPool: Send + Sync {}
50
51#[allow(deprecated)]
52impl<T: crate::engine::hosts::McpHost + ?Sized> TurnLoopMcpPool for T {}
53
54/// Canonical v3 turn-loop host: [`InnerStepHost`] + [`TurnLoopOuterHost`] + kernel seam.
55///
56/// `handle_deepseek_turn` and `EffectInterpreter` bound on this trait after batch 5 closure.
57pub trait V3TurnHost: InnerStepHost + TurnLoopOuterHost + Send {}
58
59impl<T: InnerStepHost + TurnLoopOuterHost + Send> V3TurnHost for T {}
60
61#[cfg(test)]
62mod tests {
63 use super::V3TurnHost;
64
65 #[test]
66 fn v3_turn_host_surface_partition_baselines_sum() {
67 // Session (16) + inner step (26) + outer (18) = documented host surface.
68 assert_eq!(16 + 26 + 18, 60);
69 }
70
71 /// Document that the composed host still satisfies the outer-loop seam.
72 fn _v3_turn_host_is_outer_loop_host<H: V3TurnHost>() {}
73}