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.
- package/dist/cliHookDecide.d.ts +4 -2
- package/dist/cliHookDecide.js +27 -12
- package/dist/cliHookParse.js +5 -1
- package/dist/connectorKit/callEffects.generated.js +3 -1
- package/dist/connectorKit/cli.generated.d.ts +2 -0
- package/dist/connectorKit/cli.generated.js +80 -6
- package/dist/connectorKit/cliTree.generated.d.ts +92 -0
- package/dist/connectorKit/cliTree.generated.js +134 -0
- package/dist/connectorKit/containers.generated.d.ts +46 -0
- package/dist/connectorKit/containers.generated.js +202 -0
- package/dist/connectorKit/engine.generated.d.ts +6 -14
- package/dist/connectorKit/engine.generated.js +57 -104
- package/dist/connectorKit/links.generated.d.ts +14 -0
- package/dist/connectorKit/links.generated.js +146 -0
- package/dist/connectorKit/manifest.generated.d.ts +5 -0
- package/dist/connectorKit/manifests/railway.generated.js +3 -1
- package/dist/connectorKit/manifests/railwayCapture.generated.d.ts +5 -0
- package/dist/connectorKit/manifests/railwayCapture.generated.js +52 -5
- package/dist/connectorKit/manifests/railwayCommands.generated.d.ts +17 -0
- package/dist/connectorKit/manifests/railwayCommands.generated.js +268 -0
- package/dist/connectorKit/manifests/railwayHooks.generated.js +16 -7
- package/dist/connectorKit/manifests/supabase.generated.js +6 -1
- package/dist/connectorKit/manifests/supabaseCli.generated.d.ts +3 -1
- package/dist/connectorKit/manifests/supabaseCli.generated.js +91 -2
- package/dist/connectorKit/nodeChain.generated.d.ts +22 -0
- package/dist/connectorKit/nodeChain.generated.js +90 -0
- package/dist/connectorKit/pgParser.d.ts +8 -6
- package/dist/connectorKit/pgParser.js +16 -9
- package/dist/connectorKit/scripts.generated.d.ts +72 -0
- package/dist/connectorKit/scripts.generated.js +282 -0
- package/dist/connectorKit/shell.generated.d.ts +29 -31
- package/dist/connectorKit/shell.generated.js +179 -184
- package/dist/connectorKit/shellFed.generated.d.ts +7 -1
- package/dist/connectorKit/shellFed.generated.js +111 -14
- package/dist/connectorKit/shellRuns.generated.d.ts +104 -0
- package/dist/connectorKit/shellRuns.generated.js +301 -0
- package/dist/connectorKit/sources/railway/cli-tree.generated.d.ts +122 -0
- package/dist/connectorKit/sources/railway/cli-tree.generated.js +2 -0
- package/dist/connectorKit/sources/supabase/cli-flags.generated.d.ts +479 -192
- package/dist/connectorKit/sources/supabase/cli-flags.generated.js +1 -1
- package/dist/connectorKit/spawns.generated.d.ts +3 -0
- package/dist/connectorKit/spawns.generated.js +66 -9
- package/dist/connectorKit/surfaces.generated.d.ts +81 -0
- package/dist/connectorKit/surfaces.generated.js +122 -0
- package/dist/connectorKit/template.generated.d.ts +12 -0
- package/dist/connectorKit/template.generated.js +19 -0
- package/dist/connectorKit/types.generated.d.ts +2 -0
- package/dist/connectorKit/unread.generated.d.ts +40 -0
- package/dist/connectorKit/unread.generated.js +92 -0
- package/dist/controlPlane.generated.d.ts +3 -2
- package/dist/controlPlaneCloudflare.js +5 -3
- package/dist/controlPlaneGuard.js +1 -5
- package/dist/controlPlaneRailwayGuard.d.ts +26 -34
- package/dist/controlPlaneRailwayGuard.js +131 -116
- package/dist/controlPlaneRoutes.generated.d.ts +13 -0
- package/dist/controlPlaneRoutes.generated.js +9 -0
- package/dist/controlPlaneSentry.js +5 -3
- package/dist/controlPlaneSupabase.d.ts +9 -3
- package/dist/controlPlaneSupabase.js +23 -6
- package/dist/controlPlaneTerraform.js +7 -4
- package/dist/controlPlaneUnnamed.generated.d.ts +27 -1
- package/dist/controlPlaneUnnamed.generated.js +26 -1
- package/dist/pluginPin.d.ts +1 -1
- package/dist/pluginPin.js +1 -1
- package/dist/psqlSupabase.d.ts +14 -6
- package/dist/psqlSupabase.js +24 -7
- package/dist/scriptReader.d.ts +20 -0
- package/dist/scriptReader.js +52 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/npm-shrinkwrap.json +19 -3
- package/package.json +3 -2
- package/dist/connectorKit/shadow.generated.d.ts +0 -52
- package/dist/connectorKit/shadow.generated.js +0 -148
- package/dist/controlPlaneRailway.generated.d.ts +0 -30
- package/dist/controlPlaneRailway.generated.js +0 -217
- package/dist/controlPlaneRailwayCli.generated.d.ts +0 -11
- package/dist/controlPlaneRailwayCli.generated.js +0 -455
- package/dist/kitShadow.d.ts +0 -81
- package/dist/kitShadow.js +0 -256
- package/dist/kitShadowBudget.d.ts +0 -10
- package/dist/kitShadowBudget.js +0 -15
package/dist/cliHookDecide.d.ts
CHANGED
|
@@ -53,6 +53,8 @@ export type GuardContext = {
|
|
|
53
53
|
cwd?: string | null;
|
|
54
54
|
/** The agent's environment (Railway's link from the shell). */
|
|
55
55
|
env?: Record<string, string | undefined>;
|
|
56
|
+
/** What the script files the line runs hold (`scriptReader.ts`): a platform named only there is asked about too. */
|
|
57
|
+
scripts?: readonly string[];
|
|
56
58
|
budget: AbortSignal;
|
|
57
59
|
deadline: number;
|
|
58
60
|
now: () => number;
|
|
@@ -65,14 +67,14 @@ export declare function vendorVerbs(findings: readonly CliFinding[], vendors: re
|
|
|
65
67
|
/** What the agent reads when a command that can't be undone is refused on this computer. */
|
|
66
68
|
export declare function localRefusal(verb: LocalIrreversibleVerb, why: "signed-out" | "unreachable"): string;
|
|
67
69
|
/** What the guard answers: a block's refusal, or nothing. */
|
|
68
|
-
export declare function planGuard(
|
|
70
|
+
export declare function planGuard(given: GuardContext): Promise<GuardPlan>;
|
|
69
71
|
/** The one allowed decision of a line that runs one command on a kit platform: if the agent sees that command fail,
|
|
70
72
|
* its event reads Failed (`controlPlaneLateHold.ts`). Lines of several commands keep Ran: their exit status needn't be
|
|
71
73
|
* the platform's. */
|
|
72
74
|
export declare function failIdsOf(command: string, kit: ReadonlyArray<CpAnswer | null | undefined>): string[];
|
|
73
75
|
/** The guard never got to ask (its budget ran out first, or something failed before it answered): every platform the
|
|
74
76
|
* line would have asked about counts as unreachable, so a covered action is refused and the rest is recorded. */
|
|
75
|
-
export declare function planUnreachable(
|
|
77
|
+
export declare function planUnreachable(given: GuardContext): Promise<Record<string, unknown> | null>;
|
|
76
78
|
/** What the agent reads when the guard couldn't even classify a line Passport didn't answer for. */
|
|
77
79
|
export declare const UNCHECKED_REFUSAL = "Passport couldn't be reached or check this command, so it didn't run.";
|
|
78
80
|
export {};
|
package/dist/cliHookDecide.js
CHANGED
|
@@ -26,8 +26,6 @@ import { homedir } from "node:os";
|
|
|
26
26
|
import { soleCommand } from "./cliHookParse.js";
|
|
27
27
|
import { denyOutput } from "./cliHookGuard.js";
|
|
28
28
|
import { LOCAL_IRREVERSIBLE_VERBS, LOCAL_VENDOR } from "./controlPlaneBasic.generated.js";
|
|
29
|
-
import { setShadowDeadline } from "./kitShadowBudget.js";
|
|
30
|
-
import { shadowAfterDecision } from "./kitShadow.js";
|
|
31
29
|
/** A cheap check before a classifier loads: `gh …`, a `git … push`, or `railway …`. Every other command pays nothing. */
|
|
32
30
|
const GITHUB_WORD = /(?:^|[\s;&|(/])(?:gh\s|git\s(?:[^;&|]*\s)?push\b)/;
|
|
33
31
|
/** A curl, wget or httpie line that mentions GitHub anywhere (`github`, a `GH_*` variable such as GH_TOKEN or
|
|
@@ -98,11 +96,13 @@ export function localRefusal(verb, why) {
|
|
|
98
96
|
? `"${label}" can't be undone, and this computer isn't signed in to Passport, so it didn't run.`
|
|
99
97
|
: `Passport couldn't be reached, so "${label}" didn't run: it can't be undone.`;
|
|
100
98
|
}
|
|
101
|
-
/** What a line asks Passport about: each connected platform's part, and the vendor and local verbs.
|
|
99
|
+
/** What a line asks Passport about: each connected platform's part, and the vendor and local verbs. A platform's
|
|
100
|
+
* name in a script the line runs counts like one in the line (GitHub's reader reads the line alone). */
|
|
102
101
|
function asking(context, local) {
|
|
103
|
-
const { cp
|
|
102
|
+
const { cp } = context;
|
|
103
|
+
const command = context.scripts?.length ? [context.command, ...context.scripts].join("\n") : context.command;
|
|
104
104
|
return {
|
|
105
|
-
github: Boolean(cp?.platforms.github) && githubWord(command, cp?.githubHosts),
|
|
105
|
+
github: Boolean(cp?.platforms.github) && githubWord(context.command, cp?.githubHosts),
|
|
106
106
|
railway: Boolean(cp?.platforms.railway) && railwayWord(command),
|
|
107
107
|
supabase: Boolean(cp?.platforms.supabase) && supabaseWord(command),
|
|
108
108
|
kubernetes: Boolean(cp?.platforms.kubernetes) && kubernetesWord(command),
|
|
@@ -117,7 +117,8 @@ function asking(context, local) {
|
|
|
117
117
|
};
|
|
118
118
|
}
|
|
119
119
|
/** What the guard answers: a block's refusal, or nothing. */
|
|
120
|
-
export async function planGuard(
|
|
120
|
+
export async function planGuard(given) {
|
|
121
|
+
const context = await withScripts(given);
|
|
121
122
|
const local = context.local ?? [];
|
|
122
123
|
const refuse = (verb, why) => ({
|
|
123
124
|
output: denyOutput(context.client, localRefusal(verb, why))
|
|
@@ -134,16 +135,12 @@ export async function planGuard(context) {
|
|
|
134
135
|
}
|
|
135
136
|
if (![github, railway, supabase, kubernetes, terraform, sentry, cloudflare, npm].some(Boolean) && !verbs.length)
|
|
136
137
|
return { output: null };
|
|
137
|
-
// The kit's shadow run (`kitShadow.ts`) stops before the guard's deadline.
|
|
138
|
-
setShadowDeadline(context.deadline, context.now);
|
|
139
138
|
let api;
|
|
140
139
|
const open = async () => (api ??= (await context.openApi()) ?? undefined) ?? null;
|
|
141
140
|
const signal = AbortSignal.any([context.budget, AbortSignal.timeout(left)]);
|
|
142
141
|
const extra = context.report?.sessionId ? { sessionId: context.report.sessionId } : {};
|
|
143
142
|
const asked = { github, railway, supabase, kubernetes, terraform, sentry, cloudflare, npm };
|
|
144
143
|
const { threw, githubLine, railwayAnswer, supabaseAnswer, kubernetesAnswer, terraformAnswer, sentryAnswer, cloudflareAnswer, npmAnswer, verbAnswers } = await askAll(context, asked, verbs, { open, extra, signal });
|
|
145
|
-
// Decided: the kit's shadow run reads what was asked about, off the decision's path.
|
|
146
|
-
shadowAfterDecision();
|
|
147
144
|
const withApi = (output) => ({ output, ...(api ? { api } : {}) });
|
|
148
145
|
const answers = [
|
|
149
146
|
githubLine?.decided?.answer,
|
|
@@ -190,6 +187,21 @@ export async function planGuard(context) {
|
|
|
190
187
|
await leaveDecisions(githubLine?.decided ?? null, railwayAnswer, context, [...kit, ...verbAnswers], kit);
|
|
191
188
|
return withApi(null);
|
|
192
189
|
}
|
|
190
|
+
/** The context with what the line's script files hold, read once (`scriptReader.ts`). Reading them never fails the
|
|
191
|
+
* guard: a line whose scripts can't be read is asked about by its own words. */
|
|
192
|
+
async function withScripts(context) {
|
|
193
|
+
const platforms = context.cp?.platforms ?? {};
|
|
194
|
+
if (context.scripts !== undefined || !context.canAsk || !Object.values(platforms).some(Boolean))
|
|
195
|
+
return context;
|
|
196
|
+
try {
|
|
197
|
+
const { scriptsOfLine } = await import("./scriptReader.js");
|
|
198
|
+
const home = context.env?.HOME ?? homedir();
|
|
199
|
+
return { ...context, scripts: await scriptsOfLine(context.command, context.cwd, home) };
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
return context;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
193
205
|
/** Each platform's answer but GitHub's (which is the line's), for the offline rules. */
|
|
194
206
|
function othersOf(answers) {
|
|
195
207
|
return {
|
|
@@ -370,7 +382,9 @@ async function foundOffline(context, missed) {
|
|
|
370
382
|
}
|
|
371
383
|
if (missed.supabase) {
|
|
372
384
|
const where = { cwd: context.cwd ?? null, env: context.env ?? process.env };
|
|
373
|
-
|
|
385
|
+
const supabase = await import("./controlPlaneSupabase.js");
|
|
386
|
+
await supabase.readySupabaseSql(context.command);
|
|
387
|
+
found.push(...supabase.supabaseFound(context.command, where));
|
|
374
388
|
}
|
|
375
389
|
if (missed.kubernetes) {
|
|
376
390
|
const where = { cwd: context.cwd ?? null, env: context.env ?? process.env, home: homedir() };
|
|
@@ -396,7 +410,8 @@ async function foundOffline(context, missed) {
|
|
|
396
410
|
}
|
|
397
411
|
/** The guard never got to ask (its budget ran out first, or something failed before it answered): every platform the
|
|
398
412
|
* line would have asked about counts as unreachable, so a covered action is refused and the rest is recorded. */
|
|
399
|
-
export async function planUnreachable(
|
|
413
|
+
export async function planUnreachable(given) {
|
|
414
|
+
const context = await withScripts(given);
|
|
400
415
|
const { github, railway, supabase, kubernetes, terraform, sentry, cloudflare, npm } = asking(context, []);
|
|
401
416
|
return whenUnreachable(context, { github, railway, supabase, kubernetes, terraform, sentry, cloudflare, npm }, []);
|
|
402
417
|
}
|
package/dist/cliHookParse.js
CHANGED
|
@@ -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
|
-
|
|
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
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { unreadWordsBack } from "./template.generated.js";
|
|
1
2
|
const escape = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2
3
|
/** A summary template as a pattern: each `{param}` matches any text, and the kit's own asides (" (staged)", "(run SQL
|
|
3
4
|
* on project x)") may follow. */
|
|
@@ -14,7 +15,8 @@ export function callEffectsTable(entries) {
|
|
|
14
15
|
.sort((a, b) => specificity(b[1]) - specificity(a[1]))
|
|
15
16
|
.map(([key, template, effects]) => ({ key, pattern: templatePattern(template), effects }));
|
|
16
17
|
return (keys, summary) => {
|
|
17
|
-
|
|
18
|
+
// Couldn't read's words for a target it couldn't read are the template's placeholder.
|
|
19
|
+
const text = unreadWordsBack(summary.trim());
|
|
18
20
|
const found = compiled.find((entry) => keys.includes(entry.key) && entry.pattern.test(text));
|
|
19
21
|
return found ? found.effects.map((effect) => ({ ...effect })) : undefined;
|
|
20
22
|
};
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A command run in a container (docs/design/zero-unknowns.md, follow-up 4): `docker run [options] <image> [command]`,
|
|
3
|
+
* `docker exec [options] <container> <command>`, the same for `podman` and `nerdctl`, and `docker container run|exec`.
|
|
4
|
+
* `shell.ts` reads the command like any other, in the host folder the container's working folder is mounted from
|
|
5
|
+
* (`-v "$PWD":/w -w /w/infra`), with only the variables the line gives it (`-e NAME=value`): the agent's own
|
|
6
|
+
* environment doesn't reach a container.
|
|
7
|
+
*
|
|
8
|
+
* An image whose entrypoint is a platform's CLI runs it with the command as its arguments (`hashicorp/terraform:1.14
|
|
9
|
+
* fmt` is `terraform fmt`). An option the reader doesn't know may take the next word, so the image can't be found:
|
|
10
|
+
* the caller fails closed when the line names the CLI.
|
|
11
|
+
*/
|
|
12
|
+
export declare const CONTAINER_PROGRAMS: RegExp;
|
|
13
|
+
/** Images whose entrypoint is a CLI, by repository (registry host and tag dropped). */
|
|
14
|
+
export declare const IMAGE_ENTRYPOINTS: Readonly<Record<string, string>>;
|
|
15
|
+
export type Mount = {
|
|
16
|
+
host: string;
|
|
17
|
+
container: string;
|
|
18
|
+
};
|
|
19
|
+
/** A value in the caller's words: the word at `at`, from character `from` (`-eNAME=x`, `--env=NAME=x`). */
|
|
20
|
+
export type Ref = {
|
|
21
|
+
at: number;
|
|
22
|
+
from: number;
|
|
23
|
+
};
|
|
24
|
+
export type ContainerRun = {
|
|
25
|
+
/** The command the container runs, entrypoint first: indexes into the caller's words, or the entrypoint's name. */
|
|
26
|
+
command: Array<number | string>;
|
|
27
|
+
/** `-w`: the container's working folder, as given. */
|
|
28
|
+
workdir?: Ref;
|
|
29
|
+
/** `-v host:container`, `--mount type=bind,source=…,target=…`. */
|
|
30
|
+
mounts: Ref[];
|
|
31
|
+
/** `-e NAME=value` and `-e NAME`. */
|
|
32
|
+
env: Ref[];
|
|
33
|
+
/** `run`'s image when the reader doesn't know its entrypoint (the command may be its arguments). */
|
|
34
|
+
image?: string;
|
|
35
|
+
/** Why the command can't be read (an option it doesn't know, an env file). */
|
|
36
|
+
problem?: string;
|
|
37
|
+
};
|
|
38
|
+
/** The command words a container runs, or null when the words aren't a container run (`docker ps`, `docker build`). */
|
|
39
|
+
export declare function containerRun(words: readonly string[]): ContainerRun | null;
|
|
40
|
+
/** The CLI an image runs as its entrypoint (`hashicorp/terraform:1.14`, `docker.io/hashicorp/terraform@sha256:…`). */
|
|
41
|
+
export declare function imageEntrypoint(image: string): string | undefined;
|
|
42
|
+
/** A `-v`/`--volume`/`--mount` value as a bind mount, or null for a named volume or anything else. */
|
|
43
|
+
export declare function bindMount(value: string): Mount | null;
|
|
44
|
+
/** The host folder a container's working folder is, through its bind mounts (the deepest that holds it); undefined
|
|
45
|
+
* when none does. `hostPath` resolves a mount's host side against the line's folder. */
|
|
46
|
+
export declare function hostFolder(workdir: string, mounts: readonly Mount[], hostPath: (path: string) => string | undefined): string | undefined;
|