safe_chains/registry/types.rs
1use serde::Deserialize;
2
3use crate::verdict::SafetyLevel;
4
5#[path = "types_tables.rs"]
6mod tables;
7#[path = "transfer.rs"]
8mod transfer;
9pub(super) use tables::*;
10pub(super) use transfer::TomlTransfer;
11pub(crate) use transfer::{TransferSource, TransferSpec};
12
13#[derive(Debug, Deserialize)]
14pub(super) struct TomlFile {
15 // Defaulted so a user config that contains only `[[trusted]]` (the repo-pin
16 // list, parsed separately) is valid. Unknown tables like `[[trusted]]` are
17 // ignored here.
18 #[serde(default)]
19 pub command: Vec<TomlCommand>,
20}
21
22#[derive(Debug, Deserialize)]
23pub(super) struct TomlCommand {
24 pub name: String,
25 #[serde(default)]
26 pub description: Option<String>,
27 #[serde(default)]
28 pub candidate: Option<bool>,
29 #[serde(default)]
30 pub aliases: Vec<String>,
31 #[serde(default)]
32 pub url: String,
33 #[serde(default)]
34 pub level: Option<TomlLevel>,
35 #[serde(default)]
36 pub bare: Option<bool>,
37 #[serde(default)]
38 pub max_positional: Option<usize>,
39 /// This command PUTS ITS `NAME=VALUE` POSITIONALS INTO THE ENVIRONMENT (`export`, `declare -x`).
40 /// Each one is classified through `envvars.toml`, exactly as the `VAR=value cmd` prefix form is,
41 /// so the two spellings of one capability cannot disagree.
42 #[serde(default)]
43 pub env_assignment_positionals: Option<bool>,
44 /// Lowered into [`LineChecks::flag_value_shapes`].
45 #[serde(default)]
46 pub flag_value_shapes: std::collections::BTreeMap<String, String>,
47 /// Removed in favor of `tolerate_unknown_short` / `tolerate_unknown_long`; build panics if a TOML
48 /// still sets it (SAMPLE.toml has the migration), and keeping it here lets the panic name the command.
49 #[serde(default)]
50 pub positional_style: Option<bool>,
51 #[serde(default)]
52 pub tolerate_unknown_short: Option<bool>,
53 #[serde(default)]
54 pub tolerate_unknown_long: Option<bool>,
55 #[serde(default)]
56 pub numeric_dash: Option<bool>,
57 #[serde(default)]
58 pub single_dash_words: Option<bool>,
59 #[serde(default)]
60 pub standalone: Vec<String>,
61 #[serde(default)]
62 pub valued: Vec<String>,
63 /// Flags that take a value OPTIONALLY: `--long` and `--long=27` are both real spellings.
64 /// See `build_policy` for why this compiles down to the other two lists rather than adding
65 /// a state to the walk.
66 #[serde(default)]
67 pub optional_valued: Vec<String>,
68 #[serde(default)]
69 pub bare_flags: Vec<String>,
70 #[serde(default)]
71 pub sub: Vec<TomlSub>,
72 #[serde(default)]
73 pub handler: Option<String>,
74 #[serde(default)]
75 pub doc_body: Option<String>,
76 #[serde(default)]
77 pub require_any: Vec<String>,
78 #[serde(default)]
79 pub first_arg: Vec<String>,
80 /// Flags a `first_arg` GLOB family accepts. The glob admits an invocation on its first
81 /// positional alone, so without these it never examines the flags at all and
82 /// `--endpoint-url http://evil.com` rides along on a read. Empty = family not yet researched
83 /// (permissive, grandfathered — see `no_new_unresearched_first_arg_family`).
84 #[serde(default)]
85 pub first_arg_standalone: Vec<String>,
86 #[serde(default)]
87 pub first_arg_valued: Vec<String>,
88 /// Flags admitted only when their VALUE names this machine (`--endpoint-url
89 /// http://localhost:8000`). Same arity as `first_arg_valued`; the value is classified by
90 /// `netloc::is_loopback`, and anything not positively recognized as loopback denies.
91 #[serde(default)]
92 pub first_arg_loopback_valued: Vec<String>,
93 #[serde(default)]
94 pub credential_first_arg: Vec<String>,
95 /// Top-level classifying flags (`[[command.flag]]`): a flag whose PRESENCE classifies the WHOLE
96 /// invocation as an archetype — the flat-command analog of `[[command.sub.flag]]`. For a bimodal
97 /// tool where a mode flag flips the operation: `age -d` / `sops --decrypt` reveal plaintext to the
98 /// model (`decrypt-read`), while the bare/encrypt form is an ordinary local write. Resolved by
99 /// `engine::resolve` via `registry::command_flag_archetypes`; each flag's `classifies` must name a
100 /// known archetype and carry `fact`/`source` provenance (the `assert_command_flag_provenance` guard).
101 #[serde(default)]
102 pub flag: Vec<TomlSubFlag>,
103 #[serde(default)]
104 pub flag_valued: Vec<String>,
105 #[serde(default)]
106 pub wrapper: Option<TomlWrapper>,
107 #[serde(default)]
108 pub write_flags: Vec<String>,
109 /// Path-argument gate co-located with the command (`[command.path_gate]`): the read/write
110 /// role of each path-bearing flag value and of bare positionals. Consulted by
111 /// `pathgate::should_deny` so a `--output`/`-i` path can't ship ungated. Same shape as
112 /// `pathgates.toml`'s `[roles.X]`.
113 #[serde(default)]
114 pub path_gate: Option<crate::pathgate::RoleSpec>,
115 #[serde(default)]
116 pub researched_version: Option<String>,
117 /// Sample invocations that double as test fixtures.
118 /// `examples_safe` must validate as Allowed; `examples_denied` must validate as Denied.
119 /// Use these to exercise aliases and canonical forms (e.g. `mise use` and `mise u`)
120 /// so drift between the TOML and runtime dispatch fails the test suite.
121 #[serde(default)]
122 pub examples_safe: Vec<String>,
123 #[serde(default)]
124 pub examples_denied: Vec<String>,
125 /// Marks this command's leaf invocation as safe inside
126 /// `eval "$(CMD ...)"`. Set on flat commands whose stdout is documented
127 /// shell-init code (e.g. `ssh-agent`). The leaf is the deepest matched
128 /// dispatch node — tagging here does NOT propagate to subs; each sub
129 /// must be tagged independently. Unset = not eval-safe (the default).
130 #[serde(default)]
131 pub eval_safe: Option<bool>,
132 /// Flag allowlist that extends `eval_safe = true` — these `-`-prefixed
133 /// tokens are also permitted inside the substitution. Default empty,
134 /// meaning only the bare form plus positionals are eval-safe.
135 /// Build panics if this is set without `eval_safe = true`.
136 #[serde(default)]
137 pub eval_safe_flags: Vec<String>,
138 /// Per-valued-flag value allowlist. Maps each valued flag (which
139 /// MUST also appear in `eval_safe_flags`) to the set of values
140 /// permitted in eval substitutions. Use for tools where the flag's
141 /// value determines stdout shape (`aws --format env` vs
142 /// `--format json`). Default empty = no value restriction beyond
143 /// the bare-literal alphabet.
144 #[serde(default)]
145 pub eval_safe_flag_values: std::collections::HashMap<String, Vec<String>>,
146 /// Flags where AT LEAST ONE must appear in the eval substitution.
147 /// Use for tools whose bare invocation isn't shell-init code:
148 /// `fzf` is interactive without `--bash|--zsh|--fish|--nushell`.
149 /// Every entry must also appear in `eval_safe_flags`. Default
150 /// empty = no required flags (bare invocation is fine).
151 #[serde(default)]
152 pub eval_safe_required_flags: Vec<String>,
153 /// Shortcut: every invocation of this command is denied. Used in custom
154 /// TOMLs to lock down a built-in (e.g. `name = "gh", deny = true` in
155 /// `.safe-chains.toml` denies every gh form for that project).
156 #[serde(default)]
157 pub deny: Option<bool>,
158 /// Alternate grammar engaged when standard sub-dispatch finds no match.
159 /// Only meaningful for handler-using commands (e.g. tilt's Ruby template
160 /// engine fallback when no Kubernetes tilt sub matches). The handler is
161 /// responsible for invoking it via `registry::try_fallback_grammar()`.
162 #[serde(default)]
163 pub fallback: Option<TomlFallback>,
164 /// Named flag policies the handler references by string key. Used when
165 /// a handler's dispatch logic genuinely can't move to TOML (e.g. gh's
166 /// sub × action matrix) but the per-policy WordSets are still data that
167 /// should live in TOML. The handler reads them via
168 /// `registry::check_handler_policy(cmd, key, tokens)`.
169 #[serde(default)]
170 pub handler_policy: std::collections::HashMap<String, TomlHandlerPolicy>,
171 /// Parent × action → policy matrices. One block declares: "for
172 /// these parent subcommand names, each of these action verbs maps
173 /// to a named `handler_policy` and validates at this safety level."
174 /// Lets handlers express their dispatch tables as data instead of
175 /// `match` arms. Walked by `registry::try_matrix_dispatch()`.
176 #[serde(default)]
177 pub matrix: Vec<TomlMatrix>,
178 /// A `verb-chain` grammar (`mlr`): a strict main-flag region followed by a
179 /// `then`-chain of allowlisted verbs. Fully declarative — no handler needed.
180 #[serde(default)]
181 pub verb_chain: Option<TomlVerbChain>,
182 /// Declarative facet behavior (`[command.behavior]`) — the non-legacy classification
183 /// path. When present, the engine resolves this command by building a `Profile` from the
184 /// declared operation + operand-role + flags (see `engine::resolve::resolve_behavior`),
185 /// retiring a hardcoded `RESOLVERS` entry. The legacy `level` remains only as the
186 /// fallback the engine already overrides.
187 #[serde(default)]
188 pub behavior: Option<TomlBehavior>,
189 /// What this command's STDOUT can name (`[command.output]`) — the axis that decides whether a
190 /// `$(…)` around it yields a bounded path or an unknowable one. Absent (the default) means
191 /// unpinnable: the substitution worst-cases exactly as it always has. See
192 /// docs/design/behavioral-taxonomy-substitution-locus.md.
193 #[serde(default)]
194 pub output: Option<TomlOutput>,
195 /// What this command writes in its folder without naming a path; as on a sub.
196 #[serde(default)]
197 pub writes_cwd: Option<String>,
198 #[serde(default)]
199 pub output_dirs: Vec<String>,
200}
201
202/// `[command.output]` — a researched claim about where this command's stdout can POINT. It is a
203/// separate axis from every facet: how safe a command is to RUN says nothing about what its output
204/// names (`echo` is inert and `$(echo /etc/shadow)` names a credential file), so this is declared
205/// per command or not at all.
206#[derive(Debug, Deserialize)]
207#[serde(deny_unknown_fields)]
208pub(super) struct TomlOutput {
209 /// `operands` — output names paths beneath the command's own path operands (`fd`, `git
210 /// ls-files`); `cwd` — output names the working directory (`pwd`).
211 pub locus_from: String,
212 /// Flags under which the claim does NOT hold, because they change what stdout CONTAINS.
213 /// `fd -x cat {}` prints file contents rather than paths, and `fd -l` prints `ls -l` rows —
214 /// neither is a path any more, so the locus rule cannot describe them. Any of these present
215 /// makes the substitution unpinnable again.
216 #[serde(default)]
217 pub invalidated_by: Vec<String>,
218 /// Value-taking flags, so their VALUE is not mistaken for an operand (`head -n 5` takes no
219 /// file). Carried here rather than read off the legacy top-level `valued` for the same reason
220 /// `[command.behavior]` carries its own grammar: this claim is researched as a unit, and a
221 /// silently-shared list would let an unrelated edit change what counts as a root.
222 #[serde(default)]
223 pub valued: Vec<String>,
224 /// Flags of which at least ONE must be present, or the claim does not hold. The inverse of
225 /// `invalidated_by`, and needed by any command whose default output is not paths at all:
226 /// `git diff` prints a PATCH, and only `--name-only` turns it into a list of paths. Empty
227 /// (the normal case) means the claim holds for the bare invocation.
228 #[serde(default)]
229 pub requires: Vec<String>,
230}
231
232/// A command's declarative facet behavior (`[command.behavior]`). Field values that name a
233/// facet term are the kebab strings from `engine::facet` (`operation = "observe"`); the build
234/// maps them via `FacetTerm::from_term` and PANICS (naming the command) on an unknown term, so
235/// a typo can't silently mis-classify. The behavior carries its OWN flag grammar
236/// (`standalone`/`valued`), independent of the legacy top-level `standalone` — `rm`'s legacy
237/// flag set is restricted to `--help`/`--version` (so the legacy fallback can't fail-open on
238/// `rm -rf`), while its behavior grammar is the full destructive set.
239#[derive(Debug, Deserialize)]
240#[serde(deny_unknown_fields)]
241pub(super) struct TomlBehavior {
242 /// The act each operand capability performs — an `Operation` term
243 /// (`observe`/`create`/`mutate`/`destroy`/…).
244 pub operation: String,
245 /// How bare positionals are touched: `none` | `read` | `write` | `pattern-then-read` |
246 /// `transfer` (the closed set the `Operands` enum encodes).
247 pub positionals: String,
248 /// Scale model: `single` (every read is one item — cat/head) or `breadth`
249 /// (count/glob/recursion widen it — rm/mkdir). Defaults to `single`.
250 #[serde(default)]
251 pub scale: Option<String>,
252 /// Boolean flags this command accepts (behavior's own grammar). Single-dash single-char
253 /// tokens (`-r`) cluster; `--long` tokens are matched whole.
254 #[serde(default)]
255 pub standalone: Vec<String>,
256 /// Value-taking flags (consume the next token or a glued `=value`).
257 #[serde(default)]
258 pub valued: Vec<String>,
259 /// Accept the obsolete `-NUM` count shorthand (`head -20`).
260 #[serde(default)]
261 pub numeric_shorthand: Option<bool>,
262 /// Per-flag facet deltas — a flag whose presence widens scale (`"-r" = { scale =
263 /// "unbounded" }`), consumes a path value, or supplies a pattern.
264 #[serde(default)]
265 pub flags: std::collections::HashMap<String, TomlBehaviorFlag>,
266 /// Thin custom hook for the irreducible token logic a declaration can't express
267 /// (`grep`'s pattern-vs-file disambiguation). Composes: it returns the classified operand
268 /// set; the facets + level projection stay declarative. Absent = pure declarative.
269 #[serde(default)]
270 pub hook: Option<String>,
271 /// Transfer semantics (`[command.behavior.transfer]`), REQUIRED when `positionals =
272 /// "transfer"` — the source-operand operation and the clobber/recursion flag sets that a
273 /// `cp`/`mv`/`ln`-shaped command differs on.
274 #[serde(default)]
275 pub transfer: Option<TomlTransfer>,
276}
277
278/// One flag's contribution to a `[command.behavior]` profile: a scale bump when present, and/or
279/// a path role on the flag's VALUE (a valued flag whose value is a path safe-chains must gate,
280/// e.g. `touch -r REF` reads REF's timestamp — folds the `[command.path_gate]` idea into behavior).
281#[derive(Debug, Deserialize)]
282#[serde(deny_unknown_fields)]
283pub(super) struct TomlBehaviorFlag {
284 /// Scale bump when present (`"-r" = { scale = "unbounded" }`).
285 #[serde(default)]
286 pub scale: Option<String>,
287 /// The flag's VALUE is a path with this role: `read` (gated by its read locus) or `write`
288 /// (gated by its write locus). The flag must be a valued flag (in `valued`).
289 #[serde(default)]
290 pub kind: Option<String>,
291}
292
293/// A `verb-chain` command grammar: `CMD [main-flags…] verb [args…] then verb [args…] …`
294/// (`mlr`). The main-flag region is a STRICT allowlist (an unlisted flag denies — so a
295/// mutating flag like mlr's `-I`/`--in-place`, omitted, is caught by omission); the verb
296/// region is a `then`-chain where every verb NAME must be on the `verbs` allowlist (verb
297/// ARGS are open-ended and not inspected — a pure verb has no shell/file escape).
298#[derive(Debug, Deserialize)]
299#[serde(deny_unknown_fields)]
300pub(super) struct TomlVerbChain {
301 #[serde(default)]
302 pub level: Option<TomlLevel>,
303 /// The chain separator keyword (mlr: `then`). Defaults to `then`.
304 #[serde(default)]
305 pub separator: Option<String>,
306 /// Boolean main flags (no value). SAFETY: every value-TAKING main flag must go in
307 /// `main_valued` instead, or the walk mistakes its value for the verb boundary and a
308 /// later mutating flag slips past in verb-land.
309 #[serde(default)]
310 pub main_standalone: Vec<String>,
311 /// Value-taking main flags (`--from FILE`, `--ifs ,`), each consuming the next token.
312 #[serde(default)]
313 pub main_valued: Vec<String>,
314 /// Variadic main flags (mlr `--mfrom A B …`) that consume tokens until a `--` terminator.
315 #[serde(default)]
316 pub main_variadic: Vec<String>,
317 /// The allowlist of verb names permitted in every `then`-segment.
318 #[serde(default)]
319 pub verbs: Vec<String>,
320}
321
322#[derive(Debug, Deserialize)]
323#[serde(deny_unknown_fields)]
324pub(super) struct TomlMatrix {
325 pub parents: Vec<String>,
326 pub level: TomlLevel,
327 pub actions: std::collections::HashMap<String, TomlMatrixAction>,
328}
329
330#[derive(Debug, Deserialize)]
331#[serde(untagged)]
332pub(super) enum TomlMatrixAction {
333 /// Shorthand: `list = "policy_name"` — references handler_policy by
334 /// name; no guard required.
335 Policy(String),
336 /// Detailed form: `download = { policy = "release_download", guard
337 /// = "--output", guard_short = "-O" }`. The guard flag must be
338 /// present in the action's args for the dispatch to succeed.
339 Detailed(TomlMatrixActionDetailed),
340}
341
342#[derive(Debug, Deserialize)]
343#[serde(deny_unknown_fields)]
344pub(super) struct TomlMatrixActionDetailed {
345 pub policy: String,
346 #[serde(default)]
347 pub guard: Option<String>,
348 #[serde(default)]
349 pub guard_short: Option<String>,
350}
351
352/// One `[[command.sub.flag]]`: a flag that escalates its sub's classification when present.
353#[derive(Debug, Deserialize)]
354pub(super) struct TomlSubFlag {
355 pub name: String,
356 /// The archetype (`archetypes.toml`) this flag's presence ADDS to the profile — or
357 /// `"unclassified"` to worst-case (fail-closed) a flag whose effect we can't yet name.
358 pub classifies: String,
359 /// Optional value-match: escalate only when the flag's VALUE starts with this prefix (space
360 /// form `-c core.sshCommand=…` or glued `--flag=core.sshCommand=…`). Absent = escalate on the
361 /// flag's mere PRESENCE (a bare flag like `--force`). This is what lets ONE valued flag be
362 /// benign for most values and dangerous for a specific key (`git -c core.sshCommand=` = exec).
363 #[serde(default)]
364 pub value_prefix: Option<String>,
365 /// `true` INVERTS the trigger: escalate when the flag is ABSENT, not present. For a SAFETY flag
366 /// whose absence is the risk — `npm ci` runs lifecycle scripts UNLESS `--ignore-scripts` is
367 /// given, so its base profile (local-install-pinned) escalates to supply-chain-build when
368 /// `--ignore-scripts` is missing. Mutually exclusive with `value_prefix`.
369 #[serde(default)]
370 pub when_absent: Option<bool>,
371 #[serde(default)]
372 pub fact: Option<String>,
373 #[serde(default)]
374 pub source: Option<String>,
375 #[serde(default)]
376 pub judgment: Option<String>,
377}
378
379#[derive(Debug, Deserialize)]
380pub(super) struct TomlSub {
381 pub name: String,
382 /// This sub also matches with ONE arbitrary trailing `:segment`, which inherits this sub's
383 /// classification unchanged.
384 ///
385 /// For Rails' per-database rake tasks. A Rails 8 app has four databases out of the box
386 /// (solid_cache, solid_queue, solid_cable), and rake generates a variant of each schema task
387 /// per database: `db:migrate:primary`, `db:create:cache`, `db:drop:queue`. Fourteen base tasks
388 /// times four databases is 56 names, and enumerating them does not even work — the segment is
389 /// a key out of the app's own `config/database.yml`, so another app has `db:migrate:analytics`.
390 ///
391 /// Sound because the variant is strictly NARROWER than the base: `db:migrate:primary` migrates
392 /// one of the databases `db:migrate` migrates all of. Inheriting the base's classification is
393 /// therefore never a widening — `db:drop:cache` lands wherever `db:drop` already sits.
394 ///
395 /// Set it only where that containment argument holds. It is not a general "ignore the tail":
396 /// the suffix must be a single plain identifier, and a sub that means something DIFFERENT with
397 /// a suffix must keep declaring it separately.
398 #[serde(default)]
399 pub per_database: bool,
400 #[serde(default)]
401 pub candidate: Option<bool>,
402 /// A facet archetype name (`archetypes.toml`) — the Phase-1 successor to `candidate = true`:
403 /// instead of hand-marking the sub above the line, it declares which recurring capability
404 /// profile it is, and the engine DERIVES the verdict by projecting that profile through the
405 /// levels. See `docs/design/behavioral-taxonomy-archetypes.md`.
406 #[serde(default)]
407 pub profile: Option<String>,
408 /// Per-item research provenance for the classification (required when `profile` is set — the
409 /// `every_profiled_sub_has_provenance` guard). Three layers so a future researcher can act on
410 /// each precisely: `fact` = what the upstream tool DOCUMENTS (re-check `source` if it moves),
411 /// the `profile` itself = our inference (which archetype it maps to), `judgment` = our stance
412 /// where the source doesn't decide it (a policy call they may revisit). `source` cites the
413 /// upstream doc/section. See `docs/design/behavioral-taxonomy-archetypes.md` §3.
414 #[serde(default)]
415 pub fact: Option<String>,
416 #[serde(default)]
417 pub source: Option<String>,
418 #[serde(default)]
419 pub judgment: Option<String>,
420 #[serde(default)]
421 pub aliases: Vec<String>,
422 #[serde(default)]
423 pub level: Option<TomlLevel>,
424 #[serde(default)]
425 pub bare: Option<bool>,
426 #[serde(default)]
427 pub max_positional: Option<usize>,
428 #[serde(default)]
429 pub min_positional: Option<usize>,
430 /// Removed; see TomlCommand::positional_style.
431 #[serde(default)]
432 pub positional_style: Option<bool>,
433 #[serde(default)]
434 pub tolerate_unknown_short: Option<bool>,
435 #[serde(default)]
436 pub tolerate_unknown_long: Option<bool>,
437 #[serde(default)]
438 pub numeric_dash: Option<bool>,
439 #[serde(default)]
440 pub standalone: Vec<String>,
441 #[serde(default)]
442 pub valued: Vec<String>,
443 #[serde(default)]
444 pub optional_valued: Vec<String>,
445 #[serde(default)]
446 pub guard: Option<String>,
447 #[serde(default)]
448 pub guard_short: Option<String>,
449 #[serde(default)]
450 pub allow_all: Option<bool>,
451 /// Reference a `[command.handler_policy.KEY]` block by name, copying
452 /// its standalone/valued/bare/etc. into this sub's effective policy.
453 /// Lets a single-sub form (search, browse, gh status) re-use the
454 /// same flag list a matrix entry would, without duplicating the
455 /// WordSets. Mutually exclusive with inline standalone/valued.
456 #[serde(default)]
457 pub policy: Option<String>,
458 #[serde(default)]
459 pub sub: Vec<TomlSub>,
460 /// Per-FLAG escalation + provenance (`[[command.sub.flag]]`): a flag that, when present, ADDS a
461 /// capability to this sub's resolved profile — `git push --force` (→ destroy), `-c
462 /// core.sshCommand=` (→ execution). The level algebra takes the max over the added capabilities,
463 /// so a benign base + a dangerous flag lands at the flag's tier. See
464 /// `docs/design/behavioral-taxonomy-archetypes.md` §3 (per-flag layer).
465 #[serde(default)]
466 pub flag: Vec<TomlSubFlag>,
467 /// `true` marks the sub's first positional as a NETWORK DESTINATION whose *provenance* the
468 /// engine classifies onto `locus.provenance` (established remote-name / literal URL / opaque
469 /// `$VAR`), and whose command-transport form (`ext::<cmd>`) worst-cases as RCE. For
470 /// `git push` and its kin (`scp`/`rsync`/`curl -d`). See `behavioral-taxonomy-exposure.md` §4.
471 #[serde(default)]
472 pub network_destination: Option<bool>,
473 /// A flag that ALSO carries the destination and OVERRIDES the positional (`git push
474 /// --repo=<dest>`). Classified with the same provenance rules — so `--repo=ext::sh` is caught as
475 /// RCE. Requires `network_destination`.
476 #[serde(default)]
477 pub destination_flag: Option<String>,
478 /// Flags whose VALUE is a local output-file path, for a `data-export` sub (`supabase db dump
479 /// -f`, `pg_dump --file`). When one is present the engine adds a path-gated write capability at
480 /// that file's locus — a dump to `./out.sql` is a worktree write, one to `/etc/cron.d/job` a
481 /// system write. Absent (the export goes to stdout) → no write, just the bulk remote read.
482 /// Requires `profile` (only a `data-export` sub has an output file). See
483 /// `behavioral-taxonomy-exposure.md`.
484 #[serde(default)]
485 pub output_path_flags: Vec<String>,
486 /// What this sub writes in the folder it runs in without naming a path: `"output"` (with
487 /// `output_dirs`), `"source"`, or `"none"`. See `registry::cwd_writes`.
488 #[serde(default)]
489 pub writes_cwd: Option<String>,
490 #[serde(default)]
491 pub output_dirs: Vec<String>,
492 /// Flags naming a network endpoint that must be on THIS machine (`--endpoint-url
493 /// http://localhost:8000`). Two effects, both keyed on `netloc::is_loopback`: the flag is
494 /// admitted only with a loopback value, and a loopback value re-classifies the sub's
495 /// non-destroy capabilities as local (`resolve`'s loopback modifier). Declare only where a
496 /// local emulator is a researched workflow for that service.
497 #[serde(default)]
498 pub loopback_valued: Vec<String>,
499 /// Whether a `loopback_valued` flag naming this machine re-classifies the sub: `resolve` clears
500 /// the destination-determined facets (remote reach, net direction, payload, metered cost) and
501 /// leaves everything describing the operation alone. Absent = the sub keeps its remote
502 /// classification whatever the destination; mandatory for destroy archetypes, build-enforced.
503 #[serde(default)]
504 pub loopback_localizes: Option<bool>,
505 #[serde(default)]
506 pub nested_bare: Option<bool>,
507 #[serde(default)]
508 pub require_any: Vec<String>,
509 #[serde(default)]
510 pub first_arg: Vec<String>,
511 /// Flags a `first_arg` GLOB family accepts. The glob admits an invocation on its first
512 /// positional alone, so without these it never examines the flags at all and
513 /// `--endpoint-url http://evil.com` rides along on a read. Empty = family not yet researched
514 /// (permissive, grandfathered — see `no_new_unresearched_first_arg_family`).
515 #[serde(default)]
516 pub first_arg_standalone: Vec<String>,
517 #[serde(default)]
518 pub first_arg_valued: Vec<String>,
519 /// Flags admitted only when their VALUE names this machine (`--endpoint-url
520 /// http://localhost:8000`). Same arity as `first_arg_valued`; the value is classified by
521 /// `netloc::is_loopback`, and anything not positively recognized as loopback denies.
522 #[serde(default)]
523 pub first_arg_loopback_valued: Vec<String>,
524 /// First-positional globs (`secret`, `secret/*`) that make this sub a CREDENTIAL-READ: matching
525 /// denies, before the allow-glob. The value-dependent complement to `profile=credential-read`
526 /// (whole sub) — `kubectl get secret/x`, `aws configure get aws_secret_access_key`.
527 #[serde(default)]
528 pub credential_first_arg: Vec<String>,
529 #[serde(default)]
530 pub write_flags: Vec<String>,
531 #[serde(default)]
532 pub delegate_after: Option<String>,
533 #[serde(default)]
534 pub delegate_skip: Option<usize>,
535 /// `"file"` (first positional is the executor path — `go run ./cmd`) or `"project"`
536 /// (the current project is the executor — `cargo run`). Gates via the execution-origin
537 /// engine instead of a flat level. See `DispatchKind::Executor`.
538 #[serde(default)]
539 pub executor: Option<String>,
540 /// A valued flag whose value redirects the executor out of the project
541 /// (`cargo run --manifest-path DIR/Cargo.toml`); its value is locus-gated. `Project` only.
542 #[serde(default)]
543 pub executor_redirect_flag: Option<String>,
544 /// Predicate the executor path must satisfy (`"go-package"`), else deny. `File` only.
545 #[serde(default)]
546 pub positional_shape: Option<String>,
547 /// Tokens after the executor path are the SCRIPT's argv, not this command's own arguments.
548 ///
549 /// An interpreter passes them through (`python3 ./task.py --flag arg`) and its flag grammar
550 /// cannot describe them, so only the prefix up to the script is checked. A tool that merely
551 /// TAKES a path does not: a second positional on `karma start` is a second config file it
552 /// loads and executes, and it must be counted by `max_positional`.
553 ///
554 /// Defaults to false, the enforcing answer, so a new File executor is governed by its own
555 /// declared grammar unless someone states otherwise.
556 #[serde(default)]
557 pub passes_argv: Option<bool>,
558 #[serde(default)]
559 pub handler: Option<String>,
560 #[serde(default)]
561 pub doc_body: Option<String>,
562 /// Marks this sub's leaf invocation as safe inside
563 /// `eval "$(CMD SUB ...)"`. The leaf is the deepest matched dispatch
564 /// node — if this sub has nested sub-subs and the invocation matches
565 /// deeper, the tag does NOT apply; the sub-sub must be tagged itself.
566 /// Unset = not eval-safe (the default).
567 #[serde(default)]
568 pub eval_safe: Option<bool>,
569 /// Flag allowlist that extends `eval_safe = true` — these `-`-prefixed
570 /// tokens are also permitted inside the substitution. Default empty,
571 /// meaning only the bare form plus positionals are eval-safe.
572 /// Build panics if this is set without `eval_safe = true`.
573 #[serde(default)]
574 pub eval_safe_flags: Vec<String>,
575 /// Per-valued-flag value allowlist (same semantics as the
576 /// command-level field). Maps each valued flag (which MUST also
577 /// appear in `eval_safe_flags`) to its permitted values.
578 #[serde(default)]
579 pub eval_safe_flag_values: std::collections::HashMap<String, Vec<String>>,
580 /// Flags where AT LEAST ONE must appear (same semantics as the
581 /// command-level field).
582 #[serde(default)]
583 pub eval_safe_required_flags: Vec<String>,
584 /// `[command.sub.output]` — what THIS SUB's stdout can name (same shape and
585 /// semantics as the command-level `[command.output]`).
586 ///
587 /// Sub-scoped because the claim rarely holds for a whole multi-command tool:
588 /// `git diff --name-only` prints worktree paths, while `git log` prints prose
589 /// and `git config --get` prints whatever was configured. A command-level
590 /// claim would have to be voided by an `invalidated_by` list naming every
591 /// other subcommand, which is a denylist and fails open on the next one git
592 /// adds.
593 #[serde(default)]
594 pub output: Option<TomlOutput>,
595 #[serde(default)]
596 pub passthrough: Option<TomlPassthrough>,
597}
598
599#[derive(Debug, Clone, Copy, Deserialize)]
600pub(super) enum TomlLevel {
601 Inert,
602 SafeRead,
603 SafeWrite,
604}
605
606impl From<TomlLevel> for SafetyLevel {
607 fn from(l: TomlLevel) -> Self {
608 match l {
609 TomlLevel::Inert => SafetyLevel::Inert,
610 TomlLevel::SafeRead => SafetyLevel::SafeRead,
611 TomlLevel::SafeWrite => SafetyLevel::SafeWrite,
612 }
613 }
614}
615
616#[derive(Debug)]
617pub struct CommandSpec {
618 pub name: String,
619 pub description: String,
620 pub aliases: Vec<String>,
621 pub url: String,
622 pub category: String,
623 /// Upstream version of the underlying tool that was researched
624 /// when this spec was last updated. Free-form string — e.g.
625 /// `"1.9.0"`, `"v5.10.3"`, `"2026-05-08 master"`,
626 /// `"@northflank/cli 0.10.15"`. Internal-only: not rendered in
627 /// docs or used at runtime. Surfaces in tests and as a tripwire
628 /// when researching newer versions of the same tool.
629 pub researched_version: Option<String>,
630 /// Sample invocations that the registry test runs through `is_safe_command`.
631 /// Each `examples_safe` entry must produce `Verdict::Allowed`.
632 pub examples_safe: Vec<String>,
633 /// Sample invocations that must be denied. Use these to lock in security
634 /// boundaries (e.g. `srb tc --metrics-file=/etc/passwd` should always
635 /// be denied; recording it here catches regressions).
636 pub examples_denied: Vec<String>,
637 /// True when this command's bare invocation (no sub) is tagged as
638 /// safe-to-eval. Walked by `registry::is_eval_safe_invocation()`.
639 pub eval_safe: bool,
640 /// Flag allowlist extending `eval_safe` — flags permitted in the
641 /// substituted invocation when the walker stops at this node.
642 pub eval_safe_flags: Vec<String>,
643 /// Per-valued-flag value allowlist. When the walker hits a flag
644 /// listed here, the value following the flag (separated by `=` or
645 /// space) must be in this list.
646 pub eval_safe_flag_values: std::collections::HashMap<String, Vec<String>>,
647 /// Flags where at least one must appear in the substituted
648 /// invocation. Empty = no required-flag constraint.
649 pub eval_safe_required_flags: Vec<String>,
650 /// The command's own path-argument gate (`[command.path_gate]`), if declared. Read by
651 /// `registry::command_path_gate` → `pathgate::should_deny`.
652 pub(super) path_gate: Option<crate::pathgate::RoleSpec>,
653 /// `[[command.flag]]`, read by `registry::command_flag_archetypes` → `engine::resolve::resolve`.
654 pub(super) archetype_flags: super::build::ArchetypeFlags,
655 /// Declarative facet behavior (`[command.behavior]`), lowered to typed facet enums. Read
656 /// by `registry::command_behavior` → `engine::resolve::resolve_behavior`. When present,
657 /// the engine classifies this command from its declared facets instead of a Rust resolver.
658 pub(super) behavior: Option<BehaviorSpec>,
659 /// Lowered `[command.output]` — read by `registry::command_output_locus` →
660 /// `engine::resolve::substitution_locus`, which decides whether a `$(…)` around this command
661 /// yields a bounded path instead of the unpinnable sentinel.
662 pub(super) output: Option<OutputSpec>,
663 pub(super) writes_cwd: Option<crate::pathctx::anchor::Anchor>,
664 pub(super) line_checks: LineChecks,
665 pub(super) kind: DispatchKind,
666}
667
668/// A command's declarative facet behavior, lowered from `[command.behavior]` (`TomlBehavior`)
669/// with every facet string resolved to its enum at build time. The generic resolver reads this
670/// plus the tokens and builds a `Profile`. Clone so it can be attached uniformly across the
671/// `build_command` construction sites.
672#[derive(Debug, Clone)]
673pub(crate) struct BehaviorSpec {
674 pub operation: crate::engine::facet::Operation,
675 pub positionals: PositionalRole,
676 pub scale: ScaleModel,
677 /// Behavior's own flag grammar, pre-split for the shared `walk_positionals`.
678 pub short: Vec<u8>,
679 pub valued_short: Vec<u8>,
680 pub long: Vec<String>,
681 pub valued_long: Vec<String>,
682 pub numeric_shorthand: bool,
683 /// Flags whose presence widens the scale to unbounded (`rm -r`, `grep -r`).
684 pub unbounded_flags: Vec<String>,
685 /// Valued flags whose VALUE is a path to gate (`touch -r REF` reads REF), with its role.
686 pub path_flags: Vec<PathFlag>,
687 pub hook: Option<BehaviorHook>,
688 /// Transfer semantics, present iff `positionals == Transfer`.
689 pub transfer: Option<TransferSpec>,
690}
691
692/// A valued flag whose value is a path safe-chains gates by locus. One spelling per entry (a
693/// flag with both short and long forms is two entries); the resolver scans for each.
694#[derive(Debug, Clone)]
695pub(crate) struct PathFlag {
696 pub short: Option<u8>,
697 pub long: Option<String>,
698 pub role: PathRole,
699}
700
701/// The role a path-flag's value plays — read (gated by read locus) or write (by write locus).
702#[derive(Debug, Clone, Copy, PartialEq, Eq)]
703pub(crate) enum PathRole {
704 Read,
705 Write,
706}
707
708/// The closed set of operand-role shapes (§ design doc: the `Operands` enum, as data).
709#[derive(Debug, Clone, Copy, PartialEq, Eq)]
710pub(crate) enum PositionalRole {
711 None,
712 Read,
713 Write,
714 PatternThenRead,
715 Transfer,
716}
717
718/// How a command's `Scale` is computed from its operands.
719#[derive(Debug, Clone, Copy, PartialEq, Eq)]
720pub(crate) enum ScaleModel {
721 /// Every operation is a single item regardless of operand count (cat/head).
722 Single,
723 /// Count, glob, or a recursion flag widen it (`breadth_scale`) — rm/mkdir.
724 Breadth,
725}
726
727/// Runtime form of `[command.output]`: how to derive the locus of a command's stdout.
728#[derive(Debug, Clone)]
729pub(crate) struct OutputSpec {
730 pub locus_from: OutputLocus,
731 /// Flags that void the claim (see `TomlOutput::invalidated_by`).
732 pub invalidated_by: Vec<String>,
733 /// Value-taking flags (see `TomlOutput::valued`).
734 pub valued: Vec<String>,
735 /// Flags of which at least one must be present (see `TomlOutput::requires`).
736 pub requires: Vec<String>,
737}
738
739#[derive(Debug, Clone, Copy, PartialEq, Eq)]
740pub(crate) enum OutputLocus {
741 /// Beneath the command's own path operands — the worst `read_locus` over them, or the cwd
742 /// when it has none (`fd pattern` with no root searches `.`).
743 Operands,
744 /// The working directory itself (`pwd`).
745 Cwd,
746 /// A subset of what it was piped (`head -1`, `sort`, `uniq`) — so the locus is the PREVIOUS
747 /// pipeline stage's. Only when the command has no path operand: `head f.txt` prints the
748 /// contents of a file rather than filtering a stream, and contents are not paths.
749 Stdin,
750 /// The output words are ATOMS: they carry no path separator, so splicing one into a path
751 /// cannot move which directory the path names. `seq` prints integers; `basename` prints a
752 /// single component by definition.
753 ///
754 /// This is a different KIND of claim from the others, which all answer "which locus does this
755 /// output name". An atom names no locus at all — the point is that it cannot CHANGE one. That
756 /// is what makes `for i in $(seq 1 4); do … > "$SP/dx_$i.txt"; done` confinable: the prefix is
757 /// literal, and an atom spliced into the leaf cannot escape it.
758 ///
759 /// Separator-freedom alone is not sufficient — an atom that IS a whole component could be
760 /// `..`. Confinement additionally requires the interpolation to be flanked by literal text
761 /// within its component, which is a property of the PATH, not of this declaration. See
762 /// `docs/design/behavioral-taxonomy-*` and the plan recorded in TODO.md.
763 Atom,
764}
765
766/// A named thin resolver hook for irreducible token logic a declaration can't express — a
767/// command whose operand syntax is not getopt positional (grep's pattern disambiguation, dd's
768/// `key=value`, tar's dashless mode bundles, sed's mini-language script). The hook parses the
769/// tokens; the facets still come from the declaration + the builders.
770#[derive(Debug, Clone, Copy, PartialEq, Eq)]
771pub(crate) enum BehaviorHook {
772 Grep,
773 Dd,
774 Tar,
775 Sed,
776 Perl,
777}
778
779/// Runtime form of a `[[command.sub.flag]]` — the engine-relevant part of an escalating flag: its
780/// `name` (matched against the tokens) and the archetype it `classifies` as when present. Its
781/// research provenance (`fact`/`source`/`judgment`) lives on the TOML side and is validated at build
782/// time, not carried here.
783#[derive(Debug, Clone)]
784pub(super) struct FlagProvenance {
785 pub name: String,
786 pub classifies: String,
787 /// See `TomlSubFlag::value_prefix` — `None` = escalate on presence; `Some` = only when the
788 /// flag's value starts with this.
789 pub value_prefix: Option<String>,
790 /// See `TomlSubFlag::when_absent` — escalate when the flag is ABSENT (a safety flag whose
791 /// absence is the risk).
792 pub when_absent: bool,
793}
794
795/// How a sub's declared name is matched. An enum rather than a bool because the two are genuinely
796/// different matching MODES, and because a third boolean on `SubSpec` is the point at which the
797/// struct stops being readable — `name_match: WithDatabaseSuffix` says what `per_database: true`
798/// only implied.
799#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
800pub(super) enum NameMatch {
801 #[default]
802 Exact,
803 /// Also matches `name:<dbname>` for one plain identifier — see `TomlSub::per_database`.
804 WithDatabaseSuffix,
805}
806
807#[derive(Debug, Clone)]
808pub(super) struct SubSpec {
809 pub name: String,
810 pub kind: DispatchKind,
811 /// How this sub's name is matched against an argument.
812 pub name_match: NameMatch,
813 /// The facet archetype this sub is classified as (`archetypes.toml`), if declared via
814 /// `profile = …`. The engine resolves the sub to this archetype's static capability profile
815 /// (`registry::sub_archetype`), deriving the verdict rather than taking a hand-marked level.
816 /// (Its research provenance — `fact`/`source`/`judgment` — lives on the TOML side only and is
817 /// validated at build time; it is not carried on the runtime spec.)
818 pub profile: Option<String>,
819 /// Escalating flags: each, when present, adds `classifies`'s capability to the resolved profile.
820 pub flags: Vec<FlagProvenance>,
821 /// The sub's DECLARED flag allowlist, preserved for a PROFILED sub. Its legacy `kind` is forced
822 /// to deny-all at build time, but the engine classifies a profiled sub straight from its
823 /// archetype and never reaches that kind — so without keeping the lists here the declaration
824 /// would be discarded and ANY flag would ride along on the profile. That was a fail-OPEN:
825 /// `git rebase --exec 'rm -rf /'` and `supabase db dump --frobnicate` both classified as their
826 /// benign base profile. `sub_archetypes` validates presented flags against these.
827 pub allowed_standalone: Vec<String>,
828 pub allowed_valued: Vec<String>,
829 /// The sub's declared tolerance for flags it does not enumerate — the existing, explicit way to
830 /// say "this tool's flag surface is genuinely unbounded" (a cloud API's per-service options).
831 /// Preserved alongside the allowlist so the profiled path honors it: a sub that declares it stays
832 /// open BY DECLARATION (reviewable in the TOML) rather than by a silent engine default, and a sub
833 /// that does not — `git rebase`, where a flag changes the operation — enforces.
834 pub allowed_unknown: crate::policy::UnknownTolerance,
835 /// If this sub was declared with `policy = "key"`, the referenced
836 /// handler_policy name is preserved for docs rendering so a sub
837 /// that points at a policy also shown in **Shared flag sets** can
838 /// render as a reference rather than duplicating the flag list.
839 pub policy_ref: Option<String>,
840 /// True when this sub's leaf invocation is tagged as safe-to-eval.
841 /// Walked by `registry::is_eval_safe_invocation()`.
842 pub eval_safe: bool,
843 /// Flag allowlist extending `eval_safe` — flags permitted in the
844 /// substituted invocation when the walker stops at this sub.
845 pub eval_safe_flags: Vec<String>,
846 /// Per-valued-flag value allowlist (same semantics as on
847 /// `CommandSpec`).
848 pub eval_safe_flag_values: std::collections::HashMap<String, Vec<String>>,
849 /// Lowered `[command.sub.output]` — this sub's own stdout claim, consulted by
850 /// `registry::sub_output_locus` before the command-level one.
851 pub output: Option<OutputSpec>,
852 /// Flags where at least one must appear in the substituted
853 /// invocation (same semantics as on `CommandSpec`).
854 pub eval_safe_required_flags: Vec<String>,
855 /// `true` = classify this sub's first positional as a network destination onto
856 /// `locus.provenance` (see `TomlSub::network_destination`).
857 pub network_destination: bool,
858 /// A flag that overrides the positional destination (`git push --repo=…`); see
859 /// `TomlSub::destination_flag`.
860 pub destination_flag: Option<String>,
861 /// Output-file flags for a `data-export` sub; a present one adds a path-gated write capability
862 /// at the file's locus (see `TomlSub::output_path_flags`).
863 pub output_path_flags: Vec<String>,
864 pub writes_cwd: Option<crate::pathctx::anchor::Anchor>,
865 /// Endpoint flags gated on naming this machine; see `TomlSub::loopback_valued`.
866 pub loopback_valued: Vec<String>,
867 /// What a loopback endpoint buys this sub; see `TomlSub::loopback_localizes`.
868 pub loopback_effect: LoopbackEffect,
869}
870
871/// What a recognized loopback destination buys a sub. Gating the FLAG and re-classifying the
872/// OPERATION are separate powers: a read only needs the former (it already passes), while a write
873/// needs the latter to stop looking like a call to a cloud service.
874#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
875pub(super) enum LoopbackEffect {
876 /// The endpoint flag is admissible when local; the classification is untouched.
877 #[default]
878 AdmitOnly,
879 /// Also clears the facets the destination determines (remote reach, net direction, payload,
880 /// metered cost), leaving the ones describing the operation alone.
881 Localizes,
882}
883
884#[derive(Debug, Clone)]
885pub(super) enum DispatchKind {
886 Policy {
887 policy: OwnedPolicy,
888 level: SafetyLevel,
889 },
890 FirstArg {
891 patterns: Vec<String>,
892 level: SafetyLevel,
893 /// Flags the glob family accepts. Empty = not yet researched (grandfathered); see
894 /// `glob_presents_unlisted_flag`.
895 standalone: Vec<String>,
896 valued: Vec<String>,
897 /// Flags admitted only when their value is a loopback endpoint.
898 loopback_valued: Vec<String>,
899 },
900 RequireAny {
901 require_any: Vec<String>,
902 policy: OwnedPolicy,
903 level: SafetyLevel,
904 accept_bare_help: bool,
905 },
906 Branching {
907 subs: Vec<SubSpec>,
908 bare_flags: Vec<String>,
909 bare_ok: bool,
910 pre_standalone: Vec<String>,
911 pre_valued: Vec<String>,
912 first_arg: Vec<String>,
913 first_arg_level: SafetyLevel,
914 /// Flags the `first_arg` glob family accepts, as in `DispatchKind::FirstArg`.
915 first_arg_standalone: Vec<String>,
916 first_arg_valued: Vec<String>,
917 first_arg_loopback_valued: Vec<String>,
918 /// First-positional globs that classify the invocation as a credential-read (deny), checked
919 /// after explicit subs and before the allow-glob. Empty for almost every command.
920 credential_first_arg: Vec<String>,
921 /// Accept one leading rustup toolchain selector (`cargo +nightly build`), stripped before
922 /// sub dispatch. From `[command.wrapper] toolchain_selector = true`.
923 toolchain_selector: bool,
924 },
925 WriteFlagged {
926 policy: OwnedPolicy,
927 base_level: SafetyLevel,
928 write_flags: Vec<String>,
929 },
930 DelegateAfterSeparator {
931 separator: String,
932 },
933 DelegateSkip {
934 skip: usize,
935 shape: Option<crate::policy::PositionalShape>,
936 },
937 Wrapper {
938 standalone: Vec<String>,
939 valued: Vec<String>,
940 positional_skip: usize,
941 separator: Option<String>,
942 bare_ok: bool,
943 },
944 /// A `verb-chain` grammar (`mlr`): a strict main-flag region + a `then`-chain of
945 /// allowlisted verbs. See `dispatch::dispatch_verb_chain`.
946 VerbChain(VerbChainSpec),
947 /// A code-execution command whose verdict is the execution-origin gate (worktree code
948 /// allows, foreign denies), not a flat level. See `dispatch::dispatch_executor` and
949 /// docs/design/behavioral-taxonomy-execution-origin.md.
950 Executor {
951 policy: OwnedPolicy,
952 /// Verdict for a flag-only invocation with no executor (`python3 --version`).
953 level: SafetyLevel,
954 kind: ExecutorKind,
955 /// A valued flag whose value REDIRECTS the executor out of the project
956 /// (`cargo run --manifest-path DIR/Cargo.toml`) — its value is locus-gated like a
957 /// file executor. Only meaningful for `ExecutorKind::Project`.
958 redirect_flag: Option<String>,
959 /// A predicate the executor path must satisfy, else deny (`ExecutorKind::File`).
960 /// `go run` uses `go-package` so a remote import path (`rsc.io/x@latest`) is not
961 /// treated as a worktree executor.
962 shape: Option<crate::policy::PositionalShape>,
963 /// Whether the tokens AFTER the executor path are the SCRIPT's argv rather than this
964 /// command's own arguments. `python3 ./task.py --flag arg` passes them; `karma start
965 /// ./a.conf.js` does not, and a second path there is a second CONFIG it will load.
966 ///
967 /// Decides how much of the invocation the flag policy governs, so it defaults to FALSE —
968 /// the enforcing answer. See `dispatch::dispatch_executor`.
969 passes_argv: bool,
970 },
971 Custom {
972 #[allow(dead_code)]
973 handler_name: String,
974 doc_body: Option<String>,
975 /// TOML-declared subs the handler may consult via
976 /// `registry::try_sub_dispatch()`. Empty unless the handler
977 /// uses the helper.
978 subs: Vec<SubSpec>,
979 /// TOML-declared alternate grammar the handler may consult
980 /// via `registry::try_fallback_grammar()`. `None` unless the
981 /// handler uses the helper.
982 fallback: Option<FallbackSpec>,
983 /// Named flag policies the handler consults via
984 /// `registry::check_handler_policy()`. Empty unless the handler
985 /// has dispatch logic that picks a policy by name at runtime.
986 handler_policies: std::collections::HashMap<String, OwnedPolicy>,
987 /// Sub × action matrices the handler walks via
988 /// `registry::try_matrix_dispatch()`.
989 matrices: Vec<MatrixSpec>,
990 },
991}
992
993/// How a code-execution command locates its executor. `File`: the first positional is the
994/// executor path (`bash x.sh`, `python3 x.py`, `go run ./cmd`). `Project`: the current
995/// project is the executor and there is no path operand (`cargo run`, `dotnet run`).
996#[derive(Debug, Clone, Copy, PartialEq, Eq)]
997pub(super) enum ExecutorKind {
998 File,
999 Project,
1000}
1001
1002impl ExecutorKind {
1003 pub(super) fn from_name(name: &str) -> Option<Self> {
1004 match name {
1005 "file" => Some(Self::File),
1006 "project" => Some(Self::Project),
1007 _ => None,
1008 }
1009 }
1010}
1011
1012pub use super::policy::OwnedPolicy;
1013
1014#[derive(Debug, Clone)]
1015pub(super) struct MatrixSpec {
1016 pub parents: Vec<String>,
1017 pub level: SafetyLevel,
1018 pub actions: std::collections::HashMap<String, MatrixAction>,
1019}
1020
1021#[derive(Debug, Clone)]
1022pub(super) struct VerbChainSpec {
1023 pub level: SafetyLevel,
1024 pub separator: String,
1025 pub main_standalone: Vec<String>,
1026 pub main_valued: Vec<String>,
1027 pub main_variadic: Vec<String>,
1028 pub verbs: std::collections::HashSet<String>,
1029}
1030
1031#[derive(Debug, Clone)]
1032pub(super) struct FallbackSpec {
1033 pub policy: OwnedPolicy,
1034 pub level: SafetyLevel,
1035 pub positional_shape: Option<crate::policy::PositionalShape>,
1036 /// When set, the first positional is an EXECUTOR (a script/package the command runs),
1037 /// gated by the execution-origin engine instead of the flat `level`. `ExecutorKind::File`
1038 /// is the only form used by fallbacks (interpreters). See `dispatch::dispatch_executor`.
1039 pub executor: Option<ExecutorKind>,
1040 /// See `DispatchKind::Executor::redirect_flag` (unused for `File` fallbacks).
1041 pub executor_redirect_flag: Option<String>,
1042 /// See `DispatchKind::Executor::passes_argv`, set by interpreters, whose trailing tokens are argv.
1043 pub passes_argv: bool,
1044 pub write_flags: Vec<String>,
1045}