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