logicaffeine_cli/cli.rs
1//! LOGOS CLI (largo) — argument parsing and dispatch.
2//!
3//! This module defines the `largo` command-line surface: the [`Cli`] parser,
4//! the [`Commands`] enum, and [`run_cli`], which dispatches each subcommand
5//! to its handler in `crate::commands`.
6//!
7//! # Architecture
8//!
9//! The CLI is built on [`clap`] for argument parsing with derive macros.
10//! Each command variant in [`Commands`] maps to a handler function in a
11//! dedicated module under `commands/` that performs the actual work.
12//!
13//! # Examples
14//!
15//! ```bash
16//! # Create a new project
17//! largo new my_project
18//!
19//! # Build and run
20//! cd my_project
21//! largo run
22//!
23//! # Publish to registry
24//! largo login
25//! largo publish
26//! ```
27
28use clap::{Parser, Subcommand};
29use std::path::PathBuf;
30
31use crate::commands;
32use crate::ui::{self, ColorMode};
33
34/// Command-line interface for the LOGOS build tool.
35///
36/// The `Cli` struct is the top-level argument parser for `largo`. It delegates
37/// to the [`Commands`] enum for subcommand handling.
38///
39/// # Usage
40///
41/// Typically invoked via [`run_cli`] which parses arguments and dispatches
42/// to the appropriate handler:
43///
44/// ```no_run
45/// use logicaffeine_cli::cli::run_cli;
46///
47/// if let Err(e) = run_cli() {
48/// eprintln!("Error: {}", e);
49/// std::process::exit(1);
50/// }
51/// ```
52/// The version string, flavor-stamped: the full build (Z3 verification
53/// statically linked) reports `X.Y.Z (full)` so installs are diagnosable.
54#[cfg(feature = "verification")]
55const LARGO_VERSION: &str = concat!(env!("CARGO_PKG_VERSION"), " (full)");
56/// The lean build reports the bare version.
57#[cfg(not(feature = "verification"))]
58const LARGO_VERSION: &str = env!("CARGO_PKG_VERSION");
59
60#[derive(Parser)]
61#[command(name = "largo")]
62#[command(about = "The LOGOS build tool", long_about = None)]
63#[command(version = LARGO_VERSION)]
64#[command(arg_required_else_help = true)]
65#[command(styles = ui::CLAP_STYLES)]
66pub struct Cli {
67 /// The subcommand to execute.
68 #[command(subcommand)]
69 pub command: Commands,
70
71 /// Suppress informational output (errors still print).
72 #[arg(long, short, global = true)]
73 pub quiet: bool,
74
75 /// Increase output verbosity (repeatable).
76 #[arg(long, short, global = true, action = clap::ArgAction::Count)]
77 pub verbose: u8,
78
79 /// When to use terminal colors.
80 #[arg(
81 long,
82 global = true,
83 value_enum,
84 default_value = "auto",
85 value_name = "WHEN"
86 )]
87 pub color: ColorMode,
88}
89
90/// The execution tier selected by `largo run --interpret`.
91#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, clap::ValueEnum)]
92pub enum RunEngine {
93 /// Optimized bytecode VM with native JIT tier-up.
94 #[default]
95 Jit,
96 /// Optimized bytecode VM without native tier-up.
97 Vm,
98 /// Optimized tree-walking interpreter.
99 Tree,
100}
101
102impl From<RunEngine> for logicaffeine_compile::ui_bridge::Engine {
103 fn from(engine: RunEngine) -> Self {
104 match engine {
105 RunEngine::Jit => Self::Jit,
106 RunEngine::Vm => Self::Vm,
107 RunEngine::Tree => Self::TreeWalker,
108 }
109 }
110}
111
112/// Available CLI subcommands.
113///
114/// Each variant is one operation `largo` can perform, and `largo --help` lists every one.
115/// They span project management, building and running, the package registry, logic and
116/// proof (such as `logic` and `prove`), and interactive, editor and agent tooling (such as
117/// `repl`, `dap` and `mcp`). A sample from the first three groups:
118///
119/// ## Project Management
120/// - [`New`][Commands::New] - Create a new project in a new directory
121/// - [`Init`][Commands::Init] - Initialize a project in the current directory
122///
123/// ## Build & Run
124/// - [`Build`][Commands::Build] - Compile the project
125/// - [`Run`][Commands::Run] - Build and execute
126/// - [`Check`][Commands::Check] - Type-check without building
127/// - [`Verify`][Commands::Verify] - Run Z3 static verification
128///
129/// ## Package Registry
130/// - [`Publish`][Commands::Publish] - Upload package to registry
131/// - [`Login`][Commands::Login] - Authenticate with registry
132/// - [`Logout`][Commands::Logout] - Remove stored credentials
133#[derive(Subcommand)]
134pub enum Commands {
135 /// Create a new LOGOS project in a new directory.
136 ///
137 /// Scaffolds a complete project structure including:
138 /// - `Largo.toml` manifest file
139 /// - `src/main.lg` entry point with a "Hello, world!" example
140 /// - `.gitignore` configured for LOGOS projects
141 ///
142 /// # Example
143 ///
144 /// ```bash
145 /// largo new my_project
146 /// cd my_project
147 /// largo run
148 /// ```
149 #[command(
150 after_help = "Examples:\n largo new hello\n cd hello\n largo run\n\n largo new mysite --site\n cd mysite\n largo serve\n\n largo new myapp --web\n cd myapp\n largo serve"
151 )]
152 New {
153 /// The project name, used for the directory and package name.
154 name: String,
155
156 /// Scaffold a full-stack website: a backend of `## Route`s ending in
157 /// `Serve on port 8080.` (`src/main.lg`), pages compiled to WASM
158 /// (`pages/`), and static assets (`static/`) — all served by one
159 /// `largo serve`. Pure convention: no extra manifest keys.
160 #[arg(long, conflicts_with = "site")]
161 web: bool,
162
163 /// Scaffold a site: pages compiled to WASM (`pages/`) and static assets
164 /// (`static/`), and no backend and no entry program — a `## Page`
165 /// mounts itself. `largo serve` shows it; `largo build` exports it to
166 /// `dist/` for any static host.
167 #[arg(long)]
168 site: bool,
169 },
170
171 /// Initialize a LOGOS project in the current directory.
172 ///
173 /// Similar to [`New`][Commands::New] but works in an existing directory.
174 /// Creates the manifest and source structure without creating a new folder.
175 ///
176 /// # Example
177 ///
178 /// ```bash
179 /// mkdir my_project && cd my_project
180 /// largo init
181 /// ```
182 #[command(
183 after_help = "Examples:\n mkdir app && cd app\n largo init\n largo init --name my_app"
184 )]
185 Init {
186 /// Project name. If omitted, uses the current directory name.
187 #[arg(long)]
188 name: Option<String>,
189 },
190
191 /// Build the current project.
192 ///
193 /// A program or a backend: compiles the LOGOS source to Rust, then invokes
194 /// `cargo build` on the generated code; the binary is published at
195 /// `target/debug/<name>` or `target/release/<name>`. A full-stack site's
196 /// binary carries its pages and assets inside it. A site (pages, no `Serve`
197 /// backend) has no program to compile, so it is exported to `dist/` — the
198 /// same as `--static`.
199 ///
200 /// # Verification
201 ///
202 /// When `--verify` is passed, the build process includes Z3 static
203 /// verification of logical constraints. This requires the `verification`
204 /// feature enabled at build time (the full build).
205 ///
206 /// # Example
207 ///
208 /// ```bash
209 /// largo build # Debug build
210 /// largo build --release # Release build with optimizations
211 /// largo build --verify # Build with Z3 verification
212 /// ```
213 #[command(
214 after_help = "Examples:\n largo build\n largo build --release\n largo build --static # export pages/ and static/ to dist/\n largo build --emit wasm\n largo build --lib --target aarch64-unknown-linux-gnu"
215 )]
216 Build {
217 /// Build with optimizations enabled.
218 #[arg(long, short)]
219 release: bool,
220
221 /// Run Z3 static verification after compilation (the full build).
222 #[arg(long)]
223 verify: bool,
224
225 /// Build as a library instead of an executable.
226 /// Generates `lib.rs` with `crate-type = ["cdylib"]` instead of a binary.
227 #[arg(long)]
228 lib: bool,
229
230 /// Target triple for cross-compilation.
231 /// Use "wasm" as shorthand for "wasm32-unknown-unknown".
232 #[arg(long)]
233 target: Option<String>,
234
235 /// Pre-build every `is exported for native` function into the AOT-native
236 /// tier bundle (a cached cdylib per function) under `.logos-native/`.
237 #[arg(long)]
238 native_functions: bool,
239
240 /// Emit target: `c`, `c-bytecode`, `wasm`, `wasm-linked`, `isa` or `riscv`.
241 /// `c` and `c-bytecode` build native executables from the optimized AST and bytecode respectively.
242 /// `wasm` compiles the project straight to a
243 /// self-contained `.wasm` module via the built-in backend (no rustc, cargo or wasm-bindgen),
244 /// written to `target/<name>.wasm` beside a Node.js host shim. `wasm-linked` additionally links the
245 /// real `logicaffeine_base::BigInt` runtime (via `rust-lld`) so overflowing integer arithmetic
246 /// computes the exact big number instead of wrapping; it needs the Rust toolchain and a wasm32
247 /// `base` build. `isa` writes LOGOS Silicon ISA assembly beside the entry as `<entry>.isa`.
248 /// `riscv` (also `risc-v`) writes RV64GC assembly beside the entry as `<entry>.s`, with the
249 /// `logos_rt.c` runtime shim next to it. Omit for the default rustc-based Rust build.
250 #[arg(long)]
251 emit: Option<String>,
252
253 /// Print one `logos-check/1` JSON envelope on stdout: a parse error
254 /// reports as a structured diagnostic, a cargo failure as one
255 /// `build-failure` diagnostic carrying the raw output.
256 #[arg(long)]
257 json: bool,
258
259 /// Print the machine-readable build manifest (JSON) instead of building:
260 /// the local package identity, feature selection, the resolved
261 /// `path`/`git` dependencies, and the transitive closure (every linked
262 /// `.lg` file tagged with its source dependency). No cargo/rustc runs.
263 #[arg(long)]
264 manifest: bool,
265
266 /// Export the site to `dist/` as plain files instead of building a binary —
267 /// pre-rendered HTML, the content-addressed module and shim, `static/**`,
268 /// `robots.txt`, `sitemap.xml` and a `_headers` file carrying the same cache
269 /// rules the binary sends. Deployable to any static host (Pages, Netlify,
270 /// Cloudflare, S3). No cargo, no rustc, and no backend required. What a
271 /// plain `largo build` does for a site; ask for it on a full-stack site to
272 /// export its pages without the backend.
273 #[arg(long)]
274 r#static: bool,
275 },
276
277 /// Run Z3 static verification without building.
278 ///
279 /// Performs formal verification of logical constraints in the project
280 /// using the Z3 SMT solver. This catches logical errors that would be
281 /// impossible to detect through testing alone.
282 ///
283 /// Needs the full build (the `verification` feature).
284 ///
285 /// # Example
286 ///
287 /// ```bash
288 /// largo verify
289 /// ```
290 #[command(after_help = "Examples:\n largo verify")]
291 Verify {},
292
293 /// Build and run the current project.
294 ///
295 /// Equivalent to `largo build` followed by executing the resulting binary.
296 /// The exit code of the built program is propagated.
297 ///
298 /// With `--interpret`, skips the Rust build and runs the program in-process on the
299 /// bytecode VM, with JIT tier-up on x86-64 Linux and macOS, for fast feedback during
300 /// development. A concurrent or asynchronous program, or a construct the VM compiler
301 /// does not take, runs on the tree-walking interpreter instead.
302 ///
303 /// # Example
304 ///
305 /// ```bash
306 /// largo run # Debug mode (compile to Rust)
307 /// largo run --release # Release mode
308 /// largo run --interpret # Run in-process on the VM (no Rust build)
309 /// ```
310 #[command(
311 after_help = "Examples:\n largo run\n largo run --release\n largo run --interpret\n largo run --emit wasm\n largo run -- input.txt --program-flag"
312 )]
313 Run {
314 /// Build with optimizations enabled.
315 #[arg(long, short)]
316 release: bool,
317
318 /// Run in-process on the bytecode VM (JIT where available) instead of building Rust.
319 /// Gives fast feedback but lacks full compiled-Rust performance.
320 #[arg(long, short)]
321 interpret: bool,
322
323 /// `wasm` compiles straight to a `.wasm` (built-in backend, no rustc) and runs it via the
324 /// emitted host shim (node). `wasm-linked` links the real `BigInt` runtime first (exact
325 /// arbitrary-precision integers; needs the Rust toolchain). Compile-and-run in one step.
326 #[arg(long, conflicts_with = "interpret")]
327 emit: Option<String>,
328
329 /// In-process execution tier. Valid only with `--interpret`.
330 #[arg(long, value_enum, value_name = "ENGINE", requires = "interpret")]
331 engine: Option<RunEngine>,
332
333 /// Stop after the engine executes N steps (`--interpret` only) —
334 /// deterministic, the same op on every run. Exhaustion exits 122 with the
335 /// partial output delivered.
336 #[arg(long, value_name = "N")]
337 max_steps: Option<u64>,
338
339 /// Kill the run after this wall clock (`500ms`, `10s`, `2m`).
340 /// Expiry exits 124 (the GNU timeout convention).
341 #[arg(long, value_name = "DURATION")]
342 timeout: Option<String>,
343
344 /// Scheduler seed for deterministic concurrent runs (sets LOGOS_SEED
345 /// for this run and any compiled child).
346 #[arg(long)]
347 seed: Option<u64>,
348
349 /// Print one `logos-run/1` JSON envelope on stdout (`--interpret`
350 /// only): outcome, output lines, error, steps used.
351 #[arg(long)]
352 json: bool,
353
354 /// Arguments to pass to the program.
355 #[arg(trailing_var_arg = true, allow_hyphen_values = true)]
356 args: Vec<String>,
357 },
358
359 /// Serve the project over HTTP.
360 ///
361 /// What is served is decided from the project itself. A SITE — `pages/` or
362 /// `static/` and no `Serve` backend — gets the dev server: largo owns the
363 /// public port, serves the built pages and assets with hot reload, and
364 /// answers anything else 404 as a static host would. A FULL-STACK site adds
365 /// its `Serve` backend as a child on `LOGOS_PORT`, proxied for everything the
366 /// pages do not answer. A BACKEND — a `Serve` program alone — is interpreted
367 /// directly and binds its own port. Any other program is built to
368 /// WebAssembly and served as a bundle.
369 ///
370 /// # Example
371 ///
372 /// ```bash
373 /// largo serve
374 /// ```
375 #[command(
376 after_help = "Examples:\n largo serve # site, full-stack site, or backend — decided by the project\n largo serve --port 3000\n largo serve --open # …and open it in your browser\n largo serve --host 0.0.0.0 # reachable from a phone on the same network\n largo serve --timeout 30s\n largo serve --watch # a program's bundle, rebuilt + live-reloaded on save"
377 )]
378 Serve {
379 /// Kill the server after this wall clock (`500ms`, `10s`, `2m`).
380 #[arg(long, value_name = "DURATION")]
381 timeout: Option<String>,
382
383 /// Scheduler seed for deterministic runs (sets LOGOS_SEED).
384 #[arg(long)]
385 seed: Option<u64>,
386
387 /// Serve a program's WebAssembly bundle, rebuilding and live-reloading
388 /// the browser on every source save. (A site always watches.)
389 #[arg(long)]
390 watch: bool,
391
392 /// Open the served site in your default browser (best-effort).
393 #[arg(long)]
394 open: bool,
395
396 /// Bind address for a site. Default `127.0.0.1` (this machine only);
397 /// pass `0.0.0.0` to serve the whole local network, so a phone or a
398 /// tablet on the same wifi can open the site.
399 #[arg(long, value_name = "ADDR")]
400 host: Option<String>,
401
402 /// The public port for a site or a bundle (falls forward to the next
403 /// free port if taken). Default 8080.
404 #[arg(long)]
405 port: Option<u16>,
406
407 /// (internal) Run as the full-stack dev server's backend child: the
408 /// interpreter serves the entry on the port `LOGOS_PORT` names, and
409 /// exits when the parent's stdin lifeline closes. Spawned by
410 /// `largo serve` itself.
411 #[arg(long, hide = true)]
412 as_backend: bool,
413
414 /// Arguments to pass to the program (readable via `args()`).
415 #[arg(trailing_var_arg = true, allow_hyphen_values = true)]
416 args: Vec<String>,
417 },
418
419 /// Check the project for errors without producing a binary.
420 ///
421 /// Parses and type-checks the LOGOS source without invoking the full
422 /// build pipeline. Useful for quick validation during development.
423 ///
424 /// # Example
425 ///
426 /// ```bash
427 /// largo check
428 /// ```
429 #[command(
430 after_help = "Examples:\n largo check\n largo check --quiet\n largo check --kernel Demo.andSwap.lg"
431 )]
432 Check {
433 /// A LOGOS kernel-vernacular document to check (with `--kernel`)
434 /// instead of the project.
435 #[arg(requires = "kernel")]
436 file: Option<PathBuf>,
437
438 /// Check FILE as a LOGOS kernel-vernacular literate document through
439 /// the kernel's own document door (`Repl::execute_document`): every
440 /// block, in order, stopping at the first that does not check.
441 #[arg(long, requires = "file", conflicts_with = "deep")]
442 kernel: bool,
443
444 /// Also run rustc's analysis over the generated code (the same deep
445 /// pass the IDE's flycheck uses) and translate its findings to LOGOS.
446 #[arg(long)]
447 deep: bool,
448
449 /// Print one `logos-check/1` JSON envelope on stdout (diagnostics
450 /// with stable codes, spans, and Socratic explanations). Prose stays
451 /// on stderr; exit codes are unchanged.
452 #[arg(long)]
453 json: bool,
454 },
455
456 /// Report which optimizations actually fire when compiling a LOGOS file.
457 ///
458 /// Compiles the file on the AOT, run-path, and VM-compile paths with the
459 /// firing trace on, and lists the optimizations that genuinely changed the
460 /// program (not merely the ones that are enabled). Useful for understanding
461 /// and auditing what the compiler did to a given program.
462 ///
463 /// # Example
464 ///
465 /// ```bash
466 /// largo opts src/main.lg
467 /// largo opts src/main.lg --json
468 /// largo opts src/main.lg --json --jit -- 1000
469 /// ```
470 #[command(
471 after_help = "Examples:\n largo opts src/main.lg\n largo opts src/main.lg --json\n largo opts src/main.lg --json --jit -- 1000"
472 )]
473 Opts {
474 /// The `.lg` source file to analyze.
475 file: PathBuf,
476
477 /// Emit the fired optimizations as JSON (keyword list).
478 #[arg(long)]
479 json: bool,
480
481 /// Execute through a private native tier and include a distinct JIT
482 /// optimizer/lowering/decline trace. Program arguments follow `--`.
483 #[arg(long)]
484 jit: bool,
485
486 /// Arguments presented to the traced program after `argv[0]`.
487 #[arg(last = true)]
488 args: Vec<String>,
489 },
490
491 /// Publish the package to the LOGOS registry.
492 ///
493 /// Packages the project as a tarball and uploads it to the specified
494 /// registry. Requires authentication via `largo login`.
495 ///
496 /// # Pre-flight Checks
497 ///
498 /// Before publishing, the command verifies:
499 /// - The entry point exists
500 /// - No uncommitted git changes (unless `--allow-dirty`)
501 /// - Valid authentication token
502 ///
503 /// # Example
504 ///
505 /// ```bash
506 /// largo publish # Publish to default registry
507 /// largo publish --dry-run # Validate without uploading
508 /// ```
509 #[command(
510 after_help = "Examples:\n largo publish --dry-run\n largo publish\n largo publish --allow-dirty"
511 )]
512 Publish {
513 /// Registry URL. Defaults to `registry.logicaffeine.com`.
514 #[arg(long)]
515 registry: Option<String>,
516
517 /// Perform all validation without actually uploading.
518 /// Useful for testing the publish process.
519 #[arg(long)]
520 dry_run: bool,
521
522 /// Allow publishing with uncommitted git changes.
523 /// By default, publishing requires a clean working directory.
524 #[arg(long)]
525 allow_dirty: bool,
526 },
527
528 /// Authenticate with the package registry.
529 ///
530 /// Stores an API token for the specified registry. The token is saved
531 /// in `~/.config/logos/credentials.toml` with restricted permissions.
532 ///
533 /// # Token Acquisition
534 ///
535 /// Tokens can be obtained from the registry's web interface:
536 /// 1. Visit `{registry}/auth/github` to authenticate
537 /// 2. Generate an API token from your profile
538 /// 3. Provide it via `--token` or interactive prompt
539 ///
540 /// # Example
541 ///
542 /// ```bash
543 /// largo login # Interactive prompt
544 /// largo login --token tok_xxxxx # Non-interactive
545 /// ```
546 #[command(after_help = "Examples:\n largo login\n largo login --token lgr_xxxxx")]
547 Login {
548 /// Registry URL. Defaults to `registry.logicaffeine.com`.
549 #[arg(long)]
550 registry: Option<String>,
551
552 /// API token. If omitted, prompts for input on stdin.
553 #[arg(long)]
554 token: Option<String>,
555 },
556
557 /// Remove stored credentials for a registry.
558 ///
559 /// Deletes the authentication token from the local credentials file.
560 ///
561 /// # Example
562 ///
563 /// ```bash
564 /// largo logout
565 /// ```
566 #[command(
567 after_help = "Examples:\n largo logout\n largo logout --registry https://registry.example.com"
568 )]
569 Logout {
570 /// Registry URL. Defaults to `registry.logicaffeine.com`.
571 #[arg(long)]
572 registry: Option<String>,
573 },
574
575 /// Diagnose the environment largo runs in.
576 ///
577 /// Checks the Rust toolchain (needed by `build`/`run`), the wasm32
578 /// target, node (for `--emit wasm`), the verification flavor, registry
579 /// reachability and credentials, update freshness, and — inside a
580 /// project — manifest health. Degradations are warnings; only a broken
581 /// project fails. Works offline.
582 #[command(
583 after_help = "Examples:\n largo doctor\n largo doctor --registry https://registry.example.com"
584 )]
585 Doctor {
586 /// Registry URL to probe (defaults to the LOGOS registry).
587 #[arg(long)]
588 registry: Option<String>,
589 },
590
591 /// Start the interactive LOGOS REPL.
592 ///
593 /// Two modes in one session: imperative statements against a
594 /// persistent interpreter session (`logos>`), and English→FOL logic
595 /// mode with discourse-aware anaphora (`logic>`). Type `:help` inside
596 /// for the meta-commands (`:mode`, `:format`, `:readings`, `:vars`,
597 /// `:save`, …). Works on a pipe too — no terminal required.
598 #[command(
599 after_help = "Examples:\n largo repl\n largo repl --logic\n largo repl --logic --format latex\n largo repl --load session.lg\n printf 'Let x be 5.\\nShow x.\\n' | largo repl"
600 )]
601 Repl {
602 /// Start in logic mode (English → FOL).
603 #[arg(long)]
604 logic: bool,
605
606 /// Initial logic output format.
607 #[arg(long, value_enum)]
608 format: Option<crate::commands::logic::LogicFormat>,
609
610 /// Load a saved session/program on startup.
611 #[arg(long)]
612 load: Option<PathBuf>,
613 },
614
615 /// Solve a DIMACS CNF with the certified SAT engine.
616 ///
617 /// The SAT Competition interface as a largo verb: prints
618 /// `s SATISFIABLE` with a `v` model or `s UNSATISFIABLE`, optionally
619 /// exporting a DRAT/DPR/SR refutation for external checkers
620 /// (drat-trim). Exit codes follow the competition convention:
621 /// 10 = SAT, 20 = UNSAT, 1 = error.
622 #[command(
623 after_help = "Examples:\n largo sat instance.cnf\n largo sat instance.cnf --proof refutation.drat\n largo sat instance.cnf --stats"
624 )]
625 Sat {
626 /// The DIMACS CNF file to solve.
627 file: PathBuf,
628
629 /// Write the UNSAT certificate here (DRAT; DPR/SR for symmetry routes).
630 #[arg(long)]
631 proof: Option<PathBuf>,
632
633 /// Print solver statistics to stderr.
634 #[arg(long)]
635 stats: bool,
636 },
637
638 /// Prove the theorems in a LOGOS source file (kernel-certified).
639 ///
640 /// Runs `## Theory` developments (formal Axiom/Theorem declarations,
641 /// proved in citation order) and English `## Theorem` blocks
642 /// (Given/Prove/Proof) through the proof engine. Every ✓ is certified
643 /// by the type-theory kernel — a mere derivation never counts.
644 #[command(
645 after_help = "Examples:\n largo prove # prove the project entry\n largo prove geometry.lg\n largo prove socrates.lg --trace\n largo prove tarski.lg --json\n largo prove socrates.lg --certificate # emit re-checkable proof certificates\n largo prove --kernel Demo.andSwap.lg # a kernel-vernacular document"
646 )]
647 Prove {
648 /// The source file (defaults to the project entry).
649 file: Option<PathBuf>,
650
651 /// Check FILE as a LOGOS kernel-vernacular literate document through
652 /// the kernel's own document door (`Repl::execute_document`) — the
653 /// form `largo lean import` emits.
654 #[arg(long, requires = "file", conflicts_with_all = ["trace", "certificate"])]
655 kernel: bool,
656
657 /// Show the rendered derivation tree under each proved theorem.
658 #[arg(long)]
659 trace: bool,
660
661 /// Emit machine-readable JSON results.
662 #[arg(long, conflicts_with = "trace")]
663 json: bool,
664
665 /// Emit the independently re-checkable proof certificate for every
666 /// kernel-proved theorem as JSON (the proof term + the goal + the
667 /// theorem's disclosed premises), each re-verified against the kernel.
668 /// A third party can re-check these with only the kernel — no prover.
669 #[arg(long, conflicts_with_all = ["trace", "json"])]
670 certificate: bool,
671 },
672
673 /// Translate English to First-Order Logic.
674 ///
675 /// Compiles a natural-language sentence to formal logic — the LOGOS
676 /// logic mode from the terminal. Reads the sentence inline, from
677 /// `--file`, or from piped stdin. Prints bare FOL on stdout, so output
678 /// pipes cleanly into other tools.
679 #[command(
680 after_help = "Examples:\n largo logic \"Every woman loves a man.\"\n largo logic \"Every woman loves a man.\" --all-readings\n largo logic \"It might rain.\" --format kripke\n echo \"Socrates is mortal.\" | largo logic\n printf 'A farmer owns a donkey.\\nHe feeds it.' | largo logic --discourse"
681 )]
682 Logic {
683 /// The English sentence to translate.
684 sentence: Option<String>,
685
686 /// Read the sentence (or discourse) from a file.
687 #[arg(long, short, conflicts_with = "sentence")]
688 file: Option<PathBuf>,
689
690 /// Output format for the logical form.
691 #[arg(long, value_enum, default_value = "unicode")]
692 format: crate::commands::logic::LogicFormat,
693
694 /// Show every reading (quantifier scopes + parse forest), numbered.
695 #[arg(long, conflicts_with = "discourse")]
696 all_readings: bool,
697
698 /// Enrich with scalar implicature (pragmatic strengthening).
699 #[arg(long)]
700 pragmatic: bool,
701
702 /// Treat each input line as one sentence of a discourse with
703 /// shared anaphora context.
704 #[arg(long)]
705 discourse: bool,
706 },
707
708 /// Generate documentation from the project's `##` blocks.
709 ///
710 /// Renders a markdown reference from the literate structure of the
711 /// entry file: `## To` signatures, type definitions, notes, examples,
712 /// and formal blocks — in source order. `## Main` is omitted.
713 #[command(after_help = "Examples:\n largo doc\n largo doc --out book")]
714 Doc {
715 /// Output directory (defaults to `target/doc`).
716 #[arg(long)]
717 out: Option<PathBuf>,
718 },
719
720 /// Add a dependency to Largo.toml.
721 ///
722 /// Accepts `name` (any version), `name@version`, or `logos:name` (the
723 /// registry URI form). `--path` and `--git` record local and git
724 /// dependencies. Edits preserve the manifest's comments and formatting.
725 #[command(
726 after_help = "Examples:\n largo add math_utils\n largo add math_utils@1.2\n largo add logos:std\n largo add local_lib --path ../local_lib\n largo add remote --git https://example.com/remote.git"
727 )]
728 Add {
729 /// The dependency: `name`, `name@version`, or `logos:name`.
730 spec: String,
731
732 /// Use a local path dependency.
733 #[arg(long, conflicts_with = "git")]
734 path: Option<String>,
735
736 /// Use a git dependency.
737 #[arg(long, conflicts_with = "path")]
738 git: Option<String>,
739 },
740
741 /// Remove a dependency from Largo.toml.
742 ///
743 /// Deletes the named entry from `[dependencies]`, leaving the rest of
744 /// the manifest byte-identical.
745 #[command(after_help = "Examples:\n largo remove math_utils")]
746 Remove {
747 /// The dependency name to remove.
748 name: String,
749 },
750
751 /// Format LOGOS source files.
752 ///
753 /// Applies the canonical style (4-space indentation, no tabs, no
754 /// trailing whitespace) — the same rules the language server uses.
755 /// Without paths, formats the whole project; with paths, exactly those
756 /// files. `--check` writes nothing and exits 1 if anything would change.
757 #[command(
758 after_help = "Examples:\n largo fmt\n largo fmt src/main.lg\n largo fmt --check # CI gate, writes nothing"
759 )]
760 Fmt {
761 /// Specific files to format (defaults to all project sources).
762 paths: Vec<PathBuf>,
763
764 /// Check only: list files that need formatting, exit 1 if any.
765 #[arg(long)]
766 check: bool,
767
768 /// With --check: print one `logos-fmt/1` JSON envelope on stdout.
769 #[arg(long)]
770 json: bool,
771 },
772
773 /// Emit compiled code without building a binary.
774 ///
775 /// Prints the generated Rust or C translation of the program, or writes
776 /// a self-contained `.wasm` module (built-in backend, no rustc) with its
777 /// Node.js host shim. Without FILE, uses the current project's entry;
778 /// with FILE, works on any standalone `.lg`/`.md` source.
779 #[command(
780 after_help = "Examples:\n largo emit rust\n largo emit rust -o generated.rs\n largo emit c standalone.lg\n largo emit wasm\n largo emit wasm-linked -o dist/app.wasm\n largo emit rdu --chip sn50 qwen38_tiny.lg -o out/\n largo emit rdu --format vllm qwen38_tiny.lg\n largo emit rdu --model qwen38 -o qwen38_sn50/\n largo emit rdu --model qwen38 --ctx 4096 -o qwen38_sn50_decode/\n largo emit rdu --model qwen38 --ctx 4096 --batch 8 -o qwen38_sn50_batch8/\n largo emit rdu --model qwen38 --ctx 4096 --tp 8 -o qwen38_sn50_tp8/\n largo emit rdu --model qwen38 --ctx 4096 --prefill 512 -o qwen38_sn50_prefill/"
781 )]
782 Emit {
783 /// What to emit.
784 #[arg(value_enum)]
785 target: crate::commands::emit::EmitTarget,
786
787 /// A standalone source file (defaults to the project entry).
788 file: Option<PathBuf>,
789
790 /// Write to this path instead of stdout (rust/c) or the default
791 /// module path (wasm).
792 #[arg(long, short)]
793 output: Option<PathBuf>,
794
795 /// `emit rdu`: the RDU generation to lower onto — `sn40l` or `sn50` (the default).
796 #[arg(long, value_name = "CHIP")]
797 chip: Option<String>,
798
799 /// `emit rdu`: the artifact to print bare / add to the bundle — `placement` (the default; the
800 /// neutral placement text), `spatial` (Spatial source), `sambaflow` (PyTorch module + compile
801 /// scaffold), `vllm` (the Qwen3.8 deployment plan for the chip), `report` (the MODELED II report).
802 #[arg(long, value_enum, value_name = "FORMAT")]
803 format: Option<crate::commands::emit::RduFormat>,
804
805 /// `emit rdu`: hand the certified artifact to an SDK bridge by name (`mock`, `sambaflow`).
806 #[arg(long, value_name = "BRIDGE")]
807 bridge: Option<String>,
808
809 /// `emit rdu`: lower a whole model instead of FILE — `qwen38` (Qwen3.8-27B, all 64 layers), `qwen38-tiny`,
810 /// `qwen38-mini` (the tiny shape with heads that split over 2 or 4 chips), or a Qwen3.5/3.8 checkpoint's
811 /// `.gguf`, its program read from the checkpoint — as one certified program per layer kind plus the head, the
812 /// program they are cuts of (`program.lg`) and a manifest binding every layer and naming every program's cut.
813 /// Needs `-o DIR`.
814 #[arg(long, value_name = "MODEL")]
815 model: Option<String>,
816
817 /// `emit rdu --model`: lower the DECODE deployment with a KV cache of CTX positions — an embedding
818 /// program, layer kinds whose attention appends to and reads the cache, and a head that emits the next
819 /// token; `tok` and `pos` are runtime inputs. Without it, the bundle is the authored forward.
820 #[arg(long, value_name = "CTX")]
821 ctx: Option<usize>,
822
823 /// `emit rdu --model --ctx`: serve BATCH sequences per decode step — the hidden states stacked `BATCH × d`,
824 /// every weight read once for all of them, each sequence with its own KV caches and carried state;
825 /// `tok_s{b}` and `pos_s{b}` are runtime inputs. `auto`: the most sequences whose per-step working set stays
826 /// in a chip's SRAM (the serving plan). The default is one sequence.
827 #[arg(long, value_name = "BATCH")]
828 batch: Option<String>,
829
830 /// `emit rdu --model --ctx`: TENSOR-PARALLEL over TP chips — every layer kind one program over the chips,
831 /// each chip its own heads and FFN columns and a slice of every weight, the partials summed by two
832 /// all-reduces a layer. TP must split the model's heads (Qwen3.8-27B: 1, 2, 4 or 8). `auto`: the widest width
833 /// the heads admit in the chip's scale-up domain. The default is one chip.
834 #[arg(long, value_name = "TP")]
835 tp: Option<String>,
836
837 /// `emit rdu --model --ctx`: PREFILL a chunk of PREFILL prompt tokens of one sequence per step — the chunk's
838 /// hidden states stacked `PREFILL × d`, every weight read once for the chunk, the rows taking the sequence's KV
839 /// caches and recurrent memories in order, the last row's next token out. The state is the decode bundle's,
840 /// so decoding continues from it; `tok_s{b}` and `pos_s{b}` are runtime inputs.
841 #[arg(long, value_name = "PREFILL")]
842 prefill: Option<usize>,
843 },
844
845 /// Bring a model up on every chip from its one program.
846 ///
847 /// Reads the checkpoint's spec, writes the model's computation as one LOGOS program (`program.lg`) and lowers that
848 /// program on each backend asked for: the CPU tiers (the VM's bytecode, the same with its JIT, C, Rust, RISC-V and
849 /// WebAssembly), the CUDA lane (one fused `.cu` and the sidecar of constants it reads), the D5005 decode engine (the
850 /// sequencer's program), the SN50 (a certified bundle) and the fabric. Every artifact names the cut of the program
851 /// it was lowered from (`LOGOS program: <cut>, sha256 <hex>`); a backend that does not run the model refuses it by
852 /// name. With `--run`, every chip that brought the model up and is on this machine then generates from a prompt
853 /// (or every prompt of a golden, `--prompts`) through the one program, and reports its tokens, its tokens a second
854 /// and how many lead the reference's.
855 #[command(
856 after_help = "Examples:\n largo bringup models/qwen3.8-27b/Qwen3.8-27B-Q4_K_M.gguf -o qwen38/\n largo bringup llama.gguf --target cuda --ctx 1024 -o llama/\n largo bringup qwen3.5-0.8b.gguf --target vm,c,cuda --ctx 64 --run --tokens 8 -o qwen35/\n largo bringup qwen3.5-0.8b.gguf --target cuda --run --golden benchmarks/models/qwen3.5-0.8b/golden-f32.json -o qwen35/\n largo bringup qwen3.5-0.8b.gguf --target jit,c --run --golden benchmarks/models/qwen3.5-0.8b/golden-f32.json --prompts all -o qwen35/"
857 )]
858 Bringup {
859 /// The model's GGUF checkpoint.
860 checkpoint: PathBuf,
861 /// The chips to bring the model up on, comma-separated: `vm`, `jit`, `c`, `rust`, `riscv-qemu`, `wasm`, `cuda`, `d5005`, `sn50`, `fabric`. Every one when absent.
862 #[arg(long = "target", value_name = "CHIP", value_delimiter = ',')]
863 targets: Vec<String>,
864 /// The positions the decode step's caches hold.
865 #[arg(long, value_name = "N", default_value_t = 4096)]
866 ctx: usize,
867 /// The directory the program and every backend's artifacts are written to.
868 #[arg(long, short)]
869 output: PathBuf,
870 /// Then run the model on every chip that brought it up and is on this machine, each judged by how many of its
871 /// tokens lead the reference's.
872 #[arg(long)]
873 run: bool,
874 /// The tokens a run generates after the prompt (8, or the golden's continuation, unless given).
875 #[arg(long, value_name = "N", requires = "run")]
876 tokens: Option<usize>,
877 /// The prompt a run starts from: token ids from 0, comma-separated.
878 #[arg(long, value_name = "IDS", value_delimiter = ',', default_value = "5,17,2,30", requires = "run", conflicts_with = "golden")]
879 prompt: Vec<u32>,
880 /// Judge the runs against a golden (`benchmarks/models/<model>/golden-f32.json`): its first prompt is the
881 /// prompt and its continuation the tokens to agree with; without it, the model's f64 reference generates them.
882 #[arg(long, value_name = "FILE", requires = "run")]
883 golden: Option<PathBuf>,
884 /// Run the golden's first N prompts (`all`: every one), each from an empty state and judged against its own
885 /// continuation.
886 #[arg(long, value_name = "N|all", requires = "golden")]
887 prompts: Option<String>,
888 },
889
890 /// Show what an LGX page became: the ordinary LOGOS its constructs lower to.
891 ///
892 /// A `## Component` is not run as written: it becomes a render function that writes
893 /// the view to a tape (`vdOpen`/`vdText`/`vdClose`) its commit turns into DOM calls, an
894 /// action function per action, a mount entry and a dispatcher; a `## Route` becomes a function plus the synthesized
895 /// `route(method, path)` walk. When a page behaves in a way its markup does not
896 /// explain, the lowering is the answer — this prints it.
897 #[command(after_help = "Examples:\n largo expand pages/app.lg")]
898 Expand {
899 /// The source file to expand.
900 file: PathBuf,
901 },
902
903 /// Remove build artifacts.
904 ///
905 /// Deletes the project's `target/` directory. With `--all`, also removes
906 /// the `.logos-native/` compiled-function bundle cache produced by
907 /// `largo build --native-functions`.
908 #[command(after_help = "Examples:\n largo clean\n largo clean --all")]
909 Clean {
910 /// Also remove the `.logos-native/` bundle cache.
911 #[arg(long)]
912 all: bool,
913 },
914
915 /// Generate shell completions for largo.
916 ///
917 /// Writes a completion script for the given shell to stdout. Source it
918 /// from your shell's configuration to get tab completion for every
919 /// largo command and flag.
920 #[command(
921 after_help = "Examples:\n largo completions bash > ~/.local/share/bash-completion/completions/largo\n largo completions zsh > ~/.zfunc/_largo\n largo completions fish > ~/.config/fish/completions/largo.fish"
922 )]
923 Completions {
924 /// The shell to generate completions for.
925 #[arg(value_enum)]
926 shell: clap_complete::Shell,
927 },
928
929 /// Re-execute a `.replay` failure artifact.
930 ///
931 /// A failing `largo run --interpret` writes a self-contained bundle under
932 /// `target/replays/` — embedded source, scheduler seed and decision trace,
933 /// input transcript, and the failure coordinate. Replaying it re-executes
934 /// the program deterministically and reports whether the recorded failure
935 /// still reproduces byte-identically, no longer fires (fixed), or diverged
936 /// (the program or bundle changed since recording).
937 ///
938 /// Bundles are portable and committable: a bundle checked into a project's
939 /// test corpus is a permanent reproduction of the bug it recorded.
940 #[command(
941 after_help = "Examples:\n largo replay target/replays/main-1720000000.replay\n largo replay bug.replay --verify"
942 )]
943 Replay {
944 /// Path to the `.replay` bundle.
945 file: PathBuf,
946
947 /// Treat divergence as a hard error (exit non-zero). Reproduced and
948 /// fixed are both coherent verdicts; divergence never is.
949 #[arg(long)]
950 verify: bool,
951 },
952
953 /// Explain a diagnostic code or a language construct, offline.
954 ///
955 /// Looks the topic up in the error catalog first (`largo explain
956 /// zero-index` — every code from `check --json` and the MCP tools), then
957 /// in the teach lessons (`largo explain Let`). No project or network
958 /// needed.
959 #[command(
960 after_help = "Examples:\n largo explain zero-index\n largo explain use-after-move\n largo explain Let\n largo explain zero-index --json"
961 )]
962 Explain {
963 /// An error code (kebab-case) or a construct name.
964 topic: String,
965
966 /// Print the entry as one `logos-explain/1` JSON document.
967 #[arg(long)]
968 json: bool,
969 },
970
971 /// Serve the LOGOS toolchain over the Model Context Protocol (stdio).
972 ///
973 /// Speaks JSON-RPC 2.0, one JSON object per line: check with structured
974 /// diagnostics, sandboxed deterministic runs, English→FOL, kernel-certified
975 /// proofs, code emission, and optimization reports — plus the quickguide
976 /// and docs guides as MCP resources. Made for AI agents; humans want the
977 /// plain subcommands.
978 #[command(after_help = "Examples:\n largo mcp\n claude mcp add logos -- largo mcp")]
979 Mcp {
980 /// (internal) Run the `logos_run` sandbox worker on ENGINE instead of
981 /// serving; source arrives on stdin. Spawned by the server itself.
982 #[arg(long, hide = true, value_name = "ENGINE")]
983 worker: Option<String>,
984
985 /// (internal) Program arguments for the sandbox worker.
986 #[arg(trailing_var_arg = true, hide = true)]
987 worker_args: Vec<String>,
988 },
989
990 /// Run the project's `## Test` blocks.
991 ///
992 /// Discovers every `## Test: <prose name>` in the project, runs each in a
993 /// fresh, isolated world on the interpreter tier, and prints a
994 /// deterministic, name-ordered report. `Expect that` failures
995 /// record-and-continue (one run reports everything); runaway tests fail at
996 /// a deterministic op budget (the timeout that cannot flake); skips are
997 /// loud, need a reason, and fail the run unless budgeted under
998 /// `[test] skip_budget` in Largo.toml.
999 #[command(
1000 after_help = "Examples:\n largo test\n largo test withdraw\n largo test --seed 7\n largo test --format json\n largo test --json"
1001 )]
1002 Test {
1003 /// Run only tests whose prose name contains this substring.
1004 filter: Option<String>,
1005
1006 /// The suite seed (default 0 — reproducibility is the default).
1007 #[arg(long, default_value_t = 0)]
1008 seed: u64,
1009
1010 /// Report format.
1011 #[arg(long, default_value = "text", value_parser = ["text", "json"])]
1012 format: String,
1013
1014 /// Emit the machine-readable CLAIM INVENTORY as JSON: every `## Test`
1015 /// classified by kind (example / finite-enumeration property) with an
1016 /// honest status, vacuous flags, disclosed domain bounds, and any
1017 /// concrete counterexample. A superset of `--format json`.
1018 #[arg(long)]
1019 json: bool,
1020
1021 /// Also run capability-granted tests (`This test may use the real
1022 /// filesystem.` etc.) — they leave the hermetic no-flake guarantee.
1023 #[arg(long)]
1024 live: bool,
1025
1026 /// Escalate finite-domain `For all` properties to exhaustive proof
1027 /// (booleans are checked over every case, not sampled) → rank PROVEN.
1028 #[arg(long)]
1029 prove: bool,
1030
1031 /// Cross-tier differential: `all` (or a list of `interpreter`,`vm`) also runs
1032 /// each passing test's computation on the bytecode VM and compares it byte for
1033 /// byte, failing if the compiled tier cannot run what the interpreter did (the
1034 /// F18 "works-on-my-tier" guard). Any other value is refused rather than ignored.
1035 #[arg(long)]
1036 tiers: Option<String>,
1037
1038 /// A mounted test's page tiers also drive a real headless Chrome (`CHROME_BIN`, or the
1039 /// first of `google-chrome`/`google-chrome-stable`/`chromium`/`chromium-browser`/`chrome`
1040 /// on `PATH`) and must agree with it, exactly as they already must agree with the lowered
1041 /// bytecode VM. No Chrome found is a refused run, not a silent skip.
1042 #[arg(long)]
1043 browser: bool,
1044 },
1045
1046 /// Debug a LOGOS program over the Debug Adapter Protocol (stdio).
1047 ///
1048 /// Speaks DAP with `Content-Length` framing: `launch`, breakpoints,
1049 /// `stackTrace`/`scopes`/`variables`, the stepping verbs, `evaluate`, and —
1050 /// the headline — real reverse execution (`stepBack`/`reverseContinue`,
1051 /// `supportsStepBack: true`). A thin serializer over the same `DebugSession`
1052 /// facade the Studio drawer renders, so an editor and the browser drawer
1053 /// see the same session. Made for editor integrations; humans want `largo repl`.
1054 #[command(after_help = "Examples:\n largo dap")]
1055 Dap {},
1056
1057 /// Lean 4 → LOGOS: import a Lean declaration as a checked LOGOS package.
1058 ///
1059 /// `largo lean import --project <dir> --target <Name> --out <dir>` compiles
1060 /// the project with the pinned Lean 4.14.0, exports the target with the
1061 /// pinned lean4export, checks it with the LOGOS kernel, rechecks it
1062 /// independently, holds its assumptions to policy, emits it as a LOGOS
1063 /// document and replays the package in a fresh process. stdout is one
1064 /// `logos-lean-result/1` document; stderr is NDJSON diagnostics.
1065 /// `largo lean replay <dir>` replays a published package.
1066 #[command(
1067 disable_help_flag = true,
1068 after_help = "Examples:\n largo lean import --project ./proofs --target Demo.andSwap --out ./Demo.andSwap\n largo lean import Demo.ndjson --target Demo.andSwap --out ./out\n largo lean import Demo.ndjson --arena-protocol\n largo lean replay ./Demo.andSwap\n largo lean import --help"
1069 )]
1070 Lean {
1071 /// `import …` or `replay …` (see `largo lean import --help`).
1072 #[arg(trailing_var_arg = true, allow_hyphen_values = true, num_args = 0..)]
1073 args: Vec<std::ffi::OsString>,
1074 },
1075}
1076
1077/// Parse CLI arguments and execute the corresponding command.
1078///
1079/// This is the main entry point for the `largo` CLI. It parses command-line
1080/// arguments using [`clap`], then dispatches to the appropriate handler
1081/// function based on the subcommand.
1082///
1083/// # Errors
1084///
1085/// Returns an error if:
1086/// - The project structure is invalid (missing `Largo.toml`)
1087/// - File system operations fail
1088/// - Build or compilation fails
1089/// - Registry operations fail (authentication, network, etc.)
1090///
1091/// # Example
1092///
1093/// ```no_run
1094/// use logicaffeine_cli::cli::run_cli;
1095///
1096/// fn main() {
1097/// if let Err(e) = run_cli() {
1098/// eprintln!("Error: {}", e);
1099/// std::process::exit(1);
1100/// }
1101/// }
1102/// ```
1103pub fn run_cli() -> Result<(), Box<dyn std::error::Error>> {
1104 let cli = Cli::parse();
1105 ui::init(cli.color, cli.quiet, cli.verbose);
1106
1107 match cli.command {
1108 Commands::New { name, web, site } => {
1109 let scaffold = match (web, site) {
1110 (true, _) => commands::new::Scaffold::Web,
1111 (_, true) => commands::new::Scaffold::Site,
1112 _ => commands::new::Scaffold::Program,
1113 };
1114 commands::new::cmd_new(&name, scaffold)
1115 }
1116 Commands::Init { name } => commands::new::cmd_init(name.as_deref()),
1117 Commands::Build { release, verify, lib, target, native_functions, emit, json, manifest, r#static } => {
1118 if r#static {
1119 return commands::build::cmd_build_static();
1120 }
1121 commands::build::cmd_build(release, verify, lib, target, native_functions, emit, json, manifest)
1122 }
1123 Commands::Run { emit: Some(e), args, .. } if e == "wasm" => commands::run::cmd_run_wasm(&args, false),
1124 Commands::Run { emit: Some(e), args, .. } if e == "wasm-linked" => commands::run::cmd_run_wasm(&args, true),
1125 Commands::Run { emit: Some(e), release, args, max_steps, timeout, seed, json, .. } => {
1126 match crate::project::build::Backend::from_emit(&e) {
1127 Some(backend) => commands::run::cmd_run(
1128 release,
1129 backend,
1130 &args,
1131 max_steps,
1132 timeout.as_deref(),
1133 seed,
1134 json,
1135 ),
1136 None => Err(format!("unknown --emit target '{e}' (expected 'wasm', 'wasm-linked', 'c', or 'c-bytecode')").into()),
1137 }
1138 }
1139 Commands::Run { interpret, args, max_steps, timeout, seed, json, engine, .. } if interpret => {
1140 commands::run::cmd_run_interpret(
1141 &args,
1142 max_steps,
1143 timeout.as_deref(),
1144 seed,
1145 json,
1146 engine
1147 .map(Into::into)
1148 .unwrap_or(logicaffeine_compile::ui_bridge::Engine::Auto),
1149 )
1150 }
1151 Commands::Run { release, args, max_steps, timeout, seed, json, .. } => {
1152 commands::run::cmd_run(
1153 release,
1154 crate::project::build::Backend::Rust,
1155 &args,
1156 max_steps,
1157 timeout.as_deref(),
1158 seed,
1159 json,
1160 )
1161 }
1162 Commands::Serve { timeout, seed, watch, open, port, host, as_backend, args } => {
1163 // The hidden child mode first: the full-stack parent spawned us to
1164 // run the entry's `Serve` on `LOGOS_PORT` (with a stdin lifeline).
1165 if as_backend {
1166 commands::serve::cmd_serve_backend(&args, timeout.as_deref(), seed)
1167 } else {
1168 commands::serve::cmd_serve_project(commands::serve::ServeOptions {
1169 watch,
1170 open,
1171 port,
1172 host: host.as_deref(),
1173 timeout: timeout.as_deref(),
1174 seed,
1175 args: &args,
1176 })
1177 }
1178 }
1179 Commands::Check { file: Some(file), kernel: true, json, .. } => commands::kernel_document::run(&file, json, "Checked"),
1180 Commands::Check { deep, json, .. } => commands::check::cmd_check(deep, json),
1181 Commands::Opts {
1182 file,
1183 json,
1184 jit,
1185 args,
1186 } => commands::opts::cmd_opts(&file, json, jit, &args),
1187 Commands::Verify {} => commands::verify::cmd_verify(),
1188 Commands::Publish { registry, dry_run, allow_dirty } => {
1189 commands::publish::cmd_publish(registry.as_deref(), dry_run, allow_dirty)
1190 }
1191 Commands::Login { registry, token } => commands::publish::cmd_login(registry.as_deref(), token),
1192 Commands::Logout { registry } => commands::publish::cmd_logout(registry.as_deref()),
1193 Commands::Doctor { registry } => commands::doctor::cmd_doctor(registry),
1194 Commands::Repl { logic, format, load } => crate::repl::cmd_repl(logic, format, load),
1195 Commands::Sat { file, proof, stats } => commands::sat::cmd_sat(file, proof, stats),
1196 Commands::Prove { file: Some(file), kernel: true, json, .. } => commands::kernel_document::run(&file, json, "Proved"),
1197 Commands::Prove { file, trace, json, certificate, .. } => commands::prove::cmd_prove(file, trace, json, certificate),
1198 Commands::Logic { sentence, file, format, all_readings, pragmatic, discourse } => {
1199 commands::logic::cmd_logic(sentence, file, format, all_readings, pragmatic, discourse)
1200 }
1201 Commands::Doc { out } => commands::doc::cmd_doc(out),
1202 Commands::Add { spec, path, git } => commands::deps::cmd_add(spec, path, git),
1203 Commands::Remove { name } => commands::deps::cmd_remove(name),
1204 Commands::Fmt { paths, check, json } => commands::fmt::cmd_fmt(paths, check, json),
1205 Commands::Emit { target, file, output, chip, format, bridge, model, ctx, batch, tp, prefill } => commands::emit::cmd_emit(target, file, output, chip, format, bridge, model, ctx, batch, tp, prefill),
1206 Commands::Bringup { checkpoint, targets, ctx, output, run, tokens, prompt, golden, prompts } => {
1207 let run = run.then_some(commands::bringup::RunArgs { tokens, prompt, golden, prompts });
1208 commands::bringup::cmd_bringup(checkpoint, targets, ctx, output, run)
1209 }
1210 Commands::Expand { file } => commands::expand::cmd_expand(file),
1211 Commands::Clean { all } => commands::clean::cmd_clean(all),
1212 Commands::Completions { shell } => commands::completions::cmd_completions(shell),
1213 Commands::Replay { file, verify } => commands::replay::cmd_replay(file, verify),
1214 Commands::Explain { topic, json } => commands::explain::cmd_explain(&topic, json),
1215 Commands::Mcp { worker, worker_args } => crate::mcp::cmd_mcp(worker, worker_args),
1216 Commands::Test { filter, seed, format, json, live, prove, tiers, browser } => {
1217 commands::test::cmd_test(filter.as_deref(), seed, &format, json, live, prove, tiers.as_deref(), browser)
1218 }
1219 Commands::Dap {} => crate::dap::cmd_dap(),
1220 Commands::Lean { args } => commands::lean::cmd_lean(args),
1221 }
1222}