Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 73 additions & 8 deletions crates/agent/src/antigravity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,9 @@ pub(super) fn normalize_mcp_tool_name(raw: &str, mcp_servers: &[String]) -> Opti
struct Antigravity {
/// The agent's own record of the session (`conversations/<id>.db`).
record: Mutex<Option<SessionRecord>>,
/// Incremental tailer of the session's `transcript.jsonl` to surface
/// mid-session served-model switches (e.g. Orchestrator planner <-> worker).
model_tailer: Mutex<Option<record::ParentModelTailer>>,
/// Tracks the last seen step index and any open autonomous (proactive)
/// turn so both `session_update` and the background watcher stay in sync.
proactive: Arc<Mutex<subagents::ProactiveTracker>>,
Expand Down Expand Up @@ -596,6 +599,14 @@ impl Antigravity {
.clone()
}

fn poll_served_models(&self) -> Vec<AgentEvent> {
let mut guard = self
.model_tailer
.lock()
.unwrap_or_else(|held| held.into_inner());
guard.as_mut().map_or_else(Vec::new, |t| t.poll())
}

/// Whether `update` begins autonomous (proactive) work when no turn is
/// open. Late `tool_call_update`s for a tool from an earlier turn (such as
/// a `schedule` timer completing) stay on that tool and do not open a new
Expand Down Expand Up @@ -902,17 +913,38 @@ impl Dialect for Antigravity {

if let Some(state_dir) = state_dirs(&opts.launch_env).into_iter().next() {
let path = record::path(&state_dir, &session_id.0);
let transcript = record::transcript_path(&state_dir, &session_id.0);
let initial_model = opts.model.clone().or_else(|| {
crate::acp_session::model_config_option(&config_options).and_then(|option| {
match &option.kind {
acp::SessionConfigKind::Select(select) => {
Some(select.current_value.0.to_string())
}
_ => None,
}
})
});
// A session that goes on has steps already; a new one has none.
let seen = if resumed && !anew {
let (seen, model_tailer) = {
let path = path.clone();
crate::process::unblock(move || record::last_step(&path))
.await
.map(|step| step.index)
} else {
Some(-1)
let seed_db = resumed && !anew;
crate::process::unblock(move || {
let seen = if seed_db {
record::last_step(&path).map(|step| step.index)
} else {
Some(-1)
};
let tailer = record::ParentModelTailer::open(transcript, initial_model);
(seen, tailer)
})
.await
};
*self.record.lock().unwrap_or_else(|held| held.into_inner()) =
Some(SessionRecord { path });
*self
.model_tailer
.lock()
.unwrap_or_else(|held| held.into_inner()) = Some(model_tailer);
self.proactive
.lock()
.unwrap_or_else(|held| held.into_inner())
Expand All @@ -923,6 +955,7 @@ impl Dialect for Antigravity {
let watcher = subagents::run_watcher(subagents::WatcherContext {
state_dir,
session_id: session_id.0.to_string(),
parent_cwd: opts.cwd.clone(),
acp_state: setup.state.clone(),
proactive: self.proactive.clone(),
mcp_servers: self.mcp_servers.clone(),
Expand Down Expand Up @@ -1008,6 +1041,11 @@ impl Dialect for Antigravity {

match &notification.update {
acp::SessionUpdate::ToolCall(call) => {
let served = self.poll_served_models();
if !served.is_empty() {
events.extend(state.flush_text());
events.extend(served);
}
if let Some(spawn) = subagents::parse_spawn(call) {
events.extend(state.flush_text());
if call.status == acp::ToolCallStatus::Failed {
Expand All @@ -1027,11 +1065,23 @@ impl Dialect for Antigravity {
}));
} else {
events.extend(subagents::spawn_events(&spawn));
let tool_call_id = spawn.tool_call_id.clone();
self.spawned_subagents
.lock()
.unwrap_or_else(|held| held.into_inner())
.insert(spawn.tool_call_id.clone(), spawn.clone());
.insert(tool_call_id.clone(), spawn.clone());
self.send_watcher(subagents::WatcherCommand::Spawned(spawn));
if call.status == acp::ToolCallStatus::Completed
&& let Some(ack) = subagents::parse_spawn_ack(
Some(&call.content),
call.raw_output.as_ref(),
)
{
self.send_watcher(subagents::WatcherCommand::SpawnBound {
tool_call_id,
ack,
});
}
}
return events;
}
Expand Down Expand Up @@ -1105,6 +1155,16 @@ impl Dialect for Antigravity {
effort: None,
},
}));
} else if update.fields.status == Some(acp::ToolCallStatus::Completed)
&& let Some(ack) = subagents::parse_spawn_ack(
update.fields.content.as_deref(),
update.fields.raw_output.as_ref(),
)
{
self.send_watcher(subagents::WatcherCommand::SpawnBound {
tool_call_id: spawn.tool_call_id,
ack,
});
}
// The immediate `completed` update on `invoke_subagent`
// only acknowledges the async spawn; the watcher settles
Expand Down Expand Up @@ -1204,6 +1264,11 @@ impl Dialect for Antigravity {
}

if is_usage_update {
let served = self.poll_served_models();
if !served.is_empty() {
events.extend(state.flush_text());
events.extend(served);
}
let mut tracker = self
.proactive
.lock()
Expand Down Expand Up @@ -1476,7 +1541,7 @@ mod tests {
let connection = database.connect().unwrap();
connection
.execute(
"CREATE TABLE steps (idx integer, step_type integer NOT NULL DEFAULT 0, PRIMARY KEY (idx))",
"CREATE TABLE steps (idx integer, step_type integer NOT NULL DEFAULT 0, status integer NOT NULL DEFAULT 3, PRIMARY KEY (idx))",
(),
)
.await
Expand Down
Loading
Loading