passport-bridge 0.52.0 → 0.55.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/cliHookClassify.js +34 -10
  2. package/dist/cliHookDecide.js +3 -1
  3. package/dist/cliHookParse.d.ts +4 -0
  4. package/dist/cliHookParse.js +13 -2
  5. package/dist/connectorKit/cli.generated.d.ts +8 -2
  6. package/dist/connectorKit/cli.generated.js +131 -46
  7. package/dist/connectorKit/cliTree.generated.d.ts +92 -0
  8. package/dist/connectorKit/cliTree.generated.js +134 -0
  9. package/dist/connectorKit/engine.generated.js +27 -6
  10. package/dist/connectorKit/launchers.generated.d.ts +53 -0
  11. package/dist/connectorKit/launchers.generated.js +109 -0
  12. package/dist/connectorKit/manifest.generated.d.ts +5 -0
  13. package/dist/connectorKit/manifests/railwayCapture.generated.d.ts +5 -0
  14. package/dist/connectorKit/manifests/railwayCapture.generated.js +50 -5
  15. package/dist/connectorKit/manifests/railwayCommands.generated.d.ts +17 -0
  16. package/dist/connectorKit/manifests/railwayCommands.generated.js +268 -0
  17. package/dist/connectorKit/manifests/supabase.generated.js +6 -1
  18. package/dist/connectorKit/manifests/supabaseCli.generated.d.ts +3 -1
  19. package/dist/connectorKit/manifests/supabaseCli.generated.js +91 -2
  20. package/dist/connectorKit/pgParser.d.ts +8 -6
  21. package/dist/connectorKit/pgParser.js +16 -9
  22. package/dist/connectorKit/shell.generated.js +4 -2
  23. package/dist/connectorKit/sources/railway/cli-tree.generated.d.ts +139 -0
  24. package/dist/connectorKit/sources/railway/cli-tree.generated.js +2 -0
  25. package/dist/connectorKit/sources/supabase/cli-flags.generated.d.ts +479 -192
  26. package/dist/connectorKit/sources/supabase/cli-flags.generated.js +1 -1
  27. package/dist/connectorKit/surfaces.generated.d.ts +81 -0
  28. package/dist/connectorKit/surfaces.generated.js +122 -0
  29. package/dist/connectorKit/types.generated.d.ts +2 -0
  30. package/dist/controlPlaneGuard.js +4 -3
  31. package/dist/controlPlaneKubernetes.js +4 -3
  32. package/dist/controlPlaneNpmGuard.js +6 -2
  33. package/dist/controlPlaneRailwayGuard.d.ts +4 -2
  34. package/dist/controlPlaneRailwayGuard.js +20 -73
  35. package/dist/controlPlaneRailwayReach.d.ts +1 -1
  36. package/dist/controlPlaneRailwayReach.js +2 -0
  37. package/dist/controlPlaneSupabase.d.ts +9 -3
  38. package/dist/controlPlaneSupabase.js +18 -3
  39. package/dist/controlPlaneUnnamed.generated.d.ts +10 -1
  40. package/dist/controlPlaneUnnamed.generated.js +6 -0
  41. package/dist/pluginPin.d.ts +1 -1
  42. package/dist/pluginPin.js +1 -1
  43. package/dist/psqlSupabase.d.ts +14 -6
  44. package/dist/psqlSupabase.js +24 -7
  45. package/dist/version.d.ts +1 -1
  46. package/dist/version.js +1 -1
  47. package/npm-shrinkwrap.json +19 -3
  48. package/package.json +3 -2
@@ -0,0 +1,134 @@
1
+ // Generated by scripts/generate-control-plane-classifier.mjs. Do not edit.
2
+ /**
3
+ * A vendor CLI's whole command tree, pinned to one version (docs/design/zero-unknowns.md). `scripts/cli-trees/`
4
+ * crawls the installed binary's help into `sources/<platform>/cli-tree.json`; this module turns it into the
5
+ * manifest's tables (flags, aliases, usage lines) and measures how much of it a manifest names. Pure.
6
+ *
7
+ * Every leaf command of the pinned tree is named: a hand-written rule, a reviewed read, or an entry of the
8
+ * platform's command overlay (`CommandEffect`), which becomes a rule for the platform's "Other change" with the
9
+ * effects the reviewer gave it. A command the tree doesn't have is new (a newer CLI than the pin): "New command".
10
+ */
11
+ /** The words a command is known by in the manifest: the vendor's path with the manifest's own renames applied. */
12
+ export function renamePath(path, rename = {}) {
13
+ return path
14
+ .split(" ")
15
+ .map((word) => rename[word] ?? word)
16
+ .join(" ");
17
+ }
18
+ /** Leaf commands (anything a person can run that isn't only a group), renamed. Hidden ones count: they run. */
19
+ export function treeLeaves(tree, rename) {
20
+ return tree.commands.filter((c) => !c.group).map((c) => renamePath(c.path, rename));
21
+ }
22
+ /** Groups: run alone they print help, a read. */
23
+ export function treeGroups(tree, rename) {
24
+ return tree.commands.filter((c) => c.group).map((c) => renamePath(c.path, rename));
25
+ }
26
+ /** The manifest's flag table, aliases and usage lines, from the tree. */
27
+ export function treeTables(tree, rename = {}) {
28
+ const commands = {};
29
+ const aliases = {};
30
+ const usage = {};
31
+ for (const command of tree.commands) {
32
+ const path = renamePath(command.path, rename);
33
+ if (command.flags.length)
34
+ commands[path] = [...command.flags];
35
+ // clap's "[OPTIONS]" is the flags, not an argument.
36
+ if (command.usage)
37
+ usage[path] = command.usage.replace(/\[OPTIONS\]/g, "[flags]");
38
+ const words = path.split(" ");
39
+ const parent = words.slice(0, -1);
40
+ // The vendor's own name when the manifest renamed it, and each alias, at this level of the path.
41
+ const spellings = new Set([command.path.split(" ").pop(), ...(command.aliases ?? [])]);
42
+ for (const spelling of spellings)
43
+ if (spelling !== words[words.length - 1])
44
+ aliases[[...parent, spelling].join(" ")] = path;
45
+ }
46
+ return { flags: { global: [...tree.globalFlags], commands }, aliases, usage };
47
+ }
48
+ /** Aliases merged (later wins) and followed to the end, so a spelling of a spelling lands on the command. */
49
+ export function mergeAliases(...maps) {
50
+ const merged = Object.assign({}, ...maps);
51
+ for (const key of Object.keys(merged)) {
52
+ let value = merged[key];
53
+ for (let hops = 0; hops < 8 && Object.prototype.hasOwnProperty.call(merged, value) && merged[value] !== value; hops++)
54
+ value = merged[value];
55
+ merged[key] = value;
56
+ }
57
+ return merged;
58
+ }
59
+ /** Flags from the tree, with a manifest's own reviewed additions (hand-declared flags win where both name one). */
60
+ export function mergeFlags(base, extra) {
61
+ const out = {};
62
+ for (const [command, specs] of Object.entries(base))
63
+ out[command] = [...specs];
64
+ for (const [command, specs] of Object.entries(extra)) {
65
+ const kept = (out[command] ?? []).filter((spec) => !specs.some((s) => s.long === spec.long));
66
+ out[command] = [...kept, ...specs];
67
+ }
68
+ return out;
69
+ }
70
+ /** The capture rules and reads an overlay adds for commands no hand rule names. */
71
+ export function overlayCapture(overlay, other, hooks, ruled = new Set()) {
72
+ const rules = [];
73
+ const reads = {};
74
+ for (const [command, effect] of Object.entries(overlay)) {
75
+ if (ruled.has(command))
76
+ continue;
77
+ if ("read" in effect)
78
+ reads[command] = effect.read;
79
+ else if ("local" in effect)
80
+ reads[command] = `Local only: ${effect.local}`;
81
+ else if ("other" in effect) {
82
+ const place = hooks[effect.on];
83
+ rules.push({
84
+ match: command,
85
+ action: other,
86
+ hook: place.hook,
87
+ summary: effect.other.replace("{where}", place.where)
88
+ });
89
+ }
90
+ }
91
+ return { rules, reads };
92
+ }
93
+ /** The (action, summary template, effects) rows an overlay gives the platform's call-effects table. */
94
+ export function overlayCallEffects(overlay, other, hooks) {
95
+ return Object.values(overlay).flatMap((effect) => "other" in effect
96
+ ? [
97
+ [other, effect.other.replace("{where}", hooks[effect.on].where), effect.effects]
98
+ ]
99
+ : []);
100
+ }
101
+ /** How much of a pinned tree a manifest names (the ratchet in `cliTree.test.ts`). */
102
+ export function commandCoverage(m, tree, rename, overlay = {}) {
103
+ const cli = m.capture.cli;
104
+ const ruled = new Set(cli.rules.map((rule) => rule.match));
105
+ const read = new Set(Object.keys(cli.reads));
106
+ // A leaf the manifest spells another way (an alias) is named by what that spelling names.
107
+ const as = (leaf) => Object.prototype.hasOwnProperty.call(cli.aliases ?? {}, leaf) ? cli.aliases[leaf] : leaf;
108
+ const leaves = treeLeaves(tree, rename);
109
+ const missing = leaves.filter((leaf) => !ruled.has(as(leaf)) && !read.has(as(leaf)) && !overlay[leaf]);
110
+ const ruleless = Object.entries(overlay)
111
+ .filter(([command, effect]) => "rule" in effect && !ruled.has(command))
112
+ .map(([command]) => command);
113
+ const known = (command, flag) => [...cli.flags.global, ...(cli.legacyFlags ?? []), ...(cli.flags.commands[command] ?? [])].some((s) => s.long === flag);
114
+ let flagPairs = 0;
115
+ let flagPairsKnown = 0;
116
+ for (const command of tree.commands) {
117
+ const path = renamePath(command.path, rename);
118
+ for (const flag of command.flags) {
119
+ flagPairs++;
120
+ if (known(path, flag.long))
121
+ flagPairsKnown++;
122
+ }
123
+ }
124
+ return {
125
+ cli: tree.cli,
126
+ version: tree.version,
127
+ total: leaves.length,
128
+ named: leaves.length - missing.length,
129
+ missing,
130
+ ruleless,
131
+ flagPairs,
132
+ flagPairsKnown
133
+ };
134
+ }
@@ -373,7 +373,7 @@ function unnamedOf(m, n, ops) {
373
373
  return unnamedCli([program, ...words]);
374
374
  }
375
375
  /** What a request that fails closed becomes: the Unclassified Action, on the most specific node it names. */
376
- function unclassified(m, n, params, context, hooks, problem = n.problem) {
376
+ function unclassified(m, n, params, context, hooks, problem = n.problem, why = "unread") {
377
377
  const action = m.actions.find((a) => a.key === m.capture.unclassified);
378
378
  // Words only: an id or value in a path or command never reaches the summary.
379
379
  const word = (part) => (/^(\{\w+\}|[a-z][a-z_-]{0,40})$/.test(part) ? part : "…");
@@ -388,7 +388,8 @@ function unclassified(m, n, params, context, hooks, problem = n.problem) {
388
388
  .join(" ")
389
389
  : (safeName(n.op) ?? "…");
390
390
  const at = nodeChain(m, action.appliesTo, params, context, hooks);
391
- const unnamed = unnamedOf(m, n, ops);
391
+ const hit = unnamedOf(m, n, ops);
392
+ const unnamed = hit ? { ...hit, why } : undefined;
392
393
  return {
393
394
  nodeId: at.unresolved
394
395
  ? nodeId(m.platform, m.types.find((t) => t.type === action.appliesTo)?.service ?? m.services[0].key)
@@ -430,16 +431,26 @@ export function explain(m, request, context = {}, hooks = {}) {
430
431
  return decideRequest(m, n, context, hooks, {});
431
432
  }
432
433
  function decideRequest(m, n, context, hooks, override) {
434
+ const spec = m.capture[n.iface];
435
+ const candidates = spec.rules.filter((rule) => rule.match === n.op);
436
+ // New: a readable operation the manifest has no rule or read for. Anything else (a known operation, or a line it
437
+ // couldn't read: a launcher, a hidden value, a bad flag) is Couldn't read.
438
+ const why = n.op &&
439
+ (!n.problem || n.problem.startsWith("unknown flag")) &&
440
+ !candidates.length &&
441
+ !Object.hasOwn(spec.reads, n.op)
442
+ ? "new"
443
+ : "unread";
433
444
  const failed = (rule, problem) => ({
434
- found: [unclassified(m, n, canonical(m, n, rule, context, override).params, context, hooks, problem ?? n.problem)],
445
+ found: [
446
+ unclassified(m, n, canonical(m, n, rule, context, override).params, context, hooks, problem ?? n.problem, why)
447
+ ],
435
448
  via: "failed"
436
449
  });
437
- const spec = m.capture[n.iface];
438
- const candidates = spec.rules.filter((rule) => rule.match === n.op);
439
450
  // "none": an op it doesn't know names nothing, and nor does a listed read whatever its flags.
440
451
  if (spec.unknown === "none" && n.op && candidates.length === 0)
441
452
  return Object.hasOwn(spec.reads, n.op) ? { found: [], via: "read" } : { found: [], via: "none" };
442
- if (n.problem)
453
+ if (n.problem && !(n.iface === "cli" && unreadValueOnLeafRead(m, n, candidates.length)))
443
454
  return failed();
444
455
  if (candidates.length === 0)
445
456
  return Object.hasOwn(spec.reads, n.op) ? { found: [], via: "read" } : failed();
@@ -472,6 +483,16 @@ function eachItem(m, n, context, hooks, override, name, list) {
472
483
  const via = vias.has("failed") ? "failed" : vias.has("rule") ? "rule" : "read";
473
484
  return { found: dedupe(items.flatMap((one) => one.found)), via };
474
485
  }
486
+ /**
487
+ * A value the guard can't read (`$SVC`) on a reviewed read that is a leaf command (no longer command starts with
488
+ * it, no rule names it) can't change what it does: it stays a read (docs/design/zero-unknowns.md, "Couldn't read").
489
+ * On a command with rules, or one a hidden word could turn into a subcommand (`railway service $X`), it fails.
490
+ */
491
+ function unreadValueOnLeafRead(m, n, rules) {
492
+ if (n.problem !== "a value the guard cannot read" || rules > 0 || !Object.hasOwn(m.capture.cli.reads, n.op))
493
+ return false;
494
+ return !knownOps(m).some((op) => op.startsWith(`${n.op} `));
495
+ }
475
496
  /** The body's top-level fields the operation declares (all of them when its schema isn't known). */
476
497
  function declaredBody(n) {
477
498
  if (!n.inputs || !n.body || typeof n.body !== "object" || Array.isArray(n.body))
@@ -28,6 +28,59 @@ export type Unwrapped = {
28
28
  export declare function launcherEnd(words: readonly string[], at: number): number | null;
29
29
  /** See through leading assignments and launchers to the command they run. */
30
30
  export declare function unwrapLaunchers(words: readonly string[]): Unwrapped;
31
+ /**
32
+ * Package runners: programs that run a package's program (`npx supabase db push`, `pnpm exec wrangler deploy`, `bunx
33
+ * @sentry/cli releases new 1.0`) from the project's node_modules/.bin, then PATH, or fetched from the registry. In many
34
+ * repos this is the normal way to run a platform's CLI. One table for every reader (`cli.ts` for the kit's
35
+ * manifests, and the bridge's Railway, Kubernetes, GitHub and npm readers), so a runner is seen through the same way on
36
+ * every platform.
37
+ */
38
+ export type PackageRunnerSpec = {
39
+ /** Its subcommands that run a package (`pnpm exec`, `npm x`); none when it runs one itself (`npx`). */
40
+ subcommands?: readonly string[];
41
+ /** Whether its first word may name the program it runs (`pnpm supabase …`, `yarn wrangler …`). That word may also
42
+ * be its own command or a script, so a reader counts a bare run only for its own program followed by a command it
43
+ * knows. */
44
+ bare?: boolean;
45
+ /** Options that take a value as the next word (`-p pkg`, `-C dir`). */
46
+ valued: readonly string[];
47
+ };
48
+ export declare const PACKAGE_RUNNERS: Readonly<Record<string, PackageRunnerSpec>>;
49
+ /** Packages whose program has another name: `npx @railway/cli up` runs `railway`. */
50
+ export declare const PACKAGE_PROGRAMS: Readonly<Record<string, string>>;
51
+ /** The program a package spec runs: `supabase@2.1.0` → `supabase`, `@railway/cli@4` → `railway`. A scoped package
52
+ * this table doesn't name stays as written (without its version), so it never matches a program by accident. */
53
+ export declare function packageProgram(spec: string): string;
54
+ export type PackageRun = {
55
+ /** The runner and its subcommand as Railway's guard keys them (`npx `, `pnpm exec`, `pnpm ` for a bare run). */
56
+ runner: string;
57
+ /** Where the word naming the program or package is. */
58
+ at: number;
59
+ /** The program that runs (`packageProgram` of that word). */
60
+ program: string;
61
+ /** The program's own arguments: npm takes the first `--` for itself (`npm x supabase -- db push`). */
62
+ args: string[];
63
+ /** Whether the program was named as the runner's first word (`pnpm supabase …`). */
64
+ bare: boolean;
65
+ /** Packages named by `-p`/`--package`. */
66
+ packages: string[];
67
+ /** The folder it runs in when an option moves it: a path (relative to the line's folder), or null when the
68
+ * guard can't name it (`--filter`, `-r`). Absent when no option moves it. */
69
+ dir?: string | null;
70
+ /** The option that named `dir`. */
71
+ option?: string;
72
+ };
73
+ /** A package runner at `words[at]` and the program it runs, or null when it is none (or runs a script, or nothing:
74
+ * `npx -c '…'`, `pnpm install`, `npm exec` alone). */
75
+ export declare function packageRun(words: readonly string[], at?: number): PackageRun | null;
76
+ /** The words of the program a package runner runs, its program first (`npx -y supabase@2 db push` → `supabase db
77
+ * push`), or null when `words` aren't a package run. A bare run (`pnpm supabase db push`) counts only when
78
+ * `bareRun(program, its arguments)` says the program and what follows are a CLI's command, the way #1193 counts a
79
+ * CLI's name behind a program it doesn't know. */
80
+ export declare function packageArgv(words: readonly string[], bareRun?: (program: string, args: readonly string[]) => boolean): {
81
+ argv: string[];
82
+ run: PackageRun;
83
+ } | null;
31
84
  /** Whether `head` (a program name) given `args` only reads or edits files and runs no other program. */
32
85
  export declare function neverLaunches(head: string, args: readonly string[]): boolean;
33
86
  /** Where the command `xargs` runs starts in its `args`, or null when an option can't be read. */
@@ -79,6 +79,115 @@ export function unwrapLaunchers(words) {
79
79
  }
80
80
  return { start: Math.min(at, words.length), via, assignments };
81
81
  }
82
+ const NPM_VALUED = ["-p", "--package", "-w", "--workspace", "-C", "--prefix", "--registry", "--cache", "--userconfig"];
83
+ export const PACKAGE_RUNNERS = {
84
+ npx: { valued: [...NPM_VALUED, "-c", "--call"] },
85
+ npm: { subcommands: ["exec", "x"], valued: [...NPM_VALUED, "-c", "--call", "--loglevel"] },
86
+ pnpx: { valued: ["-p", "--package"] },
87
+ pnpm: {
88
+ subcommands: ["exec", "dlx"],
89
+ bare: true,
90
+ valued: ["-C", "--dir", "-F", "--filter", "--reporter", "--loglevel", "--package"]
91
+ },
92
+ yarn: { subcommands: ["exec", "dlx"], bare: true, valued: ["--cwd", "-p", "--package"] },
93
+ bunx: { valued: ["-p", "--package"] },
94
+ bun: { subcommands: ["x"], valued: ["-p", "--package", "--cwd"] }
95
+ };
96
+ /** Packages whose program has another name: `npx @railway/cli up` runs `railway`. */
97
+ export const PACKAGE_PROGRAMS = {
98
+ "@railway/cli": "railway",
99
+ "@sentry/cli": "sentry-cli",
100
+ "@cloudflare/wrangler": "wrangler"
101
+ };
102
+ /** Runner options that name the package to install (the program is the next word that isn't one). */
103
+ const PACKAGE_OPTIONS = new Set(["-p", "--package"]);
104
+ /** Runner options that name the folder the program runs in (pnpm's `-C`; npm's `-C` is `--prefix`). */
105
+ const DIR_OPTIONS = new Set(["--dir", "--cwd"]);
106
+ /** Runner options that run it in folders the guard can't name: each workspace package, a filter's matches, and npm's
107
+ * `--prefix` (`-C`), which moves where packages are found, not reliably the folder the command runs in. */
108
+ const SPREAD_OPTIONS = new Set(["-F", "--filter", "-w", "--workspace", "-r", "--recursive", "--prefix"]);
109
+ /** Options that run a script instead of a package (`npx -c '…'`): read as a line of its own by each reader. */
110
+ const SCRIPT_OPTIONS = new Set(["-c", "--call"]);
111
+ /** The program a package spec runs: `supabase@2.1.0` → `supabase`, `@railway/cli@4` → `railway`. A scoped package
112
+ * this table doesn't name stays as written (without its version), so it never matches a program by accident. */
113
+ export function packageProgram(spec) {
114
+ const bare = /^(@[^/@\s]+\/[^@\s]+|[^@\s]+)@[^/\s]*$/.exec(spec)?.[1] ?? spec;
115
+ return Object.hasOwn(PACKAGE_PROGRAMS, bare) ? PACKAGE_PROGRAMS[bare] : bare;
116
+ }
117
+ /** A package runner at `words[at]` and the program it runs, or null when it is none (or runs a script, or nothing:
118
+ * `npx -c '…'`, `pnpm install`, `npm exec` alone). */
119
+ export function packageRun(words, at = 0) {
120
+ const name = (words[at]?.split(/[\\/]/).pop() ?? "").replace(/\.(exe|cmd|ps1)$/i, "").toLowerCase();
121
+ if (!Object.hasOwn(PACKAGE_RUNNERS, name))
122
+ return null;
123
+ const spec = PACKAGE_RUNNERS[name];
124
+ let sub = spec.subcommands ? null : "";
125
+ const packages = [];
126
+ let dir;
127
+ let dashes = false;
128
+ for (let next = at + 1; next < words.length; next++) {
129
+ const word = words[next];
130
+ if (word === "--") {
131
+ dashes = true;
132
+ continue;
133
+ }
134
+ if (word.startsWith("-") && word.length > 1) {
135
+ const eq = word.startsWith("--") ? word.indexOf("=") : -1;
136
+ const option = eq < 0 ? word : word.slice(0, eq);
137
+ if (SCRIPT_OPTIONS.has(option) && spec.valued.includes(option))
138
+ return null;
139
+ const valued = eq < 0 && spec.valued.includes(option);
140
+ const value = eq >= 0 ? word.slice(eq + 1) : valued ? words[next + 1] : undefined;
141
+ if (valued)
142
+ next += 1;
143
+ if (PACKAGE_OPTIONS.has(option) && value !== undefined)
144
+ packages.push(value);
145
+ const named = DIR_OPTIONS.has(option) || (option === "-C" && name === "pnpm");
146
+ if (named && value !== undefined)
147
+ dir = { value, option };
148
+ else if (option === "-C")
149
+ dir = { value: null, option };
150
+ else if (SPREAD_OPTIONS.has(option))
151
+ dir = { value: null, option };
152
+ continue;
153
+ }
154
+ let bare = false;
155
+ if (sub === null) {
156
+ if (spec.subcommands.includes(word)) {
157
+ sub = word;
158
+ continue;
159
+ }
160
+ if (!spec.bare)
161
+ return null;
162
+ sub = "";
163
+ bare = true;
164
+ }
165
+ const args = words.slice(next + 1);
166
+ const own = (name === "npm" || name === "npx") && !dashes ? args.indexOf("--") : -1;
167
+ return {
168
+ runner: `${name} ${sub}`,
169
+ at: next,
170
+ program: packageProgram(word),
171
+ args: own < 0 ? args : [...args.slice(0, own), ...args.slice(own + 1)],
172
+ bare,
173
+ packages,
174
+ ...(dir ? { dir: dir.value, option: dir.option } : {})
175
+ };
176
+ }
177
+ return null;
178
+ }
179
+ /** The words of the program a package runner runs, its program first (`npx -y supabase@2 db push` → `supabase db
180
+ * push`), or null when `words` aren't a package run. A bare run (`pnpm supabase db push`) counts only when
181
+ * `bareRun(program, its arguments)` says the program and what follows are a CLI's command, the way #1193 counts a
182
+ * CLI's name behind a program it doesn't know. */
183
+ export function packageArgv(words, bareRun = () => false) {
184
+ const run = packageRun(words);
185
+ if (!run)
186
+ return null;
187
+ if (run.bare && !bareRun(run.program, run.args))
188
+ return null;
189
+ return { argv: [run.program, ...run.args], run };
190
+ }
82
191
  /**
83
192
  * Programs that never run another program: a CLI's name among their words is an argument (`ls supabase`, `grep -rn
84
193
  * railway .`, `git grep terraform`, `rm -rf supabase`), not that CLI being run. Each reader of a shell line uses it
@@ -172,6 +172,11 @@ export type CliSpec = {
172
172
  localCommands?: readonly string[];
173
173
  /** Other program names for the same CLI (vc for vercel). */
174
174
  aliasPrograms?: readonly string[];
175
+ /** A flag the pinned vendor tree doesn't list, on a known command (docs/design/zero-unknowns.md, "Flags"). "fail"
176
+ * (the default): the command fails closed. "keep": the command keeps its class and the flag's name is recorded
177
+ * (`Normalized.unknownFlags`), unless its name sounds effect-changing (`EFFECT_FLAG_WORDS`) or it may hide an
178
+ * argument the command reads. */
179
+ unknownFlags?: "fail" | "keep";
175
180
  /** Every flag the CLI accepts, from the vendor's spec: global, and per command. An unknown flag fails closed. */
176
181
  flags: {
177
182
  global: readonly FlagSpec[];
@@ -1,3 +1,8 @@
1
1
  import type { CaptureSpec } from "../manifest.generated.js";
2
+ import { type CliTree } from "../cliTree.generated.js";
3
+ /** The manifest's words for the vendor's (`railway variable` is `variables` here, as Railway's MCP and 4.x say). */
4
+ export declare const RAILWAY_RENAME: Readonly<Record<string, string>>;
5
+ /** Railway 5.70.0's whole command tree (docs/design/zero-unknowns.md): flags, aliases and usage lines. */
6
+ export declare const RAILWAY_TREE: CliTree;
2
7
  export declare const GRAPHQL_ROUTE = "/graphql/v2";
3
8
  export declare const RAILWAY_CAPTURE: CaptureSpec;
@@ -1,4 +1,7 @@
1
+ import TREE from "../sources/railway/cli-tree.generated.js";
2
+ import { mergeAliases, mergeFlags, overlayCapture, treeGroups, treeTables } from "../cliTree.generated.js";
1
3
  import { flagSpecs } from "./flagSpec.generated.js";
4
+ import { RAILWAY_COMMANDS, RAILWAY_OVERLAY_PLACES } from "./railwayCommands.generated.js";
2
5
  /**
3
6
  * Railway capture for the shadow run (2026-11-14): `railway` command lines, Railway's MCP tools and GraphQL
4
7
  * calls, as today's classifier reads them. Each rule names its Action and summary; its hook places it from
@@ -22,6 +25,11 @@ const COMMANDS = {
22
25
  "volume update": flagSpecs("-n/name= mount-path="),
23
26
  "volume add": flagSpecs("mount-path=")
24
27
  };
28
+ /** The manifest's words for the vendor's (`railway variable` is `variables` here, as Railway's MCP and 4.x say). */
29
+ export const RAILWAY_RENAME = { variable: "variables", telemetry_cmd: "telemetry" };
30
+ /** Railway 5.70.0's whole command tree (docs/design/zero-unknowns.md): flags, aliases and usage lines. */
31
+ export const RAILWAY_TREE = TREE;
32
+ const tables = treeTables(RAILWAY_TREE, RAILWAY_RENAME);
25
33
  const svc = (match, action, summary, extra = {}) => ({
26
34
  match,
27
35
  action,
@@ -95,6 +103,12 @@ const CLI_RULES = [
95
103
  }),
96
104
  svc("scale", "railway.service.scale", "Change scale of {where}"),
97
105
  svc("service delete", "railway.service.delete", "Delete service {where}", { args: ["positional"] }),
106
+ svc("domain delete", "railway.service.domain.delete", "Remove domain {domain} from {where}", {
107
+ args: ["domain"],
108
+ target: { type: "domain", key: "{domain}" }
109
+ }),
110
+ svc("tcp-proxy delete", "railway.service.tcp.delete", "Remove a TCP proxy from {where}"),
111
+ svc("variables edit", "railway.service.variables", "Change variables on {where}"),
98
112
  ...["volume", "bucket"].flatMap((kind) => [
99
113
  {
100
114
  match: `${kind} delete`,
@@ -128,6 +142,22 @@ const CLI_RULES = [
128
142
  { match: "api", args: ["query"], action: "railway.unclassified", hook: "graphql" }
129
143
  ];
130
144
  const LOOKS = "Shows, lists or links; changes nothing on Railway";
145
+ /** Every pinned command no hand rule names: the overlay's reads, local commands and "Other change" rules. */
146
+ const OVERLAY = overlayCapture(RAILWAY_COMMANDS, OTHER, RAILWAY_OVERLAY_PLACES, new Set(CLI_RULES.map((rule) => rule.match)));
147
+ /** Commands a hand rule reads positional arguments of. */
148
+ const HAND_ARGS = new Set(CLI_RULES.filter((rule) => rule.args?.length).map((rule) => rule.match));
149
+ /** The same command spelled through its group (`railway service redeploy` is `railway redeploy`). */
150
+ const SPELLINGS = {
151
+ "service redeploy": "redeploy",
152
+ "service restart": "restart",
153
+ "service scale": "scale",
154
+ "service logs": "logs",
155
+ "deployment redeploy": "redeploy",
156
+ "deployment up": "up",
157
+ "project delete": "delete",
158
+ "project link": "link",
159
+ "project list": "list"
160
+ };
131
161
  const CLI_READS = Object.fromEntries([
132
162
  "logs",
133
163
  "status",
@@ -339,7 +369,8 @@ export const RAILWAY_CAPTURE = {
339
369
  programs: ["railway"],
340
370
  framework: "arg",
341
371
  infoFlags: ["help", "version"],
342
- aliases: {
372
+ unknownFlags: "keep",
373
+ aliases: mergeAliases(tables.aliases ?? {}, {
343
374
  env: "environment",
344
375
  variable: "variables",
345
376
  vars: "variables",
@@ -354,13 +385,27 @@ export const RAILWAY_CAPTURE = {
354
385
  "volume remove": "volume delete",
355
386
  "bucket rm": "bucket delete",
356
387
  "bucket remove": "bucket delete",
357
- "tcp-proxy add": "tcp-proxy create"
388
+ "tcp-proxy add": "tcp-proxy create",
389
+ ...SPELLINGS
390
+ }),
391
+ // Usage lines only where no hand rule reads arguments: those keep their reviewed `args` (4.x spellings).
392
+ usage: Object.fromEntries(Object.entries(tables.usage ?? {}).filter(([command]) => !HAND_ARGS.has(command))),
393
+ // The reviewed options every command takes win over the tree's per-command copy of them.
394
+ flags: {
395
+ global: GLOBAL,
396
+ commands: mergeFlags(Object.fromEntries(Object.entries(tables.flags.commands).map(([command, specs]) => [
397
+ command,
398
+ specs.filter((spec) => !GLOBAL.some((g) => g.long === spec.long))
399
+ ])), COMMANDS)
358
400
  },
359
- flags: { global: GLOBAL, commands: COMMANDS },
360
401
  remoteFlags: [],
361
402
  localFlags: [],
362
- rules: CLI_RULES,
363
- reads: CLI_READS
403
+ rules: [...CLI_RULES, ...OVERLAY.rules],
404
+ reads: {
405
+ ...Object.fromEntries(treeGroups(RAILWAY_TREE, RAILWAY_RENAME).map((group) => [group, "Prints its subcommands"])),
406
+ ...OVERLAY.reads,
407
+ ...CLI_READS
408
+ }
364
409
  },
365
410
  mcp: {
366
411
  prefixes: [],
@@ -0,0 +1,17 @@
1
+ import type { CommandEffect } from "../cliTree.generated.js";
2
+ /** Where an overlay command lands: the hook that places it, and the words its summary uses for that place. */
3
+ export declare const RAILWAY_OVERLAY_PLACES: {
4
+ readonly project: {
5
+ readonly hook: "project";
6
+ readonly where: "{project}";
7
+ };
8
+ readonly environment: {
9
+ readonly hook: "project";
10
+ readonly where: "{project}";
11
+ };
12
+ readonly service: {
13
+ readonly hook: "service";
14
+ readonly where: "{where}";
15
+ };
16
+ };
17
+ export declare const RAILWAY_COMMANDS: Readonly<Record<string, CommandEffect>>;