Skip to main content

glass_browser/cli/
args.rs

1//! CLI argument definitions (clap).
2//!
3//! Defines the top-level `Cli` struct and all subcommands for one-shot
4//! browser operations, profile management, and server modes.
5
6use clap::{Parser, Subcommand, ValueEnum};
7use std::path::PathBuf;
8
9use crate::browser::policy::{PolicyCapability, PolicyPreset};
10use crate::browser::session::{
11    BatchMode, InteractionMode, PreflightAction, VisualClip, VisualFormat,
12};
13use crate::results::ResponseMode;
14/// Glass — semantic browser execution for humans and agents.
15///
16/// Run `glass` for the interactive terminal workspace, or choose a command for
17/// a bounded one-shot operation. Browser actions share revision guards,
18/// verification, workspace ownership, and typed results across CLI, TUI, MCP,
19/// daemon, and Rust interfaces.
20#[derive(Debug, Parser)]
21#[command(
22    name = "glass",
23    version,
24    about = "Semantic browser execution for humans and agents",
25    disable_help_subcommand = true,
26    after_help = "Start here:\n  glass doctor                         Check browser and local runtime support\n  glass                                Open the interactive terminal workspace\n  glass navigate https://example.com   Open a page in one bounded operation\n  glass observe --level interactive    Inspect current semantic understanding\n  glass task compile task.json ir.json Compile a deterministic browser-free task\n\nUse `glass <command> --help` for command-specific options and examples."
27)]
28pub struct Cli {
29    /// Run trusted local automation without interactive capability or tool approvals.
30    /// Glass Dev also enables unrestricted Pi resources and tools in this mode.
31    #[arg(long, global = true)]
32    pub yolo: bool,
33
34    /// Browser safety preset. Hardened mode fails closed for privileged operations.
35    #[arg(long, global = true, value_enum, default_value_t = PolicyPreset::Development)]
36    pub policy: PolicyPreset,
37
38    /// Explicitly allow a privileged capability under the selected policy.
39    #[arg(long = "policy-allow", global = true, value_enum)]
40    pub policy_allow: Vec<PolicyCapability>,
41
42    /// Return a typed confirmation-required result for this capability.
43    #[arg(long = "policy-confirm", global = true, value_enum)]
44    pub policy_confirm: Vec<PolicyCapability>,
45
46    /// Supply one consumable approval token for a confirmation-required capability.
47    #[arg(long = "policy-confirm-once", global = true, value_enum)]
48    pub policy_confirm_once: Vec<PolicyCapability>,
49
50    /// Opt into the experimental sandboxed extension capability.
51    #[arg(long, global = true)]
52    pub experimental_extensions: bool,
53
54    /// Permit only these exact hosts in hardened mode (repeatable).
55    #[arg(long = "policy-allow-host", global = true)]
56    pub policy_allow_host: Vec<String>,
57
58    /// Deny these exact hosts in hardened mode (repeatable).
59    #[arg(long = "policy-deny-host", global = true)]
60    pub policy_deny_host: Vec<String>,
61
62    /// Named browser profile used for persistent cookies and storage.
63    #[arg(long, global = true, default_value = "default")]
64    pub profile: String,
65
66    /// Use a temporary browser profile without persistence.
67    #[arg(long, global = true)]
68    pub incognito: bool,
69
70    /// Attach to an existing Chrome CDP endpoint instead of launching Chrome.
71    /// The default profile value is ignored in this mode.
72    #[arg(long, global = true)]
73    pub attach: bool,
74
75    /// Attach browser operations to a named persistent local session.
76    /// The session's verified loopback port is resolved before the operation starts.
77    #[arg(long, global = true, value_name = "NAME")]
78    pub session: Option<String>,
79
80    /// Chrome page target ID. Required when the selected endpoint has multiple
81    /// page targets.
82    #[arg(long = "target-id", global = true)]
83    pub target_id: Option<String>,
84
85    /// Chrome frame ID used by commands in this one-shot session.
86    #[arg(long = "frame-id", global = true)]
87    pub frame_id: Option<String>,
88
89    /// Chrome remote debugging port.
90    #[arg(long, global = true, default_value_t = 9222)]
91    pub port: u16,
92
93    /// Show the browser window instead of using headless mode.
94    #[arg(long, global = true)]
95    pub headed: bool,
96    /// CSS viewport dimensions applied before navigation, for example `1280x800`.
97    #[arg(long, global = true, value_name = "WIDTHxHEIGHT")]
98    pub viewport: Option<String>,
99
100    /// Pointer behavior for click actions.
101    #[arg(long, global = true, value_enum, default_value_t = InteractionMode::Human)]
102    pub interaction: InteractionMode,
103
104    /// Enable bounded session audit log of high-risk operations.
105    #[arg(long, global = true)]
106    pub audit: bool,
107
108    /// Emit a bounded JSON failure-trace pack when a browser operation fails.
109    #[arg(long, global = true)]
110    pub trace_on_error: bool,
111
112    /// Path to a Chrome/Chromium binary.
113    #[arg(long = "chrome-path", alias = "chrome", global = true)]
114    pub chrome_path: Option<PathBuf>,
115
116    /// Run the MCP server over stdio.
117    #[arg(long)]
118    pub mcp: bool,
119
120    /// Terminal workspace layout. Auto uses terminal geometry only.
121    #[arg(long = "tui-layout", global = true, value_enum, default_value_t = TuiLayout::Auto)]
122    pub tui_layout: TuiLayout,
123
124    /// Connection transport policy. Auto keeps unmeasured SSH links unknown.
125    #[arg(long = "tui-transport", global = true, value_enum, default_value_t = TuiTransport::Auto)]
126    pub tui_transport: TuiTransport,
127
128    /// Graphics capability override. Auto requires an active protocol probe.
129    #[arg(long = "tui-graphics", global = true, value_enum, default_value_t = TuiGraphics::Auto)]
130    pub tui_graphics: TuiGraphics,
131
132    /// Measured/known round-trip latency for presentation policy diagnostics.
133    #[arg(long = "tui-rtt-ms", global = true)]
134    pub tui_rtt_ms: Option<f64>,
135
136    /// Measured/known effective terminal throughput in megabits per second.
137    #[arg(long = "tui-throughput-mbps", global = true)]
138    pub tui_throughput_mbps: Option<f64>,
139
140    /// Terminal-native live browser policy. Off preserves semantic-only startup.
141    #[arg(long = "tui-live", global = true, value_enum, default_value_t = TuiLiveMode::Off)]
142    pub tui_live: TuiLiveMode,
143
144    /// Preferred terminal-native live browser renderer.
145    #[arg(long = "tui-live-backend", global = true, value_enum, default_value_t = TuiLiveBackend::Auto)]
146    pub tui_live_backend: TuiLiveBackend,
147
148    /// Terminal-native live browser bandwidth and frame-rate profile.
149    #[arg(long = "tui-live-quality", global = true, value_enum, default_value_t = TuiLiveQuality::Balanced)]
150    pub tui_live_quality: TuiLiveQuality,
151
152    /// How ANSI-sampled browser pixels fit inside the terminal App pane.
153    #[arg(long = "tui-live-fit", global = true, value_enum, default_value_t = TuiLiveFit::Contain)]
154    pub tui_live_fit: TuiLiveFit,
155
156    /// Override the per-profile persistent knowledge snapshot path.
157    #[arg(long, global = true)]
158    pub knowledge_store: Option<PathBuf>,
159
160    /// Select the bounded agent-facing response projection.
161    #[arg(long, global = true, value_enum, default_value_t = ResponseMode::Minimal)]
162    pub response_mode: ResponseMode,
163
164    /// One-shot prompt, for example: `navigate to https://example.com`.
165    #[arg(value_name = "PROMPT")]
166    pub prompt: Option<String>,
167
168    #[command(subcommand)]
169    pub command: Option<Commands>,
170}
171
172#[derive(Debug, Clone, Copy, ValueEnum)]
173pub enum McpClient {
174    Generic,
175    ClaudeCode,
176    Codex,
177}
178
179/// Responsive layout policy for the interactive terminal workspace.
180#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum, Default)]
181pub enum TuiLayout {
182    /// Select from terminal geometry only.
183    #[default]
184    Auto,
185    /// Force the multi-pane desktop workspace, including on narrow terminals.
186    Desktop,
187    /// Use a single-pane, phone-friendly workspace and semantic browser output.
188    Mobile,
189    /// Force a condensed workspace independent of transport.
190    Compact,
191}
192
193/// Presentation transport classification. This is independent from layout.
194#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum, Default)]
195pub enum TuiTransport {
196    #[default]
197    Auto,
198    Local,
199    RemoteFast,
200    RemoteConstrained,
201    Mosh,
202    UnknownRemote,
203}
204
205/// Terminal graphics evidence/override, independent from transport and layout.
206#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum, Default)]
207pub enum TuiGraphics {
208    #[default]
209    Auto,
210    Kitty,
211    Sixel,
212    ITermInline,
213    Ansi,
214    SemanticOnly,
215}
216
217#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum, Default)]
218pub enum TuiLiveMode {
219    /// Do not capture continuous browser pixels; explicit screenshots still work.
220    #[default]
221    Off,
222    /// Enable live pixels only when a native Herdr or Kitty backend is detected.
223    Auto,
224    /// Enable live pixels and use the ANSI renderer when native graphics are absent.
225    On,
226}
227
228#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum, Default)]
229pub enum TuiLiveBackend {
230    /// Prefer Herdr, then Kitty, then ANSI according to the live policy.
231    #[default]
232    Auto,
233    /// Use Herdr's owned pane graphics stream.
234    Herdr,
235    /// Emit the Kitty terminal graphics protocol directly.
236    Kitty,
237    /// Render browser pixels as true-color Unicode half blocks.
238    Ansi,
239}
240
241#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum, Default)]
242pub enum TuiLiveQuality {
243    /// Approximately 3 FPS at a compact capture size.
244    Data,
245    /// Approximately 6 FPS with balanced resolution and transfer cost.
246    #[default]
247    Balanced,
248    /// Approximately 12 FPS at the largest bounded pane resolution.
249    Smooth,
250}
251
252#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum, Default)]
253pub enum TuiLiveFit {
254    /// Show the complete frame with letterboxing; native image backends always use this.
255    #[default]
256    Contain,
257    /// Fill the ANSI pane and crop browser edges when aspect ratios differ.
258    Cover,
259    /// Use one source pixel per ANSI half-block sample and crop overflow.
260    Actual,
261}
262
263#[derive(Debug, Subcommand)]
264pub enum Commands {
265    /// Update the Cargo package that owns this executable.
266    Update {
267        /// Print the resolved package, provenance, root, and Cargo command without running it.
268        #[arg(long)]
269        dry_run: bool,
270        /// Install a specific Cargo-compatible version requirement instead of the latest release.
271        #[arg(long)]
272        version: Option<String>,
273        /// Reinstall even when Cargo considers the selected version current.
274        #[arg(long)]
275        force: bool,
276        /// Use this configured Cargo registry. Required to change from an unknown or non-crates.io source.
277        #[arg(long)]
278        registry: Option<String>,
279    },
280
281    /// Download and install a managed Chrome for Testing build.
282    InstallChromium {
283        /// Reinstall the version pinned by this Glass release.
284        #[arg(long)]
285        update: bool,
286    },
287
288    /// Evaluate release evidence and forbidden outcomes without starting a browser.
289    Certify {
290        #[command(subcommand)]
291        action: CertifyCommand,
292    },
293
294    /// Inspect local workspace identity, ownership, and lifecycle state.
295    Workspace {
296        #[command(subcommand)]
297        action: WorkspaceCommand,
298    },
299    /// Inspect and operate the current project development runtime.
300    Project {
301        #[command(subcommand)]
302        action: ProjectCommand,
303    },
304    /// Send a prompt or control request to the local Glass harness.
305    Agent {
306        #[command(subcommand)]
307        action: AgentCommand,
308    },
309    /// Discover and launch installed external coding harnesses.
310    Harness {
311        #[command(subcommand)]
312        action: HarnessCommand,
313    },
314    /// Inspect and manage advisory semantic memory.
315    Memory {
316        #[command(subcommand)]
317        action: MemoryCommand,
318    },
319    /// Validate surface evidence and report capability coverage.
320    Surfaces {
321        #[command(subcommand)]
322        action: SurfaceCommand,
323    },
324    /// Inspect a declared transport-neutral backend profile.
325    Backend {
326        #[command(subcommand)]
327        action: BackendCommand,
328    },
329
330    /// Start and inspect the local daemon lifecycle.
331    Daemon {
332        #[command(subcommand)]
333        action: DaemonCommand,
334    },
335    /// Inspect, compare, or attach a validated replay bundle.
336    Replay {
337        #[command(subcommand)]
338        action: ReplayCommand,
339    },
340    /// Print the versioned Glass capability manifest without starting Chrome.
341    Capabilities,
342
343    /// Inspect local browser, daemon, profile, policy, and store health.
344    Doctor {
345        /// Emit the stable machine-readable diagnostic contract.
346        #[arg(long)]
347        json: bool,
348    },
349
350    /// Print deterministic MCP configuration for a supported client.
351    McpConfig {
352        #[arg(long, value_enum, default_value_t = McpClient::Generic)]
353        client: McpClient,
354        /// Explicitly print the generated JSON configuration.
355        #[arg(long)]
356        print: bool,
357    },
358
359    /// List or manage saved profiles.
360    Profiles {
361        #[command(subcommand)]
362        action: Option<ProfileCommand>,
363    },
364
365    /// Inspect and manage the bounded local knowledge store.
366    Knowledge {
367        #[command(subcommand)]
368        action: KnowledgeCommand,
369    },
370
371    /// Inspect and purge bounded local diagnostic result artifacts.
372    Result {
373        #[command(subcommand)]
374        action: ResultCommand,
375    },
376
377    /// Delete a saved profile.
378    DeleteProfile { name: String },
379
380    /// Navigate to a URL.
381    Navigate {
382        url: String,
383        #[arg(long, default_value_t = 20_000)]
384        timeout_ms: u64,
385        #[arg(long)]
386        expected_revision: Option<u64>,
387    },
388
389    /// Click an element by an explicit ref/name/role/text/CSS/ordinal locator.
390    Click {
391        target: String,
392        #[arg(long)]
393        expected_revision: Option<u64>,
394    },
395
396    /// Resolve a target and report clickability without performing an action.
397    Preflight {
398        target: String,
399        #[arg(long, value_enum, default_value_t = PreflightAction::Click)]
400        action: PreflightAction,
401    },
402
403    /// Click exact viewport coordinates for canvas/map surfaces.
404    ClickAt { x: f64, y: f64 },
405
406    /// Click an element expected to open exactly one causally verified popup.
407    ClickExpectPopup {
408        target: String,
409        #[arg(long)]
410        expected_revision: Option<u64>,
411    },
412
413    /// Double-click an element by an explicit ref/name/role/text/CSS/ordinal locator.
414    DoubleClick {
415        target: String,
416        #[arg(long)]
417        expected_revision: Option<u64>,
418    },
419
420    /// Move the pointer over an element without clicking.
421    Hover { target: String },
422
423    /// Drag one element to another uniquely resolved element.
424    Drag {
425        source: String,
426        destination: String,
427        #[arg(long)]
428        expected_revision: Option<u64>,
429    },
430
431    /// Type text into the focused element, optionally clicking a target first.
432    Type {
433        text: String,
434        #[arg(long)]
435        target: Option<String>,
436        #[arg(long)]
437        expected_revision: Option<u64>,
438    },
439
440    /// Dispatch one complete key press.
441    Key {
442        key: String,
443        #[arg(long)]
444        expected_revision: Option<u64>,
445    },
446
447    /// Dispatch only a key-down event.
448    KeyDown {
449        key: String,
450        #[arg(long)]
451        expected_revision: Option<u64>,
452    },
453
454    /// Dispatch only a key-up event.
455    KeyUp {
456        key: String,
457        #[arg(long)]
458        expected_revision: Option<u64>,
459    },
460
461    /// Dispatch a modifier shortcut such as Control+A.
462    Shortcut {
463        shortcut: String,
464        #[arg(long)]
465        expected_revision: Option<u64>,
466    },
467
468    /// Clear an editable element.
469    Clear {
470        target: String,
471        #[arg(long)]
472        expected_revision: Option<u64>,
473    },
474
475    /// Ensure a checkbox or radio is checked.
476    Check {
477        target: String,
478        #[arg(long)]
479        expected_revision: Option<u64>,
480    },
481
482    /// Ensure a checkbox is unchecked.
483    Uncheck {
484        target: String,
485        #[arg(long)]
486        expected_revision: Option<u64>,
487    },
488
489    /// Select one exact option value.
490    Select {
491        target: String,
492        value: String,
493        #[arg(long)]
494        expected_revision: Option<u64>,
495    },
496
497    /// Set a bounded list of regular files on one file input.
498    Upload {
499        target: String,
500        #[arg(required = true)]
501        files: Vec<PathBuf>,
502        #[arg(long)]
503        expected_revision: Option<u64>,
504    },
505
506    /// Capture a PNG screenshot.
507    Screenshot {
508        #[arg(short, long, default_value = "screenshot.png")]
509        output: String,
510        #[arg(long, value_enum, default_value_t = VisualFormat::Png)]
511        format: VisualFormat,
512        #[arg(long)]
513        quality: Option<u8>,
514        #[arg(long, default_value_t = 1.0)]
515        scale: f64,
516        #[arg(long, conflicts_with_all = ["clip", "target"])]
517        full_page: bool,
518        #[arg(long, conflicts_with_all = ["full_page", "target"])]
519        clip: Option<VisualClip>,
520        #[arg(long, conflicts_with_all = ["full_page", "clip"])]
521        target: Option<String>,
522    },
523
524    /// Print the visible page text.
525    Text,
526
527    /// Print the full DOM tree. This is an explicit deep-inspection request.
528    Dom,
529
530    /// Print compact accessibility and text context.
531    Observe {
532        /// Include the full DOM tree. This is an explicit deep-inspection request.
533        #[arg(long)]
534        deep_dom: bool,
535        /// Include a PNG screenshot in the structured context.
536        #[arg(long)]
537        screenshot: bool,
538        /// Include bounded, policy-gated form field values.
539        #[arg(long)]
540        form_values: bool,
541        /// Return the versioned semantic observation at the requested level.
542        #[arg(long = "level", alias = "semantic-level", value_parser = parse_semantic_level)]
543        semantic_level: Option<String>,
544        /// Expand one semantic region from the current observation.
545        #[arg(long, requires = "semantic_level")]
546        region: Option<String>,
547    },
548
549    /// Capture the bounded task-oriented page inspection contract.
550    InspectPage,
551    /// Run bounded navigation, observation, inspection, and safe target probes for a site manifest.
552    SmokeSites {
553        /// JSON file containing `{ "sites": [...] }`.
554        input: PathBuf,
555        /// Stop after the first site-level failure.
556        #[arg(long)]
557        stop_on_error: bool,
558    },
559
560    /// Resolve target candidates without acting.
561    FindTarget { input: PathBuf },
562
563    /// Run one guarded semantic action and verify an optional postcondition.
564    ActAndVerify {
565        input: PathBuf,
566        #[arg(long)]
567        predicate: Option<String>,
568        #[arg(long, default_value_t = 10_000)]
569        timeout_ms: u64,
570    },
571
572    /// Extract typed records from a fresh semantic region.
573    ExtractStructured { input: PathBuf },
574
575    /// Recover a potentially indeterminate execution conservatively.
576    RecoverRun { execution_id: String },
577
578    /// Scroll the page by CSS pixels.
579    Scroll {
580        #[arg(long, default_value_t = 0.0)]
581        dx: f64,
582        #[arg(long, default_value_t = 600.0)]
583        dy: f64,
584        #[arg(long)]
585        expected_revision: Option<u64>,
586    },
587
588    /// Wait for one explicit browser condition until a bounded deadline.
589    Wait {
590        condition: String,
591        #[arg(long, default_value_t = 10_000)]
592        timeout_ms: u64,
593    },
594
595    /// Collect bounded, redacted console and network evidence.
596    Diagnostics {
597        #[arg(long, default_value_t = 1_000)]
598        duration_ms: u64,
599    },
600
601    /// Accept the currently open JavaScript dialog.
602    AcceptDialog,
603
604    /// Dismiss the currently open JavaScript dialog.
605    DismissDialog,
606
607    /// Dismiss a recognized OneTrust/Cookiebot consent wall.
608    DismissConsent,
609
610    /// Wait for one download into an authorized existing directory.
611    Download {
612        destination: PathBuf,
613        #[arg(long, default_value_t = 30_000)]
614        timeout_ms: u64,
615    },
616
617    /// List discoverable page targets without changing the active target.
618    Targets,
619
620    /// Write a bounded, redacted page-target archive without selecting or closing any target.
621    ArchiveTargets {
622        /// Optional JSON output path. Without it, print the archive to stdout.
623        #[arg(short, long)]
624        output: Option<PathBuf>,
625    },
626
627    /// Create a page target without selecting it.
628    NewTarget { url: String },
629
630    /// Explicitly select the page target used by subsequent commands.
631    SelectTarget { id: String },
632
633    /// Close one page target.
634    CloseTarget { id: String },
635
636    /// List frames in the active page target.
637    Frames,
638
639    /// Explicitly select the frame used by subsequent commands.
640    SelectFrame { id: String },
641
642    /// Evaluate JavaScript in the current page.
643    Evaluate { expression: String },
644
645    /// List all browser cookies for the current page.
646    Cookies,
647
648    /// Export current browser cookies as bounded JSON.
649    ExportCookies { output: PathBuf },
650
651    /// Import browser cookies from bounded JSON.
652    ImportCookies { input: PathBuf },
653
654    /// Save the current page as a PDF.
655    Pdf {
656        #[arg(short, long, default_value = "page.pdf")]
657        output: String,
658        #[arg(long)]
659        background: bool,
660    },
661
662    /// Fill multiple form fields from a JSON value.
663    FillForm {
664        /// JSON array of {target, value} objects.
665        #[arg(long)]
666        fields: String,
667        /// Initial observation revision required before filling.
668        #[arg(long)]
669        expected_revision: Option<u64>,
670    },
671
672    /// Execute a bounded typed batch from a JSON array or stdin.
673    Batch {
674        /// JSON file containing the batch steps; omit to read stdin.
675        input: Option<PathBuf>,
676        #[arg(long)]
677        atomic: bool,
678        /// Revision policy: fixed, chain, or unguarded.
679        #[arg(long, value_enum, default_value_t = BatchMode::Unguarded)]
680        mode: BatchMode,
681        /// Initial observation revision required by fixed and chain modes.
682        #[arg(long)]
683        expected_revision: Option<u64>,
684    },
685
686    #[command(subcommand_precedence_over_arg = true)]
687    Workflow {
688        /// Offline authoring operation. Omit to execute the workflow.
689        #[command(subcommand)]
690        action: Option<WorkflowAuthoringCommand>,
691        /// JSON file containing `{ "workflow": ..., "inputs": ... }`.
692        input: Option<PathBuf>,
693    },
694
695    /// Validate and compile a browser-free Task Protocol task.
696    Task {
697        #[command(subcommand)]
698        action: TaskCommand,
699    },
700
701    /// Inspect or diff browser-free Glass Web IR v1 JSON.
702    Ir {
703        #[command(subcommand)]
704        action: IrCommand,
705    },
706
707    /// Reconcile a workflow checkpoint and execute only its safe pending suffix.
708    WorkflowResume {
709        /// JSON file containing the workflow definition.
710        workflow: PathBuf,
711        /// JSON file containing a workflow checkpoint.
712        checkpoint: PathBuf,
713        /// Optional JSON file containing the workflow input map.
714        #[arg(long)]
715        inputs: Option<PathBuf>,
716    },
717
718    /// Resolve a declared intent from JSON or stdin without dispatching it.
719    ResolveIntent {
720        /// JSON file containing the versioned intent request; omit to read stdin.
721        input: Option<PathBuf>,
722    },
723
724    /// Resolve and execute one explicitly selected intent candidate.
725    ExecuteIntent {
726        /// JSON file containing the versioned execution request; omit to read stdin.
727        input: Option<PathBuf>,
728    },
729
730    /// Evaluate a bounded JSON verification predicate.
731    Verify {
732        /// JSON object such as `{"urlEquals":"https://example.com"}`.
733        predicate: String,
734        #[arg(long, default_value_t = 10_000)]
735        timeout_ms: u64,
736    },
737
738    /// Reconcile revisioned references against the current observation.
739    ReconcileRefs {
740        #[arg(long)]
741        from_revision: u64,
742        /// Stable locators tried positionally after backend identity is gone.
743        #[arg(long = "hint")]
744        hints: Vec<String>,
745        /// Current revisioned landmark/container ref used to narrow relocation.
746        #[arg(long)]
747        scope: Option<String>,
748        #[arg(required = true)]
749        refs: Vec<String>,
750    },
751
752    /// Report a bounded delta from the last compact observation.
753    ObserveDelta,
754
755    /// Export or import a bounded workflow checkpoint.
756    Checkpoint {
757        #[command(subcommand)]
758        action: CheckpointCommand,
759    },
760
761    /// Create, inspect, diff, or purge redacted local session snapshots.
762    Snapshot {
763        #[command(subcommand)]
764        action: SnapshotCommand,
765    },
766
767    /// Read text from the system clipboard.
768    ClipboardRead,
769
770    /// Write text to the system clipboard.
771    ClipboardWrite { text: String },
772
773    /// Launch the browser-first terminal workspace.
774    ///
775    /// `glass browser` is the shortest path to a browser session; `glass browser tui`
776    /// is an explicit equivalent.
777    Browser {
778        #[command(subcommand)]
779        action: Option<BrowserCommand>,
780    },
781
782    /// Start, inspect, and stop a persistent local browser session.
783    Session {
784        #[command(subcommand)]
785        action: SessionCommand,
786    },
787
788    /// Show grouped help and the embedded Glass workflow skills.
789    Help { topic: Option<String> },
790
791    /// Launch the development terminal workspace.
792    Tui,
793}
794
795#[derive(Debug, Subcommand)]
796pub enum BrowserCommand {
797    /// Launch the focused browser terminal workspace.
798    Tui,
799}
800
801#[derive(Debug, Subcommand)]
802pub enum SessionCommand {
803    /// Start one named persistent browser session.
804    Start {
805        #[arg(default_value = "default")]
806        name: String,
807    },
808    /// Inspect one persistent browser session without starting Chrome.
809    Status {
810        #[arg(default_value = "default")]
811        name: String,
812    },
813    /// Stop one persistent browser session and its owned browser.
814    Stop {
815        #[arg(default_value = "default")]
816        name: String,
817    },
818    /// Print the attach command for one persistent browser session.
819    Open {
820        #[arg(default_value = "default")]
821        name: String,
822    },
823    /// Foreground owner used internally by `session start`.
824    #[command(hide = true)]
825    Serve {
826        name: String,
827        #[arg(long)]
828        socket: PathBuf,
829        #[arg(long)]
830        status: PathBuf,
831    },
832}
833
834fn parse_semantic_level(value: &str) -> Result<String, String> {
835    match value {
836        "summary" | "interactive" | "structured" | "detailed" | "raw" => Ok(value.into()),
837        _ => Err("expected summary, interactive, structured, detailed, or raw".into()),
838    }
839}
840
841#[derive(Debug, Subcommand)]
842pub enum ProfileCommand {
843    List,
844    Create { name: String },
845    Delete { name: String },
846}
847
848#[derive(Debug, Subcommand)]
849pub enum KnowledgeCommand {
850    /// List all validated records.
851    List,
852    /// Show one record by ID.
853    Show { record_id: String },
854    /// Explain one record's provenance, lifecycle, and invalidation rules.
855    Explain { record_id: String },
856    /// Print lifecycle and serialized-size statistics.
857    Stats,
858    /// Export the validated snapshot to stdout or a file.
859    Export { output: Option<PathBuf> },
860    /// Import and replace the complete validated snapshot.
861    Import { input: PathBuf },
862    /// Move one record to a non-eligible state.
863    Invalidate {
864        record_id: String,
865        #[arg(value_enum)]
866        state: KnowledgeInvalidationState,
867        #[arg(long)]
868        reason: Option<String>,
869        #[arg(long)]
870        observed_at: Option<String>,
871    },
872    /// Remove every record for one exact origin.
873    Purge { origin: String },
874}
875
876#[derive(Debug, Subcommand)]
877pub enum WorkspaceCommand {
878    List,
879    Inspect { id: String },
880    Suspend { id: String },
881    Resume { id: String },
882    Delete { id: String },
883}
884
885#[derive(Debug, Subcommand)]
886pub enum ProjectCommand {
887    /// Detect the project and print its runtime configuration.
888    Inspect {
889        #[arg(long, default_value = ".")]
890        root: PathBuf,
891    },
892    /// List bounded project files.
893    Files {
894        #[arg(long, default_value = ".")]
895        root: PathBuf,
896    },
897    /// Search files, browser entities, processes, events, and commands.
898    Search {
899        query: String,
900        #[arg(long, default_value_t = 64)]
901        limit: usize,
902        #[arg(long, default_value = ".")]
903        root: PathBuf,
904    },
905    /// Read one workspace-confined file.
906    Read {
907        path: String,
908        #[arg(long, default_value = ".")]
909        root: PathBuf,
910    },
911    /// Edit and save one file through the native buffer contract.
912    Edit {
913        path: String,
914        #[arg(long, conflicts_with = "input")]
915        content: Option<String>,
916        #[arg(long, conflicts_with = "content")]
917        input: Option<PathBuf>,
918        #[arg(long, default_value = ".")]
919        root: PathBuf,
920    },
921    /// Create a workspace-confined directory, including missing parents.
922    Mkdir {
923        path: String,
924        #[arg(long, default_value = ".")]
925        root: PathBuf,
926    },
927    /// Rename or move one workspace-confined file or directory.
928    Rename {
929        from: String,
930        to: String,
931        #[arg(long, default_value = ".")]
932        root: PathBuf,
933    },
934    /// Delete one file or an empty directory after explicit confirmation.
935    Delete {
936        path: String,
937        #[arg(long)]
938        yes: bool,
939        #[arg(long, default_value = ".")]
940        root: PathBuf,
941    },
942    /// Request real diagnostics from rust-analyzer through LSP.
943    Diagnostics {
944        path: String,
945        #[arg(long, default_value = ".")]
946        root: PathBuf,
947    },
948    /// Start a named development process in a real PTY.
949    Run {
950        name: String,
951        #[arg(long)]
952        command: Option<String>,
953        #[arg(long)]
954        wait: bool,
955        #[arg(long, default_value = ".")]
956        root: PathBuf,
957    },
958    /// Run the detected test command in a PTY and wait for completion.
959    Test {
960        #[arg(long, default_value = ".")]
961        root: PathBuf,
962    },
963    /// Run the detected lint command in a PTY and wait for completion.
964    Lint {
965        #[arg(long, default_value = ".")]
966        root: PathBuf,
967    },
968    /// Inspect, start, stop, or read a managed process.
969    Process {
970        #[arg(long, default_value = ".")]
971        root: PathBuf,
972        #[command(subcommand)]
973        action: ProjectProcessCommand,
974    },
975    /// Show code, runtime, semantic, and workflow impact.
976    Diff {
977        #[arg(long, default_value = ".")]
978        root: PathBuf,
979    },
980    /// Record an explicit source/runtime relationship with evidence.
981    Link {
982        entity: String,
983        path: String,
984        #[arg(long)]
985        start_line: u32,
986        #[arg(long)]
987        end_line: u32,
988        #[arg(long, default_value = "explicit-marker")]
989        provenance: String,
990        #[arg(long, default_value_t = 1.0)]
991        confidence: f32,
992        #[arg(long, default_value = "explicit project link")]
993        detail: String,
994        #[arg(long, default_value = ".")]
995        root: PathBuf,
996    },
997    /// Discover or inspect bidirectional source/runtime graph links.
998    Graph {
999        #[arg(long, default_value = ".")]
1000        root: PathBuf,
1001        #[command(subcommand)]
1002        action: ProjectGraphCommand,
1003    },
1004    /// Evaluate one semantic regression breakpoint against two snapshots.
1005    Breakpoint {
1006        kind: String,
1007        entity: String,
1008        before: PathBuf,
1009        after: PathBuf,
1010        #[arg(long, default_value = ".")]
1011        root: PathBuf,
1012    },
1013    /// Show the bounded development timeline.
1014    Timeline {
1015        #[arg(long, default_value = ".")]
1016        root: PathBuf,
1017    },
1018    /// Replay a bounded window of attributed development revisions.
1019    Replay {
1020        #[arg(long, default_value_t = 0)]
1021        start: usize,
1022        #[arg(long, default_value_t = 64)]
1023        limit: usize,
1024        #[arg(long, default_value = ".")]
1025        root: PathBuf,
1026    },
1027    /// Probe or launch Neovim integration.
1028    Neovim {
1029        #[arg(long, default_value = ".")]
1030        root: PathBuf,
1031        #[command(subcommand)]
1032        action: NeovimCommand,
1033    },
1034    /// Create an isolated Git worktree development experiment.
1035    Experiment {
1036        #[arg(long, default_value = ".")]
1037        root: PathBuf,
1038        #[command(subcommand)]
1039        action: ExperimentCommand,
1040    },
1041    /// Attach an external actor to the attributed development timeline.
1042    Attach {
1043        actor: String,
1044        #[arg(long, default_value = ".")]
1045        root: PathBuf,
1046    },
1047}
1048
1049#[derive(Debug, Subcommand)]
1050pub enum ProjectGraphCommand {
1051    Discover,
1052    Entity {
1053        entity: String,
1054    },
1055    Source {
1056        path: String,
1057        #[arg(long)]
1058        line: Option<u32>,
1059    },
1060}
1061
1062#[derive(Debug, Subcommand)]
1063pub enum NeovimCommand {
1064    Probe,
1065    Start {
1066        #[arg(long, default_value = "neovim")]
1067        name: String,
1068        path: Option<PathBuf>,
1069    },
1070}
1071
1072#[derive(Debug, Subcommand)]
1073pub enum ExperimentCommand {
1074    Create {
1075        name: String,
1076        #[arg(long)]
1077        port: u16,
1078    },
1079}
1080
1081#[derive(Debug, Subcommand)]
1082pub enum ProjectProcessCommand {
1083    List,
1084    Start {
1085        name: String,
1086        command: String,
1087        #[arg(long)]
1088        wait: bool,
1089    },
1090    Stop {
1091        name: String,
1092    },
1093    Restart {
1094        name: String,
1095    },
1096    Remove {
1097        name: String,
1098    },
1099    Input {
1100        name: String,
1101        input: String,
1102    },
1103    Resize {
1104        name: String,
1105        cols: u16,
1106        rows: u16,
1107    },
1108    Output {
1109        name: String,
1110    },
1111}
1112
1113#[derive(Debug, Subcommand)]
1114pub enum AgentCommand {
1115    /// Inspect Node, Pi SDK, authentication, model, and session readiness.
1116    Doctor,
1117    /// Install or select the Glass-managed native Pi SDK runtime.
1118    Setup {
1119        /// Select an existing Pi SDK dist/index.js instead of installing one.
1120        #[arg(long)]
1121        sdk_entry: Option<PathBuf>,
1122        /// Use this existing Pi agent directory for credentials and models.
1123        #[arg(long, requires = "sdk_entry")]
1124        agent_dir: Option<PathBuf>,
1125        /// Reinstall the pinned managed SDK even when it is already ready.
1126        #[arg(long)]
1127        update: bool,
1128        /// Open the managed Pi CLI after setup so `/login` can configure auth.
1129        #[arg(long)]
1130        login: bool,
1131    },
1132    /// Print the concise current Glass Agent readiness state.
1133    Status,
1134    /// Delegate one bounded prompt to an installed temporary external agent.
1135    Delegate {
1136        /// External agent id: codex, claude, or opencode.
1137        harness: String,
1138        /// Prompt text, or `-` to read the prompt from stdin.
1139        prompt: String,
1140        #[arg(long, default_value = ".")]
1141        root: PathBuf,
1142        #[arg(long, value_enum, default_value_t = ExternalAgentSandbox::ReadOnly)]
1143        sandbox: ExternalAgentSandbox,
1144        #[arg(long, default_value_t = 600)]
1145        timeout_secs: u64,
1146        /// Permit a workspace-write sandbox. Pair with `--yes`.
1147        #[arg(long)]
1148        allow_mutation: bool,
1149        /// Confirm the exact workspace-write delegation.
1150        #[arg(long)]
1151        yes: bool,
1152    },
1153    /// Execute one schema-validated call through the Glass agent-tool broker.
1154    #[command(hide = true)]
1155    Tool {
1156        call: String,
1157        #[arg(long, default_value = ".")]
1158        root: PathBuf,
1159        #[arg(long)]
1160        allow_mutation: bool,
1161        #[arg(long)]
1162        yes: bool,
1163    },
1164    /// Execute a one-use broker request from a private temporary file.
1165    #[command(hide = true)]
1166    ToolFile {
1167        path: PathBuf,
1168        #[arg(long, default_value = ".")]
1169        root: PathBuf,
1170        #[arg(long)]
1171        allow_mutation: bool,
1172        #[arg(long)]
1173        yes: bool,
1174    },
1175    /// Negotiate the Glass-owned harness protocol.
1176    Hello {
1177        #[arg(long, default_value = ".")]
1178        root: PathBuf,
1179        #[arg(long, value_enum, default_value_t = AgentHarness::Local)]
1180        harness: AgentHarness,
1181    },
1182    /// Run one bounded local prompt through the harness.
1183    Prompt {
1184        text: String,
1185        #[arg(long, default_value = ".")]
1186        root: PathBuf,
1187        #[arg(long, value_enum, default_value_t = AgentHarness::Local)]
1188        harness: AgentHarness,
1189    },
1190    /// Steer the active local harness request.
1191    Steer {
1192        text: String,
1193        #[arg(long, default_value = ".")]
1194        root: PathBuf,
1195        #[arg(long, value_enum, default_value_t = AgentHarness::Pi)]
1196        harness: AgentHarness,
1197    },
1198    /// Queue a follow-up through the native Pi SDK runtime.
1199    FollowUp {
1200        text: String,
1201        #[arg(long, default_value = ".")]
1202        root: PathBuf,
1203    },
1204    /// List models exposed by the native Pi SDK runtime.
1205    Models {
1206        #[arg(long, default_value = ".")]
1207        root: PathBuf,
1208    },
1209    /// Select a Pi provider/model pair.
1210    SetModel {
1211        provider: String,
1212        model_id: String,
1213        #[arg(long, default_value = ".")]
1214        root: PathBuf,
1215    },
1216    /// Set the Pi thinking level.
1217    Thinking {
1218        level: String,
1219        #[arg(long, default_value = ".")]
1220        root: PathBuf,
1221    },
1222    /// Abort the active Pi request.
1223    Abort {
1224        #[arg(long, default_value = ".")]
1225        root: PathBuf,
1226    },
1227    /// Start a fresh Pi session.
1228    NewSession {
1229        #[arg(long, default_value = ".")]
1230        root: PathBuf,
1231    },
1232}
1233
1234#[derive(Debug, Subcommand)]
1235pub enum HarnessCommand {
1236    /// List supported coding harnesses and PATH availability.
1237    List,
1238    /// Launch one installed harness in the selected project directory.
1239    Start {
1240        name: String,
1241        #[arg(long, default_value = ".")]
1242        root: PathBuf,
1243    },
1244}
1245
1246#[derive(Debug, Clone, Copy, ValueEnum)]
1247pub enum AgentHarness {
1248    Local,
1249    Pi,
1250}
1251
1252#[derive(Debug, Clone, Copy, ValueEnum)]
1253pub enum ExternalAgentSandbox {
1254    ReadOnly,
1255    WorkspaceWrite,
1256}
1257
1258#[derive(Debug, Subcommand)]
1259pub enum MemoryCommand {
1260    Status,
1261    Inspect {
1262        record_id: String,
1263    },
1264    Explain {
1265        record_id: String,
1266    },
1267    Forget {
1268        record_id: String,
1269    },
1270    Export {
1271        output: Option<PathBuf>,
1272    },
1273    /// Remove stale, contradicted, and quarantined records.
1274    Prune,
1275    /// Re-read and validate the snapshot from disk.
1276    Reindex,
1277}
1278
1279#[derive(Debug, Subcommand)]
1280pub enum SurfaceCommand {
1281    Inspect { input: PathBuf },
1282    Coverage { input: PathBuf },
1283}
1284
1285#[derive(Debug, Subcommand)]
1286pub enum BackendCommand {
1287    Status { input: PathBuf },
1288    Capabilities { input: PathBuf },
1289    Test { input: PathBuf },
1290}
1291
1292#[derive(Debug, Subcommand)]
1293pub enum ReplayCommand {
1294    Inspect {
1295        scenario: PathBuf,
1296        input: PathBuf,
1297    },
1298    Diff {
1299        scenario: PathBuf,
1300        before: PathBuf,
1301        after: PathBuf,
1302    },
1303    Attach {
1304        scenario: PathBuf,
1305        input: PathBuf,
1306    },
1307}
1308
1309#[derive(Debug, Subcommand)]
1310pub enum SnapshotCommand {
1311    Create,
1312    List,
1313    Inspect { snapshot_id: String },
1314    Diff { from: String, to: String },
1315    Purge,
1316}
1317
1318#[derive(Debug, Subcommand)]
1319pub enum ResultCommand {
1320    /// Show a stored diagnostic artifact, optionally selecting one section.
1321    Show {
1322        result_id: String,
1323        #[arg(long)]
1324        section: Option<String>,
1325    },
1326    /// Purge artifacts older than a bounded duration such as 7d or 24h.
1327    Purge {
1328        #[arg(long = "older-than")]
1329        older_than: String,
1330    },
1331}
1332#[derive(Debug, Clone, Copy, ValueEnum)]
1333pub enum KnowledgeInvalidationState {
1334    Stale,
1335    Contradicted,
1336    Quarantined,
1337}
1338
1339#[derive(Debug, Subcommand)]
1340pub enum WorkflowAuthoringCommand {
1341    /// Compile YAML or JSON source into canonical workflow JSON.
1342    Compile {
1343        input: PathBuf,
1344        #[arg(short, long)]
1345        output: Option<PathBuf>,
1346    },
1347    /// Format a YAML or JSON workflow as deterministic YAML.
1348    Format {
1349        input: PathBuf,
1350        #[arg(short, long)]
1351        output: Option<PathBuf>,
1352    },
1353    /// Show a redacted browser-free execution preview.
1354    Preview { input: PathBuf },
1355    /// Compare two workflow sources and print migration guidance.
1356    Diff { before: PathBuf, after: PathBuf },
1357    /// Import explicit semantic evidence into a reviewable draft.
1358    Record {
1359        /// JSON event envelope; omit to read stdin.
1360        #[arg(long)]
1361        input: Option<PathBuf>,
1362        #[arg(short, long)]
1363        output: Option<PathBuf>,
1364    },
1365    /// Validate authoring source against the canonical workflow contract.
1366    Validate { input: PathBuf },
1367    /// Run static workflow diagnostics without starting a browser.
1368    Lint {
1369        input: PathBuf,
1370        #[arg(long)]
1371        warnings_as_errors: bool,
1372    },
1373    /// List or initialize one of the reviewable workflow starter templates.
1374    Templates {
1375        /// Optional template name; omit to list available templates.
1376        name: Option<String>,
1377        #[arg(short, long)]
1378        output: Option<PathBuf>,
1379    },
1380    /// Initialize one of the five reviewable issue 29 starter templates.
1381    Init {
1382        /// Template name: search, form-submit, paginated-extraction,
1383        /// authenticated-session, or dialog-and-download.
1384        name: String,
1385        #[arg(short, long)]
1386        output: Option<PathBuf>,
1387    },
1388}
1389
1390#[derive(Debug, Subcommand)]
1391pub enum TaskCommand {
1392    /// Validate strict Task Protocol JSON without starting Chrome.
1393    Validate {
1394        /// JSON file containing the authored task.
1395        input: PathBuf,
1396    },
1397    /// Compile strict Task Protocol JSON into a deterministic execution plan.
1398    Compile {
1399        /// JSON file containing the authored task.
1400        input: PathBuf,
1401        /// Stable Glass Web IR v1 JSON used as compilation evidence.
1402        ir: PathBuf,
1403        /// Optional output file for the canonical execution plan.
1404        #[arg(short, long)]
1405        output: Option<PathBuf>,
1406        /// Print a deterministic compilation explanation to stderr.
1407        #[arg(long)]
1408        explain: bool,
1409    },
1410    /// Execute a validated browser-backed Task Protocol task against the current browser.
1411    Execute {
1412        /// JSON file containing the authored task from the form, navigation, dialog,
1413        /// pagination, extraction, or field-read Task Protocol families.
1414        input: PathBuf,
1415        /// Revision from the caller's preceding semantic observation.
1416        #[arg(long)]
1417        expected_revision: u64,
1418        /// Confirm a task whose risk or ambiguity policy requires confirmation.
1419        #[arg(long)]
1420        confirm: bool,
1421    },
1422}
1423
1424#[derive(Debug, Subcommand)]
1425pub enum IrCommand {
1426    /// Validate one Glass Web IR v1 document without starting Chrome.
1427    Validate { input: PathBuf },
1428    /// Print a bounded summary of one validated Glass Web IR v1 document.
1429    Inspect { input: PathBuf },
1430    /// Compute a deterministic diff between two validated Web IR revisions.
1431    Diff {
1432        before: PathBuf,
1433        after: PathBuf,
1434        /// Print the bounded canonical summary instead of detailed changes.
1435        #[arg(long)]
1436        summary: bool,
1437    },
1438    /// Classify one entity's continuity across two validated Web IR revisions.
1439    Continuity {
1440        before: PathBuf,
1441        after: PathBuf,
1442        entity_id: String,
1443    },
1444    /// Print one validated Glass Web IR v1 document in canonical JSON form.
1445    Canonical { input: PathBuf },
1446}
1447
1448#[derive(Debug, Subcommand)]
1449pub enum DaemonCommand {
1450    /// Start the daemon in the background.
1451    Start {
1452        #[arg(long)]
1453        socket: Option<PathBuf>,
1454        #[arg(long)]
1455        status: Option<PathBuf>,
1456    },
1457    /// Read the daemon status contract.
1458    Status {
1459        #[arg(long)]
1460        socket: Option<PathBuf>,
1461        #[arg(long)]
1462        status: Option<PathBuf>,
1463    },
1464    /// Stop the daemon recorded by the status contract.
1465    Stop {
1466        #[arg(long)]
1467        socket: Option<PathBuf>,
1468        #[arg(long)]
1469        status: Option<PathBuf>,
1470    },
1471    /// Check the daemon process, status, and local socket.
1472    Doctor {
1473        #[arg(long)]
1474        socket: Option<PathBuf>,
1475        #[arg(long)]
1476        status: Option<PathBuf>,
1477    },
1478    /// Read the bounded local daemon log tail.
1479    Logs {
1480        #[arg(long)]
1481        status: Option<PathBuf>,
1482    },
1483    /// Acknowledge that interrupted workflows were reconciled from checkpoints.
1484    AcknowledgeRecovery {
1485        #[arg(long)]
1486        status: Option<PathBuf>,
1487        /// Request ID for every recovery record reconciled from a checkpoint.
1488        #[arg(long = "request-id", required = true)]
1489        request_ids: Vec<String>,
1490    },
1491    /// Internal foreground server used by `daemon start`.
1492    #[command(hide = true)]
1493    Serve {
1494        #[arg(long)]
1495        socket: PathBuf,
1496        #[arg(long)]
1497        status: PathBuf,
1498    },
1499}
1500
1501#[derive(Debug, Subcommand)]
1502pub enum CertifyCommand {
1503    /// Run one scenario in a navigated browser fixture and emit evidence.
1504    Run {
1505        /// JSON scenario to execute.
1506        #[arg(long)]
1507        scenario: PathBuf,
1508        /// JSON fixture manifest used to bind controls and faults.
1509        #[arg(long)]
1510        fixture: PathBuf,
1511        /// Fixture URL to navigate before execution.
1512        #[arg(long)]
1513        url: String,
1514        /// Directory containing workflow sources referenced by the scenario.
1515        #[arg(long, default_value = ".")]
1516        workflow_root: PathBuf,
1517        /// Optional JSON object containing declared workflow inputs.
1518        #[arg(long)]
1519        inputs: Option<PathBuf>,
1520        /// Optional path for the redacted evidence bundle.
1521        #[arg(short, long)]
1522        output: Option<PathBuf>,
1523    },
1524    /// Expand a scenario into its manifest-bound execution plan.
1525    Plan {
1526        /// JSON scenario to plan.
1527        #[arg(long)]
1528        scenario: PathBuf,
1529        /// JSON fixture manifest used to bind controls and faults.
1530        #[arg(long)]
1531        fixture: PathBuf,
1532    },
1533    /// Evaluate a release-blocking reliability gate.
1534    Release {
1535        #[arg(long)]
1536        version: String,
1537        /// JSON array of validated reliability scenarios.
1538        #[arg(long)]
1539        scenarios: PathBuf,
1540        /// JSON array of scenario observations and oracle evidence.
1541        #[arg(long)]
1542        observations: PathBuf,
1543        /// Optional JSON array of redacted replay bundles to cross-check.
1544        #[arg(long)]
1545        replays: Option<PathBuf>,
1546    },
1547    /// Validate one redacted replay bundle against its versioned scenario.
1548    Replay {
1549        /// JSON scenario used to validate the replay binding.
1550        #[arg(long)]
1551        scenario: PathBuf,
1552        /// JSON replay bundle to validate.
1553        #[arg(long)]
1554        input: PathBuf,
1555    },
1556    /// Compare two redacted replay bundles for one scenario.
1557    ReplayDiff {
1558        /// JSON scenario used to validate both replay bindings.
1559        #[arg(long)]
1560        scenario: PathBuf,
1561        /// Baseline replay bundle.
1562        #[arg(long)]
1563        before: PathBuf,
1564        /// Candidate replay bundle.
1565        #[arg(long)]
1566        after: PathBuf,
1567    },
1568}
1569
1570#[derive(Debug, Subcommand)]
1571pub enum CheckpointCommand {
1572    Export,
1573    Import { input: Option<PathBuf> },
1574}
1575
1576#[cfg(test)]
1577mod tests {
1578    use super::*;
1579
1580    #[test]
1581    fn default_invocation_is_promptless_and_commandless() {
1582        let cli = Cli::try_parse_from(["glass"]).unwrap();
1583
1584        assert!(cli.prompt.is_none());
1585        assert!(cli.command.is_none());
1586    }
1587
1588    #[test]
1589    fn tui_is_discoverable_as_an_explicit_command() {
1590        assert!(matches!(
1591            Cli::try_parse_from(["glass", "tui"]).unwrap().command,
1592            Some(Commands::Tui)
1593        ));
1594    }
1595
1596    #[test]
1597    fn browser_and_session_onboarding_commands_parse() {
1598        let browser = Cli::try_parse_from(["glass", "browser"]).unwrap();
1599        assert!(matches!(
1600            browser.command,
1601            Some(Commands::Browser { action: None })
1602        ));
1603
1604        let session = Cli::try_parse_from(["glass", "--session", "work", "observe"]).unwrap();
1605        assert_eq!(session.session.as_deref(), Some("work"));
1606        assert!(matches!(session.command, Some(Commands::Observe { .. })));
1607
1608        let start = Cli::try_parse_from(["glass", "session", "start", "work"]).unwrap();
1609        assert!(matches!(
1610            start.command,
1611            Some(Commands::Session {
1612                action: SessionCommand::Start { ref name }
1613            }) if name == "work"
1614        ));
1615    }
1616    #[test]
1617    fn update_options_are_explicit_and_browser_free() {
1618        let cli = Cli::try_parse_from([
1619            "glass",
1620            "update",
1621            "--dry-run",
1622            "--version",
1623            "0.3.4",
1624            "--force",
1625            "--registry",
1626            "internal",
1627        ])
1628        .unwrap();
1629        assert!(matches!(
1630            cli.command,
1631            Some(Commands::Update {
1632                dry_run: true,
1633                version: Some(ref version),
1634                force: true,
1635                registry: Some(ref registry),
1636            }) if version == "0.3.4" && registry == "internal"
1637        ));
1638    }
1639
1640    #[test]
1641    fn tui_layout_defaults_to_auto_and_accepts_mobile_override() {
1642        let default = Cli::try_parse_from(["glass", "tui"]).unwrap();
1643        assert!(!default.yolo);
1644        assert_eq!(default.tui_layout, TuiLayout::Auto);
1645        assert_eq!(default.tui_live, TuiLiveMode::Off);
1646        assert_eq!(default.tui_live_backend, TuiLiveBackend::Auto);
1647        assert_eq!(default.tui_live_quality, TuiLiveQuality::Balanced);
1648        assert_eq!(default.tui_live_fit, TuiLiveFit::Contain);
1649
1650        let mobile = Cli::try_parse_from([
1651            "glass",
1652            "--tui-layout",
1653            "mobile",
1654            "--tui-live",
1655            "on",
1656            "--tui-live-backend",
1657            "ansi",
1658            "--tui-live-quality",
1659            "data",
1660            "--tui-live-fit",
1661            "cover",
1662            "tui",
1663        ])
1664        .unwrap();
1665        assert_eq!(mobile.tui_layout, TuiLayout::Mobile);
1666        assert_eq!(mobile.tui_live, TuiLiveMode::On);
1667        assert_eq!(mobile.tui_live_backend, TuiLiveBackend::Ansi);
1668        assert_eq!(mobile.tui_live_quality, TuiLiveQuality::Data);
1669        assert_eq!(mobile.tui_live_fit, TuiLiveFit::Cover);
1670    }
1671
1672    #[test]
1673    fn yolo_is_an_explicit_global_opt_in() {
1674        assert!(
1675            Cli::try_parse_from(["glass", "--yolo", "tui"])
1676                .unwrap()
1677                .yolo
1678        );
1679        assert!(
1680            Cli::try_parse_from(["glass", "agent", "hello", "--yolo"])
1681                .unwrap()
1682                .yolo
1683        );
1684    }
1685
1686    #[test]
1687    fn agent_readiness_commands_are_explicit() {
1688        assert!(matches!(
1689            Cli::try_parse_from(["glass", "agent", "doctor"])
1690                .unwrap()
1691                .command,
1692            Some(Commands::Agent {
1693                action: AgentCommand::Doctor
1694            })
1695        ));
1696        assert!(matches!(
1697            Cli::try_parse_from([
1698                "glass",
1699                "agent",
1700                "setup",
1701                "--sdk-entry",
1702                "/opt/pi/dist/index.js",
1703                "--agent-dir",
1704                "/opt/pi/config",
1705                "--update"
1706            ])
1707            .unwrap()
1708            .command,
1709            Some(Commands::Agent {
1710                action: AgentCommand::Setup {
1711                    sdk_entry: Some(_),
1712                    agent_dir: Some(_),
1713                    update: true,
1714                    login: false,
1715                }
1716            })
1717        ));
1718    }
1719
1720    #[test]
1721    fn external_harness_commands_are_available_to_the_cli() {
1722        assert!(matches!(
1723            Cli::try_parse_from(["glass", "harness", "list"])
1724                .unwrap()
1725                .command,
1726            Some(Commands::Harness {
1727                action: HarnessCommand::List
1728            })
1729        ));
1730        assert!(matches!(
1731            Cli::try_parse_from(["glass", "harness", "start", "codex", "--root", "/tmp/project"])
1732                .unwrap()
1733                .command,
1734            Some(Commands::Harness {
1735                action: HarnessCommand::Start { ref name, ref root }
1736            }) if name == "codex" && root == std::path::Path::new("/tmp/project")
1737        ));
1738    }
1739
1740    #[test]
1741    fn observation_and_human_interaction_are_defaults() {
1742        let cli = Cli::try_parse_from(["glass", "observe"]).unwrap();
1743
1744        assert_eq!(cli.interaction, InteractionMode::Human);
1745        assert!(matches!(
1746            cli.command,
1747            Some(Commands::Observe {
1748                deep_dom: false,
1749                screenshot: false,
1750                form_values: false,
1751                semantic_level: None,
1752                region: None,
1753            })
1754        ));
1755    }
1756
1757    #[test]
1758    fn screenshot_and_fast_interaction_require_explicit_flags() {
1759        let cli =
1760            Cli::try_parse_from(["glass", "--interaction", "fast", "observe", "--screenshot"])
1761                .unwrap();
1762
1763        assert_eq!(cli.interaction, InteractionMode::Fast);
1764        assert!(matches!(
1765            cli.command,
1766            Some(Commands::Observe {
1767                deep_dom: false,
1768                screenshot: true,
1769                form_values: false,
1770                semantic_level: None,
1771                region: None,
1772            })
1773        ));
1774    }
1775
1776    #[test]
1777    fn deep_dom_requires_an_explicit_observation_flag() {
1778        let cli = Cli::try_parse_from(["glass", "observe", "--deep-dom"]).unwrap();
1779
1780        assert!(matches!(
1781            cli.command,
1782            Some(Commands::Observe {
1783                deep_dom: true,
1784                screenshot: false,
1785                form_values: false,
1786                semantic_level: None,
1787                region: None,
1788            })
1789        ));
1790    }
1791
1792    #[test]
1793    fn semantic_observation_level_and_region_are_explicit() {
1794        let cli = Cli::try_parse_from([
1795            "glass",
1796            "observe",
1797            "--level",
1798            "interactive",
1799            "--region",
1800            "region_main",
1801        ])
1802        .unwrap();
1803        assert!(matches!(
1804            cli.command,
1805            Some(Commands::Observe {
1806                semantic_level: Some(level),
1807                region: Some(region),
1808                ..
1809            }) if level == "interactive" && region == "region_main"
1810        ));
1811
1812        assert!(Cli::try_parse_from(["glass", "observe", "--level", "verbose"]).is_err());
1813    }
1814
1815    #[test]
1816    fn screenshot_remains_a_separate_explicit_command() {
1817        let cli = Cli::try_parse_from(["glass", "screenshot", "--output", "page.png"]).unwrap();
1818
1819        assert!(matches!(
1820            cli.command,
1821            Some(Commands::Screenshot { output, .. }) if output == "page.png"
1822        ));
1823    }
1824
1825    #[test]
1826    fn double_click_is_an_explicit_action_command() {
1827        let cli = Cli::try_parse_from(["glass", "double-click", "r7:b42"]).unwrap();
1828
1829        assert!(matches!(
1830            cli.command,
1831            Some(Commands::DoubleClick { target, .. }) if target == "r7:b42"
1832        ));
1833    }
1834
1835    #[test]
1836    fn click_expect_popup_is_an_explicit_action_command() {
1837        let cli = Cli::try_parse_from(["glass", "click-expect-popup", "css=#popup"]).unwrap();
1838        assert!(matches!(
1839            cli.command,
1840            Some(Commands::ClickExpectPopup { target, .. }) if target == "css=#popup"
1841        ));
1842    }
1843
1844    #[test]
1845    fn wait_has_an_explicit_condition_and_bounded_default() {
1846        let cli = Cli::try_parse_from(["glass", "wait", "text=Ready"]).unwrap();
1847        assert!(matches!(
1848            cli.command,
1849            Some(Commands::Wait { condition, timeout_ms: 10_000 }) if condition == "text=Ready"
1850        ));
1851    }
1852
1853    #[test]
1854    fn topology_commands_are_explicit() {
1855        assert!(matches!(
1856            Cli::try_parse_from(["glass", "targets"]).unwrap().command,
1857            Some(Commands::Targets)
1858        ));
1859        let cli = Cli::try_parse_from([
1860            "glass",
1861            "--target-id",
1862            "page-1",
1863            "--frame-id",
1864            "frame-1",
1865            "evaluate",
1866            "document.title",
1867        ])
1868        .unwrap();
1869        assert_eq!(cli.target_id.as_deref(), Some("page-1"));
1870        assert_eq!(cli.frame_id.as_deref(), Some("frame-1"));
1871        assert!(matches!(
1872            Cli::try_parse_from(["glass", "select-frame", "frame-1"])
1873                .unwrap()
1874                .command,
1875            Some(Commands::SelectFrame { id }) if id == "frame-1"
1876        ));
1877    }
1878
1879    #[test]
1880    fn archive_targets_accepts_optional_workspace_output() {
1881        let stdout = Cli::try_parse_from(["glass", "archive-targets"])
1882            .unwrap()
1883            .command;
1884        assert!(matches!(
1885            stdout,
1886            Some(Commands::ArchiveTargets { output: None })
1887        ));
1888        let file = Cli::try_parse_from(["glass", "archive-targets", "--output", "targets.json"])
1889            .unwrap()
1890            .command;
1891        assert!(matches!(
1892            file,
1893            Some(Commands::ArchiveTargets {
1894                output: Some(path)
1895            }) if path == std::path::Path::new("targets.json")
1896        ));
1897    }
1898
1899    #[test]
1900    fn complete_input_commands_are_explicit() {
1901        assert!(matches!(
1902            Cli::try_parse_from(["glass", "drag", "css=#from", "css=#to"])
1903                .unwrap()
1904                .command,
1905            Some(Commands::Drag { source, destination, .. }) if source == "css=#from" && destination == "css=#to"
1906        ));
1907        assert!(matches!(
1908            Cli::try_parse_from(["glass", "shortcut", "Control+A"])
1909                .unwrap()
1910                .command,
1911            Some(Commands::Shortcut { shortcut, .. }) if shortcut == "Control+A"
1912        ));
1913        assert!(matches!(
1914            Cli::try_parse_from([
1915                "glass",
1916                "fill-form",
1917                "--fields",
1918                "[]",
1919                "--expected-revision",
1920                "7"
1921            ])
1922            .unwrap()
1923            .command,
1924            Some(Commands::FillForm {
1925                fields,
1926                expected_revision: Some(7)
1927            }) if fields == "[]"
1928        ));
1929    }
1930
1931    #[test]
1932    fn rejects_unknown_interaction_modes() {
1933        assert!(Cli::try_parse_from(["glass", "--interaction", "instant", "observe"]).is_err());
1934    }
1935
1936    #[test]
1937    fn attach_and_target_id_are_explicit_global_options() {
1938        let cli = Cli::try_parse_from([
1939            "glass",
1940            "--attach",
1941            "--port",
1942            "9333",
1943            "--target-id",
1944            "page-2",
1945            "observe",
1946        ])
1947        .unwrap();
1948
1949        assert!(cli.attach);
1950        assert_eq!(cli.port, 9333);
1951        assert_eq!(cli.target_id.as_deref(), Some("page-2"));
1952    }
1953
1954    #[test]
1955    fn workflow_command_accepts_optional_json_input() {
1956        let cli = Cli::try_parse_from(["glass", "workflow", "workflow.json"]).unwrap();
1957        assert!(matches!(
1958            cli.command,
1959            Some(Commands::Workflow {
1960                action: None,
1961                input: Some(path)
1962            })
1963                if path.as_os_str() == "workflow.json"
1964        ));
1965        let cli = Cli::try_parse_from(["glass", "workflow", "validate", "workflow.yaml"]).unwrap();
1966        assert!(matches!(
1967            cli.command,
1968            Some(Commands::Workflow {
1969                action: Some(WorkflowAuthoringCommand::Validate { input }),
1970                input: None,
1971            }) if input.as_os_str() == "workflow.yaml"
1972        ));
1973        let cli = Cli::try_parse_from(["glass", "workflow", "preview", "workflow.yaml"]).unwrap();
1974        assert!(matches!(
1975            cli.command,
1976            Some(Commands::Workflow {
1977                action: Some(WorkflowAuthoringCommand::Preview { input }),
1978                input: None,
1979            }) if input.as_os_str() == "workflow.yaml"
1980        ));
1981        let cli = Cli::try_parse_from([
1982            "glass",
1983            "workflow",
1984            "record",
1985            "--input",
1986            "events.json",
1987            "--output",
1988            "draft.json",
1989        ])
1990        .unwrap();
1991        assert!(matches!(
1992            cli.command,
1993            Some(Commands::Workflow {
1994                action: Some(WorkflowAuthoringCommand::Record { input: Some(input), output: Some(output) }),
1995                input: None,
1996            }) if input.as_os_str() == "events.json" && output.as_os_str() == "draft.json"
1997        ));
1998    }
1999
2000    #[test]
2001    fn certify_release_command_accepts_versioned_evidence_paths() {
2002        let cli = Cli::try_parse_from([
2003            "glass",
2004            "certify",
2005            "release",
2006            "--version",
2007            "0.2.0",
2008            "--scenarios",
2009            "scenarios.json",
2010            "--observations",
2011            "observations.json",
2012        ])
2013        .unwrap();
2014        assert!(matches!(
2015            cli.command,
2016            Some(Commands::Certify {
2017                action: CertifyCommand::Release {
2018                    version,
2019                    scenarios,
2020                    observations,
2021                    replays: None,
2022                },
2023            }) if version == "0.2.0"
2024                && scenarios.as_os_str() == "scenarios.json"
2025                && observations.as_os_str() == "observations.json"
2026        ));
2027    }
2028
2029    #[test]
2030    fn certify_plan_command_accepts_scenario_and_fixture_paths() {
2031        let cli = Cli::try_parse_from([
2032            "glass",
2033            "certify",
2034            "plan",
2035            "--scenario",
2036            "scenario.json",
2037            "--fixture",
2038            "fixture.json",
2039        ])
2040        .unwrap();
2041        assert!(matches!(
2042            cli.command,
2043            Some(Commands::Certify {
2044                action: CertifyCommand::Plan { scenario, fixture },
2045            }) if scenario.as_os_str() == "scenario.json" && fixture.as_os_str() == "fixture.json"
2046        ));
2047    }
2048
2049    #[test]
2050    fn certify_replay_command_accepts_scenario_and_bundle_paths() {
2051        let cli = Cli::try_parse_from([
2052            "glass",
2053            "certify",
2054            "replay",
2055            "--scenario",
2056            "scenario.json",
2057            "--input",
2058            "replay.json",
2059        ])
2060        .unwrap();
2061        assert!(matches!(
2062            cli.command,
2063            Some(Commands::Certify {
2064                action: CertifyCommand::Replay { scenario, input },
2065            }) if scenario.as_os_str() == "scenario.json" && input.as_os_str() == "replay.json"
2066        ));
2067    }
2068
2069    #[test]
2070    fn certify_replay_diff_command_accepts_two_bundle_paths() {
2071        let cli = Cli::try_parse_from([
2072            "glass",
2073            "certify",
2074            "replay-diff",
2075            "--scenario",
2076            "scenario.json",
2077            "--before",
2078            "before.json",
2079            "--after",
2080            "after.json",
2081        ])
2082        .unwrap();
2083        assert!(matches!(
2084            cli.command,
2085            Some(Commands::Certify {
2086                action: CertifyCommand::ReplayDiff { scenario, before, after },
2087            }) if scenario.as_os_str() == "scenario.json"
2088                && before.as_os_str() == "before.json"
2089                && after.as_os_str() == "after.json"
2090        ));
2091    }
2092
2093    #[test]
2094    fn workflow_resume_command_accepts_checkpoint_and_inputs() {
2095        let cli = Cli::try_parse_from([
2096            "glass",
2097            "workflow-resume",
2098            "workflow.json",
2099            "checkpoint.json",
2100            "--inputs",
2101            "inputs.json",
2102        ])
2103        .unwrap();
2104        assert!(matches!(
2105            cli.command,
2106            Some(Commands::WorkflowResume {
2107                workflow,
2108                checkpoint,
2109                inputs: Some(inputs)
2110            }) if workflow.as_os_str() == "workflow.json"
2111                && checkpoint.as_os_str() == "checkpoint.json"
2112                && inputs.as_os_str() == "inputs.json"
2113        ));
2114    }
2115
2116    #[test]
2117    fn resolve_intent_command_accepts_optional_json_input() {
2118        let cli = Cli::try_parse_from(["glass", "resolve-intent", "intent.json"]).unwrap();
2119        assert!(matches!(
2120            cli.command,
2121            Some(Commands::ResolveIntent { input: Some(path) })
2122                if path.as_os_str() == "intent.json"
2123        ));
2124        assert!(Cli::try_parse_from(["glass", "resolve-intent"]).is_ok());
2125    }
2126
2127    #[test]
2128    fn execute_intent_command_accepts_optional_json_input() {
2129        let cli = Cli::try_parse_from(["glass", "execute-intent", "intent.json"]).unwrap();
2130        assert!(matches!(
2131            cli.command,
2132            Some(Commands::ExecuteIntent { input: Some(path) })
2133                if path.as_os_str() == "intent.json"
2134        ));
2135        assert!(Cli::try_parse_from(["glass", "execute-intent"]).is_ok());
2136    }
2137
2138    #[test]
2139    fn reliability_run_command_requires_fixture_url_and_sources() {
2140        let cli = Cli::try_parse_from([
2141            "glass",
2142            "certify",
2143            "run",
2144            "--scenario",
2145            "scenario.json",
2146            "--fixture",
2147            "fixture.json",
2148            "--url",
2149            "http://127.0.0.1:8000/fixture.html",
2150            "--workflow-root",
2151            "fixtures",
2152            "--inputs",
2153            "inputs.json",
2154            "--output",
2155            "evidence.json",
2156        ])
2157        .unwrap();
2158        assert!(matches!(
2159            cli.command,
2160            Some(Commands::Certify {
2161                action: CertifyCommand::Run {
2162                    scenario,
2163                    fixture,
2164                    url,
2165                    workflow_root,
2166                    inputs: Some(inputs),
2167                    output: Some(output),
2168                }
2169            }) if scenario.as_os_str() == "scenario.json"
2170                && fixture.as_os_str() == "fixture.json"
2171                && url == "http://127.0.0.1:8000/fixture.html"
2172                && workflow_root.as_os_str() == "fixtures"
2173                && inputs.as_os_str() == "inputs.json"
2174                && output.as_os_str() == "evidence.json"
2175        ));
2176    }
2177
2178    #[test]
2179    fn capabilities_command_is_explicitly_offline() {
2180        let cli = Cli::try_parse_from(["glass", "capabilities"]).unwrap();
2181        assert!(matches!(cli.command, Some(Commands::Capabilities)));
2182    }
2183
2184    #[test]
2185    fn experimental_extensions_require_an_explicit_global_opt_in() {
2186        let cli =
2187            Cli::try_parse_from(["glass", "--experimental-extensions", "capabilities"]).unwrap();
2188        assert!(cli.experimental_extensions);
2189    }
2190
2191    #[test]
2192    fn daemon_lifecycle_commands_accept_explicit_local_paths() {
2193        let cli = Cli::try_parse_from([
2194            "glass",
2195            "daemon",
2196            "start",
2197            "--socket",
2198            "/tmp/glass.sock",
2199            "--status",
2200            "/tmp/glass.json",
2201        ])
2202        .unwrap();
2203        assert!(matches!(
2204            cli.command,
2205            Some(Commands::Daemon {
2206                action: DaemonCommand::Start { socket: Some(socket), status: Some(status) }
2207            }) if socket.as_os_str() == "/tmp/glass.sock"
2208                && status.as_os_str() == "/tmp/glass.json"
2209        ));
2210    }
2211
2212    #[test]
2213    fn doctor_command_is_available_without_starting_a_browser() {
2214        let cli = Cli::try_parse_from(["glass", "doctor"]).unwrap();
2215        assert!(matches!(
2216            cli.command,
2217            Some(Commands::Doctor { json: false })
2218        ));
2219    }
2220
2221    #[test]
2222    fn knowledge_management_commands_parse_without_browser_startup() {
2223        let cli = Cli::try_parse_from(["glass", "knowledge", "list"]).unwrap();
2224        assert!(matches!(
2225            cli.command,
2226            Some(Commands::Knowledge {
2227                action: KnowledgeCommand::List
2228            })
2229        ));
2230        let cli = Cli::try_parse_from(["glass", "knowledge", "explain", "record-1"]).unwrap();
2231        assert!(matches!(
2232            cli.command,
2233            Some(Commands::Knowledge {
2234                action: KnowledgeCommand::Explain { .. }
2235            })
2236        ));
2237        let cli = Cli::try_parse_from([
2238            "glass",
2239            "--knowledge-store",
2240            "knowledge.json",
2241            "knowledge",
2242            "invalidate",
2243            "record-1",
2244            "stale",
2245        ])
2246        .unwrap();
2247        assert!(matches!(
2248            cli.command,
2249            Some(Commands::Knowledge {
2250                action: KnowledgeCommand::Invalidate { .. }
2251            })
2252        ));
2253    }
2254    #[test]
2255    fn task_compile_command_is_explicitly_offline() {
2256        use clap::CommandFactory;
2257
2258        let cli = Cli::try_parse_from([
2259            "glass",
2260            "task",
2261            "compile",
2262            "task.json",
2263            "web-ir.json",
2264            "--output",
2265            "plan.json",
2266            "--explain",
2267        ])
2268        .unwrap();
2269        assert!(Cli::command().find_subcommand("task").is_some());
2270        assert!(matches!(
2271            cli.command,
2272            Some(Commands::Task {
2273                action: TaskCommand::Compile {
2274                    input,
2275                    ir,
2276                    output: Some(output),
2277                    explain
2278                }
2279            }) if input.as_os_str() == "task.json"
2280                && ir.as_os_str() == "web-ir.json"
2281                && output.as_os_str() == "plan.json"
2282                && explain
2283        ));
2284    }
2285
2286    #[test]
2287    fn task_execute_help_advertises_supported_families() {
2288        use clap::CommandFactory;
2289
2290        let mut command = Cli::command();
2291        let execute = command
2292            .find_subcommand_mut("task")
2293            .and_then(|task| task.find_subcommand_mut("execute"))
2294            .expect("task execute command should be present");
2295        let help = execute.render_help().to_string();
2296        let normalized = help.split_whitespace().collect::<Vec<_>>().join(" ");
2297
2298        assert!(normalized.contains(
2299            "form, navigation, dialog, pagination, extraction, or field-read Task Protocol families"
2300        ));
2301    }
2302    #[test]
2303    fn task_validate_command_is_explicitly_offline() {
2304        let cli = Cli::try_parse_from(["glass", "task", "validate", "task.json"]).unwrap();
2305        assert!(matches!(
2306            cli.command,
2307            Some(Commands::Task {
2308                action: TaskCommand::Validate { input }
2309            }) if input.as_os_str() == "task.json"
2310        ));
2311    }
2312    #[test]
2313    fn ir_commands_are_explicitly_offline() {
2314        let cli = Cli::try_parse_from(["glass", "ir", "inspect", "draft.json"]).unwrap();
2315        assert!(matches!(
2316            cli.command,
2317            Some(Commands::Ir {
2318                action: IrCommand::Inspect { input }
2319            }) if input.as_os_str() == "draft.json"
2320        ));
2321
2322        let cli =
2323            Cli::try_parse_from(["glass", "ir", "diff", "before.json", "after.json"]).unwrap();
2324        assert!(matches!(
2325            cli.command,
2326            Some(Commands::Ir {
2327                action: IrCommand::Diff {
2328                    before,
2329                    after,
2330                    summary
2331                }
2332            }) if before.as_os_str() == "before.json"
2333                && after.as_os_str() == "after.json"
2334                && !summary
2335        ));
2336
2337        let cli = Cli::try_parse_from([
2338            "glass",
2339            "ir",
2340            "diff",
2341            "before.json",
2342            "after.json",
2343            "--summary",
2344        ])
2345        .unwrap();
2346        assert!(matches!(
2347            cli.command,
2348            Some(Commands::Ir {
2349                action: IrCommand::Diff {
2350                    before,
2351                    after,
2352                    summary
2353                }
2354            }) if before.as_os_str() == "before.json"
2355                && after.as_os_str() == "after.json"
2356                && summary
2357        ));
2358
2359        let cli = Cli::try_parse_from([
2360            "glass",
2361            "ir",
2362            "continuity",
2363            "before.json",
2364            "after.json",
2365            "field-1",
2366        ])
2367        .unwrap();
2368        assert!(matches!(
2369            cli.command,
2370            Some(Commands::Ir {
2371                action: IrCommand::Continuity {
2372                    before,
2373                    after,
2374                    entity_id
2375                }
2376            }) if before.as_os_str() == "before.json"
2377                && after.as_os_str() == "after.json"
2378                && entity_id == "field-1"
2379        ));
2380
2381        let cli = Cli::try_parse_from(["glass", "ir", "validate", "draft.json"]).unwrap();
2382        assert!(matches!(
2383            cli.command,
2384            Some(Commands::Ir {
2385                action: IrCommand::Validate { input }
2386            }) if input.as_os_str() == "draft.json"
2387        ));
2388
2389        let cli = Cli::try_parse_from(["glass", "ir", "canonical", "draft.json"]).unwrap();
2390        assert!(matches!(
2391            cli.command,
2392            Some(Commands::Ir {
2393                action: IrCommand::Canonical { input }
2394            }) if input.as_os_str() == "draft.json"
2395        ));
2396    }
2397    #[test]
2398    fn browser_first_and_persistent_session_commands_parse() {
2399        let cli = Cli::try_parse_from(["glass", "browser", "tui"]).unwrap();
2400        assert!(matches!(
2401            cli.command,
2402            Some(Commands::Browser {
2403                action: Some(BrowserCommand::Tui)
2404            })
2405        ));
2406
2407        let cli = Cli::try_parse_from(["glass", "--session", "work", "observe"]).unwrap();
2408        assert_eq!(cli.session.as_deref(), Some("work"));
2409        assert!(matches!(cli.command, Some(Commands::Observe { .. })));
2410
2411        let cli = Cli::try_parse_from(["glass", "session", "status", "work"]).unwrap();
2412        assert!(matches!(
2413            cli.command,
2414            Some(Commands::Session {
2415                action: SessionCommand::Status { name }
2416            }) if name == "work"
2417        ));
2418    }
2419}