1use 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#[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 #[arg(long, global = true)]
32 pub yolo: bool,
33
34 #[arg(long, global = true, value_enum, default_value_t = PolicyPreset::Development)]
36 pub policy: PolicyPreset,
37
38 #[arg(long = "policy-allow", global = true, value_enum)]
40 pub policy_allow: Vec<PolicyCapability>,
41
42 #[arg(long = "policy-confirm", global = true, value_enum)]
44 pub policy_confirm: Vec<PolicyCapability>,
45
46 #[arg(long = "policy-confirm-once", global = true, value_enum)]
48 pub policy_confirm_once: Vec<PolicyCapability>,
49
50 #[arg(long, global = true)]
52 pub experimental_extensions: bool,
53
54 #[arg(long = "policy-allow-host", global = true)]
56 pub policy_allow_host: Vec<String>,
57
58 #[arg(long = "policy-deny-host", global = true)]
60 pub policy_deny_host: Vec<String>,
61
62 #[arg(long, global = true, default_value = "default")]
64 pub profile: String,
65
66 #[arg(long, global = true)]
68 pub incognito: bool,
69
70 #[arg(long, global = true)]
73 pub attach: bool,
74
75 #[arg(long, global = true, value_name = "NAME")]
78 pub session: Option<String>,
79
80 #[arg(long = "target-id", global = true)]
83 pub target_id: Option<String>,
84
85 #[arg(long = "frame-id", global = true)]
87 pub frame_id: Option<String>,
88
89 #[arg(long, global = true, default_value_t = 9222)]
91 pub port: u16,
92
93 #[arg(long, global = true)]
95 pub headed: bool,
96 #[arg(long, global = true, value_name = "WIDTHxHEIGHT")]
98 pub viewport: Option<String>,
99
100 #[arg(long, global = true, value_enum, default_value_t = InteractionMode::Human)]
102 pub interaction: InteractionMode,
103
104 #[arg(long, global = true)]
106 pub audit: bool,
107
108 #[arg(long, global = true)]
110 pub trace_on_error: bool,
111
112 #[arg(long = "chrome-path", alias = "chrome", global = true)]
114 pub chrome_path: Option<PathBuf>,
115
116 #[arg(long)]
118 pub mcp: bool,
119
120 #[arg(long = "tui-layout", global = true, value_enum, default_value_t = TuiLayout::Auto)]
122 pub tui_layout: TuiLayout,
123
124 #[arg(long = "tui-transport", global = true, value_enum, default_value_t = TuiTransport::Auto)]
126 pub tui_transport: TuiTransport,
127
128 #[arg(long = "tui-graphics", global = true, value_enum, default_value_t = TuiGraphics::Auto)]
130 pub tui_graphics: TuiGraphics,
131
132 #[arg(long = "tui-rtt-ms", global = true)]
134 pub tui_rtt_ms: Option<f64>,
135
136 #[arg(long = "tui-throughput-mbps", global = true)]
138 pub tui_throughput_mbps: Option<f64>,
139
140 #[arg(long = "tui-live", global = true, value_enum, default_value_t = TuiLiveMode::Off)]
142 pub tui_live: TuiLiveMode,
143
144 #[arg(long = "tui-live-backend", global = true, value_enum, default_value_t = TuiLiveBackend::Auto)]
146 pub tui_live_backend: TuiLiveBackend,
147
148 #[arg(long = "tui-live-quality", global = true, value_enum, default_value_t = TuiLiveQuality::Balanced)]
150 pub tui_live_quality: TuiLiveQuality,
151
152 #[arg(long = "tui-live-fit", global = true, value_enum, default_value_t = TuiLiveFit::Contain)]
154 pub tui_live_fit: TuiLiveFit,
155
156 #[arg(long, global = true)]
158 pub knowledge_store: Option<PathBuf>,
159
160 #[arg(long, global = true, value_enum, default_value_t = ResponseMode::Minimal)]
162 pub response_mode: ResponseMode,
163
164 #[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#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum, Default)]
181pub enum TuiLayout {
182 #[default]
184 Auto,
185 Desktop,
187 Mobile,
189 Compact,
191}
192
193#[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#[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 #[default]
221 Off,
222 Auto,
224 On,
226}
227
228#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum, Default)]
229pub enum TuiLiveBackend {
230 #[default]
232 Auto,
233 Herdr,
235 Kitty,
237 Ansi,
239}
240
241#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum, Default)]
242pub enum TuiLiveQuality {
243 Data,
245 #[default]
247 Balanced,
248 Smooth,
250}
251
252#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum, Default)]
253pub enum TuiLiveFit {
254 #[default]
256 Contain,
257 Cover,
259 Actual,
261}
262
263#[derive(Debug, Subcommand)]
264pub enum Commands {
265 Update {
267 #[arg(long)]
269 dry_run: bool,
270 #[arg(long)]
272 version: Option<String>,
273 #[arg(long)]
275 force: bool,
276 #[arg(long)]
278 registry: Option<String>,
279 },
280
281 InstallChromium {
283 #[arg(long)]
285 update: bool,
286 },
287
288 Certify {
290 #[command(subcommand)]
291 action: CertifyCommand,
292 },
293
294 Workspace {
296 #[command(subcommand)]
297 action: WorkspaceCommand,
298 },
299 Project {
301 #[command(subcommand)]
302 action: ProjectCommand,
303 },
304 Agent {
306 #[command(subcommand)]
307 action: AgentCommand,
308 },
309 Harness {
311 #[command(subcommand)]
312 action: HarnessCommand,
313 },
314 Memory {
316 #[command(subcommand)]
317 action: MemoryCommand,
318 },
319 Surfaces {
321 #[command(subcommand)]
322 action: SurfaceCommand,
323 },
324 Backend {
326 #[command(subcommand)]
327 action: BackendCommand,
328 },
329
330 Daemon {
332 #[command(subcommand)]
333 action: DaemonCommand,
334 },
335 Replay {
337 #[command(subcommand)]
338 action: ReplayCommand,
339 },
340 Capabilities,
342
343 Doctor {
345 #[arg(long)]
347 json: bool,
348 },
349
350 McpConfig {
352 #[arg(long, value_enum, default_value_t = McpClient::Generic)]
353 client: McpClient,
354 #[arg(long)]
356 print: bool,
357 },
358
359 Profiles {
361 #[command(subcommand)]
362 action: Option<ProfileCommand>,
363 },
364
365 Knowledge {
367 #[command(subcommand)]
368 action: KnowledgeCommand,
369 },
370
371 Result {
373 #[command(subcommand)]
374 action: ResultCommand,
375 },
376
377 DeleteProfile { name: String },
379
380 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 {
391 target: String,
392 #[arg(long)]
393 expected_revision: Option<u64>,
394 },
395
396 Preflight {
398 target: String,
399 #[arg(long, value_enum, default_value_t = PreflightAction::Click)]
400 action: PreflightAction,
401 },
402
403 ClickAt { x: f64, y: f64 },
405
406 ClickExpectPopup {
408 target: String,
409 #[arg(long)]
410 expected_revision: Option<u64>,
411 },
412
413 DoubleClick {
415 target: String,
416 #[arg(long)]
417 expected_revision: Option<u64>,
418 },
419
420 Hover { target: String },
422
423 Drag {
425 source: String,
426 destination: String,
427 #[arg(long)]
428 expected_revision: Option<u64>,
429 },
430
431 Type {
433 text: String,
434 #[arg(long)]
435 target: Option<String>,
436 #[arg(long)]
437 expected_revision: Option<u64>,
438 },
439
440 Key {
442 key: String,
443 #[arg(long)]
444 expected_revision: Option<u64>,
445 },
446
447 KeyDown {
449 key: String,
450 #[arg(long)]
451 expected_revision: Option<u64>,
452 },
453
454 KeyUp {
456 key: String,
457 #[arg(long)]
458 expected_revision: Option<u64>,
459 },
460
461 Shortcut {
463 shortcut: String,
464 #[arg(long)]
465 expected_revision: Option<u64>,
466 },
467
468 Clear {
470 target: String,
471 #[arg(long)]
472 expected_revision: Option<u64>,
473 },
474
475 Check {
477 target: String,
478 #[arg(long)]
479 expected_revision: Option<u64>,
480 },
481
482 Uncheck {
484 target: String,
485 #[arg(long)]
486 expected_revision: Option<u64>,
487 },
488
489 Select {
491 target: String,
492 value: String,
493 #[arg(long)]
494 expected_revision: Option<u64>,
495 },
496
497 Upload {
499 target: String,
500 #[arg(required = true)]
501 files: Vec<PathBuf>,
502 #[arg(long)]
503 expected_revision: Option<u64>,
504 },
505
506 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 Text,
526
527 Dom,
529
530 Observe {
532 #[arg(long)]
534 deep_dom: bool,
535 #[arg(long)]
537 screenshot: bool,
538 #[arg(long)]
540 form_values: bool,
541 #[arg(long = "level", alias = "semantic-level", value_parser = parse_semantic_level)]
543 semantic_level: Option<String>,
544 #[arg(long, requires = "semantic_level")]
546 region: Option<String>,
547 },
548
549 InspectPage,
551 SmokeSites {
553 input: PathBuf,
555 #[arg(long)]
557 stop_on_error: bool,
558 },
559
560 FindTarget { input: PathBuf },
562
563 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 ExtractStructured { input: PathBuf },
574
575 RecoverRun { execution_id: String },
577
578 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 {
590 condition: String,
591 #[arg(long, default_value_t = 10_000)]
592 timeout_ms: u64,
593 },
594
595 Diagnostics {
597 #[arg(long, default_value_t = 1_000)]
598 duration_ms: u64,
599 },
600
601 AcceptDialog,
603
604 DismissDialog,
606
607 DismissConsent,
609
610 Download {
612 destination: PathBuf,
613 #[arg(long, default_value_t = 30_000)]
614 timeout_ms: u64,
615 },
616
617 Targets,
619
620 ArchiveTargets {
622 #[arg(short, long)]
624 output: Option<PathBuf>,
625 },
626
627 NewTarget { url: String },
629
630 SelectTarget { id: String },
632
633 CloseTarget { id: String },
635
636 Frames,
638
639 SelectFrame { id: String },
641
642 Evaluate { expression: String },
644
645 Cookies,
647
648 ExportCookies { output: PathBuf },
650
651 ImportCookies { input: PathBuf },
653
654 Pdf {
656 #[arg(short, long, default_value = "page.pdf")]
657 output: String,
658 #[arg(long)]
659 background: bool,
660 },
661
662 FillForm {
664 #[arg(long)]
666 fields: String,
667 #[arg(long)]
669 expected_revision: Option<u64>,
670 },
671
672 Batch {
674 input: Option<PathBuf>,
676 #[arg(long)]
677 atomic: bool,
678 #[arg(long, value_enum, default_value_t = BatchMode::Unguarded)]
680 mode: BatchMode,
681 #[arg(long)]
683 expected_revision: Option<u64>,
684 },
685
686 #[command(subcommand_precedence_over_arg = true)]
687 Workflow {
688 #[command(subcommand)]
690 action: Option<WorkflowAuthoringCommand>,
691 input: Option<PathBuf>,
693 },
694
695 Task {
697 #[command(subcommand)]
698 action: TaskCommand,
699 },
700
701 Ir {
703 #[command(subcommand)]
704 action: IrCommand,
705 },
706
707 WorkflowResume {
709 workflow: PathBuf,
711 checkpoint: PathBuf,
713 #[arg(long)]
715 inputs: Option<PathBuf>,
716 },
717
718 ResolveIntent {
720 input: Option<PathBuf>,
722 },
723
724 ExecuteIntent {
726 input: Option<PathBuf>,
728 },
729
730 Verify {
732 predicate: String,
734 #[arg(long, default_value_t = 10_000)]
735 timeout_ms: u64,
736 },
737
738 ReconcileRefs {
740 #[arg(long)]
741 from_revision: u64,
742 #[arg(long = "hint")]
744 hints: Vec<String>,
745 #[arg(long)]
747 scope: Option<String>,
748 #[arg(required = true)]
749 refs: Vec<String>,
750 },
751
752 ObserveDelta,
754
755 Checkpoint {
757 #[command(subcommand)]
758 action: CheckpointCommand,
759 },
760
761 Snapshot {
763 #[command(subcommand)]
764 action: SnapshotCommand,
765 },
766
767 ClipboardRead,
769
770 ClipboardWrite { text: String },
772
773 Browser {
778 #[command(subcommand)]
779 action: Option<BrowserCommand>,
780 },
781
782 Session {
784 #[command(subcommand)]
785 action: SessionCommand,
786 },
787
788 Help { topic: Option<String> },
790
791 Tui,
793}
794
795#[derive(Debug, Subcommand)]
796pub enum BrowserCommand {
797 Tui,
799}
800
801#[derive(Debug, Subcommand)]
802pub enum SessionCommand {
803 Start {
805 #[arg(default_value = "default")]
806 name: String,
807 },
808 Status {
810 #[arg(default_value = "default")]
811 name: String,
812 },
813 Stop {
815 #[arg(default_value = "default")]
816 name: String,
817 },
818 Open {
820 #[arg(default_value = "default")]
821 name: String,
822 },
823 #[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,
852 Show { record_id: String },
854 Explain { record_id: String },
856 Stats,
858 Export { output: Option<PathBuf> },
860 Import { input: PathBuf },
862 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 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 Inspect {
889 #[arg(long, default_value = ".")]
890 root: PathBuf,
891 },
892 Files {
894 #[arg(long, default_value = ".")]
895 root: PathBuf,
896 },
897 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 {
907 path: String,
908 #[arg(long, default_value = ".")]
909 root: PathBuf,
910 },
911 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 Mkdir {
923 path: String,
924 #[arg(long, default_value = ".")]
925 root: PathBuf,
926 },
927 Rename {
929 from: String,
930 to: String,
931 #[arg(long, default_value = ".")]
932 root: PathBuf,
933 },
934 Delete {
936 path: String,
937 #[arg(long)]
938 yes: bool,
939 #[arg(long, default_value = ".")]
940 root: PathBuf,
941 },
942 Diagnostics {
944 path: String,
945 #[arg(long, default_value = ".")]
946 root: PathBuf,
947 },
948 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 Test {
960 #[arg(long, default_value = ".")]
961 root: PathBuf,
962 },
963 Lint {
965 #[arg(long, default_value = ".")]
966 root: PathBuf,
967 },
968 Process {
970 #[arg(long, default_value = ".")]
971 root: PathBuf,
972 #[command(subcommand)]
973 action: ProjectProcessCommand,
974 },
975 Diff {
977 #[arg(long, default_value = ".")]
978 root: PathBuf,
979 },
980 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 Graph {
999 #[arg(long, default_value = ".")]
1000 root: PathBuf,
1001 #[command(subcommand)]
1002 action: ProjectGraphCommand,
1003 },
1004 Breakpoint {
1006 kind: String,
1007 entity: String,
1008 before: PathBuf,
1009 after: PathBuf,
1010 #[arg(long, default_value = ".")]
1011 root: PathBuf,
1012 },
1013 Timeline {
1015 #[arg(long, default_value = ".")]
1016 root: PathBuf,
1017 },
1018 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 Neovim {
1029 #[arg(long, default_value = ".")]
1030 root: PathBuf,
1031 #[command(subcommand)]
1032 action: NeovimCommand,
1033 },
1034 Experiment {
1036 #[arg(long, default_value = ".")]
1037 root: PathBuf,
1038 #[command(subcommand)]
1039 action: ExperimentCommand,
1040 },
1041 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 Doctor,
1117 Setup {
1119 #[arg(long)]
1121 sdk_entry: Option<PathBuf>,
1122 #[arg(long, requires = "sdk_entry")]
1124 agent_dir: Option<PathBuf>,
1125 #[arg(long)]
1127 update: bool,
1128 #[arg(long)]
1130 login: bool,
1131 },
1132 Status,
1134 Delegate {
1136 harness: String,
1138 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 #[arg(long)]
1148 allow_mutation: bool,
1149 #[arg(long)]
1151 yes: bool,
1152 },
1153 #[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 #[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 Hello {
1177 #[arg(long, default_value = ".")]
1178 root: PathBuf,
1179 #[arg(long, value_enum, default_value_t = AgentHarness::Local)]
1180 harness: AgentHarness,
1181 },
1182 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 {
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 FollowUp {
1200 text: String,
1201 #[arg(long, default_value = ".")]
1202 root: PathBuf,
1203 },
1204 Models {
1206 #[arg(long, default_value = ".")]
1207 root: PathBuf,
1208 },
1209 SetModel {
1211 provider: String,
1212 model_id: String,
1213 #[arg(long, default_value = ".")]
1214 root: PathBuf,
1215 },
1216 Thinking {
1218 level: String,
1219 #[arg(long, default_value = ".")]
1220 root: PathBuf,
1221 },
1222 Abort {
1224 #[arg(long, default_value = ".")]
1225 root: PathBuf,
1226 },
1227 NewSession {
1229 #[arg(long, default_value = ".")]
1230 root: PathBuf,
1231 },
1232}
1233
1234#[derive(Debug, Subcommand)]
1235pub enum HarnessCommand {
1236 List,
1238 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 Prune,
1275 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 {
1322 result_id: String,
1323 #[arg(long)]
1324 section: Option<String>,
1325 },
1326 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 {
1343 input: PathBuf,
1344 #[arg(short, long)]
1345 output: Option<PathBuf>,
1346 },
1347 Format {
1349 input: PathBuf,
1350 #[arg(short, long)]
1351 output: Option<PathBuf>,
1352 },
1353 Preview { input: PathBuf },
1355 Diff { before: PathBuf, after: PathBuf },
1357 Record {
1359 #[arg(long)]
1361 input: Option<PathBuf>,
1362 #[arg(short, long)]
1363 output: Option<PathBuf>,
1364 },
1365 Validate { input: PathBuf },
1367 Lint {
1369 input: PathBuf,
1370 #[arg(long)]
1371 warnings_as_errors: bool,
1372 },
1373 Templates {
1375 name: Option<String>,
1377 #[arg(short, long)]
1378 output: Option<PathBuf>,
1379 },
1380 Init {
1382 name: String,
1385 #[arg(short, long)]
1386 output: Option<PathBuf>,
1387 },
1388}
1389
1390#[derive(Debug, Subcommand)]
1391pub enum TaskCommand {
1392 Validate {
1394 input: PathBuf,
1396 },
1397 Compile {
1399 input: PathBuf,
1401 ir: PathBuf,
1403 #[arg(short, long)]
1405 output: Option<PathBuf>,
1406 #[arg(long)]
1408 explain: bool,
1409 },
1410 Execute {
1412 input: PathBuf,
1415 #[arg(long)]
1417 expected_revision: u64,
1418 #[arg(long)]
1420 confirm: bool,
1421 },
1422}
1423
1424#[derive(Debug, Subcommand)]
1425pub enum IrCommand {
1426 Validate { input: PathBuf },
1428 Inspect { input: PathBuf },
1430 Diff {
1432 before: PathBuf,
1433 after: PathBuf,
1434 #[arg(long)]
1436 summary: bool,
1437 },
1438 Continuity {
1440 before: PathBuf,
1441 after: PathBuf,
1442 entity_id: String,
1443 },
1444 Canonical { input: PathBuf },
1446}
1447
1448#[derive(Debug, Subcommand)]
1449pub enum DaemonCommand {
1450 Start {
1452 #[arg(long)]
1453 socket: Option<PathBuf>,
1454 #[arg(long)]
1455 status: Option<PathBuf>,
1456 },
1457 Status {
1459 #[arg(long)]
1460 socket: Option<PathBuf>,
1461 #[arg(long)]
1462 status: Option<PathBuf>,
1463 },
1464 Stop {
1466 #[arg(long)]
1467 socket: Option<PathBuf>,
1468 #[arg(long)]
1469 status: Option<PathBuf>,
1470 },
1471 Doctor {
1473 #[arg(long)]
1474 socket: Option<PathBuf>,
1475 #[arg(long)]
1476 status: Option<PathBuf>,
1477 },
1478 Logs {
1480 #[arg(long)]
1481 status: Option<PathBuf>,
1482 },
1483 AcknowledgeRecovery {
1485 #[arg(long)]
1486 status: Option<PathBuf>,
1487 #[arg(long = "request-id", required = true)]
1489 request_ids: Vec<String>,
1490 },
1491 #[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 {
1505 #[arg(long)]
1507 scenario: PathBuf,
1508 #[arg(long)]
1510 fixture: PathBuf,
1511 #[arg(long)]
1513 url: String,
1514 #[arg(long, default_value = ".")]
1516 workflow_root: PathBuf,
1517 #[arg(long)]
1519 inputs: Option<PathBuf>,
1520 #[arg(short, long)]
1522 output: Option<PathBuf>,
1523 },
1524 Plan {
1526 #[arg(long)]
1528 scenario: PathBuf,
1529 #[arg(long)]
1531 fixture: PathBuf,
1532 },
1533 Release {
1535 #[arg(long)]
1536 version: String,
1537 #[arg(long)]
1539 scenarios: PathBuf,
1540 #[arg(long)]
1542 observations: PathBuf,
1543 #[arg(long)]
1545 replays: Option<PathBuf>,
1546 },
1547 Replay {
1549 #[arg(long)]
1551 scenario: PathBuf,
1552 #[arg(long)]
1554 input: PathBuf,
1555 },
1556 ReplayDiff {
1558 #[arg(long)]
1560 scenario: PathBuf,
1561 #[arg(long)]
1563 before: PathBuf,
1564 #[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}