blob: b504a96a7e300455ffe892ede9e6bb735384aef5 (
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
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) {
return AgentState::Blocked;
}
if has_antigravity_spinner(content) || has_antigravity_background_tasks(content) {
return AgentState::Working;
}
AgentState::Idle
}
fn has_antigravity_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 !('\u{2800}'..='\u{28FF}').contains(&first) {
return false;
}
let rest = chars
.as_str()
.trim_start_matches(|c| ('\u{2800}'..='\u{28FF}').contains(&c))
.trim_start();
status_word_is_active(rest)
})
}
fn has_antigravity_background_tasks(content: &str) -> bool {
let bottom_lines: Vec<&str> = content
.lines()
.rev()
.filter(|line| !line.trim().is_empty())
.take(5)
.collect();
bottom_lines.into_iter().any(|line| {
let line = line.trim().to_lowercase();
line.contains("/tasks") && antigravity_task_count(&line).is_some_and(|count| count > 0)
})
}
fn antigravity_task_count(line: &str) -> Option<u32> {
for marker in [" task(s)", " tasks", " task"] {
let Some((before, _)) = line.split_once(marker) else {
continue;
};
let raw_count = before.split_whitespace().last()?.trim_matches(|c| c == '·');
if let Ok(count) = raw_count.parse() {
return Some(count);
}
}
None
}
fn status_word_is_active(rest: &str) -> bool {
let Some(word) = rest.split_whitespace().next() else {
return false;
};
word.trim_end_matches(|c: char| !c.is_alphabetic())
.to_ascii_lowercase()
.ends_with("ing")
}
|