Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
fix(agent-tui): stop parsing inline think tags unless think_tags is enabled
Akarshan Biswas02cabfb99b31
diff --git a/docs/src/pages/docs/agent/console.mdx b/docs/src/pages/docs/agent/console.mdxindex 1d25b964a..ef30c6dd9 100644--- a/docs/src/pages/docs/agent/console.mdx+++ b/docs/src/pages/docs/agent/console.mdx@@ -201,7 +201,7 @@ Two knobs in `agent.toml` and two in `~/.jan/config.toml` tune this:| --- | --- | --- | --- || `[agent].show_reasoning` | `agent.toml` | `false` | Unfold every reasoning block in the transcript by default. Still folds when off; <kbd>Ctrl</kbd>+<kbd>O</kbd> or a click expands a block either way || `[agent].send_reasoning` | `agent.toml` | `true` | Resend a prior turn's reasoning to the model with the conversation. Turn off for an upstream that rejects the field (Groq), or to keep chains of thought out of the context budget |-| `think_tags` | `~/.jan/config.toml` | `true` | Treat `<thinking>` tags in model content as reasoning (folded and resendable). Off renders them as ordinary prose |+| `think_tags` | `~/.jan/config.toml` | `false` | Treat `<think>` tags in model content as reasoning (folded and resendable). Only for a provider that inlines its reasoning; a `reasoning_content` field needs no tags. Off renders tags as ordinary prose || `stream_reasoning` | `~/.jan/config.toml` | `true` | Stream an open reasoning block's last lines into the live tail. Off shows only the `[thinking]` badge |See [Project config](/docs/agent/project-config) for the `agent.toml` keys.diff --git a/src-tauri/src/core/agent/global_config.rs b/src-tauri/src/core/agent/global_config.rsindex 9bf9502f3..7fbdca347 100644--- a/src-tauri/src/core/agent/global_config.rs+++ b/src-tauri/src/core/agent/global_config.rs@@ -26,10 +26,11 @@ const GLOBAL_CONFIG_TEMPLATE: &str = r#"# Jan Agent global provider config.# worktree = true # run each session in its own git worktree# # (same as passing --worktree); off by# # default, so the agent edits your checkout-# think_tags = false # stop treating <think> tags in model-# # content as reasoning; they render and-# # are resent as ordinary prose. On by-# # default+# think_tags = true # treat <think> tags in model content as+# # reasoning (folded, resent); only for a+# # provider that inlines them, since a+# # reasoning_content field needs no tags.+# # Off by default: tags render as prose# stream_reasoning = false # stop streaming reasoning into the TUI# # live tail while it folds; only the# # [thinking] badge shows it. On by default@@ -118,7 +119,7 @@ struct GlobalConfigToml {#[serde(default, skip_serializing_if = "Option::is_none")]worktree: Option<bool>,/// Parse `<think>` tags in model *content* as reasoning. `None` = the- /// default, on. Native `reasoning_content` streaming is a separate+ /// default, off. Native `reasoning_content` streaming is a separate/// mechanism and is unaffected.#[serde(default, skip_serializing_if = "Option::is_none")]think_tags: Option<bool>,@@ -527,9 +528,11 @@ pub(crate) fn hook_entries() -> Vec<tauri_plugin_agent_tools::tools::hooks::Hook}/// Whether inline `<think>` tags in model content are parsed as reasoning-/// (`think_tags` in `~/.jan/config.toml`), defaulting to on. `false` makes the-/// tags ordinary prose: rendered verbatim, kept in the answer sent back as-/// history, and never folded into a reasoning block.+/// (`think_tags` in `~/.jan/config.toml`), defaulting to off: reasoning arrives+/// in its own `reasoning_content` field, so a tag in content is the model+/// writing about tags. Off renders them verbatim, keeps them in the answer sent+/// back as history, and never folds them into a reasoning block; on is for a+/// provider that inlines its reasoning.////// A display preference must never block startup, so an unreadable or malformed/// config yields the default rather than an error.@@ -537,7 +540,7 @@ pub(crate) fn think_tags_enabled() -> bool {load_raw().ok().and_then(|config| config.think_tags)- .unwrap_or(true)+ .unwrap_or(false)}/// Whether other projects' memory is listed and readable@@ -1049,20 +1052,20 @@ mod tests {}#[test]- fn think_tags_default_on_and_read_from_the_toml_key() {+ fn think_tags_default_off_and_read_from_the_toml_key() {with_temp_home(|_| {- assert!(think_tags_enabled(), "missing file -> parsing on");+ assert!(!think_tags_enabled(), "missing file -> parsing off");let path = ensure_global_config().expect("ensure");- assert!(think_tags_enabled(), "scaffolded file -> parsing on");+ assert!(!think_tags_enabled(), "scaffolded file -> parsing off");- std::fs::write(&path, "think_tags = false\n").unwrap();- assert!(!think_tags_enabled());std::fs::write(&path, "think_tags = true\n").unwrap();assert!(think_tags_enabled());+ std::fs::write(&path, "think_tags = false\n").unwrap();+ assert!(!think_tags_enabled());std::fs::write(&path, "not valid toml [[[").unwrap();assert!(- think_tags_enabled(),+ !think_tags_enabled(),"an unreadable config keeps the default");});diff --git a/src-tauri/src/core/cli/tui.rs b/src-tauri/src/core/cli/tui.rsindex 07e3e86ce..1b510bf51 100644--- a/src-tauri/src/core/cli/tui.rs+++ b/src-tauri/src/core/cli/tui.rs@@ -11033,16 +11033,19 @@ fn think_re() -> &'static regex::Regex {/// Whether inline `<think>` tags in model content are parsed as reasoning./// Process-wide rather than a session field because the split runs on every/// rendered row, from free functions a `Row` reaches with no session in hand.-/// Seeded once from `~/.jan/config.toml` by `set_think_tags_parsed`; `true`+/// Seeded once from `~/.jan/config.toml` by `set_think_tags_parsed`; `false`/// until then, which is also the default.-static PARSE_THINK_TAGS: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(true);+static PARSE_THINK_TAGS: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);#[cfg(test)]thread_local! {/// Per-test override. A test flips its own thread's answer instead of the/// shared static, so a gate-off test cannot race the rest of the suite.+ /// Starts on: the reasoning-fold tests feed inline tags, which production+ /// only parses once `think_tags = true`. The shipped default (off) is+ /// pinned by the `global_config` test.static PARSE_THINK_TAGS_OVERRIDE: std::cell::Cell<Option<bool>> =- const { std::cell::Cell::new(None) };+ const { std::cell::Cell::new(Some(true)) };}/// Apply the `think_tags` setting for the process. Called once per session from@@ -11066,7 +11069,7 @@ fn think_tags_parsed() -> bool {fn without_think_tags<T>(f: impl FnOnce() -> T) -> T {PARSE_THINK_TAGS_OVERRIDE.with(|c| c.set(Some(false)));let out = f();- PARSE_THINK_TAGS_OVERRIDE.with(|c| c.set(None));+ PARSE_THINK_TAGS_OVERRIDE.with(|c| c.set(Some(true)));out}