wire/command/kind.rs
1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4// Copyright (c) 2026 2youg1 and the sprawling contributors
5
6//! Command kinds: names, steps, the wire enum.
7
8use kernel::model::{RunPolicy, Window};
9use kernel::{
10 Address, ApprovalId, Autonomy, Ceiling, DialectKind, Effort, GitOid, IdemKey, InputKinds,
11 McpServer, ModelTag, Origin, ResidentId, Restoration, Ruling, RunId, SandboxLimits, Sealed,
12 SessionName,
13};
14use serde::{Deserialize, Serialize};
15
16use crate::carried_name::{ProviderName, TemplateName, ToolkitSlug};
17use crate::command::shelf::Shelf;
18use crate::command::step::{
19 Carry, CitySettings, DoorAnswer, DoorOpening, DoorStep, GovernedDocument, HaltScope,
20 IdentityCard, PolicyChange, ProposalDecisions, PursuitStep, RangeWrite, RulesWrite,
21 SecretForgetting, SessionNaming, SpineDocument,
22};
23use crate::command::tuning::EndpointTuning;
24use crate::guide::GuideProgress;
25use crate::named_frames::named_frames;
26use crate::preference::PreferencePatch;
27
28named_frames! {
29/// Commands change state, require authorization, and are idempotent. Deliberately *not*
30/// `#[non_exhaustive]`, for the reason the module documentation of `command::wire` gives.
31#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
32#[serde(rename_all = "snake_case")]
33#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
34#[cfg_attr(feature = "schema", schemars(rename = "Command"))]
35pub enum Command<Secret = Sealed<String>> {
36 Dispatch {
37 addr: Address,
38 task: String,
39 goal: String,
40 /// The four values the run works under: mode, write limit,
41 /// admission requirement and landing policy, all four stated
42 /// (`crates/wire/spec/Command.lean` §8-57). Written as sent into the run's
43 /// `run_started` line.
44 policy: RunPolicy,
45 idem: IdemKey,
46 /// What this session is called, when it is a new one.
47 ///
48 /// `Some` means `addr` names a building and the city opens a room of this name
49 /// under it; `None` means `addr` already names the room, which is how an earlier
50 /// session is continued. Two dispatches to one room are one session with a
51 /// history, and that is a different thing from two sessions sharing a folder.
52 session: Option<SessionName>,
53 /// How hard the model is asked to think in this session.
54 ///
55 /// `None` leaves the layer above to answer, which is the city's
56 /// own configuration and, failing that, the provider's default.
57 /// A value is written into the session's own configuration when
58 /// its room is opened, so it is chosen once and holds for every
59 /// run in that room (`crates/city/Spec.lean` §8-14).
60 effort: Option<Effort>,
61 /// Which registered model this one dispatch calls, by its id.
62 ///
63 /// `None` takes the model behind the `main` tag. A value names a
64 /// model the city registered under some tag, so it arrives with
65 /// the endpoint and the window it was registered with; an id the
66 /// city never registered is refused before anything is written
67 /// (`crates/wire/spec/Command.lean` §8-48c).
68 model: Option<String>,
69 },
70 /// Asks a base URL what it serves, and attaches nothing.
71 ///
72 /// A person cannot choose from a list they have not seen, so the list is asked for apart from
73 /// attaching; the answer lands as `endpoint_probed`, which the page folds like any other fact.
74 ///
75 /// It carries the same `tuning` the attachment will, because a probe that reached a gateway
76 /// without the header that gateway requires answers 401 for a key that is in fact good.
77 ProbeEndpoint {
78 name: ProviderName,
79 base_url: String,
80 dialect: DialectKind,
81 secret: Option<String>,
82 auth_header: Option<String>,
83 tuning: EndpointTuning,
84 idem: IdemKey,
85 },
86 /// What a building's runs may reach: the sandbox's limits, the external servers its tools come
87 /// from, and the windows on this person's own machine its desktop connector may touch.
88 ///
89 /// Each field is optional and an absent one leaves that section alone; an empty `mcp` list is a
90 /// building that reaches no server, which is a different statement from not saying.
91 ///
92 /// `desktop` is the allowlist's text and not a parsed value: the connector that reads that file
93 /// at start-up is the authority on its syntax and fails closed, and a second parser here would
94 /// be a second authority (`crates/city/Spec.lean` §8-26).
95 ConfigureBuilding {
96 addr: Address,
97 sandbox: Option<SandboxLimits>,
98 mcp: Option<Vec<McpServer>>,
99 desktop: Option<String>,
100 /// Where the context reminder's second rung sits, as one layer states it: a raw
101 /// percent on the wire. The domain is `kernel::config::SecondThreshold`'s one
102 /// construction point, and a deserializer that enforced it here would be the
103 /// second place that rule lives.
104 context_second_threshold: Option<u64>,
105 idem: IdemKey,
106 },
107 AttachEndpoint {
108 name: ProviderName,
109 /// The base URL as a provider's documentation prints it; the
110 /// dialect owns the path that hangs off it.
111 base_url: String,
112 dialect: DialectKind,
113 /// `secret:<realm>/<name>`, or absent for a local server that
114 /// asks for no credential.
115 secret: Option<String>,
116 /// Header name for providers that do not take a bearer token.
117 auth_header: Option<String>,
118 /// Which of the models this endpoint serves the city admits. An
119 /// empty list admits everything it serves, which is what a
120 /// person who did not look at the list meant.
121 admit: Vec<String>,
122 /// What this endpoint is called, how long it may take, and what
123 /// every request to it carries, kept beside the registration so a
124 /// call made a week later is made the way the person set it up.
125 tuning: EndpointTuning,
126 idem: IdemKey,
127 },
128 /// Point one tag at one model of an attached endpoint, with the two
129 /// facts no model list returns.
130 SelectModel {
131 endpoint: ProviderName,
132 model: String,
133 tag: ModelTag,
134 /// The model's window. Absent when nobody stated one, and the
135 /// context reminder then stays silent rather than measuring a
136 /// conversation against a number nobody gave it.
137 context_tokens: Option<Window>,
138 /// The model's output ceiling. Absent when the person did not
139 /// state one: the city then takes the catalogue's figure, and
140 /// where the catalogue has no row the model is registered
141 /// without a ceiling rather than with a zero one.
142 max_output_tokens: Option<Ceiling>,
143 /// What the person says the model accepts. Absent, the catalogue and
144 /// the preset table answer (`crates/gateway/Spec.lean` §8-37, D16).
145 input: Option<InputKinds>,
146 idem: IdemKey,
147 },
148 /// Starts a new session at an address: same room, a fresh stretch of conversation in it, so a
149 /// person who changed the model starts it on purpose rather than having the room's frozen shape
150 /// move behind their back (`crates/sprawling/Spec.lean` §8-82). [`Carry`] names what crosses; the default
151 /// keeps nothing. Writes `session_opened`.
152 OpenSession {
153 addr: Address,
154 carry: Carry,
155 /// What this session continues, when it continues something: a
156 /// branch is a session whose first run begins from a line of
157 /// another conversation, and everything else about it - model,
158 /// effort, handoff - is what [`Carry`] and the room already say
159 /// (`crates/sprawling/Spec.lean` §8-82).
160 from: Option<Origin>,
161 idem: IdemKey,
162 },
163 CreateBuilding {
164 addr: Address,
165 template: TemplateName,
166 idem: IdemKey,
167 },
168 /// Take a building out of the city. Its files move under the reserved subtree and its history
169 /// stays in the Ledger, so nothing the person made is lost; a building with a run going is
170 /// refused. Writes `building_removed`.
171 RemoveBuilding {
172 addr: Address,
173 idem: IdemKey,
174 },
175 /// The one Command with no byte form. `Secret` is `Sealed<String>` in
176 /// process and uninhabited on the wire.
177 PutSecret {
178 realm: String,
179 name: String,
180 value: Secret,
181 },
182 Steer {
183 run: RunId,
184 text: String,
185 idem: IdemKey,
186 },
187 Cancel {
188 run: RunId,
189 idem: IdemKey,
190 },
191 Halt {
192 scope: HaltScope,
193 idem: IdemKey,
194 },
195 /// Show a person this address in their own file manager. The
196 /// grammar is the guard: an `Address` cannot climb out of the city,
197 /// so there is no way to spell a request for anything else.
198 Reveal {
199 at: Address,
200 idem: IdemKey,
201 },
202 /// Put one recycle-bin row back. The frame carries the row's own
203 /// restoration rather than a path, because a path can be discarded
204 /// twice and the row already knows which commit holds the bytes.
205 RestoreDiscard {
206 restoration: Restoration,
207 idem: IdemKey,
208 },
209 /// Install one thing this machine lacks, named as the doctor's answer names it.
210 ///
211 /// Only a recipe this city may run is run. A recipe that has to be printed, and one that has no
212 /// command at all, are refused with what the person does instead: a script piped into a shell
213 /// is code nobody read, and that rule does not soften because the request arrived from a page
214 /// rather than from a terminal.
215 DoctorInstall {
216 item: String,
217 idem: IdemKey,
218 },
219 /// Look at this machine again, in place of the snapshot taken when the city was served.
220 ///
221 /// [`Query::Doctor`](crate::Query::Doctor) answers that snapshot, which a page that has just
222 /// installed something must not be given. Probing starts programs for seconds, so it runs here,
223 /// where the city already serialises work, rather than inside a read.
224 DoctorRefresh {
225 idem: IdemKey,
226 },
227 Release {
228 scope: HaltScope,
229 idem: IdemKey,
230 },
231 BatchByBuilding {
232 addr: Address,
233 idem: IdemKey,
234 },
235 Approve {
236 item: ApprovalId,
237 verdict: Ruling,
238 idem: IdemKey,
239 },
240 /// Give one waiting question to a resident to answer.
241 ///
242 /// A person who does not want to answer a question may name
243 /// somebody who will. This moves one item and leaves
244 /// [`Command::SetAutonomy`] to say who answers everything, because
245 /// handing over one question and appointing a standing delegate are
246 /// different decisions with different reach.
247 ///
248 /// Writes `question_handed`, after which the named resident may
249 /// answer this item even though it is not the standing delegate.
250 HandOff {
251 item: ApprovalId,
252 to: ResidentId,
253 idem: IdemKey,
254 },
255 SetAutonomy {
256 scope: HaltScope,
257 autonomy: Autonomy,
258 idem: IdemKey,
259 },
260 /// A goal the city keeps working towards until the work runs out.
261 ///
262 /// One frame with four steps rather than four frames: a person who can set a goal can pause it,
263 /// and splitting that into separate commands would let a client offer one without the other.
264 Pursue {
265 addr: Address,
266 step: PursuitStep,
267 idem: IdemKey,
268 },
269 /// Something happened outside. The city never asks whether anything
270 /// did; the service holding the connection pushes, and this is the
271 /// shape a push takes once it is inside.
272 ///
273 /// It carries no address. Where an arrival lands is the watch
274 /// table's answer and then triage's, so a caller that could name a
275 /// room would be a caller that could reach past the routing a person
276 /// wrote.
277 Wake {
278 source: String,
279 subject: String,
280 body: String,
281 idem: IdemKey,
282 },
283 /// Writes one of the three documents that govern this city, whole,
284 /// only if it still holds `base`: the raw editor and the identity
285 /// cards are two writers of one file (`crates/wire/spec/Answer/Identity.lean` §8-59).
286 PutDocument {
287 which: GovernedDocument,
288 base: String,
289 body: String,
290 idem: IdemKey,
291 },
292 /// One identity card: the city rewrites the card's keys in `base`'s
293 /// identity area and leaves every other byte (`crates/wire/spec/Answer/Identity.lean` §8-59).
294 PutIdentity {
295 card: IdentityCard,
296 base: String,
297 idem: IdemKey,
298 },
299 /// Writes a building's `RULES.toml` whole (`crates/wire/spec/Command/Step.lean` §8-60).
300 PutRules(RulesWrite),
301 /// Takes one file of the city's own tree back to what a checkpoint
302 /// holds, or away when it holds none (`crates/wire/spec/Answer/Automation.lean` §8-62).
303 RestoreFile {
304 at: Address,
305 point: GitOid,
306 idem: IdemKey,
307 },
308 /// Writes this city's first-run guide progress whole; the later of
309 /// two writes stays (`crates/wire/spec/Guide.lean` §8-68).
310 PutGuide {
311 progress: GuideProgress,
312 idem: IdemKey,
313 },
314 /// Writes the city's own layer (`crates/wire/spec/Command/Step.lean` §8-61).
315 ConfigureCity(CitySettings),
316 /// Writes one of a building's own spine documents.
317 ///
318 /// The body replaces the file whole. Unlike [`Command::PutDocument`]
319 /// these have a second writer - a resident reaches `Roadmap.md`
320 /// through `plan` and the others through `edit` - so `base` carries
321 /// the text the sender started from and a file that moved underneath
322 /// it is refused rather than overwritten. One guard for two writers,
323 /// and the same one `edit` holds resident-side.
324 PutSpine {
325 building: Address,
326 which: SpineDocument,
327 base: String,
328 body: String,
329 idem: IdemKey,
330 },
331 /// Saves edits on one document version (`crates/wire/spec/Command/Step.lean` §8-72).
332 PutRange(RangeWrite),
333 /// Decides proposal cards on one document (`crates/wire/spec/Answer/Proposals.lean` §8-73).
334 DecideProposals(ProposalDecisions),
335 /// Connects one outside application through the broker that holds its OAuth, answered with the
336 /// whole shelf: the broker was asked, so every row is fresh, and the pressed one carries its
337 /// consent page.
338 ///
339 /// **The client opens the consent page, never the city**, which may run on a machine nobody is
340 /// looking at. The `IdemKey` stops a second press from opening a second account on one
341 /// application.
342 ConnectToolkit {
343 toolkit: ToolkitSlug,
344 idem: IdemKey,
345 },
346 /// Change one fact about how this person reads their own city.
347 ///
348 /// One named fact per frame rather than a whole record: two screens settling different things
349 /// must not be able to overwrite each other's field on the way past.
350 PutPreferences {
351 patch: PreferencePatch,
352 idem: IdemKey,
353 },
354 /// Write one skill or script onto a shelf.
355 ///
356 /// The shelf and the name are separate because the city owns where a shelf lives: the two
357 /// shelves sit inside the reserved subtree, which no write domain reaches, so this is the door
358 /// a person writes there through and there is no path to spell. `name` may carry
359 /// sub-directories, which is how a script keeps its folder.
360 ///
361 /// The body replaces the file whole, for the reason [`Command::PutDocument`] gives. Its
362 /// executor writes `skill_shelved` (kernel D23) once it lands; until then the city answers
363 /// `not_built`.
364 PutShelved {
365 shelf: Shelf,
366 name: String,
367 text: String,
368 idem: IdemKey,
369 },
370 /// Names one session of a room; writes `session_named` (`spec/Answer/Sessions.lean` D27).
371 NameSession(SessionNaming),
372 /// Changes a room's run policy; writes `run_policy_changed` (same decision).
373 ChangeRunPolicy(PolicyChange),
374 OpenRemoteDoor(DoorOpening),
375 ReplaceCityKey(DoorStep),
376 ConfirmRemoteDoor(DoorAnswer),
377 CloseRemoteDoor(DoorStep),
378 PrivacyOperation(crate::PrivacyRequest),
379 /// Deletes the vault's value of one reference ([`SecretForgetting`]).
380 ForgetSecret(SecretForgetting),
381 /// Closes the city; `Command/Kind.lean` §19-2 has the four rows below.
382 CloseCity(crate::CityClosing),
383 AddAgent(crate::AgentAdding),
384 AgentLogin(crate::AgentLoginStart),
385 ForgetDevice(crate::DeviceForgetting),
386 /// Presenting a pairing token. Read-only, hence no `IdemKey`; the token is plain here because a
387 /// token that must cross a wire has, by definition, no secrecy left to protect in transit - it
388 /// is sealed the moment it lands (see `server::decide_handshake`).
389 Auth {
390 token: String,
391 },
392}
393
394/// The Command surface, in declaration order — the order the handshake hash mixes these names in.
395pub const COMMAND_NAMES;
396}