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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
// @generated from the MSP stable schema and protocol sources; do not edit by hand.
use super::RecoveryMode;
use super::session_mcp::SessionConfig;
use super::session_start_nodes::SessionStartNode;
use super::session_start_nodes::SessionStartNodeRoster;
use super::session_start_switch_policy::SwitchPolicy;
use crate::msp::method::approval::ClientApprovalRule;
use crate::msp::method::limits::SessionLimitsChoice;
use crate::msp::method::session::Session;
use crate::msp::method::session::SessionSpawnedBy;
use crate::msp::method::worktree::WorktreeStartRequest;
use crate::msp::view::state::ApprovalMode;
use serde::Deserialize;
use serde::Serialize;
/// `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 = "super::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 = "super::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 = "super::deserialize_non_null_optional",
skip_serializing_if = "Option::is_none"
)]
pub permission_profile: Option<String>,
/// The session's client-supplied shell prefix allow-rules: `{argvPrefix}`
/// objects in the `ShellPrefixSuggestion.argv_prefix` shape. Omitted means
/// no client rules. Explicit `null` is invalid params; an empty array is an
/// explicit empty set. Until the served-handler slice, a host refuses any
/// spelled `approvalRules` on `session/start`/`fork`/`resume` with
/// `-32602`; clients omit it. **Experimental**
/// (`session/start.approvalRules`).
#[serde(
default,
deserialize_with = "super::deserialize_non_null_optional",
skip_serializing_if = "Option::is_none"
)]
pub approval_rules: Option<Vec<ClientApprovalRule>>,
/// Reserved for future per-session overrides; only its `mcpServers` member
/// is admitted.
#[serde(
default,
deserialize_with = "super::deserialize_non_null_optional",
skip_serializing_if = "Option::is_none"
)]
pub config: Option<SessionConfig>,
/// The session that opens this one, in the `Session.spawnedBy` shape: a
/// spawner that starts a worker session over MSP names its own session
/// here. The host writes it once into the new session's creation record, as
/// a worker process records its environment hand-over, and `session/list` /
/// `session/read` serve it back as `Session.spawnedBy`; `session/resume`
/// never takes it. **Additive-optional** and **provenance only**. A value
/// the host cannot use (a `parentSessionId` that is not a session id, a
/// malformed member) records nothing and never refuses the start; an
/// unusable `project` or `thread` is dropped on its own. Hosts that predate
/// the member ignore it.
#[serde(skip_serializing_if = "Option::is_none")]
pub spawned_by: Option<SessionSpawnedBy>,
/// 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>,
/// The per-session restriction: the axes this session chooses, each at or
/// below the host ceiling. **Experimental, socket-only**
/// (`session/start.limits`; unopted callers are refused `-32602`, as are
/// opted callers on hosts with no limits regime). Absent means the default
/// on every axis — the daemon default for trust, the daemon's own posture
/// for the sandbox axes (the ceiling, unless `--allow-session-posture`
/// widens the ceiling above it). A choice wider than the ceiling on any
/// axis refuses the start `-32028 limitsAboveMax` naming every too-wide
/// axis. An equal or tighter choice is what the session runs and reports,
/// with two exceptions refused `-32602`: on a daemon whose default sandbox
/// is off, a start naming `sandboxEnabled: true` without `sandboxNetwork`,
/// or a network restriction (`restricted` or `proxy-only`) without naming
/// `sandboxEnabled`, until a tracked change settles how a session turns the
/// sandbox on there, and a network restriction beside an explicit
/// `sandboxEnabled: false`, which never turns it on and stays refused while
/// a tracked change is open: drop the restriction, since a sandbox-off
/// session has no network to restrict (`data.reason:
/// "tighterSandboxUnserved"` for all three); and under `--trust-workspace
/// --listen` without `--allow-session-posture`, an explicit
/// `workspaceTrusted: false`, naming the axis. Elsewhere a network
/// restriction beside `sandboxEnabled: false` restricts nothing: with the
/// sandbox off the network is not sandboxed (`sandboxNetwork` reports
/// `enabled`).
#[serde(skip_serializing_if = "Option::is_none")]
pub limits: Option<SessionLimitsChoice>,
/// The `/new` predecessor link: the outgoing session this start succeeds.
/// Any syntactically valid session UUID; there is no existence check, so a
/// link to a session that is gone still commits. Omitted means a true root.
/// Explicit `null` is invalid params.
#[serde(
default,
deserialize_with = "super::deserialize_non_null_optional",
skip_serializing_if = "Option::is_none"
)]
pub previous_session_id: Option<String>,
/// Marks this start as a `/clear`: `true` starts the new session as a
/// clear, so its `SessionStart` hooks get source `clear` instead of
/// `startup`. `false` and omitted are the same plain start (source
/// `startup`). It neither needs nor implies `previousSessionId`. Explicit
/// `null` is invalid params.
#[serde(
default,
deserialize_with = "super::deserialize_non_null_optional",
skip_serializing_if = "Option::is_none"
)]
pub clear: Option<bool>,
/// What happens to the `previousSessionId` predecessor's unfinished
/// background work. **Experimental** (`session/start.switchPolicy`; unopted
/// callers are refused `-32602`). `kill` cancels the predecessor's
/// unfinished work once the new start is durable, as the gate-off `/new`
/// does; `keep` ends its persistent monitors only. A policy without the
/// link is invalid params, and so is explicit `null`. Omitted means no
/// policy: the start records `keep`, exactly as today.
#[serde(
default,
deserialize_with = "super::deserialize_non_null_optional",
skip_serializing_if = "Option::is_none"
)]
pub switch_policy: Option<SwitchPolicy>,
/// The nodes this session's tool calls run on, in the order that sets the
/// default. **Experimental** (`session/start.nodes`; unopted callers are
/// refused `-32602`). Each is attached before the start answers; a start in
/// which one fails to attach is refused `commandRejected`
/// (`node_attach_refused`) and leaves no session. A host with the nodes
/// feature off refuses the member (`nodes_feature_off`), and so does a host
/// that does not offer nodes (`nodes_not_offered`). Omitted means the
/// session runs on the host's own machine, exactly as today. Explicit
/// `null` is invalid params.
#[serde(
default,
deserialize_with = "super::deserialize_non_null_optional",
skip_serializing_if = "Option::is_none"
)]
pub nodes: Option<Vec<SessionStartNode>>,
/// The name of the default node, one of `nodes`. **Experimental**
/// (`session/start.defaultNode`; unopted callers are refused `-32602`).
/// Omitted means the first node. Without `nodes`, a host that would refuse
/// `nodes` refuses it the same way (`nodes_feature_off`,
/// `nodes_not_offered`) and a host that attaches nodes answers invalid
/// params. Explicit `null` is invalid params.
#[serde(
default,
deserialize_with = "super::deserialize_non_null_optional",
skip_serializing_if = "Option::is_none"
)]
pub default_node: Option<String>,
}
/// `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,
/// What the host did not apply. **Experimental**
/// (`session/start.warnings`). Absent when there is nothing to warn about,
/// never an empty array.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub warnings: Option<Vec<SessionLoadWarning>>,
/// The roster the session started with. **Experimental**
/// (`session/start.nodeRoster`; stripped per-connection for unopted
/// callers). Present when the start named nodes, the host attached them and
/// the session is still loaded with that roster; a retry answered after
/// that omits it. A client that named nodes and reads no echo sends no turn
/// to the session.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub node_roster: Option<SessionStartNodeRoster>,
/// The built-in tool set this start runs with, when the request
/// spelled `config.allowedBuiltInTools` and the host serves the
/// restriction (design kt-2n1z N3): the post-intersection set, `[]`
/// when applied-to-empty. Absent = not requested or a pre-feature
/// host; an absent echo on a spelled input means unapplied. Declared
/// here (P5, kt-kqr8), never filled until the last enforcing piece
/// (P8). **Experimental** (`session/start.appliedBuiltInTools`).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub applied_built_in_tools: Option<Vec<String>>,
/// The session MCP servers this start admitted. **Experimental**
/// (`session/start.admittedSessionMcpServers`). Present iff the
/// request spelled `config.admitSessionMcpServers` and the admission
/// gate is open; the value is the effective admitted set — names
/// joined and not withheld, `[]` when applied-to-empty. Absent means
/// not requested or a pre-feature host. Never filled before the last
/// enforcing piece lands, so no host can read "applied" early.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub admitted_session_mcp_servers: Option<Vec<String>>,
}
/// One `session/start` or `session/resume` result warning. **Experimental.**
/// The command succeeded; the warning names what the host did not apply.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct SessionLoadWarning {
/// Machine code. `setting_ignored`: this host composes no
/// `config.settingsOverrides`, so the named keys were ignored.
/// `selection_unavailable`: the session's selection names items it
/// cannot have; the session started without them (`items`).
pub code: String,
/// Human-readable text.
pub message: String,
/// The `config.settingsOverrides` keys the warning names, as sent, in
/// ascending string order.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub keys: Vec<String>,
/// For `selection_unavailable`: each selected item with the reason it is
/// unavailable.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub items: Vec<SessionLoadWarningItem>,
}
/// One `selection_unavailable` item. **Experimental.**
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct SessionLoadWarningItem {
/// The selected item: `plugin:<plugin id>`.
pub id: String,
/// `not_installed`, `host_disabled`, `enterprise_refused`, or
/// `managed_disabled`.
pub reason: String,
}