Skip to main content

trusty_code_tui/
model.rs

1//! Engine-supplied UI data: [`StatuslineSegment`], [`PickerItem`]/[`PickerRequest`],
2//! and [`CommandDescriptor`].
3//!
4//! Why: DOC-50 §3.2 (Slice 1.5) requires the statusline, pickers, and
5//! slash-command help to be driven entirely by data the engine supplies, not
6//! by constants baked into the shared crate. Slice 1 shipped provisional
7//! stubs for these three types directly in `crate::event`, flagged as
8//! zero-consumer placeholders; this module is their real, spec-shaped home.
9//! Splitting them out of `event.rs` also keeps that module's focus narrow
10//! (the `ReplEvent` wire vocabulary) versus this module's focus (the
11//! semantic data an engine hands the TUI to render).
12//!
13//! What: three families of type, one per generalized surface:
14//! - [`StatuslineSegment`] — an enum, per DOC-50 §3.2's explicit correction
15//!   of Slice 1's flat `{label, value}` struct.
16//! - [`PickerItem`] / [`PickerRequest`] — a named, engine-supplied picker
17//!   (replacing tagent's hardcoded `PickerKind::{Model,Provider}`,
18//!   `crates/trusty-agents/src/repl/tui/types.rs:28-35`).
19//! - [`CommandDescriptor`] / [`CommandRouting`] — a slash-command registry
20//!   entry that records whether the shared crate or the engine handles it
21//!   (replacing tagent's hardcoded `SLASH_COMMANDS` array,
22//!   `crates/trusty-agents/src/repl/tui/helpers.rs:156-181`).
23//!
24//! None of these types encode product-specific formulas or lists (e.g.
25//! tagent's OpenRouter haiku cost formula, `crates/trusty-agents/src/repl/tui/status.rs:145-155`,
26//! or its `/model`/`/provider` literals) — that logic stays in each engine
27//! adapter (`AgentEngine`, `CodeEngine`); this crate only defines the shapes
28//! the engine populates.
29//!
30//! # Spec References
31//! - [`SPEC-TTUI-03~draft`](docs/specs/DOC-50-tcode-tui-claude-code-clone.md#SPEC-TTUI-03~draft) — §3.2, the generalization layer this module implements.
32//! - [`SPEC-TTUI-05~draft`](docs/specs/DOC-50-tcode-tui-claude-code-clone.md#SPEC-TTUI-05~draft) — Slice 1.5 deliverable and acceptance criteria.
33
34use serde::{Deserialize, Serialize};
35
36/// One labeled segment of the status line, supplied by the engine.
37///
38/// Why: DOC-50 §3.2 specifies the statusline as "enum-driven, engine
39/// populated" — each variant is a semantic kind of thing an engine can
40/// report (a session, the active model, the project, the active
41/// workstream, an approximate cost), not an arbitrary string pair. This
42/// replaces Slice 1's provisional flat `StatuslineSegment { label, value }`
43/// (zero consumers today, so the redefinition is free — see that struct's
44/// removal from `crate::event`).
45/// What: `ReplEvent::StatuslineUpdate(Vec<StatuslineSegment>)` carries these
46/// in render order; the Slice 4 status-line widget matches on variant to
47/// decide layout/styling per kind, falling back to [`Self::Custom`] for
48/// anything not worth a first-class variant (e.g. tagent's TM/claude-mpm
49/// session counts, `status.rs`'s `tm_chunk`/`local_model_chunk`).
50/// [`Self::Cost`] carries a pre-formatted string rather than raw
51/// token/pricing data — per DOC-50 Q9, cost display is a Phase 2 concern
52/// pending a daemon API, and the shared crate must never contain a pricing
53/// formula (tagent's OpenRouter haiku formula stays in `AgentEngine`, not
54/// here).
55#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
56#[serde(tag = "kind", content = "data", rename_all = "snake_case")]
57pub enum StatuslineSegment {
58    /// The active session's identifier (e.g. a short session id).
59    SessionId(String),
60    /// The active LLM provider + model (e.g. `provider: "anthropic"`,
61    /// `name: "claude-sonnet-5"`). Kept as two fields (not one formatted
62    /// string) so the widget can style them independently, mirroring
63    /// tagent's `LLM: {provider} ({model})` chunk without hardcoding the
64    /// `provider (model)` formatting choice into the shared crate.
65    Model { provider: String, name: String },
66    /// The active project name or path.
67    Project(String),
68    /// The active workstream (DOC-48 §2.1): `id` + `name`, matching
69    /// `WorkstreamSummary` and the Slice 6 status-line example
70    /// ("WS: Token rotation (a1b2c3d4)").
71    Workstream { id: String, name: String },
72    /// A pre-formatted, engine-computed cost string (e.g. `"$0.0034"`).
73    /// Deferred to Phase 2 per DOC-50 Q9 (no daemon API yet to source real
74    /// cost from) — this variant exists so the wire shape doesn't need a
75    /// breaking change once that API lands; no engine populates it yet.
76    ///
77    /// **Multi-cost case:** `Cost` carries a single string, not a label +
78    /// value pair, so an engine that wants to show more than one cost
79    /// figure at once (tagent shows both the current session's cost and
80    /// the day's running total, `status.rs`'s `session_cost`/`daily_cost`)
81    /// bakes the distinction into the string itself and emits multiple
82    /// `Cost` segments — e.g. `Cost("$0.0034 session")` and
83    /// `Cost("$0.0145 today")` — matching tagent's existing `"{cost}
84    /// session"` / `"{cost} today"` suffix convention
85    /// (`crates/trusty-agents/src/repl/tui/status.rs`'s `format_cost_value`
86    /// call sites) rather than inventing a new labeled-cost shape here.
87    Cost(String),
88    /// Escape hatch for an engine-specific segment that doesn't warrant a
89    /// first-class variant (e.g. tagent's `TM: N sessions` / `MPM: N
90    /// sessions` counts). `label` is the short prefix, `value` is the
91    /// rendered text; `emphasis` is the same wire-safe style hint
92    /// [`Chrome`](Self::Chrome) carries — added so a labeled segment like
93    /// `MPM: 2 sessions` can render bold/accented the way tagent's
94    /// `status.rs` distinguishes it from the plainer `TM: N sessions`
95    /// segment, without the shared crate encoding either label's meaning.
96    Custom {
97        label: String,
98        value: String,
99        emphasis: StatuslineEmphasis,
100    },
101    /// Free-form styled text with no `label: value` structure — the
102    /// generalization of tagent's un-labeled statusline chrome (the bold-
103    /// cyan `"[trusty-agents] "` bracket prefix, the green `"✓ "` / `"All
104    /// systems go."` success framing, `status.rs`'s `style_status_chunk`).
105    /// Why a separate variant from `Custom` rather than an empty `label`:
106    /// `Custom`'s renderer always emits the `"{label}: "` separator, which
107    /// is wrong for chrome that isn't a label/value pair at all — an empty
108    /// label would still render `": ✓ All systems go."`.
109    /// What: `text` renders verbatim, styled per `emphasis`. No tagent-
110    /// specific color/text is hardcoded here — the engine supplies both.
111    Chrome {
112        text: String,
113        emphasis: StatuslineEmphasis,
114    },
115}
116
117/// A generic, wire-safe (JSON, via `serde`) style hint an engine can attach
118/// to a free-form statusline segment ([`StatuslineSegment::Custom`]/
119/// [`StatuslineSegment::Chrome`]).
120///
121/// Why: tagent's statusline (`crates/trusty-agents/src/repl/tui/status.rs`,
122/// NOT migrated to this crate — see `crate::widgets::status_line`'s module
123/// doc comment) has real chrome this crate's Slice 1.5 segment set couldn't
124/// express at all: a bold-cyan bracket prefix, green success framing, and a
125/// bold/dim distinction between two otherwise-identical `Custom`-shaped
126/// segments (`TM: N sessions` vs `MPM: N sessions`). Without a style hook,
127/// Slice 10's tagent cutover would have no way to reproduce that chrome
128/// through this crate's widgets — a silent UX regression Slice 10 wouldn't
129/// discover until it tried. This enum is deliberately independent of any
130/// terminal-rendering library (`crate::model` has zero terminal-library
131/// dependency, by design, per the crate root doc comment — even though
132/// `trusty-code-tui` as a whole now depends on `ratatui`) so it stays JSON-safe
133/// for an HTTP-transported engine (`CodeEngine`, Slice 3) and so this module
134/// never needs a `ratatui::style::Color`/`Modifier` in its public API.
135/// What: a small, closed set of semantic emphases — not raw RGB/attribute
136/// bits — so an engine names *what kind* of emphasis it wants (`Success`,
137/// `Accent`, …) and [`crate::widgets::status_line`] owns the actual
138/// `ratatui::style::Style` each maps to. `Normal` (the default) renders
139/// exactly like today's unstyled segments, so this is purely additive.
140#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
141#[serde(rename_all = "snake_case")]
142pub enum StatuslineEmphasis {
143    /// No special styling — today's default rendering.
144    #[default]
145    Normal,
146    /// De-emphasized (tagent's `Modifier::DIM`).
147    Dim,
148    /// Emphasized (tagent's `Modifier::BOLD`).
149    Bold,
150    /// A positive/OK signal (tagent's green "✓ … All systems go.").
151    Success,
152    /// A caution signal.
153    Warning,
154    /// A problem signal.
155    Error,
156    /// The product's accent color (tagent's bold-cyan `"[trusty-agents] "`
157    /// bracket prefix).
158    Accent,
159}
160
161/// One selectable row in an engine-supplied picker (model, provider,
162/// workstream, …).
163///
164/// Why: DOC-50 §3.3 requires picker data sources to be engine-provided
165/// rather than hardcoded lists (tagent's model/provider pickers today are
166/// hardcoded in `pickers.rs`, with items carried as bare `Vec<String>` in
167/// `PickerState.items`, `crates/trusty-agents/src/repl/tui/types.rs:44-50`).
168/// What: `id` is what gets sent back to the engine on selection (via
169/// [`PickerRequest::dispatch_command`]); `label` is the display text (may
170/// differ from `id`, e.g. a friendly name over a model slug);
171/// `description` is optional secondary text (e.g. a model's context-window
172/// size) the Slice 4 widget may render alongside the label.
173#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
174pub struct PickerItem {
175    pub id: String,
176    pub label: String,
177    pub description: Option<String>,
178}
179
180/// A complete engine-supplied picker: what to show, and what selecting an
181/// item does.
182///
183/// Why: tagent hardcodes two picker kinds (`PickerKind::Model`,
184/// `PickerKind::Provider`, `crates/trusty-agents/src/repl/tui/types.rs:28-35`)
185/// with Enter-dispatch bound to the literal strings `"/model"` /
186/// `"/provider"` — the shared crate must not know either of those concepts
187/// exist. `PickerRequest` generalizes this: the engine names the picker
188/// (`title`), supplies the rows (`items`), and supplies the command prefix
189/// to dispatch on selection (`dispatch_command`) — the shared event loop
190/// (Slice 4/7) confirms a selection by emitting
191/// `ReplEvent::Submit(format!("{} {}", dispatch_command, selected.id))`,
192/// reproducing tagent's exact `/model <selected>` / `/provider <selected>`
193/// behavior without the shared crate hardcoding either command name.
194/// What: `title` renders in the picker's border/header; `items` is the
195/// (already-fetched) list of choices — no lazy paging in this slice.
196/// `TuiEngine::picker` (see `crate::engine`) is how the shared event loop
197/// asks an engine for one of these by name.
198#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
199pub struct PickerRequest {
200    pub title: String,
201    pub items: Vec<PickerItem>,
202    pub dispatch_command: String,
203}
204
205/// The permission request currently blocking the turn (#3422).
206///
207/// Why: [`crate::event::ReplEvent::PermissionRequested`]'s payload has to
208/// outlive the event so the prompt widget can redraw it every frame and the
209/// answer can be addressed back to the right `request_id`. Held in
210/// [`crate::app::ReplApp::pending_permission`].
211/// What: every field is the producer's own text, stored verbatim — `subject`
212/// arrives already redacted and bounded, and this crate never re-derives,
213/// re-redacts, or re-interprets any of them.
214/// Test: `crate::app::reduce::tests::permission_requested_opens_a_prompt_and_records_it`.
215#[derive(Debug, Clone, PartialEq, Eq)]
216pub struct PendingPermission {
217    /// The correlation key the answer is sent back on.
218    pub request_id: String,
219    /// The agent whose call is suspended.
220    pub agent: String,
221    /// That agent's opaque per-spawn id; empty when unattributed.
222    pub agent_id: String,
223    /// The tool that would run.
224    pub tool: String,
225    /// What the tool would act on, already redacted by the producer.
226    pub subject: String,
227    /// The policy pattern that matched.
228    pub rule: String,
229}
230
231/// The user's answer to a [`PendingPermission`] (#3422).
232///
233/// Why: the TUI must offer all three answers the backend understands, and
234/// must compute none of them — per the thin-client axiom (ADR-0063) this
235/// enum only NAMES which button was pressed; the engine adapter translates
236/// it into its own backend's decision type and the backend applies the
237/// policy. Nothing here knows what a grant covers or how long it lasts.
238/// What: `AllowForSession.pattern` is the optional grant width. This crate
239/// never invents one — the key binding sends `None`, which asks the backend
240/// for whatever its own default width is for the subject it asked about.
241/// Test: `crate::app::reduce::tests::permission_key_y_answers_allow_once`
242/// and its siblings.
243#[derive(Debug, Clone, PartialEq, Eq)]
244pub enum PermissionAnswer {
245    /// Permit this one call.
246    AllowOnce,
247    /// Permit this call and stop asking for the rest of the session.
248    AllowForSession { pattern: Option<String> },
249    /// Refuse this call.
250    Deny,
251}
252
253/// An answer staged for the outer driver to relay to
254/// [`crate::engine::TuiEngine::respond_permission`] (#3422).
255///
256/// Why: the reducer holds only `&mut ReplApp` and cannot call an `async`
257/// engine method, so it stages the answer here — the same pattern
258/// [`crate::app::ReplApp::pending_submit`] and `pending_cancel` use.
259/// What: drained by [`crate::run::TuiModel::take_pending_permission_response`]
260/// after every `apply` call. It carries the whole [`PendingPermission`],
261/// not just its `request_id` (#3422): the prompt is cleared optimistically
262/// when the key is pressed, so the request would be unrecoverable if the
263/// `respond_permission` RPC failed — the dispatch layer hands this value
264/// back through [`crate::event::ReplEvent::PermissionAnswerFailed`] to
265/// reopen the prompt.
266/// Test: `crate::run::tests::dispatch_pending_permission_answer_reaches_respond_permission`,
267/// `crate::run::tests::dispatch_pending_permission_answer_failure_reopens_the_prompt`.
268#[derive(Debug, Clone, PartialEq, Eq)]
269pub struct PermissionResponse {
270    /// The request this answers, kept whole so a failed relay can reopen it.
271    pub pending: PendingPermission,
272    /// What the user chose.
273    pub answer: PermissionAnswer,
274}
275
276impl PermissionResponse {
277    /// The correlation key [`crate::engine::TuiEngine::respond_permission`]
278    /// sends this answer back on.
279    pub fn request_id(&self) -> &str {
280        &self.pending.request_id
281    }
282}
283
284/// What a backend actually confirmed about a dispatched cancel (#8207).
285///
286/// Why: a cooperative cancel has three outcomes, not two, and the TUI renders
287/// each differently. "The run stopped" ends the turn and reopens input; "the
288/// cancel was accepted but the run has not stopped yet" must keep the
289/// cancelling state on screen, because reopening input there is exactly how
290/// the next prompt earned a `-32003 already has a task running` refusal from
291/// the daemon (#8207's transcript); "the cancel could not be delivered at all"
292/// is a failure and must never read as either of the first two.
293/// What: produced by [`crate::engine::TuiEngine::cancel_session_reply`] and
294/// carried to the reducer as
295/// [`crate::event::ReplEvent::CancelSettled`]. Every payload string here is
296/// rendered VERBATIM into the scrollback, so an implementor owes a plain
297/// sentence — never a protocol code or a JSON-RPC envelope.
298/// Test: `crate::app::reduce::tests::apply_cancel_settled_stopped_reopens_input`
299/// and its siblings.
300#[derive(Debug, Clone, PartialEq, Eq)]
301pub enum CancelReply {
302    /// The backend confirmed the run has terminated. The turn is over.
303    Stopped,
304    /// The backend accepted the cancel; the run had not stopped yet. `detail`
305    /// is the backend's own account of what it is still waiting on.
306    StillCancelling { detail: String },
307    /// The cancel never landed — a transport failure, or a refusal that is not
308    /// "still cancelling". `error` is a plain sentence, already stripped of
309    /// protocol detail by the engine adapter.
310    Failed { error: String },
311}
312
313/// One entry in an engine-supplied slash-command registry.
314///
315/// Why: DOC-50 §5 Slice 7 / Q4 splits slash commands into client-side
316/// built-ins (`/help`, `/clear`, `/quit`, handled entirely inside
317/// `trusty-code-tui`, never reaching `TuiEngine::handle_input`) and
318/// engine-routed domain commands (`/model`, `/workstream`, forwarded to
319/// `TuiEngine::handle_input`). `/help` needs to enumerate both, so
320/// [`CommandRouting`] records which side owns dispatch — generalizing
321/// tagent's flat `SLASH_COMMANDS: &[(&str, &str)]` array
322/// (`crates/trusty-agents/src/repl/tui/helpers.rs:156-181`), which mixes
323/// generic commands (`/help`, `/clear`) with tagent-specific ones
324/// (`/agent`, `/local`, `/tm`) and carries no routing information at all.
325/// What: `name` is the command without its leading `/` (e.g.
326/// `"workstream"`); `summary` is the one-line help text `/help` renders;
327/// `args_hint` is optional completion metadata shown after the name (e.g.
328/// `Some("<id>")` renders as `/workstream activate <id>` in autocomplete),
329/// mirroring tagent's `update_slash_completions` prefix-match behavior
330/// without hardcoding argument shapes into the shared crate.
331#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
332pub struct CommandDescriptor {
333    pub name: String,
334    pub summary: String,
335    pub routing: CommandRouting,
336    pub args_hint: Option<String>,
337}
338
339/// Which side of the seam dispatches a [`CommandDescriptor`] (DOC-50 §6 Q4,
340/// "mixed routing").
341#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
342#[serde(rename_all = "snake_case")]
343pub enum CommandRouting {
344    /// Handled entirely inside `trusty-code-tui` (`/help`, `/clear`, `/quit`);
345    /// never reaches `TuiEngine::handle_input`.
346    BuiltIn,
347    /// Forwarded to `TuiEngine::handle_input` for the engine to execute
348    /// (`/model`, `/workstream`, and other domain commands).
349    Engine,
350}
351
352#[cfg(test)]
353mod tests {
354    use super::*;
355
356    /// Every `StatuslineSegment` variant must round-trip through JSON — the
357    /// wire shape an HTTP-transported engine (`CodeEngine`, Slice 3) will
358    /// carry these over. Each variant is compared against a JSON literal so a
359    /// wrong `kind` tag, `data` key or emphasis spelling fails; a symmetric
360    /// round trip alone would let one pass.
361    #[test]
362    fn statusline_segment_variants_round_trip_through_json() {
363        use serde_json::json;
364        let cases = vec![
365            (
366                StatuslineSegment::SessionId("a1b2c3d4".to_string()),
367                json!({"kind": "session_id", "data": "a1b2c3d4"}),
368            ),
369            (
370                StatuslineSegment::Model {
371                    provider: "anthropic".to_string(),
372                    name: "claude-sonnet-5".to_string(),
373                },
374                json!({"kind": "model", "data": {"provider": "anthropic", "name": "claude-sonnet-5"}}),
375            ),
376            (
377                StatuslineSegment::Project("trusty-tools".to_string()),
378                json!({"kind": "project", "data": "trusty-tools"}),
379            ),
380            (
381                StatuslineSegment::Workstream {
382                    id: "a1b2c3d4".to_string(),
383                    name: "Token rotation".to_string(),
384                },
385                json!({"kind": "workstream", "data": {"id": "a1b2c3d4", "name": "Token rotation"}}),
386            ),
387            (
388                StatuslineSegment::Cost("$0.0034".to_string()),
389                json!({"kind": "cost", "data": "$0.0034"}),
390            ),
391            (
392                StatuslineSegment::Custom {
393                    label: "TM".to_string(),
394                    value: "2 sessions".to_string(),
395                    emphasis: StatuslineEmphasis::Normal,
396                },
397                json!({"kind": "custom", "data": {"label": "TM", "value": "2 sessions", "emphasis": "normal"}}),
398            ),
399            (
400                StatuslineSegment::Custom {
401                    label: "MPM".to_string(),
402                    value: "2 sessions".to_string(),
403                    emphasis: StatuslineEmphasis::Bold,
404                },
405                json!({"kind": "custom", "data": {"label": "MPM", "value": "2 sessions", "emphasis": "bold"}}),
406            ),
407            (
408                StatuslineSegment::Chrome {
409                    text: "✓ All systems go.".to_string(),
410                    emphasis: StatuslineEmphasis::Success,
411                },
412                json!({"kind": "chrome", "data": {"text": "✓ All systems go.", "emphasis": "success"}}),
413            ),
414        ];
415        for (seg, wire) in cases {
416            assert_eq!(serde_json::to_value(&seg).expect("serialize"), wire);
417            let back: StatuslineSegment = serde_json::from_value(wire).expect("deserialize");
418            assert_eq!(back, seg);
419        }
420    }
421
422    /// `StatuslineSegment` is an enum per DOC-50 §3.2 — confirm distinct
423    /// variants (even ones sharing a `String` payload shape) are not equal,
424    /// which would be the failure mode of accidentally collapsing back to a
425    /// flat struct.
426    #[test]
427    fn statusline_segment_variants_are_distinct() {
428        let session = StatuslineSegment::SessionId("x".to_string());
429        let project = StatuslineSegment::Project("x".to_string());
430        assert_ne!(session, project);
431    }
432
433    /// `Custom` segments that differ ONLY in `emphasis` must be distinct —
434    /// the whole point of adding the field is to distinguish a bold `MPM:`
435    /// segment from an otherwise-identical plain one.
436    #[test]
437    fn custom_segments_with_different_emphasis_are_distinct() {
438        let plain = StatuslineSegment::Custom {
439            label: "TM".to_string(),
440            value: "2 sessions".to_string(),
441            emphasis: StatuslineEmphasis::Normal,
442        };
443        let bold = StatuslineSegment::Custom {
444            label: "TM".to_string(),
445            value: "2 sessions".to_string(),
446            emphasis: StatuslineEmphasis::Bold,
447        };
448        assert_ne!(plain, bold);
449    }
450
451    /// `StatuslineEmphasis::default()` must be `Normal` so an engine that
452    /// doesn't care about styling gets today's plain rendering for free.
453    #[test]
454    fn statusline_emphasis_defaults_to_normal() {
455        assert_eq!(StatuslineEmphasis::default(), StatuslineEmphasis::Normal);
456    }
457
458    /// The whole point of `dispatch_command`: the shared event loop
459    /// synthesizes `"<dispatch_command> <selected.id>"` on confirmation,
460    /// reproducing tagent's `/model <selected>` behavior generically. This
461    /// test locks the exact composition so a future event-loop
462    /// implementation (Slice 4/7) has a documented contract to build
463    /// against.
464    #[test]
465    fn picker_request_dispatch_command_composes_with_selected_item_id() {
466        let req = PickerRequest {
467            title: "Select a provider".to_string(),
468            items: vec![PickerItem {
469                id: "openrouter".to_string(),
470                label: "OpenRouter".to_string(),
471                description: None,
472            }],
473            dispatch_command: "/provider".to_string(),
474        };
475        let selected = &req.items[0];
476        let synthesized = format!("{} {}", req.dispatch_command, selected.id);
477        assert_eq!(synthesized, "/provider openrouter");
478    }
479
480    /// `CommandDescriptor`/`CommandRouting` must round-trip through JSON,
481    /// covering both routing kinds so DOC-50 Q4's mixed-routing model is
482    /// exercised, not just the default.
483    #[test]
484    fn command_descriptor_round_trips_through_json_for_both_routing_kinds() {
485        let builtin = CommandDescriptor {
486            name: "clear".to_string(),
487            summary: "clear chat".to_string(),
488            routing: CommandRouting::BuiltIn,
489            args_hint: None,
490        };
491        let json = serde_json::to_string(&builtin).expect("serialize");
492        assert_eq!(builtin, serde_json::from_str(&json).expect("deserialize"));
493
494        let engine_routed = CommandDescriptor {
495            name: "workstream".to_string(),
496            summary: "List or activate a workstream".to_string(),
497            routing: CommandRouting::Engine,
498            args_hint: Some("activate <id>".to_string()),
499        };
500        let json = serde_json::to_string(&engine_routed).expect("serialize");
501        assert_eq!(
502            engine_routed,
503            serde_json::from_str(&json).expect("deserialize")
504        );
505    }
506}