passport-bridge 0.55.0 → 0.57.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/connectorKit/callEffects.generated.js +3 -1
- 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 +42 -103
- package/dist/connectorKit/githubDecide.generated.d.ts +6 -0
- package/dist/connectorKit/githubDecide.generated.js +26 -7
- package/dist/connectorKit/links.generated.d.ts +14 -0
- package/dist/connectorKit/links.generated.js +146 -0
- package/dist/connectorKit/manifest.generated.d.ts +3 -0
- package/dist/connectorKit/manifests/cloudflareApiOverlay.generated.d.ts +22 -0
- package/dist/connectorKit/manifests/cloudflareApiOverlay.generated.js +50 -0
- package/dist/connectorKit/manifests/cloudflareCli.generated.d.ts +3 -0
- package/dist/connectorKit/manifests/cloudflareCli.generated.js +27 -6
- package/dist/connectorKit/manifests/cloudflareCommands.generated.d.ts +17 -0
- package/dist/connectorKit/manifests/cloudflareCommands.generated.js +353 -0
- package/dist/connectorKit/manifests/githubCapture.generated.js +3 -2
- package/dist/connectorKit/manifests/githubHooks.generated.js +3 -1
- package/dist/connectorKit/manifests/githubReads.generated.d.ts +4 -0
- package/dist/connectorKit/manifests/githubReads.generated.js +36 -2
- package/dist/connectorKit/manifests/kubernetesCli.generated.d.ts +6 -0
- package/dist/connectorKit/manifests/kubernetesCli.generated.js +18 -4
- package/dist/connectorKit/manifests/railway.generated.js +3 -1
- package/dist/connectorKit/manifests/railwayCapture.generated.js +16 -1
- package/dist/connectorKit/manifests/railwayCommands.generated.js +9 -1
- package/dist/connectorKit/manifests/railwayGraphql.generated.d.ts +40 -0
- package/dist/connectorKit/manifests/railwayGraphql.generated.js +409 -0
- package/dist/connectorKit/manifests/railwayHooks.generated.d.ts +10 -1
- package/dist/connectorKit/manifests/railwayHooks.generated.js +105 -41
- package/dist/connectorKit/manifests/sentryCli.generated.js +3 -0
- package/dist/connectorKit/manifests/supabaseApi.generated.js +6 -0
- package/dist/connectorKit/manifests/supabaseCapture.generated.js +4 -0
- package/dist/connectorKit/manifests/terraform.generated.d.ts +16 -4
- package/dist/connectorKit/manifests/terraform.generated.js +85 -104
- package/dist/connectorKit/manifests/terraformCatalog.generated.d.ts +15 -0
- package/dist/connectorKit/manifests/terraformCatalog.generated.js +36 -0
- package/dist/connectorKit/manifests/terraformCommands.generated.d.ts +2 -0
- package/dist/connectorKit/manifests/terraformCommands.generated.js +109 -0
- package/dist/connectorKit/nodeChain.generated.d.ts +22 -0
- package/dist/connectorKit/nodeChain.generated.js +90 -0
- 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/cloudflare/api-overlay.generated.d.ts +3793 -0
- package/dist/connectorKit/sources/cloudflare/api-overlay.generated.js +2 -0
- package/dist/connectorKit/sources/cloudflare/cli-tree.generated.d.ts +56 -0
- package/dist/connectorKit/sources/cloudflare/cli-tree.generated.js +2 -0
- package/dist/connectorKit/sources/railway/cli-tree.generated.d.ts +0 -17
- package/dist/connectorKit/sources/railway/cli-tree.generated.js +1 -1
- package/dist/connectorKit/sources/sentry/cli-commands.generated.d.ts +2 -0
- package/dist/connectorKit/sources/sentry/cli-commands.generated.js +1 -1
- package/dist/connectorKit/sources/supabase/api-operations.generated.js +1 -1
- package/dist/connectorKit/sources/terraform/cli-tree.generated.d.ts +32 -0
- package/dist/connectorKit/sources/terraform/cli-tree.generated.js +2 -0
- package/dist/connectorKit/spawns.generated.d.ts +3 -0
- package/dist/connectorKit/spawns.generated.js +66 -9
- package/dist/connectorKit/template.generated.d.ts +12 -0
- package/dist/connectorKit/template.generated.js +19 -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.d.ts +8 -3
- package/dist/controlPlaneCloudflare.js +22 -10
- package/dist/controlPlaneGuard.js +6 -8
- package/dist/controlPlaneNpmCommands.generated.d.ts +3 -0
- package/dist/controlPlaneNpmCommands.generated.js +17 -2
- package/dist/controlPlaneRailwayGuard.d.ts +42 -35
- package/dist/controlPlaneRailwayGuard.js +229 -117
- package/dist/controlPlaneRoutes.generated.d.ts +13 -0
- package/dist/controlPlaneRoutes.generated.js +9 -0
- package/dist/controlPlaneSentry.js +5 -3
- package/dist/controlPlaneSupabase.js +5 -3
- package/dist/controlPlaneTerraform.js +7 -4
- package/dist/controlPlaneUnnamed.generated.d.ts +17 -0
- package/dist/controlPlaneUnnamed.generated.js +20 -1
- package/dist/pluginPin.d.ts +1 -1
- package/dist/pluginPin.js +1 -1
- 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 +2 -2
- package/package.json +1 -1
- 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 {
|
|
@@ -388,7 +400,9 @@ async function foundOffline(context, missed) {
|
|
|
388
400
|
}
|
|
389
401
|
if (missed.cloudflare) {
|
|
390
402
|
const where = { cwd: context.cwd ?? null, env: context.env ?? process.env };
|
|
391
|
-
|
|
403
|
+
const cloudflare = await import("./controlPlaneCloudflare.js");
|
|
404
|
+
const api = await cloudflare.cloudflareApiManifest(context.command);
|
|
405
|
+
found.push(...cloudflare.cloudflareFound(context.command, where, api));
|
|
392
406
|
}
|
|
393
407
|
if (missed.npm) {
|
|
394
408
|
const where = { cwd: context.cwd ?? null, env: context.env ?? process.env, home: homedir() };
|
|
@@ -398,7 +412,8 @@ async function foundOffline(context, missed) {
|
|
|
398
412
|
}
|
|
399
413
|
/** The guard never got to ask (its budget ran out first, or something failed before it answered): every platform the
|
|
400
414
|
* line would have asked about counts as unreachable, so a covered action is refused and the rest is recorded. */
|
|
401
|
-
export async function planUnreachable(
|
|
415
|
+
export async function planUnreachable(given) {
|
|
416
|
+
const context = await withScripts(given);
|
|
402
417
|
const { github, railway, supabase, kubernetes, terraform, sentry, cloudflare, npm } = asking(context, []);
|
|
403
418
|
return whenUnreachable(context, { github, railway, supabase, kubernetes, terraform, sentry, cloudflare, npm }, []);
|
|
404
419
|
}
|
|
@@ -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
|
};
|
|
@@ -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;
|
|
@@ -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
|
|
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 {
|
|
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) {
|
|
@@ -425,12 +341,24 @@ export function explain(m, request, context = {}, hooks = {}) {
|
|
|
425
341
|
return { found: [], via: "none" };
|
|
426
342
|
if (!n.op && !n.problem)
|
|
427
343
|
return { found: [], via: "read" }; // the program alone, `--help`, `--version`
|
|
344
|
+
if (n.iface === "api" && docsRead(m, n.op))
|
|
345
|
+
return { found: [], via: "read" };
|
|
428
346
|
const infoOnly = (m.capture.cli.infoFlags ?? []).some((flag) => n.params[flag] === true);
|
|
429
347
|
if (n.iface === "cli" && infoOnly && !n.problem)
|
|
430
348
|
return { found: [], via: "read" };
|
|
431
|
-
|
|
349
|
+
// What the guard's shell resolver couldn't read (a script, a folder, a launcher) is shell shape's to decide
|
|
350
|
+
// (`shell.ts`, `launchers.ts`): it stays Unclassified here, why "unread", until they call `unreadFinding`.
|
|
351
|
+
const shell = (request.interface === "cli" && request.problem !== undefined) || n.problem === RUNNER_FOLDER;
|
|
352
|
+
return decideRequest(m, n, context, hooks, {}, shell);
|
|
353
|
+
}
|
|
354
|
+
/** A GET or HEAD of a path that only serves the vendor's own documentation (`api.docs`). */
|
|
355
|
+
function docsRead(m, op) {
|
|
356
|
+
const [method, path] = op.split(" ");
|
|
357
|
+
return (method === "GET" || method === "HEAD") && (m.capture.api.docs ?? []).includes(path ?? "");
|
|
432
358
|
}
|
|
433
|
-
|
|
359
|
+
/** `normalizeCli`'s problem for a package runner whose folder the guard can't name (`launchers.ts`). */
|
|
360
|
+
const RUNNER_FOLDER = "a package runner's folder the guard cannot name";
|
|
361
|
+
function decideRequest(m, n, context, hooks, override, shell = false) {
|
|
434
362
|
const spec = m.capture[n.iface];
|
|
435
363
|
const candidates = spec.rules.filter((rule) => rule.match === n.op);
|
|
436
364
|
// New: a readable operation the manifest has no rule or read for. Anything else (a known operation, or a line it
|
|
@@ -441,12 +369,23 @@ function decideRequest(m, n, context, hooks, override) {
|
|
|
441
369
|
!Object.hasOwn(spec.reads, n.op)
|
|
442
370
|
? "new"
|
|
443
371
|
: "unread";
|
|
444
|
-
const failed = (rule, problem) =>
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
372
|
+
const failed = (rule, problem) => {
|
|
373
|
+
const params = canonical(m, n, rule, context, override).params;
|
|
374
|
+
const said = problem ?? n.problem;
|
|
375
|
+
// Couldn't read a known operation: the most it could do (`unreadFinding`); Unclassified when that only reads, or
|
|
376
|
+
// when not even the operation could be read (the shell's own cases, `shell.ts`).
|
|
377
|
+
const hit = why === "unread" && n.op && !shell ? unnamedOf(m, n, n.iface === "cli" ? knownOps(m) : []) : undefined;
|
|
378
|
+
const unread = why === "unread" && n.op && !shell
|
|
379
|
+
? unreadFinding(m, n.op, { iface: n.iface, params, context, hooks, problem: said, ...(hit ? { hit } : {}) })
|
|
380
|
+
: null;
|
|
381
|
+
if (unread)
|
|
382
|
+
return { found: [unread], via: "failed" };
|
|
383
|
+
// A known operation that can only read stays a read whatever Passport couldn't read of it (decision 8): a hidden
|
|
384
|
+
// word that could be a subcommand already took that subcommand's worst case above.
|
|
385
|
+
if (why === "unread" && n.op && !shell && readsOnly(m, n.iface, n.op))
|
|
386
|
+
return { found: [], via: "read" };
|
|
387
|
+
return { found: [unclassified(m, n, params, context, hooks, said, why)], via: "failed" };
|
|
388
|
+
};
|
|
450
389
|
// "none": an op it doesn't know names nothing, and nor does a listed read whatever its flags.
|
|
451
390
|
if (spec.unknown === "none" && n.op && candidates.length === 0)
|
|
452
391
|
return Object.hasOwn(spec.reads, n.op) ? { found: [], via: "read" } : { found: [], via: "none" };
|
|
@@ -463,7 +402,7 @@ function decideRequest(m, n, context, hooks, override) {
|
|
|
463
402
|
// A list, one item at a time: each item is classified as if the request named only it.
|
|
464
403
|
const list = rule.each !== undefined && !(rule.each in override) ? params[rule.each] : undefined;
|
|
465
404
|
if (Array.isArray(list) && list.length > 1)
|
|
466
|
-
return eachItem(m, n, context, hooks, override, rule.each, list);
|
|
405
|
+
return eachItem(m, n, context, hooks, override, rule.each, list, shell);
|
|
467
406
|
if (!holds(rule.when, params, declaredBody(n)))
|
|
468
407
|
continue;
|
|
469
408
|
if (n.iface === "cli" && unnamedArgs(n, rule))
|
|
@@ -477,8 +416,8 @@ function decideRequest(m, n, context, hooks, override) {
|
|
|
477
416
|
}
|
|
478
417
|
return failed();
|
|
479
418
|
}
|
|
480
|
-
function eachItem(m, n, context, hooks, override, name, list) {
|
|
481
|
-
const items = list.map((item) => decideRequest(m, n, context, hooks, { ...override, [name]: item }));
|
|
419
|
+
function eachItem(m, n, context, hooks, override, name, list, shell) {
|
|
420
|
+
const items = list.map((item) => decideRequest(m, n, context, hooks, { ...override, [name]: item }, shell));
|
|
482
421
|
const vias = new Set(items.map((one) => one.via));
|
|
483
422
|
const via = vias.has("failed") ? "failed" : vias.has("rule") ? "rule" : "read";
|
|
484
423
|
return { found: dedupe(items.flatMap((one) => one.found)), via };
|
|
@@ -27,6 +27,12 @@ export type GithubCliArgs = {
|
|
|
27
27
|
};
|
|
28
28
|
/** Whether a command line is `git push` (git's own options before it don't count). */
|
|
29
29
|
export declare function isGitPush(argv: readonly string[]): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* `git send-pack <url> <ref>…` (push's plumbing, same options and positions) as the push it is, so the push path
|
|
32
|
+
* names each ref it moves. With no ref, send-pack pushes every branch both sides have: read as `--all`, a superset.
|
|
33
|
+
* Any other line is returned as it is.
|
|
34
|
+
*/
|
|
35
|
+
export declare function gitPushArgv(argv: readonly string[]): readonly string[];
|
|
30
36
|
/**
|
|
31
37
|
* Every ref a `git push` moves, one classification each, worst first, with the worst case for what it can't name;
|
|
32
38
|
* null when it isn't a push to GitHub (or is a dry run).
|