Skip to main content

calcit_cli/
cli_args.rs

1use argh::FromArgs;
2
3pub const CALCIT_VERSION: &str = env!("CARGO_PKG_VERSION");
4
5#[derive(FromArgs, PartialEq, Debug, Clone)]
6/// Top-level command.
7pub struct ToplevelCalcit {
8  #[argh(subcommand)]
9  pub subcommand: Option<CalcitCommand>,
10  /// enable watch mode for direct run mode (default behavior is run once)
11  #[argh(switch, short = 'w')]
12  pub watch: bool,
13  /// check-only mode: validate without execution or codegen
14  #[argh(switch)]
15  pub check_only: bool,
16  /// reuse a successful entry preprocessing result in check-only mode
17  #[argh(switch)]
18  pub incremental: bool,
19  /// continue check-only validation across independent definitions
20  #[argh(switch)]
21  pub keep_going: bool,
22  /// with --check-only, also check every definition in project namespaces (not only entry-reachable ones); implies --keep-going
23  #[argh(switch)]
24  pub all_defs: bool,
25  /// with --check-only, check every definition in this public namespace for the active entry target; repeat for shared and target-specific namespaces
26  #[argh(option)]
27  pub ns: Vec<String>,
28  /// with --check-only, enforce portable Static Core rules across Browser JS and WASI targets
29  #[argh(switch, long = "static-core")]
30  pub static_core: bool,
31  /// with --check-only --ns, admit selected namespaces loaded from dependencies or calcit.core
32  #[argh(switch)]
33  pub deps: bool,
34  /// with --check-only (--ns, --keep-going, or --all-defs), emit compact summary output without passed definition rows
35  #[argh(switch, long = "summary-only")]
36  pub summary_only: bool,
37  /// check-only report format: human, edn, or json
38  #[argh(option, default = "String::from(\"human\")")]
39  pub format: String,
40  /// disable stack trace for errors
41  #[argh(switch)]
42  pub disable_stack: bool,
43  /// skip arity check in js codegen
44  #[argh(switch)]
45  pub skip_arity_check: bool,
46  /// warn on dynamic method calls that cannot be monomorphized
47  #[argh(switch)]
48  pub warn_dyn_method: bool,
49  /// keep strict diagnostics but skip the default assertion-proof audit
50  #[argh(switch)]
51  pub no_proof_audit: bool,
52  /// treat downgraded runtime predicate warnings (W_RUNTIME_TYPE_PREDICATE on `(:open :reflect|:decode)` boundaries) as blocking errors
53  #[argh(switch, long = "deny-migration-warnings")]
54  pub deny_migration_warnings: bool,
55  /// print FFI dylib calls and callbacks for debugging native crashes
56  #[argh(switch)]
57  pub trace_ffi: bool,
58  /// entry file path, defaults to "js-out/"
59  #[argh(option, default = "String::from(\"js-out/\")")]
60  pub emit_path: String,
61  /// specify `init_fn` which is main function
62  #[argh(option)]
63  pub init_fn: Option<String>,
64  /// specify `reload_fn` which is called after hot reload
65  #[argh(option)]
66  pub reload_fn: Option<String>,
67  /// select an entry; defaults to "default"
68  #[argh(option)]
69  pub entry: Option<String>,
70  #[argh(switch)]
71  /// force reloading libs data during code reload
72  pub reload_libs: bool,
73  #[argh(option)]
74  /// specify a path to watch assets changes
75  pub watch_dir: Option<String>,
76  /// input source file, defaults to "calcit.cirru"; retired compact.cirru inputs receive migration guidance
77  #[argh(positional, default = "String::from(calcit_core::DEFAULT_SNAPSHOT_FILE)")]
78  pub input: String,
79  /// print version only
80  #[argh(switch, short = 'v')]
81  pub version: bool,
82  /// print progress details and timing while loading and compiling
83  #[argh(switch)]
84  pub verbose: bool,
85  /// emit machine-readable macro expansion metrics to stderr on exit
86  #[argh(switch)]
87  pub macro_metrics: bool,
88  /// emit machine-readable native async FFI metrics to stderr on exit
89  #[argh(switch)]
90  pub ffi_metrics: bool,
91  /// maximum seconds for one JS/IR compilation (0 disables the limit)
92  #[argh(option, default = "60")]
93  pub timeout: u64,
94  /// show full tips output in all commands
95  #[argh(switch)]
96  pub tips: bool,
97  /// control tips verbosity: minimal (default), full, none
98  #[argh(option)]
99  pub tips_level: Option<String>,
100  /// cursor feedback after mutating edit/tree commands: none, summary (default), focus
101  #[argh(option, default = "String::from(\"summary\")")]
102  pub cursor_after: String,
103}
104
105#[derive(FromArgs, PartialEq, Debug, Clone)]
106#[argh(subcommand)]
107pub enum CalcitCommand {
108  /// emit JavaScript rather than interpreting
109  EmitJs(EmitJsCommand),
110  /// emit a browser or embedded WebAssembly core module
111  EmitWasm(EmitWasmCommand),
112  /// emit a WebAssembly command module for a WASI host
113  EmitWasi(EmitWasiCommand),
114  /// diagnostic: emit compiler IR as Cirru EDN to program-ir.cirru
115  EmitIr(EmitIrCommand),
116  /// evaluate snippet
117  Eval(EvalCommand),
118  /// discover and run definition-attached tests
119  Test(TestCommand),
120  /// preview or apply compiler-guided source migrations
121  Fix(FixCommand),
122  /// analyze code structure, type-debt views, and helpers (call-graph, program-diff, weak-types, check-examples, verify)
123  Analyze(AnalyzeCommand),
124  /// query project information (namespaces, definitions, configs)
125  Query(QueryCommand),
126  /// documentation tools for guidebook, installed module docs, and local markdown docs
127  Docs(DocsCommand),
128  /// Cirru syntax tools (parse, format)
129  Cirru(CirruCommand),
130  /// coarse-grained code editing (namespaces, definitions, metadata); for internal expression changes, use `tree` instead
131  Edit(EditCommand),
132  /// fine-grained tree operations (view and modify AST nodes within definitions)
133  Tree(TreeCommand),
134  /// maintain a persistent virtual cursor for tree navigation and editing
135  Cursor(CursorCommand),
136  /// manage project configuration (show, set, modules, add-module, rm-module)
137  Config(ConfigCommand),
138  /// inspect and export typed FFI interface contracts
139  Ffi(FfiCommand),
140}
141
142#[derive(FromArgs, PartialEq, Debug, Clone)]
143#[argh(
144  subcommand,
145  name = "fix",
146  note = "Project upgrades follow one ordered sequence: run `calcit docs agents 项目升级入口` (embedded in this CLI), then `calcit docs read upgrade.md '当前升级闭环'` from a guidebook checked out at the same release tag."
147)]
148/// preview or apply compiler-guided migrations or reviewed structural source rewrites
149pub struct FixCommand {
150  /// write applicable fixes atomically after validation
151  #[argh(switch)]
152  pub apply: bool,
153  /// explicitly request preview mode; preview is also the default
154  #[argh(switch, long = "dry-run")]
155  pub dry_run: bool,
156  /// include definition tests and examples in supported migration rules
157  #[argh(switch, long = "include-attached")]
158  pub include_attached: bool,
159  /// output format: human (default), edn (primary structured data), or json (interoperability)
160  #[argh(option, default = "String::from(\"human\")")]
161  pub format: String,
162  /// restrict fixes to one exact project namespace
163  #[argh(option)]
164  pub ns: Option<String>,
165  /// restrict fixes to one definition; requires --ns
166  #[argh(option, long = "def")]
167  pub definition: Option<String>,
168  /// restrict fixes to one stable rule ID
169  #[argh(option)]
170  pub rule: Option<String>,
171  /// select surface-latest-v1, surface-latest-v2, core-api-0.28-v1, or core-api-0.29-v1 migration rules
172  #[argh(option)]
173  pub preset: Option<String>,
174  /// match one exact Cirru source pattern with ?name subtree variables (reviewed syntax only)
175  #[argh(option)]
176  pub pattern: Option<String>,
177  /// replacement Cirru template for --pattern; does not prove semantic equivalence
178  #[argh(option, long = "replace")]
179  pub replacement: Option<String>,
180  /// compose a project workflow; currently supports strict
181  #[argh(option)]
182  pub workflow: Option<String>,
183  /// verify a selected project workflow without mutating the snapshot
184  #[argh(switch)]
185  pub verify: bool,
186  /// show strict verification status and failure locations without the full migration report
187  #[argh(switch, long = "summary-only")]
188  pub summary_only: bool,
189  /// replacement name required by rename-definition-v1 and rename-local-v1
190  #[argh(option, long = "to")]
191  pub replacement_name: Option<String>,
192  /// path of the local binding name for rename-local-v1, such as 3.1.0.0
193  #[argh(option)]
194  pub at: Option<String>,
195  /// require the snapshot content to match this revision before applying
196  #[argh(option, long = "expect-revision")]
197  pub expect_revision: Option<String>,
198  /// allow applying while the Git working tree contains changes
199  #[argh(switch, long = "allow-dirty")]
200  pub allow_dirty: bool,
201  /// allow applying when the project is not inside a Git worktree
202  #[argh(switch, long = "allow-no-vcs")]
203  pub allow_no_vcs: bool,
204}
205
206#[derive(FromArgs, PartialEq, Debug, Clone)]
207#[argh(subcommand, name = "ffi")]
208/// inspect and export typed FFI interface contracts
209pub struct FfiCommand {
210  #[argh(subcommand)]
211  pub subcommand: FfiSubcommand,
212}
213
214#[derive(FromArgs, PartialEq, Debug, Clone)]
215#[argh(subcommand)]
216pub enum FfiSubcommand {
217  /// export versioned Interface IR from local definitions with typed schemas and FFI lowering metadata
218  Export(FfiExportCommand),
219}
220
221#[derive(FromArgs, PartialEq, Debug, Clone)]
222#[argh(subcommand, name = "export")]
223/// export versioned Interface IR from local definitions with typed schemas and FFI lowering metadata
224pub struct FfiExportCommand {
225  /// select native raw bindings or the directional component surface
226  #[argh(option, default = "String::from(\"native\")")]
227  pub boundary: String,
228  /// output format: human, edn, or json; component defaults to edn
229  #[argh(option)]
230  pub format: Option<String>,
231  /// restrict export to one exact local namespace
232  #[argh(option)]
233  pub ns: Option<String>,
234}
235
236/// discover and run definition-attached tests.
237///
238/// Assert expected results explicitly; a returned false, nil or Unit does not
239/// fail a test.
240#[derive(FromArgs, PartialEq, Debug, Clone)]
241#[argh(subcommand, name = "test")]
242pub struct TestCommand {
243  /// optional namespace or namespace/definition scope
244  #[argh(positional)]
245  pub target: Option<String>,
246  /// run only a test with this exact name
247  #[argh(option)]
248  pub name: Option<String>,
249  /// run tests tagged with this tag; repeat to require multiple tags
250  #[argh(option)]
251  pub tag: Vec<String>,
252  /// skip tests tagged with this tag; repeat to exclude any matching tag
253  #[argh(option)]
254  pub exclude_tag: Vec<String>,
255  /// select tests that statically depend on this namespace/definition; repeat for multiple changed definitions
256  #[argh(option)]
257  pub affected: Vec<String>,
258  /// list selected tests without running them
259  #[argh(switch)]
260  pub list: bool,
261  /// stop after the first failed test
262  #[argh(switch)]
263  pub fail_fast: bool,
264  /// fail when the requested scope and filters select no tests
265  #[argh(switch)]
266  pub require_match: bool,
267  /// omit individual test rows; useful for large CI and agent runs
268  #[argh(switch)]
269  pub summary_only: bool,
270  /// output format: human (default), edn, or json
271  #[argh(option, default = "String::from(\"human\")")]
272  pub format: String,
273}
274
275/// emit JavaScript rather than interpreting
276#[derive(FromArgs, PartialEq, Debug, Clone)]
277#[argh(subcommand, name = "js")]
278pub struct EmitJsCommand {
279  /// enable watch mode (default behavior is run once)
280  #[argh(switch, short = 'w')]
281  pub watch: bool,
282  /// check-only mode for JS emit
283  #[argh(switch)]
284  pub check_only: bool,
285}
286
287/// emit a browser or embedded WebAssembly core module
288#[derive(FromArgs, PartialEq, Debug, Clone)]
289#[argh(subcommand, name = "wasm")]
290pub struct EmitWasmCommand {
291  /// input source file, defaults to "calcit.cirru"
292  #[argh(positional)]
293  pub input: Option<String>,
294  /// output directory for program.wasm; defaults to the top-level emit path
295  #[argh(option)]
296  pub emit_path: Option<String>,
297  /// select a configured entry
298  #[argh(option)]
299  pub entry: Option<String>,
300  /// override the configured initialization definition
301  #[argh(option)]
302  pub init_fn: Option<String>,
303  /// override the configured reload definition
304  #[argh(option)]
305  pub reload_fn: Option<String>,
306  /// output ABI boundary: native (default) or component
307  #[argh(option, default = "String::from(\"native\")")]
308  pub boundary: String,
309  /// validate the core module without writing program.wasm
310  #[argh(switch)]
311  pub check_only: bool,
312}
313
314/// emit a WebAssembly command module for a WASI host
315#[derive(FromArgs, PartialEq, Debug, Clone)]
316#[argh(subcommand, name = "wasi")]
317pub struct EmitWasiCommand {
318  /// input source file, defaults to "calcit.cirru"
319  #[argh(positional)]
320  pub input: Option<String>,
321  /// output directory for program.wasm; defaults to the top-level emit path
322  #[argh(option)]
323  pub emit_path: Option<String>,
324  /// select a configured entry
325  #[argh(option)]
326  pub entry: Option<String>,
327  /// override the configured initialization definition; it must take no arguments
328  #[argh(option)]
329  pub init_fn: Option<String>,
330  /// override the configured reload definition
331  #[argh(option)]
332  pub reload_fn: Option<String>,
333  /// output ABI boundary: component (WASI 0.3 default) or native (Preview 1)
334  #[argh(option, default = "String::from(\"component\")")]
335  pub boundary: String,
336  /// target WASI world: command (WASI 0.3 default) or http (WASI 0.2 proxy)
337  #[argh(option, default = "String::from(\"command\")")]
338  pub world: String,
339  /// emit a raw Canonical ABI core module without built-in Component packaging (for external WIT embedding and component composition)
340  #[argh(switch)]
341  pub emit_core: bool,
342  /// validate the WASI component without writing program.wasm
343  #[argh(switch)]
344  pub check_only: bool,
345}
346
347/// diagnostic compiler output; not an application execution target
348#[derive(FromArgs, PartialEq, Debug, Clone)]
349#[argh(subcommand, name = "ir")]
350pub struct EmitIrCommand {
351  /// enable watch mode (default behavior is run once)
352  #[argh(switch, short = 'w')]
353  pub watch: bool,
354  /// write only `:meta`, `:configs` and `:sources` (source, docs, types, deps) for program viewers
355  #[argh(switch)]
356  pub sources_only: bool,
357}
358
359/// evaluate snippet
360#[derive(FromArgs, PartialEq, Debug, Clone)]
361#[argh(subcommand, name = "eval")]
362pub struct EvalCommand {
363  /// evaluate a snippet
364  #[argh(positional)]
365  pub snippet: Option<String>,
366  /// read a snippet from stdin instead of a positional argument
367  #[argh(switch)]
368  pub stdin: bool,
369  /// entry file path
370  #[argh(option)]
371  pub dep: Vec<String>,
372}
373
374// ═══════════════════════════════════════════════════════════════════════════════
375// Analyze subcommand - code structure analysis
376// ═══════════════════════════════════════════════════════════════════════════════
377
378#[derive(FromArgs, PartialEq, Debug, Clone)]
379#[argh(subcommand, name = "analyze")]
380/// analyze code structure, type-debt views, and helpers (call-graph, program-diff, weak-types, check-examples, verify)
381pub struct AnalyzeCommand {
382  #[argh(subcommand)]
383  pub subcommand: AnalyzeSubcommand,
384}
385
386#[derive(FromArgs, PartialEq, Debug, Clone)]
387#[argh(subcommand)]
388pub enum AnalyzeSubcommand {
389  /// analyze call graph structure from entry point; `--counts` counts calls, `--diff <ref>` compares against a Git ref, `--effects` builds the State/Transform/Effect graph
390  CallGraph(CallGraphCommand),
391  /// compare current snapshot (or one definition) against a Git ref with structured tree diff
392  ProgramDiff(ProgramDiffCommand),
393  /// check examples in namespace
394  CheckExamples(CheckExamplesCommand),
395  /// locate weakly-typed hotspots, type coverage, dynamic method dispatch, or deprecated calls (select with --only)
396  WeakTypes(WeakTypesCommand),
397  /// run a declarative project verification profile
398  Verify(VerifyCommand),
399}
400
401/// run a declarative project verification profile
402#[derive(FromArgs, PartialEq, Debug, Clone)]
403#[argh(subcommand, name = "verify")]
404pub struct VerifyCommand {
405  /// profile name from snapshot :verification.profiles
406  #[argh(option)]
407  pub profile: String,
408  /// output format: human (default), edn (primary structured data), or json (interoperability)
409  #[argh(option, default = "String::from(\"human\")")]
410  pub format: String,
411}
412
413/// Options of the public-definition check that `--check-only --ns` runs.
414#[derive(PartialEq, Debug, Clone)]
415pub struct CheckPublicCommand {
416  /// exact public namespaces to check, shared and target-specific
417  pub ns: Vec<String>,
418  /// output format: human, edn, or json
419  pub format: String,
420  /// allow selected namespaces loaded from dependencies or calcit.core
421  pub deps: bool,
422  /// emit aggregate counts without per-definition rows
423  pub summary_only: bool,
424  /// enforce portable Static Core rules without requiring an entry :target
425  pub static_core: bool,
426}
427
428/// Options of the type-coverage view that `analyze weak-types --only coverage` runs.
429#[derive(PartialEq, Debug, Clone)]
430pub struct CheckTypesCommand {
431  /// exact namespace to analyze
432  pub ns: Option<String>,
433  /// namespace prefix scope filter
434  pub ns_prefix: Option<String>,
435  /// coverage levels to include, comma-separated: none,partial,full
436  pub only: Option<String>,
437  /// output format: human, edn, or json
438  pub format: String,
439  /// include dependency/core namespaces
440  pub deps: bool,
441  /// emit aggregate counts without per-definition details
442  pub summary_only: bool,
443  /// reuse revision-keyed per-definition analysis from .calcit local state
444  pub incremental: bool,
445}
446
447/// locate weakly-typed hotspots, type coverage, dynamic method dispatch, or deprecated calls
448#[derive(FromArgs, PartialEq, Debug, Clone)]
449#[argh(subcommand, name = "weak-types")]
450pub struct WeakTypesCommand {
451  /// exact namespace to analyze
452  #[argh(option)]
453  pub ns: Option<String>,
454  /// namespace prefix scope filter
455  #[argh(option)]
456  pub ns_prefix: Option<String>,
457  /// match kinds to include, comma-separated: schema-dynamic,schema-open,unresolved-type-slot,code-dynamic,code-nil,unsafe-coerce,data-dynamic (opt-in, not in the default report); or exactly one view: coverage, dynamic-method, deprecated-call, option-nil-roundtrip, inferred-dynamic, legacy-migration
458  #[argh(option)]
459  pub only: Option<String>,
460  /// with --only coverage, coverage levels to include, comma-separated: none,partial,full
461  #[argh(option, long = "coverage-level")]
462  pub coverage_level: Option<String>,
463  /// intent classes to include, comma-separated: unresolved,intentional-js-ffi,js-ffi-non-host,intentional-macro-syntax,intentional-type-slot-dynamic,intentional-decode,intentional-open,explicit-unsafe,declared-unit
464  #[argh(option)]
465  pub intent: Option<String>,
466  /// output format: human (default), edn, or json
467  #[argh(option, default = "String::from(\"human\")")]
468  pub format: String,
469  /// include dependency/core namespaces
470  #[argh(switch)]
471  pub deps: bool,
472  /// include review-only JS FFI boundary evidence and migration candidates
473  #[argh(switch, long = "ffi-evidence")]
474  pub ffi_evidence: bool,
475  /// include review-only schema, map-shape, and dispatch candidates
476  #[argh(switch, long = "schema-evidence")]
477  pub schema_evidence: bool,
478  /// emit aggregate counts without per-definition details
479  #[argh(switch, long = "summary-only")]
480  pub summary_only: bool,
481  /// reuse revision-keyed per-definition analysis from .calcit local state
482  #[argh(switch)]
483  pub incremental: bool,
484}
485
486/// options of `analyze weak-types --only dynamic-method`, normalized from `WeakTypesCommand`
487#[derive(PartialEq, Debug, Clone)]
488pub struct DynamicMethodsCommand {
489  /// output format: human (default), edn, or json
490  pub format: String,
491  /// include dependency namespaces
492  pub deps: bool,
493  /// emit aggregate counts without individual findings
494  pub summary_only: bool,
495  /// reuse entry preprocessing findings when its dependency closure is unchanged
496  pub incremental: bool,
497}
498
499/// options of `analyze weak-types --only deprecated-call`, normalized from `WeakTypesCommand`
500#[derive(PartialEq, Debug, Clone)]
501pub struct DeprecatedCommand {
502  /// exact namespace to analyze
503  pub ns: Option<String>,
504  /// namespace prefix scope filter
505  pub ns_prefix: Option<String>,
506  /// output format: human (default), edn, or json
507  pub format: String,
508  /// include dependency/core namespaces
509  pub deps: bool,
510  /// emit aggregate counts without per-definition details
511  pub summary_only: bool,
512}
513
514/// check examples in namespace
515#[derive(FromArgs, PartialEq, Debug, Clone)]
516#[argh(subcommand, name = "check-examples")]
517pub struct CheckExamplesCommand {
518  /// target namespace to check examples
519  #[argh(option)]
520  pub ns: String,
521  /// check only one definition in the namespace
522  #[argh(option, long = "def")]
523  pub definition: Option<String>,
524  /// run examples through JavaScript codegen and Node.js
525  #[argh(switch)]
526  pub js: bool,
527}
528
529/// analyze call tree structure from entry point; `--counts` counts call occurrences, `--diff <ref>` compares against a Git ref, `--effects` builds the State/Transform/Effect graph
530#[derive(FromArgs, PartialEq, Debug, Clone)]
531#[argh(subcommand, name = "call-graph")]
532pub struct CallGraphCommand {
533  /// directly specify root definition to analyze (format: ns/def). If omitted, uses init-fn from config
534  #[argh(option)]
535  pub root: Option<String>,
536  /// only show definitions whose namespace starts with this prefix
537  #[argh(option)]
538  pub ns_prefix: Option<String>,
539  /// include core/library calls in the output
540  #[argh(switch)]
541  pub include_core: bool,
542  /// maximum depth to traverse (default: 0 = unlimited, or 2 with --effects)
543  #[argh(option)]
544  pub max_depth: Option<usize>,
545  /// show definitions unreachable from the selected entry (may include external entry points)
546  #[argh(switch)]
547  pub show_unused: bool,
548  /// output format: human (default, LLM-friendly; legacy aliases text, tree), edn, or json; `--diff` supports human only
549  #[argh(option, default = "String::from(\"text\")")]
550  pub format: String,
551  /// count call occurrences per definition instead of printing the tree
552  #[argh(switch)]
553  pub counts: bool,
554  /// with --counts, sort by "count" (default, descending) or "name"
555  #[argh(option)]
556  pub sort: Option<String>,
557  /// compare the call graph against a Git ref (e.g. HEAD~1, main, or a commit SHA) and annotate code changes
558  #[argh(option)]
559  pub diff: Option<String>,
560  /// decompose entry into a State / Transform / Effect dependency graph instead of a plain call tree
561  #[argh(switch)]
562  pub effects: bool,
563  /// with --effects, transform compression level: summary (default), full, or minimal
564  #[argh(option)]
565  pub detail: Option<String>,
566  /// with --effects, enable ANSI colors in tree output (default: true; pass false to disable)
567  #[argh(option)]
568  pub color: Option<bool>,
569}
570
571/// options of `analyze call-graph --effects`, normalized from `CallGraphCommand`
572#[derive(PartialEq, Debug, Clone)]
573pub struct EffectsGraphCommand {
574  /// directly specify root definition to analyze (format: ns/def). If omitted, uses init-fn from config
575  pub root: Option<String>,
576  /// only show definitions whose namespace starts with this prefix
577  pub ns_prefix: Option<String>,
578  /// include core/library calls in the output
579  pub include_core: bool,
580  /// maximum depth to traverse (0 = unlimited, 2 = default)
581  pub max_depth: usize,
582  /// output format: human (default, State / Transform / Effect tree; legacy alias tree), edn, or json
583  pub format: String,
584  /// transform compression level: summary, full, or minimal
585  pub detail: String,
586  /// enable ANSI colors in tree output (default: true; pass false to disable)
587  pub color: bool,
588}
589
590/// options of `analyze call-graph --diff <ref>`, normalized from `CallGraphCommand`
591#[derive(PartialEq, Debug, Clone)]
592pub struct CallGraphDiffCommand {
593  /// git reference to compare against, e.g. HEAD~1, main, v0.1.0, or a commit SHA
594  pub git_ref: String,
595  /// directly specify root definition to analyze (format: ns/def). If omitted, uses current config init-fn
596  pub root: Option<String>,
597  /// only show definitions whose namespace starts with this prefix
598  pub ns_prefix: Option<String>,
599  /// include core/library calls in the output
600  pub include_core: bool,
601  /// maximum depth to traverse (0 = unlimited)
602  pub max_depth: usize,
603}
604
605/// options of `analyze call-graph --counts`, normalized from `CallGraphCommand`
606#[derive(PartialEq, Debug, Clone)]
607pub struct CountCallsCommand {
608  /// directly specify root definition to analyze (format: ns/def). If omitted, uses init-fn from config
609  pub root: Option<String>,
610  /// only show definitions whose namespace starts with this prefix
611  pub ns_prefix: Option<String>,
612  /// include core/library calls in the count
613  pub include_core: bool,
614  /// output format: human (default; legacy alias text), edn, or json
615  pub format: String,
616  /// sort by: "count" (default, descending) or "name"
617  pub sort: String,
618}
619
620/// compare current snapshot (or one definition) against a Git ref with structured tree diff;
621/// use --base to diff two arbitrary refs from git history
622#[derive(FromArgs, PartialEq, Debug, Clone)]
623#[argh(subcommand, name = "program-diff")]
624pub struct ProgramDiffCommand {
625  /// git reference to compare against, e.g. HEAD~1, main, v0.1.0, or a commit SHA
626  #[argh(positional)]
627  pub git_ref: String,
628  /// base git reference for two-ref diff (compare base vs positional ref, both from git history).
629  /// When omitted, compares working tree against the positional ref.
630  #[argh(option)]
631  pub base: Option<String>,
632  /// narrow diff to a single definition in format ns/def
633  #[argh(option)]
634  pub def: Option<String>,
635  /// output format: human (default), edn (primary structured data), or json (interoperability)
636  #[argh(option, default = "String::from(\"human\")")]
637  pub format: String,
638  /// exit with an error after printing when any definition schema widens a slot (whole Snapshot only; rejected with --def)
639  #[argh(switch)]
640  pub fail_on_widening: bool,
641}
642
643// ═══════════════════════════════════════════════════════════════════════════════
644// Query subcommand - project information queries
645// ═══════════════════════════════════════════════════════════════════════════════
646
647#[derive(FromArgs, PartialEq, Debug, Clone)]
648#[argh(subcommand, name = "query")]
649/// query project and builtin information (namespaces, definitions, configs)
650pub struct QueryCommand {
651  #[argh(subcommand)]
652  pub subcommand: QuerySubcommand,
653}
654
655#[derive(FromArgs, PartialEq, Debug, Clone)]
656#[argh(subcommand)]
657pub enum QuerySubcommand {
658  /// list namespaces (or show ns details if namespace provided)
659  Ns(QueryNsCommand),
660  /// list definitions in a namespace
661  Defs(QueryDefsCommand),
662  /// read project configs
663  Config(QueryConfigCommand),
664  /// read .calcit/error.cirru file
665  Error(QueryErrorCommand),
666  /// read a definition's full code, summary (`--summary`), or examples/tests (`--only`)
667  Def(QueryDefCommand),
668  /// find symbol across namespaces
669  Find(QueryFindCommand),
670  /// find usages of a definition
671  Usages(QueryUsagesCommand),
672  /// search for leaf nodes (strings) in definition
673  Search(QuerySearchCommand),
674  /// search for structural expressions (Cirru expr or JSON array) in definition
675  SearchExpr(QuerySearchExprCommand),
676  /// read a definition's schema (type information)
677  Schema(QuerySchemaCommand),
678  /// inspect a type and its statically available methods
679  Type(QueryTypeCommand),
680  /// inspect the inferred and expected type at one Snapshot expression path
681  TypeAt(QueryTypeAtCommand),
682  /// gather bounded semantic context for one definition
683  Context(QueryContextCommand),
684}
685
686#[derive(FromArgs, PartialEq, Debug, Clone)]
687#[argh(subcommand, name = "schema")]
688/// read a definition's schema (type information)
689pub struct QuerySchemaCommand {
690  /// target in format "namespace/definition"
691  #[argh(positional)]
692  pub target: String,
693  /// output format: Markdown-compatible human (default), edn, or json
694  #[argh(option, default = "String::from(\"human\")")]
695  pub format: String,
696}
697
698#[derive(FromArgs, PartialEq, Debug, Clone)]
699#[argh(subcommand, name = "type")]
700/// inspect a type and list methods available through static dispatch metadata
701pub struct QueryTypeCommand {
702  /// builtin type annotation (e.g. 'Number or ":: 'List 'Number") or namespace/definition
703  #[argh(positional)]
704  pub target: String,
705  /// output format: Markdown-compatible human (default), edn, or json
706  #[argh(option, default = "String::from(\"human\")")]
707  pub format: String,
708}
709
710#[derive(FromArgs, PartialEq, Debug, Clone)]
711#[argh(subcommand, name = "type-at")]
712/// inspect static type evidence for an expression at a Snapshot path without running the program
713pub struct QueryTypeAtCommand {
714  /// target in format "namespace/definition"
715  #[argh(positional)]
716  pub target: String,
717  /// snapshot path, e.g. "code@3.2", "@3.2", or "3.2"
718  #[argh(option)]
719  pub path: String,
720  /// output format: Markdown-compatible human (default), edn, or json
721  #[argh(option, default = "String::from(\"human\")")]
722  pub format: String,
723}
724
725#[derive(FromArgs, PartialEq, Debug, Clone)]
726#[argh(subcommand, name = "context")]
727/// gather bounded Snapshot metadata, static analysis, dependencies, and usages for one definition
728pub struct QueryContextCommand {
729  /// target in format "namespace/definition"
730  #[argh(positional)]
731  pub target: String,
732  /// approximate character budget for variable-size content
733  #[argh(option, default = "6000")]
734  pub budget: usize,
735  /// output format: Markdown-compatible human (default), edn, or json
736  #[argh(option, default = "String::from(\"human\")")]
737  pub format: String,
738  /// include references from dependency and core namespaces
739  #[argh(switch)]
740  pub deps: bool,
741  /// maximum number of direct dependencies to include
742  #[argh(option, default = "12")]
743  pub dependency_limit: usize,
744  /// maximum number of usages to include
745  #[argh(option, default = "8")]
746  pub usage_limit: usize,
747  /// maximum number of examples to include
748  #[argh(option, default = "3")]
749  pub example_limit: usize,
750  /// maximum number of definition-attached tests to include
751  #[argh(option, default = "3")]
752  pub test_limit: usize,
753  /// also list core macro/syntax dependencies and the generic Fn methods shared by every function
754  #[argh(switch)]
755  pub include_core: bool,
756}
757
758#[derive(FromArgs, PartialEq, Debug, Clone)]
759#[argh(subcommand, name = "ns")]
760/// list namespaces, or show ns details if namespace provided
761pub struct QueryNsCommand {
762  /// namespace to show details (optional, lists all if omitted)
763  #[argh(positional)]
764  pub namespace: Option<String>,
765  /// include dependency and core namespaces
766  #[argh(switch)]
767  pub deps: bool,
768  /// output format: Markdown-compatible human (default), edn, json, or cirru (the namespace's `%{} 'FileEntry` data as stored in the Snapshot, accepted by `edit ns`; generated namespaces such as `<package>.$meta` are not stored and are rejected)
769  #[argh(option, default = "String::from(\"human\")")]
770  pub format: String,
771}
772
773#[derive(FromArgs, PartialEq, Debug, Clone)]
774#[argh(subcommand, name = "defs")]
775/// list definitions in a namespace
776pub struct QueryDefsCommand {
777  /// namespace to query
778  #[argh(positional)]
779  pub namespace: String,
780  /// filter definitions that contain this tag (e.g. macro or :macro)
781  #[argh(option)]
782  pub tag: Option<String>,
783  /// show each definition's signature (schema, or its declaration head when untyped) instead of a [schema] marker
784  #[argh(switch)]
785  pub signatures: bool,
786  /// output format: Markdown-compatible human (default), edn, or json
787  #[argh(option, default = "String::from(\"human\")")]
788  pub format: String,
789}
790
791// read-ns merged into ns command
792
793#[derive(FromArgs, PartialEq, Debug, Clone)]
794#[argh(subcommand, name = "config")]
795/// read project configs (init_fn, reload_fn, version)
796pub struct QueryConfigCommand {
797  /// output format: Markdown-compatible human (default), edn, or json
798  #[argh(option, default = "String::from(\"human\")")]
799  pub format: String,
800}
801
802#[derive(FromArgs, PartialEq, Debug, Clone)]
803#[argh(subcommand, name = "error")]
804/// read .calcit/error.cirru file for error stack traces
805pub struct QueryErrorCommand {}
806
807#[derive(FromArgs, PartialEq, Debug, Clone)]
808#[argh(subcommand, name = "def")]
809/// read a definition's full code, summary (`--summary`), examples/tests (`--only`), or builtin metadata
810pub struct QueryDefCommand {
811  /// target in format "namespace/definition"
812  #[argh(positional)]
813  pub target: String,
814  /// output format: Markdown-compatible human (default), edn, json, or cirru (`quote $ <definition>` for `edit def --overwrite`, or with `--only examples` one `quote $ <example>` per example without JSON AST for `edit meta --examples`)
815  #[argh(option, default = "String::from(\"human\")")]
816  pub format: String,
817  /// show compact signature/doc/schema/cases/counts preview without full body
818  #[argh(switch)]
819  pub summary: bool,
820  /// show only one section of the definition: examples or tests
821  #[argh(option)]
822  pub only: Option<String>,
823  /// preferred nodes per display fragment when large expressions are chunked
824  #[argh(option, default = "56")]
825  pub chunk_target_nodes: usize,
826  /// stop recursive chunk splitting once fragments fall below this node count
827  #[argh(option, default = "68")]
828  pub chunk_max_nodes: usize,
829  /// only enable chunked display when total expression nodes reach this threshold
830  #[argh(option, default = "88")]
831  pub chunk_trigger_nodes: usize,
832  /// only enable chunked display when the formatted definition reaches this many bytes
833  #[argh(option, default = "2048")]
834  pub chunk_trigger_bytes: usize,
835  /// non-chunked Markdown output; use --format cirru for source that can be written back
836  #[argh(switch)]
837  pub raw: bool,
838}
839
840#[derive(FromArgs, PartialEq, Debug, Clone)]
841#[argh(subcommand, name = "find")]
842/// find symbol across namespaces (fuzzy match by default; use --exact for precise match)
843pub struct QueryFindCommand {
844  /// symbol name or pattern to search for (fuzzy match by default)
845  #[argh(positional)]
846  pub symbol: String,
847  /// include dependency namespaces in search
848  #[argh(switch)]
849  pub deps: bool,
850  /// exact match: only match definitions with this exact name
851  #[argh(switch)]
852  pub exact: bool,
853  /// maximum number of results (default 20)
854  #[argh(option, default = "20")]
855  pub limit: usize,
856  /// start index for detailed display window (3 detailed items)
857  #[argh(option, long = "detail-offset", default = "0")]
858  pub detail_offset: usize,
859}
860
861#[derive(FromArgs, PartialEq, Debug, Clone)]
862#[argh(subcommand, name = "usages")]
863/// find usages of a definition across the project
864pub struct QueryUsagesCommand {
865  /// target in format "namespace/definition"
866  #[argh(positional)]
867  pub target: String,
868  /// include dependency namespaces in search
869  #[argh(switch)]
870  pub deps: bool,
871  /// start index for detailed display window (3 detailed items)
872  #[argh(option, long = "detail-offset", default = "0")]
873  pub detail_offset: usize,
874}
875
876#[derive(FromArgs, PartialEq, Debug, Clone)]
877#[argh(subcommand, name = "search")]
878/// search for leaf nodes across selected sources or a specific namespace/definition (fuzzy match by default)
879pub struct QuerySearchCommand {
880  /// string pattern to search for in leaf nodes
881  #[argh(positional)]
882  pub pattern: String,
883  /// filter search to specific namespace or namespace/definition (optional)
884  #[argh(option, long = "filter")]
885  pub filter: Option<String>,
886  /// exact match: only match nodes equal to the pattern (default is contains-match)
887  #[argh(switch)]
888  pub exact: bool,
889  /// regex match: treat pattern as a regular expression for leaf node matching
890  #[argh(switch, long = "regex")]
891  pub regex: bool,
892  /// maximum search depth (0 = unlimited)
893  #[argh(option, default = "0")]
894  pub max_depth: usize,
895  /// start search from specific path (dot-separated indices preferred, e.g. "@2.1.0")
896  #[argh(option, long = "start-path")]
897  pub start_path: Option<String>,
898  /// include modules configured for a specific entry in `entries`
899  #[argh(option, long = "entry")]
900  pub entry: Option<String>,
901  /// source scope: project, core, deps, or all (default)
902  #[argh(option, default = "String::from(\"all\")")]
903  pub source: String,
904  /// start index for detailed display window (3 detailed items)
905  #[argh(option, long = "detail-offset", default = "0")]
906  pub detail_offset: usize,
907  /// also print parent path for each match (strip trailing index for editable node)
908  #[argh(switch, long = "parent-path")]
909  pub parent_path: bool,
910  /// output format: Markdown-compatible human (default), edn, or json
911  #[argh(option, default = "String::from(\"human\")")]
912  pub format: String,
913  /// set the persistent cursor to this zero-based global match index
914  #[argh(option, long = "set-cursor")]
915  pub set_cursor: Option<usize>,
916}
917
918#[derive(FromArgs, PartialEq, Debug, Clone)]
919#[argh(subcommand, name = "search-expr")]
920/// search for structural expressions (Cirru expr or JSON array) across project or in specific namespace/definition (fuzzy match by default)
921pub struct QuerySearchExprCommand {
922  /// pattern to search for (Cirru one-liner or JSON array with --json)
923  #[argh(positional)]
924  pub pattern: String,
925  /// filter search to specific namespace or namespace/definition (optional)
926  #[argh(option, long = "filter")]
927  pub filter: Option<String>,
928  /// exact match: only match structurally identical expressions (default is prefix/contains match)
929  #[argh(switch)]
930  pub exact: bool,
931  /// maximum search depth (0 = unlimited)
932  #[argh(option, default = "0")]
933  pub max_depth: usize,
934  /// start search from a concrete path or the active cursor
935  #[argh(option, long = "start-path")]
936  pub start_path: Option<String>,
937  /// treat pattern as JSON array instead of Cirru expr
938  #[argh(switch)]
939  pub json: bool,
940  /// include modules configured for a specific entry in `entries`
941  #[argh(option, long = "entry")]
942  pub entry: Option<String>,
943  /// start index for detailed display window (3 detailed items)
944  #[argh(option, long = "detail-offset", default = "0")]
945  pub detail_offset: usize,
946  /// output format: Markdown-compatible human (default), edn, or json
947  #[argh(option, default = "String::from(\"human\")")]
948  pub format: String,
949  /// set the persistent cursor to this zero-based global match index
950  #[argh(option, long = "set-cursor")]
951  pub set_cursor: Option<usize>,
952}
953
954// ═══════════════════════════════════════════════════════════════════════════════
955// Docs subcommand - documentation tools
956// ═══════════════════════════════════════════════════════════════════════════════
957
958#[derive(FromArgs, PartialEq, Debug, Clone)]
959#[argh(subcommand, name = "docs")]
960/// documentation tools for calcit guidebook and installed module docs
961pub struct DocsCommand {
962  #[argh(subcommand)]
963  pub subcommand: DocsSubcommand,
964}
965
966#[derive(FromArgs, PartialEq, Debug, Clone)]
967#[argh(subcommand)]
968pub enum DocsSubcommand {
969  /// list available doc scopes (calcit and installed modules)
970  Scopes(DocsScopesCommand),
971  /// browse remote library registry and read remote library docs
972  RemoteLibs(DocsRemoteLibsCommand),
973  /// search calcit guidebook or installed module docs by keyword
974  Search(DocsSearchCommand),
975  /// list available files in calcit guidebook or one installed module
976  List(DocsListCommand),
977  /// list markdown section headings in one file
978  Sections(DocsSectionsCommand),
979  /// read markdown content from calcit guidebook or one installed module
980  Read(DocsReadCommand),
981  /// read the embedded Agents guide or compact mutation contract
982  Agents(DocsAgentsCommand),
983  /// check ```cirru code blocks in a markdown file via eval
984  CheckMd(DocsCheckMdCommand),
985  /// format fenced ```cirru code blocks in a markdown file
986  FormatMd(DocsFormatMdCommand),
987}
988
989#[derive(FromArgs, PartialEq, Debug, Clone)]
990#[argh(subcommand, name = "scopes")]
991/// list available doc scopes (calcit and installed modules)
992pub struct DocsScopesCommand {}
993
994#[derive(FromArgs, PartialEq, Debug, Clone)]
995#[argh(subcommand, name = "remote-libs")]
996/// browse remote library registry and read remote library docs
997pub struct DocsRemoteLibsCommand {
998  #[argh(subcommand)]
999  pub subcommand: Option<LibsSubcommand>,
1000}
1001
1002#[derive(FromArgs, PartialEq, Debug, Clone)]
1003#[argh(subcommand, name = "search")]
1004/// search calcit guidebook by default, or switch to one installed module with --module
1005pub struct DocsSearchCommand {
1006  /// keyword to search
1007  #[argh(positional)]
1008  pub keyword: String,
1009  /// number of context lines to show before and after match (default: 5)
1010  #[argh(option, default = "5")]
1011  pub context: usize,
1012  /// filter by filename (optional)
1013  #[argh(option)]
1014  pub filename: Option<String>,
1015  /// search docs for a specific installed module (e.g. respo.calcit)
1016  #[argh(option)]
1017  pub module: Option<String>,
1018  /// show only document title and summary (no content snippets)
1019  #[argh(switch, long = "summary")]
1020  pub summary: bool,
1021}
1022
1023#[derive(FromArgs, PartialEq, Debug, Clone)]
1024#[argh(subcommand, name = "list")]
1025/// list available files in calcit guidebook or one installed module
1026pub struct DocsListCommand {
1027  /// limit listing to one installed module (e.g. respo.calcit)
1028  #[argh(option)]
1029  pub module: Option<String>,
1030}
1031
1032#[derive(FromArgs, PartialEq, Debug, Clone)]
1033#[argh(subcommand, name = "sections")]
1034/// list markdown section headings in one file
1035pub struct DocsSectionsCommand {
1036  /// filename to inspect (e.g., "intro.md")
1037  #[argh(positional)]
1038  pub filename: String,
1039  /// read docs from a specific installed module (e.g. respo.calcit)
1040  #[argh(option)]
1041  pub module: Option<String>,
1042  /// show line numbers in section titles
1043  #[argh(switch)]
1044  pub with_lines: bool,
1045}
1046
1047#[derive(FromArgs, PartialEq, Debug, Clone)]
1048#[argh(subcommand, name = "read")]
1049/// read markdown content from calcit guidebook by default, or from one installed module with --module
1050pub struct DocsReadCommand {
1051  /// filename to read (e.g., "syntax.md")
1052  #[argh(positional)]
1053  pub filename: String,
1054  /// optional section heading keyword(s) for fuzzy match, can pass multiple; omit to read full file
1055  #[argh(positional)]
1056  pub headings: Vec<String>,
1057  /// do not include nested subheadings when showing matched parent heading content
1058  #[argh(switch)]
1059  pub no_subheadings: bool,
1060  /// show full file content directly
1061  #[argh(switch)]
1062  pub full: bool,
1063  /// show line numbers in heading list and section titles
1064  #[argh(switch)]
1065  pub with_lines: bool,
1066  /// read docs from a specific installed module (e.g. respo.calcit)
1067  #[argh(option)]
1068  pub module: Option<String>,
1069  /// read a line range that skips this many lines (default 0 when --lines is given)
1070  #[argh(option)]
1071  pub start: Option<usize>,
1072  /// number of lines in a line range (default 80 when --start is given)
1073  #[argh(option)]
1074  pub lines: Option<usize>,
1075}
1076
1077#[derive(FromArgs, PartialEq, Debug, Clone)]
1078#[argh(subcommand, name = "agents")]
1079/// read the embedded Agents guide, compact mutation contract, or refreshed remote guide
1080pub struct DocsAgentsCommand {
1081  /// heading keyword(s) for fuzzy match, can pass multiple; if omitted, list all markdown headings
1082  #[argh(positional)]
1083  pub headings: Vec<String>,
1084  /// do not include nested subheadings when showing matched parent heading content
1085  #[argh(switch)]
1086  pub no_subheadings: bool,
1087  /// show full file content directly
1088  #[argh(switch)]
1089  pub full: bool,
1090  /// show the compact versioned mutation contract
1091  #[argh(switch)]
1092  pub contract: bool,
1093  /// show line numbers in heading list and section titles
1094  #[argh(switch)]
1095  pub with_lines: bool,
1096  /// force refresh from remote and ignore cache age
1097  #[argh(switch)]
1098  pub refresh: bool,
1099}
1100
1101#[derive(FromArgs, PartialEq, Debug, Clone)]
1102#[argh(subcommand, name = "check-md")]
1103/// check ```cirru code blocks in a markdown file via eval
1104pub struct DocsCheckMdCommand {
1105  /// path to the markdown file to check
1106  #[argh(positional)]
1107  pub file: String,
1108  /// snapshot .cirru file for eval context (default: calcit.cirru)
1109  #[argh(option, default = "String::from(\"calcit.cirru\")")]
1110  pub snapshot: String,
1111  /// retired spelling for --snapshot; --entry selects a named entry elsewhere
1112  #[argh(option, long = "entry")]
1113  pub legacy_entry: Option<String>,
1114  /// extra dependency module path for eval context, can be provided multiple times; defaults to modules from entries.default.modules; paths ending with '/' resolve calcit.cirru and reject retired compact.cirru modules
1115  #[argh(option)]
1116  pub dep: Vec<String>,
1117  /// suppress successful block logs; still prints failures and summary on error
1118  #[argh(switch)]
1119  pub quiet: bool,
1120  /// only display failed blocks and summary; implies --quiet
1121  #[argh(switch, long = "failures-only")]
1122  pub failures_only: bool,
1123}
1124
1125#[derive(FromArgs, PartialEq, Debug, Clone)]
1126#[argh(subcommand, name = "format-md")]
1127/// format fenced ```cirru code blocks in a markdown file
1128pub struct DocsFormatMdCommand {
1129  /// path to the markdown file to format
1130  #[argh(positional)]
1131  pub file: String,
1132  /// report non-canonical blocks without writing the file
1133  #[argh(switch)]
1134  pub check: bool,
1135}
1136
1137// ═══════════════════════════════════════════════════════════════════════════════
1138// Cirru subcommand - syntax tools
1139// ═══════════════════════════════════════════════════════════════════════════════
1140
1141#[derive(FromArgs, PartialEq, Debug, Clone)]
1142#[argh(subcommand, name = "cirru")]
1143/// Cirru syntax tools (parse, format, edn)
1144pub struct CirruCommand {
1145  #[argh(subcommand)]
1146  pub subcommand: CirruSubcommand,
1147}
1148
1149#[derive(FromArgs, PartialEq, Debug, Clone)]
1150#[argh(subcommand)]
1151pub enum CirruSubcommand {
1152  /// parse Cirru code to JSON
1153  Parse(CirruParseCommand),
1154  /// format JSON to Cirru code
1155  Format(CirruFormatCommand),
1156  /// parse Cirru EDN to JSON
1157  ParseEdn(CirruParseEdnCommand),
1158}
1159
1160#[derive(FromArgs, PartialEq, Debug, Clone)]
1161#[argh(subcommand, name = "parse")]
1162/// parse Cirru code to JSON
1163pub struct CirruParseCommand {
1164  /// cirru code to parse
1165  #[argh(positional)]
1166  pub code: String,
1167  /// parse input as a single-line Cirru expression (one-liner parser, default is multi-line)
1168  #[argh(switch, short = 'e', long = "expr-one")]
1169  pub expr_one_liner: bool,
1170  /// perform basic syntax validation after parsing (checks keywords, strings, numbers)
1171  #[argh(switch, long = "validate")]
1172  pub validate: bool,
1173}
1174
1175#[derive(FromArgs, PartialEq, Debug, Clone)]
1176#[argh(subcommand, name = "format")]
1177/// format JSON to Cirru code
1178pub struct CirruFormatCommand {
1179  /// JSON data to format (as string)
1180  #[argh(positional)]
1181  pub json: String,
1182}
1183
1184#[derive(FromArgs, PartialEq, Debug, Clone)]
1185#[argh(subcommand, name = "parse-edn")]
1186/// parse Cirru EDN to JSON
1187pub struct CirruParseEdnCommand {
1188  /// cirru EDN to parse; use --file - to read stdin
1189  #[argh(positional)]
1190  pub edn: Option<String>,
1191  /// read cirru EDN from a file; use - to read stdin
1192  #[argh(option)]
1193  pub file: Option<String>,
1194}
1195
1196// ═══════════════════════════════════════════════════════════════════════════════
1197// Remote library subcommands
1198// ═══════════════════════════════════════════════════════════════════════════════
1199
1200#[derive(FromArgs, PartialEq, Debug, Clone)]
1201#[argh(subcommand)]
1202pub enum LibsSubcommand {
1203  /// show README of a library
1204  Readme(LibsReadmeCommand),
1205  /// search libraries by keyword
1206  Search(LibsSearchCommand),
1207  /// scan markdown files in a module directory
1208  ScanMd(LibsScanMdCommand),
1209}
1210
1211#[derive(FromArgs, PartialEq, Debug, Clone)]
1212#[argh(subcommand, name = "readme")]
1213/// show README of a library from local ~/.config/calcit/modules or GitHub
1214pub struct LibsReadmeCommand {
1215  /// package name to look up
1216  #[argh(positional)]
1217  pub package: String,
1218  /// heading keyword(s) for fuzzy match, can pass multiple; if omitted, list markdown headings
1219  #[argh(positional)]
1220  pub headings: Vec<String>,
1221  /// optional file path relative to package directory (e.g., "Skills.md")
1222  #[argh(option)]
1223  pub file: Option<String>,
1224  /// do not include nested subheadings when showing matched parent heading content
1225  #[argh(switch)]
1226  pub no_subheadings: bool,
1227  /// show full file content directly
1228  #[argh(switch)]
1229  pub full: bool,
1230  /// show line numbers in heading list and section titles
1231  #[argh(switch)]
1232  pub with_lines: bool,
1233}
1234
1235#[derive(FromArgs, PartialEq, Debug, Clone)]
1236#[argh(subcommand, name = "search")]
1237/// search libraries by keyword in name or description
1238pub struct LibsSearchCommand {
1239  /// keyword to search
1240  #[argh(positional)]
1241  pub keyword: String,
1242}
1243
1244#[derive(FromArgs, PartialEq, Debug, Clone)]
1245#[argh(subcommand, name = "scan-md")]
1246/// scan markdown files in a module directory
1247pub struct LibsScanMdCommand {
1248  /// module name to scan
1249  #[argh(positional, default = "String::new()")]
1250  pub module: String,
1251}
1252
1253// ═══════════════════════════════════════════════════════════════════════════════
1254// Edit subcommand - code editing operations
1255// ═══════════════════════════════════════════════════════════════════════════════
1256
1257/// Transport format used when a mutation command receives one syntax node.
1258#[derive(PartialEq, Eq, Debug, Clone, Copy, Default)]
1259pub enum SyntaxInputFormat {
1260  /// Preserve the historical JSON-array/Cirru-quote content detection path.
1261  #[default]
1262  Auto,
1263  /// Cirru EDN whose payload crosses the code/data boundary through `quote`.
1264  Cirru,
1265  /// A serialized Cirru AST represented by JSON strings and arrays.
1266  JsonAst,
1267}
1268
1269impl std::fmt::Display for SyntaxInputFormat {
1270  fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1271    f.write_str(match self {
1272      Self::Auto => "auto",
1273      Self::Cirru => "cirru",
1274      Self::JsonAst => "json-ast",
1275    })
1276  }
1277}
1278
1279impl std::str::FromStr for SyntaxInputFormat {
1280  type Err = String;
1281
1282  fn from_str(raw: &str) -> Result<Self, Self::Err> {
1283    match raw {
1284      "auto" => Ok(Self::Auto),
1285      "cirru" | "cirru-edn" => Ok(Self::Cirru),
1286      "json-ast" | "json" => Ok(Self::JsonAst),
1287      other => Err(format!(
1288        "Unknown syntax input format `{other}`. Expected `cirru`, `json-ast`, or compatibility mode `auto`."
1289      )),
1290    }
1291  }
1292}
1293
1294#[derive(FromArgs, PartialEq, Debug, Clone)]
1295#[argh(subcommand, name = "edit")]
1296/// coarse-grained code editing (namespaces, definitions, metadata). For internal structural changes within definitions, use the `tree` command.
1297pub struct EditCommand {
1298  #[argh(subcommand)]
1299  pub subcommand: EditSubcommand,
1300}
1301
1302#[derive(FromArgs, PartialEq, Debug, Clone)]
1303#[argh(subcommand)]
1304pub enum EditSubcommand {
1305  /// rewrite snapshot file in canonical format without semantic changes
1306  Format(EditFormatCommand),
1307  /// three-way merge another Snapshot version into this one per definition (Git merge driver)
1308  Merge(EditMergeCommand),
1309  /// apply multiple existing edit/tree/config commands against one staged snapshot
1310  Transaction(EditTransactionCommand),
1311  /// validate a definition-graph architecture plan and preview scaffold work
1312  Scaffold(EditScaffoldCommand),
1313  /// add or update a definition
1314  Def(EditDefCommand),
1315  /// move a definition to another namespace
1316  MvDef(EditMvDefCommand),
1317  /// delete a definition
1318  RmDef(EditRmDefCommand),
1319  /// update definition metadata (doc, tags, examples, test removals)
1320  Meta(EditMetaCommand),
1321  /// update definition schema payload (inside quote)
1322  Schema(EditSchemaCommand),
1323  /// set or clear host FFI metadata on a definition
1324  Ffi(EditFfiCommand),
1325  /// add a named test to a definition
1326  AddTest(EditAddTestCommand),
1327  /// add a new namespace
1328  AddNs(EditAddNsCommand),
1329  /// delete a namespace
1330  RmNs(EditRmNsCommand),
1331  /// write back a namespace's `FileEntry` data from `query ns --format cirru`, updating only changed definitions
1332  Ns(EditNsCommand),
1333  /// update namespace imports (replace all)
1334  Imports(EditImportsCommand),
1335  /// add a single import rule to namespace
1336  AddImport(EditAddImportCommand),
1337  /// remove an import rule from namespace
1338  RmImport(EditRmImportCommand),
1339  /// rename a definition within its namespace (no overwrite)
1340  Rename(EditRenameCommand),
1341  /// extract a sub-expression into a new definition and replace in-place with the new name
1342  SplitDef(EditSplitDefCommand),
1343}
1344
1345#[derive(FromArgs, PartialEq, Debug, Clone)]
1346#[argh(subcommand, name = "format")]
1347/// rewrite target snapshot file in canonical format
1348pub struct EditFormatCommand {
1349  /// remove a reviewed unknown legacy entry field before migrating, as `<entry>.<field>`
1350  /// (repeatable); each dropped value is reported
1351  #[argh(option, long = "drop-legacy-entry-field")]
1352  pub drop_legacy_entry_fields: Vec<String>,
1353}
1354
1355#[derive(FromArgs, PartialEq, Debug, Clone)]
1356#[argh(subcommand, name = "merge")]
1357/// three-way merge another Snapshot version into this one per namespace and definition; for Git use
1358/// `merge.calcit.driver = calcit %A edit merge --base %O --theirs %B`
1359pub struct EditMergeCommand {
1360  /// common ancestor Snapshot file
1361  #[argh(option)]
1362  pub base: String,
1363  /// the other side's Snapshot file to merge in
1364  #[argh(option)]
1365  pub theirs: String,
1366}
1367
1368#[derive(FromArgs, PartialEq, Debug, Clone)]
1369#[argh(subcommand, name = "transaction")]
1370/// apply multiple existing mutating commands atomically (input via --file, --code, or stdin)
1371pub struct EditTransactionCommand {
1372  /// read transaction operations from a Cirru EDN file (JSON is also accepted)
1373  #[argh(option)]
1374  pub file: Option<String>,
1375  /// transaction operations as inline Cirru EDN (JSON is also accepted)
1376  #[argh(option, long = "code")]
1377  pub code: Option<String>,
1378  /// require the snapshot content to match this revision before applying
1379  #[argh(option, long = "expect-revision")]
1380  pub expect_revision: Option<String>,
1381  /// validate and preview the transaction without replacing the snapshot
1382  #[argh(switch, long = "dry-run")]
1383  pub dry_run: bool,
1384  /// output format: human (default), edn (primary structured data), or json (interoperability)
1385  #[argh(option, default = "String::from(\"human\")")]
1386  pub format: String,
1387}
1388
1389#[derive(FromArgs, PartialEq, Debug, Clone)]
1390#[argh(subcommand, name = "scaffold")]
1391/// preview or atomically create a definition-graph architecture scaffold
1392pub struct EditScaffoldCommand {
1393  /// read architecture Cirru EDN from file
1394  #[argh(option)]
1395  pub file: Option<String>,
1396  /// architecture Cirru EDN as inline text
1397  #[argh(option, long = "code")]
1398  pub code: Option<String>,
1399  /// require the snapshot content to match this revision before planning
1400  #[argh(option, long = "expect-revision")]
1401  pub expect_revision: Option<String>,
1402  /// validate and preview the scaffold without replacing the snapshot
1403  #[argh(switch, long = "dry-run")]
1404  pub dry_run: bool,
1405  /// output format: human (default), edn, or json
1406  #[argh(option, default = "String::from(\"human\")")]
1407  pub format: String,
1408}
1409
1410// --- Definition operations ---
1411
1412#[derive(FromArgs, PartialEq, Debug, Clone)]
1413#[argh(subcommand, name = "def")]
1414/// add a new definition (input via --file, --code, or pipe via stdin)
1415pub struct EditDefCommand {
1416  /// target in format "namespace/definition"
1417  #[argh(positional)]
1418  pub target: String,
1419  /// read syntax_tree from file; select its transport with --input-format
1420  #[argh(option)]
1421  pub file: Option<String>,
1422  /// syntax_tree as inline text; select its transport with --input-format
1423  #[argh(option, long = "code")]
1424  pub code: Option<String>,
1425  /// syntax-node transport format: cirru, json-ast, or compatibility mode auto
1426  #[argh(option, long = "input-format", default = "SyntaxInputFormat::Auto")]
1427  pub input_format: SyntaxInputFormat,
1428  /// overwrite existing definition if it already exists
1429  #[argh(switch, long = "overwrite")]
1430  pub overwrite: bool,
1431  /// allow an unrecognized definition head; shape and name checks still apply
1432  #[argh(switch, long = "allow-unknown-head")]
1433  pub allow_unknown_head: bool,
1434}
1435
1436#[derive(FromArgs, PartialEq, Debug, Clone)]
1437#[argh(subcommand, name = "mv-def")]
1438/// move a definition to another namespace or rename it
1439pub struct EditMvDefCommand {
1440  /// source in format "namespace/definition"
1441  #[argh(positional)]
1442  pub source: String,
1443  /// target in format "namespace/definition"
1444  #[argh(positional)]
1445  pub target: String,
1446}
1447
1448#[derive(FromArgs, PartialEq, Debug, Clone)]
1449#[argh(subcommand, name = "rm-def")]
1450/// delete a definition
1451pub struct EditRmDefCommand {
1452  /// target in format "namespace/definition"
1453  #[argh(positional)]
1454  pub target: String,
1455}
1456
1457#[derive(FromArgs, PartialEq, Debug, Clone)]
1458#[argh(subcommand, name = "meta")]
1459/// update definition metadata (`doc`, `tags`, `examples`, `tests` removals)
1460pub struct EditMetaCommand {
1461  /// target in format "namespace/definition"
1462  #[argh(positional)]
1463  pub target: String,
1464  /// set definition documentation text verbatim
1465  #[argh(option)]
1466  pub doc: Option<String>,
1467  /// replace tags with a comma-separated list (pass "" to clear)
1468  #[argh(option)]
1469  pub tags: Option<String>,
1470  /// add a tag (repeatable)
1471  #[argh(option, long = "add-tag")]
1472  pub add_tags: Vec<String>,
1473  /// remove a tag (repeatable)
1474  #[argh(option, long = "rm-tag")]
1475  pub rm_tags: Vec<String>,
1476  /// clear all tags
1477  #[argh(switch, long = "clear-tags")]
1478  pub clear_tags: bool,
1479  /// replace all examples from --file, --code, or stdin (one top-level quote per example)
1480  #[argh(switch, long = "examples")]
1481  pub examples: bool,
1482  /// append or insert one example from --file, --code, or stdin
1483  #[argh(switch, long = "add-example")]
1484  pub add_example: bool,
1485  /// insertion index for --add-example (default: append to end)
1486  #[argh(option, long = "at")]
1487  pub at: Option<usize>,
1488  /// clear all examples
1489  #[argh(switch, long = "clear-examples")]
1490  pub clear_examples: bool,
1491  /// read example payload from file (used with --examples or --add-example)
1492  #[argh(option)]
1493  pub file: Option<String>,
1494  /// inline example payload (used with --examples or --add-example)
1495  #[argh(option, long = "code")]
1496  pub code: Option<String>,
1497  /// syntax-node transport format for --add-example: cirru, json-ast, or compatibility mode auto
1498  #[argh(option, long = "input-format", default = "SyntaxInputFormat::Auto")]
1499  pub input_format: SyntaxInputFormat,
1500  /// remove a named test from the definition (repeatable)
1501  #[argh(option, long = "rm-test")]
1502  pub rm_tests: Vec<String>,
1503  /// require snapshot content to match this revision before writing
1504  #[argh(option, long = "expect-revision")]
1505  pub expect_revision: Option<String>,
1506  /// preview metadata changes without writing the snapshot
1507  #[argh(switch, long = "dry-run")]
1508  pub dry_run: bool,
1509  /// output format: human (default), edn (primary structured data), or json (interoperability)
1510  #[argh(option, default = "String::from(\"human\")")]
1511  pub format: String,
1512}
1513
1514#[derive(FromArgs, PartialEq, Debug, Clone)]
1515#[argh(subcommand, name = "schema")]
1516/// update definition schema (input via --file, --code, or pipe via stdin; validates structure before writing)
1517pub struct EditSchemaCommand {
1518  /// target in format "namespace/definition"
1519  #[argh(positional)]
1520  pub target: String,
1521  /// read one quoted Cirru type node from file
1522  #[argh(option)]
1523  pub file: Option<String>,
1524  /// one quoted Cirru type node; core Option/Result may be short, project nominal types must be qualified
1525  #[argh(option, long = "code")]
1526  pub code: Option<String>,
1527  /// syntax-node transport format: cirru, json-ast, or compatibility mode auto
1528  #[argh(option, long = "input-format", default = "SyntaxInputFormat::Auto")]
1529  pub input_format: SyntaxInputFormat,
1530  /// remove the schema declaration; does not declare Dynamic or bypass strict checking
1531  #[argh(switch, long = "clear")]
1532  pub clear: bool,
1533  /// add a feature (js-ffi, erased-cache, state or io) to an existing structured Fn schema without replacing its signature
1534  #[argh(option, long = "add-feature")]
1535  pub add_feature: Option<String>,
1536}
1537
1538#[derive(FromArgs, PartialEq, Debug, Clone)]
1539#[argh(subcommand, name = "ffi")]
1540/// update optional host FFI metadata stored on a CodeEntry
1541pub struct EditFfiCommand {
1542  /// target in format "namespace/definition"
1543  #[argh(positional)]
1544  pub target: String,
1545  /// read a Cirru EDN map from file
1546  #[argh(option)]
1547  pub file: Option<String>,
1548  /// FFI metadata as Cirru EDN map
1549  #[argh(option, long = "code")]
1550  pub code: Option<String>,
1551  /// clear FFI metadata
1552  #[argh(switch, long = "clear")]
1553  pub clear: bool,
1554}
1555
1556#[derive(FromArgs, PartialEq, Debug, Clone)]
1557#[argh(subcommand, name = "add-test")]
1558/// add a named test to a definition (input via --file, --code, or pipe via stdin)
1559pub struct EditAddTestCommand {
1560  /// target in format "namespace/definition"
1561  #[argh(positional)]
1562  pub target: String,
1563  /// stable test name, unique within the definition
1564  #[argh(positional)]
1565  pub name: String,
1566  /// comma-separated test tags
1567  #[argh(option)]
1568  pub tags: Option<String>,
1569  /// read test expression from file
1570  #[argh(option)]
1571  pub file: Option<String>,
1572  /// test expression as inline text
1573  #[argh(option, long = "code")]
1574  pub code: Option<String>,
1575  /// syntax-node transport format: cirru, json-ast, or compatibility mode auto
1576  #[argh(option, long = "input-format", default = "SyntaxInputFormat::Auto")]
1577  pub input_format: SyntaxInputFormat,
1578  /// replace an existing test with the same name
1579  #[argh(switch, long = "overwrite")]
1580  pub overwrite: bool,
1581}
1582
1583// --- Namespace operations ---
1584
1585#[derive(FromArgs, PartialEq, Debug, Clone)]
1586#[argh(subcommand, name = "add-ns")]
1587/// add a new namespace (optional ns syntax via --file, --code, or stdin)
1588pub struct EditAddNsCommand {
1589  /// namespace name to create
1590  #[argh(positional)]
1591  pub namespace: String,
1592  /// read ns syntax_tree from file; select its transport with --input-format
1593  #[argh(option)]
1594  pub file: Option<String>,
1595  /// ns syntax_tree as inline text; select its transport with --input-format
1596  #[argh(option, long = "code")]
1597  pub code: Option<String>,
1598  /// syntax-node transport format: cirru, json-ast, or compatibility mode auto
1599  #[argh(option, long = "input-format", default = "SyntaxInputFormat::Auto")]
1600  pub input_format: SyntaxInputFormat,
1601}
1602
1603#[derive(FromArgs, PartialEq, Debug, Clone)]
1604#[argh(subcommand, name = "rm-ns")]
1605/// delete a namespace
1606pub struct EditRmNsCommand {
1607  /// namespace to delete
1608  #[argh(positional)]
1609  pub namespace: String,
1610}
1611
1612#[derive(FromArgs, PartialEq, Debug, Clone)]
1613#[argh(subcommand, name = "ns")]
1614/// write back the `%{} 'FileEntry` data from `query ns <ns> --format cirru`: validate it with the Snapshot loader, compare per
1615/// definition, and write only added or changed definitions (input via --file, --code, or pipe via stdin)
1616pub struct EditNsCommand {
1617  /// namespace whose `:files` entry the data replaces
1618  #[argh(positional)]
1619  pub namespace: String,
1620  /// read the namespace data from file
1621  #[argh(option)]
1622  pub file: Option<String>,
1623  /// namespace data as inline text
1624  #[argh(option, long = "code")]
1625  pub code: Option<String>,
1626  /// require the snapshot content (or a scoped revision from a dry-run) to match before writing
1627  #[argh(option, long = "expect-revision")]
1628  pub expect_revision: Option<String>,
1629  /// compare and validate without replacing the snapshot
1630  #[argh(switch, long = "dry-run")]
1631  pub dry_run: bool,
1632  /// delete definitions that are missing from the data
1633  #[argh(switch, long = "allow-remove")]
1634  pub allow_remove: bool,
1635  /// allow unrecognized definition heads in changed or added definitions; shape and name checks still apply
1636  #[argh(switch, long = "allow-unknown-head")]
1637  pub allow_unknown_head: bool,
1638  /// output format: human (default), edn (primary structured data), or json (interoperability)
1639  #[argh(option, default = "String::from(\"human\")")]
1640  pub format: String,
1641}
1642
1643#[derive(FromArgs, PartialEq, Debug, Clone)]
1644#[argh(subcommand, name = "imports")]
1645/// update namespace imports — replaces all (input via --file, --code, or pipe via stdin)
1646pub struct EditImportsCommand {
1647  /// namespace to update
1648  #[argh(positional)]
1649  pub namespace: String,
1650  /// read one imports-vector syntax node from file; select its transport with --input-format
1651  #[argh(option)]
1652  pub file: Option<String>,
1653  /// one imports-vector syntax node as inline text; select its transport with --input-format
1654  #[argh(option, long = "code")]
1655  pub code: Option<String>,
1656  /// syntax-node transport format: cirru, json-ast, or compatibility mode auto
1657  #[argh(option, long = "input-format", default = "SyntaxInputFormat::Auto")]
1658  pub input_format: SyntaxInputFormat,
1659}
1660
1661#[derive(FromArgs, PartialEq, Debug, Clone)]
1662#[argh(subcommand, name = "add-import")]
1663/// add a single import rule to namespace (input via --file, --code, or pipe via stdin)
1664pub struct EditAddImportCommand {
1665  /// namespace to add import rule to
1666  #[argh(positional)]
1667  pub namespace: String,
1668  /// read one import-rule node from file; select its transport with --input-format
1669  #[argh(option)]
1670  pub file: Option<String>,
1671  /// one import-rule node as inline text; select its transport with --input-format
1672  #[argh(option, long = "code")]
1673  pub code: Option<String>,
1674  /// syntax-node transport format: cirru, json-ast, or compatibility mode auto
1675  #[argh(option, long = "input-format", default = "SyntaxInputFormat::Auto")]
1676  pub input_format: SyntaxInputFormat,
1677  /// overwrite existing rule for the same source namespace
1678  #[argh(switch, long = "overwrite")]
1679  pub overwrite: bool,
1680}
1681
1682#[derive(FromArgs, PartialEq, Debug, Clone)]
1683#[argh(subcommand, name = "rm-import")]
1684/// remove an import rule from namespace
1685pub struct EditRmImportCommand {
1686  /// namespace to remove import rule from
1687  #[argh(positional)]
1688  pub namespace: String,
1689  /// source namespace to remove (e.g. "calcit.core")
1690  #[argh(positional)]
1691  pub source_ns: String,
1692}
1693
1694// ========================================================================
1695// Code command - fine-grained code tree operations
1696// ========================================================================
1697
1698#[derive(FromArgs, PartialEq, Debug, Clone)]
1699#[argh(subcommand, name = "tree")]
1700/// fine-grained code tree operations (view and modify AST nodes)
1701pub struct TreeCommand {
1702  #[argh(subcommand)]
1703  pub subcommand: TreeSubcommand,
1704}
1705
1706#[derive(FromArgs, PartialEq, Debug, Clone)]
1707#[argh(subcommand)]
1708pub enum TreeSubcommand {
1709  Show(TreeShowCommand),
1710  Replace(TreeReplaceCommand),
1711  ReplaceLeaf(TreeReplaceLeafCommand),
1712  Delete(TreeDeleteCommand),
1713  Insert(TreeInsertCommand),
1714  Swap(TreeSwapCommand),
1715  Unwrap(TreeUnwrapCommand),
1716  Raise(TreeRaiseCommand),
1717  Wrap(TreeWrapCommand),
1718  SearchReplace(TreeSearchReplaceCommand),
1719  Rewrite(TreeStructuralCommand),
1720}
1721
1722/// view tree node at specific path
1723#[derive(FromArgs, PartialEq, Debug, Clone)]
1724#[argh(subcommand, name = "show")]
1725pub struct TreeShowCommand {
1726  /// target in format "namespace/definition"
1727  #[argh(positional)]
1728  pub target: String,
1729  /// path to the node (dot-separated preferred; e.g. "@2.1.0"); omit to show from root
1730  #[argh(option)]
1731  pub path: Option<String>,
1732  /// max depth for result preview (0 = unlimited, default 2)
1733  #[argh(option, default = "2")]
1734  pub depth: usize,
1735  /// output format: Markdown-compatible human (default), edn, or json (the selected node as a JSON AST document)
1736  #[argh(option, default = "String::from(\"human\")")]
1737  pub format: String,
1738  /// preferred nodes per display fragment when large expressions are chunked
1739  #[argh(option, default = "56")]
1740  pub chunk_target_nodes: usize,
1741  /// stop recursive chunk splitting once fragments fall below this node count
1742  #[argh(option, default = "68")]
1743  pub chunk_max_nodes: usize,
1744  /// only enable chunked display when total expression nodes reach this threshold
1745  #[argh(option, default = "88")]
1746  pub chunk_trigger_nodes: usize,
1747  /// nested chunk layers to expand beyond ROOT (default 1 shows ROOT + direct chunks only)
1748  #[argh(option, default = "1")]
1749  pub chunk_expand_depth: usize,
1750  /// force raw subtree display without chunking
1751  #[argh(switch)]
1752  pub raw: bool,
1753  /// annotate each nested list with its path index
1754  #[argh(switch)]
1755  pub path_annotations: bool,
1756}
1757
1758/// rename a definition within its namespace (no overwrite)
1759#[derive(FromArgs, PartialEq, Debug, Clone)]
1760#[argh(subcommand, name = "rename")]
1761pub struct EditRenameCommand {
1762  /// source in format "namespace/definition"
1763  #[argh(positional)]
1764  pub source: String,
1765  /// new definition name (within same namespace)
1766  #[argh(positional)]
1767  pub new_name: String,
1768}
1769
1770/// extract a sub-expression into a new definition and replace the original location with the new name
1771#[derive(FromArgs, PartialEq, Debug, Clone)]
1772#[argh(subcommand, name = "split-def")]
1773pub struct EditSplitDefCommand {
1774  /// source definition in format "namespace/definition"
1775  #[argh(positional)]
1776  pub target: String,
1777  /// path to the node to extract (dot-separated coordinates, e.g. "@3.2.1")
1778  #[argh(option, long = "path")]
1779  pub path: String,
1780  /// name for the new extracted definition (within the same namespace)
1781  #[argh(option, long = "name")]
1782  pub new_name: String,
1783}
1784
1785/// rewrite node using references; requires `--with name=path` (use `replace` if no references)
1786#[derive(FromArgs, PartialEq, Debug, Clone)]
1787#[argh(subcommand, name = "rewrite")]
1788pub struct TreeStructuralCommand {
1789  /// target in format "namespace/definition"
1790  #[argh(positional)]
1791  pub target: String,
1792  /// path to the node (dot-separated coordinates, e.g. "@2.1.0")
1793  #[argh(option)]
1794  pub path: String,
1795  /// read syntax_tree from file; select its transport with --input-format
1796  #[argh(option)]
1797  pub file: Option<String>,
1798  /// syntax_tree as inline text; select its transport with --input-format
1799  #[argh(option, long = "code")]
1800  pub code: Option<String>,
1801  /// syntax-node transport format: cirru, json-ast, or compatibility mode auto
1802  #[argh(option, long = "input-format", default = "SyntaxInputFormat::Auto")]
1803  pub input_format: SyntaxInputFormat,
1804  /// bind placeholder to original-node path: `--with self=.` , `--with rhs=2`
1805  #[argh(option, long = "with")]
1806  pub with: Vec<String>,
1807  /// max depth for result preview (0 = unlimited, default 2)
1808  #[argh(option, default = "2")]
1809  pub depth: usize,
1810}
1811
1812/// find unique leaf node and replace it; if multiple found, returns error with helpful hints
1813#[derive(FromArgs, PartialEq, Debug, Clone)]
1814#[argh(subcommand, name = "search-replace")]
1815pub struct TreeSearchReplaceCommand {
1816  /// target in format "namespace/definition"
1817  #[argh(positional)]
1818  pub target: String,
1819  /// pattern to search for (exact match on leaf nodes by default; use --regex for regex matching)
1820  #[argh(option, long = "pattern")]
1821  pub pattern: String,
1822  /// treat pattern as a regular expression for matching leaf nodes
1823  #[argh(switch, long = "regex")]
1824  pub regex: bool,
1825  /// read syntax_tree from file; select its transport with --input-format
1826  #[argh(option)]
1827  pub file: Option<String>,
1828  /// syntax_tree as inline text; select its transport with --input-format
1829  #[argh(option, long = "code")]
1830  pub code: Option<String>,
1831  /// syntax-node transport format: cirru, json-ast, or compatibility mode auto
1832  #[argh(option, long = "input-format", default = "SyntaxInputFormat::Auto")]
1833  pub input_format: SyntaxInputFormat,
1834  /// max depth for result preview (0 = unlimited, default 2)
1835  #[argh(option, default = "2")]
1836  pub depth: usize,
1837  /// pick the Nth candidate (0-based) when multiple matches are found
1838  #[argh(option, long = "pick")]
1839  pub pick: Option<usize>,
1840  /// semantic path expression to narrow search scope
1841  /// e.g. "path heading def {} :name |add nth 2 heading let nth 0"
1842  #[argh(option, long = "selector")]
1843  pub selector: Option<String>,
1844}
1845
1846/// replace node at specific path
1847#[derive(FromArgs, PartialEq, Debug, Clone)]
1848#[argh(subcommand, name = "replace")]
1849pub struct TreeReplaceCommand {
1850  /// target in format "namespace/definition"
1851  #[argh(positional)]
1852  pub target: String,
1853  /// path to the node (dot-separated coordinates, e.g. "@2.1.0")
1854  #[argh(option)]
1855  pub path: String,
1856  /// read syntax_tree from file; select its transport with --input-format
1857  #[argh(option)]
1858  pub file: Option<String>,
1859  /// syntax_tree as inline text; select its transport with --input-format
1860  #[argh(option, long = "code")]
1861  pub code: Option<String>,
1862  /// syntax-node transport format: cirru, json-ast, or compatibility mode auto
1863  #[argh(option, long = "input-format", default = "SyntaxInputFormat::Auto")]
1864  pub input_format: SyntaxInputFormat,
1865  /// require the current node to equal this quoted Cirru node before replacing
1866  #[argh(option)]
1867  pub expect: Option<String>,
1868  /// max depth for result preview (0 = unlimited, default 2)
1869  #[argh(option, default = "2")]
1870  pub depth: usize,
1871}
1872
1873/// find and replace all matching leaf nodes in definition (no path needed)
1874#[derive(FromArgs, PartialEq, Debug, Clone)]
1875#[argh(subcommand, name = "replace-leaf")]
1876pub struct TreeReplaceLeafCommand {
1877  /// target in format "namespace/definition"
1878  #[argh(positional)]
1879  pub target: String,
1880  /// pattern to search for (exact match on leaf nodes by default; use --regex for regex matching)
1881  #[argh(option, long = "pattern")]
1882  pub pattern: String,
1883  /// treat pattern as a regular expression for matching leaf nodes
1884  #[argh(switch, long = "regex")]
1885  pub regex: bool,
1886  /// read syntax_tree from file; select its transport with --input-format
1887  #[argh(option)]
1888  pub file: Option<String>,
1889  /// syntax_tree as inline text; select its transport with --input-format
1890  #[argh(option, long = "code")]
1891  pub code: Option<String>,
1892  /// syntax-node transport format: cirru, json-ast, or compatibility mode auto
1893  #[argh(option, long = "input-format", default = "SyntaxInputFormat::Auto")]
1894  pub input_format: SyntaxInputFormat,
1895  /// max depth for result preview (0 = unlimited, default 2)
1896  #[argh(option, default = "2")]
1897  pub depth: usize,
1898}
1899
1900/// delete node at specific path
1901#[derive(FromArgs, PartialEq, Debug, Clone)]
1902#[argh(subcommand, name = "delete")]
1903pub struct TreeDeleteCommand {
1904  /// target in format "namespace/definition"
1905  #[argh(positional)]
1906  pub target: String,
1907  /// path to the node (dot-separated coordinates, e.g. "@2.1.0")
1908  #[argh(option)]
1909  pub path: String,
1910  /// require the node at path to equal this quoted Cirru node before deleting
1911  #[argh(option)]
1912  pub expect: Option<String>,
1913  /// max depth for result preview (0 = unlimited, default 2)
1914  #[argh(option, default = "2")]
1915  pub depth: usize,
1916}
1917
1918/// insert node relative to the target at a path: --at before, after, prepend-child, or append-child
1919#[derive(FromArgs, PartialEq, Debug, Clone)]
1920#[argh(subcommand, name = "insert")]
1921pub struct TreeInsertCommand {
1922  /// target in format "namespace/definition"
1923  #[argh(positional)]
1924  pub target: String,
1925  /// path to the anchor node (dot-separated coordinates, e.g. "@2.1.0")
1926  #[argh(option)]
1927  pub path: String,
1928  /// insert position relative to the anchor: before, after, prepend-child, or append-child
1929  #[argh(option)]
1930  pub at: String,
1931  /// read syntax_tree from file; select its transport with --input-format
1932  #[argh(option)]
1933  pub file: Option<String>,
1934  /// syntax_tree as inline text; select its transport with --input-format
1935  #[argh(option, long = "code")]
1936  pub code: Option<String>,
1937  /// syntax-node transport format: cirru, json-ast, or compatibility mode auto
1938  #[argh(option, long = "input-format", default = "SyntaxInputFormat::Auto")]
1939  pub input_format: SyntaxInputFormat,
1940  /// require the anchor node to equal this quoted Cirru node before inserting
1941  #[argh(option)]
1942  pub expect: Option<String>,
1943  /// max depth for result preview (0 = unlimited, default 2)
1944  #[argh(option, default = "2")]
1945  pub depth: usize,
1946}
1947
1948/// swap node with a sibling: --with next or prev
1949#[derive(FromArgs, PartialEq, Debug, Clone)]
1950#[argh(subcommand, name = "swap")]
1951pub struct TreeSwapCommand {
1952  /// target in format "namespace/definition"
1953  #[argh(positional)]
1954  pub target: String,
1955  /// path to the node (dot-separated coordinates, e.g. "@2.1.0")
1956  #[argh(option)]
1957  pub path: String,
1958  /// sibling to swap with: next or prev
1959  #[argh(option, long = "with")]
1960  pub with: String,
1961  /// max depth for result preview (0 = unlimited, default 2)
1962  #[argh(option, default = "2")]
1963  pub depth: usize,
1964}
1965
1966/// splice all children of a node into its parent (inverse of wrap/rewrite)
1967#[derive(FromArgs, PartialEq, Debug, Clone)]
1968#[argh(subcommand, name = "unwrap")]
1969pub struct TreeUnwrapCommand {
1970  /// target in format "namespace/definition"
1971  #[argh(positional)]
1972  pub target: String,
1973  /// path to the node to unwrap (dot-separated coordinates, e.g. "@2.1.0")
1974  #[argh(option)]
1975  pub path: String,
1976  /// max depth for result preview (0 = unlimited, default 2)
1977  #[argh(option, default = "2")]
1978  pub depth: usize,
1979}
1980
1981/// replace the parent node with this child node (Paredit raise-sexp)
1982#[derive(FromArgs, PartialEq, Debug, Clone)]
1983#[argh(subcommand, name = "raise")]
1984pub struct TreeRaiseCommand {
1985  /// target in format "namespace/definition"
1986  #[argh(positional)]
1987  pub target: String,
1988  /// path to the child node to raise (must have at least one element; its parent will be replaced)
1989  #[argh(option)]
1990  pub path: String,
1991  /// max depth for result preview (0 = unlimited, default 2)
1992  #[argh(option, default = "2")]
1993  pub depth: usize,
1994}
1995
1996/// wrap the node at path inside a new expression, using `self` as placeholder for the original node
1997#[derive(FromArgs, PartialEq, Debug, Clone)]
1998#[argh(subcommand, name = "wrap")]
1999pub struct TreeWrapCommand {
2000  /// target in format "namespace/definition"
2001  #[argh(positional)]
2002  pub target: String,
2003  /// path to the node to wrap (dot-separated coordinates, e.g. "@2.1.0")
2004  #[argh(option)]
2005  pub path: String,
2006  /// wrapping expression with `self` as placeholder for the original node (e.g. 'println self')
2007  #[argh(option, long = "code")]
2008  pub code: Option<String>,
2009  /// read wrapping expression from file; select its transport with --input-format
2010  #[argh(option)]
2011  pub file: Option<String>,
2012  /// syntax-node transport format: cirru, json-ast, or compatibility mode auto
2013  #[argh(option, long = "input-format", default = "SyntaxInputFormat::Auto")]
2014  pub input_format: SyntaxInputFormat,
2015  /// max depth for result preview (0 = unlimited, default 2)
2016  #[argh(option, default = "2")]
2017  pub depth: usize,
2018}
2019
2020// ========================================================================
2021// Cursor command - persistent virtual tree selection
2022// ========================================================================
2023
2024#[derive(FromArgs, PartialEq, Debug, Clone)]
2025#[argh(subcommand, name = "cursor")]
2026/// maintain the project-local virtual tree cursor
2027pub struct CursorCommand {
2028  #[argh(subcommand)]
2029  pub subcommand: CursorSubcommand,
2030}
2031
2032#[derive(FromArgs, PartialEq, Debug, Clone)]
2033#[argh(subcommand)]
2034pub enum CursorSubcommand {
2035  Set(CursorSetCommand),
2036  Show(CursorShowCommand),
2037  Clear(CursorClearCommand),
2038  Move(CursorMoveCommand),
2039  Apply(CursorApplyCommand),
2040}
2041
2042#[derive(FromArgs, PartialEq, Debug, Clone)]
2043#[argh(subcommand, name = "set")]
2044/// set the virtual cursor to a definition tree path
2045pub struct CursorSetCommand {
2046  /// target in format "namespace/definition"
2047  #[argh(positional)]
2048  pub target: String,
2049  /// path to the selected node (dot-separated, e.g. "@2.1.0")
2050  #[argh(option)]
2051  pub path: String,
2052}
2053
2054#[derive(FromArgs, PartialEq, Debug, Clone)]
2055#[argh(subcommand, name = "show")]
2056/// validate and display the current virtual cursor
2057pub struct CursorShowCommand {
2058  /// output format: human (default), edn, or json
2059  #[argh(option, default = "String::from(\"human\")")]
2060  pub format: String,
2061  /// preview view: focus (default), node, or full
2062  #[argh(option, default = "String::from(\"focus\")")]
2063  pub view: String,
2064}
2065
2066#[derive(FromArgs, PartialEq, Debug, Clone)]
2067#[argh(subcommand, name = "clear")]
2068/// remove the current virtual cursor
2069pub struct CursorClearCommand {}
2070
2071#[derive(FromArgs, PartialEq, Debug, Clone)]
2072#[argh(subcommand, name = "move")]
2073/// move the virtual cursor: parent, child [INDEX] [--last], next, prev, forward, backward, or back
2074pub struct CursorMoveCommand {
2075  /// direction: parent, child, next, prev, forward, backward, or back
2076  #[argh(positional)]
2077  pub direction: String,
2078  /// zero-based child index for `child` (defaults to the first child)
2079  #[argh(positional)]
2080  pub index: Option<usize>,
2081  /// enter the last child (only with `child`)
2082  #[argh(switch)]
2083  pub last: bool,
2084  /// steps for next, prev, forward, backward, or back (default 1)
2085  #[argh(option)]
2086  pub count: Option<usize>,
2087}
2088
2089#[derive(FromArgs, PartialEq, Debug, Clone)]
2090#[argh(subcommand, name = "apply")]
2091/// apply a structural tree operation to the active cursor without repeating target or path
2092pub struct CursorApplyCommand {
2093  /// operation: delete, swap-next, swap-prev, unwrap (alias splice), raise, replace, wrap, insert-before, insert-after, insert-child, append-child, slurp-next, slurp-prev, barf-last, barf-first, duplicate
2094  #[argh(positional)]
2095  pub operation: String,
2096  /// read the replacement, wrapper, or inserted expression from a file
2097  #[argh(option)]
2098  pub file: Option<String>,
2099  /// replacement, wrapper, or inserted syntax; select its transport with --input-format
2100  #[argh(option, long = "code")]
2101  pub code: Option<String>,
2102  /// syntax-node transport format: cirru, json-ast, or compatibility mode auto
2103  #[argh(option, long = "input-format", default = "SyntaxInputFormat::Auto")]
2104  pub input_format: SyntaxInputFormat,
2105  /// max depth for the underlying tree command result preview
2106  #[argh(option, default = "2")]
2107  pub depth: usize,
2108  /// position of the new copy for `duplicate`: before or after (default)
2109  #[argh(option)]
2110  pub at: Option<String>,
2111}
2112
2113// ═══════════════════════════════════════════════════════════════════════════════
2114// Config command — top-level shortcut for configuration management
2115// ═══════════════════════════════════════════════════════════════════════════════
2116
2117/// manage project configuration
2118#[derive(FromArgs, PartialEq, Debug, Clone)]
2119#[argh(subcommand, name = "config")]
2120pub struct ConfigCommand {
2121  #[argh(subcommand)]
2122  pub subcommand: ConfigSubcommand,
2123}
2124
2125#[derive(FromArgs, PartialEq, Debug, Clone)]
2126#[argh(subcommand)]
2127pub enum ConfigSubcommand {
2128  /// show project configuration values and entries
2129  Show(ConfigShowCommand),
2130  /// list modules included in the project
2131  Modules(ConfigModulesCommand),
2132  /// list entry-level type-slot bindings
2133  TypeSlots(ConfigTypeSlotsCommand),
2134  /// set a configuration key to a value (package, mode, target, init-fn, reload-fn, description, feature-policy.<name>); use caps version for project versions
2135  Set(ConfigSetCommand),
2136  /// unset target, or remove a named entry with an explicit --entry
2137  Unset(ConfigUnsetCommand),
2138  /// create a named entry with a complete configuration, or clone one with --from
2139  AddEntry(ConfigAddEntryCommand),
2140  /// add a module path to an entry's modules
2141  AddModule(ConfigAddModuleCommand),
2142  /// remove a module path from an entry's modules
2143  RmModule(ConfigRmModuleCommand),
2144  /// bind a type slot to a full namespace/definition path
2145  SetTypeSlot(ConfigSetTypeSlotCommand),
2146  /// remove an entry-level type-slot binding
2147  RmTypeSlot(ConfigRmTypeSlotCommand),
2148}
2149
2150#[derive(FromArgs, PartialEq, Debug, Clone)]
2151#[argh(subcommand, name = "show")]
2152/// show project configuration values and entries
2153pub struct ConfigShowCommand {
2154  /// show a named entry (e.g. "test"); defaults to showing all entries
2155  #[argh(option)]
2156  pub entry: Option<String>,
2157  /// output format: human (default), edn, or json
2158  #[argh(option, default = "String::from(\"human\")")]
2159  pub format: String,
2160}
2161
2162#[derive(FromArgs, PartialEq, Debug, Clone)]
2163#[argh(subcommand, name = "modules")]
2164/// list modules included in the project
2165pub struct ConfigModulesCommand {
2166  /// list modules for a named entry (e.g. "test"); defaults to "default"
2167  #[argh(option)]
2168  pub entry: Option<String>,
2169  /// output format: human (default), edn, or json
2170  #[argh(option, default = "String::from(\"human\")")]
2171  pub format: String,
2172}
2173
2174#[derive(FromArgs, PartialEq, Debug, Clone)]
2175#[argh(subcommand, name = "type-slots")]
2176/// list entry-level type-slot bindings
2177pub struct ConfigTypeSlotsCommand {
2178  /// list bindings for a named entry; defaults to "default"
2179  #[argh(option)]
2180  pub entry: Option<String>,
2181  /// output format: human (default), edn, or json
2182  #[argh(option, default = "String::from(\"human\")")]
2183  pub format: String,
2184}
2185
2186#[derive(FromArgs, PartialEq, Debug, Clone)]
2187#[argh(subcommand, name = "set")]
2188/// set a configuration key (package, mode, target, init-fn, reload-fn, description, feature-policy.<name>); use caps version for project versions
2189pub struct ConfigSetCommand {
2190  /// apply to a named entry (e.g. "test"); defaults to "default"; package is project-level and rejects --entry
2191  #[argh(option)]
2192  pub entry: Option<String>,
2193  /// config key: package, mode, target, init-fn, reload-fn, description, feature-policy.<name>; project versions use caps version
2194  #[argh(positional)]
2195  pub key: String,
2196  /// config value; package is a namespace prefix; target accepts browser|node|native|wasm
2197  #[argh(positional)]
2198  pub value: String,
2199}
2200
2201#[derive(FromArgs, PartialEq, Debug, Clone)]
2202#[argh(subcommand, name = "unset")]
2203/// unset target, or remove a named entry with an explicit --entry
2204pub struct ConfigUnsetCommand {
2205  /// entry to change; defaults to "default" for target, required and non-default for entry removal
2206  #[argh(option)]
2207  pub entry: Option<String>,
2208  /// config key to unset: target or entry; entry removes the entire named configuration
2209  #[argh(positional)]
2210  pub key: String,
2211}
2212
2213#[derive(FromArgs, PartialEq, Debug, Clone)]
2214#[argh(subcommand, name = "add-entry")]
2215/// create a named entry; without --from, --mode, --init-fn and --reload-fn are required
2216pub struct ConfigAddEntryCommand {
2217  /// name of the new entry; must not exist yet
2218  #[argh(positional)]
2219  pub name: String,
2220  /// copy every field (modules, type slots, feature policy included) from an existing entry
2221  #[argh(option)]
2222  pub from: Option<String>,
2223  /// run mode: native or js
2224  #[argh(option)]
2225  pub mode: Option<String>,
2226  /// host target: browser, node, native or wasm
2227  #[argh(option)]
2228  pub target: Option<String>,
2229  /// init function as a full namespace/definition path
2230  #[argh(option)]
2231  pub init_fn: Option<String>,
2232  /// reload function as a full namespace/definition path
2233  #[argh(option)]
2234  pub reload_fn: Option<String>,
2235  /// human-readable purpose of the entry
2236  #[argh(option)]
2237  pub description: Option<String>,
2238}
2239
2240#[derive(FromArgs, PartialEq, Debug, Clone)]
2241#[argh(subcommand, name = "add-module")]
2242/// add a module path to an entry
2243pub struct ConfigAddModuleCommand {
2244  /// add to a named entry (e.g. "test"); defaults to "default"
2245  #[argh(option)]
2246  pub entry: Option<String>,
2247  /// module path to add (e.g. "calcit-test/")
2248  #[argh(positional)]
2249  pub module_path: String,
2250}
2251
2252#[derive(FromArgs, PartialEq, Debug, Clone)]
2253#[argh(subcommand, name = "rm-module")]
2254/// remove a module path from an entry
2255pub struct ConfigRmModuleCommand {
2256  /// remove from a named entry (e.g. "test"); defaults to "default"
2257  #[argh(option)]
2258  pub entry: Option<String>,
2259  /// module path to remove
2260  #[argh(positional)]
2261  pub module_path: String,
2262}
2263
2264#[derive(FromArgs, PartialEq, Debug, Clone)]
2265#[argh(subcommand, name = "set-type-slot")]
2266/// bind a type slot to a full namespace/definition path
2267pub struct ConfigSetTypeSlotCommand {
2268  /// apply to a named entry; defaults to "default"
2269  #[argh(option)]
2270  pub entry: Option<String>,
2271  /// slot name, with or without a leading colon
2272  #[argh(positional)]
2273  pub slot: String,
2274  /// full namespace/definition type path, or :dynamic
2275  #[argh(positional)]
2276  pub type_path: String,
2277}
2278
2279#[derive(FromArgs, PartialEq, Debug, Clone)]
2280#[argh(subcommand, name = "rm-type-slot")]
2281/// remove an entry-level type-slot binding
2282pub struct ConfigRmTypeSlotCommand {
2283  /// remove from a named entry; defaults to "default"
2284  #[argh(option)]
2285  pub entry: Option<String>,
2286  /// slot name, with or without a leading colon
2287  #[argh(positional)]
2288  pub slot: String,
2289}
2290
2291#[cfg(test)]
2292mod wasm_command_tests {
2293  use super::*;
2294
2295  #[test]
2296  fn parses_config_unset_target() {
2297    let parsed = ToplevelCalcit::from_args(&["calcit"], &["config", "unset", "target"]).expect("parse config unset");
2298    let Some(CalcitCommand::Config(cmd)) = parsed.subcommand else {
2299      panic!("expected config subcommand");
2300    };
2301    let ConfigSubcommand::Unset(opts) = cmd.subcommand else {
2302      panic!("expected config unset subcommand");
2303    };
2304    assert_eq!(opts.entry, None);
2305    assert_eq!(opts.key, "target");
2306
2307    let named = ToplevelCalcit::from_args(&["calcit"], &["config", "unset", "--entry", "server", "target"]).expect("parse named unset");
2308    let Some(CalcitCommand::Config(cmd)) = named.subcommand else {
2309      panic!("expected config subcommand");
2310    };
2311    let ConfigSubcommand::Unset(opts) = cmd.subcommand else {
2312      panic!("expected config unset subcommand");
2313    };
2314    assert_eq!(opts.entry.as_deref(), Some("server"));
2315  }
2316
2317  #[test]
2318  fn parses_public_wasm_commands_with_distinct_targets() {
2319    let wasm = ToplevelCalcit::from_args(&["calcit"], &["wasm", "app.cirru", "--emit-path", "target/core", "--check-only"])
2320      .expect("parse calcit wasm");
2321    let Some(CalcitCommand::EmitWasm(options)) = wasm.subcommand else {
2322      panic!("expected wasm subcommand");
2323    };
2324    assert_eq!(options.input.as_deref(), Some("app.cirru"));
2325    assert_eq!(options.emit_path.as_deref(), Some("target/core"));
2326    assert_eq!(options.boundary, "native");
2327    assert!(options.check_only);
2328
2329    let component =
2330      ToplevelCalcit::from_args(&["calcit"], &["wasm", "app.cirru", "--boundary", "component"]).expect("parse component boundary");
2331    let Some(CalcitCommand::EmitWasm(options)) = component.subcommand else {
2332      panic!("expected wasm subcommand");
2333    };
2334    assert_eq!(options.boundary, "component");
2335
2336    let wasi =
2337      ToplevelCalcit::from_args(&["calcit"], &["wasi", "command.cirru", "--init-fn", "app.main/main!"]).expect("parse calcit wasi");
2338    let Some(CalcitCommand::EmitWasi(options)) = wasi.subcommand else {
2339      panic!("expected wasi subcommand");
2340    };
2341    assert_eq!(options.input.as_deref(), Some("command.cirru"));
2342    assert_eq!(options.init_fn.as_deref(), Some("app.main/main!"));
2343    assert_eq!(options.boundary, "component");
2344    assert_eq!(options.world, "command");
2345    assert!(!options.check_only);
2346
2347    let http = ToplevelCalcit::from_args(&["calcit"], &["wasi", "http.cirru", "--world", "http"]).expect("parse WASI HTTP proxy world");
2348    let Some(CalcitCommand::EmitWasi(options)) = http.subcommand else {
2349      panic!("expected wasi subcommand");
2350    };
2351    assert_eq!(options.boundary, "component");
2352    assert_eq!(options.world, "http");
2353    assert!(!options.emit_core);
2354
2355    let emit_core_http = ToplevelCalcit::from_args(&["calcit"], &["wasi", "http.cirru", "--world", "http", "--emit-core"])
2356      .expect("parse WASI HTTP emit-core flag");
2357    let Some(CalcitCommand::EmitWasi(options)) = emit_core_http.subcommand else {
2358      panic!("expected wasi subcommand");
2359    };
2360    assert_eq!(options.world, "http");
2361    assert!(options.emit_core);
2362
2363    let emit_core_cmd =
2364      ToplevelCalcit::from_args(&["calcit"], &["wasi", "command.cirru", "--emit-core"]).expect("parse WASI command emit-core flag");
2365    let Some(CalcitCommand::EmitWasi(options)) = emit_core_cmd.subcommand else {
2366      panic!("expected wasi subcommand");
2367    };
2368    assert_eq!(options.world, "command");
2369    assert!(options.emit_core);
2370
2371    let preview1 = ToplevelCalcit::from_args(&["calcit"], &["wasi", "command.cirru", "--boundary", "native"])
2372      .expect("parse WASI Preview 1 command boundary");
2373    let Some(CalcitCommand::EmitWasi(options)) = preview1.subcommand else {
2374      panic!("expected wasi subcommand");
2375    };
2376    assert_eq!(options.boundary, "native");
2377  }
2378
2379  #[test]
2380  fn parses_keep_going_check_report_options() {
2381    let command = ToplevelCalcit::from_args(&["calcit"], &["app.cirru", "--check-only", "--keep-going", "--format", "edn"])
2382      .expect("parse keep-going strict check");
2383    assert_eq!(command.input, "app.cirru");
2384    assert!(command.check_only);
2385    assert!(command.keep_going);
2386    assert_eq!(command.format, "edn");
2387  }
2388
2389  #[test]
2390  fn parses_incremental_check_only_option() {
2391    let command =
2392      ToplevelCalcit::from_args(&["calcit"], &["app.cirru", "--check-only", "--incremental"]).expect("parse incremental strict check");
2393    assert_eq!(command.input, "app.cirru");
2394    assert!(command.check_only);
2395    assert!(command.incremental);
2396    assert!(!command.keep_going);
2397  }
2398
2399  #[test]
2400  fn parses_all_defs_check_only_option() {
2401    let command = ToplevelCalcit::from_args(&["calcit"], &["app.cirru", "--check-only", "--all-defs", "--format", "edn"])
2402      .expect("parse all-definitions strict check");
2403    assert!(command.check_only);
2404    assert!(command.all_defs);
2405    assert!(!command.summary_only);
2406    assert_eq!(command.format, "edn");
2407  }
2408
2409  #[test]
2410  fn parses_all_defs_summary_only_check_only_option() {
2411    let command = ToplevelCalcit::from_args(
2412      &["calcit"],
2413      &["app.cirru", "--check-only", "--all-defs", "--summary-only", "--format", "edn"],
2414    )
2415    .expect("parse all-definitions summary-only strict check");
2416    assert!(command.check_only);
2417    assert!(command.all_defs);
2418    assert!(command.summary_only);
2419    assert_eq!(command.format, "edn");
2420  }
2421}