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: 2 additions & 0 deletions agent-client-protocol-schema/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ unstable = [
"unstable_prompt_suggestions",
"unstable_proxy_chains",
"unstable_session_archive",
"unstable_session_cursors",
"unstable_session_fork",
"unstable_session_status",
"unstable_session_options",
Expand All @@ -55,6 +56,7 @@ unstable_plan_operations = []
unstable_prompt_suggestions = []
unstable_proxy_chains = []
unstable_session_archive = []
unstable_session_cursors = []
unstable_session_fork = []
unstable_session_status = []
unstable_session_options = []
Expand Down
81 changes: 81 additions & 0 deletions agent-client-protocol-schema/src/v1/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ use serde_with::{DefaultOnError, DefaultOnNull, VecSkipError, serde_as, skip_ser

use crate::{IntoOption, ProtocolVersion};

#[cfg(all(
feature = "unstable_session_fork",
feature = "unstable_session_cursors"
))]
use super::CursorId;

use super::{
ClientCapabilities, ContentBlock, ExtNotification, ExtRequest, ExtResponse, Meta, SessionId,
};
Expand Down Expand Up @@ -1689,6 +1695,21 @@ impl LoadSessionResponse {
pub struct ForkSessionRequest {
/// The ID of the session to fork.
pub session_id: SessionId,
/// **UNSTABLE**
///
/// This capability is not part of the spec yet, and may be removed or changed at any point.
///
/// The session cursor to fork at. The new session's history is the source
/// session's history before the cursor.
///
/// Optional. Omitted and `null` are equivalent and fork the whole session.
/// Clients MUST only send the ID of a cursor that the Agent announced on the
/// source session and that currently advertises `capabilities.fork`. The Agent
/// rejects any other ID with `-32602`. It does not fall back to forking the
/// whole session.
#[cfg(feature = "unstable_session_cursors")]
#[serde(default)]
pub cursor_id: Option<CursorId>,
/// The working directory for this session. Must be an absolute path.
pub cwd: PathBuf,
/// Additional workspace roots to activate for this session. Each path must be absolute.
Expand Down Expand Up @@ -1756,6 +1777,8 @@ impl ForkSessionRequest {
pub fn new(session_id: impl Into<SessionId>, cwd: impl Into<PathBuf>) -> Self {
Self {
session_id: session_id.into(),
#[cfg(feature = "unstable_session_cursors")]
cursor_id: None,
cwd: cwd.into(),
additional_directories: vec![],
mcp_servers: vec![],
Expand All @@ -1766,6 +1789,21 @@ impl ForkSessionRequest {
}
}

/// **UNSTABLE**
///
/// This capability is not part of the spec yet, and may be removed or changed at any point.
///
/// The session cursor to fork at. Omitting it forks the whole session.
///
/// Clients MUST only send the ID of a cursor that the Agent announced on the
/// source session and that currently advertises `capabilities.fork`.
#[cfg(feature = "unstable_session_cursors")]
#[must_use]
pub fn cursor_id(mut self, cursor_id: impl IntoOption<CursorId>) -> Self {
self.cursor_id = cursor_id.into_option();
self
}

/// Additional workspace roots to activate for this session. Each path must be absolute.
#[must_use]
pub fn additional_directories(mut self, additional_directories: Vec<PathBuf>) -> Self {
Expand Down Expand Up @@ -9158,4 +9196,47 @@ mod test_serialization {
json!({"state": "unauthenticated"})
);
}

#[cfg(all(
feature = "unstable_session_fork",
feature = "unstable_session_cursors"
))]
#[test]
fn fork_session_request_cursor_id_is_optional_and_strict() {
let request = ForkSessionRequest::new("sess_abc123", "/home/user/project")
.cursor_id(CursorId::new("cur_1"));
let wire = json!({
"sessionId": "sess_abc123",
"cursorId": "cur_1",
"cwd": "/home/user/project"
});
assert_eq!(serde_json::to_value(&request).unwrap(), wire);
assert_eq!(
serde_json::from_value::<ForkSessionRequest>(wire).unwrap(),
request
);

// Omitted and `null` both fork the whole session.
for wire in [
json!({ "sessionId": "sess_abc123", "cwd": "/home/user/project" }),
json!({ "sessionId": "sess_abc123", "cwd": "/home/user/project", "cursorId": null }),
] {
assert_eq!(
serde_json::from_value::<ForkSessionRequest>(wire)
.unwrap()
.cursor_id,
None
);
}

// A malformed cursor ID fails the request. It never forks the whole session.
assert!(
serde_json::from_value::<ForkSessionRequest>(json!({
"sessionId": "sess_abc123",
"cwd": "/home/user/project",
"cursorId": 7
}))
.is_err()
);
}
}
Loading
Loading