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
12 changes: 12 additions & 0 deletions app/src/terminal/cli_agent_sessions/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ pub struct CLIAgentEventPayload {
/// On Claude Code, this comes from the `StopFailure` hook (e.g. `"rate_limit"`).
/// Not implemented for Codex.
pub error_type: Option<String>,
/// Background tasks and scheduled wakeups still pending when a `Stop` fired. Claude Code
/// wakes the agent again when any of them completes or fires, so a stop with pending work is
/// a pause, not the end of the session. `None` when the plugin predates this field.
pub pending_background_work_count: Option<u32>,
}

impl CLIAgentEventPayload {
/// Whether the agent reported work that will wake it again without user input.
pub fn has_pending_background_work(&self) -> bool {
self.pending_background_work_count
.is_some_and(|count| count > 0)
}
}

/// A parsed event from a CLI agent plugin.
Expand Down
6 changes: 6 additions & 0 deletions app/src/terminal/cli_agent_sessions/event/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ pub(super) fn parse(body: &str) -> Option<CLIAgentEvent> {
.and_then(resolve_agent)
.unwrap_or(CLIAgent::Unknown);

let pending_background_work_count = match (raw.background_task_count, raw.session_cron_count) {
(None, None) => None,
(tasks, crons) => Some(tasks.unwrap_or(0).saturating_add(crons.unwrap_or(0))),
};

Some(CLIAgentEvent {
v: raw.v.unwrap_or(1),
agent,
Expand All @@ -55,6 +60,7 @@ pub(super) fn parse(body: &str) -> Option<CLIAgentEvent> {
tool_input_preview,
plugin_version: raw.plugin_version,
error_type: raw.error_type,
pending_background_work_count,
},
source: CLIAgentEventSource::RichPlugin,
})
Expand Down
5 changes: 5 additions & 0 deletions app/src/terminal/cli_agent_sessions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,11 @@ impl CLIAgentSession {
self.session_context.query = event.payload.query.clone();
self.session_context.response = event.payload.response.clone();
self.clear_permission_scoped_state();
// The agent will wake itself again once that work finishes, so this turn
// boundary is a pause rather than the end of the session.
if event.payload.has_pending_background_work() {
return None;
}
CLIAgentSessionStatus::Success
}
CLIAgentEventType::StopFailure => {
Expand Down
29 changes: 29 additions & 0 deletions app/src/terminal/cli_agent_sessions/mod_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,35 @@ fn needs_input_is_ignored_in_the_desktop_app() {
assert_needs_input_blocks_session_in_mode(ExecutionMode::App, false);
}

#[test]
fn stop_with_pending_background_work_keeps_session_in_progress() {
let body = r#"{"v":1,"agent":"claude","event":"stop","query":"build it","response":"Build started in the background.","background_task_count":1,"session_cron_count":2}"#;
let event = parse_event(Some("warp://cli-agent"), body).unwrap();
assert_eq!(event.payload.pending_background_work_count, Some(3));
assert!(event.payload.has_pending_background_work());
let mut session = cli_agent_session(CLIAgentSessionStatus::InProgress, true);

assert_eq!(session.apply_event(&event), None);

assert_eq!(session.status, CLIAgentSessionStatus::InProgress);
assert_eq!(
session.session_context.response.as_deref(),
Some("Build started in the background.")
);
}

#[test]
fn stop_without_pending_background_work_succeeds() {
let body = r#"{"v":1,"agent":"claude","event":"stop","background_task_count":0,"session_cron_count":0}"#;
let event = parse_event(Some("warp://cli-agent"), body).unwrap();
let mut session = cli_agent_session(CLIAgentSessionStatus::InProgress, true);

assert_eq!(
session.apply_event(&event),
Some(CLIAgentSessionStatus::Success)
);
}

// --- Ctrl-C pending-cancel state machine ---

/// Grace window used by the tests below. Long enough to comfortably
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const MARKETPLACE_NAME: &str = "claude-code-warp";

// Keep in sync with the plugin version in warpdotdev/claude-code-warp.
// (See the Versioning section of that repo's README.)
const MINIMUM_PLUGIN_VERSION: &str = "2.1.0";
const MINIMUM_PLUGIN_VERSION: &str = "2.4.0";
// Keep in sync with the oz-harness-support plugin version in warpdotdev/claude-code-warp.
const MINIMUM_PLATFORM_PLUGIN_VERSION: &str = "1.1.2";

Expand Down
6 changes: 6 additions & 0 deletions crates/warp_core/src/cli_agent_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ pub struct CLIAgentNotification {
pub tool_input: Option<serde_json::Value>,
pub plugin_version: Option<String>,
pub error_type: Option<String>,
/// Background tasks (shell, subagent, monitor, ...) still running when the agent stopped.
pub background_task_count: Option<u32>,
/// Session-scoped scheduled wakeups (cron, loop) pending when the agent stopped.
pub session_cron_count: Option<u32>,
}

impl CLIAgentNotification {
Expand All @@ -50,6 +54,8 @@ impl CLIAgentNotification {
tool_input: None,
plugin_version: None,
error_type: None,
background_task_count: None,
session_cron_count: None,
}
}
}
Loading