Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

fix(agent-tui): address review of #9167 (find stepping, orphaned Ctrl-Z, think-tag endpoint)

Akarshan Biswas3fc467c3e5da
diff --git a/docs/src/pages/docs/agent/console.mdx b/docs/src/pages/docs/agent/console.mdx
index 4ad1ac1ea..6a2b02981 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` | per provider | Treat `<think>` tags in model content as reasoning (folded and resendable), for every provider. Unset, it is on for a custom OpenAI-compatible provider and off for `openai`, `anthropic` and `tokamak`, which send reasoning in its own field, and for the Anthropic, Google and Responses wire APIs. Off renders tags as ordinary prose |
+| `think_tags` | `~/.jan/config.toml` | per provider | Treat `<think>` tags in model content as reasoning (folded and resendable), for every provider. Unset, it is on for a custom OpenAI-compatible provider and off for `openai`, `anthropic` and `tokamak` on their own endpoints (`api.openai.com`, `api.anthropic.com`, `api.tokamak.sh`), which send reasoning in its own field; an entry with one of those names but another `base_url` (vLLM, OpenRouter, a local server) is treated as custom and stays on. Also off for the Anthropic, Google and Responses wire APIs. Off renders tags as ordinary prose |
| `parse_think_tags` | `[providers.<name>]` in `~/.jan/config.toml` | inherits `think_tags` | The same switch for one provider; it beats `think_tags` |
| `stream_reasoning` | `~/.jan/config.toml` | `true` | Stream an open reasoning block's last lines into the live tail. Off shows only the `[thinking]` badge |
diff --git a/docs/src/pages/docs/agent/slash-commands.mdx b/docs/src/pages/docs/agent/slash-commands.mdx
index cc2d68ba4..61f3ec14c 100644
--- a/docs/src/pages/docs/agent/slash-commands.mdx
+++ b/docs/src/pages/docs/agent/slash-commands.mdx
@@ -59,7 +59,7 @@ See [Sessions](/docs/agent/sessions).
| `/shells` (alias `/jobs`) | Inspect background shell commands the agent left running: one `• command` row each, with how long it has run; `x` stops the selected one |
| `/stop` | Stop every background shell command at once |
| `/monitors` | Inspect the monitors watching for a condition: id, name, polls so far and script; `x` stops the selected one |
-| `/find <term>` | Search the whole transcript (case-insensitive) and jump to the nearest match, unfolding it if needed. <kbd>n</kbd> / <kbd>N</kbd> step to the next / previous match, wrapping at the ends, while the input is empty; <kbd>Esc</kbd> or the next message clears it. A miss is reported in the footer |
+| `/find <term>` | Search the whole transcript (case-insensitive) and jump to the nearest match, unfolding it if needed. <kbd>Enter</kbd> / <kbd>Shift</kbd>+<kbd>Enter</kbd> step to the next / previous match, wrapping at the ends, while the input is empty (they type nothing, so the start of your next message is never eaten); a term that word-wraps across two lines is not matched; <kbd>Esc</kbd> or the next message clears it. A miss is reported in the footer |
See [Run modes](/docs/agent/run-modes), [Goals and todos](/docs/agent/goals-and-todos), and
[Context and compaction](/docs/agent/context).
diff --git a/src-tauri/jan-cli/tests/tui_suspend.rs b/src-tauri/jan-cli/tests/tui_suspend.rs
index 8ff974c46..7eb6ccb45 100644
--- a/src-tauri/jan-cli/tests/tui_suspend.rs
+++ b/src-tauri/jan-cli/tests/tui_suspend.rs
@@ -114,6 +114,13 @@ impl Drop for Session {
}
fn spawn() -> Session {
+ spawn_with(false)
+}
+
+/// `new_session` runs `jan` through `setsid --ctty`, so it leads a session of
+/// its own and its parent (this runner) is in another one: an orphaned process
+/// group, like `ssh -t host jan` or `docker exec -it`.
+fn spawn_with(new_session: bool) -> Session {
let size = Winsize {
ws_row: 24,
ws_col: 80,
@@ -126,15 +133,24 @@ fn spawn() -> Session {
let slave = File::from(pty.slave);
let home = std::env::temp_dir().join(format!("jan-tui-suspend-{}", std::process::id()));
std::fs::create_dir_all(&home).unwrap();
- let child = Command::new(env!("CARGO_BIN_EXE_jan"))
+ let mut command = if new_session {
+ let mut c = Command::new("setsid");
+ c.arg("--ctty").arg(env!("CARGO_BIN_EXE_jan"));
+ c
+ } else {
+ Command::new(env!("CARGO_BIN_EXE_jan"))
+ };
+ if !new_session {
+ // The suspend stops jan's whole process group; without a group of its
+ // own that would be this test runner's.
+ command.process_group(0);
+ }
+ let child = command
.env("HOME", &home)
.env("JAN_CLI_NO_UPDATE_CHECK", "1")
.stdin(Stdio::from(slave.try_clone().expect("clone PTY slave")))
.stdout(Stdio::from(slave.try_clone().expect("clone PTY slave")))
.stderr(Stdio::from(slave))
- // The suspend stops jan's whole process group; without a group of its
- // own that would be this test runner's.
- .process_group(0)
.spawn()
.expect("spawn jan under the test PTY");
let pid = Pid::from_raw(child.id() as i32);
@@ -179,3 +195,21 @@ fn ctrl_z_and_sigtstp_suspend_and_resume_cleanly() {
);
assert!(session.alive(), "jan exited after resuming: {:?}", session.text());
}
+
+/// With no job-control shell above it nothing would ever send SIGCONT, so
+/// Ctrl-Z must refuse (and say so) rather than stop and hang the terminal.
+#[test]
+fn ctrl_z_in_an_orphaned_group_refuses_instead_of_stopping() {
+ let session = spawn_with(true);
+ session.wait_for(0, &ENTER, "the TUI to start");
+ let mut master = session.master.try_clone().expect("clone PTY master");
+ let before = session.text().len();
+ master.write_all(b"\x1a").expect("type Ctrl-Z");
+ let deadline = Instant::now() + DEADLINE;
+ while !session.text()[before..].contains("could not suspend") {
+ assert!(Instant::now() < deadline, "no refusal: {:?}", session.text());
+ std::thread::sleep(Duration::from_millis(50));
+ }
+ assert!(session.alive(), "jan stopped or exited: {:?}", session.text());
+ assert!(session.raw(), "the TUI kept the terminal");
+}
diff --git a/src-tauri/src/core/agent/global_config.rs b/src-tauri/src/core/agent/global_config.rs
index 7831a00e9..88d1ed91e 100644
--- a/src-tauri/src/core/agent/global_config.rs
+++ b/src-tauri/src/core/agent/global_config.rs
@@ -538,14 +538,39 @@ pub(crate) fn hook_entries() -> Vec<tauri_plugin_agent_tools::tools::hooks::Hook
load_raw().map(|config| config.hooks).unwrap_or_default()
}
-/// Providers known to send reasoning in its own `reasoning_content` field, so
-/// tag parsing is off for them unless the user opts in. Anything else on the
-/// OpenAI wire (a custom endpoint, a local server) may inline its reasoning.
-const SEPARATE_REASONING_PROVIDERS: &[&str] = &["openai", "anthropic", "tokamak"];
+/// Providers known to send reasoning in its own `reasoning_content` field, with
+/// the host that is really theirs, so tag parsing is off for them unless the
+/// user opts in. Anything else on the OpenAI wire (a custom endpoint, a local
+/// server) may inline its reasoning. The host matters as much as the name: an
+/// `openai` entry pointed at vLLM or OpenRouter is a compatible server, not
+/// OpenAI.
+const SEPARATE_REASONING_PROVIDERS: &[(&str, &str)] = &[
+ ("openai", "api.openai.com"),
+ ("anthropic", "api.anthropic.com"),
+ ("tokamak", "api.tokamak.sh"),
+];
+
+/// Whether `provider` is one of the known providers talking to its own
+/// endpoint. No `base_url` means the built-in one.
+fn sends_reasoning_separately(provider: &str, base_url: Option<&str>) -> bool {
+ let Some((_, host)) = SEPARATE_REASONING_PROVIDERS
+ .iter()
+ .find(|(name, _)| *name == provider)
+ else {
+ return false;
+ };
+ match base_url.map(str::trim).filter(|u| !u.is_empty()) {
+ None => true,
+ Some(url) => url::Url::parse(url)
+ .ok()
+ .and_then(|u| u.host_str().map(|h| h.eq_ignore_ascii_case(host)))
+ .unwrap_or(false),
+ }
+}
/// Whether inline `<think>` tags in the content `provider` serves are parsed as
-/// reasoning. `provider` is the one serving the active model and `api_type` its
-/// wire API; `None` when nothing serves it.
+/// reasoning. `provider` is the one serving the active model, `api_type` its
+/// wire API and `base_url` its endpoint; `None` when nothing serves it.
///
/// Answered in this order: the provider's own `parse_think_tags`, the root
/// `think_tags` (every provider), then the default. The default is on only for
@@ -556,7 +581,11 @@ const SEPARATE_REASONING_PROVIDERS: &[&str] = &["openai", "anthropic", "tokamak"
///
/// A display preference must never block startup, so an unreadable or malformed
/// config yields the default rather than an error.
-pub(crate) fn think_tags_enabled_for(provider: Option<&str>, api_type: Option<&str>) -> bool {
+pub(crate) fn think_tags_enabled_for(
+ provider: Option<&str>,
+ api_type: Option<&str>,
+ base_url: Option<&str>,
+) -> bool {
let Some(provider) = provider else {
return false;
};
@@ -567,7 +596,7 @@ pub(crate) fn think_tags_enabled_for(provider: Option<&str>, api_type: Option<&s
.and_then(|entry| entry.parse_think_tags)
.or_else(|| config.as_ref().and_then(|c| c.think_tags))
.unwrap_or_else(|| {
- !SEPARATE_REASONING_PROVIDERS.contains(&provider)
+ !sends_reasoning_separately(provider, base_url)
&& matches!(api_type, None | Some("openai"))
})
}
@@ -1086,16 +1115,47 @@ mod tests {
// Providers known to send reasoning in its own field, and any
// non-chat-completions wire API, never need tag parsing.
for known in ["openai", "anthropic", "tokamak"] {
- assert!(!think_tags_enabled_for(Some(known), None), "{known}");
+ assert!(!think_tags_enabled_for(Some(known), None, None), "{known}");
}
- assert!(!think_tags_enabled_for(Some("mine"), Some("anthropic")));
- assert!(!think_tags_enabled_for(Some("mine"), Some("google")));
- assert!(!think_tags_enabled_for(Some("mine"), Some("openai-responses")));
+ assert!(!think_tags_enabled_for(Some("mine"), Some("anthropic"), None));
+ assert!(!think_tags_enabled_for(Some("mine"), Some("google"), None));
+ assert!(!think_tags_enabled_for(Some("mine"), Some("openai-responses"), None));
// A custom OpenAI-compatible endpoint may inline its reasoning.
- assert!(think_tags_enabled_for(Some("mine"), None));
- assert!(think_tags_enabled_for(Some("mine"), Some("openai")));
+ assert!(think_tags_enabled_for(Some("mine"), None, None));
+ assert!(think_tags_enabled_for(Some("mine"), Some("openai"), None));
// Nothing serves the model: nothing to parse for.
- assert!(!think_tags_enabled_for(None, None));
+ assert!(!think_tags_enabled_for(None, None, None));
+ });
+ }
+
+ #[test]
+ fn a_known_provider_name_on_a_foreign_endpoint_keeps_tag_parsing_on() {
+ with_temp_home(|_| {
+ let own = [
+ ("openai", "https://api.openai.com/v1"),
+ ("anthropic", "https://API.Anthropic.com/v1/"),
+ ("tokamak", "https://api.tokamak.sh/v1"),
+ ];
+ for (name, url) in own {
+ assert!(!think_tags_enabled_for(Some(name), None, Some(url)), "{name}");
+ }
+ // No base_url (or an empty one) is the built-in endpoint.
+ assert!(!think_tags_enabled_for(Some("openai"), None, Some(" ")));
+ // The same name pointed at a compatible server may inline reasoning.
+ for url in [
+ "http://localhost:8000/v1",
+ "https://openrouter.ai/api/v1",
+ "https://api.openai.com.evil.example/v1",
+ "not a url",
+ ] {
+ assert!(think_tags_enabled_for(Some("openai"), None, Some(url)), "{url}");
+ }
+ // The wire API still wins over the endpoint.
+ assert!(!think_tags_enabled_for(
+ Some("openai"),
+ Some("anthropic"),
+ Some("http://localhost:8000/v1"),
+ ));
});
}
@@ -1103,13 +1163,13 @@ mod tests {
fn think_tags_overrides_beat_the_default_provider_first() {
with_temp_home(|_| {
let path = ensure_global_config().expect("ensure");
- assert!(think_tags_enabled_for(Some("mine"), None), "scaffold is neutral");
+ assert!(think_tags_enabled_for(Some("mine"), None, None), "scaffold is neutral");
// The root key is the user-wide answer for every provider.
std::fs::write(&path, "think_tags = false\n").unwrap();
- assert!(!think_tags_enabled_for(Some("mine"), None));
+ assert!(!think_tags_enabled_for(Some("mine"), None, None));
std::fs::write(&path, "think_tags = true\n").unwrap();
- assert!(think_tags_enabled_for(Some("openai"), None));
+ assert!(think_tags_enabled_for(Some("openai"), None, None));
// A provider's own key beats the root key, both ways.
std::fs::write(
@@ -1118,15 +1178,15 @@ mod tests {
[providers.mine]\nparse_think_tags = false\n",
)
.unwrap();
- assert!(!think_tags_enabled_for(Some("openai"), None));
- assert!(!think_tags_enabled_for(Some("mine"), None));
+ assert!(!think_tags_enabled_for(Some("openai"), None, None));
+ assert!(!think_tags_enabled_for(Some("mine"), None, None));
std::fs::write(&path, "[providers.openai]\nparse_think_tags = true\n").unwrap();
- assert!(think_tags_enabled_for(Some("openai"), None));
- assert!(!think_tags_enabled_for(Some("anthropic"), None));
+ assert!(think_tags_enabled_for(Some("openai"), None, None));
+ assert!(!think_tags_enabled_for(Some("anthropic"), None, None));
std::fs::write(&path, "not valid toml [[[").unwrap();
assert!(
- think_tags_enabled_for(Some("mine"), None),
+ think_tags_enabled_for(Some("mine"), None, None),
"an unreadable config keeps the default"
);
});
diff --git a/src-tauri/src/core/cli/mod.rs b/src-tauri/src/core/cli/mod.rs
index e2bbe0358..e19f95c2b 100644
--- a/src-tauri/src/core/cli/mod.rs
+++ b/src-tauri/src/core/cli/mod.rs
@@ -1822,12 +1822,13 @@ fn prepare_agent_session(
// 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.
+ let serving_config = serving_provider
+ .as_deref()
+ .and_then(|name| provider_configs.get(name));
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()),
+ serving_config.and_then(|config| config.api_type.as_deref()),
+ serving_config.and_then(|config| config.base_url.as_deref()),
));
// MCP servers marked `active` in mcp_config.json connect off-thread so setup/
diff --git a/src-tauri/src/core/cli/tui.rs b/src-tauri/src/core/cli/tui.rs
index 4caf51703..2fd23aca6 100644
--- a/src-tauri/src/core/cli/tui.rs
+++ b/src-tauri/src/core/cli/tui.rs
@@ -216,6 +216,11 @@ fn is_suspend_key(key: &KeyEvent) -> bool {
fn suspend_to_shell(mouse: bool) -> io::Result<()> {
use nix::sys::signal::{kill, Signal};
use nix::unistd::Pid;
+ if group_is_orphaned() {
+ return Err(io::Error::other(
+ "no job-control shell above jan (ssh -t, docker exec); nothing could resume it",
+ ));
+ }
restore_terminal_modes();
let stopped = kill(Pid::from_raw(0), Signal::SIGSTOP).map_err(io::Error::from);
enable_raw_mode()?;
@@ -223,6 +228,26 @@ fn suspend_to_shell(mouse: bool) -> io::Result<()> {
stopped
}
+/// POSIX: a process group is orphaned when no member has a parent in another
+/// group of the same session, so no job-control shell is there to `fg` it. The
+/// kernel discards SIGTSTP for such a group (which is why vim's Ctrl-Z does
+/// nothing there), but SIGSTOP always stops, and nobody would send SIGCONT.
+/// Only our own parent is inspected: the other members of the group are not
+/// enumerable without `/proc`, and a false "orphaned" only refuses a suspend,
+/// where a false "not orphaned" hangs the terminal.
+#[cfg(unix)]
+fn group_is_orphaned() -> bool {
+ use nix::unistd::{getpgid, getpgrp, getppid, getsid};
+ let parent = getppid();
+ let (Ok(parent_group), Ok(parent_session), Ok(session)) =
+ (getpgid(Some(parent)), getsid(Some(parent)), getsid(None))
+ else {
+ // The parent is gone: reparented to init, which is in another session.
+ return true;
+ };
+ parent_session != session || parent_group == getpgrp()
+}
+
/// Suspend from the render loop, noting a failure in the transcript rather
/// than ending the session over it.
#[cfg(unix)]
@@ -5531,7 +5556,7 @@ impl App {
let index = self.transcript.region_index();
for (i, row) in self.transcript.rows.iter().enumerate() {
// Read in place: copying every row of the session out of its cache
- // on each `/find` and `n` was most of the scan's cost.
+ // on each `/find` and step was most of the scan's cost.
row.fill(width);
if let Some(cached) = row.cache.borrow().as_ref() {
scan(i, false, &cached.lines);
@@ -5568,7 +5593,7 @@ impl App {
/// can report it without snapping the view back to the bottom.
fn start_find(&mut self, term: &str) {
let Some(needle) = find::needle(term) else {
- self.note("usage: /find <term> (n/N next/previous, Esc clears)");
+ self.note("usage: /find <term> (Enter next, Shift-Enter previous, Esc clears)");
return;
};
let hits = self.find_hits(&needle);
@@ -5593,7 +5618,7 @@ impl App {
}
}
- /// `n` (`forward`) / `N`: move to the next/previous match, wrapping at the
+ /// Enter (`forward`) / Shift-Enter: move to the next/previous match, wrapping at the
/// ends. Rescans first, so rows that landed since the search began count.
fn find_step(&mut self, forward: bool) {
let Some(find) = self.find.as_ref() else {
@@ -6982,14 +7007,19 @@ impl App {
/// Whether the current model's provider has its inline tags parsed.
fn think_tags_gate(&mut self) -> bool {
let provider = self.serving_provider();
- let api_type = provider.as_deref().and_then(|name| {
- let args = self.args.as_ref()?;
- let pc = args.provider_configs.try_lock().ok()?;
- pc.get(name)?.api_type.clone()
- });
+ let (api_type, base_url) = provider
+ .as_deref()
+ .and_then(|name| {
+ let args = self.args.as_ref()?;
+ let pc = args.provider_configs.try_lock().ok()?;
+ let config = pc.get(name)?;
+ Some((config.api_type.clone(), config.base_url.clone()))
+ })
+ .unwrap_or_default();
crate::core::agent::global_config::think_tags_enabled_for(
provider.as_deref(),
api_type.as_deref(),
+ base_url.as_deref(),
)
}
@@ -14686,9 +14716,10 @@ async fn handle_key(
app.exit_armed = false;
// An active search owns Esc (ahead of cancel and rewind, so the first Esc
- // only ends the search) and, while the input is empty, `n`/`N`. Once
- // anything is typed those letters are text again, so a search can never
- // swallow a message being written.
+ // only ends the search) and, while the input is empty, Enter / Shift-Enter
+ // to step. A letter key would eat the first character of the next message
+ // (the input is empty right after `/find x`), so stepping uses keys that
+ // type nothing; with text in the composer Enter submits as usual.
if app.find.is_some() {
match key.code {
KeyCode::Esc => {
@@ -14696,8 +14727,8 @@ async fn handle_key(
app.last_esc = None;
return;
}
- KeyCode::Char(c @ ('n' | 'N')) if !ctrl && !alt && app.input.is_empty() => {
- app.find_step(c == 'n');
+ KeyCode::Enter if !ctrl && !sup && app.input.is_empty() => {
+ app.find_step(!newline);
return;
}
_ => {}
@@ -15161,7 +15192,7 @@ const SLASH_COMMANDS: &[SlashCommand] = &[
SlashCommand {
name: "/find",
hint: "<term>",
- description: "Search the transcript; n/N step through matches, Esc clears",
+ description: "Search the transcript; Enter / Shift-Enter step through matches, Esc clears",
alias_of: None,
},
SlashCommand {
@@ -21106,7 +21137,7 @@ fn draw(f: &mut Frame, app: &mut App) {
if let (Some(start), Some(hit)) = (layout.find_at, find_hit) {
// Down to the matching line inside its segment, measured with the same
// wrap the body uses. Only on the jump frame, so the lines above it are
- // cloned once per `n`/`N`, not every frame.
+ // cloned once per step, not every frame.
let above = layout
.segs
.get(layout.find_seg.unwrap_or(usize::MAX))
@@ -23788,7 +23819,7 @@ fn footer_spans(app: &App) -> Vec<Span<'static>> {
)],
};
let keys: &[(&str, &str)] = if find.current.is_some() {
- &[("n/N", "next/prev"), ("Esc", "clear")]
+ &[("Enter/Shift-Enter", "next/prev"), ("Esc", "clear")]
} else {
&[("Esc", "clear")]
};
@@ -30143,12 +30174,17 @@ mod tests {
#[test]
fn think_tag_gate_follows_the_serving_provider_across_a_model_switch() {
crate::core::agent::global_config::with_temp_home(|_| {
+ // `tokamak` is only "separate reasoning" on its own host.
let provider = |name: &str, model: &str| {
+ let base_url = match name {
+ "tokamak" => "https://api.tokamak.sh/v1",
+ _ => "http://127.0.0.1:1/v1",
+ };
(
name.to_string(),
crate::core::state::ProviderConfig {
provider: name.into(),
- base_url: Some("http://127.0.0.1:1/v1".into()),
+ base_url: Some(base_url.into()),
models: vec![model.into()],
..Default::default()
},
@@ -30180,10 +30216,14 @@ mod tests {
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| {
+ let base_url = match name {
+ "tokamak" => "https://api.tokamak.sh/v1",
+ _ => "http://127.0.0.1:1/v1",
+ };
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()),
+ base_url: Some(base_url.into()),
models: Some(vec![model.into()]),
..Default::default()
},
@@ -46403,7 +46443,7 @@ mod tests {
}
#[tokio::test]
- async fn n_and_shift_n_step_through_matches_and_wrap() {
+ async fn enter_and_shift_enter_step_through_matches_and_wrap() {
let mut app = test_app();
for word in ["alpha one", "beta", "alpha two", "alpha three"] {
app.note(word);
@@ -46416,21 +46456,26 @@ mod tests {
// Never drawn, so the whole transcript counts as above the view: the
// search lands on the newest match.
assert_eq!(at(&app), (2, 3));
- press(&mut app, KeyCode::Char('n'), KeyModifiers::NONE).await;
+ press(&mut app, KeyCode::Enter, KeyModifiers::NONE).await;
assert_eq!(at(&app), (0, 3), "next wraps past the last match");
- press(&mut app, KeyCode::Char('n'), KeyModifiers::NONE).await;
+ press(&mut app, KeyCode::Enter, KeyModifiers::NONE).await;
assert_eq!(at(&app), (1, 3));
- press(&mut app, KeyCode::Char('N'), KeyModifiers::SHIFT).await;
+ press(&mut app, KeyCode::Enter, KeyModifiers::SHIFT).await;
assert_eq!(at(&app), (0, 3));
- press(&mut app, KeyCode::Char('N'), KeyModifiers::SHIFT).await;
+ press(&mut app, KeyCode::Enter, KeyModifiers::SHIFT).await;
assert_eq!(at(&app), (2, 3), "previous wraps past the first match");
- assert!(app.input.is_empty(), "n/N never reach the composer");
+ assert!(app.input.is_empty(), "stepping never reaches the composer");
+ }
- // With text in the composer, n is typing again.
- type_key_chars(&mut app, "x").await;
- press(&mut app, KeyCode::Char('n'), KeyModifiers::NONE).await;
- assert_eq!(app.input, "xn");
- assert_eq!(at(&app), (2, 3), "typing does not move the search");
+ #[tokio::test]
+ async fn letters_typed_after_a_search_are_not_swallowed() {
+ let mut app = test_app();
+ app.note("needle here");
+ run_command(&mut app, "find needle", &no_mcp()).await;
+ assert!(app.find.is_some());
+ // The next message starts with n and N: both must be text.
+ type_key_chars(&mut app, "nNow").await;
+ assert_eq!(app.input, "nNow");
}
#[tokio::test]
@@ -46440,8 +46485,8 @@ mod tests {
let rows = app.transcript.rows.len();
app.scrollback = 3;
run_command(&mut app, "find answer line", &no_mcp()).await;
- press(&mut app, KeyCode::Char('n'), KeyModifiers::NONE).await;
- press(&mut app, KeyCode::Char('N'), KeyModifiers::SHIFT).await;
+ press(&mut app, KeyCode::Enter, KeyModifiers::NONE).await;
+ press(&mut app, KeyCode::Enter, KeyModifiers::SHIFT).await;
assert_eq!(app.scrollback, 3, "only the draw moves the viewport");
press_esc(&mut app).await;
assert!(app.find.is_none());
diff --git a/src-tauri/src/core/cli/tui/find.rs b/src-tauri/src/core/cli/tui/find.rs
index 3292dd202..6bfc50205 100644
--- a/src-tauri/src/core/cli/tui/find.rs
+++ b/src-tauri/src/core/cli/tui/find.rs
@@ -1,4 +1,4 @@
-//! In-transcript search (`/find`, Ctrl-F, `n`/`N`).
+//! In-transcript search (`/find`, Ctrl-F, Enter / Shift-Enter).
//!
//! The transcript is a single scrollable pane, so search is narrow on purpose:
//! it never rebuilds or filters rows, it only records where matches are and
@@ -14,7 +14,7 @@ use ratatui::text::{Line, Span};
/// One matching line: its transcript row, whether it sits in that row's folded
/// detail (what Ctrl-O or a click reveals) rather than the row itself, and the
/// line within that part. The field order makes the derived ordering top to
-/// bottom as drawn, which is the order `n` walks.
+/// bottom as drawn, which is the order Enter walks.
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub(super) struct Hit {
pub(super) row: usize,
@@ -27,7 +27,7 @@ pub(super) struct Hit {
pub(super) struct Find {
/// The term as typed; matching folds case on both sides.
pub(super) term: String,
- /// Matches from the latest scan. Rescanned on every `n`/`N`, so rows that
+ /// Matches from the latest scan. Rescanned on every step, so rows that
/// landed after the search started are reachable without searching again.
pub(super) hits: Vec<Hit>,
/// Index into `hits` of the current match, `None` when nothing matched.
@@ -108,7 +108,7 @@ fn current_style() -> Style {
/// 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. 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
+/// gets the current style: hits are whole lines, so that is the one a step 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);