From 401b56334658208329f9772dfe64a3db485d3c83 Mon Sep 17 00:00:00 2001 From: wangfeng Date: Mon, 4 May 2026 18:05:34 -0700 Subject: [PATCH] feat(engine): context-limit handoff thresholds (closes #664) --- crates/tui/src/compaction.rs | 5 +++++ crates/tui/src/handoff.rs | 8 ++++++++ crates/tui/src/main.rs | 1 + 3 files changed, 14 insertions(+) create mode 100644 crates/tui/src/handoff.rs diff --git a/crates/tui/src/compaction.rs b/crates/tui/src/compaction.rs index cda69077..5d6380a8 100644 --- a/crates/tui/src/compaction.rs +++ b/crates/tui/src/compaction.rs @@ -25,6 +25,10 @@ pub struct CompactionConfig { pub message_threshold: usize, pub model: String, pub cache_summary: bool, + /// When `Some(true)`, the engine prefers writing a handoff file over + /// running LLM-based compaction when context pressure triggers. + /// `None` / `Some(false)` means default compaction behaviour. + pub prefer_handoff: Option, } impl Default for CompactionConfig { @@ -40,6 +44,7 @@ impl Default for CompactionConfig { message_threshold: 50, model: DEFAULT_TEXT_MODEL.to_string(), cache_summary: true, + prefer_handoff: None, } } } diff --git a/crates/tui/src/handoff.rs b/crates/tui/src/handoff.rs new file mode 100644 index 00000000..8fcf9825 --- /dev/null +++ b/crates/tui/src/handoff.rs @@ -0,0 +1,8 @@ +pub const THRESHOLDS: [(f32, &str); 3] = [ + (0.9, "Context at 90%: stop and write handoff to .deepseek/handoff.md now"), + (0.8, "Context at 80%: draft handoff to .deepseek/handoff.md"), + (0.7, "Context at 70%: consider wrapping current sub-task"), +]; +pub fn threshold_message(ratio: f32) -> Option<&'static str> { + THRESHOLDS.iter().find(|(t,_)| ratio >= *t).map(|(_,m)| *m) +} diff --git a/crates/tui/src/main.rs b/crates/tui/src/main.rs index 40b664df..f1e8ce77 100644 --- a/crates/tui/src/main.rs +++ b/crates/tui/src/main.rs @@ -30,6 +30,7 @@ mod error_taxonomy; mod eval; mod execpolicy; mod features; +mod handoff; mod hooks; mod llm_client; mod localization;