passport-bridge 0.53.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 (36) hide show
  1. package/dist/cliHookDecide.js +3 -1
  2. package/dist/cliHookParse.js +5 -1
  3. package/dist/connectorKit/cli.generated.d.ts +2 -0
  4. package/dist/connectorKit/cli.generated.js +80 -6
  5. package/dist/connectorKit/cliTree.generated.d.ts +92 -0
  6. package/dist/connectorKit/cliTree.generated.js +134 -0
  7. package/dist/connectorKit/engine.generated.js +27 -6
  8. package/dist/connectorKit/manifest.generated.d.ts +5 -0
  9. package/dist/connectorKit/manifests/railwayCapture.generated.d.ts +5 -0
  10. package/dist/connectorKit/manifests/railwayCapture.generated.js +50 -5
  11. package/dist/connectorKit/manifests/railwayCommands.generated.d.ts +17 -0
  12. package/dist/connectorKit/manifests/railwayCommands.generated.js +268 -0
  13. package/dist/connectorKit/manifests/supabase.generated.js +6 -1
  14. package/dist/connectorKit/manifests/supabaseCli.generated.d.ts +3 -1
  15. package/dist/connectorKit/manifests/supabaseCli.generated.js +91 -2
  16. package/dist/connectorKit/pgParser.d.ts +8 -6
  17. package/dist/connectorKit/pgParser.js +16 -9
  18. package/dist/connectorKit/sources/railway/cli-tree.generated.d.ts +139 -0
  19. package/dist/connectorKit/sources/railway/cli-tree.generated.js +2 -0
  20. package/dist/connectorKit/sources/supabase/cli-flags.generated.d.ts +479 -192
  21. package/dist/connectorKit/sources/supabase/cli-flags.generated.js +1 -1
  22. package/dist/connectorKit/surfaces.generated.d.ts +81 -0
  23. package/dist/connectorKit/surfaces.generated.js +122 -0
  24. package/dist/connectorKit/types.generated.d.ts +2 -0
  25. package/dist/controlPlaneSupabase.d.ts +9 -3
  26. package/dist/controlPlaneSupabase.js +18 -3
  27. package/dist/controlPlaneUnnamed.generated.d.ts +10 -1
  28. package/dist/controlPlaneUnnamed.generated.js +6 -0
  29. package/dist/pluginPin.d.ts +1 -1
  30. package/dist/pluginPin.js +1 -1
  31. package/dist/psqlSupabase.d.ts +14 -6
  32. package/dist/psqlSupabase.js +24 -7
  33. package/dist/version.d.ts +1 -1
  34. package/dist/version.js +1 -1
  35. package/npm-shrinkwrap.json +19 -3
  36. package/package.json +3 -2
@@ -370,7 +370,9 @@ async function foundOffline(context, missed) {
370
370
  }
371
371
  if (missed.supabase) {
372
372
  const where = { cwd: context.cwd ?? null, env: context.env ?? process.env };
373
- found.push(...(await import("./controlPlaneSupabase.js")).supabaseFound(context.command, where));
373
+ const supabase = await import("./controlPlaneSupabase.js");
374
+ await supabase.readySupabaseSql(context.command);
375
+ found.push(...supabase.supabaseFound(context.command, where));
374
376
  }
375
377
  if (missed.kubernetes) {
376
378
  const where = { cwd: context.cwd ?? null, env: context.env ?? process.env, home: homedir() };
@@ -170,8 +170,12 @@ function readDoubleQuoted(state) {
170
170
  let cursor = state.index + 1;
171
171
  let text = "";
172
172
  while (cursor < end && input[cursor] !== '"') {
173
+ // Inside double quotes a backslash escapes only $ ` " \ and a newline; before anything else the shell keeps it
174
+ // (`psql -c "select 1 \gexec"` hands psql `\gexec`).
173
175
  if (input[cursor] === "\\" && cursor + 1 < end) {
174
- text += input[cursor + 1];
176
+ const next = input[cursor + 1];
177
+ if (next !== "\n")
178
+ text += '$`"\\'.includes(next) ? next : `\\${next}`;
175
179
  cursor += 2;
176
180
  continue;
177
181
  }
@@ -8,6 +8,8 @@ import type { Manifest } from "./manifest.generated.js";
8
8
  import type { Normalized, Value } from "./types.generated.js";
9
9
  /** Every command the manifest knows, longest first. */
10
10
  export declare function knownOps(m: Manifest): string[];
11
+ /** An unknown flag whose name says it may change what the command does: never kept, always fails closed. */
12
+ export declare const EFFECT_FLAG_WORDS: RegExp;
11
13
  export declare const present: (value: Value | undefined) => boolean;
12
14
  export declare const programName: (word: string) => string;
13
15
  /** Strip what runs a program without changing it: env assignments, launchers (`launchers.ts`: env, sudo, timeout,
@@ -27,6 +27,27 @@ function tablesOf(m) {
27
27
  tables.set(cli, built);
28
28
  return built;
29
29
  }
30
+ const flagNames = new WeakMap();
31
+ /** Every flag name the manifest knows anywhere (long and short): global, legacy, any command's, local and remote. */
32
+ function manifestFlags(m) {
33
+ const cli = m.capture.cli;
34
+ const hit = flagNames.get(cli);
35
+ if (hit)
36
+ return hit;
37
+ const names = new Set([
38
+ ...cli.localFlags,
39
+ ...cli.remoteFlags,
40
+ ...(cli.contextFlags ?? []),
41
+ ...(cli.infoFlags ?? [])
42
+ ]);
43
+ for (const spec of [...cli.flags.global, ...(cli.legacyFlags ?? []), ...Object.values(cli.flags.commands).flat()]) {
44
+ names.add(spec.long);
45
+ if (spec.short)
46
+ names.add(spec.short);
47
+ }
48
+ flagNames.set(cli, names);
49
+ return names;
50
+ }
30
51
  /** Every command the manifest knows, longest first. */
31
52
  export function knownOps(m) {
32
53
  return tablesOf(m).ops;
@@ -41,10 +62,24 @@ function flagTable(specs) {
41
62
  }
42
63
  return { long, short };
43
64
  }
65
+ /** An unknown flag whose name says it may change what the command does: never kept, always fails closed. */
66
+ export const EFFECT_FLAG_WORDS = /(^|-)(force|delete|del|remove|rm|prune|purge|drop|destroy|wipe|reset|all|recursive|cascade|yes|y|overwrite|replace|no-verify|unsafe|skip|confirm|auto-approve|allow)(-|$)/;
44
67
  /** Parse argv with one flag table, the way cobra (or Vercel's arg) does. */
45
- function parseArgs(words, specs, strict, framework) {
68
+ function parseArgs(words, specs, strict, framework, lenient) {
46
69
  const { long, short } = flagTable(specs);
47
- const out = { positional: [], flags: {} };
70
+ const out = { positional: [], flags: {}, unknown: [], maybeValues: new Set() };
71
+ // Lenient: an unknown flag is recorded; the word after it, unless it is a flag, may be its value.
72
+ // `lenient` holds every flag the manifest knows anywhere: one of those in the wrong place isn't new, it fails.
73
+ const unknownFlag = (name, inline, shown) => {
74
+ if (!lenient || lenient.has(name) || EFFECT_FLAG_WORDS.test(name)) {
75
+ fail(`unknown flag ${shown}`);
76
+ return;
77
+ }
78
+ out.unknown.push(name);
79
+ if (!inline)
80
+ pendingUnknown = true;
81
+ };
82
+ let pendingUnknown = false;
48
83
  const fail = (problem) => {
49
84
  out.problem ??= problem;
50
85
  };
@@ -77,6 +112,8 @@ function parseArgs(words, specs, strict, framework) {
77
112
  };
78
113
  for (let i = 0; i < words.length; i++) {
79
114
  const word = words[i];
115
+ const afterUnknown = pendingUnknown;
116
+ pendingUnknown = false;
80
117
  if (word === "--") {
81
118
  out.positional.push(...words.slice(i + 1));
82
119
  break;
@@ -90,7 +127,7 @@ function parseArgs(words, specs, strict, framework) {
90
127
  const spec = long.get(name);
91
128
  if (!spec) {
92
129
  if (strict)
93
- fail(`unknown flag ${word.slice(0, dashes)}${name}`);
130
+ unknownFlag(name, eq >= 0, `${word.slice(0, dashes)}${name}`);
94
131
  continue;
95
132
  }
96
133
  if (eq >= 0)
@@ -110,8 +147,9 @@ function parseArgs(words, specs, strict, framework) {
110
147
  for (let j = 0; j < letters.length; j++) {
111
148
  const spec = short.get(letters[j]);
112
149
  if (!spec) {
150
+ // Letters after an unknown one may be its value (`-n5`); only a lone unknown letter can take the next word.
113
151
  if (strict)
114
- fail(`unknown flag -${letters[j]}`);
152
+ unknownFlag(letters[j], j + 1 < letters.length, `-${letters[j]}`);
115
153
  break;
116
154
  }
117
155
  if (spec.value === "none") {
@@ -133,6 +171,8 @@ function parseArgs(words, specs, strict, framework) {
133
171
  }
134
172
  continue;
135
173
  }
174
+ if (afterUnknown)
175
+ out.maybeValues.add(out.positional.length);
136
176
  out.positional.push(word);
137
177
  }
138
178
  return out;
@@ -241,6 +281,38 @@ function folderOf(cli, flags, folderIndex, args, runnerDir) {
241
281
  : undefined;
242
282
  return typeof runnerDir === "string" ? joinFolder(runnerDir, named ?? ".") : named;
243
283
  }
284
+ /** How many positional arguments the vendor's usage line allows (Infinity for a rest argument or no usage line). */
285
+ function usageMax(usage) {
286
+ if (usage === undefined || usage.includes("..."))
287
+ return Infinity;
288
+ return (usage.match(/[<[][^>\]]+[>\]]/g) ?? []).filter((p) => !/flags|options/i.test(p)).length;
289
+ }
290
+ /**
291
+ * Lenient flags: the words right after an unknown flag written without `=` are its value or an argument. They are
292
+ * values when the command's rules read no argument, or when counting them as arguments would pass the usage line;
293
+ * otherwise the command can't be read (it fails closed, "Couldn't read").
294
+ */
295
+ function keptPositional(m, op, opLength, parsed) {
296
+ if (!parsed.maybeValues.size)
297
+ return { words: parsed.positional };
298
+ const dropped = parsed.positional.filter((_, i) => !parsed.maybeValues.has(i));
299
+ if ([...parsed.maybeValues].some((i) => i < opLength))
300
+ return { words: parsed.positional, problem: "an unknown flag before the command" };
301
+ const readsArgs = m.capture.cli.rules.some((rule) => rule.match === op && rule.args?.length);
302
+ if (!readsArgs)
303
+ return { words: dropped };
304
+ const max = usageMax(m.capture.cli.usage?.[op]);
305
+ if (parsed.positional.length - opLength > max && dropped.length - opLength <= max)
306
+ return { words: dropped };
307
+ return { words: parsed.positional, problem: "an unknown flag may hide an argument" };
308
+ }
309
+ /** The words parsed with the command's flags, strictly, or leniently where the manifest keeps unknown flags. */
310
+ function parseCommand(m, words, specs, op, defaulted, opLength) {
311
+ const cli = m.capture.cli;
312
+ const lenient = cli.unknownFlags === "keep" && op !== undefined && !defaulted ? manifestFlags(m) : undefined;
313
+ const exact = parseArgs(words, specs, true, cli.framework, lenient);
314
+ return { exact, kept: lenient ? keptPositional(m, op, opLength, exact) : { words: exact.positional } };
315
+ }
244
316
  export function normalizeCli(m, argv, given) {
245
317
  const cli = m.capture.cli;
246
318
  const programs = [...cli.programs, ...(cli.aliasPrograms ?? [])];
@@ -257,9 +329,9 @@ export function normalizeCli(m, argv, given) {
257
329
  const own = op ? (cli.flags.commands[op] ?? []) : [];
258
330
  // Deprecated target flags (--linked, --local, --db-url) still work only where the command takes a target.
259
331
  const legacy = own.some((flag) => flag.long === "remote") ? (cli.legacyFlags ?? []) : [];
260
- const exact = parseArgs(words, [...cli.flags.global, ...legacy, ...own], true, cli.framework);
261
332
  const opWords = op && !defaulted ? op.split(" ") : [];
262
- const positional = canonicalWords(exact.positional, cli.aliases ?? {});
333
+ const { exact, kept } = parseCommand(m, words, [...cli.flags.global, ...legacy, ...own], op, defaulted, opWords.length);
334
+ const positional = canonicalWords(kept.words, cli.aliases ?? {});
263
335
  const args = positional.slice(opWords.length);
264
336
  const params = { ...exact.flags };
265
337
  args.forEach((value, index) => (params[`$${index + 1}`] = value));
@@ -267,6 +339,7 @@ export function normalizeCli(m, argv, given) {
267
339
  const remote = cli.remoteFlags.some((flag) => present(exact.flags[flag]));
268
340
  const problem = given ??
269
341
  exact.problem ??
342
+ kept.problem ??
270
343
  (op && !opWords.every((part, i) => positional[i] === part) ? "flags moved the command" : undefined) ??
271
344
  (op && tooManyArgs(cli.usage?.[op], args.length) ? "more arguments than the command takes" : undefined) ??
272
345
  (remote && localFlagsUsed.some((flag) => flag === "local" || !own.some((spec) => spec.long === flag))
@@ -282,6 +355,7 @@ export function normalizeCli(m, argv, given) {
282
355
  local: info || localFlagsUsed.length > 0,
283
356
  remote,
284
357
  ...(localFlagsUsed.length ? { localFlagsUsed } : {}),
358
+ ...(exact.unknown.length ? { unknownFlags: [...new Set(exact.unknown)] } : {}),
285
359
  ...(folder ? { folder } : {}),
286
360
  ...(problem ? { problem } : {})
287
361
  };
@@ -0,0 +1,92 @@
1
+ /**
2
+ * A vendor CLI's whole command tree, pinned to one version (docs/design/zero-unknowns.md). `scripts/cli-trees/`
3
+ * crawls the installed binary's help into `sources/<platform>/cli-tree.json`; this module turns it into the
4
+ * manifest's tables (flags, aliases, usage lines) and measures how much of it a manifest names. Pure.
5
+ *
6
+ * Every leaf command of the pinned tree is named: a hand-written rule, a reviewed read, or an entry of the
7
+ * platform's command overlay (`CommandEffect`), which becomes a rule for the platform's "Other change" with the
8
+ * effects the reviewer gave it. A command the tree doesn't have is new (a newer CLI than the pin): "New command".
9
+ */
10
+ import type { Effect } from "../controlPlaneActions.generated.js";
11
+ import type { CaptureRule, CliSpec, FlagSpec, Manifest } from "./manifest.generated.js";
12
+ export type CliTreeCommand = {
13
+ path: string;
14
+ aliases?: readonly string[];
15
+ usage?: string;
16
+ /** Only holds subcommands: run alone it prints help. */
17
+ group?: boolean;
18
+ hidden?: boolean;
19
+ deprecated?: boolean;
20
+ summary?: string;
21
+ flags: readonly FlagSpec[];
22
+ };
23
+ export type CliTree = {
24
+ cli: string;
25
+ version: string;
26
+ framework: string;
27
+ source: string;
28
+ globalFlags: readonly FlagSpec[];
29
+ commands: readonly CliTreeCommand[];
30
+ };
31
+ /**
32
+ * What one operation does, reviewed. Each is explicit; the gate counts an operation with none as missing.
33
+ * - `read`: changes nothing on the platform; the reason is the evidence.
34
+ * - `local`: acts only on this computer (a local dev server, a config file, shell completion).
35
+ * - `rule`: a hand-written capture rule names it (the gate confirms one exists).
36
+ * - `other`: the app's "Other change" on `on`, with this summary and these effects (kind and impact follow them).
37
+ */
38
+ export type OpEffect = {
39
+ read: string;
40
+ } | {
41
+ local: string;
42
+ } | {
43
+ rule: true;
44
+ } | {
45
+ other: string;
46
+ effects: readonly Effect[];
47
+ on: "project" | "service" | "environment";
48
+ };
49
+ /** A CLI command's overlay entry: the same shape as every interface's. */
50
+ export type CommandEffect = OpEffect;
51
+ /** The words a command is known by in the manifest: the vendor's path with the manifest's own renames applied. */
52
+ export declare function renamePath(path: string, rename?: Readonly<Record<string, string>>): string;
53
+ /** Leaf commands (anything a person can run that isn't only a group), renamed. Hidden ones count: they run. */
54
+ export declare function treeLeaves(tree: CliTree, rename?: Readonly<Record<string, string>>): string[];
55
+ /** Groups: run alone they print help, a read. */
56
+ export declare function treeGroups(tree: CliTree, rename?: Readonly<Record<string, string>>): string[];
57
+ /** The manifest's flag table, aliases and usage lines, from the tree. */
58
+ export declare function treeTables(tree: CliTree, rename?: Readonly<Record<string, string>>): Pick<CliSpec, "flags" | "aliases" | "usage">;
59
+ /** Aliases merged (later wins) and followed to the end, so a spelling of a spelling lands on the command. */
60
+ export declare function mergeAliases(...maps: ReadonlyArray<Readonly<Record<string, string>>>): Record<string, string>;
61
+ /** Flags from the tree, with a manifest's own reviewed additions (hand-declared flags win where both name one). */
62
+ export declare function mergeFlags(base: Readonly<Record<string, readonly FlagSpec[]>>, extra: Readonly<Record<string, readonly FlagSpec[]>>): Record<string, FlagSpec[]>;
63
+ /** The capture rules and reads an overlay adds for commands no hand rule names. */
64
+ export declare function overlayCapture(overlay: Readonly<Record<string, CommandEffect>>, other: string, hooks: Readonly<Record<"project" | "service" | "environment", {
65
+ hook: string;
66
+ where: string;
67
+ }>>, ruled?: ReadonlySet<string>): {
68
+ rules: CaptureRule[];
69
+ reads: Record<string, string>;
70
+ };
71
+ /** The (action, summary template, effects) rows an overlay gives the platform's call-effects table. */
72
+ export declare function overlayCallEffects(overlay: Readonly<Record<string, CommandEffect>>, other: string, hooks: Readonly<Record<"project" | "service" | "environment", {
73
+ hook: string;
74
+ where: string;
75
+ }>>): Array<[string, string, readonly Effect[]]>;
76
+ export type CommandCoverage = {
77
+ cli: string;
78
+ version: string;
79
+ /** Leaf commands in the pinned tree. */
80
+ total: number;
81
+ /** Named by a rule, a read or the overlay. */
82
+ named: number;
83
+ /** Leaves nothing names: each would be Unclassified ("New command") today. */
84
+ missing: string[];
85
+ /** Overlay entries saying `rule` with no hand rule behind them. */
86
+ ruleless: string[];
87
+ /** (command, flag) pairs in the tree, and those the manifest's flag table knows. */
88
+ flagPairs: number;
89
+ flagPairsKnown: number;
90
+ };
91
+ /** How much of a pinned tree a manifest names (the ratchet in `cliTree.test.ts`). */
92
+ export declare function commandCoverage(m: Manifest, tree: CliTree, rename?: Readonly<Record<string, string>>, overlay?: Readonly<Record<string, CommandEffect>>): CommandCoverage;
@@ -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))
@@ -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>>;