Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
fix(agent-tui): mouse-wheel scroll + awaiting throbber below prose
Akarshan Biswasb43a44235725
diff --git a/src-tauri/src/core/agent/context.rs b/src-tauri/src/core/agent/context.rsindex 264d6b6a3..22739cac4 100644--- a/src-tauri/src/core/agent/context.rs+++ b/src-tauri/src/core/agent/context.rs@@ -45,10 +45,24 @@ pub(crate) fn load_skills(project_root: &Path) -> Option<String> {))}+/// Guidance injected only when subagent tools are actually available, so the+/// model delegates context-heavy exploration instead of exhausting its own+/// (limited) context window reading files and tool output directly.+const SUBAGENT_GUIDE: &str = "# Subagents\n\nYour own context window is limited. For open-ended exploration \+that could pull in a lot of file content or tool output (broad codebase search, reading many files, \+multi-step research), prefer `dispatch_subagent` over doing it inline: the subagent absorbs that context \+in its own window and returns only the distilled answer. Dispatch independent subagents in parallel when \+their work doesn't depend on each other, then `await_subagent` each. Do inline work yourself for small, \+targeted tasks where delegating would cost more than it saves.";+/// Assemble the project system prompt: the optional base prompt, the always-on/// built-in skills/memory guide, then any project-authored skills. The guide is/// always present for project runs, so this never returns None.-pub(crate) fn build_system_prompt(base: Option<&str>, project_root: &Path) -> Option<String> {+pub(crate) fn build_system_prompt(+ base: Option<&str>,+ project_root: &Path,+ subagents_enabled: bool,+) -> Option<String> {let mut blocks: Vec<String> = Vec::new();if let Some(b) = base {blocks.push(b.to_string());@@ -57,6 +71,9 @@ pub(crate) fn build_system_prompt(base: Option<&str>, project_root: &Path) -> Op"# Working Directory\n\nCurrent project directory: `{}`\n\nAll relative paths in tool calls resolve against this directory unless stated otherwise.",project_root.display()));+ if subagents_enabled {+ blocks.push(SUBAGENT_GUIDE.to_string());+ }blocks.push(DEFAULT_SKILL_GUIDE.trim().to_string());if let Some(skills) = load_skills(project_root) {blocks.push(skills);@@ -130,7 +147,7 @@ mod tests {fn build_system_prompt_orders_base_guide_then_skills() {let root = scratch_project("merge");write_skill(&root, "s.md", "Do the thing.");- let out = build_system_prompt(Some("You are Jan."), &root).expect("prompt");+ let out = build_system_prompt(Some("You are Jan."), &root, false).expect("prompt");assert!(out.starts_with("You are Jan."));assert!(out.contains("Do the thing."));// Guide sits between the base prompt and the project skills.@@ -144,15 +161,25 @@ mod tests {fn build_system_prompt_always_includes_guide() {let root = scratch_project("guide");// No base and no project skills: the built-in guide is still injected.- let out = build_system_prompt(None, &root).expect("guide always present");+ let out = build_system_prompt(None, &root, false).expect("guide always present");assert!(out.contains("Skills and Project Memory"));assert!(out.contains("skill_write"));assert!(out.contains("memory_write"));// Base is preserved and precedes the guide.- let with_base = build_system_prompt(Some("base"), &root).expect("prompt");+ let with_base = build_system_prompt(Some("base"), &root, false).expect("prompt");assert!(with_base.starts_with("base"));assert!(with_base.contains("Skills and Project Memory"));let _ = std::fs::remove_dir_all(&root);}++ #[test]+ fn build_system_prompt_advertises_subagents_only_when_enabled() {+ let root = scratch_project("subagents");+ let without = build_system_prompt(None, &root, false).expect("prompt");+ assert!(!without.contains("dispatch_subagent"));+ let with = build_system_prompt(None, &root, true).expect("prompt");+ assert!(with.contains("dispatch_subagent"));+ let _ = std::fs::remove_dir_all(&root);+ }}diff --git a/src-tauri/src/core/agent/loop.rs b/src-tauri/src/core/agent/loop.rsindex ec92564be..2de9b2710 100644--- a/src-tauri/src/core/agent/loop.rs+++ b/src-tauri/src/core/agent/loop.rs@@ -626,7 +626,7 @@ async fn orchestrate_inner(project_root,permission_requests,system_prompt_override,- subagents_enabled: _,+ subagents_enabled,} = args;let messages_value = json_body@@ -652,6 +652,7 @@ async fn orchestrate_inner(let mut sp = crate::core::agent::context::build_system_prompt(assistant_instructions.as_deref(),root,+ *subagents_enabled,);// Recall project memory for the current query before it is indexed, so// the active turn cannot surface itself.diff --git a/src-tauri/src/core/cli/tui.rs b/src-tauri/src/core/cli/tui.rsindex 0d13bea6d..90e56e2fc 100644--- a/src-tauri/src/core/cli/tui.rs+++ b/src-tauri/src/core/cli/tui.rs@@ -2098,6 +2098,19 @@ async fn chat_loop<B: Backend>(/// Ignores clicks outside the transcript viewport or on rows that aren't a/// region's own summary row (detail lines, blank padding, etc).fn handle_mouse(app: &mut App, mouse: MouseEvent) {+ // Wheel scrolls the transcript (clamped to `max_back` on the next draw);+ // one notch matches a single arrow-key step.+ match mouse.kind {+ MouseEventKind::ScrollUp => {+ app.scrollback = app.scrollback.saturating_add(1);+ return;+ }+ MouseEventKind::ScrollDown => {+ app.scrollback = app.scrollback.saturating_sub(1);+ return;+ }+ _ => {}+ }if !matches!(mouse.kind, MouseEventKind::Down(MouseButton::Left)) {return;}@@ -3051,16 +3064,6 @@ fn draw(f: &mut Frame, app: &mut App) {}}}- for (_, _, name) in &app.awaiting {- let frame = SPINNER[app.spinner_frame % SPINNER.len()];- lines.push(Line::from(vec![- Span::styled(format!("{frame} "), Style::new().cyan()),- Span::styled(- format!("Awaiting subagent: {name}"),- Style::new().cyan().dim(),- ),- ]));- }for panel in &app.subagents {let last_blank = lines.last()@@ -3102,7 +3105,19 @@ fn draw(f: &mut Frame, app: &mut App) {lines.extend(tail);}}- // Awaiting throbbers, live subagent panels, and streaming prose above have+ // Awaiting throbbers render last: below the assistant's reasoning/message+ // so the "still waiting" state trails the prose that led up to the wait.+ for (_, _, name) in &app.awaiting {+ let frame = SPINNER[app.spinner_frame % SPINNER.len()];+ lines.push(Line::from(vec![+ Span::styled(format!("{frame} "), Style::new().cyan()),+ Span::styled(+ format!("Awaiting subagent: {name}"),+ Style::new().cyan().dim(),+ ),+ ]));+ }+ // Live subagent panels, streaming prose, and awaiting throbbers above have// no transcript index; they're all appended after the transcript loop.row_index.resize(lines.len(), None);@@ -4032,6 +4047,38 @@ mod tests {assert_eq!(tool_activity("create_subagent", &json!({"name": "r"})), "Creating subagent: r");}+ #[test]+ fn awaiting_throbber_renders_below_assistant_prose() {+ use ratatui::{backend::TestBackend, Terminal};+ let mut app = test_app();+ app.apply(StreamEvent::Token {+ text: "Let me wait for the subagent.".into(),+ });+ app.apply(StreamEvent::ToolCall {+ id: "a1".into(),+ name: "await_subagent".into(),+ args: json!({ "run_id": "sub-reviewer-1" }),+ });+ let mut terminal = Terminal::new(TestBackend::new(60, 30)).unwrap();+ terminal.draw(|f| super::draw(f, &mut app)).unwrap();+ let buf = terminal.backend().buffer().clone();+ let rows: Vec<String> = (0..buf.area.height)+ .map(|y| {+ (0..buf.area.width)+ .map(|x| buf[(x, y)].symbol())+ .collect::<String>()+ })+ .collect();+ let prose = rows.iter().position(|r| r.contains("wait for the subagent"));+ let awaiting = rows.iter().position(|r| r.contains("Awaiting subagent: reviewer"));+ let (prose, awaiting) = (prose.expect("prose row"), awaiting.expect("awaiting row"));+ assert!(+ awaiting > prose,+ "awaiting throbber must render below prose:\n{}",+ rows.join("\n")+ );+ }+#[test]fn subagent_name_from_run_id_strips_prefix_and_seq() {assert_eq!(subagent_name_from_run_id("sub-reviewer-3"), "reviewer");@@ -4811,6 +4858,36 @@ mod tests {assert!(app.expanded.contains(&group_idx));}+ #[test]+ fn wheel_scrolls_transcript() {+ let mut app = test_app();+ app.transcript_rect = Rect::new(0, 0, 80, 10);+ let up = |app: &mut App| {+ handle_mouse(+ app,+ MouseEvent {+ kind: MouseEventKind::ScrollUp,+ column: 5,+ row: 5,+ modifiers: KeyModifiers::NONE,+ },+ )+ };+ up(&mut app);+ up(&mut app);+ assert_eq!(app.scrollback, 2);+ handle_mouse(+ &mut app,+ MouseEvent {+ kind: MouseEventKind::ScrollDown,+ column: 5,+ row: 5,+ modifiers: KeyModifiers::NONE,+ },+ );+ assert_eq!(app.scrollback, 1);+ }+#[test]fn toggle_region_expands_still_running_group() {// A tool group is still open (not yet finalized into `app.groups`)