Skip to main content

muse_code_sdk/msp/method/
session.rs

1// @generated from the MSP stable schema and protocol sources; do not edit by hand.
2
3pub use super::session_events::SessionStatus;
4use crate::msp::method::worktree::SessionWorktree;
5use crate::msp::view::state::ApprovalMode;
6use crate::msp::view::state::ApprovalModeSource;
7use crate::msp::view::state::PermissionAxes;
8use crate::msp::view::state::ReviewerAuthority;
9use crate::msp::view::state::SessionNameOrigin;
10use serde::Deserialize;
11use serde::Serialize;
12
13mod catch_all;
14
15/// What kind of session this is.
16///
17/// **Open**: a new kind is additive evolution, and a client MUST render an
18/// unknown value as an unknown-but-present kind rather than rejecting the
19/// row. Both v1 values are terms the tree already uses — the child log
20/// directory is `subagent` and `ItemKind` already carries a `subagent`
21/// variant — so no new vocabulary is minted.
22#[derive(Debug, Clone, PartialEq, Eq)]
23#[non_exhaustive]
24pub enum SessionKind {
25    /// A canonical or legacy root home.
26    Root,
27    /// A child home under `<parent-session-dir>/subagent/<child-id>/`.
28    Subagent,
29    /// A value from a newer host, kept verbatim so an older client decodes the
30    /// rest of the message. Excluded from the generated schema while the enum
31    /// stays declared open; never construct it with a known word.
32    Unknown(String),
33}
34
35/// The session object every lifecycle method returns or lists.
36///
37/// Additive-optional evolution applies: clients must ignore unknown fields.
38#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
39#[serde(rename_all = "camelCase")]
40#[non_exhaustive]
41pub struct Session {
42    /// The session identity.
43    pub session_id: String,
44    /// Absolute path of the session's durable log; non-nullable. Under the
45    /// ephemeral session profile it is the **empty string**, meaning "no
46    /// durable log exists" — the one value a client must not hand to a
47    /// filesystem call.
48    pub path: String,
49    /// Load state as this host knows it; `session/list` reports `notLoaded` for
50    /// sessions loaded by *other* hosts.
51    pub status: SessionStatus,
52    /// The `turnId` of the current foreground turn when `status` is `running`,
53    /// and `null` when the session is idle.
54    ///
55    /// **Required-nullable.** Every served `Session` carries the member: `null`
56    /// when the session is idle or not loaded, the turn id when it is running.
57    /// An optional-absent shape would publish it as plain `string` and reject
58    /// every idle `Session` frame the host sends.
59    pub active_turn_id: Option<String>,
60    /// RFC3339. For a fork this is the fork session id's UUIDv7 mint instant.
61    pub created_at: String,
62    /// RFC3339; never precedes `createdAt`.
63    pub updated_at: String,
64    /// The winning metadata fold's workspace root; `null` when that record
65    /// omits it — absent is never fabricated.
66    pub workspace_root: Option<String>,
67    /// The winning metadata fold's provider; `null` when that record omits it.
68    pub provider_id: Option<String>,
69    /// The winning metadata fold's model; `null` when that record omits it.
70    pub model_id: Option<String>,
71    /// The folded effective approval mode. **Additive-optional**: a Session
72    /// object that omits it means the host has not folded a mode, which is why
73    /// the index-derived `session/list` entry may legitimately omit it.
74    #[serde(skip_serializing_if = "Option::is_none")]
75    pub approval_mode: Option<EffectiveApprovalModeState>,
76    /// The folded effective permission state. **Additive-optional**: a
77    /// `"notLoaded"` row omits it (no live evidence, matching the `attention`
78    /// precedent) and an older host omits it everywhere; absent is unknown,
79    /// never active. `approvalMode` stays the effective-mode answer; this never
80    /// restates it.
81    #[serde(skip_serializing_if = "Option::is_none")]
82    pub permission_state: Option<EffectivePermissionState>,
83    /// Attention flags. **Additive-optional**, present only when at least one
84    /// flag is set; absence is a NON-assertion (nothing pending, or the loaded
85    /// session's pending source declined to answer). Loaded sessions only: a
86    /// `notLoaded` row omits it even while its durable pending set is
87    /// non-empty.
88    #[serde(skip_serializing_if = "Option::is_none")]
89    pub attention: Option<Vec<AttentionFlag>>,
90    /// Content-activity recency, RFC3339. **Additive-optional**: omitted when
91    /// no content record exists. Never advanced by lifecycle bookkeeping (the
92    /// resume marker, re-stamps) or a fork's copied seed-replay records, and
93    /// never precedes `createdAt`.
94    #[serde(skip_serializing_if = "Option::is_none")]
95    pub last_activity_at: Option<String>,
96    /// Completed-turn count from the session view fold.
97    pub turn_count: u64,
98    /// `null` for root sessions; fork provenance otherwise.
99    pub forked_from: Option<ForkProvenance>,
100    /// `null` for root sessions and forks; side provenance otherwise. A session
101    /// carries at most one of `forkedFrom` and `sideFrom`.
102    pub side_from: Option<SideProvenance>,
103    /// The durable allocated session name. **Additive-optional**: present when
104    /// the serving path holds an allocated name, omitted otherwise — absent is
105    /// never fabricated. Authoritative and renameable via `session/rename`.
106    #[serde(skip_serializing_if = "Option::is_none")]
107    pub name: Option<String>,
108    /// How the served `name` was set. **Additive-optional**, **fold-only**: the
109    /// snapshot fold (`session/read`, the resume/start/fork-ack snapshot)
110    /// derives and carries it from the log; `session/list` rows never carry it.
111    /// Absent — and any value the client does not recognize — reads as unknown,
112    /// never fabricated.
113    #[serde(skip_serializing_if = "Option::is_none")]
114    pub name_origin: Option<SessionNameOrigin>,
115    /// The served generated short title. **Additive-optional**, **fold-only**:
116    /// the snapshot fold derives the latest retained generated pair's short
117    /// title from the log; `session/list` rows never carry it. Omitted when no
118    /// pair was ever published — absent reads as unpublished, never fabricated,
119    /// never inferred from the name text. `name` stays the canonical name it
120    /// always was.
121    #[serde(skip_serializing_if = "Option::is_none")]
122    pub generated_name: Option<String>,
123    /// Derived display title: a heuristic that may evolve — its carriage, not
124    /// its derivation, is the contract. **Additive-optional**, omitted when
125    /// underivable.
126    #[serde(skip_serializing_if = "Option::is_none")]
127    pub title: Option<String>,
128    /// Derived first-user-prompt preview. **Additive-optional**, omitted when
129    /// underivable.
130    #[serde(skip_serializing_if = "Option::is_none")]
131    pub first_user_prompt: Option<String>,
132    /// Derived workspace branch — the index's last derived value; the
133    /// live-change signal stays `session/branchChanged`. **Additive-optional**,
134    /// omitted when underivable.
135    #[serde(skip_serializing_if = "Option::is_none")]
136    pub branch: Option<String>,
137    /// What kind of session this is. **Open enum**, v1 values `"root"` and
138    /// `"subagent"`; a client treats an unknown value as an unknown-but-present
139    /// kind and renders it, never rejecting the row. **Additive-optional**:
140    /// absence asserts nothing — the host could not determine the home shape,
141    /// or the value is not yet available to serve.
142    #[serde(skip_serializing_if = "Option::is_none")]
143    pub kind: Option<SessionKind>,
144    /// The containing session's id when `kind` is `"subagent"` — the id of the
145    /// TOP-LEVEL session whose home holds this child, which is **not
146    /// necessarily the session that spawned it**: native-child homes are
147    /// physical siblings under the outer session's `subagent/` directory, so a
148    /// subagent spawned by another subagent resolves to the outer session, not
149    /// to its spawner. A client building a tree from this field gets one level,
150    /// not a chain. Flat rather than nested: there is exactly one fact to
151    /// carry, unlike `forkedFrom`'s four-field `ForkProvenance`.
152    /// **Additive-optional**; a root carries none.
153    #[serde(skip_serializing_if = "Option::is_none")]
154    pub parent_session_id: Option<String>,
155    /// The handshake `ClientInfo` recorded when the session was opened, echoed
156    /// verbatim — provenance, never an interpretation, and never a visibility
157    /// gate. **Additive-optional**; absence has four indistinguishable causes:
158    /// an in-process open; an earlier record; a half stamp where only one of
159    /// name/version was recorded and `ClientInfo` requires both; and a session
160    /// with no admitting handshake of its own — a fork child or a subagent —
161    /// which never carries a stamp to begin with.
162    #[serde(skip_serializing_if = "Option::is_none")]
163    pub created_by_client: Option<crate::msp::handshake::ClientInfo>,
164    /// The worktree this session runs in — path and origin only (the branch
165    /// stays in `branch`). **Experimental** (`Session.worktree`; stripped
166    /// per-connection for unopted callers). Omitted when the session runs in no
167    /// worktree.
168    #[serde(skip_serializing_if = "Option::is_none")]
169    pub worktree: Option<SessionWorktree>,
170    /// This session's effective limits: the clamp output — the sandbox axes
171    /// read the live ceiling, the trust axis clamps the session's durable
172    /// stored choice (the clamp input) to it. Until a tracked change lands,
173    /// `workspaceTrusted` reports the recorded choice. **Experimental,
174    /// same-user socket only** (`Session.currentLimits`; stripped
175    /// per-connection for unopted callers). Loaded sessions only (`notLoaded`
176    /// rows and hosts with no limits regime omit it) — absent is never
177    /// fabricated.
178    #[serde(skip_serializing_if = "Option::is_none")]
179    pub current_limits: Option<super::limits::SessionLimits>,
180}
181
182/// `session/listChanged` params: one changed row of the `session/list` shape —
183/// the full Session object as the answering host's list face serves it at
184/// emission, a replace, never a delta. Emitted only on connections that
185/// negotiated the `sessionListStream` capability at `initialize`; row birth
186/// stays on `session/started`, unload pairs with `session/closed`.
187#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
188#[serde(rename_all = "camelCase")]
189#[non_exhaustive]
190pub struct SessionListChangedParams {
191    /// The served list row for the changed session.
192    pub session: Session,
193}
194
195/// One attention flag: a pending server-initiated request class parked on the
196/// session. Open on the wire — clients MUST ignore unknown values; future
197/// attention kinds are additive.
198#[derive(Debug, Clone, PartialEq, Eq)]
199#[allow(clippy::enum_variant_names)]
200#[non_exhaustive]
201pub enum AttentionFlag {
202    /// At least one approval request is open and unresolved.
203    ApprovalPending,
204    /// At least one user-input request is open.
205    InputPending,
206    /// At least one peer-admission request is open. Experimental: stripped
207    /// per-connection for unopted callers.
208    AdmissionPending,
209    /// A value from a newer host, kept verbatim so an older client decodes the
210    /// rest of the message. Never construct it with a known word.
211    Unknown(String),
212}
213
214/// The effective approval-mode projection: the same object
215/// `session/setApprovalMode` returns as `effectiveMode` and the `Session`
216/// object carries as `approvalMode`.
217#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
218#[serde(rename_all = "camelCase")]
219#[non_exhaustive]
220pub struct EffectiveApprovalModeState {
221    /// The mode in effect.
222    pub mode: ApprovalMode,
223    /// How the mode took effect.
224    pub source: ApprovalModeSource,
225    /// The command that last set it; `null` when no command did.
226    pub last_command_id: Option<String>,
227}
228
229/// The effective permission-state projection: the committed native permission
230/// snapshot (profile identity, reviewer authority) plus the live per-session
231/// runtime's attachment evidence. The same object
232/// `session/setPermissionProfile` returns and the `Session` object carries as
233/// `permissionState`. Served values must be coherent: a read never combines an
234/// old profile with a newer runtime's attachment claim.
235#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
236#[serde(rename_all = "camelCase")]
237#[non_exhaustive]
238pub struct EffectivePermissionState {
239    /// The committed profile id; `null` when the committed source is a launch
240    /// override (`LaunchOverrides` pins `id: None`); every catalog row and
241    /// configured/default commit carries a non-null id.
242    pub profile_id: Option<String>,
243    /// The committed profile's reviewer authority.
244    pub reviewer_authority: ReviewerAuthority,
245    /// Whether an executable reviewer is currently installed for this loaded
246    /// session (live runtime evidence).
247    pub reviewer_attached: bool,
248    /// The committed profile's effective four axis values: the resolved
249    /// filesystem, network, approval, and reviewer the YOLO predicate reads.
250    /// Omitted when unknown — an older host, the no-profile state, or the
251    /// commit-receipt fallback arm that reports without a re-inspect — and a
252    /// client MUST fall back to the served id there, never infer equivalence it
253    /// cannot see.
254    #[serde(skip_serializing_if = "Option::is_none")]
255    pub axes: Option<PermissionAxes>,
256}
257
258/// Fork provenance folded from the durable `session.fork.created` record.
259#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
260#[serde(rename_all = "camelCase")]
261#[non_exhaustive]
262pub struct ForkProvenance {
263    /// The source session this fork was cut from.
264    pub session_id: String,
265    /// An **opaque provenance string** preserved verbatim from the durable
266    /// record. Display-only — not one of the cursor families: clients MUST NOT
267    /// parse it and no method accepts it.
268    pub cut_cursor: String,
269    /// Whether the fork named an explicit cut point.
270    pub cut_explicit: bool,
271    /// The `commandId` of the `session/fork` that created it.
272    pub command_id: String,
273}
274
275/// Side provenance folded from the durable side provenance.
276#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
277#[serde(rename_all = "camelCase")]
278#[non_exhaustive]
279pub struct SideProvenance {
280    /// The source main session this side was opened from.
281    pub session_id: String,
282    /// An **opaque provenance string** preserved verbatim from the durable side
283    /// provenance (`source_cut_cursor`). Display-only — not one of the cursor
284    /// families: clients MUST NOT parse it and no method accepts it.
285    pub cut_cursor: String,
286    /// The `commandId` of the `session/sideChat` that created it.
287    pub command_id: String,
288}