ππΌββοΈ The blackboard for coding agents - agentic development environment for claude code, codex, cursor, opencode, grok and more.
Rust adeai-agentsclaudeclaude-codecodexcursorgeminigrokopencodespec-driven-developmentvibe-codingvim
feat: add multi agent support per task lifetime (#24)
Fynn FlΓΌgge13743c13e360
diff --git a/README.md b/README.mdindex 6a50f96..c76dfa4 100644--- a/README.md+++ b/README.md@@ -1,19 +1,24 @@<div align="center">-# agtx+<img src="https://github.com/user-attachments/assets/f8d3f9b6-712b-49d0-a84e-2a2c9400bacc" width="680" />-**Terminal-native kanban board for managing spec-driven coding agent sessions. Plugin any existing spec-driven development framework or specify your own workflow with per-phase skills, prompts, artifact tracking and automatic execution.**+### **Terminal-native kanban board for managing spec-driven AI coding agent sessions.**++Let different coding agents collaborate on the same task. Plug in any existing spec-driven development framework or specify your own workflow as a custom plugin with per-phase skills, prompts, artifact tracking and autonomous execution.++<img width="960" height="645" alt="Screenshot 2026-02-28 at 18 32 06" src="https://github.com/user-attachments/assets/442965f4-d2c4-435f-a065-df56dc483ab7" /></div>-+[//]: <>## Features- **Kanban workflow**: Backlog/Research β Planning β Running β Review β Done- **Git worktree and tmux isolation**: Each task gets its own worktree and tmux window, keeping work separated-- **Coding agent integrations**: Automatic session management for Claude Code, Codex, Gemini, Copilot and OpenCode-- **Spec-driven workflow plugins**: Plug in and select any spec-driven development framework per task β or define individual skills, prompts and artifacts - with automatic execution and tracking at each phase+- **Coding agent integrations**: Automatic session management for Claude Code, Codex, Gemini, OpenCode and Copilot+- **Multi-agent per task**: Configure different agents per workflow phase β e.g. Gemini for planning, Claude for implementation, Codex for review β with automatic agent switching in the same tmux window+- **Spec-driven development plugins**: Plug in any spec-driven development framework or select from a predefined set of plugins like GSD or Spec-kit β or define custom skills, prompts and artifact tracking - with automatic execution and tracking at each phase- **Multi-project dashboard**: Manage tasks across all your projects- **PR workflow**: Generate descriptions with AI, create PRs directly from the TUI- **Customizable themes**: Configure colors via config file@@ -37,7 +42,7 @@ cp target/release/agtx ~/.local/bin/- **tmux** - Agent sessions run in a dedicated tmux server- **gh** - GitHub CLI for PR operations-- Supported coding agents: [Claude Code](https://github.com/anthropics/claude-code), [Codex](https://github.com/openai/codex), [Gemini](https://github.com/google-gemini/gemini-cli), [Copilot](https://github.com/github/copilot-cli), [OpenCode](https://github.com/sst/opencode)+- Supported coding agents: [Claude Code](https://github.com/anthropics/claude-code), [Codex](https://github.com/openai/codex), [Gemini](https://github.com/google-gemini/gemini-cli), [OpenCode](https://github.com/sst/opencode), [Copilot](https://github.com/github/copilot-cli)## Quick Start@@ -62,13 +67,14 @@ agtx -g| `h/l` or `β/β` | Move between columns || `j/k` or `β/β` | Move between tasks || `o` | Create new task |+| `R` | Enter research mode || `β©` | Open task (view agent session) || `m` | Move task forward in workflow || `r` | Resume task (Review β Running) || `d` | Show git diff || `x` | Delete task || `/` | Search tasks |-| `P` | Select workflow plugin |+| `P` | Select spec-driven workflow plugin || `e` | Toggle project sidebar || `q` | Quit |@@ -115,6 +121,31 @@ init_script = "scripts/init_worktree.sh"Both options run during the Backlog β Research/Planning/Running transition, after worktree creationand before the agent session starts.+### Per-Phase Agent Configuration++By default, all phases use `default_agent`. You can override the agent for specific phases globally or per project:++```toml+# ~/.config/agtx/config.toml+default_agent = "claude"++[agents]+research = "claude"+planning = "claude"+running = "codex"+review = "claude"+```++```toml+# .agtx/config.toml (project override β takes precedence over global)+[agents]+running = "gemini"+```++When a task moves to a phase with a different agent configured, the current agent session is terminated and the new agent starts automatically in the same tmux window. The worktree, git state, and all file changes are preserved across the switch.++Phases without an explicit agent override keep whatever agent is currently running β no unnecessary switching occurs.+## Spec-driven Development Pluginsagtx ships with a plugin system that lets any spec-driven development framework hook into the task lifecycle. A plugin is a single TOML file that defines what happens at each phase transition β the commands sent to the agent, the prompts, the artifact files that signal completion, and optional setup scripts. Write a command once in canonical format and agtx translates it automatically for every supported agent.@@ -123,12 +154,10 @@ Press `P` to select a plugin for the current project. The active plugin is shown| Plugin | Description ||--------|-------------|+| **void** | Plain agent session - no prompting or skills, task description prefilled in input || **agtx** (default) | Built-in workflow with skills and prompts for each phase || **gsd** | [Get Shit Done](https://github.com/fynnfluegge/get-shit-done-cc) - structured spec-driven development with interactive planning || **spec-kit** | [Spec-Driven Development](https://github.com/github/spec-kit) by GitHub - specifications become executable artifacts |-| **void** | Plain agent session - no prompting or skills, task description prefilled in input |--Each task remembers the plugin it was started with. Switching plugins only affects new tasks β existing tasks continue using their original plugin throughout their lifecycle.### Agent Compatibility@@ -158,6 +187,7 @@ name = "my-plugin"description = "My custom workflow"[commands]+research = "/my-plugin:research {task}"planning = "/my-plugin:plan"running = "/my-plugin:execute"review = "/my-plugin:review"@@ -225,12 +255,12 @@ review = ""research = "What do you want to build?"```-**How it works at each phase transition:**+**What happens at each phase transition:**1. The **command** is sent to the agent via tmux (e.g., `/my-plugin:plan`)-2. If a **prompt_trigger** is set, agtx waits for that text to appear in the tmux pane+2. If a **prompt_trigger** is set, agtx waits for that prompt trigger to appear in the tmux pane3. The **prompt** is sent with `{task}` and `{task_id}` replaced-4. agtx polls for the **artifact** file β when found, the spinner becomes a checkmark+4. agtx polls for the **artifact** file β when found, the spinner becomes a checkmark to indicate task phase completion**Custom skills:** If your plugin provides its own skill files, place them in the plugin directory:diff --git a/plugins/gsd/plugin.toml b/plugins/gsd/plugin.tomlindex 877de42..b39aafe 100644--- a/plugins/gsd/plugin.toml+++ b/plugins/gsd/plugin.toml@@ -2,6 +2,8 @@ name = "gsd"description = "Get Shit Done - structured spec-driven development framework"init_script = "npx get-shit-done-cc@latest --{agent} --local --non-interactive"supported_agents = ["claude", "codex", "gemini", "opencode"]+research_required = true+copy_dirs = [".planning"][artifacts]research = ".planning/ROADMAP.md"diff --git a/skills/plan.md b/skills/plan.mdindex 1846736..437ad96 100644--- a/skills/plan.md+++ b/skills/plan.md@@ -9,10 +9,11 @@ You are in the **planning phase** of an agtx-managed task.## Instructions-1. Read and understand the task description-2. Explore the codebase to understand relevant files, patterns, and architecture-3. Identify all files that need to be created or modified-4. Create a detailed implementation plan+1. **Wait for the next message** β it contains the task title, description, and context. Do not start working until you receive it.+2. Read and understand the task description+3. Explore the codebase to understand relevant files, patterns, and architecture+4. Identify all files that need to be created or modified+5. Create a detailed implementation plan## Outputdiff --git a/skills/research.md b/skills/research.mdindex 6b69984..d2f27b2 100644--- a/skills/research.md+++ b/skills/research.md@@ -9,10 +9,11 @@ You are in the **research phase** of an agtx-managed task. This is a read-only e## Instructions-1. Read and understand the task description-2. Explore the codebase to find relevant files, patterns, and architecture-3. Identify dependencies, related code, and potential complexity-4. Assess feasibility and estimate scope+1. **Wait for the next message** β it contains the task title, description, and artifact path. Do not start working until you receive it.+2. Read and understand the task description+3. Explore the codebase to find relevant files, patterns, and architecture+4. Identify dependencies, related code, and potential complexity+5. Assess feasibility and estimate scope## Outputdiff --git a/src/agent/mod.rs b/src/agent/mod.rsindex 7b0e367..bfb9207 100644--- a/src/agent/mod.rs+++ b/src/agent/mod.rs@@ -40,7 +40,7 @@ impl Agent {if prompt.is_empty() {return match self.name.as_str() {"claude" => "claude --dangerously-skip-permissions".to_string(),- "codex" => "codex --approval-mode full-auto".to_string(),+ "codex" => "codex --full-auto".to_string(),"copilot" => "copilot --allow-all-tools".to_string(),"gemini" => "gemini --approval-mode yolo".to_string(),"opencode" => "opencode".to_string(),@@ -51,7 +51,7 @@ impl Agent {let escaped_prompt = prompt.replace('\'', "'\"'\"'");match self.name.as_str() {"claude" => format!("claude --dangerously-skip-permissions '{}'", escaped_prompt),- "codex" => format!("codex --approval-mode full-auto '{}'", escaped_prompt),+ "codex" => format!("codex --full-auto '{}'", escaped_prompt),"copilot" => format!("copilot --allow-all-tools -p '{}'", escaped_prompt),"gemini" => format!("gemini --approval-mode yolo -i '{}'", escaped_prompt),"opencode" => format!("opencode -p '{}'", escaped_prompt),diff --git a/src/agent/operations.rs b/src/agent/operations.rsindex 4e6126b..57b150e 100644--- a/src/agent/operations.rs+++ b/src/agent/operations.rs@@ -45,7 +45,7 @@ impl AgentOperations for CodingAgent {// Build the command based on agent typelet (cmd, args) = match self.agent.name.as_str() {"claude" => ("claude", vec!["--print", prompt]),- "codex" => ("codex", vec!["-q", prompt]),+ "codex" => ("codex", vec!["exec", "--full-auto", prompt]),"copilot" => ("copilot", vec!["-p", prompt]),"gemini" => ("gemini", vec!["-p", prompt]),_ => (self.agent.command.as_str(), vec![prompt]),diff --git a/src/config/mod.rs b/src/config/mod.rsindex 5332743..d71052d 100644--- a/src/config/mod.rs+++ b/src/config/mod.rs@@ -9,6 +9,10 @@ pub struct GlobalConfig {#[serde(default = "default_agent")]pub default_agent: String,+ /// Per-phase agent overrides+ #[serde(default)]+ pub agents: PhaseAgentsConfig,+/// Worktree settings#[serde(default)]pub worktree: WorktreeConfig,@@ -22,6 +26,7 @@ impl Default for GlobalConfig {fn default() -> Self {Self {default_agent: default_agent(),+ agents: PhaseAgentsConfig::default(),worktree: WorktreeConfig::default(),theme: ThemeConfig::default(),}@@ -138,6 +143,15 @@ fn default_agent() -> String {"claude".to_string()}+/// Per-phase agent overrides+#[derive(Debug, Clone, Serialize, Deserialize, Default)]+pub struct PhaseAgentsConfig {+ pub research: Option<String>,+ pub planning: Option<String>,+ pub running: Option<String>,+ pub review: Option<String>,+}+/// Worktree configuration#[derive(Debug, Clone, Serialize, Deserialize)]pub struct WorktreeConfig {@@ -178,6 +192,9 @@ pub struct ProjectConfig {/// Override default agent for this projectpub default_agent: Option<String>,+ /// Per-phase agent overrides for this project+ pub agents: Option<PhaseAgentsConfig>,+/// Override base branch for this projectpub base_branch: Option<String>,@@ -302,6 +319,7 @@ pub fn determine_first_run_action(#[derive(Debug, Clone)]pub struct MergedConfig {pub default_agent: String,+ pub phase_agents: PhaseAgentsConfig,pub worktree_enabled: bool,pub auto_cleanup: bool,pub base_branch: String,@@ -315,11 +333,18 @@ pub struct MergedConfig {impl MergedConfig {/// Create merged config from global and project configspub fn merge(global: &GlobalConfig, project: &ProjectConfig) -> Self {+ let project_agents = project.agents.clone().unwrap_or_default();Self {default_agent: project.default_agent.clone().unwrap_or_else(|| global.default_agent.clone()),+ phase_agents: PhaseAgentsConfig {+ research: project_agents.research.or(global.agents.research.clone()),+ planning: project_agents.planning.or(global.agents.planning.clone()),+ running: project_agents.running.or(global.agents.running.clone()),+ review: project_agents.review.or(global.agents.review.clone()),+ },worktree_enabled: global.worktree.enabled,auto_cleanup: global.worktree.auto_cleanup,base_branch: project@@ -333,6 +358,25 @@ impl MergedConfig {workflow_plugin: project.workflow_plugin.clone(),}}++ /// Get the agent name for a given phase.+ /// Falls back to default_agent if no phase-specific override is set.+ pub fn agent_for_phase(&self, phase: &str) -> &str {+ self.explicit_agent_for_phase(phase)+ .unwrap_or(&self.default_agent)+ }++ /// Get the explicitly configured agent for a phase, if any.+ /// Returns None when no phase-specific override is set (no fallback).+ pub fn explicit_agent_for_phase(&self, phase: &str) -> Option<&str> {+ match phase {+ "research" => self.phase_agents.research.as_deref(),+ "planning" | "planning_with_research" => self.phase_agents.planning.as_deref(),+ "running" => self.phase_agents.running.as_deref(),+ "review" => self.phase_agents.review.as_deref(),+ _ => None,+ }+ }}/// Workflow plugin configuration loaded from plugin.toml@@ -353,6 +397,10 @@ pub struct WorkflowPlugin {pub prompts: PluginPrompts,#[serde(default)]pub prompt_triggers: PluginPromptTriggers,+ /// When true, research phase must be completed before planning or running.+ /// Prevents skipping research for plugins that depend on it (e.g. GSD creates .planning/ during research).+ #[serde(default)]+ pub research_required: bool,/// Extra directories to copy from project root to worktrees (e.g. [".specify"]).#[serde(default)]pub copy_dirs: Vec<String>,diff --git a/src/main.rs b/src/main.rsindex 1d5c1e1..360c412 100644--- a/src/main.rs+++ b/src/main.rs@@ -96,17 +96,18 @@ fn prompt_agent_selection(agents: &[agent::Agent]) -> Result<&agent::Agent> {stdout.execute(cursor::Hide)?;// Print ASCII art banner+ let gold = style::Color::Rgb { r: 234, g: 212, b: 154 }; // #ead49alet banner: &[(&str, &str)] = &[- (" ββββββ βββββββ ββββββββββββ βββ", ""),- (" ββββββββββββββββ βββββββββββββββββ", ""),- (" βββββββββββ ββββ βββ ββββββ ", " Autonomous multi-session"),- (" βββββββββββ βββ βββ ββββββ ", " AI coding in the terminal"),- (" βββ ββββββββββββ βββ ββββ βββ", ""),- (" βββ βββ βββββββ βββ βββ βββ", ""),+ (" ββββββ βββββββββββββββββββ βββ", ""),+ ("βββββββββββββββββββββββββββββββββ", ""),+ ("βββββββββββ ββββ βββ ββββββ ", " Autonomous multi-session spec-driven"),+ ("βββββββββββ βββ βββ ββββββ ", " AI coding orchestration in the terminal"),+ ("βββ ββββββββββββ βββ ββββ βββ", ""),+ ("βββ βββ βββββββ βββ βββ βββ", ""),];stdout.execute(style::Print("\r\n"))?;for (art, tagline) in banner {- stdout.execute(style::PrintStyledContent((*art).cyan()))?;+ stdout.execute(style::PrintStyledContent(style::style(format!(" {}", art)).with(gold)))?;if !tagline.is_empty() {stdout.execute(style::PrintStyledContent((*tagline).dark_grey()))?;}diff --git a/src/skills.rs b/src/skills.rsindex 87d2f28..85c440b 100644--- a/src/skills.rs+++ b/src/skills.rs@@ -24,7 +24,7 @@ pub const DEFAULT_PROMPT_RESEARCH: &str =pub const DEFAULT_PROMPT_PLANNING: &str ="Task: {task}";pub const DEFAULT_PROMPT_PLANNING_WITH_RESEARCH: &str =- "Task: {task}\n\nResearch findings are available in .agtx/research.md β use them as context.";+ "Task: {task}\n\nIf research was done, findings are available in .agtx/research/{task_id}.md β use them as context if present.";pub const DEFAULT_PROMPT_RUNNING: &str ="Plan approved. Implement the changes described in .agtx/plan.md";pub const DEFAULT_PROMPT_REVIEW: &str =@@ -38,7 +38,7 @@ pub fn agent_native_skill_dir(agent_name: &str) -> Option<(&'static str, &'statimatch agent_name {"claude" => Some((".claude/commands", "agtx")),"gemini" => Some((".gemini/commands", "agtx")),- "opencode" => Some((".config/opencode/command", "")),+ "opencode" => Some((".opencode/commands", "")),"codex" => Some((".codex/skills", "")),"copilot" => Some((".github/agents", "agtx")),_ => None,diff --git a/src/tmux/operations.rs b/src/tmux/operations.rsindex 875528e..4de33b5 100644--- a/src/tmux/operations.rs+++ b/src/tmux/operations.rs@@ -41,6 +41,9 @@ pub trait TmuxOperations: Send + Sync {/// Resize a tmux windowfn resize_window(&self, target: &str, width: u16, height: u16) -> Result<()>;+ /// Get the current command running in a pane (e.g. "claude", "bash", "zsh")+ fn pane_current_command(&self, target: &str) -> Option<String>;+/// Check if a session existsfn has_session(&self, session: &str) -> bool;@@ -95,12 +98,10 @@ impl TmuxOperations for RealTmuxOps {}fn send_keys(&self, target: &str, keys: &str) -> Result<()> {- // Send the text firststd::process::Command::new("tmux").args(["-L", super::AGENT_SERVER]).args(["send-keys", "-t", target, keys]).output()?;- // Send Enter separately (like the original implementation)std::process::Command::new("tmux").args(["-L", super::AGENT_SERVER]).args(["send-keys", "-t", target, "Enter"])@@ -163,6 +164,20 @@ impl TmuxOperations for RealTmuxOps {Ok(())}+ fn pane_current_command(&self, target: &str) -> Option<String> {+ let output = std::process::Command::new("tmux")+ .args(["-L", super::AGENT_SERVER])+ .args(["display", "-p", "-t", target, "#{pane_current_command}"])+ .output()+ .ok()?;+ if output.status.success() {+ let cmd = String::from_utf8_lossy(&output.stdout).trim().to_string();+ if !cmd.is_empty() { Some(cmd) } else { None }+ } else {+ None+ }+ }+fn has_session(&self, session: &str) -> bool {std::process::Command::new("tmux").args(["-L", super::AGENT_SERVER])diff --git a/src/tui/app.rs b/src/tui/app.rsindex ea30389..9e02fb9 100644--- a/src/tui/app.rs+++ b/src/tui/app.rs@@ -53,8 +53,8 @@ fn build_footer_text(input_mode: InputMode, sidebar_focused: bool, selected_colutype Terminal = ratatui::Terminal<CrosstermBackend<Stdout>>;/// Shell popup dimensions - used for both rendering and tmux window sizing-const SHELL_POPUP_WIDTH: u16 = 82; // Total width including borders-const SHELL_POPUP_CONTENT_WIDTH: u16 = 80; // Content width (SHELL_POPUP_WIDTH - 2 for borders)+const SHELL_POPUP_WIDTH: u16 = 128; // Total width including borders+const SHELL_POPUP_CONTENT_WIDTH: u16 = 126; // Content width (SHELL_POPUP_WIDTH - 2 for borders)const SHELL_POPUP_HEIGHT_PERCENT: u16 = 75; // Percentage of terminal height/// Application state (separate from terminal for borrow checker)@@ -114,10 +114,16 @@ struct AppState {pr_creation_rx: Option<mpsc::Receiver<Result<(i32, String), String>>>,// Confirmation popup for moving to Done with open PRdone_confirm_popup: Option<DoneConfirmPopup>,+ // Confirmation popup for moving task when phase is incomplete+ move_confirm_popup: Option<MoveConfirmPopup>,+ // Flag to skip move confirmation (set after user confirms popup)+ skip_move_confirm: bool,// Confirmation popup for deleting a taskdelete_confirm_popup: Option<DeleteConfirmPopup>,// Confirmation popup for asking if user wants to create PR when moving to Reviewreview_confirm_popup: Option<ReviewConfirmPopup>,+ // Channel for receiving background worktree setup results+ setup_rx: Option<mpsc::Receiver<SetupResult>>,// Phase detectionphase_status_cache: HashMap<String, (PhaseStatus, Instant)>,spinner_frame: usize,@@ -141,9 +147,30 @@ enum DoneConfirmPrState {Open,Merged,Closed,+ UncommittedChanges,Unknown,}+/// State for confirming move when phase is incomplete (agent still working)+#[derive(Debug, Clone)]+struct MoveConfirmPopup {+ task_id: String,+ from_status: TaskStatus,+ to_status: TaskStatus,+}++/// Result from background worktree setup (research, planning, move-to-running)+struct SetupResult {+ task_id: String,+ session_name: String,+ worktree_path: String,+ branch_name: String,+ new_status: Option<TaskStatus>,+ agent: String,+ plugin: Option<String>,+ error: Option<String>,+}+/// State for PR creation status popup (loading/success/error)#[derive(Debug, Clone)]struct PrStatusPopup {@@ -349,7 +376,10 @@ impl App {pr_generation_rx: None,pr_status_popup: None,pr_creation_rx: None,+ setup_rx: None,done_confirm_popup: None,+ move_confirm_popup: None,+ skip_move_confirm: false,delete_confirm_popup: None,review_confirm_popup: None,phase_status_cache: HashMap::new(),@@ -414,6 +444,33 @@ impl App {}}+ // Check for worktree setup completion+ if let Some(ref rx) = self.state.setup_rx {+ if let Ok(result) = rx.try_recv() {+ self.state.setup_rx = None;+ if let Some(err) = result.error {+ self.state.warning_message = Some((err, Instant::now()));+ } else {+ // Update task with worktree info from background setup+ if let Some(db) = &self.state.db {+ if let Ok(Some(mut task)) = db.get_task(&result.task_id) {+ task.session_name = Some(result.session_name);+ task.worktree_path = Some(result.worktree_path);+ task.branch_name = Some(result.branch_name);+ task.agent = result.agent;+ task.plugin = result.plugin;+ if let Some(status) = result.new_status {+ task.status = status;+ }+ task.updated_at = chrono::Utc::now();+ let _ = db.update_task(&task);+ }+ }+ self.refresh_tasks()?;+ }+ }+ }+if event::poll(std::time::Duration::from_millis(100))? {if let Event::Key(key) = event::read()? {if key.kind == KeyEventKind::Press {@@ -1083,7 +1140,39 @@ impl App {"PR #{} state unknown.\n\nAre you sure you want to move this task to Done?\n\nWorktree will be deleted, tmux coding session killed.\nBranch kept locally.\n\n[y] Yes, move to Done [n/Esc] Cancel",popup.pr_number),+ DoneConfirmPrState::UncommittedChanges => String::from(+ "There are uncommitted changes in the worktree.\n\nAre you sure you want to move this task to Done?\n\nUncommitted changes will be lost.\nWorktree will be deleted, tmux coding session killed.\nBranch kept locally.\n\n[y] Yes, move to Done [n/Esc] Cancel"+ ),+ };+ let content = Paragraph::new(text)+ .style(Style::default().fg(Color::White))+ .alignment(ratatui::layout::Alignment::Center)+ .wrap(Wrap { trim: false });+ frame.render_widget(content, inner);+ }++ // Move confirmation popup (phase incomplete)+ if let Some(ref popup) = state.move_confirm_popup {+ let popup_area = centered_rect(50, 20, area);+ frame.render_widget(Clear, popup_area);++ let phase_name = match popup.from_status {+ TaskStatus::Planning => "Planning",+ TaskStatus::Running => "Running",+ TaskStatus::Review => "Review",+ _ => "Current",};+ let main_block = Block::default()+ .title(format!(" {} Phase Incomplete ", phase_name))+ .borders(Borders::ALL)+ .border_style(Style::default().fg(hex_to_color(&state.config.theme.color_selected)));+ frame.render_widget(main_block, popup_area);++ let inner = popup_area.inner(ratatui::layout::Margin { horizontal: 2, vertical: 2 });+ let text = format!(+ "The agent is still working and the {} artifact\nhas not been created yet.\n\nAre you sure you want to move this task forward?\n\n[y] Yes, move [n/Esc] Cancel",+ phase_name.to_lowercase()+ );let content = Paragraph::new(text).style(Style::default().fg(Color::White)).alignment(ratatui::layout::Alignment::Center)@@ -1333,13 +1422,17 @@ impl App {frame.render_widget(title_line, title_area);}+ // Footer line with agent name (for active tasks)+ let show_agent = task.status != TaskStatus::Backlog || task.session_name.is_some();+ let footer_height = if show_agent && inner.height > 2 { 1u16 } else { 0u16 };+// Preview area (below title) - always show description- if inner.height > 1 {+ if inner.height > 1 + footer_height {let preview_area = Rect {x: inner.x,y: inner.y + 1,width: inner.width,- height: inner.height.saturating_sub(1),+ height: inner.height.saturating_sub(1 + footer_height),};// Show description or placeholder@@ -1358,6 +1451,27 @@ impl App {.wrap(Wrap { trim: true });frame.render_widget(preview, preview_area);}++ // Agent footer+ if footer_height > 0 {+ let footer_area = Rect {+ x: inner.x,+ y: inner.y + inner.height.saturating_sub(1),+ width: inner.width,+ height: 1,+ };+ let agent_style = match task.agent.as_str() {+ "claude" => Style::default().fg(Color::Rgb(227, 148, 62)), // orange+ "gemini" => Style::default().fg(Color::Rgb(234, 130, 180)), // pink+ "opencode" => Style::default().fg(Color::White).bg(Color::Rgb(80, 80, 80)), // white on grey+ "codex" => Style::default().fg(Color::White).bg(Color::Rgb(20, 20, 20)), // white on black+ _ => Style::default().fg(Color::White),+ };+ let agent_label = Paragraph::new(format!(" {} ", task.agent))+ .style(agent_style)+ .alignment(Alignment::Right);+ frame.render_widget(agent_label, footer_area);+ }}fn draw_sidebar(state: &AppState, frame: &mut Frame, area: Rect) {@@ -1402,42 +1516,37 @@ impl App {}fn draw_dashboard(state: &AppState, frame: &mut Frame, area: Rect) {- let chunks = Layout::default()- .direction(Direction::Vertical)- .constraints([- Constraint::Length(3),- Constraint::Min(0),- Constraint::Length(3),- ])- .split(area);-- // Header- let header = Paragraph::new(" agtx Dashboard ")- .style(Style::default().fg(Color::Cyan).bold())- .block(Block::default().borders(Borders::ALL));- frame.render_widget(header, chunks[0]);+ let dimmed_color = hex_to_color(&state.config.theme.color_dimmed);+ let selected_color = hex_to_color(&state.config.theme.color_selected);- // Content area split: message + options/project list- let content_chunks = Layout::default()+ let chunks = Layout::default().direction(Direction::Vertical).constraints([- Constraint::Length(5), // Message+ Constraint::Length(10), // Logo + subtitleConstraint::Min(0), // Project list or options+ Constraint::Length(3), // Footer])- .split(chunks[1]);-- let dimmed_color = hex_to_color(&state.config.theme.color_dimmed);- let selected_color = hex_to_color(&state.config.theme.color_selected);+ .split(area);- // Message- let message = Paragraph::new("\n No project found in current directory.\n")- .style(Style::default().fg(selected_color))- .block(Block::default().borders(Borders::ALL).border_style(Style::default().fg(dimmed_color)));- frame.render_widget(message, content_chunks[0]);+ // ASCII art logo β hardcoded gold to match docs/banner.svg+ let logo_color = Color::Rgb(234, 212, 154); // #ead49a+ let logo = vec![+ Line::from(""),+ Line::from(Span::styled(" ββββββ βββββββββββββββββββ βββ", Style::default().fg(logo_color).bold())),+ Line::from(Span::styled("βββββββββββββββββββββββββββββββββ", Style::default().fg(logo_color).bold())),+ Line::from(Span::styled("βββββββββββ ββββ βββ ββββββ ", Style::default().fg(logo_color).bold())),+ Line::from(Span::styled("βββββββββββ βββ βββ ββββββ ", Style::default().fg(logo_color).bold())),+ Line::from(Span::styled("βββ ββββββββββββ βββ ββββ βββ", Style::default().fg(logo_color).bold())),+ Line::from(Span::styled("βββ βββ βββββββ βββ βββ βββ", Style::default().fg(logo_color).bold())),+ Line::from(""),+ Line::from(Span::styled("Autonomous multi-session spec-driven AI coding orchestration in the terminal", Style::default().fg(dimmed_color))),+ ];+ let logo_widget = Paragraph::new(logo)+ .alignment(Alignment::Center);+ frame.render_widget(logo_widget, chunks[0]);// Project list or optionsif state.show_project_list && !state.projects.is_empty() {- // Show project listlet items: Vec<ListItem> = state.projects.iter()@@ -1459,14 +1568,13 @@ impl App {.borders(Borders::ALL).border_style(Style::default().fg(selected_color)),);- frame.render_widget(list, content_chunks[1]);+ frame.render_widget(list, chunks[1]);} else {- // Show optionslet options = Paragraph::new("\n [p] Open existing project\n [n] Create new project in current directory\n",).block(Block::default().title(" Options ").borders(Borders::ALL).border_style(Style::default().fg(dimmed_color)));- frame.render_widget(options, content_chunks[1]);+ frame.render_widget(options, chunks[1]);}// Footer@@ -1488,6 +1596,11 @@ impl App {return Ok(());}+ // Handle Move confirmation popup if open (phase incomplete)+ if self.state.move_confirm_popup.is_some() {+ return self.handle_move_confirm_key(key);+ }+// Handle Done confirmation popup if openif self.state.done_confirm_popup.is_some() {return self.handle_done_confirm_key(key);@@ -1559,6 +1672,24 @@ impl App {Ok(())}+ fn handle_move_confirm_key(&mut self, key: crossterm::event::KeyEvent) -> Result<()> {+ if self.state.move_confirm_popup.is_some() {+ match key.code {+ KeyCode::Char('y') | KeyCode::Char('Y') => {+ self.state.move_confirm_popup = None;+ self.state.skip_move_confirm = true;+ self.move_task_right()?;+ self.state.skip_move_confirm = false;+ }+ KeyCode::Char('n') | KeyCode::Char('N') | KeyCode::Esc => {+ self.state.move_confirm_popup = None;+ }+ _ => {}+ }+ }+ Ok(())+ }+fn handle_delete_confirm_key(&mut self, key: crossterm::event::KeyEvent) -> Result<()> {if let Some(popup) = self.state.delete_confirm_popup.clone() {match key.code {@@ -1691,14 +1822,28 @@ impl App {fn force_move_to_done(&mut self, task_id: &str) -> Result<()> {if let (Some(db), Some(project_path)) = (&self.state.db, self.state.project_path.clone()) {if let Some(mut task) = db.get_task(task_id)? {- cleanup_task_for_done(- &mut task,- &project_path,- self.state.tmux_ops.as_ref(),- self.state.git_ops.as_ref(),- );+ let session_name = task.session_name.clone();+ let worktree_path = task.worktree_path.clone();+ let branch_name = task.branch_name.clone();++ // Update task status immediately+ task.session_name = None;+ task.worktree_path = None;+ task.status = TaskStatus::Done;+ task.updated_at = chrono::Utc::now();db.update_task(&task)?;self.refresh_tasks()?;++ // Cleanup in background (archive, kill tmux, remove worktree)+ let tmux_ops = Arc::clone(&self.state.tmux_ops);+ let git_ops = Arc::clone(&self.state.git_ops);+ let task_id = task.id.clone();+ std::thread::spawn(move || {+ cleanup_task_resources(+ &task_id, &branch_name, &session_name, &worktree_path,+ &project_path, tmux_ops.as_ref(), git_ops.as_ref(),+ );+ });}}Ok(())@@ -2732,6 +2877,30 @@ impl App {};if let Some(new_status) = next_status {+ // Check if phase is incomplete and agent is still working+ if !self.state.skip_move_confirm+ && matches!(current_status, TaskStatus::Planning | TaskStatus::Running | TaskStatus::Review)+ {+ let plugin = self.load_task_plugin(&task);+ if let Some(ref wt_path) = task.worktree_path {+ if !phase_artifact_exists(wt_path, current_status, &plugin) {+ // Check if agent is still running in the tmux pane+ let agent_running = task.session_name.as_ref().map_or(false, |target| {+ self.state.tmux_ops.window_exists(target).unwrap_or(false)+ && is_agent_active(&*self.state.tmux_ops, target)+ });+ if agent_running {+ self.state.move_confirm_popup = Some(MoveConfirmPopup {+ task_id: task.id.clone(),+ from_status: current_status,+ to_status: new_status,+ });+ return Ok(());+ }+ }+ }+ }+// Create worktree and tmux window when moving from Backlog to Planningif current_status == TaskStatus::Backlog && new_status == TaskStatus::Planning {// Stamp plugin on task if not already set (may be set from research)@@ -2740,136 +2909,205 @@ impl App {}let plugin = self.load_task_plugin(&task);+ // Block if plugin requires research and it hasn't been completed+ if plugin.as_ref().map_or(false, |p| p.research_required) {+ let has_research = task.worktree_path.as_ref().map_or(false, |wt| {+ research_artifact_exists(wt, &task.id, &plugin)+ });+ if !has_research {+ self.state.warning_message = Some((+ format!("Research phase required first β press R to start research"),+ std::time::Instant::now(),+ ));+ return Ok(());+ }+ }++ let (planning_agent, agent_switch) = needs_agent_switch(&self.state.config, &task, "planning");+let has_live_session = task.session_name.as_ref().map_or(false, |s| {self.state.tmux_ops.window_exists(s).unwrap_or(false)});if has_live_session {- // Reuse existing session from research β just send planning command+ // Reuse existing session from research β switch agent if needed, then send planning commandlet target = task.session_name.clone().unwrap();let task_content = if let Some(desc) = &task.description {- format!("{}\n\n{}", task.title, desc)+ desc.clone()} else {task.title.clone()};- let skill_cmd = resolve_skill_command(&plugin, "planning", &self.state.config.default_agent, &task_content);- let prompt = resolve_prompt(&plugin, "planning", &task_content, &task.id, &self.state.config.default_agent);+ // If research artifact exists, agent already has context β don't resend task description+ let has_research = task.worktree_path.as_ref().map_or(false, |wt| {+ research_artifact_exists(wt, &task.id, &plugin)+ });+ let planning_phase = if has_research { "planning_with_research" } else { "planning" };+ let skill_cmd = resolve_skill_command(&plugin, planning_phase, &planning_agent, &task_content);+ let prompt = resolve_prompt(&plugin, planning_phase, &task_content, &task.id, &planning_agent);+ let prompt_trigger = resolve_prompt_trigger(&plugin, planning_phase);let tmux_ops = Arc::clone(&self.state.tmux_ops);let task_content_clone = task_content.clone();+ let agent_registry = Arc::clone(&self.state.agent_registry);+ let planning_agent_clone = planning_agent.clone();+ let current_agent_clone = task.agent.clone();std::thread::spawn(move || {- if let Some(ref cmd) = skill_cmd {- let _ = tmux_ops.send_keys(&target, cmd);- std::thread::sleep(std::time::Duration::from_millis(500));- }- if !prompt.is_empty() {- let _ = tmux_ops.send_keys(&target, &prompt);- } else if skill_cmd.is_none() {- // No command and no prompt (e.g. void plugin): prefill task in input- let oneline = task_content_clone.lines().map(|l| l.trim()).filter(|l| !l.is_empty()).collect::<Vec<_>>().join(" ");- if !oneline.is_empty() {- let _ = tmux_ops.send_keys_literal(&target, &oneline);- }+ if agent_switch {+ let agent_ops = agent_registry.get(&planning_agent_clone);+ let new_cmd = agent_ops.build_interactive_command("");+ switch_agent_in_tmux(tmux_ops.as_ref(), &target, ¤t_agent_clone, &new_cmd);+ let _ = wait_for_agent_ready(&tmux_ops, &target);}+ send_skill_and_prompt(&tmux_ops, &target, &skill_cmd, &prompt, &prompt_trigger, &task_content_clone, &planning_agent_clone);});+ } else if self.state.setup_rx.is_some() {+ // Setup already in progress, skip+ return Ok(());} else {- // No research session β create worktree + tmux window from scratch+ // No research session β create worktree + tmux window from scratch (non-blocking)let task_content = if let Some(desc) = &task.description {- format!("{}\n\n{}", task.title, desc)+ desc.clone()} else {task.title.clone()};- let prompt = resolve_prompt(&plugin, "planning", &task_content, &task.id, &self.state.config.default_agent);-- let target = setup_task_worktree(- &mut task,- &project_path,- &self.state.project_name,- &prompt,- self.state.config.copy_files.clone(),- self.state.config.init_script.clone(),- &plugin,- &self.state.config.default_agent,- self.state.tmux_ops.as_ref(),- self.state.git_ops.as_ref(),- self.state.agent_registry.get(&self.state.config.default_agent).as_ref(),- )?;-- // Wait for agent to be ready, then send skill command and task content- let target_clone = target.clone();- let tmux_ops = Arc::clone(&self.state.tmux_ops);- let skill_cmd = resolve_skill_command(&plugin, "planning", &self.state.config.default_agent, &task_content);- let prompt_clone = prompt.clone();+ let prompt = resolve_prompt(&plugin, "planning", &task_content, &task.id, &planning_agent);+ let skill_cmd = resolve_skill_command(&plugin, "planning", &planning_agent, &task_content);let prompt_trigger = resolve_prompt_trigger(&plugin, "planning");- let task_content_clone = task_content.clone();+ let all_agents = collect_phase_agents(&self.state.config);+ let project_name = self.state.project_name.clone();+ let copy_files = self.state.config.copy_files.clone();+ let init_script = self.state.config.init_script.clone();+ let tmux_ops = Arc::clone(&self.state.tmux_ops);+ let git_ops = Arc::clone(&self.state.git_ops);+ let agent_ops = self.state.agent_registry.get(&planning_agent);+ let task_id = task.id.clone();+ let task_title = task.title.clone();+ let plugin_name = task.plugin.clone();+ let planning_agent_clone = planning_agent.clone();++ let (tx, rx) = mpsc::channel();+ self.state.setup_rx = Some(rx);+std::thread::spawn(move || {- if let Some(target) = wait_for_agent_ready(&tmux_ops, &target_clone) {- if let Some(ref cmd) = skill_cmd {- let _ = tmux_ops.send_keys(&target, cmd);- std::thread::sleep(std::time::Duration::from_millis(500));- }- if !prompt_clone.is_empty() {- if let Some(ref trigger) = prompt_trigger {- if wait_for_prompt_trigger(&tmux_ops, &target, trigger) {- std::thread::sleep(std::time::Duration::from_millis(500));- let _ = tmux_ops.send_keys(&target, &prompt_clone);- }- } else {- let _ = tmux_ops.send_keys(&target, &prompt_clone);- }- } else if skill_cmd.is_none() {- // No command and no prompt (e.g. void plugin): prefill task in input- let oneline = task_content_clone.lines().map(|l| l.trim()).filter(|l| !l.is_empty()).collect::<Vec<_>>().join(" ");- if !oneline.is_empty() {- let _ = tmux_ops.send_keys_literal(&target, &oneline);+ let mut tmp_task = Task::new(&task_title, &planning_agent_clone, &project_name);+ tmp_task.id = task_id.clone();+ tmp_task.plugin = plugin_name.clone();++ let result = setup_task_worktree(+ &mut tmp_task,+ &project_path,+ &project_name,+ &prompt,+ copy_files,+ init_script,+ &plugin,+ &planning_agent_clone,+ &all_agents,+ tmux_ops.as_ref(),+ git_ops.as_ref(),+ agent_ops.as_ref(),+ );++ match result {+ Ok(target) => {+ let _ = tx.send(SetupResult {+ task_id: task_id.clone(),+ session_name: tmp_task.session_name.unwrap_or_default(),+ worktree_path: tmp_task.worktree_path.unwrap_or_default(),+ branch_name: tmp_task.branch_name.unwrap_or_default(),+ new_status: Some(TaskStatus::Planning),+ agent: planning_agent_clone.clone(),+ plugin: plugin_name,+ error: None,+ });++ if let Some(target) = wait_for_agent_ready(&tmux_ops, &target) {+ send_skill_and_prompt(&tmux_ops, &target, &skill_cmd, &prompt, &prompt_trigger, &task_content, &planning_agent_clone);}}+ Err(e) => {+ let _ = tx.send(SetupResult {+ task_id,+ session_name: String::new(),+ worktree_path: String::new(),+ branch_name: String::new(),+ new_status: None,+ agent: planning_agent_clone,+ plugin: plugin_name,+ error: Some(format!("Planning setup failed: {}", e)),+ });+ }}});++ return Ok(());}+ task.agent = planning_agent;}// When moving from Planning to Running, send skill command to agentif current_status == TaskStatus::Planning && new_status == TaskStatus::Running {if let Some(session_name) = &task.session_name {let plugin = self.load_task_plugin(&task);+ let (running_agent, agent_switch) = needs_agent_switch(&self.state.config, &task, "running");let task_content = if let Some(desc) = &task.description {- format!("{}\n\n{}", task.title, desc)+ desc.clone()} else {task.title.clone()};- let skill_cmd = resolve_skill_command(&plugin, "running", &self.state.config.default_agent, &task_content);- if let Some(cmd) = skill_cmd {- let _ = self.state.tmux_ops.send_keys(session_name, &cmd);- } else {- let msg = resolve_prompt(&plugin, "running", &task_content, &task.id, &self.state.config.default_agent);- if !msg.is_empty() {- let _ = self.state.tmux_ops.send_keys(session_name, &msg);+ let skill_cmd = resolve_skill_command(&plugin, "running", &running_agent, &task_content);+ let prompt = resolve_prompt(&plugin, "running", &task_content, &task.id, &running_agent);+ let prompt_trigger = resolve_prompt_trigger(&plugin, "running");+ let session_clone = session_name.clone();+ let tmux_ops = Arc::clone(&self.state.tmux_ops);+ let agent_registry = Arc::clone(&self.state.agent_registry);+ let running_agent_clone = running_agent.clone();+ let current_agent_clone = task.agent.clone();+ let task_content_clone = task_content.clone();+ std::thread::spawn(move || {+ if agent_switch {+ let agent_ops = agent_registry.get(&running_agent_clone);+ let new_cmd = agent_ops.build_interactive_command("");+ switch_agent_in_tmux(tmux_ops.as_ref(), &session_clone, ¤t_agent_clone, &new_cmd);+ let _ = wait_for_agent_ready(&tmux_ops, &session_clone);}- }+ send_skill_and_prompt(&tmux_ops, &session_clone, &skill_cmd, &prompt, &prompt_trigger, &task_content_clone, &running_agent_clone);+ });+ task.agent = running_agent;}}// When moving from Running to Review: send skill command, then ask about PRif current_status == TaskStatus::Running && new_status == TaskStatus::Review {- // Send review skill command to agent+ // Send review skill command to agent (with optional agent switch)+ let (review_agent, agent_switch) = needs_agent_switch(&self.state.config, &task, "review");if let Some(session_name) = &task.session_name {let plugin = self.load_task_plugin(&task);let task_content = if let Some(desc) = &task.description {- format!("{}\n\n{}", task.title, desc)+ desc.clone()} else {task.title.clone()};- let skill_cmd = resolve_skill_command(&plugin, "review", &self.state.config.default_agent, &task_content);- if let Some(cmd) = skill_cmd {- let _ = self.state.tmux_ops.send_keys(session_name, &cmd);- } else {- let msg = resolve_prompt(&plugin, "review", &task_content, &task.id, &self.state.config.default_agent);- if !msg.is_empty() {- let _ = self.state.tmux_ops.send_keys(session_name, &msg);+ let skill_cmd = resolve_skill_command(&plugin, "review", &review_agent, &task_content);+ let prompt = resolve_prompt(&plugin, "review", &task_content, &task.id, &review_agent);+ let prompt_trigger = resolve_prompt_trigger(&plugin, "review");+ let session_clone = session_name.clone();+ let tmux_ops = Arc::clone(&self.state.tmux_ops);+ let agent_registry = Arc::clone(&self.state.agent_registry);+ let review_agent_clone = review_agent.clone();+ let current_agent_clone = task.agent.clone();+ let task_content_clone = task_content.clone();+ std::thread::spawn(move || {+ if agent_switch {+ let agent_ops = agent_registry.get(&review_agent_clone);+ let new_cmd = agent_ops.build_interactive_command("");+ switch_agent_in_tmux(tmux_ops.as_ref(), &session_clone, ¤t_agent_clone, &new_cmd);+ let _ = wait_for_agent_ready(&tmux_ops, &session_clone);}- }+ send_skill_and_prompt(&tmux_ops, &session_clone, &skill_cmd, &prompt, &prompt_trigger, &task_content_clone, &review_agent_clone);+ });}+ task.agent = review_agent.clone();// Check if PR already exists (task was resumed from Review)if task.pr_number.is_some() {// PR already exists - just commit and push the new changes@@ -2882,7 +3120,7 @@ impl App {let task_clone = task.clone();let project_path_clone = project_path.clone();let git_ops = Arc::clone(&self.state.git_ops);- let agent_ops = self.state.agent_registry.get(&self.state.config.default_agent);+ let agent_ops = self.state.agent_registry.get(&review_agent);let (tx, rx) = mpsc::channel();self.state.pr_creation_rx = Some(rx);@@ -2939,14 +3177,36 @@ impl App {});return Ok(());}- // No PR - allow moving to Done directly (task might have been abandoned early)- // Cleanup resources (but don't set status yet - that's done below)- cleanup_task_for_done(- &mut task,- &project_path,- self.state.tmux_ops.as_ref(),- self.state.git_ops.as_ref(),- );+ // No PR - check for uncommitted changes before allowing move to Done+ let has_uncommitted = task.worktree_path.as_ref().map_or(false, |wt| {+ self.state.git_ops.has_changes(Path::new(wt))+ });+ if has_uncommitted {+ self.state.done_confirm_popup = Some(DoneConfirmPopup {+ task_id: task.id.clone(),+ pr_number: 0,+ pr_state: DoneConfirmPrState::UncommittedChanges,+ });+ return Ok(());+ }++ // Cleanup resources in background (archive, kill tmux, remove worktree)+ let session_name = task.session_name.clone();+ let worktree_path = task.worktree_path.clone();+ let branch_name = task.branch_name.clone();+ task.session_name = None;+ task.worktree_path = None;++ let tmux_ops = Arc::clone(&self.state.tmux_ops);+ let git_ops = Arc::clone(&self.state.git_ops);+ let task_id_clone = task.id.clone();+ let project_path_clone = project_path.clone();+ std::thread::spawn(move || {+ cleanup_task_resources(+ &task_id_clone, &branch_name, &session_name, &worktree_path,+ &project_path_clone, tmux_ops.as_ref(), git_ops.as_ref(),+ );+ });}task.status = new_status;@@ -2962,85 +3222,108 @@ impl App {/// Start a research session for a Backlog task (creates worktree, reused in planning)fn start_research(&mut self, task_id: &str) -> Result<()> {+ // Don't start if a setup is already in progress+ if self.state.setup_rx.is_some() { return Ok(()) }+let mut task = {let Some(db) = &self.state.db else { return Ok(()) };let Some(task) = db.get_task(task_id)? else { return Ok(()) };task};let Some(project_path) = self.state.project_path.clone() else { return Ok(()) };+// Stamp plugin on task for researchtask.plugin = self.state.config.workflow_plugin.clone();+ let plugin_name = task.plugin.clone();let plugin = self.load_task_plugin(&task);- let agent_name = self.state.config.default_agent.clone();+ let agent_name = self.state.config.agent_for_phase("research").to_string();let task_content = if let Some(desc) = &task.description {- format!("{}\n\n{}", task.title, desc)+ desc.clone()} else {task.title.clone()};let prompt = resolve_prompt(&plugin, "research", &task_content, &task.id, &agent_name);-- // Create worktree + tmux window (same as planning, so it can be reused)- let target = setup_task_worktree(- &mut task,- &project_path,- &self.state.project_name,- &prompt,- self.state.config.copy_files.clone(),- self.state.config.init_script.clone(),- &plugin,- &agent_name,- self.state.tmux_ops.as_ref(),- self.state.git_ops.as_ref(),- self.state.agent_registry.get(&agent_name).as_ref(),- )?;-- // Send research skill command + task prompt (with optional trigger polling)- let target_clone = target.clone();- let tmux_ops = Arc::clone(&self.state.tmux_ops);let skill_cmd = resolve_skill_command(&plugin, "research", &agent_name, &task_content);- let prompt_clone = prompt.clone();let prompt_trigger = resolve_prompt_trigger(&plugin, "research");- let task_content_clone = task_content.clone();+ let all_agents = collect_phase_agents(&self.state.config);+ let project_name = self.state.project_name.clone();+ let copy_files = self.state.config.copy_files.clone();+ let init_script = self.state.config.init_script.clone();++ let tmux_ops = Arc::clone(&self.state.tmux_ops);+ let git_ops = Arc::clone(&self.state.git_ops);+ let agent_ops = self.state.agent_registry.get(&agent_name);++ let task_id = task.id.clone();+ let task_title = task.title.clone();++ let (tx, rx) = mpsc::channel();+ self.state.setup_rx = Some(rx);+std::thread::spawn(move || {- if let Some(target) = wait_for_agent_ready(&tmux_ops, &target_clone) {- if let Some(ref cmd) = skill_cmd {- let _ = tmux_ops.send_keys(&target, cmd);- std::thread::sleep(std::time::Duration::from_millis(500));- }- if !prompt_clone.is_empty() {- if let Some(ref trigger) = prompt_trigger {- // Wait for the trigger text before sending the prompt- if wait_for_prompt_trigger(&tmux_ops, &target, trigger) {- std::thread::sleep(std::time::Duration::from_millis(500));- let _ = tmux_ops.send_keys(&target, &prompt_clone);- }- } else {- let _ = tmux_ops.send_keys(&target, &prompt_clone);- }- } else if skill_cmd.is_none() {- // No command and no prompt (e.g. void plugin): prefill task in input- let oneline = task_content_clone.lines().map(|l| l.trim()).filter(|l| !l.is_empty()).collect::<Vec<_>>().join(" ");- if !oneline.is_empty() {- let _ = tmux_ops.send_keys_literal(&target, &oneline);+ // Create a temporary task to pass to setup_task_worktree+ let mut tmp_task = Task::new(&task_title, &agent_name, &project_name);+ tmp_task.id = task_id.clone();+ tmp_task.plugin = plugin_name.clone();++ let result = setup_task_worktree(+ &mut tmp_task,+ &project_path,+ &project_name,+ &prompt,+ copy_files,+ init_script,+ &plugin,+ &agent_name,+ &all_agents,+ tmux_ops.as_ref(),+ git_ops.as_ref(),+ agent_ops.as_ref(),+ );++ match result {+ Ok(target) => {+ let _ = tx.send(SetupResult {+ task_id: task_id.clone(),+ session_name: tmp_task.session_name.unwrap_or_default(),+ worktree_path: tmp_task.worktree_path.unwrap_or_default(),+ branch_name: tmp_task.branch_name.unwrap_or_default(),+ new_status: None, // stays in Backlog+ agent: agent_name.clone(),+ plugin: plugin_name,+ error: None,+ });++ // Wait for agent ready and send skill+prompt+ if let Some(target) = wait_for_agent_ready(&tmux_ops, &target) {+ send_skill_and_prompt(&tmux_ops, &target, &skill_cmd, &prompt, &prompt_trigger, &task_content, &agent_name);}}+ Err(e) => {+ let _ = tx.send(SetupResult {+ task_id,+ session_name: String::new(),+ worktree_path: String::new(),+ branch_name: String::new(),+ new_status: None,+ agent: agent_name,+ plugin: plugin_name,+ error: Some(format!("Research setup failed: {}", e)),+ });+ }}});- // Store session name β task stays in Backlog- task.updated_at = chrono::Utc::now();- if let Some(db) = &self.state.db {- db.update_task(&task)?;- }- self.refresh_tasks()?;-Ok(())}/// Move task directly from Backlog to Running (skip Planning)fn move_backlog_to_running(&mut self) -> Result<()> {+ // Don't start if a setup is already in progress+ if self.state.setup_rx.is_some() { return Ok(()) }+let (mut task, project_path) = match (self.state.board.selected_task().cloned(),self.state.project_path.clone(),@@ -3053,9 +3336,24 @@ impl App {return Ok(());}+ // Block if plugin requires research and it hasn't been completed+ let plugin_check = self.load_task_plugin(&task);+ if plugin_check.as_ref().map_or(false, |p| p.research_required) {+ let has_research = task.worktree_path.as_ref().map_or(false, |wt| {+ research_artifact_exists(wt, &task.id, &plugin_check)+ });+ if !has_research {+ self.state.warning_message = Some((+ format!("Research phase required first β press R to start research"),+ std::time::Instant::now(),+ ));+ return Ok(());+ }+ }+// Build prompt - skip planning, go straight to implementationlet task_content = if let Some(desc) = &task.description {- format!("{}\n\n{}", task.title, desc)+ desc.clone()} else {task.title.clone()};@@ -3066,53 +3364,77 @@ impl App {// Stamp plugin on tasktask.plugin = self.state.config.workflow_plugin.clone();+ let plugin_name = task.plugin.clone();let plugin = self.load_task_plugin(&task);- let target = setup_task_worktree(- &mut task,- &project_path,- &self.state.project_name,- &prompt,- self.state.config.copy_files.clone(),- self.state.config.init_script.clone(),- &plugin,- &self.state.config.default_agent,- self.state.tmux_ops.as_ref(),- self.state.git_ops.as_ref(),- self.state.agent_registry.get(&self.state.config.default_agent).as_ref(),- )?;-- // Wait for agent to be ready, then send execute skill command and task content- let target_clone = target.clone();- let tmux_ops = Arc::clone(&self.state.tmux_ops);- let skill_cmd = resolve_skill_command(&plugin, "running", &self.state.config.default_agent, &task_content);- let prompt_clone = prompt.clone();+ let running_agent = self.state.config.agent_for_phase("running").to_string();+ let all_agents = collect_phase_agents(&self.state.config);+ let skill_cmd = resolve_skill_command(&plugin, "running", &running_agent, &task_content);let prompt_trigger = resolve_prompt_trigger(&plugin, "running");+ let project_name = self.state.project_name.clone();+ let copy_files = self.state.config.copy_files.clone();+ let init_script = self.state.config.init_script.clone();+ let tmux_ops = Arc::clone(&self.state.tmux_ops);+ let git_ops = Arc::clone(&self.state.git_ops);+ let agent_ops = self.state.agent_registry.get(&running_agent);+ let task_id = task.id.clone();+ let task_title = task.title.clone();+ let running_agent_clone = running_agent.clone();++ let (tx, rx) = mpsc::channel();+ self.state.setup_rx = Some(rx);+std::thread::spawn(move || {- if let Some(target) = wait_for_agent_ready(&tmux_ops, &target_clone) {- if let Some(ref cmd) = skill_cmd {- let _ = tmux_ops.send_keys(&target, cmd);- std::thread::sleep(std::time::Duration::from_millis(500));- }- if !prompt_clone.is_empty() {- if let Some(ref trigger) = prompt_trigger {- if wait_for_prompt_trigger(&tmux_ops, &target, trigger) {- std::thread::sleep(std::time::Duration::from_millis(500));- let _ = tmux_ops.send_keys(&target, &prompt_clone);- }- } else {- let _ = tmux_ops.send_keys(&target, &prompt_clone);+ let mut tmp_task = Task::new(&task_title, &running_agent_clone, &project_name);+ tmp_task.id = task_id.clone();+ tmp_task.plugin = plugin_name.clone();++ let result = setup_task_worktree(+ &mut tmp_task,+ &project_path,+ &project_name,+ &prompt,+ copy_files,+ init_script,+ &plugin,+ &running_agent_clone,+ &all_agents,+ tmux_ops.as_ref(),+ git_ops.as_ref(),+ agent_ops.as_ref(),+ );++ match result {+ Ok(target) => {+ let _ = tx.send(SetupResult {+ task_id: task_id.clone(),+ session_name: tmp_task.session_name.unwrap_or_default(),+ worktree_path: tmp_task.worktree_path.unwrap_or_default(),+ branch_name: tmp_task.branch_name.unwrap_or_default(),+ new_status: Some(TaskStatus::Running),+ agent: running_agent_clone.clone(),+ plugin: plugin_name,+ error: None,+ });++ if let Some(target) = wait_for_agent_ready(&tmux_ops, &target) {+ send_skill_and_prompt(&tmux_ops, &target, &skill_cmd, &prompt, &prompt_trigger, &task_content, &running_agent_clone);}}+ Err(e) => {+ let _ = tx.send(SetupResult {+ task_id,+ session_name: String::new(),+ worktree_path: String::new(),+ branch_name: String::new(),+ new_status: None,+ agent: running_agent_clone,+ plugin: plugin_name,+ error: Some(format!("Running setup failed: {}", e)),+ });+ }}});- task.status = TaskStatus::Running;- task.updated_at = chrono::Utc::now();-- if let Some(db) = &self.state.db {- db.update_task(&task)?;- }- self.refresh_tasks()?;Ok(())}@@ -3125,7 +3447,24 @@ impl App {return Ok(());}- // Just move the task back to Running - the tmux window should still be open+ // Switch agent if running phase uses a different agent than review+ let (running_agent, agent_switch) = needs_agent_switch(&self.state.config, &task, "running");+ if agent_switch {+ if let Some(session_name) = &task.session_name {+ let session_clone = session_name.clone();+ let tmux_ops = Arc::clone(&self.state.tmux_ops);+ let agent_registry = Arc::clone(&self.state.agent_registry);+ let running_agent_clone = running_agent.clone();+ let current_agent_clone = task.agent.clone();+ std::thread::spawn(move || {+ let agent_ops = agent_registry.get(&running_agent_clone);+ let new_cmd = agent_ops.build_interactive_command("");+ switch_agent_in_tmux(tmux_ops.as_ref(), &session_clone, ¤t_agent_clone, &new_cmd);+ });+ }+ }++ task.agent = running_agent;task.status = TaskStatus::Running;task.updated_at = chrono::Utc::now();db.update_task(&task)?;@@ -3142,7 +3481,24 @@ impl App {return Ok(());}- // Just move the task back to Planning - the tmux window should still be open+ // Switch agent if planning phase uses a different agent than running+ let (planning_agent, agent_switch) = needs_agent_switch(&self.state.config, &task, "planning");+ if agent_switch {+ if let Some(session_name) = &task.session_name {+ let session_clone = session_name.clone();+ let tmux_ops = Arc::clone(&self.state.tmux_ops);+ let agent_registry = Arc::clone(&self.state.agent_registry);+ let planning_agent_clone = planning_agent.clone();+ let current_agent_clone = task.agent.clone();+ std::thread::spawn(move || {+ let agent_ops = agent_registry.get(&planning_agent_clone);+ let new_cmd = agent_ops.build_interactive_command("");+ switch_agent_in_tmux(tmux_ops.as_ref(), &session_clone, ¤t_agent_clone, &new_cmd);+ });+ }+ }++ task.agent = planning_agent;task.status = TaskStatus::Planning;task.updated_at = chrono::Utc::now();db.update_task(&task)?;@@ -3169,6 +3525,8 @@ impl App {// doing tmux -L agtx resize-window -t session:window -x 30 -y 30 workslet _ = self.state.tmux_ops.resize_window(&window_name, pane_width, pane_height);popup.last_pane_size = Some((pane_width, pane_height));+ // Give TUI apps (OpenCode, Gemini Ink) time to re-render after resize+ std::thread::sleep(std::time::Duration::from_millis(200));}// Capture initial content@@ -3401,6 +3759,46 @@ fn cleanup_task_for_done(task.updated_at = chrono::Utc::now();}+/// Background-safe cleanup: archive artifacts, kill tmux window, remove worktree.+/// Takes owned/cloned values so it can run in a spawned thread.+fn cleanup_task_resources(+ task_id: &str,+ branch_name: &Option<String>,+ session_name: &Option<String>,+ worktree_path: &Option<String>,+ project_path: &Path,+ tmux_ops: &dyn TmuxOperations,+ git_ops: &dyn GitOperations,+) {+ // Archive artifacts before removing worktree+ if let Some(worktree) = worktree_path {+ let artifacts_dir = Path::new(worktree).join(".agtx");+ if artifacts_dir.exists() {+ let slug = branch_name.as_deref()+ .and_then(|b| b.strip_prefix("task/"))+ .unwrap_or(task_id);+ let archive_dir = project_path.join(".agtx").join("archive").join(slug);+ if let Ok(()) = std::fs::create_dir_all(&archive_dir) {+ if let Ok(entries) = std::fs::read_dir(&artifacts_dir) {+ for entry in entries.flatten() {+ let path = entry.path();+ if path.is_file() && path.extension().map_or(false, |ext| ext == "md") {+ let _ = std::fs::copy(&path, archive_dir.join(entry.file_name()));+ }+ }+ }+ }+ }+ }++ if let Some(session_name) = session_name {+ let _ = tmux_ops.kill_window(session_name);+ }+ if let Some(worktree) = worktree_path {+ let _ = git_ops.remove_worktree(project_path, worktree);+ }+}+/// Set up a worktree and tmux window for a task./// Creates worktree, initializes it (copy files + init script), creates tmux window with agent./// Updates task fields (session_name, worktree_path, branch_name) in place.@@ -3418,6 +3816,7 @@ fn setup_task_worktree(init_script: Option<String>,plugin: &Option<WorkflowPlugin>,agent_name: &str,+ all_phase_agents: &[String],tmux_ops: &dyn TmuxOperations,git_ops: &dyn GitOperations,agent_ops: &dyn AgentOperations,@@ -3451,7 +3850,9 @@ fn setup_task_worktree(}// Write skills to worktree .agtx/skills/ and agent-native discovery paths- write_skills_to_worktree(&worktree_path_str, project_path, plugin, agent_name);+ // Deploy for all unique agents configured across phases+ let agent_refs: Vec<&str> = all_phase_agents.iter().map(|s| s.as_str()).collect();+ write_skills_to_worktree(&worktree_path_str, project_path, plugin, &agent_refs);// Copy research artifact into worktree if it existslet research_path = project_path.join(".agtx").join("research")@@ -4144,9 +4545,14 @@ fn resolve_skill_command(plugin: &Option<WorkflowPlugin>, phase: &str, agent_nam// Explicit empty command means "no command" (e.g., void plugin)return None;}- // Collapse task content to single line for commands (newlines β spaces)- let task_oneline = task_content.lines().map(|l| l.trim()).filter(|l| !l.is_empty()).collect::<Vec<_>>().join(" ");- let expanded = c.replace("{task}", &task_oneline);+ // When research was already done, strip {task} β agent already has context+ let expanded = if phase == "planning_with_research" {+ c.replace("{task}", "").trim().to_string()+ } else {+ // Collapse task content to single line for commands (newlines β spaces)+ let task_oneline = task_content.lines().map(|l| l.trim()).filter(|l| !l.is_empty()).collect::<Vec<_>>().join(" ");+ c.replace("{task}", &task_oneline)+ };return skills::transform_plugin_command(&expanded, agent_name);}}@@ -4158,6 +4564,107 @@ fn resolve_skill_command(plugin: &Option<WorkflowPlugin>, phase: &str, agent_nam/// Resolve the prompt trigger text for a given phase./// When set, the system polls the tmux pane for this text before sending the prompt.+/// Send skill command and prompt to the agent via tmux.+/// When there is no prompt_trigger, combines skill command + prompt into a single message+/// (separated by a newline). When a prompt_trigger is set, sends them as two separate messages+/// with the prompt sent only after the trigger text appears in the pane.+fn send_skill_and_prompt(+ tmux_ops: &Arc<dyn TmuxOperations>,+ target: &str,+ skill_cmd: &Option<String>,+ prompt: &str,+ prompt_trigger: &Option<String>,+ task_content: &str,+ agent_name: &str,+) {+ // Gemini & Codex: always combine skill+prompt into a single message.+ // Gemini: sending separately causes it to execute the skill and queue the+ // prompt, which gets lost or arrives too late.+ // Codex: skill mentions ($skill-name) are inline references that must be+ // part of a message β sending just "$skill" standalone does nothing.+ if matches!(agent_name, "gemini" | "codex") {+ let text_to_send = if let Some(cmd) = skill_cmd {+ if !prompt.is_empty() {+ Some(format!("{}\n\n{}", cmd, prompt))+ } else {+ Some(cmd.clone())+ }+ } else if !prompt.is_empty() {+ Some(prompt.to_string())+ } else {+ let oneline = task_content.lines().map(|l| l.trim()).filter(|l| !l.is_empty()).collect::<Vec<_>>().join(" ");+ if !oneline.is_empty() { Some(oneline) } else { None }+ };++ if let Some(text) = text_to_send {+ let _ = tmux_ops.send_keys_literal(target, &text);+ // Wait for text to appear in pane before sending Enter (Ink TUIs need time to render)+ let check_str = text.lines().next().unwrap_or(&text);+ for _ in 0..20 { // up to 4s+ std::thread::sleep(std::time::Duration::from_millis(200));+ if let Ok(content) = tmux_ops.capture_pane(target) {+ if content.contains(check_str) {+ break;+ }+ }+ }+ std::thread::sleep(std::time::Duration::from_millis(200));+ let _ = tmux_ops.send_keys_literal(target, "Enter");+ }+ return;+ }++ match (skill_cmd, prompt_trigger) {+ // Skill + prompt trigger: must send separately, wait for trigger between them+ (Some(cmd), Some(trigger)) => {+ let _ = tmux_ops.send_keys(target, cmd);+ if !prompt.is_empty() {+ if wait_for_prompt_trigger(tmux_ops, target, trigger) {+ std::thread::sleep(std::time::Duration::from_millis(500));+ let _ = tmux_ops.send_keys(target, prompt);+ }+ }+ }+ // Skill + prompt, no trigger: send separately, wait for pane to stabilize+ (Some(cmd), None) => {+ let _ = tmux_ops.send_keys(target, cmd);+ if !prompt.is_empty() {+ // Wait for agent to finish processing the skill command before sending the prompt.+ // Poll pane content until it stabilizes (agent re-rendered its UI after the command).+ let mut last_content = String::new();+ let mut stable_ticks = 0u32;+ for _ in 0..50 { // 10s max+ std::thread::sleep(std::time::Duration::from_millis(200));+ if let Ok(content) = tmux_ops.capture_pane(target) {+ if content == last_content {+ stable_ticks += 1;+ if stable_ticks >= 10 { // 2s of no changes+ break;+ }+ } else {+ stable_ticks = 0;+ last_content = content;+ }+ }+ }+ let _ = tmux_ops.send_keys(target, prompt);+ }+ }+ // No skill command, just prompt+ (None, _) => {+ if !prompt.is_empty() {+ let _ = tmux_ops.send_keys(target, prompt);+ } else {+ // No command and no prompt (e.g. void plugin): prefill task in input+ let oneline = task_content.lines().map(|l| l.trim()).filter(|l| !l.is_empty()).collect::<Vec<_>>().join(" ");+ if !oneline.is_empty() {+ let _ = tmux_ops.send_keys_literal(target, &oneline);+ }+ }+ }+ }+}+fn resolve_prompt_trigger(plugin: &Option<WorkflowPlugin>, phase: &str) -> Option<String> {plugin.as_ref().and_then(|p| {match phase {@@ -4185,6 +4692,22 @@ fn wait_for_prompt_trigger(tmux_ops: &Arc<dyn TmuxOperations>, target: &str, tristable_ticks = 0;last_content = content.clone();}++ // Auto-dismiss known interactive prompts that block the trigger.+ // GSD's "Map codebase first?" prompt: select "Skip mapping" (option 2).+ if stable_ticks >= 4+ && content.contains("Map codebase")+ && content.contains("Skip mapping")+ && content.contains("Enter to select")+ {+ let _ = tmux_ops.send_keys_literal(target, "2");+ std::thread::sleep(std::time::Duration::from_millis(100));+ let _ = tmux_ops.send_keys_literal(target, "Enter");+ stable_ticks = 0;+ last_content.clear();+ continue;+ }+// Trigger when the text is present AND pane has been stable for ~2s.// While the agent is reading files / generating output, content keeps// changing. Once it asks the question and waits for input, it settles.@@ -4226,6 +4749,23 @@ fn phase_artifact_exists(worktree_path: &str, status: TaskStatus, plugin: &Optiofull_path.exists()}+/// Check if the research artifact exists for a task.+/// Uses plugin-configured artifact path or defaults to `.agtx/research/{task_id}.md`.+fn research_artifact_exists(worktree_path: &str, task_id: &str, plugin: &Option<WorkflowPlugin>) -> bool {+ let rel_path = plugin.as_ref()+ .and_then(|p| p.artifacts.research.as_deref())+ .unwrap_or(".agtx/research/{task_id}.md")+ .replace("{task_id}", task_id);++ let full_path = Path::new(worktree_path).join(&rel_path);++ if rel_path.contains('*') {+ return glob_path_exists(&full_path.to_string_lossy());+ }++ full_path.exists()+}+/// Simple glob matching for paths with a single `*` wildcard (one directory level)./// e.g. "/path/to/specs/*/plan.md" matches "/path/to/specs/my-feature/plan.md"fn glob_path_exists(pattern: &str) -> bool {@@ -4258,15 +4798,206 @@ fn glob_path_exists(pattern: &str) -> bool {false}+/// Check if a phase transition requires switching to a different agent.+/// Returns (target_agent_name, needs_switch).+/// Only switches when an explicit phase-specific agent is configured.+/// When no override exists, the current agent is kept (no switch).+fn needs_agent_switch(config: &MergedConfig, task: &Task, phase: &str) -> (String, bool) {+ match config.explicit_agent_for_phase(phase) {+ Some(target) => {+ let switch = task.agent != target;+ (target.to_string(), switch)+ }+ None => {+ // No explicit agent for this phase β keep the current session+ (task.agent.clone(), false)+ }+ }+}++/// Collect all unique agent names configured across phases.+/// Used to deploy skills for all agents that might be used during a task's lifecycle.+fn collect_phase_agents(config: &MergedConfig) -> Vec<String> {+ let mut agents: Vec<String> = vec![config.default_agent.clone()];+ for phase in &["research", "planning", "running", "review"] {+ let agent = config.agent_for_phase(phase).to_string();+ if !agents.contains(&agent) {+ agents.push(agent);+ }+ }+ agents+}++/// Known agent binary names as they appear in `pane_current_command`.+const AGENT_COMMANDS: &[&str] = &["claude", "codex", "gemini", "copilot", "opencode", "node", "python3", "python"];++/// Strings in pane content that indicate an agent TUI is active.+/// Used by `is_agent_active` to detect agents like Gemini that run inside+/// bash and don't change `pane_current_command`.+const AGENT_ACTIVE_INDICATORS: &[&str] = &[+ "Type your message", // Gemini+];++/// Check if the pane is running a shell (i.e. the agent has exited).+/// Returns true when `pane_current_command` reports a shell (bash, zsh, sh, fish)+/// rather than an agent process.+fn is_pane_at_shell(tmux_ops: &dyn TmuxOperations, target: &str) -> bool {+ if let Some(cmd) = tmux_ops.pane_current_command(target) {+ !AGENT_COMMANDS.iter().any(|a| cmd.contains(a))+ } else {+ false+ }+}++/// Check if an agent is actively running in the pane.+/// Uses both `pane_current_command` (works for Claude, Codex, Copilot) and+/// pane content indicators (works for Gemini which runs inside bash).+fn is_agent_active(tmux_ops: &dyn TmuxOperations, target: &str) -> bool {+ // Check 1: agent process visible in pane_current_command+ if !is_pane_at_shell(tmux_ops, target) {+ return true;+ }+ // Check 2: check the bottom of the visible pane for agent UI indicators.+ // Only the last few lines are checked to avoid false positives from+ // indicator strings appearing in conversation output higher up.+ if let Ok(content) = tmux_ops.capture_pane(target) {+ let lines: Vec<&str> = content.lines().collect();+ let bottom = lines.len().saturating_sub(5);+ let tail = &lines[bottom..];+ let tail_text = tail.join("\n");+ if AGENT_ACTIVE_INDICATORS.iter().any(|s| tail_text.contains(s)) {+ return true;+ }+ }+ false+}++/// Gracefully switch the agent running in a tmux window.+/// Terminates the current agent, waits for the shell prompt,+/// then starts the new agent.+///+/// Exit commands per agent:+/// - Claude, OpenCode: `/exit`+/// - Gemini, Codex: `/quit`+/// - Fallback: Ctrl+C + Ctrl+D as last resort+///+/// Detection uses `tmux display -p #{pane_current_command}` which reports+/// the actual process name (e.g. "claude", "node", "bash"), avoiding+/// false positives from parsing pane text content.+fn switch_agent_in_tmux(+ tmux_ops: &dyn TmuxOperations,+ target: &str,+ current_agent: &str,+ new_agent_cmd: &str,+) {+ // 1. Send the graceful exit command for the current agent.+ let exit_cmd = match current_agent {+ "codex" => None, // Codex has no exit command β Ctrl+C is the only way+ "gemini" => Some("/quit"),+ _ => Some("/exit"), // claude, opencode, and others+ };++ if let Some(cmd) = exit_cmd {+ let _ = tmux_ops.send_keys(target, cmd);+ } else {+ let _ = tmux_ops.send_keys_literal(target, "C-c");+ }++ // 2. Poll for shell (agent exited). If the agent was busy, the exit command+ // may have been queued β so we wait up to 3s for it to take effect.+ let mut found_shell = false;+ for _ in 0..30 { // 3s+ std::thread::sleep(std::time::Duration::from_millis(100));+ if is_pane_at_shell(tmux_ops, target) {+ found_shell = true;+ break;+ }+ }++ // 3. If still running, the agent was likely busy. Ctrl+C to cancel, then retry exit.+ if !found_shell {+ let _ = tmux_ops.send_keys_literal(target, "C-c");+ std::thread::sleep(std::time::Duration::from_millis(1000));++ if let Some(cmd) = exit_cmd {+ let _ = tmux_ops.send_keys(target, cmd);+ }++ // Wait for shell after retry+ for _ in 0..50 { // 5s+ std::thread::sleep(std::time::Duration::from_millis(100));+ if is_pane_at_shell(tmux_ops, target) {+ found_shell = true;+ break;+ }+ }+ }++ // 4. Last resort: Ctrl+D to force exit+ if !found_shell {+ let _ = tmux_ops.send_keys_literal(target, "C-d");+ for _ in 0..20 { // 2s+ std::thread::sleep(std::time::Duration::from_millis(100));+ if is_pane_at_shell(tmux_ops, target) {+ break;+ }+ }+ }++ // 4. Let the shell fully initialize before sending the new agent command+ std::thread::sleep(std::time::Duration::from_millis(2000));++ // 5. Start the new agent+ let _ = tmux_ops.send_keys(target, new_agent_cmd);++ // 6. Wait for the new agent process to actually start (pane_current_command != shell).+ // Without this, wait_for_agent_ready may see stale ">" from old pane content+ // and return before the new agent has even launched.+ for _ in 0..100 { // 10s max+ std::thread::sleep(std::time::Duration::from_millis(100));+ if !is_pane_at_shell(tmux_ops, target) {+ break;+ }+ }+}+/// Wait for an agent in a tmux pane to be ready for input.-/// Handles both the bypass warning prompt (sends acceptance) and agents that skip it.-/// Returns the target string if the agent became ready, None on timeout.+/// First waits for the agent process to start (pane_current_command != shell),+/// then waits a fixed delay for the agent to fully initialize.+/// Handles the bypass warning prompt (sends acceptance) during the wait.+/// Always returns Some β the prompt is always sent (better late than never).+/// Strings that indicate an agent's TUI is ready for input.+const AGENT_READY_INDICATORS: &[&str] = &[+ "Type your message", // Gemini+ "Yes, I accept", // Claude bypass prompt+ "I accept the risk", // Claude bypass prompt (alt)+];++/// Number of consecutive stable polls (200ms each) before considering the agent ready.+/// 3s of no pane content changes = agent has finished loading its TUI.+const CONTENT_STABLE_THRESHOLD: u32 = 15;+fn wait_for_agent_ready(tmux_ops: &Arc<dyn TmuxOperations>, target: &str) -> Option<String> {- for _ in 0..50 {- std::thread::sleep(std::time::Duration::from_millis(100));+ // Poll until the agent is ready (up to 30s).+ // Three detection methods, whichever fires first:+ // 1. Agent process detected via pane_current_command (Claude, Codex, Copilot)+ // 2. Known ready indicator in pane content (Gemini's "Type your message")+ // 3. Content stabilization: pane unchanged for 3s (universal fallback)+ let mut last_content = String::new();+ let mut stable_ticks: u32 = 0;+ let mut change_count: u32 = 0;++ for _ in 0..150 { // 30s (150 * 200ms)+ std::thread::sleep(std::time::Duration::from_millis(200));+ // Check 1: agent process detected via pane_current_command+ if !is_pane_at_shell(tmux_ops.as_ref(), target) {+ break;+ }++ // Check 2 & 3: pane content checksif let Ok(content) = tmux_ops.capture_pane(target) {- // Check for bypass warning prompt (needs acceptance)+ // Handle Claude bypass prompt immediatelyif content.contains("Yes, I accept") || content.contains("I accept the risk") {let _ = tmux_ops.send_keys_literal(target, "2");std::thread::sleep(std::time::Duration::from_millis(50));@@ -4274,14 +5005,33 @@ fn wait_for_agent_ready(tmux_ops: &Arc<dyn TmuxOperations>, target: &str) -> Optstd::thread::sleep(std::time::Duration::from_millis(1000));return Some(target.to_string());}- // Agent started without acceptance prompt (e.g. --dangerously-skip-permissions)- if content.contains(">") || content.contains("β―") || content.contains("$") {- std::thread::sleep(std::time::Duration::from_millis(500));- return Some(target.to_string());++ // Check 2: known ready indicator+ if AGENT_READY_INDICATORS.iter().any(|s| content.contains(s)) {+ break;+ }++ // Check 3: content stabilization (unchanged for 3s)+ // Only count after content has changed multiple times (>=3), so we+ // don't false-positive on shell init output (e.g. asdf notice prints+ // once, then shell pauses while loading profiles/launching agent).+ if content != last_content {+ change_count += 1;+ stable_ticks = 0;+ last_content = content;+ } else if change_count >= 3 {+ stable_ticks += 1;+ if stable_ticks >= CONTENT_STABLE_THRESHOLD {+ break;+ }}}}- None++ // Short settle delay for the TUI to be fully interactive+ std::thread::sleep(std::time::Duration::from_millis(1000));++ Some(target.to_string())}/// Load workflow plugin if configured@@ -4291,8 +5041,9 @@ fn load_plugin_if_configured(config: &MergedConfig, project_path: Option<&Path>)}/// Write skill files to a worktree's .agtx/skills/ directory and agent-native discovery paths.-/// `agent_name` determines which native path to use (e.g. `.claude/commands/agtx/` for Claude).-fn write_skills_to_worktree(worktree_path: &str, project_path: &Path, plugin: &Option<WorkflowPlugin>, agent_name: &str) {+/// `agent_names` determines which native paths to use (e.g. `.claude/commands/agtx/` for Claude).+/// When multiple agents are configured for different phases, skills are deployed for all of them.+fn write_skills_to_worktree(worktree_path: &str, project_path: &Path, plugin: &Option<WorkflowPlugin>, agent_names: &[&str]) {let agtx_dir = Path::new(worktree_path).join(".agtx");let _ = std::fs::create_dir_all(&agtx_dir);@@ -4328,44 +5079,48 @@ fn write_skills_to_worktree(worktree_path: &str, project_path: &Path, plugin: &O}}- // Write to agent-native discovery path (e.g. .claude/commands/agtx/)- if let Some((base_dir, namespace)) = skills::agent_native_skill_dir(agent_name) {- let native_dir = if namespace.is_empty() {- Path::new(worktree_path).join(base_dir)- } else {- Path::new(worktree_path).join(base_dir).join(namespace)- };- let _ = std::fs::create_dir_all(&native_dir);-- for (skill_dir_name, default_content) in skills::DEFAULT_SKILLS {- let content = resolve_skill_content(plugin, skill_dir_name, project_path, default_content);-- match agent_name {- "gemini" => {- // Gemini uses .toml command files with description + prompt fields- let description = skills::extract_description(&content)- .unwrap_or_else(|| format!("agtx {} phase skill", skill_dir_name));- let toml_content = skills::skill_to_gemini_toml(&description, &content);- let filename = skills::skill_dir_to_filename(skill_dir_name, agent_name);- let _ = std::fs::write(native_dir.join(&filename), toml_content);- }- "codex" => {- // Codex uses SKILL.md in skill-name/ subdirectories- let skill_subdir = native_dir.join(skill_dir_name);- let _ = std::fs::create_dir_all(&skill_subdir);- let _ = std::fs::write(skill_subdir.join("SKILL.md"), &content);- }- "opencode" => {- // OpenCode uses flat .md files: command/agtx-plan.md (invoked as /agtx-plan)- let content = transform_skill_for_opencode(&content);- let filename = skills::skill_dir_to_filename(skill_dir_name, agent_name);- let _ = std::fs::write(native_dir.join(&filename), content);- }- _ => {- // Claude and others: .md files with transformed frontmatter- let content = transform_skill_frontmatter(&content);- let filename = skills::skill_dir_to_filename(skill_dir_name, agent_name);- let _ = std::fs::write(native_dir.join(&filename), content);+ // Write to agent-native discovery paths (e.g. .claude/commands/agtx/)+ // Deploy for all configured agents so skills are available across phase transitions+ for agent_name in agent_names {+ if let Some((base_dir, namespace)) = skills::agent_native_skill_dir(agent_name) {+ let native_dir = if namespace.is_empty() {+ Path::new(worktree_path).join(base_dir)+ } else {+ Path::new(worktree_path).join(base_dir).join(namespace)+ };+ let _ = std::fs::create_dir_all(&native_dir);++ for (skill_dir_name, default_content) in skills::DEFAULT_SKILLS {+ let content = resolve_skill_content(plugin, skill_dir_name, project_path, default_content);++ match *agent_name {+ "gemini" => {+ // Gemini uses .toml command files with description + prompt fields+ let description = skills::extract_description(&content)+ .unwrap_or_else(|| format!("agtx {} phase skill", skill_dir_name));+ let toml_content = skills::skill_to_gemini_toml(&description, &content);+ let filename = skills::skill_dir_to_filename(skill_dir_name, agent_name);+ let _ = std::fs::write(native_dir.join(&filename), toml_content);+ }+ "codex" => {+ // Codex uses SKILL.md in skill-name/ subdirectories+ let skill_subdir = native_dir.join(skill_dir_name);+ let _ = std::fs::create_dir_all(&skill_subdir);+ let _ = std::fs::write(skill_subdir.join("SKILL.md"), &content);+ }+ "opencode" => {+ // OpenCode uses flat .md command files: .opencode/commands/agtx-research.md+ // Commands have description frontmatter + prompt template+ let oc_content = transform_skill_for_opencode(&content);+ let filename = skills::skill_dir_to_filename(skill_dir_name, agent_name);+ let _ = std::fs::write(native_dir.join(&filename), oc_content);+ }+ _ => {+ // Claude and others: .md files with transformed frontmatter+ let content = transform_skill_frontmatter(&content);+ let filename = skills::skill_dir_to_filename(skill_dir_name, agent_name);+ let _ = std::fs::write(native_dir.join(&filename), content);+ }}}}@@ -4392,8 +5147,11 @@ fn transform_skill_frontmatter(content: &str) -> String {/// Transform skill content for OpenCode: strip frontmatter, keep as .md/// OpenCode uses flat command files and hyphen-separated names (no colon namespace)fn transform_skill_for_opencode(content: &str) -> String {- // OpenCode doesn't use YAML frontmatter in commands β just the markdown body- skills::strip_frontmatter(content).to_string()+ // OpenCode commands use description frontmatter + prompt body+ let description = skills::extract_description(content)+ .unwrap_or_else(|| "agtx skill".to_string());+ let body = skills::strip_frontmatter(content);+ format!("---\ndescription: \"{}\"\n---\n{}", description, body)}/// Resolve skill content: check plugin override, then fall back to defaultdiff --git a/src/tui/app_tests.rs b/src/tui/app_tests.rsindex 882f9c9..cb035aa 100644--- a/src/tui/app_tests.rs+++ b/src/tui/app_tests.rs@@ -1367,6 +1367,7 @@ fn test_setup_task_worktree_success() {None,&None,"claude",+ &vec!["claude".to_string()],&mock_tmux,&mock_git,&mock_agent,@@ -1414,6 +1415,7 @@ fn test_setup_task_worktree_sets_task_fields() {Some("./init.sh".to_string()),&None,"claude",+ &vec!["claude".to_string()],&mock_tmux,&mock_git,&mock_agent,@@ -1464,6 +1466,7 @@ fn test_setup_task_worktree_worktree_creation_fails() {None,&None,"claude",+ &vec!["claude".to_string()],&mock_tmux,&mock_git,&mock_agent,@@ -1512,6 +1515,7 @@ fn test_setup_task_worktree_tmux_window_fails() {None,&None,"claude",+ &vec!["claude".to_string()],&mock_tmux,&mock_git,&mock_agent,@@ -1564,6 +1568,7 @@ fn test_setup_task_worktree_creates_session_when_missing() {None,&None,"claude",+ &vec!["claude".to_string()],&mock_tmux,&mock_git,&mock_agent,@@ -1612,6 +1617,7 @@ fn test_setup_task_worktree_passes_init_config() {Some("./setup.sh".to_string()),&None,"claude",+ &vec!["claude".to_string()],&mock_tmux,&mock_git,&mock_agent,@@ -1653,7 +1659,7 @@ fn test_skill_dir_to_filename() {fn test_agent_native_skill_dir() {assert_eq!(skills::agent_native_skill_dir("claude"), Some((".claude/commands", "agtx")));assert_eq!(skills::agent_native_skill_dir("gemini"), Some((".gemini/commands", "agtx")));- assert_eq!(skills::agent_native_skill_dir("opencode"), Some((".config/opencode/command", "")));+ assert_eq!(skills::agent_native_skill_dir("opencode"), Some((".opencode/commands", "")));assert_eq!(skills::agent_native_skill_dir("codex"), Some((".codex/skills", "")));assert_eq!(skills::agent_native_skill_dir("copilot"), Some((".github/agents", "agtx")));assert_eq!(skills::agent_native_skill_dir("unknown"), None);@@ -1832,6 +1838,7 @@ fn test_resolve_skill_command_with_plugin() {},prompts: PluginPrompts::default(),prompt_triggers: PluginPromptTriggers::default(),+ research_required: false,copy_dirs: vec![],});// Claude/Gemini: canonical form unchanged@@ -1863,6 +1870,7 @@ fn test_plugin_supports_agent() {commands: Default::default(),prompts: Default::default(),prompt_triggers: Default::default(),+ research_required: false,copy_dirs: vec![],};assert!(plugin.supports_agent("claude"));@@ -1879,6 +1887,7 @@ fn test_plugin_supports_agent() {commands: Default::default(),prompts: Default::default(),prompt_triggers: Default::default(),+ research_required: false,copy_dirs: vec![],};assert!(plugin.supports_agent("claude"));@@ -1945,6 +1954,7 @@ fn test_phase_artifact_exists_with_glob() {commands: PluginCommands::default(),prompts: PluginPrompts::default(),prompt_triggers: Default::default(),+ research_required: false,copy_dirs: vec![],});@@ -2217,6 +2227,7 @@ fn test_resolve_prompt_trigger_with_gsd() {running: None,review: None,},+ research_required: false,copy_dirs: vec![],});assert_eq!(@@ -2251,6 +2262,7 @@ fn test_resolve_prompt_trigger_empty_string_filtered() {running: None,review: None,},+ research_required: false,copy_dirs: vec![],});// Empty strings should be filtered out@@ -2357,3 +2369,255 @@ fn test_skill_fuzzy_matching() {let score_desc = fuzzy_score("plan a task implementation", "plan");assert!(score_desc > 0);}++// ββ Per-Phase Agent Configuration Tests βββββββββββββββββββββββββββββββββββββ++#[test]+fn test_needs_agent_switch_no_config_keeps_current() {+ use crate::config::{GlobalConfig, ProjectConfig, MergedConfig};+ use crate::db::Task;++ // No [agents] section β should keep whatever agent is running+ let config = MergedConfig::merge(&GlobalConfig::default(), &ProjectConfig::default());+ let task = Task::new("Test", "claude", "project-1");++ let (agent, switch) = needs_agent_switch(&config, &task, "running");+ assert_eq!(agent, "claude");+ assert!(!switch);+}++#[test]+fn test_needs_agent_switch_no_config_keeps_non_default_agent() {+ use crate::config::{GlobalConfig, ProjectConfig, MergedConfig};+ use crate::db::Task;++ // No review agent configured, but task is running codex (set by explicit running override).+ // Moving to review should NOT switch back to default β keep codex.+ let mut global = GlobalConfig::default();+ global.agents.running = Some("codex".to_string());+ let config = MergedConfig::merge(&global, &ProjectConfig::default());+ let mut task = Task::new("Test", "claude", "project-1");+ task.agent = "codex".to_string(); // was switched to codex for running phase++ let (agent, switch) = needs_agent_switch(&config, &task, "review");+ assert_eq!(agent, "codex"); // keeps codex, not fallback to claude+ assert!(!switch);+}++#[test]+fn test_needs_agent_switch_explicit_override() {+ use crate::config::{GlobalConfig, ProjectConfig, MergedConfig};+ use crate::db::Task;++ let mut global = GlobalConfig::default();+ global.agents.running = Some("codex".to_string());+ let config = MergedConfig::merge(&global, &ProjectConfig::default());+ let task = Task::new("Test", "claude", "project-1");++ let (agent, switch) = needs_agent_switch(&config, &task, "running");+ assert_eq!(agent, "codex");+ assert!(switch);+}++#[test]+fn test_needs_agent_switch_explicit_same_as_current() {+ use crate::config::{GlobalConfig, ProjectConfig, MergedConfig};+ use crate::db::Task;++ // Explicit override exists but matches current agent β no switch needed+ let mut global = GlobalConfig::default();+ global.agents.review = Some("codex".to_string());+ let config = MergedConfig::merge(&global, &ProjectConfig::default());+ let mut task = Task::new("Test", "claude", "project-1");+ task.agent = "codex".to_string();++ let (agent, switch) = needs_agent_switch(&config, &task, "review");+ assert_eq!(agent, "codex");+ assert!(!switch);+}++#[test]+fn test_collect_phase_agents_all_same() {+ use crate::config::{GlobalConfig, ProjectConfig, MergedConfig};++ let config = MergedConfig::merge(&GlobalConfig::default(), &ProjectConfig::default());+ let agents = collect_phase_agents(&config);+ assert_eq!(agents, vec!["claude".to_string()]);+}++#[test]+fn test_collect_phase_agents_mixed() {+ use crate::config::{GlobalConfig, ProjectConfig, MergedConfig};++ let mut global = GlobalConfig::default();+ global.agents.running = Some("codex".to_string());+ global.agents.review = Some("gemini".to_string());+ let config = MergedConfig::merge(&global, &ProjectConfig::default());+ let agents = collect_phase_agents(&config);+ assert_eq!(agents, vec!["claude".to_string(), "codex".to_string(), "gemini".to_string()]);+}++// === is_pane_at_shell tests ===++#[test]+#[cfg(feature = "test-mocks")]+fn test_is_pane_at_shell_returns_true_for_bash() {+ let mut mock = MockTmuxOperations::new();+ mock.expect_pane_current_command()+ .withf(|t| t == "sess:win")+ .returning(|_| Some("bash".to_string()));++ assert!(is_pane_at_shell(&mock, "sess:win"));+}++#[test]+#[cfg(feature = "test-mocks")]+fn test_is_pane_at_shell_returns_true_for_zsh() {+ let mut mock = MockTmuxOperations::new();+ mock.expect_pane_current_command()+ .withf(|t| t == "sess:win")+ .returning(|_| Some("zsh".to_string()));++ assert!(is_pane_at_shell(&mock, "sess:win"));+}++#[test]+#[cfg(feature = "test-mocks")]+fn test_is_pane_at_shell_returns_true_for_fish() {+ let mut mock = MockTmuxOperations::new();+ mock.expect_pane_current_command()+ .withf(|t| t == "sess:win")+ .returning(|_| Some("fish".to_string()));++ assert!(is_pane_at_shell(&mock, "sess:win"));+}++#[test]+#[cfg(feature = "test-mocks")]+fn test_is_pane_at_shell_returns_false_for_claude() {+ let mut mock = MockTmuxOperations::new();+ mock.expect_pane_current_command()+ .withf(|t| t == "sess:win")+ .returning(|_| Some("claude".to_string()));++ assert!(!is_pane_at_shell(&mock, "sess:win"));+}++#[test]+#[cfg(feature = "test-mocks")]+fn test_is_pane_at_shell_returns_false_for_node() {+ let mut mock = MockTmuxOperations::new();+ mock.expect_pane_current_command()+ .withf(|t| t == "sess:win")+ .returning(|_| Some("node".to_string()));++ assert!(!is_pane_at_shell(&mock, "sess:win"));+}++#[test]+#[cfg(feature = "test-mocks")]+fn test_is_pane_at_shell_returns_false_for_codex() {+ let mut mock = MockTmuxOperations::new();+ mock.expect_pane_current_command()+ .withf(|t| t == "sess:win")+ .returning(|_| Some("codex".to_string()));++ assert!(!is_pane_at_shell(&mock, "sess:win"));+}++#[test]+#[cfg(feature = "test-mocks")]+fn test_is_pane_at_shell_returns_false_when_none() {+ let mut mock = MockTmuxOperations::new();+ mock.expect_pane_current_command()+ .withf(|t| t == "sess:win")+ .returning(|_| None);++ assert!(!is_pane_at_shell(&mock, "sess:win"));+}++// === switch_agent_in_tmux tests ===++/// Test that switch_agent_in_tmux sends the correct exit command per agent+/// and starts the new agent. Uses relaxed mocking since the function has+/// multiple polling loops with retries.+#[test]+#[cfg(feature = "test-mocks")]+fn test_switch_agent_claude_sends_exit() {+ use std::sync::atomic::{AtomicBool, Ordering};+ use std::sync::Arc;++ let mut mock = MockTmuxOperations::new();+ let exit_sent = Arc::new(AtomicBool::new(false));+ let new_agent_sent = Arc::new(AtomicBool::new(false));+ let exit_sent_c = exit_sent.clone();+ let new_agent_sent_c = new_agent_sent.clone();++ // Claude uses /exit+ mock.expect_send_keys()+ .returning(move |_, k| {+ if k == "/exit" { exit_sent_c.store(true, Ordering::SeqCst); }+ if k == "codex" { new_agent_sent_c.store(true, Ordering::SeqCst); }+ Ok(())+ });+ mock.expect_send_keys_literal().returning(|_, _| Ok(()));+ // Return shell immediately so polling exits fast+ mock.expect_pane_current_command()+ .returning(|_| Some("bash".to_string()));+ mock.expect_capture_pane()+ .returning(|_| Ok(String::new()));++ switch_agent_in_tmux(&mock, "sess:win", "claude", "codex");+ assert!(exit_sent.load(Ordering::SeqCst), "/exit should be sent for claude");+ assert!(new_agent_sent.load(Ordering::SeqCst), "new agent command should be sent");+}++#[test]+#[cfg(feature = "test-mocks")]+fn test_switch_agent_gemini_sends_quit() {+ use std::sync::atomic::{AtomicBool, Ordering};+ use std::sync::Arc;++ let mut mock = MockTmuxOperations::new();+ let quit_sent = Arc::new(AtomicBool::new(false));+ let quit_sent_c = quit_sent.clone();++ mock.expect_send_keys()+ .returning(move |_, k| {+ if k == "/quit" { quit_sent_c.store(true, Ordering::SeqCst); }+ Ok(())+ });+ mock.expect_send_keys_literal().returning(|_, _| Ok(()));+ mock.expect_pane_current_command()+ .returning(|_| Some("zsh".to_string()));+ mock.expect_capture_pane()+ .returning(|_| Ok(String::new()));++ switch_agent_in_tmux(&mock, "sess:win", "gemini", "claude");+ assert!(quit_sent.load(Ordering::SeqCst), "/quit should be sent for gemini");+}++#[test]+#[cfg(feature = "test-mocks")]+fn test_switch_agent_codex_sends_ctrl_c() {+ use std::sync::atomic::{AtomicBool, Ordering};+ use std::sync::Arc;++ let mut mock = MockTmuxOperations::new();+ let ctrl_c_sent = Arc::new(AtomicBool::new(false));+ let ctrl_c_sent_c = ctrl_c_sent.clone();++ mock.expect_send_keys().returning(|_, _| Ok(()));+ mock.expect_send_keys_literal()+ .returning(move |_, k| {+ if k == "C-c" { ctrl_c_sent_c.store(true, Ordering::SeqCst); }+ Ok(())+ });+ mock.expect_pane_current_command()+ .returning(|_| Some("bash".to_string()));+ mock.expect_capture_pane()+ .returning(|_| Ok(String::new()));++ switch_agent_in_tmux(&mock, "sess:win", "codex", "claude");+ assert!(ctrl_c_sent.load(Ordering::SeqCst), "Ctrl+C should be sent for codex");+}diff --git a/src/tui/shell_popup.rs b/src/tui/shell_popup.rsindex a7408d3..5868031 100644--- a/src/tui/shell_popup.rs+++ b/src/tui/shell_popup.rs@@ -145,9 +145,17 @@ pub fn trim_content_to_cursor(content: Vec<u8>, cursor_info: Option<(usize, usiz// cursor position in capture = visible_pane_start + cursor_ylet visible_pane_start = total_lines.saturating_sub(pane_height);let cursor_line_in_capture = visible_pane_start + cursor_y;-- // Keep lines up to and including the cursor line- (cursor_line_in_capture + 1).min(total_lines)+ let trim_at = (cursor_line_in_capture + 1).min(total_lines);++ // Only trim at cursor if everything below it is blank.+ // TUI apps (OpenCode, Gemini) place the cursor mid-screen with+ // real content below β trimming there would cut the UI in half.+ let has_content_below = lines[trim_at..].iter().any(|l| !l.trim().is_empty());+ if has_content_below {+ total_lines+ } else {+ trim_at+ }} else {total_lines}diff --git a/tests/config_tests.rs b/tests/config_tests.rsindex e6db565..e5b834e 100644--- a/tests/config_tests.rs+++ b/tests/config_tests.rs@@ -1,6 +1,6 @@use agtx::config::{- determine_first_run_action, FirstRunAction, GlobalConfig, MergedConfig, ProjectConfig,- ThemeConfig, WorktreeConfig,+ determine_first_run_action, FirstRunAction, GlobalConfig, MergedConfig, PhaseAgentsConfig,+ ProjectConfig, ThemeConfig, WorktreeConfig,};// === ThemeConfig Tests ===@@ -103,6 +103,7 @@ fn test_merged_config_project_overrides() {let global = GlobalConfig::default();let project = ProjectConfig {default_agent: Some("codex".to_string()),+ agents: None,base_branch: Some("develop".to_string()),github_url: Some("https://github.com/user/repo".to_string()),copy_files: Some(".env, .env.local".to_string()),@@ -170,3 +171,123 @@ fn test_first_run_new_user_prompt() {FirstRunAction::NewUserPrompt,);}++// === PhaseAgentsConfig Tests ===++#[test]+fn test_agent_for_phase_all_defaults() {+ let config = MergedConfig::merge(+ &GlobalConfig::default(),+ &ProjectConfig::default(),+ );+ assert_eq!(config.agent_for_phase("research"), "claude");+ assert_eq!(config.agent_for_phase("planning"), "claude");+ assert_eq!(config.agent_for_phase("running"), "claude");+ assert_eq!(config.agent_for_phase("review"), "claude");+ assert_eq!(config.agent_for_phase("unknown"), "claude");+}++#[test]+fn test_agent_for_phase_global_overrides() {+ let mut global = GlobalConfig::default();+ global.agents.running = Some("codex".to_string());+ global.agents.review = Some("gemini".to_string());++ let config = MergedConfig::merge(&global, &ProjectConfig::default());+ assert_eq!(config.agent_for_phase("research"), "claude");+ assert_eq!(config.agent_for_phase("planning"), "claude");+ assert_eq!(config.agent_for_phase("running"), "codex");+ assert_eq!(config.agent_for_phase("review"), "gemini");+}++#[test]+fn test_agent_for_phase_project_overrides_global() {+ let mut global = GlobalConfig::default();+ global.agents.running = Some("codex".to_string());++ let project = ProjectConfig {+ agents: Some(PhaseAgentsConfig {+ running: Some("gemini".to_string()),+ ..Default::default()+ }),+ ..Default::default()+ };++ let config = MergedConfig::merge(&global, &project);+ // Project override wins+ assert_eq!(config.agent_for_phase("running"), "gemini");+ // Unset phases fall back to default_agent+ assert_eq!(config.agent_for_phase("planning"), "claude");+}++#[test]+fn test_agent_for_phase_project_default_agent() {+ let project = ProjectConfig {+ default_agent: Some("codex".to_string()),+ ..Default::default()+ };++ let config = MergedConfig::merge(&GlobalConfig::default(), &project);+ // All phases fall back to project's default_agent+ assert_eq!(config.agent_for_phase("research"), "codex");+ assert_eq!(config.agent_for_phase("running"), "codex");+}++#[test]+fn test_agent_for_phase_planning_with_research() {+ let mut global = GlobalConfig::default();+ global.agents.planning = Some("gemini".to_string());++ let config = MergedConfig::merge(&global, &ProjectConfig::default());+ // "planning_with_research" maps to the planning agent+ assert_eq!(config.agent_for_phase("planning_with_research"), "gemini");+}++#[test]+fn test_explicit_agent_for_phase_returns_none_when_unset() {+ let config = MergedConfig::merge(&GlobalConfig::default(), &ProjectConfig::default());+ // No [agents] section β all phases return None+ assert_eq!(config.explicit_agent_for_phase("research"), None);+ assert_eq!(config.explicit_agent_for_phase("planning"), None);+ assert_eq!(config.explicit_agent_for_phase("running"), None);+ assert_eq!(config.explicit_agent_for_phase("review"), None);+}++#[test]+fn test_explicit_agent_for_phase_returns_some_when_set() {+ let mut global = GlobalConfig::default();+ global.agents.running = Some("codex".to_string());++ let config = MergedConfig::merge(&global, &ProjectConfig::default());+ assert_eq!(config.explicit_agent_for_phase("running"), Some("codex"));+ assert_eq!(config.explicit_agent_for_phase("review"), None);+}++#[test]+fn test_phase_agents_config_serde_roundtrip() {+ let toml_str = r#"+default_agent = "claude"++[agents]+running = "codex"+review = "gemini"+"#;+ let config: GlobalConfig = toml::from_str(toml_str).unwrap();+ assert_eq!(config.agents.running, Some("codex".to_string()));+ assert_eq!(config.agents.review, Some("gemini".to_string()));+ assert_eq!(config.agents.research, None);+ assert_eq!(config.agents.planning, None);+}++#[test]+fn test_phase_agents_config_backwards_compatible() {+ // Config without [agents] section should parse fine+ let toml_str = r#"+default_agent = "claude"+"#;+ let config: GlobalConfig = toml::from_str(toml_str).unwrap();+ assert_eq!(config.agents.research, None);+ assert_eq!(config.agents.planning, None);+ assert_eq!(config.agents.running, None);+ assert_eq!(config.agents.review, None);+}diff --git a/tests/shell_popup_tests.rs b/tests/shell_popup_tests.rsindex 6246c56..9eaadf8 100644--- a/tests/shell_popup_tests.rs+++ b/tests/shell_popup_tests.rs@@ -410,8 +410,8 @@ fn test_trim_content_to_cursor_with_cursor_info() {// Simulate: 10 lines captured, pane_height=5, cursor at line 2 of visible area// visible_pane_start = 10 - 5 = 5// cursor_in_capture = 5 + 2 = 7- // Should keep lines 0-7 (8 lines)- let content = b"line 0\nline 1\nline 2\nline 3\nline 4\nline 5\nline 6\nline 7\nline 8\nline 9".to_vec();+ // Lines below cursor are empty (unused pane buffer) β trimmed at cursor+ let content = b"line 0\nline 1\nline 2\nline 3\nline 4\nline 5\nline 6\nline 7\n\n".to_vec();let cursor_info = Some((2, 5)); // cursor_y=2, pane_height=5let result = trim_content_to_cursor(content, cursor_info);let result_str = String::from_utf8_lossy(&result);@@ -422,6 +422,21 @@ fn test_trim_content_to_cursor_with_cursor_info() {assert_eq!(lines[7], "line 7");}+#[test]+fn test_trim_content_to_cursor_tui_cursor_mid_screen() {+ // TUI app (OpenCode, Gemini) with cursor in the middle β content below cursor is NOT empty+ // Should keep all content, not trim at cursor+ let content = b"header\nstatus bar\n\ninput field\n\noutput area\nmore output\nbottom bar".to_vec();+ let cursor_info = Some((3, 8)); // cursor_y=3 (mid-screen), pane_height=8+ let result = trim_content_to_cursor(content, cursor_info);+ let result_str = String::from_utf8_lossy(&result);+ let lines: Vec<&str> = result_str.lines().collect();++ assert_eq!(lines.len(), 8); // All lines kept+ assert_eq!(lines[0], "header");+ assert_eq!(lines[7], "bottom bar");+}+#[test]fn test_trim_content_to_cursor_cursor_at_bottom_with_empty() {// Cursor at bottom of pane, but those lines are empty