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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
// @generated from the MSP stable schema and protocol sources; do not edit by hand.
use crate::msp::method::session::Session;
use crate::msp::method::worktree::WorktreeStartRequest;
use crate::msp::view::state::ApprovalMode;
pub use recovery::RecoveryMode;
pub use recovery::RecoveryObservation;
use serde::Deserialize;
use serde::Deserializer;
use serde::Serialize;
pub use session_mcp::SessionConfig;
pub use session_resume::HistoryNoneReason;
pub use session_resume::LastTurn;
pub use session_resume::PendingRequestPointer;
pub use session_resume::SessionHistory;
pub(crate) mod recovery;
pub(crate) mod session_leave;
pub(crate) mod session_list;
pub(crate) mod session_mcp;
pub(crate) mod session_resume;
/// `session/start` params.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SessionStartParams {
/// The idempotency handle (UUIDv7). Required; the server never mints one.
pub command_id: String,
/// Recovery choice for this construction; omission keeps legacy behavior.
/// Explicit null is invalid.
#[serde(
default,
deserialize_with = "deserialize_non_null_optional",
skip_serializing_if = "Option::is_none"
)]
pub recovery_mode: Option<RecoveryMode>,
/// Exact identity for this new root session. When omitted the server mints
/// a UUIDv7. This field never selects an existing session: a retained or
/// reserved id is rejected `commandRejected` with reason
/// `session_id_conflict`.
#[serde(skip_serializing_if = "Option::is_none")]
pub session_id: Option<String>,
/// Absolute path, folded into the first metadata record.
#[serde(skip_serializing_if = "Option::is_none")]
pub workspace_root: Option<String>,
/// The session's initial runtime workspace-root set: ordered absolute
/// canonical existing directory paths; the first root is the CWD and plays
/// the primary-root role; every root receives the `:workspace_roots` rules;
/// extra roots grant no Project Trust. When `workspaceRoot` is also present
/// the two must name the same folder, compared on canonical forms, or the
/// request is invalid params, and so is explicit `null`. Omitted preserves
/// single-root behavior.
#[serde(
default,
deserialize_with = "deserialize_non_null_optional",
skip_serializing_if = "Option::is_none"
)]
pub workspace_roots: Option<Vec<String>>,
/// Initial model; server default when omitted.
#[serde(skip_serializing_if = "Option::is_none")]
pub model_id: Option<String>,
/// Initial provider routing; server default when omitted or explicit `null`
/// — both spellings select the default.
#[serde(skip_serializing_if = "Option::is_none")]
pub provider_id: Option<String>,
/// The session's starting approval mode; server default when omitted or
/// explicit `null` — both spellings select the default. Select, never
/// create — the value names a mode the host's configuration already
/// defines. This is the only surface that declares a non-interactive run's
/// policy.
#[serde(skip_serializing_if = "Option::is_none")]
pub approval_mode: Option<ApprovalMode>,
/// The new session's initial permission profile: a profile id the host
/// catalog already admits — the rows `permissionProfile/list` serves
/// without `sessionId`. Select, never create. Omitted means today's
/// behavior: the host's configured default under native admission,
/// unchanged. An id the catalog does not carry, or one it serves
/// unavailable, refuses the start `commandRejected` (-32030;
/// `permission_profile_unknown` / `permission_profile_unavailable`) before
/// any durable byte, and an ephemeral host refuses any id
/// (`permission_profile_ephemeral_fixed`). `session/fork` does not admit
/// the member; `session/resume` admits it as the launch pick. Explicit
/// `null` is invalid params: the set of members that tolerate `null` is
/// closed and excludes this one, exactly as it excludes `workspaceRoots`.
#[serde(
default,
deserialize_with = "deserialize_non_null_optional",
skip_serializing_if = "Option::is_none"
)]
pub permission_profile: Option<String>,
/// Reserved for per-session overrides owned by a future Configuration
/// section. Issue a tracked change admits only its `mcpServers` member.
#[serde(
default,
deserialize_with = "deserialize_non_null_optional",
skip_serializing_if = "Option::is_none"
)]
pub config: Option<SessionConfig>,
/// a tracked change: ask for a created worktree or attach an existing one.
/// **Experimental** (`session/start.worktree`; unopted callers are refused
/// `-32602`). Absent means no worktree — the start proceeds exactly as
/// today.
#[serde(skip_serializing_if = "Option::is_none")]
pub worktree: Option<WorktreeStartRequest>,
}
pub(crate) fn deserialize_non_null_optional<'de, D, T>(
deserializer: D,
) -> Result<Option<T>, D::Error>
where
D: Deserializer<'de>,
T: Deserialize<'de>,
{
T::deserialize(deserializer).map(Some)
}
pub(crate) fn deserialize_optional_recovery_observation<'de, D>(
deserializer: D,
) -> Result<Option<RecoveryObservation>, D::Error>
where
D: Deserializer<'de>,
{
let value = serde_json::Value::deserialize(deserializer)?;
if !value.is_object() {
return Ok(None);
}
Ok(serde_json::from_value(value).ok())
}
/// `session/start` result.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct SessionStartResult {
/// The new session.
pub session: Session,
/// The session view head after the start fold; the connection is subscribed
/// and receives every view event after this cursor. A deduplicated retry
/// returns this same result.
pub view_cursor: String,
}
/// `session/fork` params.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SessionForkParams {
/// The idempotency handle (UUIDv7).
pub command_id: String,
/// The source session.
pub session_id: String,
/// Copy history through a completed turn, inclusive. Omitted means "all
/// completed turns".
#[serde(skip_serializing_if = "Option::is_none")]
pub cut_point: Option<ForkCutPoint>,
/// Skip inline history in the result and page it later — same as
/// `session/resume`.
#[serde(skip_serializing_if = "Option::is_none")]
pub exclude_items: Option<bool>,
}
/// Where a fork cuts the source history. Turn ids are used instead of counts
/// because ids stay stable across compaction and concurrent appends while
/// indices do not.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ForkCutPoint {
/// The last completed turn to copy, inclusive. Naming an in-progress or
/// unknown turn fails `forkBoundaryInvalid`.
pub last_turn_id: String,
}
/// `session/fork` result: the `session/resume` envelope for the **new**
/// session, whose `session.forkedFrom` carries the provenance.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct SessionForkResult {
/// The new fork session, carrying `forkedFrom` provenance.
pub session: Session,
/// The new session's view head.
pub view_cursor: String,
/// The served history.
pub history: SessionHistory,
/// The late-joiner pointer set.
pub pending_requests: Vec<PendingRequestPointer>,
}
/// `session/sideChat` params.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SessionSideChatParams {
/// The idempotency handle (UUIDv7).
pub command_id: String,
/// The source main session.
pub session_id: String,
}
/// `session/sideChat` result: the `session/resume` envelope for the **new**
/// side session, whose `session.sideFrom` carries the provenance. The side
/// opens empty.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct SessionSideChatResult {
/// The new side session, carrying `sideFrom` provenance.
pub session: Session,
/// The new side session's view head.
pub view_cursor: String,
/// The served history.
pub history: SessionHistory,
/// The late-joiner pointer set.
pub pending_requests: Vec<PendingRequestPointer>,
}
/// `session/read` params: read one stored session **without attaching** — no
/// writer lease, no load, no subscription, no `SessionResumed` record.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SessionReadParams {
/// The session to read.
pub session_id: String,
/// Metadata-only unless you ask: `false` carries the folded item history.
/// Same name and polarity as `session/resume`/`session/fork`; only the
/// default differs — here it is `true`.
#[serde(skip_serializing_if = "Option::is_none")]
pub exclude_items: Option<bool>,
}
/// `session/read` result. The `viewCursor` is the fold head at read time — a
/// point-in-time read, immediately stale if a foreign host is appending.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct SessionReadResult {
/// The session as folded point-in-time.
pub session: Session,
/// Current local construction only; never inferred from retained history.
/// Absence establishes neither a choice nor supported recovery.
#[serde(
default,
deserialize_with = "deserialize_optional_recovery_observation",
skip_serializing_if = "Option::is_none"
)]
pub recovery_observation: Option<RecoveryObservation>,
/// The fold head at read time.
pub view_cursor: String,
/// The served history.
pub history: SessionHistory,
/// The same pointer shape as `session/resume`. Because `session/read` never
/// subscribes this is a point-in-time log read only: no requests are
/// re-issued after it.
pub pending_requests: Vec<PendingRequestPointer>,
/// Same member as `session/resume`.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub last_turn: Option<LastTurn>,
}