Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
fix(agent): seed the think-tag gate in session setup so headless runs strip reasoning
Akarshan Biswas17c251cae5bb
diff --git a/src-tauri/src/core/cli/mod.rs b/src-tauri/src/core/cli/mod.rsindex da94a68c7..e2bbe0358 100644--- a/src-tauri/src/core/cli/mod.rs+++ b/src-tauri/src/core/cli/mod.rs@@ -1819,6 +1819,17 @@ fn prepare_agent_session(let serving_provider =crate::core::cli::providers::provider_for_model(&model, &provider_configs);+ // The tag gate is process-wide and read by free rendering functions, and a+ // headless run strips reasoning through it too, so every surface seeds it+ // here. The TUI re-applies it when the serving provider changes.+ tui::set_think_tags_parsed(crate::core::agent::global_config::think_tags_enabled_for(+ serving_provider.as_deref(),+ serving_provider+ .as_deref()+ .and_then(|name| provider_configs.get(name))+ .and_then(|config| config.api_type.as_deref()),+ ));+// MCP servers marked `active` in mcp_config.json connect off-thread so setup/// render isn't blocked on a cold stdio spawn. The caller awaits `mcp_task`// before the first turn (tools are collected once per run), so a race withdiff --git a/src-tauri/src/core/cli/tui.rs b/src-tauri/src/core/cli/tui.rsindex 50f218451..c7de1d57b 100644--- a/src-tauri/src/core/cli/tui.rs+++ b/src-tauri/src/core/cli/tui.rs@@ -11072,9 +11072,10 @@ thread_local! {const { std::cell::Cell::new(Some(true)) };}-/// Apply the tag gate for the process. `App::sync_think_tags` calls it at-/// startup and whenever the serving provider can change.-fn set_think_tags_parsed(enabled: bool) {+/// Apply the tag gate for the process. Seeded by `prepare_agent_session` for+/// every surface; `App::sync_think_tags` re-applies it in the TUI whenever the+/// serving provider can change.+pub(crate) fn set_think_tags_parsed(enabled: bool) {PARSE_THINK_TAGS.store(enabled, std::sync::atomic::Ordering::Relaxed);}@@ -30142,6 +30143,44 @@ mod tests {});}+ /// A headless run (`jan cli agent run`, rpc, acp) never builds an `App`, yet+ /// its result strips reasoning through the same gate, so session setup has+ /// to seed it from the provider that serves the model.+ #[test]+ fn preparing_a_session_seeds_the_think_tag_gate_for_headless_runs() {+ crate::core::agent::global_config::with_temp_home(|_| {+ let set = |name: &str, model: &str| {+ crate::core::agent::global_config::set_provider(+ name,+ crate::core::agent::global_config::ProviderUpdate {+ base_url: Some("http://127.0.0.1:1/v1".into()),+ models: Some(vec![model.into()]),+ ..Default::default()+ },+ )+ .expect("seed provider");+ };+ set("mine", "local-reasoner");+ set("tokamak", "tk-1");+ let dir = tempfile::tempdir().unwrap();+ let prepare = |model: &str| {+ super::super::prepare_agent_session(+ dir.path().to_str().unwrap(),+ Some(model.to_string()),+ super::super::ProviderOverrides::default(),+ super::super::SessionFlags::default(),+ None,+ )+ .expect("session")+ };+ let gate = || super::PARSE_THINK_TAGS.load(std::sync::atomic::Ordering::Relaxed);+ prepare("local-reasoner");+ assert!(gate(), "custom provider parses tags");+ prepare("tk-1");+ assert!(!gate(), "tokamak sends reasoning separately");+ });+ }+/// A contended provider-config lock must not re-key the session's usage/// rows: without the last-known fallback the same model bills into a/// `(model, Some(provider))` row and a `(model, None)` one, and thediff --git a/src-tauri/src/core/cli/tui/find.rs b/src-tauri/src/core/cli/tui/find.rsindex cfa538e75..3292dd202 100644--- a/src-tauri/src/core/cli/tui/find.rs+++ b/src-tauri/src/core/cli/tui/find.rs@@ -106,13 +106,15 @@ fn current_style() -> Style {/// `line` with every occurrence of `needle` painted over its own style. Spans/// are split at match edges, so a match that straddles two styled spans is-/// still covered whole. A line without a match comes back unchanged.+/// still covered whole. A line without a match comes back unchanged. When+/// `current` is set the line is the jumped-to hit, and only its first match+/// gets the current style: hits are whole lines, so that is the one `n` landed+/// on, and the rest stay reversed.pub(super) fn highlight_line(line: Line<'static>, needle: &str, current: bool) -> Line<'static> {let ranges = match_ranges(&line_text(&line), needle);if ranges.is_empty() {return line;}- let paint = if current { current_style() } else { match_style() };let mut spans: Vec<Span<'static>> = Vec::with_capacity(line.spans.len() + ranges.len() * 2);let mut offset = 0;for span in line.spans {@@ -120,7 +122,11 @@ pub(super) fn highlight_line(line: Line<'static>, needle: &str, current: bool) -let (start, end) = (offset, offset + text.len());offset = end;let mut cut = start;- for r in ranges.iter().filter(|r| r.start < end && r.end > start) {+ for (n, r) in ranges.iter().enumerate() {+ if r.start >= end || r.end <= start {+ continue;+ }+ let paint = if current && n == 0 { current_style() } else { match_style() };let (a, b) = (r.start.max(start), r.end.min(end));if a > cut {spans.push(Span::styled(text[cut - start..a - start].to_string(), span.style));@@ -249,6 +255,18 @@ mod tests {assert_eq!(plain, Line::raw("no match here"));}+ #[test]+ fn only_the_first_match_on_the_current_line_gets_the_current_style() {+ let out = highlight_line(Line::raw("needle and needle"), "needle", true);+ let bands: Vec<bool> = out+ .spans+ .iter()+ .filter(|s| s.content == "needle")+ .map(|s| s.style.bg == Some(Color::Yellow))+ .collect();+ assert_eq!(bands, vec![true, false]);+ }+#[test]fn nearest_prefers_the_last_match_at_or_above_the_view() {let hits = [hit(2, 0), hit(5, 1), hit(9, 0)];diff --git a/src-tauri/src/core/cli/tui/motion.rs b/src-tauri/src/core/cli/tui/motion.rsindex b1df04697..121ba1a10 100644--- a/src-tauri/src/core/cli/tui/motion.rs+++ b/src-tauri/src/core/cli/tui/motion.rs@@ -1,12 +1,11 @@//! The one place the TUI decides whether something moves.//!//! Every animated element -- the throbber, the brightness sweep on a status-//! word, the travelling `wave` glyph, a running tool row -- asks this module-//! for its frame and gets an explicit static fallback when motion is off. The-//! mode is resolved once at launch from `[tui] animations` in-//! `~/.jan/config.toml` and the OS reduce-motion preference, and is-//! process-wide for the same reason as the theme: the render helpers are free-//! functions with no session in hand.+//! word, a running tool row -- asks this module for its frame and gets an+//! explicit static fallback when motion is off. The mode is resolved once at+//! launch from `[tui] animations` in `~/.jan/config.toml` and the OS+//! reduce-motion preference, and is process-wide for the same reason as the+//! theme: the render helpers are free functions with no session in hand.//!//! Animation is driven by the render loop's frame counter rather than the wall//! clock, so every frame is a pure function of its inputs: a test passes a@@ -43,7 +42,7 @@ static REDUCED: AtomicBool = AtomicBool::new(false);#[cfg(test)]thread_local! {- /// Per-test override, like `WAVE_GLYPH_OVERRIDE`: a test pins its own+ /// Per-test override, like `theme::with_theme`: a test pins its own/// thread's mode instead of racing others on the shared flag.static MODE_OVERRIDE: std::cell::Cell<Option<MotionMode>> =const { std::cell::Cell::new(None) };