aboutsummaryrefslogtreecommitdiff
path: root/src/detect/agents/kiro.rs
blob: 5ef1fbcaceed66a35f35a95416b6a8d0a3fb3107 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use super::super::AgentState;

/// Kiro CLI detection.
///
/// Kiro exposes reliable working and idle terminal markers. Tool approval
/// prompts render with a stable "requires approval" line and an action menu.
pub(super) fn detect(content: &str) -> AgentState {
    let lower = content.to_lowercase();

    let has_approval_request = lower.contains("requires approval");
    let has_approval_actions = lower.contains("yes, single permission")
        || lower.contains("trust, always allow")
        || lower.contains("no (tab to edit)")
        || lower.contains("esc to close");
    if has_approval_request && has_approval_actions {
        return AgentState::Blocked;
    }

    if lower.contains("kiro is working")
        || (lower.contains("esc to cancel") && has_kiro_tool_spinner(content))
    {
        return AgentState::Working;
    }

    AgentState::Idle
}

fn has_kiro_tool_spinner(content: &str) -> bool {
    content.lines().any(|line| {
        let trimmed = line.trim_start();
        let mut chars = trimmed.chars();
        let Some(first) = chars.next() else {
            return false;
        };
        if !matches!(first, '◔' | '◑' | '◕' | '●') {
            return false;
        }
        let rest = chars.as_str().trim_start();
        rest.chars().next().is_some_and(char::is_alphabetic)
    })
}