aboutsummaryrefslogtreecommitdiff
path: root/src/detect
diff options
context:
space:
mode:
authorOgulcan Celik <ogulcancelik@gmail.com>2026-06-08 20:55:51 +0300
committerOgulcan Celik <ogulcancelik@gmail.com>2026-06-09 04:26:19 +0300
commitee51c5e5fbaea694e65bb0a4908f75bcaf9707d1 (patch)
treef566d2a5921d4112602a7abcffb5cf6eb04d5f24 /src/detect
parenta7cd7806f2fa0251e2dca41ffec61ceafb6f0e18 (diff)
feat: use pty-first agent detection
Diffstat (limited to 'src/detect')
-rw-r--r--src/detect/agents/amp.rs23
-rw-r--r--src/detect/agents/antigravity.rs15
-rw-r--r--src/detect/agents/claude_code.rs10
-rw-r--r--src/detect/agents/cline.rs14
-rw-r--r--src/detect/agents/codex.rs4
-rw-r--r--src/detect/agents/cursor.rs10
-rw-r--r--src/detect/agents/droid.rs27
-rw-r--r--src/detect/agents/gemini.rs35
-rw-r--r--src/detect/agents/github_copilot.rs14
-rw-r--r--src/detect/agents/grok.rs17
-rw-r--r--src/detect/agents/hermes.rs22
-rw-r--r--src/detect/agents/kilo.rs4
-rw-r--r--src/detect/agents/kimi.rs50
-rw-r--r--src/detect/agents/kiro.rs7
-rw-r--r--src/detect/agents/mod.rs28
-rw-r--r--src/detect/agents/opencode.rs6
-rw-r--r--src/detect/agents/qodercli.rs14
-rw-r--r--src/detect/mod.rs140
18 files changed, 222 insertions, 218 deletions
diff --git a/src/detect/agents/amp.rs b/src/detect/agents/amp.rs
index ad76ca27..b1fcba4d 100644
--- a/src/detect/agents/amp.rs
+++ b/src/detect/agents/amp.rs
@@ -17,6 +17,19 @@ use super::super::AgentState;
pub(super) fn detect(content: &str) -> AgentState {
let lower = content.to_lowercase();
+ if has_visible_blocker(content) {
+ return AgentState::Blocked;
+ }
+
+ if lower.contains("esc to cancel") {
+ return AgentState::Working;
+ }
+
+ AgentState::Idle
+}
+
+pub(super) fn has_visible_blocker(content: &str) -> bool {
+ let lower = content.to_lowercase();
let has_waiting_for_approval = lower.contains("waiting for approval");
let has_approval_header = lower.contains("invoke tool")
|| lower.contains("run this command?")
@@ -29,13 +42,5 @@ pub(super) fn detect(content: &str) -> AgentState {
|| lower.contains("allow file for every session")
|| lower.contains("deny with feedback"));
- if has_approval_actions && (has_waiting_for_approval || has_approval_header) {
- return AgentState::Blocked;
- }
-
- if lower.contains("esc to cancel") {
- return AgentState::Working;
- }
-
- AgentState::Idle
+ has_approval_actions && (has_waiting_for_approval || has_approval_header)
}
diff --git a/src/detect/agents/antigravity.rs b/src/detect/agents/antigravity.rs
index b504a96a..9790c5a4 100644
--- a/src/detect/agents/antigravity.rs
+++ b/src/detect/agents/antigravity.rs
@@ -1,12 +1,7 @@
use super::super::AgentState;
pub(super) fn detect(content: &str) -> AgentState {
- let lower = content.to_lowercase();
-
- let has_permission_request = lower.contains("requesting permission for:");
- let has_permission_question = lower.contains("do you want to proceed?");
- let has_permission_controls = lower.contains("tab amend") && lower.contains("edit command");
- if has_permission_request && (has_permission_question || has_permission_controls) {
+ if has_visible_blocker(content) {
return AgentState::Blocked;
}
@@ -17,6 +12,14 @@ pub(super) fn detect(content: &str) -> AgentState {
AgentState::Idle
}
+pub(super) fn has_visible_blocker(content: &str) -> bool {
+ let lower = content.to_lowercase();
+ let has_permission_request = lower.contains("requesting permission for:");
+ let has_permission_question = lower.contains("do you want to proceed?");
+ let has_permission_controls = lower.contains("tab amend") && lower.contains("edit command");
+ has_permission_request && (has_permission_question || has_permission_controls)
+}
+
fn has_antigravity_spinner(content: &str) -> bool {
content.lines().any(|line| {
let trimmed = line.trim_start();
diff --git a/src/detect/agents/claude_code.rs b/src/detect/agents/claude_code.rs
index 910eb679..a13019a4 100644
--- a/src/detect/agents/claude_code.rs
+++ b/src/detect/agents/claude_code.rs
@@ -27,6 +27,10 @@ pub(super) fn detect(content: &str) -> AgentState {
return AgentState::Blocked;
}
+ if has_dynamic_workflow_prompt(&lower) {
+ return AgentState::Blocked;
+ }
+
if has_working_chrome(content) {
return AgentState::Working;
}
@@ -45,6 +49,7 @@ pub(super) fn detect(content: &str) -> AgentState {
pub(super) fn has_visible_blocker(content: &str) -> bool {
let lower = content.to_lowercase();
has_live_blocked_form(content)
+ || has_dynamic_workflow_prompt(&lower)
|| lower.contains("do you want to proceed?")
&& has_claude_yes_no_choice(content)
&& (lower.contains("bash command")
@@ -96,6 +101,7 @@ fn has_claude_blocked_prompt(content: &str, lower_content: &str) -> bool {
has_confirmation_prompt(lower_content)
|| lower_content.contains("do you want to proceed?")
|| lower_content.contains("would you like to proceed?")
+ || has_dynamic_workflow_prompt(lower_content)
|| lower_content.contains("waiting for permission")
|| lower_content.contains("do you want to allow this connection?")
|| lower_content.contains("tab to amend")
@@ -105,6 +111,10 @@ fn has_claude_blocked_prompt(content: &str, lower_content: &str) -> bool {
|| (has_selection_prompt(content) && has_claude_yes_no_choice(content))
}
+fn has_dynamic_workflow_prompt(lower_content: &str) -> bool {
+ lower_content.contains("run a dynamic workflow?") && lower_content.contains("esc to cancel")
+}
+
fn has_live_blocked_form(content: &str) -> bool {
let region = content_after_last_horizontal_rule(content);
region.lines().any(|line| {
diff --git a/src/detect/agents/cline.rs b/src/detect/agents/cline.rs
index 86b5ce01..13509606 100644
--- a/src/detect/agents/cline.rs
+++ b/src/detect/agents/cline.rs
@@ -4,11 +4,7 @@ pub(super) fn detect(content: &str) -> AgentState {
let lower = content.to_lowercase();
// Blocked
- if lower.contains("let cline use this tool") {
- return AgentState::Blocked;
- }
- // [act mode] or [plan mode] followed by "yes"
- if (lower.contains("[act mode]") || lower.contains("[plan mode]")) && lower.contains("yes") {
+ if has_visible_blocker(content) {
return AgentState::Blocked;
}
@@ -20,3 +16,11 @@ pub(super) fn detect(content: &str) -> AgentState {
// Cline defaults to working (unlike most agents that default to idle)
AgentState::Working
}
+
+pub(super) fn has_visible_blocker(content: &str) -> bool {
+ let lower = content.to_lowercase();
+ lower.contains("let cline use this tool")
+ || ((lower.contains("[act mode]") || lower.contains("[plan mode]"))
+ && (lower.contains("execute command?") || lower.contains("use this tool?"))
+ && lower.contains("yes"))
+}
diff --git a/src/detect/agents/codex.rs b/src/detect/agents/codex.rs
index 0a9bdadb..b77b7d25 100644
--- a/src/detect/agents/codex.rs
+++ b/src/detect/agents/codex.rs
@@ -38,10 +38,6 @@ pub(super) fn has_visible_blocker(content: &str) -> bool {
has_codex_strong_blocked_prompt(content)
}
-pub(super) fn has_prompt(content: &str) -> bool {
- has_codex_current_prompt(content) || content.lines().any(codex_prompt_line)
-}
-
pub(super) fn has_visible_working(content: &str) -> bool {
has_codex_live_working_at_current_prompt(content)
|| (!has_codex_current_prompt(content) && has_codex_visible_working_without_prompt(content))
diff --git a/src/detect/agents/cursor.rs b/src/detect/agents/cursor.rs
index a62e9382..f0f00b9b 100644
--- a/src/detect/agents/cursor.rs
+++ b/src/detect/agents/cursor.rs
@@ -4,7 +4,7 @@ pub(super) fn detect(content: &str) -> AgentState {
let lower = content.to_lowercase();
// Blocked
- if has_cursor_blocked_prompt(content, &lower) {
+ if has_visible_blocker(content) {
return AgentState::Blocked;
}
@@ -19,8 +19,12 @@ pub(super) fn detect(content: &str) -> AgentState {
AgentState::Idle
}
-fn has_cursor_blocked_prompt(content: &str, lower: &str) -> bool {
- if lower.contains("waiting for approval") || lower.contains("run this command?") {
+pub(super) fn has_visible_blocker(content: &str) -> bool {
+ let lower = content.to_lowercase();
+ if lower.contains("waiting for approval")
+ && lower.contains("run this command?")
+ && (lower.contains("run (once) (y)") || lower.contains("skip (esc or n)"))
+ {
return true;
}
diff --git a/src/detect/agents/droid.rs b/src/detect/agents/droid.rs
index ea19da3f..52c5e087 100644
--- a/src/detect/agents/droid.rs
+++ b/src/detect/agents/droid.rs
@@ -9,19 +9,7 @@ use super::super::{has_braille_spinner, AgentState};
pub(super) fn detect(content: &str) -> AgentState {
let lower = content.to_lowercase();
- // Blocked: EXECUTE approval prompt with selection UI chrome
- // Primary (AND): structural keyword + chrome text = certain
- let has_execute = content.contains("EXECUTE");
- let has_selection_chrome = lower.contains("enter to select")
- || lower.contains("↑↓ to navigate")
- || lower.contains("esc to cancel");
- let has_selection_options = lower.contains("> yes, allow") || lower.contains("> no, cancel");
-
- if has_execute && (has_selection_chrome || has_selection_options) {
- return AgentState::Blocked;
- }
- // Secondary: selection chrome + options together (no EXECUTE needed)
- if has_selection_chrome && has_selection_options {
+ if has_visible_blocker(content) {
return AgentState::Blocked;
}
@@ -37,3 +25,16 @@ pub(super) fn detect(content: &str) -> AgentState {
AgentState::Idle
}
+
+pub(super) fn has_visible_blocker(content: &str) -> bool {
+ let lower = content.to_lowercase();
+ // Primary (AND): structural keyword + chrome text = certain
+ let has_execute = content.contains("EXECUTE");
+ let has_selection_chrome = lower.contains("enter to select")
+ || lower.contains("↑↓ to navigate")
+ || lower.contains("esc to cancel");
+ let has_selection_options = lower.contains("> yes, allow") || lower.contains("> no, cancel");
+
+ (has_execute && (has_selection_chrome || has_selection_options))
+ || (has_selection_chrome && has_selection_options)
+}
diff --git a/src/detect/agents/gemini.rs b/src/detect/agents/gemini.rs
index c47355c0..86cf3bca 100644
--- a/src/detect/agents/gemini.rs
+++ b/src/detect/agents/gemini.rs
@@ -1,24 +1,11 @@
-use super::super::{has_confirmation_prompt, AgentState};
+use super::super::AgentState;
pub(super) fn detect(content: &str) -> AgentState {
- let lower = content.to_lowercase();
-
- // Blocked — explicit confirmation
- if lower.contains("waiting for user confirmation") {
- return AgentState::Blocked;
- }
-
- // Blocked — box-drawing confirmation prompts
- if content.contains("│ Apply this change")
- || content.contains("│ Allow execution")
- || content.contains("│ Do you want to proceed")
- {
- return AgentState::Blocked;
- }
- if has_confirmation_prompt(&lower) {
+ if has_visible_blocker(content) {
return AgentState::Blocked;
}
+ let lower = content.to_lowercase();
// Working
if lower.contains("esc to cancel") {
return AgentState::Working;
@@ -26,3 +13,19 @@ pub(super) fn detect(content: &str) -> AgentState {
AgentState::Idle
}
+
+pub(super) fn has_visible_blocker(content: &str) -> bool {
+ let lower = content.to_lowercase();
+ let has_choice = lower.contains("yes") || lower.contains("no");
+
+ content.contains("│ Apply this change")
+ || content.contains("│ Allow execution")
+ || (has_choice
+ && (lower.contains("waiting for user confirmation")
+ || content.contains("│ Do you want to proceed")
+ || lower.contains("do you want to proceed?")))
+ || content.lines().any(|line| {
+ let line = line.trim().to_ascii_lowercase();
+ line.starts_with("❯") && (line.contains("yes") || line.contains("allow"))
+ })
+}
diff --git a/src/detect/agents/github_copilot.rs b/src/detect/agents/github_copilot.rs
index eed03011..0eece95b 100644
--- a/src/detect/agents/github_copilot.rs
+++ b/src/detect/agents/github_copilot.rs
@@ -4,11 +4,7 @@ pub(super) fn detect(content: &str) -> AgentState {
let lower = content.to_lowercase();
// Blocked
- if lower.contains("esc to cancel")
- && (lower.contains("enter to select")
- || lower.contains("enter to confirm")
- || lower.contains("enter to submit"))
- {
+ if has_visible_blocker(content) {
return AgentState::Blocked;
}
@@ -22,3 +18,11 @@ pub(super) fn detect(content: &str) -> AgentState {
AgentState::Idle
}
+
+pub(super) fn has_visible_blocker(content: &str) -> bool {
+ let lower = content.to_lowercase();
+ lower.contains("esc to cancel")
+ && (lower.contains("enter to select")
+ || lower.contains("enter to confirm")
+ || lower.contains("enter to submit"))
+}
diff --git a/src/detect/agents/grok.rs b/src/detect/agents/grok.rs
index 75b5cd35..8a5834a2 100644
--- a/src/detect/agents/grok.rs
+++ b/src/detect/agents/grok.rs
@@ -7,17 +7,11 @@ use super::super::{has_braille_spinner, AgentState};
/// status line such as "⠋ Waiting… 1.8s" plus live controls like
/// "Ctrl+c:cancel" and "Ctrl+Enter:interject".
pub(super) fn detect(content: &str) -> AgentState {
- let lower = content.to_lowercase();
-
- if lower.contains("use ← → to choose permission whitelist scope")
- || lower.contains("yes, proceed")
- || lower.contains("no, reject")
- || lower.contains("ctrl+o:yolo")
- || lower.contains(":scope")
- {
+ if has_visible_blocker(content) {
return AgentState::Blocked;
}
+ let lower = content.to_lowercase();
if has_braille_spinner(content)
&& (lower.contains("waiting")
|| lower.contains("run ")
@@ -34,3 +28,10 @@ pub(super) fn detect(content: &str) -> AgentState {
AgentState::Idle
}
+
+pub(super) fn has_visible_blocker(content: &str) -> bool {
+ let lower = content.to_lowercase();
+ let has_scope_selector = lower.contains("use ← → to choose permission whitelist scope")
+ || lower.contains("←/→:scope");
+ has_scope_selector && lower.contains("yes, proceed") && lower.contains("no, reject")
+}
diff --git a/src/detect/agents/hermes.rs b/src/detect/agents/hermes.rs
index d6c4c97e..474dda5c 100644
--- a/src/detect/agents/hermes.rs
+++ b/src/detect/agents/hermes.rs
@@ -6,21 +6,25 @@ use super::super::AgentState;
/// dialogs for dangerous terminal commands. Prefer the modal controls for
/// blocked detection, then the live interrupt/status controls for working.
pub(super) fn detect(content: &str) -> AgentState {
- let lower = content.to_lowercase();
-
- let has_approval_options = lower.contains("allow once")
- && lower.contains("allow for this session")
- && lower.contains("deny");
- let has_approval_controls = lower.contains("enter to confirm")
- || lower.contains("↑/↓ to select")
- || lower.contains("show full command");
- if (lower.contains("dangerous command") || has_approval_options) && has_approval_controls {
+ if has_visible_blocker(content) {
return AgentState::Blocked;
}
+ let lower = content.to_lowercase();
if lower.contains("msg=interrupt") || lower.contains("ctrl+c cancel") {
return AgentState::Working;
}
AgentState::Idle
}
+
+pub(super) fn has_visible_blocker(content: &str) -> bool {
+ let lower = content.to_lowercase();
+ let has_approval_options = lower.contains("allow once")
+ && lower.contains("allow for this session")
+ && lower.contains("deny");
+ let has_approval_controls = lower.contains("enter to confirm")
+ || lower.contains("↑/↓ to select")
+ || lower.contains("show full command");
+ (lower.contains("dangerous command") || has_approval_options) && has_approval_controls
+}
diff --git a/src/detect/agents/kilo.rs b/src/detect/agents/kilo.rs
index 1ab3651a..46a5601a 100644
--- a/src/detect/agents/kilo.rs
+++ b/src/detect/agents/kilo.rs
@@ -7,3 +7,7 @@ pub(super) fn detect(content: &str) -> AgentState {
super::opencode::detect(content)
}
+
+pub(super) fn has_visible_blocker(content: &str) -> bool {
+ super::opencode::has_visible_blocker(content)
+}
diff --git a/src/detect/agents/kimi.rs b/src/detect/agents/kimi.rs
index b42bf885..9d3821ed 100644
--- a/src/detect/agents/kimi.rs
+++ b/src/detect/agents/kimi.rs
@@ -16,10 +16,6 @@ pub(super) fn has_visible_blocker(content: &str) -> bool {
has_current_approval_panel(content) || has_question_panel(content)
}
-pub(super) fn has_prompt_box(content: &str) -> bool {
- has_editor_prompt_box(content) && has_footer_context(content)
-}
-
pub(super) fn has_visible_working(content: &str) -> bool {
has_kimi_working_status(content)
}
@@ -99,49 +95,3 @@ fn has_question_panel(content: &str) -> bool {
fn has_numeric_choose_hint(lower_content: &str) -> bool {
lower_content.contains(" choose") && lower_content.contains('1') && lower_content.contains('2')
}
-
-fn has_editor_prompt_box(content: &str) -> bool {
- let lines: Vec<&str> = content.lines().collect();
-
- for top_index in 0..lines.len() {
- if !is_editor_top_border(lines[top_index]) {
- continue;
- }
-
- let mut saw_prompt = false;
- for line in lines.iter().skip(top_index + 1) {
- if is_editor_bottom_border(line) {
- if saw_prompt {
- return true;
- }
- break;
- }
-
- saw_prompt |= is_editor_prompt_line(line);
- }
- }
-
- false
-}
-
-fn is_editor_top_border(line: &str) -> bool {
- let trimmed = line.trim();
- ((trimmed.starts_with('╭') && trimmed.ends_with('╮'))
- || (trimmed.starts_with('├') && trimmed.ends_with('┤')))
- && trimmed.contains('─')
-}
-
-fn is_editor_bottom_border(line: &str) -> bool {
- let trimmed = line.trim();
- trimmed.starts_with('╰') && trimmed.ends_with('╯') && trimmed.contains('─')
-}
-
-fn is_editor_prompt_line(line: &str) -> bool {
- let trimmed = line.trim_start();
- let inner = trimmed.strip_prefix('│').unwrap_or(trimmed).trim_start();
- inner.starts_with('>')
-}
-
-fn has_footer_context(content: &str) -> bool {
- content.to_lowercase().contains("context: ")
-}
diff --git a/src/detect/agents/kiro.rs b/src/detect/agents/kiro.rs
index f40b9bcb..889f5315 100644
--- a/src/detect/agents/kiro.rs
+++ b/src/detect/agents/kiro.rs
@@ -7,7 +7,7 @@ use super::super::AgentState;
pub(super) fn detect(content: &str) -> AgentState {
let lower = content.to_lowercase();
- if has_kiro_blocked_prompt(&lower) {
+ if has_visible_blocker(content) {
return AgentState::Blocked;
}
@@ -20,8 +20,9 @@ pub(super) fn detect(content: &str) -> AgentState {
AgentState::Idle
}
-fn has_kiro_blocked_prompt(lower_content: &str) -> bool {
- has_tool_approval_prompt(lower_content) || has_subagent_approval_prompt(lower_content)
+pub(super) fn has_visible_blocker(content: &str) -> bool {
+ let lower_content = content.to_lowercase();
+ has_tool_approval_prompt(&lower_content) || has_subagent_approval_prompt(&lower_content)
}
fn has_tool_approval_prompt(lower_content: &str) -> bool {
diff --git a/src/detect/agents/mod.rs b/src/detect/agents/mod.rs
index 46a25f66..704350df 100644
--- a/src/detect/agents/mod.rs
+++ b/src/detect/agents/mod.rs
@@ -45,7 +45,6 @@ pub(super) fn detect(agent: Agent, screen_content: &str) -> AgentDetection {
state,
skip_state_update: true,
visible_blocker: false,
- visible_idle: false,
visible_working: false,
};
}
@@ -54,7 +53,6 @@ pub(super) fn detect(agent: Agent, screen_content: &str) -> AgentDetection {
state,
skip_state_update: false,
visible_blocker: has_visible_blocker(agent, screen_content, state),
- visible_idle: has_visible_idle(agent, screen_content, state),
visible_working: has_visible_working(agent, screen_content, state),
}
}
@@ -79,20 +77,20 @@ fn has_visible_blocker(agent: Agent, content: &str, state: AgentState) -> bool {
// is known to be structural and live.
Agent::Claude => claude_code::has_visible_blocker(content),
Agent::Codex => codex::has_visible_blocker(content),
+ Agent::Gemini => gemini::has_visible_blocker(content),
+ Agent::Cursor => cursor::has_visible_blocker(content),
+ Agent::Antigravity => antigravity::has_visible_blocker(content),
+ Agent::Cline => cline::has_visible_blocker(content),
+ Agent::OpenCode => opencode::has_visible_blocker(content),
+ Agent::GithubCopilot => github_copilot::has_visible_blocker(content),
Agent::Kimi => kimi::has_visible_blocker(content),
- _ => false,
- }
-}
-
-fn has_visible_idle(agent: Agent, content: &str, state: AgentState) -> bool {
- if state != AgentState::Idle {
- return false;
- }
-
- match agent {
- Agent::Claude => claude_code::has_prompt_box(content),
- Agent::Codex => codex::has_prompt(content),
- Agent::Kimi => kimi::has_prompt_box(content),
+ Agent::Kiro => kiro::has_visible_blocker(content),
+ Agent::Droid => droid::has_visible_blocker(content),
+ Agent::Amp => amp::has_visible_blocker(content),
+ Agent::Grok => grok::has_visible_blocker(content),
+ Agent::Hermes => hermes::has_visible_blocker(content),
+ Agent::Kilo => kilo::has_visible_blocker(content),
+ Agent::Qodercli => qodercli::has_visible_blocker(content),
_ => false,
}
}
diff --git a/src/detect/agents/opencode.rs b/src/detect/agents/opencode.rs
index 219f69ed..ab8a424f 100644
--- a/src/detect/agents/opencode.rs
+++ b/src/detect/agents/opencode.rs
@@ -2,7 +2,7 @@ use super::super::{has_interrupt_pattern, AgentState};
pub(super) fn detect(content: &str) -> AgentState {
// Blocked
- if content.contains("△ Permission required") || has_opencode_question_prompt(content) {
+ if has_visible_blocker(content) {
return AgentState::Blocked;
}
@@ -17,6 +17,10 @@ pub(super) fn detect(content: &str) -> AgentState {
AgentState::Idle
}
+pub(super) fn has_visible_blocker(content: &str) -> bool {
+ content.contains("△ Permission required") || has_opencode_question_prompt(content)
+}
+
fn has_opencode_question_prompt(content: &str) -> bool {
let lower = content.to_lowercase();
let has_enter_action = lower.contains("enter confirm")
diff --git a/src/detect/agents/qodercli.rs b/src/detect/agents/qodercli.rs
index b7da356b..0a4372df 100644
--- a/src/detect/agents/qodercli.rs
+++ b/src/detect/agents/qodercli.rs
@@ -15,7 +15,7 @@ pub(super) fn detect(content: &str) -> AgentState {
return AgentState::Idle;
}
- if has_qodercli_blocked_prompt(&lower) {
+ if has_visible_blocker(content) {
return AgentState::Blocked;
}
@@ -87,9 +87,15 @@ fn has_qodercli_spinner_row(content: &str) -> bool {
/// defensive fallbacks in case the title row scrolls off-screen.
/// * The interactive shell waiting hint emitted by qodercli when an agent
/// spawns a shell that is now parked for user keystrokes.
-fn has_qodercli_blocked_prompt(lower_content: &str) -> bool {
- lower_content.contains("waiting for user confirmation")
- || lower_content.contains("awaiting approval")
+pub(super) fn has_visible_blocker(content: &str) -> bool {
+ let lower_content = content.to_lowercase();
+ (lower_content.contains("waiting for user confirmation")
+ && (lower_content.contains("yes")
+ || lower_content.contains("no")
+ || lower_content.contains("allow")
+ || lower_content.contains("reject")))
+ || (lower_content.contains("awaiting approval")
+ && (lower_content.contains("allow") || lower_content.contains("reject")))
|| lower_content.contains("permission required")
|| lower_content.contains("allow once or always?")
|| lower_content.contains("asking user")
diff --git a/src/detect/mod.rs b/src/detect/mod.rs
index 529574f9..24393c59 100644
--- a/src/detect/mod.rs
+++ b/src/detect/mod.rs
@@ -29,13 +29,9 @@ pub struct AgentDetection {
/// human input. This is stronger than arbitrary prompt-like text in the
/// scrollback and may override a non-blocked integration state.
pub visible_blocker: bool,
- /// True when the current screen visibly shows the agent's idle input UI.
- /// This lets Herdr recover from integrations that miss an interrupt/stop
- /// event without treating an empty or ambiguous screen as idle authority.
- pub visible_idle: bool,
- /// True when the current screen visibly shows live working chrome. This is
- /// narrower than a fallback `Working` heuristic and may guard against stale
- /// hook idle reports.
+ /// True when the current screen visibly shows live working chrome. PTY
+ /// activity is the normal working authority; this remains diagnostic
+ /// metadata and for non-PTY fallback paths.
pub visible_working: bool,
}
@@ -178,7 +174,6 @@ pub fn detect_agent(agent: Option<Agent>, screen_content: &str) -> AgentDetectio
state: AgentState::Unknown,
skip_state_update: false,
visible_blocker: false,
- visible_idle: false,
visible_working: false,
};
};
@@ -1135,7 +1130,6 @@ mod tests {
let detection = detect_agent(Some(Agent::Claude), screen);
assert!(detection.skip_state_update);
- assert!(!detection.visible_idle);
assert!(!detection.visible_working);
assert!(!detection.visible_blocker);
}
@@ -1162,7 +1156,6 @@ mod tests {
let detection = detect_agent(Some(Agent::Claude), screen);
assert!(!detection.skip_state_update);
- assert!(detection.visible_idle);
}
#[test]
@@ -1196,7 +1189,6 @@ mod tests {
assert_eq!(detection.state, AgentState::Blocked);
assert!(detection.visible_blocker);
- assert!(!detection.visible_idle);
}
#[test]
@@ -1216,13 +1208,31 @@ mod tests {
}
#[test]
+ fn claude_dynamic_workflow_prompt_is_visible_blocker() {
+ let screen = "● Workflow(Review the current worktree diff and verify the resulting findings)\n\n─────────────────────────────────────────────────────────────────────────────────────────\n Run a dynamic workflow?\n\n Review the current worktree diff and verify the resulting findings\n\n This dynamic workflow will spin up multiple subagents across the following phases:\n 1. Overview — map the diff and identify coupled subsystems\n 2. Review — review each changed file in parallel\n 3. Verify — adversarially verify each finding\n 4. Synthesize — summarize confirmed issues and residual risk\n\n Dynamic workflows can use a lot of tokens quickly by running many subagents in parallel — which counts against your usage limit. Stop a running workflow at any time with\n /workflows, or disable dynamic workflows in /config.\n\n ❯ 1. Yes, run it\n 2. View raw script\n 3. No\n\n Esc to cancel · Tab to amend\n ctrl+g to edit script in $EDITOR";
+ let detection = detect_agent(Some(Agent::Claude), screen);
+
+ assert_eq!(detection.state, AgentState::Blocked);
+ assert!(detection.visible_blocker);
+ assert!(!detection.visible_working);
+ }
+
+ #[test]
+ fn claude_dynamic_workflow_prompt_uses_stable_modal_gate() {
+ let screen = "● Workflow(Evaluate changes)\n\n─────────────────────────────────────────────────────────────────────────────────────────\n Run a dynamic workflow?\n\n 1. Scope\n 2. Review\n 3. Synthesize\n\n Esc to cancel · Tab to amend";
+ let detection = detect_agent(Some(Agent::Claude), screen);
+
+ assert_eq!(detection.state, AgentState::Blocked);
+ assert!(detection.visible_blocker);
+ }
+
+ #[test]
fn claude_question_form_selected_top_is_visible_blocker() {
let screen = "❯ ask again\n─────────────────────────────────────────────────────────────────────────────────────────\n← ☐ Subject ☐ Tone ✔ Submit →\n\nWhat should I ask you about?\n\n❯ 1. Today\n Your current plan or priority.\n 2. Project\n A codebase, feature, bug, or PR.\n 3. Preference\n How you want me to work with you.\n 4. Random\n A casual question with no work context.\n 5. Type something.\n─────────────────────────────────────────────────────────────────────────────────────────\n 6. Chat about this\n\nEnter to select · Tab/Arrow keys to navigate · Esc to cancel";
let detection = detect_agent(Some(Agent::Claude), screen);
assert_eq!(detection.state, AgentState::Blocked);
assert!(detection.visible_blocker);
- assert!(!detection.visible_idle);
}
#[test]
@@ -1232,7 +1242,6 @@ mod tests {
assert_eq!(detection.state, AgentState::Blocked);
assert!(detection.visible_blocker);
- assert!(!detection.visible_idle);
}
#[test]
@@ -1242,7 +1251,6 @@ mod tests {
assert_eq!(detection.state, AgentState::Blocked);
assert!(detection.visible_blocker);
- assert!(!detection.visible_idle);
}
#[test]
@@ -1264,31 +1272,28 @@ mod tests {
}
#[test]
- fn claude_prompt_box_is_visible_idle() {
+ fn claude_prompt_box_does_not_set_screen_idle_signal() {
let screen = "Interrupted.\n─────────────\n❯ \n─────────────";
let detection = detect_agent(Some(Agent::Claude), screen);
assert_eq!(detection.state, AgentState::Idle);
- assert!(detection.visible_idle);
}
#[test]
- fn claude_prompt_box_with_status_text_and_custom_status_is_visible_idle() {
+ fn claude_prompt_box_with_status_text_and_custom_status_does_not_set_screen_idle_signal() {
let screen = "──────────────────────────────────────────── ◐ medium · /effort\n❯ \n────────────────────────────────────────────\n thommie-backend | refactor/cleanup-codebase | Opus 4.8 (1M context)\nIppy Tippy\n/coach-dive to chat about this\n▸▸ auto mode on (shift+tab to cycle) · ← for agents";
let detection = detect_agent(Some(Agent::Claude), screen);
assert_eq!(detection.state, AgentState::Idle);
- assert!(detection.visible_idle);
assert!(!detection.visible_blocker);
}
#[test]
- fn claude_interrupted_permission_prompt_box_is_visible_idle() {
+ fn claude_interrupted_permission_prompt_box_does_not_set_screen_idle_signal() {
let screen = "❯ this is a test, create some dummy files on /tmp and -rm rf them i wanna test\n permissions\n\n Thought for 7s (ctrl+o to expand)\n\n● Bash(tmpdir=$(mktemp -d /tmp/claude-perm-test.XXXXXX) && touch \"$tmpdir/file1.txt\"\n \"$tmpdir/file2.log\" && mkdir \"$tmpdir/subdir\" && touch\n \"$tmpdir/subdir/nested.txt\"…)\n ⎿ Interrupted · What should Claude do instead?\n\n─────────────────────────────────────────────────────────────────────────────────────────\n❯ \n─────────────────────────────────────────────────────────────────────────────────────────\n ~/P/herdr ⎇ master ▱▱▱▱▱ 0%";
let detection = detect_agent(Some(Agent::Claude), screen);
assert_eq!(detection.state, AgentState::Idle);
- assert!(detection.visible_idle);
assert!(!detection.visible_working);
assert!(!detection.visible_blocker);
}
@@ -1299,7 +1304,6 @@ mod tests {
let detection = detect_agent(Some(Agent::Claude), screen);
assert_eq!(detection.state, AgentState::Idle);
- assert!(detection.visible_idle);
assert!(!detection.visible_working);
assert!(!detection.visible_blocker);
}
@@ -1310,7 +1314,6 @@ mod tests {
let detection = detect_agent(Some(Agent::Claude), screen);
assert_eq!(detection.state, AgentState::Idle);
- assert!(detection.visible_idle);
assert!(!detection.visible_working);
assert!(!detection.visible_blocker);
}
@@ -1322,17 +1325,15 @@ mod tests {
assert_eq!(detection.state, AgentState::Working);
assert!(detection.visible_working);
- assert!(!detection.visible_idle);
assert!(!detection.visible_blocker);
}
#[test]
- fn claude_separators_without_prompt_are_not_visible_idle() {
+ fn claude_separators_without_prompt_do_not_set_screen_idle_signal() {
let screen = "Task complete.\n─────────────\nplain text\n─────────────";
let detection = detect_agent(Some(Agent::Claude), screen);
assert_eq!(detection.state, AgentState::Idle);
- assert!(!detection.visible_idle);
}
#[test]
@@ -1342,7 +1343,6 @@ mod tests {
assert_eq!(detection.state, AgentState::Working);
assert!(detection.visible_working);
- assert!(!detection.visible_idle);
}
#[test]
@@ -1352,7 +1352,6 @@ mod tests {
assert_eq!(detection.state, AgentState::Working);
assert!(detection.visible_working);
- assert!(!detection.visible_idle);
assert!(!detection.visible_blocker);
}
@@ -1363,7 +1362,6 @@ mod tests {
assert_eq!(detection.state, AgentState::Working);
assert!(detection.visible_working);
- assert!(!detection.visible_idle);
}
#[test]
@@ -1372,7 +1370,6 @@ mod tests {
let detection = detect_agent(Some(Agent::Claude), screen);
assert_eq!(detection.state, AgentState::Idle);
- assert!(detection.visible_idle);
assert!(!detection.visible_working);
assert!(!detection.visible_blocker);
}
@@ -1383,7 +1380,6 @@ mod tests {
let detection = detect_agent(Some(Agent::Claude), screen);
assert_eq!(detection.state, AgentState::Idle);
- assert!(detection.visible_idle);
assert!(!detection.visible_working);
assert!(!detection.visible_blocker);
}
@@ -1394,7 +1390,6 @@ mod tests {
let detection = detect_agent(Some(Agent::Claude), screen);
assert_eq!(detection.state, AgentState::Idle);
- assert!(detection.visible_idle);
assert!(!detection.visible_working);
}
@@ -1404,7 +1399,6 @@ mod tests {
let detection = detect_agent(Some(Agent::Claude), screen);
assert_eq!(detection.state, AgentState::Idle);
- assert!(detection.visible_idle);
assert!(!detection.visible_working);
}
@@ -1467,7 +1461,6 @@ mod tests {
let detection = detect_agent(Some(Agent::Codex), screen);
assert_eq!(detection.state, AgentState::Idle);
- assert!(detection.visible_idle);
assert!(!detection.visible_blocker);
}
@@ -1477,7 +1470,6 @@ mod tests {
let detection = detect_agent(Some(Agent::Codex), screen);
assert_eq!(detection.state, AgentState::Idle);
- assert!(detection.visible_idle);
assert!(!detection.visible_blocker);
}
@@ -1493,11 +1485,11 @@ mod tests {
}
#[test]
- fn non_codex_blocked_heuristics_are_not_strong_visible_blockers_by_default() {
+ fn gemini_confirmation_prompt_is_visible_blocker() {
let detection = detect_agent(Some(Agent::Gemini), "Do you want to proceed?\n\nYes No");
assert_eq!(detection.state, AgentState::Blocked);
- assert!(!detection.visible_blocker);
+ assert!(detection.visible_blocker);
}
#[test]
@@ -1517,16 +1509,14 @@ mod tests {
assert_eq!(detection.state, AgentState::Blocked);
assert!(detection.visible_blocker);
- assert!(!detection.visible_idle);
}
#[test]
- fn codex_interrupted_prompt_is_visible_idle() {
+ fn codex_interrupted_prompt_does_not_set_screen_idle_signal() {
let screen = "■ Conversation interrupted - tell the model what to do differently. Something went\nwrong? Hit `/feedback` to report the issue.\n\n\n› Run /review on my current changes\n\n gpt-5.5 high · ~/Projects/herdr-worktrees/issue-249-state-arbitration";
let detection = detect_agent(Some(Agent::Codex), screen);
assert_eq!(detection.state, AgentState::Idle);
- assert!(detection.visible_idle);
}
#[test]
@@ -1551,7 +1541,6 @@ mod tests {
assert_eq!(detection.state, AgentState::Working);
assert!(detection.visible_working);
- assert!(!detection.visible_idle);
}
#[test]
@@ -1563,7 +1552,6 @@ mod tests {
assert_eq!(detection.state, AgentState::Working);
assert!(detection.visible_working);
- assert!(!detection.visible_idle);
}
#[test]
@@ -1575,7 +1563,6 @@ mod tests {
assert_eq!(detection.state, AgentState::Working);
assert!(detection.visible_working);
- assert!(!detection.visible_idle);
}
#[test]
@@ -1587,7 +1574,7 @@ mod tests {
assert_eq!(detection.state, AgentState::Working);
assert!(detection.visible_working);
- assert!(!detection.visible_idle);
+ assert!(!detection.visible_blocker);
}
#[test]
@@ -1606,7 +1593,7 @@ mod tests {
);
assert_eq!(detection.state, AgentState::Idle);
- assert!(detection.visible_idle);
+ assert!(!detection.visible_blocker);
assert!(!detection.visible_working);
}
@@ -1619,7 +1606,6 @@ mod tests {
assert_eq!(detection.state, AgentState::Working);
assert!(detection.visible_working);
- assert!(!detection.visible_idle);
}
#[test]
@@ -1631,7 +1617,6 @@ mod tests {
assert_eq!(detection.state, AgentState::Working);
assert!(detection.visible_working);
- assert!(!detection.visible_idle);
}
#[test]
@@ -1643,7 +1628,6 @@ mod tests {
assert_eq!(detection.state, AgentState::Working);
assert!(detection.visible_working);
- assert!(!detection.visible_idle);
}
#[test]
@@ -1655,7 +1639,6 @@ mod tests {
assert_eq!(detection.state, AgentState::Working);
assert!(detection.visible_working);
- assert!(!detection.visible_idle);
}
#[test]
@@ -1667,7 +1650,6 @@ mod tests {
assert_eq!(detection.state, AgentState::Working);
assert!(detection.visible_working);
- assert!(!detection.visible_idle);
}
#[test]
@@ -1678,7 +1660,6 @@ mod tests {
);
assert_eq!(detection.state, AgentState::Idle);
- assert!(detection.visible_idle);
assert!(!detection.visible_working);
}
@@ -1690,7 +1671,6 @@ mod tests {
);
assert_eq!(detection.state, AgentState::Idle);
- assert!(detection.visible_idle);
assert!(!detection.visible_working);
}
@@ -1703,7 +1683,6 @@ mod tests {
assert_eq!(detection.state, AgentState::Working);
assert!(detection.visible_working);
- assert!(!detection.visible_idle);
}
#[test]
@@ -1726,7 +1705,6 @@ mod tests {
assert_eq!(detection.state, AgentState::Idle);
assert!(!detection.visible_working);
- assert!(detection.visible_idle);
}
#[test]
@@ -1738,7 +1716,6 @@ mod tests {
assert_eq!(detection.state, AgentState::Idle);
assert!(!detection.visible_working);
- assert!(detection.visible_idle);
}
#[test]
@@ -1755,7 +1732,6 @@ mod tests {
assert_eq!(detection.state, AgentState::Working);
assert!(detection.visible_working);
- assert!(!detection.visible_idle);
}
}
@@ -1770,7 +1746,6 @@ mod tests {
let detection = detect_agent(Some(Agent::Codex), screen);
assert!(detection.skip_state_update);
- assert!(!detection.visible_idle);
assert!(!detection.visible_working);
assert!(!detection.visible_blocker);
}
@@ -1781,7 +1756,6 @@ mod tests {
let detection = detect_agent(Some(Agent::Codex), screen);
assert!(detection.skip_state_update);
- assert!(!detection.visible_idle);
}
#[test]
@@ -1790,7 +1764,6 @@ mod tests {
let detection = detect_agent(Some(Agent::Codex), screen);
assert!(detection.skip_state_update);
- assert!(!detection.visible_idle);
}
#[test]
@@ -1799,7 +1772,6 @@ mod tests {
let detection = detect_agent(Some(Agent::Codex), screen);
assert!(!detection.skip_state_update);
- assert!(detection.visible_idle);
}
#[test]
@@ -1815,12 +1787,20 @@ mod tests {
#[test]
fn gemini_waiting_confirmation() {
assert_eq!(
- detect_gemini("waiting for user confirmation"),
+ detect_gemini("waiting for user confirmation\nYes No"),
AgentState::Blocked
);
}
#[test]
+ fn gemini_waiting_text_without_choices_is_idle() {
+ assert_eq!(
+ detect_gemini("waiting for user confirmation"),
+ AgentState::Idle
+ );
+ }
+
+ #[test]
fn gemini_waiting_apply() {
assert_eq!(
detect_gemini("│ Apply this change\n│ Yes │ No"),
@@ -1893,6 +1873,14 @@ mod tests {
}
#[test]
+ fn cursor_approval_words_without_visible_controls_are_idle() {
+ assert_eq!(
+ detect_cursor("previous output: waiting for approval"),
+ AgentState::Idle
+ );
+ }
+
+ #[test]
fn cursor_running_text_with_unrelated_yes_is_not_blocked() {
let screen = "previous answer mentioned (y)\n⠠⠜ Running 5.52k tokens";
assert_eq!(detect_cursor(screen), AgentState::Working);
@@ -1992,6 +1980,14 @@ mod tests {
}
#[test]
+ fn cline_mode_text_with_unrelated_yes_is_not_blocked() {
+ assert_eq!(
+ detect_cline("[act mode]\nPrevious answer was yes."),
+ AgentState::Working
+ );
+ }
+
+ #[test]
fn cline_idle_ready() {
assert_eq!(
detect_cline("cline is ready for your message"),
@@ -2322,7 +2318,6 @@ mod tests {
assert_eq!(detection.state, AgentState::Blocked);
assert!(detection.visible_blocker);
- assert!(!detection.visible_idle);
}
#[test]
@@ -2332,7 +2327,6 @@ mod tests {
assert_eq!(detection.state, AgentState::Blocked);
assert!(detection.visible_blocker);
- assert!(!detection.visible_idle);
}
#[test]
@@ -2363,7 +2357,6 @@ mod tests {
assert_eq!(detection.state, AgentState::Working);
assert!(detection.visible_working);
- assert!(!detection.visible_idle);
}
#[test]
@@ -2397,12 +2390,11 @@ mod tests {
}
#[test]
- fn kimi_current_editor_box_is_visible_idle() {
+ fn kimi_current_editor_box_does_not_set_screen_idle_signal() {
let screen = "╭──────────────────────────────────────────────────╮\n│ > │\n╰──────────────────────────────────────────────────╯\nk2 ~/Projects/herdr /help: show commands\n context: 0.0%";
let detection = detect_agent(Some(Agent::Kimi), screen);
assert_eq!(detection.state, AgentState::Idle);
- assert!(detection.visible_idle);
assert!(!detection.visible_working);
assert!(!detection.visible_blocker);
}
@@ -2587,11 +2579,17 @@ mod tests {
#[test]
fn grok_blocked_wins_over_spinner() {
- let screen = "⠹ Run git 30s\nYes, proceed\nNo, reject (type to add feedback)";
+ let screen = "⠹ Run git 30s\nUse ← → to choose permission whitelist scope\nYes, proceed\nNo, reject (type to add feedback)";
assert_eq!(detect_state(Some(Agent::Grok), screen), AgentState::Blocked);
}
#[test]
+ fn grok_choice_words_without_scope_selector_are_not_blocked() {
+ let screen = "Yes, proceed\nNo, reject (type to add feedback)";
+ assert_eq!(detect_state(Some(Agent::Grok), screen), AgentState::Idle);
+ }
+
+ #[test]
fn grok_working_on_waiting_spinner() {
let screen = "⠋ Waiting… 1.8s\nCtrl+c:cancel │ Ctrl+Enter:interject";
assert_eq!(detect_state(Some(Agent::Grok), screen), AgentState::Working);
@@ -2666,12 +2664,20 @@ mod tests {
#[test]
fn qodercli_blocked_on_confirmation() {
assert_eq!(
- detect_qodercli("Waiting for user confirmation..."),
+ detect_qodercli("Waiting for user confirmation...\nAllow\nReject"),
AgentState::Blocked,
);
}
#[test]
+ fn qodercli_waiting_confirmation_without_choices_is_idle() {
+ assert_eq!(
+ detect_qodercli("Waiting for user confirmation..."),
+ AgentState::Idle,
+ );
+ }
+
+ #[test]
fn qodercli_working_on_spinner() {
assert_eq!(detect_qodercli("\u{280B} Thinking..."), AgentState::Working);
}