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
2 changes: 1 addition & 1 deletion src/app/act.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ impl Workspace {
let auto_handoff_model = s.auto_handoff_model.clone();
let default_model = s.default_model();
let text_generation_model = s.text_generation_model.clone();
let claude_hint = self.claude_exe.as_ref().map_or("not found".to_string(), |p| p.to_string_lossy().into_owned());
let claude_hint = self.executable(Harness::Claude).map_or("not found".to_string(), |p| p.to_string_lossy().into_owned());
let defaults = s.new_session.clone();
self.executable_errors.clear();
let claude = self.executable_input(&claude_t, &claude_hint, window, cx);
Expand Down
35 changes: 23 additions & 12 deletions src/app/agent_handoff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! sending the transcript + the user's new message as the first turn.

use super::*;
use crate::harness::capabilities::{self, Initiator};
use crate::harness::thread::NoticeKind;

/// Entries read from the end before the cut, so a long session is not turned into text whole.
Expand Down Expand Up @@ -45,11 +46,17 @@ impl Workspace {
return;
}
let Some(mut rec) = self.store.session(id).cloned() else { return };
if !self.store.data.settings.harness_enabled(to) {
let initiator = if by_agent { Initiator::Automatic } else { Initiator::User };
let refusal = if !self.store.data.settings.harness_enabled(to) {
Some(format!("{} is unavailable for this session.", to.name()))
} else {
capabilities::handoff(thread.read(cx).harness, to, initiator).refusal().map(String::from)
};
if let Some(refusal) = refusal {
if !by_agent {
thread.update(cx, |v, cx| v.paste_text(&message, window, cx));
}
thread.update(cx, |v, cx| v.fail_handoff(format!("{} is unavailable for this session.", to.name()), cx));
thread.update(cx, |v, cx| v.fail_handoff(refusal, cx));
return;
}
let cwd = rec.cwd.clone();
Expand Down Expand Up @@ -130,7 +137,7 @@ impl Workspace {
}
}

pub(super) fn reconnect_antigravity_permission(&mut self, id: &str, permission: Permission, window: &mut Window, cx: &mut Context<Self>) {
pub(super) fn reconnect_full_access_permission(&mut self, id: &str, permission: Permission, window: &mut Window, cx: &mut Context<Self>) {
if self.pending_handoffs.contains_key(id) { return; }
if self.switching_worktree.contains_key(id) {
self.toast("Wait for the worktree switch to finish.", cx);
Expand Down Expand Up @@ -183,6 +190,15 @@ impl Workspace {
self.toast(reason, cx);
return;
}
let from = thread.read(cx).harness;
let refusal = from.adapter().capabilities.rewind.refusal().or_else(|| {
target_model.as_ref().and_then(|target| capabilities::handoff(from, target.harness, Initiator::User).refusal())
});
if let Some(refusal) = refusal {
thread.update(cx, |v, cx| v.paste_text(&message, window, cx));
self.toast(refusal, cx);
return;
}
let Some(mut rec) = self.store.session(id).cloned() else { return };
let cwd = rec.cwd.clone();
let mut meta = rec.agent.clone().unwrap_or_default();
Expand Down Expand Up @@ -398,7 +414,7 @@ impl Workspace {
pub(super) fn compact_session(&mut self, id: &str, transcript: String, instructions: Option<String>, window: &mut Window, cx: &mut Context<Self>) {
let Some(thread) = self.live_view(id).and_then(|v| v.thread()).cloned() else { return };
if self.compacting.contains_key(id) || self.pending_handoffs.contains_key(id) || self.switching_worktree.contains_key(id)
|| thread.read(cx).has_active_turn()
|| thread.read(cx).has_active_turn() || !thread.read(cx).harness.adapter().capabilities.compaction_fallback.allowed()
{
thread.update(cx, |v, cx| v.cancel_compaction(cx));
return;
Expand All @@ -413,13 +429,8 @@ impl Workspace {
return;
};
let meta = rec.agent.clone().unwrap_or_default();
let gen_model = self.store.data.settings.text_generation_model.clone().unwrap_or_else(|| {
crate::store::TextGenerationModel {
harness: meta.harness,
id: meta.chosen_model.clone().unwrap_or_default(),
}
});
let env = self.harness_model_env(gen_model.harness).ok();
let generator = self.summary_model(meta.harness, meta.chosen_model.clone())
.and_then(|model| Some((self.harness_model_env(model.harness).ok()?, model)));
let system = match instructions {
Some(ref extra) if !extra.trim().is_empty() => format!(
"Summarize the following coding-session conversation concisely so work can continue in a fresh context window. \
Expand All @@ -431,7 +442,7 @@ impl Workspace {
let session_id = id.to_string();
let fallback = condensed_transcript(&transcript, 6000);
cx.spawn_in(window, async move |this, cx| {
let summary = if let Some(env) = env {
let summary = if let Some((env, gen_model)) = generator {
let timeout = cx.background_executor().timer(std::time::Duration::from_secs(60));
match crate::harness::text_generation::complete(&gen_model, env, &system, &transcript, timeout).await {
Ok(text) if !text.trim().is_empty() => text.trim().to_string(),
Expand Down
58 changes: 29 additions & 29 deletions src/app/background.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,28 +157,28 @@ impl Workspace {
)
}

/// Once a second: derive each Claude session's `Activity` from its terminal output. When one stops working
/// Once a second: derive each terminal session's `Activity` from its agent's own status or its output. When one stops working
/// while the user isn't looking at it, mark it for attention, and if the whole window is in the
/// background as well, send a system notification.
pub(super) fn start_activity_poll(&mut self, window: &Window, cx: &mut Context<Self>) {
cx.spawn_in(window, async move |this, cx| {
let mut seen = claude::StatusFiles::default();
loop {
cx.background_executor().timer(Duration::from_secs(1)).await;
let (statuses, requests, back) = cx
let (statuses, requests) = cx
.background_executor()
.spawn(async move {
let statuses = Harness::Claude.is_registered().then(claude::claude_home).flatten()
.map(|h| claude::session_statuses(&h, &mut seen)).unwrap_or_default();
(statuses, crate::mcp::bridge::take_requests(), seen)
let statuses: HashMap<String, String> = Harness::registered()
.filter_map(|harness| harness.adapter().native_sessions.as_ref())
.flat_map(|native| (native.statuses)())
.collect();
(statuses, crate::mcp::bridge::take_requests())
})
.await;
seen = back;
let update = this.update_in(cx, |ws, window, cx| {
ws.serve_requests(requests, window, cx);
ws.run_pending_switches(&statuses, window, cx);
ws.check_open_files(window, cx);
ws.claude_statuses = statuses;
ws.native_statuses = statuses;
ws.update_activity(window, cx)
});
if update.is_err() {
Expand All @@ -190,11 +190,11 @@ impl Workspace {
}

/// Work out each session's row state and alert on a finished turn or a new question. Runs on the activity poll,
/// and at once when a thread's turn ends. A terminal session reads Claude Code's own busy/idle/waiting from the
/// last poll (`claude_statuses`); one it doesn't list (older Claude Code, no registry file) falls back to the
/// terminal-output heuristic.
/// and at once when a thread's turn ends. A terminal session reads its agent's own busy/idle/waiting from the
/// last poll (`native_statuses`); one it doesn't list (an agent that keeps no status, or an older version of one)
/// falls back to the terminal-output heuristic.
pub(super) fn update_activity(&mut self, window: &mut Window, cx: &mut Context<Self>) {
let statuses = std::mem::take(&mut self.claude_statuses);
let statuses = std::mem::take(&mut self.native_statuses);
let window_active = window.is_window_active();
let editing = self.editing();
let shown = self.active_id().cloned();
Expand Down Expand Up @@ -260,7 +260,7 @@ impl Workspace {
next.insert(l.id.clone(), now);
}
}
self.claude_statuses = statuses;
self.native_statuses = statuses;
self.idle_since.retain(|id, _| next.get(id) == Some(&Activity::Working));
if next != self.activity {
self.activity = next;
Expand All @@ -275,25 +275,25 @@ impl Workspace {
for text in toast_notices {
self.toast(text, cx);
}
self.sync_claude_names();
self.sync_native_names();
}

/// Claude Code keeps its own session name (`/resume`, Remote Control, the mobile apps). `--name` covers
/// launches; for a running session the name goes to its name file and the mod runs `/rename` once Claude
/// Code is idle. Nothing is typed into the PTY.
fn sync_claude_names(&mut self) {
/// An agent that keeps its own session names (Claude Code's `/resume`, Remote Control, the mobile apps) gets the
/// chosen title. A launch passes it as a flag; for a running session the adapter writes it where the agent picks
/// it up. Nothing is typed into the PTY.
fn sync_native_names(&mut self) {
for l in &mut self.live {
let Some((cid, w)) = self
let Some((write_name, cid, w)) = self
.store
.session(&l.id)
.filter(|r| r.agent.as_ref().is_some_and(|m| m.harness == Harness::Claude))
.and_then(|r| Some((r.provider_session_id()?, r.chosen_title()?)))
.filter(|(_, w)| l.claude_name.as_deref() != Some(*w))
.and_then(|r| Some((r.agent.as_ref()?.harness.adapter().native_sessions.as_ref()?.write_name, r)))
.and_then(|(write_name, r)| Some((write_name, r.provider_session_id()?, r.chosen_title()?)))
.filter(|(_, _, w)| l.native_name.as_deref() != Some(*w))
else {
continue;
};
l.claude_name = Some(w.to_string());
claude::write_name(cid, Some(w));
l.native_name = Some(w.to_string());
write_name(cid, Some(w));
}
}

Expand All @@ -305,7 +305,7 @@ impl Workspace {
self.sync_attached(cx);
self.refresh_if_stale(cx);
self.refresh_marks(cx);
self.raise_claude_priority(cx);
self.raise_agent_priority(cx);
self.refresh_pending(cx);
// The steps above redraw when they change something. The sidebar's "5m ago" and the reset countdowns count
// in minutes, so they need a redraw only when the minute turns.
Expand All @@ -316,19 +316,19 @@ impl Workspace {
}
}

/// Windows: run the Claude sessions above the builds and tests they start.
fn raise_claude_priority(&self, cx: &mut Context<Self>) {
/// Windows: run the agent sessions above the builds and tests they start.
fn raise_agent_priority(&self, cx: &mut Context<Self>) {
#[cfg(windows)]
{
// Only a session still drawn in a terminal has a process id here. Agents now run as ACP processes,
// whose ids the chat view doesn't expose yet, so they keep the normal priority until it does.
let claude_pids: Vec<u32> = self
let agent_pids: Vec<u32> = self
.live
.iter()
.filter(|l| self.store.session(&l.id).is_some_and(|r| r.kind == SessionKind::Agent))
.filter_map(|l| l.view.terminal()?.read(cx).terminal.process_id())
.collect();
cx.background_executor().spawn(async move { crate::priority::raise_claude_priority(&claude_pids) }).detach();
cx.background_executor().spawn(async move { crate::priority::raise_agent_priority(&agent_pids) }).detach();
}
#[cfg(not(windows))]
let _ = cx;
Expand Down
17 changes: 11 additions & 6 deletions src/app/cross.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,20 +205,21 @@ impl Workspace {
Ok(())
}

/// Start the switches whose session has ended its turn. Looks at Claude Code's own status, as a switch from
/// the menu does, so the call that asked is finished and answered first.
/// Start the switches whose session has ended its turn. Looks at the agent's own status where it keeps one, as a
/// switch from the menu does, so the call that asked is finished and answered first.
pub(super) fn run_pending_switches(&mut self, statuses: &std::collections::HashMap<String, String>, window: &mut Window, cx: &mut Context<Self>) {
let now = crate::store::now();
let pending = std::mem::take(&mut self.pending_switches);
for p in pending {
let claude_id = self.store.session(&p.id)
.filter(|r| r.agent.as_ref().is_some_and(|meta| meta.harness == Harness::Claude))
let native_id = self.store.session(&p.id)
.filter(|r| r.agent.as_ref().is_some_and(|meta| meta.harness.adapter().native_sessions.is_some()))
.and_then(|r| r.provider_session_id());
// Without a registry entry (older Claude Code) the terminal's own activity decides, as in `switch::inspect`.
// Without a status (an older Claude Code keeps no registry) the view's own activity decides, as in
// `switch::inspect`.
let idle = !self.switching_worktree.contains_key(&p.id)
&& !self.pending_handoffs.contains_key(&p.id)
&& self.live_view(&p.id).and_then(|v| v.thread()).is_none_or(|t| t.read(cx).can_move_workspace())
&& match claude_id.and_then(|c| statuses.get(c)) {
&& match native_id.and_then(|c| statuses.get(c)) {
Some(status) => status == "idle",
None => self.live_view(&p.id).is_some_and(|v| !v.is_working(cx)),
};
Expand Down Expand Up @@ -347,6 +348,10 @@ impl Workspace {
let effort = effort_for(req.args["effort"].as_str(), model.is_some());
match model {
Some(model) if req.args["cross"].as_bool() == Some(true) => {
let from = thread.read(cx).harness;
if let Some(refusal) = crate::harness::capabilities::handoff(from, model.harness, crate::harness::capabilities::Initiator::Automatic).refusal() {
return Err(refusal.into());
}
let message = req.args["message"].as_str().map(str::trim).filter(|m| !m.is_empty()).map_or_else(|| "Carry on with the task from where the conversation left off.".into(), String::from);
let name = model.name.clone();
thread.update(cx, |t, cx| t.hand_off_after_turn(model, effort, message, cx));
Expand Down
15 changes: 7 additions & 8 deletions src/app/fresh_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ impl Workspace {
};
{
let t = thread.read(cx);
if let Some(refusal) = t.harness.adapter().capabilities.continue_fresh.refusal() {
self.toast(refusal, cx);
return;
}
if t.has_active_turn() {
self.toast("Wait for the current turn to finish before continuing in a fresh session.", cx);
return;
Expand Down Expand Up @@ -91,18 +95,13 @@ impl Workspace {
self.toast("Summarizing session for fresh linked thread…", cx);
cx.notify();

let gen_model = self.store.data.settings.text_generation_model.clone().unwrap_or_else(|| {
crate::store::TextGenerationModel {
harness: snapshot.harness,
id: snapshot.model.clone().unwrap_or_default(),
}
});
let env = self.harness_model_env(gen_model.harness).ok();
let generator = self.summary_model(snapshot.harness, snapshot.model.clone())
.and_then(|model| Some((self.harness_model_env(model.harness).ok()?, model)));
let system = "Summarize the following coding-session conversation concisely as a handoff brief for a fresh linked session. \
Preserve the user's goal, key decisions, modified or relevant file paths, symbol names, errors/blockers, and clear next steps.";
let session_id = id.to_string();
cx.spawn_in(window, async move |this, cx| {
let summary = if let Some(env) = env {
let summary = if let Some((env, gen_model)) = generator {
let timeout = cx.background_executor().timer(std::time::Duration::from_secs(60));
match crate::harness::text_generation::complete(&gen_model, env, system, &transcript, timeout).await {
Ok(text) if !text.trim().is_empty() => text.trim().to_string(),
Expand Down
11 changes: 3 additions & 8 deletions src/app/github_pane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,10 @@ impl Workspace {
}

pub(crate) fn sign_in_to_harness(&mut self, harness: Harness, window: &mut Window, cx: &mut Context<Self>) {
let (program, args): (&str, &[&str]) = match harness {
Harness::Claude => ("claude", &["auth", "login"]),
Harness::Codex => ("codex", &["login"]),
Harness::OpenCode => ("opencode", &["auth", "login"]),
Harness::Antigravity => ("agy", &[]),
};
let configured = (harness == Harness::Claude).then(|| self.claude_exe.clone()).flatten();
let crate::harness::SignIn { program, locate, args, .. } = harness.adapter().sign_in;
let configured = self.executable(harness).map(std::path::Path::to_path_buf);
cx.spawn_in(window, async move |this, cx| {
let executable = cx.background_executor().spawn(async move { configured.or_else(|| crate::harness::find(program)) }).await;
let executable = cx.background_executor().spawn(async move { locate(configured.as_deref()) }).await;
let _ = this.update_in(cx, |ws, window, cx| {
let Some(executable) = executable else {
ws.show_toast(format!("{program} was not found. Install its CLI to sign in."), Some(("Check setup".into(), Act::OpenSetup)), cx);
Expand Down
2 changes: 1 addition & 1 deletion src/app/headless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ mod skills;
impl Workspace {
pub(crate) fn start_screenshot_session(&mut self, cwd: PathBuf, window: &mut Window, cx: &mut Context<Self>) {
self.acp_server = Some(fake_agent(&cwd));
self.claude_exe = Some("offline-screenshot-agent".into());
*self.executables.get_mut(crate::harness::Harness::Claude) = Some("offline-screenshot-agent".into());
self.new_session_from_home(Harness::Claude, None, cwd, None, None, None, window, cx);
if let Some(id) = self.active_id().cloned() {
if let Some(record) = self.store.session_mut(&id) {
Expand Down
Loading
Loading