passport-bridge 0.53.0 → 0.56.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 (82) hide show
  1. package/dist/cliHookDecide.d.ts +4 -2
  2. package/dist/cliHookDecide.js +27 -12
  3. package/dist/cliHookParse.js +5 -1
  4. package/dist/connectorKit/callEffects.generated.js +3 -1
  5. package/dist/connectorKit/cli.generated.d.ts +2 -0
  6. package/dist/connectorKit/cli.generated.js +80 -6
  7. package/dist/connectorKit/cliTree.generated.d.ts +92 -0
  8. package/dist/connectorKit/cliTree.generated.js +134 -0
  9. package/dist/connectorKit/containers.generated.d.ts +46 -0
  10. package/dist/connectorKit/containers.generated.js +202 -0
  11. package/dist/connectorKit/engine.generated.d.ts +6 -14
  12. package/dist/connectorKit/engine.generated.js +57 -104
  13. package/dist/connectorKit/links.generated.d.ts +14 -0
  14. package/dist/connectorKit/links.generated.js +146 -0
  15. package/dist/connectorKit/manifest.generated.d.ts +5 -0
  16. package/dist/connectorKit/manifests/railway.generated.js +3 -1
  17. package/dist/connectorKit/manifests/railwayCapture.generated.d.ts +5 -0
  18. package/dist/connectorKit/manifests/railwayCapture.generated.js +52 -5
  19. package/dist/connectorKit/manifests/railwayCommands.generated.d.ts +17 -0
  20. package/dist/connectorKit/manifests/railwayCommands.generated.js +268 -0
  21. package/dist/connectorKit/manifests/railwayHooks.generated.js +16 -7
  22. package/dist/connectorKit/manifests/supabase.generated.js +6 -1
  23. package/dist/connectorKit/manifests/supabaseCli.generated.d.ts +3 -1
  24. package/dist/connectorKit/manifests/supabaseCli.generated.js +91 -2
  25. package/dist/connectorKit/nodeChain.generated.d.ts +22 -0
  26. package/dist/connectorKit/nodeChain.generated.js +90 -0
  27. package/dist/connectorKit/pgParser.d.ts +8 -6
  28. package/dist/connectorKit/pgParser.js +16 -9
  29. package/dist/connectorKit/scripts.generated.d.ts +72 -0
  30. package/dist/connectorKit/scripts.generated.js +282 -0
  31. package/dist/connectorKit/shell.generated.d.ts +29 -31
  32. package/dist/connectorKit/shell.generated.js +179 -184
  33. package/dist/connectorKit/shellFed.generated.d.ts +7 -1
  34. package/dist/connectorKit/shellFed.generated.js +111 -14
  35. package/dist/connectorKit/shellRuns.generated.d.ts +104 -0
  36. package/dist/connectorKit/shellRuns.generated.js +301 -0
  37. package/dist/connectorKit/sources/railway/cli-tree.generated.d.ts +122 -0
  38. package/dist/connectorKit/sources/railway/cli-tree.generated.js +2 -0
  39. package/dist/connectorKit/sources/supabase/cli-flags.generated.d.ts +479 -192
  40. package/dist/connectorKit/sources/supabase/cli-flags.generated.js +1 -1
  41. package/dist/connectorKit/spawns.generated.d.ts +3 -0
  42. package/dist/connectorKit/spawns.generated.js +66 -9
  43. package/dist/connectorKit/surfaces.generated.d.ts +81 -0
  44. package/dist/connectorKit/surfaces.generated.js +122 -0
  45. package/dist/connectorKit/template.generated.d.ts +12 -0
  46. package/dist/connectorKit/template.generated.js +19 -0
  47. package/dist/connectorKit/types.generated.d.ts +2 -0
  48. package/dist/connectorKit/unread.generated.d.ts +40 -0
  49. package/dist/connectorKit/unread.generated.js +92 -0
  50. package/dist/controlPlane.generated.d.ts +3 -2
  51. package/dist/controlPlaneCloudflare.js +5 -3
  52. package/dist/controlPlaneGuard.js +1 -5
  53. package/dist/controlPlaneRailwayGuard.d.ts +26 -34
  54. package/dist/controlPlaneRailwayGuard.js +131 -116
  55. package/dist/controlPlaneRoutes.generated.d.ts +13 -0
  56. package/dist/controlPlaneRoutes.generated.js +9 -0
  57. package/dist/controlPlaneSentry.js +5 -3
  58. package/dist/controlPlaneSupabase.d.ts +9 -3
  59. package/dist/controlPlaneSupabase.js +23 -6
  60. package/dist/controlPlaneTerraform.js +7 -4
  61. package/dist/controlPlaneUnnamed.generated.d.ts +27 -1
  62. package/dist/controlPlaneUnnamed.generated.js +26 -1
  63. package/dist/pluginPin.d.ts +1 -1
  64. package/dist/pluginPin.js +1 -1
  65. package/dist/psqlSupabase.d.ts +14 -6
  66. package/dist/psqlSupabase.js +24 -7
  67. package/dist/scriptReader.d.ts +20 -0
  68. package/dist/scriptReader.js +52 -0
  69. package/dist/version.d.ts +1 -1
  70. package/dist/version.js +1 -1
  71. package/npm-shrinkwrap.json +19 -3
  72. package/package.json +3 -2
  73. package/dist/connectorKit/shadow.generated.d.ts +0 -52
  74. package/dist/connectorKit/shadow.generated.js +0 -148
  75. package/dist/controlPlaneRailway.generated.d.ts +0 -30
  76. package/dist/controlPlaneRailway.generated.js +0 -217
  77. package/dist/controlPlaneRailwayCli.generated.d.ts +0 -11
  78. package/dist/controlPlaneRailwayCli.generated.js +0 -455
  79. package/dist/kitShadow.d.ts +0 -81
  80. package/dist/kitShadow.js +0 -256
  81. package/dist/kitShadowBudget.d.ts +0 -10
  82. package/dist/kitShadowBudget.js +0 -15
@@ -0,0 +1,202 @@
1
+ // Generated by scripts/generate-control-plane-classifier.mjs. Do not edit.
2
+ /**
3
+ * A command run in a container (docs/design/zero-unknowns.md, follow-up 4): `docker run [options] <image> [command]`,
4
+ * `docker exec [options] <container> <command>`, the same for `podman` and `nerdctl`, and `docker container run|exec`.
5
+ * `shell.ts` reads the command like any other, in the host folder the container's working folder is mounted from
6
+ * (`-v "$PWD":/w -w /w/infra`), with only the variables the line gives it (`-e NAME=value`): the agent's own
7
+ * environment doesn't reach a container.
8
+ *
9
+ * An image whose entrypoint is a platform's CLI runs it with the command as its arguments (`hashicorp/terraform:1.14
10
+ * fmt` is `terraform fmt`). An option the reader doesn't know may take the next word, so the image can't be found:
11
+ * the caller fails closed when the line names the CLI.
12
+ */
13
+ import { programName } from "./cli.generated.js";
14
+ export const CONTAINER_PROGRAMS = /^(docker|podman|nerdctl)$/;
15
+ /** Images whose entrypoint is a CLI, by repository (registry host and tag dropped). */
16
+ export const IMAGE_ENTRYPOINTS = {
17
+ "hashicorp/terraform": "terraform",
18
+ "opentofu/opentofu": "tofu",
19
+ "getsentry/sentry-cli": "sentry-cli",
20
+ "bitnami/kubectl": "kubectl",
21
+ "alpine/helm": "helm",
22
+ "rancher/kubectl": "kubectl"
23
+ };
24
+ /** The container tool's own options that take a value, before `run`/`exec`. */
25
+ const GLOBAL_VALUED = new Set([
26
+ "-H",
27
+ "--host",
28
+ "--context",
29
+ "-c",
30
+ "--config",
31
+ "-l",
32
+ "--log-level",
33
+ "--namespace",
34
+ "-n"
35
+ ]);
36
+ /** `run` and `exec` options that take the next word as their value. */
37
+ const VALUED = new Set([
38
+ "-e",
39
+ "--env",
40
+ "--env-file",
41
+ "-v",
42
+ "--volume",
43
+ "--mount",
44
+ "-w",
45
+ "--workdir",
46
+ "--name",
47
+ "--network",
48
+ "--net",
49
+ "--network-alias",
50
+ "-p",
51
+ "--publish",
52
+ "--expose",
53
+ "-u",
54
+ "--user",
55
+ "--entrypoint",
56
+ "-l",
57
+ "--label",
58
+ "--label-file",
59
+ "--cpus",
60
+ "--cpu-shares",
61
+ "--cpuset-cpus",
62
+ "-m",
63
+ "--memory",
64
+ "--memory-swap",
65
+ "--platform",
66
+ "-h",
67
+ "--hostname",
68
+ "--add-host",
69
+ "--cap-add",
70
+ "--cap-drop",
71
+ "--device",
72
+ "--dns",
73
+ "--gpus",
74
+ "--ipc",
75
+ "--pid",
76
+ "--restart",
77
+ "--runtime",
78
+ "--security-opt",
79
+ "--shm-size",
80
+ "--tmpfs",
81
+ "--ulimit",
82
+ "--userns",
83
+ "--volumes-from",
84
+ "--stop-signal",
85
+ "--stop-timeout",
86
+ "--cidfile",
87
+ "--cgroupns",
88
+ "--log-driver",
89
+ "--log-opt",
90
+ "--pull",
91
+ "--link",
92
+ "--ip",
93
+ "--ip6",
94
+ "--mac-address",
95
+ "--detach-keys",
96
+ "--group-add",
97
+ "--health-cmd",
98
+ "--attach",
99
+ "-a"
100
+ ]);
101
+ /** Options that take no value. */
102
+ const FLAGS = /^(-[itdP]+|--rm|--interactive|--tty|--detach|--init|--privileged|--read-only|--publish-all|--no-healthcheck|--oom-kill-disable|--sig-proxy|--quiet|-q)$/;
103
+ /** The command words a container runs, or null when the words aren't a container run (`docker ps`, `docker build`). */
104
+ export function containerRun(words) {
105
+ if (!CONTAINER_PROGRAMS.test(programName(words[0] ?? "")))
106
+ return null;
107
+ let at = 1;
108
+ while (at < words.length && words[at].startsWith("-"))
109
+ at += GLOBAL_VALUED.has(words[at]) ? 2 : 1;
110
+ if (words[at] === "container")
111
+ at += 1;
112
+ const sub = words[at];
113
+ if (sub !== "run" && sub !== "exec")
114
+ return null;
115
+ const out = { command: [], mounts: [], env: [] };
116
+ const read = readOptions(words, at + 1, out);
117
+ if (read === null)
118
+ return { ...out, command: [], problem: "an option the guard cannot read" };
119
+ const { entrypoint } = read;
120
+ at = read.at;
121
+ // `run`: the image, then its command; `exec`: the container, then the command.
122
+ const image = words[at];
123
+ if (image === undefined)
124
+ return { ...out, command: [] };
125
+ const rest = Array.from({ length: Math.max(0, words.length - at - 1) }, (_, i) => at + 1 + i);
126
+ const named = sub === "run" && entrypoint === undefined ? imageEntrypoint(image) : undefined;
127
+ if (sub === "run" && entrypoint === undefined && !named)
128
+ out.image = image;
129
+ // `--entrypoint` names the program; the image's own entrypoint is the CLI it runs.
130
+ const program = entrypoint !== undefined ? programName(words[entrypoint.at].slice(entrypoint.from)) : named;
131
+ out.command = program ? [program, ...rest] : rest;
132
+ return out;
133
+ }
134
+ /** `run`/`exec` options from `at`, recorded into `out`: where the image or container is, and `--entrypoint`. Null at
135
+ * an option the reader doesn't know (it may take the next word, so the image can't be found). */
136
+ function readOptions(words, start, out) {
137
+ let entrypoint;
138
+ let at = start;
139
+ for (; at < words.length; at++) {
140
+ const word = words[at];
141
+ if (word === "--")
142
+ return { at: at + 1, ...(entrypoint ? { entrypoint } : {}) };
143
+ if (!word.startsWith("-") || word === "-")
144
+ break;
145
+ const eq = word.startsWith("--") ? word.indexOf("=") : -1;
146
+ const option = eq < 0 ? (/^-[evwpu]./.test(word) ? word.slice(0, 2) : word) : word.slice(0, eq);
147
+ if (FLAGS.test(option) || (eq >= 0 && BOOLEAN_LONG.test(option)))
148
+ continue;
149
+ if (!VALUED.has(option))
150
+ return null;
151
+ const value = eq >= 0 || option !== word ? { at, from: eq >= 0 ? eq + 1 : 2 } : { at: ++at, from: 0 };
152
+ if (option === "-w" || option === "--workdir")
153
+ out.workdir = value;
154
+ else if (option === "-v" || option === "--volume" || option === "--mount")
155
+ out.mounts.push(value);
156
+ else if (option === "-e" || option === "--env")
157
+ out.env.push(value);
158
+ else if (option === "--env-file")
159
+ out.problem = "an env file the guard cannot read";
160
+ else if (option === "--entrypoint")
161
+ entrypoint = value;
162
+ }
163
+ return { at, ...(entrypoint ? { entrypoint } : {}) };
164
+ }
165
+ /** Long flags written with a value (`--rm=false`, `--sig-proxy=false`). */
166
+ const BOOLEAN_LONG = /^--(rm|init|privileged|read-only|sig-proxy|interactive|tty|detach)$/;
167
+ /** The CLI an image runs as its entrypoint (`hashicorp/terraform:1.14`, `docker.io/hashicorp/terraform@sha256:…`). */
168
+ export function imageEntrypoint(image) {
169
+ const repository = image.replace(/@.*$/, "").replace(/:[^/]*$/, "");
170
+ const parts = repository.split("/");
171
+ // A registry host (has a dot or a port, or is localhost) is not part of the name.
172
+ const name = (parts.length > 2 || /[.:]|^localhost$/.test(parts[0]) ? parts.slice(1) : parts).join("/");
173
+ return Object.hasOwn(IMAGE_ENTRYPOINTS, name) ? IMAGE_ENTRYPOINTS[name] : undefined;
174
+ }
175
+ /** A `-v`/`--volume`/`--mount` value as a bind mount, or null for a named volume or anything else. */
176
+ export function bindMount(value) {
177
+ if (value.includes("type=") || value.includes("source=") || value.includes("src=")) {
178
+ const fields = Object.fromEntries(value.split(",").map((pair) => [pair.slice(0, pair.indexOf("=")), pair.slice(pair.indexOf("=") + 1)]));
179
+ const host = fields.source ?? fields.src;
180
+ const container = fields.target ?? fields.destination ?? fields.dst;
181
+ return fields.type === "bind" && host && container ? { host, container } : null;
182
+ }
183
+ const [host, container] = value.split(":");
184
+ // A named volume (`cache:/root/.cache`) is no folder on this computer.
185
+ return host && container && /^[./~]/.test(host) ? { host, container } : null;
186
+ }
187
+ /** The host folder a container's working folder is, through its bind mounts (the deepest that holds it); undefined
188
+ * when none does. `hostPath` resolves a mount's host side against the line's folder. */
189
+ export function hostFolder(workdir, mounts, hostPath) {
190
+ const inside = (path) => (path.endsWith("/") ? path.slice(0, -1) : path);
191
+ let best;
192
+ for (const mount of mounts) {
193
+ const target = inside(mount.container);
194
+ if ((workdir === target || workdir.startsWith(`${target}/`)) &&
195
+ target.length > inside(best?.container ?? "").length)
196
+ best = mount;
197
+ }
198
+ if (!best)
199
+ return undefined;
200
+ const rest = workdir.slice(inside(best.container).length).replace(/^\//, "");
201
+ return hostPath(rest ? `${inside(best.host)}/${rest}` : best.host);
202
+ }
@@ -12,28 +12,20 @@
12
12
  * field sent twice with two values; a list where a rule takes one value; a
13
13
  * node whose parent can't be resolved from the request or the inventory; a
14
14
  * hook that's missing; a problem the guard's resolver found (`shell.ts`).
15
+ * Each carries why (`unnamed.why`, docs/design/zero-unknowns.md decision 10): "new", an operation the manifest
16
+ * doesn't have, stays Unclassified; "unread", a known operation it couldn't read, takes the most that operation could
17
+ * do, its effects possible (`unreadFinding`), and stays Unclassified only when that is nothing but reads.
15
18
  * Only a reviewed read (a reads entry or a "read" rule), a local-only command,
16
19
  * or SQL the parser shows only reads returns null.
17
20
  */
18
- import { type Classification, type DiscoveredNode } from "../controlPlane.generated.js";
21
+ import { type Classification } from "../controlPlane.generated.js";
19
22
  import { type Manifest } from "./manifest.generated.js";
20
23
  import type { ClassifyContext, ConnectorHooks, Normalized, Request } from "./types.generated.js";
21
24
  export { at, fill, parseTemplate, placeholders, render, safeName, valuePlaceholders } from "./template.generated.js";
25
+ export { nodeChain, type Chain } from "./nodeChain.generated.js";
26
+ export { readsOnly, unreadFinding, type UnreadOptions } from "./unread.generated.js";
22
27
  export type * from "./types.generated.js";
23
28
  export declare function normalize(m: Manifest, request: Request): Normalized | null;
24
- export type Chain = {
25
- nodeId: string;
26
- chain: DiscoveredNode[];
27
- unresolved?: string;
28
- };
29
- /**
30
- * The node a request lands on and its chain from the service down. The
31
- * requested type, or its nearest ancestor the params can name; every
32
- * ancestor above it must be named by the params or found in the inventory
33
- * (context.parents, hooks.resolveParent), or the chain is `unresolved` and
34
- * the caller fails closed.
35
- */
36
- export declare function nodeChain(m: Manifest, type: string, params: Readonly<Record<string, unknown>>, context?: ClassifyContext, hooks?: ConnectorHooks): Chain;
37
29
  export declare function assertSchema(m: Manifest): void;
38
30
  /**
39
31
  * How a request was decided: `rule` (a capture rule or its hook named the Actions, which may include the
@@ -13,6 +13,9 @@
13
13
  * field sent twice with two values; a list where a rule takes one value; a
14
14
  * node whose parent can't be resolved from the request or the inventory; a
15
15
  * hook that's missing; a problem the guard's resolver found (`shell.ts`).
16
+ * Each carries why (`unnamed.why`, docs/design/zero-unknowns.md decision 10): "new", an operation the manifest
17
+ * doesn't have, stays Unclassified; "unread", a known operation it couldn't read, takes the most that operation could
18
+ * do, its effects possible (`unreadFinding`), and stays Unclassified only when that is nothing but reads.
16
19
  * Only a reviewed read (a reads entry or a "read" rule), a local-only command,
17
20
  * or SQL the parser shows only reads returns null.
18
21
  */
@@ -22,8 +25,12 @@ import { knownOps, normalizeCli } from "./cli.generated.js";
22
25
  import { MANIFEST_SCHEMA } from "./manifest.generated.js";
23
26
  import { canonical, holds } from "./params.generated.js";
24
27
  import { classifySql, SQL_LABEL } from "./sql.generated.js";
25
- import { fill, render, safeName, valuePlaceholders } from "./template.generated.js";
28
+ import { nodeChain, typeChain } from "./nodeChain.generated.js";
29
+ import { fill, safeName, summaryOf, valuePlaceholders } from "./template.generated.js";
30
+ import { readsOnly, unreadFinding } from "./unread.generated.js";
26
31
  export { at, fill, parseTemplate, placeholders, render, safeName, valuePlaceholders } from "./template.generated.js";
32
+ export { nodeChain } from "./nodeChain.generated.js";
33
+ export { readsOnly, unreadFinding } from "./unread.generated.js";
27
34
  /* ------------------------------------------------------------------ */
28
35
  /* Normalize */
29
36
  /* ------------------------------------------------------------------ */
@@ -175,92 +182,6 @@ export function normalize(m, request) {
175
182
  return normalizeApi(m, request.method, request.url, request.body);
176
183
  }
177
184
  /* ------------------------------------------------------------------ */
178
- /* Nodes */
179
- /* ------------------------------------------------------------------ */
180
- /** A node the inventory knows, and its ancestors up to the service, as discovered nodes (service first). */
181
- function inventoryChain(id, context, serviceId) {
182
- const out = [];
183
- for (let current = id, guard = 0; current && current !== serviceId && guard < 8; guard++) {
184
- const parentId = context.parents?.[current] ?? serviceId;
185
- const tail = current.slice(current.lastIndexOf("/") + 1);
186
- const type = tail.slice(0, tail.indexOf(":"));
187
- const key = current.slice(current.indexOf(":") + 1);
188
- out.unshift({ id: current, parentId, type, name: context.names?.[current] ?? key, externalKey: key });
189
- current = parentId;
190
- }
191
- return out;
192
- }
193
- /** The node types from the service down to `type`. */
194
- function typeChain(m, type) {
195
- const specs = [];
196
- for (let t = type, guard = 0; t && guard < 8; guard++) {
197
- const spec = m.nodes[t];
198
- if (!spec)
199
- break;
200
- specs.unshift(t);
201
- t = spec.parent === "service" ? null : spec.parent.type;
202
- }
203
- return specs;
204
- }
205
- /**
206
- * The node a request lands on and its chain from the service down. The
207
- * requested type, or its nearest ancestor the params can name; every
208
- * ancestor above it must be named by the params or found in the inventory
209
- * (context.parents, hooks.resolveParent), or the chain is `unresolved` and
210
- * the caller fails closed.
211
- */
212
- export function nodeChain(m, type, params, context = {}, hooks = {}) {
213
- const specs = typeChain(m, type);
214
- const service = m.types.find((def) => def.type === type)?.service ?? m.services[0].key;
215
- const serviceId = nodeId(m.platform, service);
216
- const aliases = context.aliases ?? {};
217
- const idOf = (t, key) => {
218
- const named = nodeId(m.platform, service, t, key);
219
- return aliases[named] ?? named;
220
- };
221
- const keys = specs.map((t) => fill(m.nodes[t].key, params));
222
- // The deepest type the params name.
223
- let deepest = specs.length - 1;
224
- while (deepest >= 0 && keys[deepest] === null)
225
- deepest -= 1;
226
- if (deepest < 0)
227
- return { nodeId: serviceId, chain: [], unresolved: type };
228
- const chain = [];
229
- let parentId = serviceId;
230
- for (let i = 0; i <= deepest; i++) {
231
- const t = specs[i];
232
- const key = keys[i] ?? null;
233
- if (key === null) {
234
- // An ancestor the request doesn't name: the inventory may know the child's parent.
235
- const childIndex = keys.findIndex((k, index) => index > i && index <= deepest && k !== null);
236
- const childKey = keys[childIndex];
237
- const childType = specs[childIndex];
238
- const childId = idOf(childType, childKey);
239
- const found = context.parents?.[childId] ?? hooks.resolveParent?.(childType, childId, context) ?? null;
240
- if (!found)
241
- return { nodeId: serviceId, chain: [], unresolved: t };
242
- chain.push(...inventoryChain(found, context, serviceId));
243
- parentId = found;
244
- // Skip the other ancestors the request doesn't name: the inventory chain covers them.
245
- while (i + 1 <= deepest && keys[i + 1] === null)
246
- i += 1;
247
- continue;
248
- }
249
- const id = idOf(t, key);
250
- // The inventory knows this node's parent: it wins over a parent the request claims.
251
- const known = context.parents?.[id];
252
- if (known && known !== parentId && i === deepest) {
253
- chain.splice(0, chain.length, ...inventoryChain(known, context, serviceId));
254
- parentId = known;
255
- }
256
- const spec = m.nodes[t];
257
- const name = context.names?.[id] ?? (spec.name ? fill(spec.name, params) : null) ?? key.split("/").pop();
258
- chain.push({ id, parentId, type: t, name, externalKey: id.slice(id.indexOf(":") + 1) });
259
- parentId = id;
260
- }
261
- return { nodeId: parentId, chain };
262
- }
263
- /* ------------------------------------------------------------------ */
264
185
  /* Build */
265
186
  /* ------------------------------------------------------------------ */
266
187
  const UNCLASSIFIED = Symbol("unclassified");
@@ -344,11 +265,6 @@ function build(m, part, params, context, hooks, each) {
344
265
  });
345
266
  return out;
346
267
  }
347
- /** A rule's summary: the first template that fills, else the last rendered with "(unknown)" for what doesn't. */
348
- function summaryOf(part, summary, p) {
349
- const all = [summary, ...(part.summaryElse ?? [])];
350
- return fill(all, p) ?? render(all[all.length - 1], p);
351
- }
352
268
  /** What an unnamed request hit, coarse (`controlPlaneUnnamed.ts`): an API call's method and path template, a command
353
269
  * line's program and the words the CLI itself uses, up to the first it doesn't, an MCP tool's name. */
354
270
  function unnamedOf(m, n, ops) {
@@ -373,7 +289,7 @@ function unnamedOf(m, n, ops) {
373
289
  return unnamedCli([program, ...words]);
374
290
  }
375
291
  /** 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) {
292
+ function unclassified(m, n, params, context, hooks, problem = n.problem, why = "unread") {
377
293
  const action = m.actions.find((a) => a.key === m.capture.unclassified);
378
294
  // Words only: an id or value in a path or command never reaches the summary.
379
295
  const word = (part) => (/^(\{\w+\}|[a-z][a-z_-]{0,40})$/.test(part) ? part : "…");
@@ -388,7 +304,8 @@ function unclassified(m, n, params, context, hooks, problem = n.problem) {
388
304
  .join(" ")
389
305
  : (safeName(n.op) ?? "…");
390
306
  const at = nodeChain(m, action.appliesTo, params, context, hooks);
391
- const unnamed = unnamedOf(m, n, ops);
307
+ const hit = unnamedOf(m, n, ops);
308
+ const unnamed = hit ? { ...hit, why } : undefined;
392
309
  return {
393
310
  nodeId: at.unresolved
394
311
  ? nodeId(m.platform, m.types.find((t) => t.type === action.appliesTo)?.service ?? m.services[0].key)
@@ -427,19 +344,45 @@ export function explain(m, request, context = {}, hooks = {}) {
427
344
  const infoOnly = (m.capture.cli.infoFlags ?? []).some((flag) => n.params[flag] === true);
428
345
  if (n.iface === "cli" && infoOnly && !n.problem)
429
346
  return { found: [], via: "read" };
430
- return decideRequest(m, n, context, hooks, {});
347
+ // What the guard's shell resolver couldn't read (a script, a folder, a launcher) is shell shape's to decide
348
+ // (`shell.ts`, `launchers.ts`): it stays Unclassified here, why "unread", until they call `unreadFinding`.
349
+ const shell = (request.interface === "cli" && request.problem !== undefined) || n.problem === RUNNER_FOLDER;
350
+ return decideRequest(m, n, context, hooks, {}, shell);
431
351
  }
432
- function decideRequest(m, n, context, hooks, override) {
433
- const failed = (rule, problem) => ({
434
- found: [unclassified(m, n, canonical(m, n, rule, context, override).params, context, hooks, problem ?? n.problem)],
435
- via: "failed"
436
- });
352
+ /** `normalizeCli`'s problem for a package runner whose folder the guard can't name (`launchers.ts`). */
353
+ const RUNNER_FOLDER = "a package runner's folder the guard cannot name";
354
+ function decideRequest(m, n, context, hooks, override, shell = false) {
437
355
  const spec = m.capture[n.iface];
438
356
  const candidates = spec.rules.filter((rule) => rule.match === n.op);
357
+ // New: a readable operation the manifest has no rule or read for. Anything else (a known operation, or a line it
358
+ // couldn't read: a launcher, a hidden value, a bad flag) is Couldn't read.
359
+ const why = n.op &&
360
+ (!n.problem || n.problem.startsWith("unknown flag")) &&
361
+ !candidates.length &&
362
+ !Object.hasOwn(spec.reads, n.op)
363
+ ? "new"
364
+ : "unread";
365
+ const failed = (rule, problem) => {
366
+ const params = canonical(m, n, rule, context, override).params;
367
+ const said = problem ?? n.problem;
368
+ // Couldn't read a known operation: the most it could do (`unreadFinding`); Unclassified when that only reads, or
369
+ // when not even the operation could be read (the shell's own cases, `shell.ts`).
370
+ const hit = why === "unread" && n.op && !shell ? unnamedOf(m, n, n.iface === "cli" ? knownOps(m) : []) : undefined;
371
+ const unread = why === "unread" && n.op && !shell
372
+ ? unreadFinding(m, n.op, { iface: n.iface, params, context, hooks, problem: said, ...(hit ? { hit } : {}) })
373
+ : null;
374
+ if (unread)
375
+ return { found: [unread], via: "failed" };
376
+ // A known operation that can only read stays a read whatever Passport couldn't read of it (decision 8): a hidden
377
+ // word that could be a subcommand already took that subcommand's worst case above.
378
+ if (why === "unread" && n.op && !shell && readsOnly(m, n.iface, n.op))
379
+ return { found: [], via: "read" };
380
+ return { found: [unclassified(m, n, params, context, hooks, said, why)], via: "failed" };
381
+ };
439
382
  // "none": an op it doesn't know names nothing, and nor does a listed read whatever its flags.
440
383
  if (spec.unknown === "none" && n.op && candidates.length === 0)
441
384
  return Object.hasOwn(spec.reads, n.op) ? { found: [], via: "read" } : { found: [], via: "none" };
442
- if (n.problem)
385
+ if (n.problem && !(n.iface === "cli" && unreadValueOnLeafRead(m, n, candidates.length)))
443
386
  return failed();
444
387
  if (candidates.length === 0)
445
388
  return Object.hasOwn(spec.reads, n.op) ? { found: [], via: "read" } : failed();
@@ -452,7 +395,7 @@ function decideRequest(m, n, context, hooks, override) {
452
395
  // A list, one item at a time: each item is classified as if the request named only it.
453
396
  const list = rule.each !== undefined && !(rule.each in override) ? params[rule.each] : undefined;
454
397
  if (Array.isArray(list) && list.length > 1)
455
- return eachItem(m, n, context, hooks, override, rule.each, list);
398
+ return eachItem(m, n, context, hooks, override, rule.each, list, shell);
456
399
  if (!holds(rule.when, params, declaredBody(n)))
457
400
  continue;
458
401
  if (n.iface === "cli" && unnamedArgs(n, rule))
@@ -466,12 +409,22 @@ function decideRequest(m, n, context, hooks, override) {
466
409
  }
467
410
  return failed();
468
411
  }
469
- function eachItem(m, n, context, hooks, override, name, list) {
470
- const items = list.map((item) => decideRequest(m, n, context, hooks, { ...override, [name]: item }));
412
+ function eachItem(m, n, context, hooks, override, name, list, shell) {
413
+ const items = list.map((item) => decideRequest(m, n, context, hooks, { ...override, [name]: item }, shell));
471
414
  const vias = new Set(items.map((one) => one.via));
472
415
  const via = vias.has("failed") ? "failed" : vias.has("rule") ? "rule" : "read";
473
416
  return { found: dedupe(items.flatMap((one) => one.found)), via };
474
417
  }
418
+ /**
419
+ * A value the guard can't read (`$SVC`) on a reviewed read that is a leaf command (no longer command starts with
420
+ * it, no rule names it) can't change what it does: it stays a read (docs/design/zero-unknowns.md, "Couldn't read").
421
+ * On a command with rules, or one a hidden word could turn into a subcommand (`railway service $X`), it fails.
422
+ */
423
+ function unreadValueOnLeafRead(m, n, rules) {
424
+ if (n.problem !== "a value the guard cannot read" || rules > 0 || !Object.hasOwn(m.capture.cli.reads, n.op))
425
+ return false;
426
+ return !knownOps(m).some((op) => op.startsWith(`${n.op} `));
427
+ }
475
428
  /** The body's top-level fields the operation declares (all of them when its schema isn't known). */
476
429
  function declaredBody(n) {
477
430
  if (!n.inputs || !n.body || typeof n.body !== "object" || Array.isArray(n.body))
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Folders and link files for the guard-side resolver (`shell.ts`): a path joined onto a folder, and a folder's link
3
+ * (the manifest's link file in the folder or the nearest parent), read through the guard's file reader.
4
+ */
5
+ import type { Manifest } from "./manifest.generated.js";
6
+ /** What reading a link needs from the guard. */
7
+ export type LinkReader = {
8
+ readFile?: (path: string) => string | undefined;
9
+ };
10
+ /** A path joined onto a folder, with "." and ".." resolved; posix. */
11
+ export declare function joinPath(folder: string, path: string): string;
12
+ /** A folder's link: the manifest's link file (the first of several it names) in the folder or the nearest parent
13
+ * that has one. */
14
+ export declare function folderLink(m: Manifest, folder: string, guard: LinkReader): Record<string, string> | undefined;
@@ -0,0 +1,146 @@
1
+ // Generated by scripts/generate-control-plane-classifier.mjs. Do not edit.
2
+ /**
3
+ * Folders and link files for the guard-side resolver (`shell.ts`): a path joined onto a folder, and a folder's link
4
+ * (the manifest's link file in the folder or the nearest parent), read through the guard's file reader.
5
+ */
6
+ /** A path joined onto a folder, with "." and ".." resolved; posix. */
7
+ export function joinPath(folder, path) {
8
+ const parts = [];
9
+ for (const part of `${path.startsWith("/") ? "" : folder}/${path}`.split("/")) {
10
+ if (part === "" || part === ".")
11
+ continue;
12
+ if (part === "..")
13
+ parts.pop();
14
+ else
15
+ parts.push(part);
16
+ }
17
+ return `/${parts.join("/")}`;
18
+ }
19
+ /** An INI file's "section.key" values the link names, as params: `[defaults]` then `org = acme`. */
20
+ function iniFields(text, fields) {
21
+ const out = {};
22
+ let section = "";
23
+ for (const raw of text.split(/\r?\n/)) {
24
+ const line = raw.trim();
25
+ if (!line || line.startsWith(";") || line.startsWith("#"))
26
+ continue;
27
+ const header = /^\[([^\]]+)\]$/.exec(line);
28
+ if (header) {
29
+ section = header[1].trim().toLowerCase();
30
+ continue;
31
+ }
32
+ const eq = line.indexOf("=");
33
+ if (eq <= 0)
34
+ continue;
35
+ const param = fields[`${section}.${line.slice(0, eq).trim().toLowerCase()}`];
36
+ const value = line.slice(eq + 1).trim();
37
+ if (param && value)
38
+ out[param] = value;
39
+ }
40
+ return Object.keys(out).length ? out : undefined;
41
+ }
42
+ /** A link file's text as params, or undefined when it can't be read. */
43
+ function linkParams(link, text) {
44
+ if (link.format === "text")
45
+ return text.trim() ? { [link.param]: text.trim() } : undefined;
46
+ if (link.format === "ini")
47
+ return iniFields(text, link.fields);
48
+ const parsed = link.format === "toml" ? tomlTop(text) : jsonTop(link.format === "jsonc" ? withoutComments(text) : text);
49
+ if (!parsed)
50
+ return undefined;
51
+ const out = {};
52
+ for (const [field, param] of Object.entries(link.fields))
53
+ if (typeof parsed[field] === "string")
54
+ out[param] = parsed[field];
55
+ return out;
56
+ }
57
+ function jsonTop(text) {
58
+ try {
59
+ const parsed = JSON.parse(text);
60
+ return parsed && typeof parsed === "object" && !Array.isArray(parsed)
61
+ ? parsed
62
+ : undefined;
63
+ }
64
+ catch {
65
+ return undefined;
66
+ }
67
+ }
68
+ /** JSONC as JSON: line and block comments outside strings, and trailing commas, removed. */
69
+ function withoutComments(text) {
70
+ let out = "";
71
+ for (let i = 0; i < text.length; i++) {
72
+ const ch = text[i];
73
+ if (ch === '"') {
74
+ const end = /"(?:[^"\\]|\\.)*"/y;
75
+ end.lastIndex = i;
76
+ const found = end.exec(text);
77
+ if (!found)
78
+ return out + text.slice(i);
79
+ out += found[0];
80
+ i += found[0].length - 1;
81
+ }
82
+ else if (ch === "/" && text[i + 1] === "/") {
83
+ while (i < text.length && text[i] !== "\n")
84
+ i++;
85
+ out += "\n";
86
+ }
87
+ else if (ch === "/" && text[i + 1] === "*") {
88
+ const close = text.indexOf("*/", i + 2);
89
+ i = close < 0 ? text.length : close + 1;
90
+ }
91
+ else
92
+ out += ch;
93
+ }
94
+ return out.replace(/,(\s*[}\]])/g, "$1");
95
+ }
96
+ /** A TOML file's top-level string keys (`name = "api"`), up to its first table header; nothing else is read. */
97
+ function tomlTop(text) {
98
+ const out = {};
99
+ for (const raw of text.split(/\r?\n/)) {
100
+ const line = raw.trim();
101
+ if (line.startsWith("["))
102
+ break;
103
+ const found = /^([A-Za-z0-9_-]+)\s*=\s*(?:"((?:[^"\\]|\\.)*)"|'([^']*)')\s*(?:#.*)?$/.exec(line);
104
+ if (found)
105
+ out[found[1]] = found[2] ?? found[3] ?? "";
106
+ }
107
+ return out;
108
+ }
109
+ /** A path that names a link file itself (Wrangler's `--config staging.toml`): read as the link spec of its format, never
110
+ * a parent's. Undefined when the path isn't one (a folder) or the file can't be read; null when nothing can name it. */
111
+ function readLinkFile(links, path, guard) {
112
+ const format = /\.toml$/i.test(path)
113
+ ? "toml"
114
+ : /\.jsonc$/i.test(path)
115
+ ? "jsonc"
116
+ : /\.json$/i.test(path)
117
+ ? "json"
118
+ : null;
119
+ if (!format)
120
+ return undefined;
121
+ const link = links.find((spec) => spec.format === format);
122
+ const text = link ? guard.readFile?.(path) : undefined;
123
+ return link && text !== undefined ? (linkParams(link, text) ?? null) : null;
124
+ }
125
+ /** A folder's link: the manifest's link file (the first of several it names) in the folder or the nearest parent
126
+ * that has one. */
127
+ export function folderLink(m, folder, guard) {
128
+ const spec = m.capture.cli.link;
129
+ if (!spec || !guard.readFile)
130
+ return undefined;
131
+ const links = Array.isArray(spec) ? spec : [spec];
132
+ const file = readLinkFile(links, folder, guard);
133
+ if (file !== undefined)
134
+ return file ?? undefined;
135
+ for (let dir = folder, guardDepth = 0; guardDepth < 64; guardDepth++) {
136
+ for (const link of links) {
137
+ const text = guard.readFile(joinPath(dir, link.file));
138
+ if (text !== undefined)
139
+ return linkParams(link, text);
140
+ }
141
+ if (dir === "/")
142
+ return undefined;
143
+ dir = joinPath(dir, "..");
144
+ }
145
+ return undefined;
146
+ }
@@ -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,7 +1,9 @@
1
1
  import { MANIFEST_SCHEMA } from "../manifest.generated.js";
2
2
  import { RAILWAY_CAPTURE } from "./railwayCapture.generated.js";
3
3
  /**
4
- * Railway at Level 1, for the shadow run (integrations spike, 2026-11-14). Derived from today's classifier
4
+ * Railway at Level 1: it decides every `railway` command line on this computer (docs/design/zero-unknowns.md,
5
+ * follow-up 2, 2026-11-28); Railway's MCP tools at the gateway still run in its shadow (integrations spike,
6
+ * 2026-11-14). Derived from today's classifier
5
7
  * (`shared/controlPlaneRailway*.ts`) and its tests: the same action keys (including the ones the catalog
6
8
  * folded into others on 2026-11-13, which the server still maps: `removed.ts`), node ids and targets. Every
7
9
  * node is placed from the inventory (an environment or service by id or name, the folder's link, the