# Print an optspec for argparse to handle cmd's options that are independent of any subcommand.
function __fish_nucleos_global_optspecs
	string join \n v/verbose d/debug p/skip-wfc threads= no-compress license output= h/help V/version
end

function __fish_nucleos_needs_command
	# Figure out if the current invocation already has a command.
	set -l cmd (commandline -opc)
	set -e cmd[1]
	argparse -s (__fish_nucleos_global_optspecs) -- $cmd 2>/dev/null
	or return
	if set -q argv[1]
		# Also print the command, so this can be used to figure out what it is.
		echo $argv[1]
		return 1
	end
	return 0
end

function __fish_nucleos_using_subcommand
	set -l cmd (__fish_nucleos_needs_command)
	test -z "$cmd"
	and return 1
	contains -- $cmd[1] $argv
end

complete -c nucleos -n "__fish_nucleos_needs_command" -l threads -d 'Parallel BFS threads [1]' -r
complete -c nucleos -n "__fish_nucleos_needs_command" -l output -d 'Output format: `text` (default) or `json`' -r -f -a "text\t''
json\t''"
complete -c nucleos -n "__fish_nucleos_needs_command" -s v -l verbose -d 'Verbose: show per-check progress'
complete -c nucleos -n "__fish_nucleos_needs_command" -s d -l debug -d 'Enable debug output and a full diagnostic backtrace on panic'
complete -c nucleos -n "__fish_nucleos_needs_command" -s p -l skip-wfc -d 'Skip well-formedness checking'
complete -c nucleos -n "__fish_nucleos_needs_command" -l no-compress -d 'Disable leaf-LTS compression when composing a system LTS. By default each leaf is replaced by its strong-bisimulation quotient (weak-failures-equivalent, much smaller) before the product BFS, for any leaf above a size threshold; this opts out (exact serial product, byte-identical to the pre-compression output)'
complete -c nucleos -n "__fish_nucleos_needs_command" -l license -d 'Print the full proprietary licence text and exit'
complete -c nucleos -n "__fish_nucleos_needs_command" -s h -l help -d 'Print help'
complete -c nucleos -n "__fish_nucleos_needs_command" -s V -l version -d 'Print version'
complete -c nucleos -n "__fish_nucleos_needs_command" -f -a "anonymize" -d 'Rewrite a .dzn source file with identifiers replaced by `_<N>` and comments stripped'
complete -c nucleos -n "__fish_nucleos_needs_command" -f -a "bug-report" -d 'Bundle diagnostic info into a .zip / .tar.gz archive for a support ticket'
complete -c nucleos -n "__fish_nucleos_needs_command" -f -a "parse" -d 'Parse a Dezyne file and run well-formedness checks'
complete -c nucleos -n "__fish_nucleos_needs_command" -f -a "inspect-ports" -d 'Emit JSON describing the ports of a component / interface: names, directions (provides/requires), iface in/out events, param signatures. Read-only; no LTS, no simulation'
complete -c nucleos -n "__fish_nucleos_needs_command" -f -a "lts" -d 'Generate an LTS for a Dezyne component or interface in `.aut` format'
complete -c nucleos -n "__fish_nucleos_needs_command" -f -a "traces" -d 'Generate an exhaustive set of traces for a Dezyne model (each trace ends at an RTC node). Mirrors `dzn traces`'
complete -c nucleos -n "__fish_nucleos_needs_command" -f -a "lts-walk" -d 'Replay a trace through the generated LTS, dumping state vectors at each step'
complete -c nucleos -n "__fish_nucleos_needs_command" -f -a "lts-diagnose" -d '(dev) Stream a verbose `[dbg]` trace of one handler\'s LTS exploration (emitted edges, requires-call replies, external- spontaneous fire/no-fire, dedup NEW/MERGE) for a target post-trigger state — for localising weak-failures divergences'
complete -c nucleos -n "__fish_nucleos_needs_command" -f -a "verify" -d 'Check a Dezyne model for verification errors (deadlock, livelock, illegal, ...)'
complete -c nucleos -n "__fish_nucleos_needs_command" -f -a "simulate" -d 'Simulate a Dezyne model against a trace'
complete -c nucleos -n "__fish_nucleos_needs_command" -f -a "trace" -d '(dev) Convert `simulate` textual output to sequence-diagram JSON, identical to `dzn trace -f json`. Reads stdin or FILE; output is always JSON (no `-f`). Backs the IDE trace view'
complete -c nucleos -n "__fish_nucleos_needs_command" -f -a "sim-judge" -d '(dev) Judge a simulate/repl output against a golden under the L4 shape-regression policy (docs/sim_judge_design.md). Prints the verdict; exit 0 Pass/Excused, 1 Fail. Advisory shape check — NOT correctness'
complete -c nucleos -n "__fish_nucleos_using_subcommand anonymize" -l output -d 'Output format: `text` (default) or `json`' -r -f -a "text\t''
json\t''"
complete -c nucleos -n "__fish_nucleos_using_subcommand anonymize" -s h -l help -d 'Print help'
complete -c nucleos -n "__fish_nucleos_using_subcommand bug-report" -s o -l out -d 'Output path; extension picks format (.zip / .tar.gz / .tgz / .tar)' -r -F
complete -c nucleos -n "__fish_nucleos_using_subcommand bug-report" -l model -d 'Include this .dzn file (flattened via `parse -E`)' -r -F
complete -c nucleos -n "__fish_nucleos_using_subcommand bug-report" -s I -l import -d 'Import directory for --model (repeatable)' -r -F
complete -c nucleos -n "__fish_nucleos_using_subcommand bug-report" -l panic-log -d 'Include this captured panic stderr (overrides last-panic.log auto-pickup)' -r -F
complete -c nucleos -n "__fish_nucleos_using_subcommand bug-report" -l capture-output -d 'Include this captured run output (overrides last-run.log auto-pickup)' -r -F
complete -c nucleos -n "__fish_nucleos_using_subcommand bug-report" -l description -d 'Free-text "what went wrong" note' -r
complete -c nucleos -n "__fish_nucleos_using_subcommand bug-report" -l output -d 'Output format: `text` (default) or `json`' -r -f -a "text\t''
json\t''"
complete -c nucleos -n "__fish_nucleos_using_subcommand bug-report" -l anonymize -d 'Force-anonymize the model (skips the anonymize prompt)'
complete -c nucleos -n "__fish_nucleos_using_subcommand bug-report" -l no-anonymize -d 'Force-DO-NOT-anonymize the model (skips the anonymize prompt)'
complete -c nucleos -n "__fish_nucleos_using_subcommand bug-report" -l no-last-panic -d 'Skip auto-pickup of last-panic.log'
complete -c nucleos -n "__fish_nucleos_using_subcommand bug-report" -l no-last-run -d 'Skip auto-pickup of last-run.log'
complete -c nucleos -n "__fish_nucleos_using_subcommand bug-report" -l no-infer -d 'Skip argv inference from last-{panic,run}.log'
complete -c nucleos -n "__fish_nucleos_using_subcommand bug-report" -l no-env -d 'Skip env-var collection (privacy override)'
complete -c nucleos -n "__fish_nucleos_using_subcommand bug-report" -s y -l yes -d 'Non-interactive: skip all prompts, take each default. The "include source" default is NO unless --model was explicit or --include-source was passed, so scripted runs never bundle source by accident'
complete -c nucleos -n "__fish_nucleos_using_subcommand bug-report" -l include-source -d 'Force "yes" to the source-inclusion prompt — explicitly opts a non-interactive run into bundling the inferred model. No effect when source is already locked in via `--model`. Pair with `--yes` for CI use'
complete -c nucleos -n "__fish_nucleos_using_subcommand bug-report" -s h -l help -d 'Print help'
complete -c nucleos -n "__fish_nucleos_using_subcommand parse" -s I -l import -d 'Add DIR to import path (repeatable)' -r
complete -c nucleos -n "__fish_nucleos_using_subcommand parse" -l output -d 'Output format: `text` (default) or `json`' -r -f -a "text\t''
json\t''"
complete -c nucleos -n "__fish_nucleos_using_subcommand parse" -s E -l preprocess -d 'Resolve imports and write the flattened source to stdout (gcc-style preprocessor mode). Skips WFC'
complete -c nucleos -n "__fish_nucleos_using_subcommand parse" -s D -l no-directives -d 'With `-E`: omit the `#file`/`#imported` directive lines, emitting only the concatenated source. Re-parsing such output loses the per-file (line, col) tracking — locations report against the flattened stream instead of the original sources'
complete -c nucleos -n "__fish_nucleos_using_subcommand parse" -s l -l list-models -d 'Print `<name> <type>` for each model declared in FILE — one per line, in source order — then exit. `<type>` is one of `interface`, `component`, `foreign`, `system`. Only models declared in FILE are listed (imports are not resolved), mirroring `dzn parse --list-models`'
complete -c nucleos -n "__fish_nucleos_using_subcommand parse" -s h -l help -d 'Print help'
complete -c nucleos -n "__fish_nucleos_using_subcommand inspect-ports" -s m -l model -d 'Restrict introspection to model MODEL (e.g. `-m hello_bool`). When omitted the subcommand picks a default the same way `verify` does (the file\'s main-component / iface)' -r
complete -c nucleos -n "__fish_nucleos_using_subcommand inspect-ports" -s I -l import -d 'Add DIR to import path (repeatable)' -r
complete -c nucleos -n "__fish_nucleos_using_subcommand inspect-ports" -l output -d 'Output format: `text` (default) or `json`' -r -f -a "text\t''
json\t''"
complete -c nucleos -n "__fish_nucleos_using_subcommand inspect-ports" -s h -l help -d 'Print help'
complete -c nucleos -n "__fish_nucleos_using_subcommand lts" -s m -l model -d 'Select component/interface by name' -r
complete -c nucleos -n "__fish_nucleos_using_subcommand lts" -s I -l import -d 'Add DIR to import path (repeatable)' -r
complete -c nucleos -n "__fish_nucleos_using_subcommand lts" -s q -l queue-size -d 'Event queue size [3]' -r
complete -c nucleos -n "__fish_nucleos_using_subcommand lts" -l queue-size-defer -d 'Defer queue size [2]' -r
complete -c nucleos -n "__fish_nucleos_using_subcommand lts" -l queue-size-external -d 'External queue size [1]' -r
complete -c nucleos -n "__fish_nucleos_using_subcommand lts" -l output -d 'Output format: `text` (default) or `json`' -r -f -a "text\t''
json\t''"
complete -c nucleos -n "__fish_nucleos_using_subcommand lts" -l full-lts -d 'Emit the full LTS instead of the fail-fast one. By default `lts` stops exploration on the first error edge — the same (possibly truncated) graph `verify` consumes — so the two commands agree. `--full-lts` forces a complete exploration of every reachable state'
complete -c nucleos -n "__fish_nucleos_using_subcommand lts" -l defer-origin -d 'Tag each `<defer>` discharge edge with its origin leaf (`<defer:<inst>>`) in the RTC-product system LTS. OFF by default (bare `<defer>`, matching dzn). No effect on non-system models'
complete -c nucleos -n "__fish_nucleos_using_subcommand lts" -s h -l help -d 'Print help'
complete -c nucleos -n "__fish_nucleos_using_subcommand traces" -s m -l model -d 'Select component/interface by name' -r
complete -c nucleos -n "__fish_nucleos_using_subcommand traces" -s I -l import -d 'Add DIR to import path (repeatable)' -r
complete -c nucleos -n "__fish_nucleos_using_subcommand traces" -s o -l output-dir -d 'Write traces to DIR as `<model>.trace.<N>` (default "."); `-` writes all traces to stdout. (Long form is `--output-dir`; the global `--output` selects the text/json report mode.)' -r
complete -c nucleos -n "__fish_nucleos_using_subcommand traces" -s q -l queue-size -d 'Event queue size [3]' -r
complete -c nucleos -n "__fish_nucleos_using_subcommand traces" -l queue-size-defer -d 'Defer queue size [2]' -r
complete -c nucleos -n "__fish_nucleos_using_subcommand traces" -l queue-size-external -d 'External queue size [1]' -r
complete -c nucleos -n "__fish_nucleos_using_subcommand traces" -l output -d 'Output format: `text` (default) or `json`' -r -f -a "text\t''
json\t''"
complete -c nucleos -n "__fish_nucleos_using_subcommand traces" -s f -l flush -d 'Include `<flush>` events in the traces'
complete -c nucleos -n "__fish_nucleos_using_subcommand traces" -s i -l illegal -d 'Include traces that lead to an illegal'
complete -c nucleos -n "__fish_nucleos_using_subcommand traces" -l defer-origin -d 'Tag each `<defer>` discharge edge with its origin leaf (`<defer:<inst>>`) in the system LTS. OFF by default (bare `<defer>`). Replay such traces with `simulate --defer-origin`. No effect on non-system models'
complete -c nucleos -n "__fish_nucleos_using_subcommand traces" -s h -l help -d 'Print help'
complete -c nucleos -n "__fish_nucleos_using_subcommand lts-walk" -s m -l model -d 'Select component/interface by name' -r
complete -c nucleos -n "__fish_nucleos_using_subcommand lts-walk" -s I -l import -d 'Add DIR to import path (repeatable)' -r
complete -c nucleos -n "__fish_nucleos_using_subcommand lts-walk" -s t -l trail -d 'Read trace from FILE (default: stdin)' -r
complete -c nucleos -n "__fish_nucleos_using_subcommand lts-walk" -s q -l queue-size -d 'Event queue size' -r
complete -c nucleos -n "__fish_nucleos_using_subcommand lts-walk" -l queue-size-defer -d 'Defer queue size' -r
complete -c nucleos -n "__fish_nucleos_using_subcommand lts-walk" -l queue-size-external -d 'External queue size' -r
complete -c nucleos -n "__fish_nucleos_using_subcommand lts-walk" -l compare-aut -d 'Walk the same trace through a second LTS read from FILE (Aldebaran .aut) and at every step diff the weak-refusal sets. Halts on the first non-empty diff, dumping the full state context. Use to localize structural divergence vs. a dzn/golden LTS' -r
complete -c nucleos -n "__fish_nucleos_using_subcommand lts-walk" -l output -d 'Output format: `text` (default) or `json`' -r -f -a "text\t''
json\t''"
complete -c nucleos -n "__fish_nucleos_using_subcommand lts-walk" -l show-eligible -d 'Print weak-outgoing label set at each step'
complete -c nucleos -n "__fish_nucleos_using_subcommand lts-walk" -l state-as-tau -d 'Treat `port.<state>(...)` labels as tau when looking for the next step (off by default — ltscompare\'s `--tau` only covers `<flush>`)'
complete -c nucleos -n "__fish_nucleos_using_subcommand lts-walk" -s h -l help -d 'Print help'
complete -c nucleos -n "__fish_nucleos_using_subcommand lts-diagnose" -s m -l model -d 'Select component by name' -r
complete -c nucleos -n "__fish_nucleos_using_subcommand lts-diagnose" -s I -l import -d 'Add DIR to import path (repeatable)' -r
complete -c nucleos -n "__fish_nucleos_using_subcommand lts-diagnose" -l state -d 'Post-trigger LTS state id whose handler exploration to trace verbosely (the state the trigger event lands on; find it with `lts-walk --compare-aut`). Equivalent to `NUC_DBG_STATE`' -r
complete -c nucleos -n "__fish_nucleos_using_subcommand lts-diagnose" -s q -l queue-size -d 'Event queue size' -r
complete -c nucleos -n "__fish_nucleos_using_subcommand lts-diagnose" -l queue-size-defer -d 'Defer queue size' -r
complete -c nucleos -n "__fish_nucleos_using_subcommand lts-diagnose" -l queue-size-external -d 'External queue size' -r
complete -c nucleos -n "__fish_nucleos_using_subcommand lts-diagnose" -l output -d 'Output format: `text` (default) or `json`' -r -f -a "text\t''
json\t''"
complete -c nucleos -n "__fish_nucleos_using_subcommand lts-diagnose" -s h -l help -d 'Print help'
complete -c nucleos -n "__fish_nucleos_using_subcommand verify" -s m -l model -d 'Restrict verification to model MODEL' -r
complete -c nucleos -n "__fish_nucleos_using_subcommand verify" -s I -l import -d 'Add DIR to import path (repeatable)' -r
complete -c nucleos -n "__fish_nucleos_using_subcommand verify" -s q -l queue-size -d 'Event queue size [3]' -r
complete -c nucleos -n "__fish_nucleos_using_subcommand verify" -l queue-size-defer -d 'Defer queue size [2]' -r
complete -c nucleos -n "__fish_nucleos_using_subcommand verify" -l queue-size-external -d 'External queue size [1]' -r
complete -c nucleos -n "__fish_nucleos_using_subcommand verify" -l output -d 'Output format: `text` (default) or `json`' -r -f -a "text\t''
json\t''"
complete -c nucleos -n "__fish_nucleos_using_subcommand verify" -s k -l keep-going -d 'Keep verifying after finding an error (default: stop on first)'
complete -c nucleos -n "__fish_nucleos_using_subcommand verify" -l no-interfaces -d 'Skip interface verification'
complete -c nucleos -n "__fish_nucleos_using_subcommand verify" -s U -l no-unreachable -d 'Skip the unreachable code check'
complete -c nucleos -n "__fish_nucleos_using_subcommand verify" -l full-lts -d 'Explore the full LTS instead of stopping at the first error edge. Verify is fail-fast by default (it stops exploring once a reachable error is found, which is all the report needs); `--full-lts` forces a complete exploration of every reachable state. Same flag as `lts`'
complete -c nucleos -n "__fish_nucleos_using_subcommand verify" -s h -l help -d 'Print help'
complete -c nucleos -n "__fish_nucleos_using_subcommand simulate" -s m -l model -d 'Select component/interface by name' -r
complete -c nucleos -n "__fish_nucleos_using_subcommand simulate" -s I -l import -d 'Add DIR to import path (repeatable)' -r
complete -c nucleos -n "__fish_nucleos_using_subcommand simulate" -s t -l trail -d 'Read trace from FILE (default: stdin)' -r
complete -c nucleos -n "__fish_nucleos_using_subcommand simulate" -s q -l queue-size -d 'Event queue size [3]' -r
complete -c nucleos -n "__fish_nucleos_using_subcommand simulate" -l queue-size-defer -d 'Defer queue size [2]' -r
complete -c nucleos -n "__fish_nucleos_using_subcommand simulate" -l queue-size-external -d 'External queue size [1]' -r
complete -c nucleos -n "__fish_nucleos_using_subcommand simulate" -l check-trace -d 'Test the REPL against a golden trace FILE: drive the interactive engine using the trace as the "user" — at each turn the next env-choosable trace event is selected (it MUST be eligible), the RTC is executed, and each produced event is matched against the head of the trace (a mismatch fails with exit 1). The canonical simulate output is printed to stdout so it can be diffed against the golden `simulate.N`. Implies `--repl`' -r
complete -c nucleos -n "__fish_nucleos_using_subcommand simulate" -l output -d 'Output format: `text` (default) or `json`' -r -f -a "text\t''
json\t''"
complete -c nucleos -n "__fish_nucleos_using_subcommand simulate" -l repl -d 'REPL mode: stay running, after each RTC print the `(eligible …)` menu (to stderr) and read the next environment choice from stdin (one event per line); the chosen event is executed and driven to the end of its RTC (or to a valued requires-call awaiting a reply value). The canonical simulate output goes to stdout; `quit`/EOF ends the session. Environment choices in, produced events + verdicts deduced. On a terminal the prompt offers Tab completion of the eligible events, command history, and a `help` command'
complete -c nucleos -n "__fish_nucleos_using_subcommand simulate" -l defer-any-order -d 'Follow the trace\'s defer discharge order instead of assuming a global defer FIFO. The system LTS is over-approximating (the FIFO is not modelled — too expensive), so with this flag every valid LTS-generated trace renders rather than bailing on a non-FIFO cross-leaf discharge. See docs/global_defer_sync.md'
complete -c nucleos -n "__fish_nucleos_using_subcommand simulate" -l defer-origin -d 'Tag each `<defer>` discharge edge with its origin leaf (`<defer:<inst>>`) in the RTC-product system LTS. OFF by default (bare `<defer>`). A trace generated with this flag must be replayed with it; selfcheck uses it on both ends. Has no effect on non-system models'
complete -c nucleos -n "__fish_nucleos_using_subcommand simulate" -s f -l flush -d 'Explicit-flush mode: the model\'s traces were cut with `(flush #t)` (dzn META), so the interactive Extend renderer auto-produces the `p.<flush>` after every queue drain — mirroring `dzn traces --flush`. Without it a drain renders silently (batch\'s flush-less spelling). See flush_mode'
complete -c nucleos -n "__fish_nucleos_using_subcommand simulate" -s h -l help -d 'Print help'
complete -c nucleos -n "__fish_nucleos_using_subcommand trace" -l output -d 'Output format: `text` (default) or `json`' -r -f -a "text\t''
json\t''"
complete -c nucleos -n "__fish_nucleos_using_subcommand trace" -s h -l help -d 'Print help'
complete -c nucleos -n "__fish_nucleos_using_subcommand sim-judge" -l class -d 'Classification: shape (default) | exact | goldenartifact | nondet | stateartifact. When omitted, a `<golden>.judge` sidecar (first non-comment line) supplies the per-(model,trace) class' -r
complete -c nucleos -n "__fish_nucleos_using_subcommand sim-judge" -l output -d 'Output format: `text` (default) or `json`' -r -f -a "text\t''
json\t''"
complete -c nucleos -n "__fish_nucleos_using_subcommand sim-judge" -l emit-doc -d 'Emit the normative doc sections (§6/§7/§8) from the code, for the drift check (scripts/check_judge_doc.sh). Ignores golden/ours'
complete -c nucleos -n "__fish_nucleos_using_subcommand sim-judge" -s h -l help -d 'Print help'
