passport-bridge 0.48.2 → 0.49.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/cliHookAfter.js +10 -1
- package/dist/cliHookDecide.d.ts +9 -3
- package/dist/cliHookDecide.js +182 -28
- package/dist/cliHookSessionState.d.ts +4 -1
- package/dist/cliHookSessionState.js +1 -1
- package/dist/connectorKit/callEffects.generated.d.ts +36 -0
- package/dist/connectorKit/callEffects.generated.js +73 -0
- package/dist/connectorKit/cli.generated.js +5 -2
- package/dist/connectorKit/engine.generated.d.ts +1 -1
- package/dist/connectorKit/engine.generated.js +32 -13
- package/dist/connectorKit/githubIds.generated.d.ts +1 -1
- package/dist/connectorKit/githubIds.generated.js +3 -2
- package/dist/connectorKit/manifest.generated.d.ts +34 -14
- package/dist/connectorKit/manifests/cloudflare.generated.d.ts +2 -0
- package/dist/connectorKit/manifests/cloudflare.generated.js +186 -0
- package/dist/connectorKit/manifests/cloudflareApi.generated.d.ts +4 -0
- package/dist/connectorKit/manifests/cloudflareApi.generated.js +207 -0
- package/dist/connectorKit/manifests/cloudflareCatalog.generated.d.ts +18 -0
- package/dist/connectorKit/manifests/cloudflareCatalog.generated.js +83 -0
- package/dist/connectorKit/manifests/cloudflareCli.generated.d.ts +2 -0
- package/dist/connectorKit/manifests/cloudflareCli.generated.js +441 -0
- package/dist/connectorKit/manifests/githubCapture.generated.js +19 -1
- package/dist/connectorKit/manifests/githubReads.generated.js +0 -3
- package/dist/connectorKit/manifests/kubernetes.generated.d.ts +76 -0
- package/dist/connectorKit/manifests/kubernetes.generated.js +210 -0
- package/dist/connectorKit/manifests/kubernetesArgs.generated.d.ts +21 -0
- package/dist/connectorKit/manifests/kubernetesArgs.generated.js +82 -0
- package/dist/connectorKit/manifests/kubernetesCli.generated.d.ts +30 -0
- package/dist/connectorKit/manifests/kubernetesCli.generated.js +530 -0
- package/dist/connectorKit/manifests/kubernetesEffects.generated.d.ts +15 -0
- package/dist/connectorKit/manifests/kubernetesEffects.generated.js +111 -0
- package/dist/connectorKit/manifests/kubernetesObjects.generated.d.ts +24 -0
- package/dist/connectorKit/manifests/kubernetesObjects.generated.js +154 -0
- package/dist/connectorKit/manifests/railwayHooks.generated.js +11 -5
- package/dist/connectorKit/manifests/sentry.generated.d.ts +6 -0
- package/dist/connectorKit/manifests/sentry.generated.js +27 -0
- package/dist/connectorKit/manifests/sentryApi.generated.d.ts +6 -0
- package/dist/connectorKit/manifests/sentryApi.generated.js +282 -0
- package/dist/connectorKit/manifests/sentryCapture.generated.d.ts +2 -0
- package/dist/connectorKit/manifests/sentryCapture.generated.js +165 -0
- package/dist/connectorKit/manifests/sentryCatalog.generated.d.ts +5 -0
- package/dist/connectorKit/manifests/sentryCatalog.generated.js +70 -0
- package/dist/connectorKit/manifests/sentryCli.generated.d.ts +2 -0
- package/dist/connectorKit/manifests/sentryCli.generated.js +230 -0
- package/dist/connectorKit/manifests/sentryIssues.generated.d.ts +20 -0
- package/dist/connectorKit/manifests/sentryIssues.generated.js +204 -0
- package/dist/connectorKit/manifests/supabase.generated.js +3 -2
- package/dist/connectorKit/manifests/supabaseApi.generated.js +52 -52
- package/dist/connectorKit/manifests/supabaseCapture.generated.js +22 -21
- package/dist/connectorKit/manifests/supabaseCatalog.generated.d.ts +2 -2
- package/dist/connectorKit/manifests/supabaseCatalog.generated.js +8 -7
- package/dist/connectorKit/manifests/supabaseCli.generated.js +32 -32
- package/dist/connectorKit/manifests/supabaseProbes.generated.js +29 -29
- package/dist/connectorKit/manifests/terraform.generated.d.ts +5 -0
- package/dist/connectorKit/manifests/terraform.generated.js +214 -0
- package/dist/connectorKit/manifests/terraformLink.generated.d.ts +30 -0
- package/dist/connectorKit/manifests/terraformLink.generated.js +73 -0
- package/dist/connectorKit/manifests/terraformPlan.generated.d.ts +48 -0
- package/dist/connectorKit/manifests/terraformPlan.generated.js +192 -0
- package/dist/connectorKit/params.generated.js +2 -0
- package/dist/connectorKit/shell.generated.d.ts +5 -1
- package/dist/connectorKit/shell.generated.js +121 -20
- package/dist/connectorKit/sources/cloudflare/api-operations.generated.d.ts +37 -0
- package/dist/connectorKit/sources/cloudflare/api-operations.generated.js +2 -0
- package/dist/connectorKit/sources/cloudflare/cli-flags.generated.d.ts +617 -0
- package/dist/connectorKit/sources/cloudflare/cli-flags.generated.js +2 -0
- package/dist/connectorKit/sources/cloudflare/mcp-tools.generated.d.ts +16 -0
- package/dist/connectorKit/sources/cloudflare/mcp-tools.generated.js +2 -0
- package/dist/connectorKit/sources/sentry/api-operations.generated.d.ts +121 -0
- package/dist/connectorKit/sources/sentry/api-operations.generated.js +2 -0
- package/dist/connectorKit/sources/sentry/cli-commands.generated.d.ts +530 -0
- package/dist/connectorKit/sources/sentry/cli-commands.generated.js +2 -0
- package/dist/connectorKit/sources/sentry/mcp-tools.generated.d.ts +32 -0
- package/dist/connectorKit/sources/sentry/mcp-tools.generated.js +2 -0
- package/dist/connectorKit/template.generated.d.ts +8 -4
- package/dist/connectorKit/template.generated.js +19 -6
- package/dist/controlPlane.generated.d.ts +11 -2
- package/dist/controlPlaneActions.generated.d.ts +52 -12
- package/dist/controlPlaneActions.generated.js +40 -11
- package/dist/controlPlaneCloudflare.d.ts +70 -0
- package/dist/controlPlaneCloudflare.js +188 -0
- package/dist/controlPlaneKubernetes.d.ts +72 -0
- package/dist/controlPlaneKubernetes.js +260 -0
- package/dist/controlPlaneModel.generated.d.ts +6 -0
- package/dist/controlPlaneNpm.generated.d.ts +83 -0
- package/dist/controlPlaneNpm.generated.js +307 -0
- package/dist/controlPlaneNpmCommands.generated.d.ts +35 -0
- package/dist/controlPlaneNpmCommands.generated.js +567 -0
- package/dist/controlPlaneNpmGuard.d.ts +44 -0
- package/dist/controlPlaneNpmGuard.js +210 -0
- package/dist/controlPlaneOffline.d.ts +1 -1
- package/dist/controlPlaneRailway.generated.js +2 -2
- package/dist/controlPlaneRailwayCli.generated.js +13 -2
- package/dist/controlPlaneRailwayModel.generated.d.ts +5 -0
- package/dist/controlPlaneRailwayModel.generated.js +15 -1
- package/dist/controlPlaneSentry.d.ts +68 -0
- package/dist/controlPlaneSentry.js +205 -0
- package/dist/controlPlaneTerraform.d.ts +86 -0
- package/dist/controlPlaneTerraform.js +273 -0
- package/dist/controlPlaneUnnamed.generated.d.ts +41 -2
- package/dist/controlPlaneUnnamed.generated.js +148 -2
- package/dist/cpCli.d.ts +1 -1
- package/dist/cpCli.js +1 -1
- package/dist/pluginPin.d.ts +1 -1
- package/dist/pluginPin.js +1 -1
- package/dist/terraformPlans.d.ts +45 -0
- package/dist/terraformPlans.js +96 -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
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The control plane for Terraform and OpenTofu on this computer, through the connector kit (2026-11-21;
|
|
3
|
+
* `shared/connectorKit/manifests/terraform.ts`, copied to `connectorKit/` by
|
|
4
|
+
* scripts/generate-control-plane-classifier.mjs). The guard classifies each `terraform` or `tofu` command of a line
|
|
5
|
+
* with the kit's manifest, in the folder it runs in (`cd`, `-chdir`, `bash -c`), on the backend and workspace that
|
|
6
|
+
* folder's `.terraform/` names (`terraformLink.ts`; `TF_WORKSPACE` and an earlier `workspace select` in the same line
|
|
7
|
+
* win), and asks `POST /api/cp/decide` once per command.
|
|
8
|
+
*
|
|
9
|
+
* An apply given a saved plan, or following a `plan -out` this session made in the same folder and workspace, has its
|
|
10
|
+
* plan read here (`terraformPlans.ts`): the summary carries only how many resources it creates, updates, replaces and
|
|
11
|
+
* deletes, and the resource types that touch access or become public. Never a plan's values, an address, a variable,
|
|
12
|
+
* a path or the command line: the masked command keeps only the program, its command words and its flags' names.
|
|
13
|
+
* Terraform needs no App setup, so every workspace asks.
|
|
14
|
+
*/
|
|
15
|
+
import type { Classification } from "./controlPlane.generated.js";
|
|
16
|
+
import { type Guard } from "./connectorKit/shell.generated.js";
|
|
17
|
+
import { type CpAnswer } from "./controlPlaneGuard.js";
|
|
18
|
+
import type { SessionState } from "./cliHookSessionState.js";
|
|
19
|
+
import { type PlanReader } from "./terraformPlans.js";
|
|
20
|
+
type ApiCall = (path: string, init: RequestInit) => Promise<Response>;
|
|
21
|
+
/** At most this many Terraform commands in one line are asked about; a line doing more is refused. */
|
|
22
|
+
export declare const MAX_TERRAFORM_COMMANDS = 8;
|
|
23
|
+
export declare const TOO_MANY_TERRAFORM = "Blocked by Passport: this line runs more than 8 Terraform commands. Split it up so each can be checked.";
|
|
24
|
+
export type TerraformWhere = {
|
|
25
|
+
cwd?: string | null;
|
|
26
|
+
env: Record<string, string | undefined>;
|
|
27
|
+
};
|
|
28
|
+
/** One command's decide: its action, the production hint, and its masked command. */
|
|
29
|
+
export type TerraformAsk = {
|
|
30
|
+
found: Classification;
|
|
31
|
+
production: boolean;
|
|
32
|
+
command?: string;
|
|
33
|
+
};
|
|
34
|
+
/** What the kit's resolver may read here: the folder, `TF_WORKSPACE`, and the two files under `.terraform/`. */
|
|
35
|
+
export declare function terraformGuard(where: TerraformWhere, read?: (path: string) => string | undefined): Guard;
|
|
36
|
+
/** The masked command: the program, the command words, each flag's name (`-var=…`); every value and argument `…`. */
|
|
37
|
+
export declare function maskTerraform(argv: readonly string[]): string | undefined;
|
|
38
|
+
export type TerraformLineOptions = {
|
|
39
|
+
state?: SessionState;
|
|
40
|
+
now?: number;
|
|
41
|
+
/** Time left for reading plans (the guard's budget); 0 reads only remembered ones. */
|
|
42
|
+
planMs?: number;
|
|
43
|
+
reader?: PlanReader;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* What a line's Terraform commands do: one decide each, with its plan read when there is one. Returns the session's
|
|
47
|
+
* state with each `plan -out` of the line remembered (its file is read once it exists, by the after-hook).
|
|
48
|
+
*/
|
|
49
|
+
export declare function classifyTerraformLine(command: string, where: TerraformWhere, options?: TerraformLineOptions): Promise<{
|
|
50
|
+
asks: TerraformAsk[];
|
|
51
|
+
state: SessionState;
|
|
52
|
+
}>;
|
|
53
|
+
/** The after-hook: each `plan -out` of a line that ran, read now and remembered, so the apply that follows reads it
|
|
54
|
+
* at once. */
|
|
55
|
+
export declare function rememberTerraformPlans(command: string, where: TerraformWhere, state: SessionState, options?: {
|
|
56
|
+
reader?: PlanReader;
|
|
57
|
+
timeoutMs?: number;
|
|
58
|
+
}): Promise<SessionState>;
|
|
59
|
+
/** What a line's Terraform commands do, classified locally (for when Passport can't be reached). */
|
|
60
|
+
export declare function terraformFound(command: string, where: TerraformWhere): Promise<{
|
|
61
|
+
platform: "terraform";
|
|
62
|
+
nodeId: string;
|
|
63
|
+
actionKey: string;
|
|
64
|
+
summary: string;
|
|
65
|
+
}[]>;
|
|
66
|
+
/** The decide request for one command. Only the classification leaves: nodes, the action, its summary, the hint. */
|
|
67
|
+
export declare function terraformDecideBody(ask: TerraformAsk, extra: {
|
|
68
|
+
sessionId?: string;
|
|
69
|
+
}): Record<string, unknown>;
|
|
70
|
+
/** Ask about one command under a new request id. A server that doesn't decide Terraform answers 400: undecided. */
|
|
71
|
+
export declare function askTerraform(api: ApiCall, ask: TerraformAsk, extra: {
|
|
72
|
+
sessionId?: string;
|
|
73
|
+
}, signal: AbortSignal): Promise<CpAnswer>;
|
|
74
|
+
export type TerraformLinePlan = {
|
|
75
|
+
answer: CpAnswer;
|
|
76
|
+
label: string;
|
|
77
|
+
};
|
|
78
|
+
/** The guard's question for a line's Terraform commands: the worst answer of its decides. */
|
|
79
|
+
export declare function terraformLinePlan(command: string, where: TerraformWhere, open: () => Promise<ApiCall | null>, extra: {
|
|
80
|
+
sessionId?: string;
|
|
81
|
+
}, signal: AbortSignal, session: {
|
|
82
|
+
state: SessionState;
|
|
83
|
+
planMs: number;
|
|
84
|
+
save: (state: SessionState) => void;
|
|
85
|
+
}): Promise<TerraformLinePlan | null>;
|
|
86
|
+
export {};
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The control plane for Terraform and OpenTofu on this computer, through the connector kit (2026-11-21;
|
|
3
|
+
* `shared/connectorKit/manifests/terraform.ts`, copied to `connectorKit/` by
|
|
4
|
+
* scripts/generate-control-plane-classifier.mjs). The guard classifies each `terraform` or `tofu` command of a line
|
|
5
|
+
* with the kit's manifest, in the folder it runs in (`cd`, `-chdir`, `bash -c`), on the backend and workspace that
|
|
6
|
+
* folder's `.terraform/` names (`terraformLink.ts`; `TF_WORKSPACE` and an earlier `workspace select` in the same line
|
|
7
|
+
* win), and asks `POST /api/cp/decide` once per command.
|
|
8
|
+
*
|
|
9
|
+
* An apply given a saved plan, or following a `plan -out` this session made in the same folder and workspace, has its
|
|
10
|
+
* plan read here (`terraformPlans.ts`): the summary carries only how many resources it creates, updates, replaces and
|
|
11
|
+
* deletes, and the resource types that touch access or become public. Never a plan's values, an address, a variable,
|
|
12
|
+
* a path or the command line: the masked command keeps only the program, its command words and its flags' names.
|
|
13
|
+
* Terraform needs no App setup, so every workspace asks.
|
|
14
|
+
*/
|
|
15
|
+
import { readFileSync, statSync } from "node:fs";
|
|
16
|
+
import { join } from "node:path";
|
|
17
|
+
import { explain, normalize } from "./connectorKit/engine.generated.js";
|
|
18
|
+
import { programName } from "./connectorKit/cli.generated.js";
|
|
19
|
+
import { TERRAFORM } from "./connectorKit/manifests/terraform.generated.js";
|
|
20
|
+
import { productionHint, terraformLink } from "./connectorKit/manifests/terraformLink.generated.js";
|
|
21
|
+
import { APPLY_KEY, DESTROY_KEY, finishTerraform } from "./connectorKit/manifests/terraformPlan.generated.js";
|
|
22
|
+
import { joinPath, resolveCommand } from "./connectorKit/shell.generated.js";
|
|
23
|
+
import { CP_DECIDE_PATH, CP_DECIDE_TIMEOUT_MS, worstAnswer } from "./controlPlaneGuard.js";
|
|
24
|
+
import { newRequestId } from "./controlPlaneLate.js";
|
|
25
|
+
import { NO_ANSWER_STATUSES, noAnswer, refusalOf } from "./cpRefusal.js";
|
|
26
|
+
import { readBoundedJson } from "./boundedResponse.js";
|
|
27
|
+
import { lastPlan, readPlan, remember, showJson, PLAN_READ_MS, absolutePlan } from "./terraformPlans.js";
|
|
28
|
+
/** At most this many Terraform commands in one line are asked about; a line doing more is refused. */
|
|
29
|
+
export const MAX_TERRAFORM_COMMANDS = 8;
|
|
30
|
+
export const TOO_MANY_TERRAFORM = `Blocked by Passport: this line runs more than ${MAX_TERRAFORM_COMMANDS} Terraform commands. Split it up so each can be checked.`;
|
|
31
|
+
const MAX_SUMMARY = 200;
|
|
32
|
+
/** `.terraform/terraform.tfstate` holds the backend's settings; anything bigger isn't read. */
|
|
33
|
+
const MAX_LINK_BYTES = 64 * 1024;
|
|
34
|
+
const PROGRAMS = TERRAFORM.capture.cli.programs;
|
|
35
|
+
function readSmall(path, max = MAX_LINK_BYTES) {
|
|
36
|
+
try {
|
|
37
|
+
if (statSync(path).size > max)
|
|
38
|
+
return undefined;
|
|
39
|
+
return readFileSync(path, "utf8");
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/** What the kit's resolver may read here: the folder, `TF_WORKSPACE`, and the two files under `.terraform/`. */
|
|
46
|
+
export function terraformGuard(where, read = readSmall) {
|
|
47
|
+
const env = Object.fromEntries(Object.entries(where.env).filter((entry) => typeof entry[1] === "string"));
|
|
48
|
+
return {
|
|
49
|
+
cwd: where.cwd || process.cwd(),
|
|
50
|
+
env,
|
|
51
|
+
readFile: read,
|
|
52
|
+
readLink: (folder) => ({
|
|
53
|
+
...terraformLink({
|
|
54
|
+
folder,
|
|
55
|
+
backendFile: read(join(folder, ".terraform", "terraform.tfstate")),
|
|
56
|
+
environmentFile: read(join(folder, ".terraform", "environment"))
|
|
57
|
+
})
|
|
58
|
+
})
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/** The masked command: the program, the command words, each flag's name (`-var=…`); every value and argument `…`. */
|
|
62
|
+
export function maskTerraform(argv) {
|
|
63
|
+
const start = argv.findIndex((word) => PROGRAMS.includes(programName(word)));
|
|
64
|
+
if (start < 0)
|
|
65
|
+
return undefined;
|
|
66
|
+
const flags = new Map([...TERRAFORM.capture.cli.flags.global, ...Object.values(TERRAFORM.capture.cli.flags.commands).flat()].map((spec) => [spec.long, spec.value]));
|
|
67
|
+
const words = new Set(Object.keys({ ...TERRAFORM.capture.cli.flags.commands, ...TERRAFORM.capture.cli.reads }).flatMap((op) => op.split(" ")));
|
|
68
|
+
const out = [programName(argv[start])];
|
|
69
|
+
let commandWords = 0;
|
|
70
|
+
let argument = false;
|
|
71
|
+
for (let i = start + 1; i < argv.length; i++) {
|
|
72
|
+
const word = argv[i];
|
|
73
|
+
const flag = /^--?([a-z][a-z0-9-]{0,40})(=.*)?$/s.exec(word);
|
|
74
|
+
if (flag) {
|
|
75
|
+
const takes = flags.get(flag[1]);
|
|
76
|
+
out.push(`-${flag[1]}${flag[2] !== undefined ? "=…" : ""}`);
|
|
77
|
+
if (flag[2] === undefined && takes === "required") {
|
|
78
|
+
if (i + 1 < argv.length)
|
|
79
|
+
out.push("…");
|
|
80
|
+
i += 1;
|
|
81
|
+
}
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
// Command words only while they lead (`state rm`), never an argument that happens to match one.
|
|
85
|
+
if (commandWords < 2 && !argument && words.has(word)) {
|
|
86
|
+
out.push(word);
|
|
87
|
+
commandWords += 1;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
out.push("…");
|
|
91
|
+
argument = true;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return out.join(" ").slice(0, 260);
|
|
95
|
+
}
|
|
96
|
+
/** Each command of a line in order, an earlier `workspace select` or `workspace new` moving the later ones of the same
|
|
97
|
+
* folder to that workspace (Terraform switches as it goes; the kit's resolver reads the folder as it was). */
|
|
98
|
+
function inOrder(resolved, cwd) {
|
|
99
|
+
const switched = new Map();
|
|
100
|
+
return resolved.map((entry) => {
|
|
101
|
+
const n = normalize(TERRAFORM, entry.request);
|
|
102
|
+
const base = entry.context.linked ?? {};
|
|
103
|
+
const folder = n?.folder ? joinPath(cwd, n.folder) : cwd;
|
|
104
|
+
const workspace = switched.get(folder);
|
|
105
|
+
const linked = workspace ? { ...base, workspace } : base;
|
|
106
|
+
const linkedOf = entry.context.linkOf;
|
|
107
|
+
const context = {
|
|
108
|
+
...entry.context,
|
|
109
|
+
...(Object.keys(linked).length ? { linked } : {}),
|
|
110
|
+
...(linkedOf && workspace ? { linkOf: (other) => ({ ...linkedOf(other), workspace }) } : {})
|
|
111
|
+
};
|
|
112
|
+
if (n && (n.op === "workspace select" || n.op === "workspace new") && typeof n.params.$1 === "string")
|
|
113
|
+
switched.set(folder, n.params.$1);
|
|
114
|
+
return { ...entry, context, folder };
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
/** Where each request's plan comes from: the saved plan it names, else (an apply) the session's last one here. */
|
|
118
|
+
function planWanted(found, params, state, where) {
|
|
119
|
+
if (found.actionKey !== APPLY_KEY && found.actionKey !== DESTROY_KEY)
|
|
120
|
+
return null;
|
|
121
|
+
if (typeof params.plan === "string")
|
|
122
|
+
return { path: params.plan, from: "saved" };
|
|
123
|
+
if (found.actionKey !== APPLY_KEY)
|
|
124
|
+
return null;
|
|
125
|
+
const last = lastPlan(state, where.folder, where.workspace, where.now);
|
|
126
|
+
return last ? { path: last.path, from: "last" } : null;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* What a line's Terraform commands do: one decide each, with its plan read when there is one. Returns the session's
|
|
130
|
+
* state with each `plan -out` of the line remembered (its file is read once it exists, by the after-hook).
|
|
131
|
+
*/
|
|
132
|
+
export async function classifyTerraformLine(command, where, options = {}) {
|
|
133
|
+
const guard = terraformGuard(where);
|
|
134
|
+
const now = options.now ?? Date.now();
|
|
135
|
+
let state = options.state ?? {};
|
|
136
|
+
const asks = [];
|
|
137
|
+
const started = Date.now();
|
|
138
|
+
for (const entry of inOrder(resolveCommand(TERRAFORM, command, guard), guard.cwd)) {
|
|
139
|
+
const request = entry.request;
|
|
140
|
+
const n = normalize(TERRAFORM, request);
|
|
141
|
+
const params = n?.params ?? {};
|
|
142
|
+
const workspace = entry.context.linked?.workspace ?? "default";
|
|
143
|
+
const program = PROGRAMS.find((name) => request.argv.some((word) => programName(word) === name)) ?? "terraform";
|
|
144
|
+
if (n?.op === "plan" && typeof params.out === "string" && !n.problem)
|
|
145
|
+
state = remember(state, {
|
|
146
|
+
folder: entry.folder,
|
|
147
|
+
workspace,
|
|
148
|
+
path: absolutePlan(entry.folder, params.out),
|
|
149
|
+
at: now
|
|
150
|
+
});
|
|
151
|
+
const found = explain(TERRAFORM, request, entry.context).found;
|
|
152
|
+
for (const one of found) {
|
|
153
|
+
const wanted = planWanted(one, { ...params, plan: params.$1 }, state, { folder: entry.folder, workspace, now });
|
|
154
|
+
let plan = null;
|
|
155
|
+
if (wanted) {
|
|
156
|
+
const left = Math.max(0, (options.planMs ?? PLAN_READ_MS) - (Date.now() - started));
|
|
157
|
+
const read = await readPlan(state, { program, folder: entry.folder, workspace, path: wanted.path, timeoutMs: Math.min(left, PLAN_READ_MS) }, options.reader ?? showJson);
|
|
158
|
+
if (read) {
|
|
159
|
+
plan = { plan: read.plan, from: wanted.from };
|
|
160
|
+
state = remember(state, read.memo);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
const varFiles = []
|
|
164
|
+
.concat(params["var-file"] ?? [])
|
|
165
|
+
.filter((v) => typeof v === "string");
|
|
166
|
+
const command = maskTerraform(request.argv);
|
|
167
|
+
asks.push({
|
|
168
|
+
found: finishTerraform(one, { params, plan }),
|
|
169
|
+
production: productionHint(entry.folder, varFiles),
|
|
170
|
+
...(command ? { command } : {})
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return { asks, state };
|
|
175
|
+
}
|
|
176
|
+
/** The after-hook: each `plan -out` of a line that ran, read now and remembered, so the apply that follows reads it
|
|
177
|
+
* at once. */
|
|
178
|
+
export async function rememberTerraformPlans(command, where, state, options = {}) {
|
|
179
|
+
const guard = terraformGuard(where);
|
|
180
|
+
let next = state;
|
|
181
|
+
for (const entry of inOrder(resolveCommand(TERRAFORM, command, guard), guard.cwd)) {
|
|
182
|
+
const request = entry.request;
|
|
183
|
+
const n = normalize(TERRAFORM, request);
|
|
184
|
+
if (n?.op !== "plan" || typeof n.params.out !== "string" || n.problem)
|
|
185
|
+
continue;
|
|
186
|
+
const program = PROGRAMS.find((name) => request.argv.some((word) => programName(word) === name)) ?? "terraform";
|
|
187
|
+
const workspace = entry.context.linked?.workspace ?? "default";
|
|
188
|
+
const read = await readPlan(next, { program, folder: entry.folder, workspace, path: n.params.out, timeoutMs: options.timeoutMs ?? 1_200 }, options.reader ?? showJson);
|
|
189
|
+
if (read)
|
|
190
|
+
next = remember(next, read.memo);
|
|
191
|
+
}
|
|
192
|
+
return next;
|
|
193
|
+
}
|
|
194
|
+
/** What a line's Terraform commands do, classified locally (for when Passport can't be reached). */
|
|
195
|
+
export async function terraformFound(command, where) {
|
|
196
|
+
const { asks } = await classifyTerraformLine(command, where, { planMs: 0 });
|
|
197
|
+
return asks.map(({ found }) => ({
|
|
198
|
+
platform: "terraform",
|
|
199
|
+
nodeId: found.nodeId,
|
|
200
|
+
actionKey: found.actionKey,
|
|
201
|
+
summary: found.summary.slice(0, MAX_SUMMARY)
|
|
202
|
+
}));
|
|
203
|
+
}
|
|
204
|
+
/** The decide request for one command. Only the classification leaves: nodes, the action, its summary, the hint. */
|
|
205
|
+
export function terraformDecideBody(ask, extra) {
|
|
206
|
+
const { found } = ask;
|
|
207
|
+
return {
|
|
208
|
+
nodeId: found.nodeId,
|
|
209
|
+
actionKey: found.actionKey,
|
|
210
|
+
summary: found.summary.slice(0, MAX_SUMMARY),
|
|
211
|
+
...(found.nodes?.length ? { nodes: found.nodes } : {}),
|
|
212
|
+
...(found.unnamed ? { unnamed: found.unnamed } : {}),
|
|
213
|
+
...(ask.production ? { production: true } : {}),
|
|
214
|
+
interface: "cli",
|
|
215
|
+
platform: "terraform",
|
|
216
|
+
credential: "own",
|
|
217
|
+
...(ask.command ? { command: ask.command } : {}),
|
|
218
|
+
...(extra.sessionId && /^[A-Za-z0-9._:-]{1,128}$/.test(extra.sessionId) ? { sessionId: extra.sessionId } : {})
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
/** Ask about one command under a new request id. A server that doesn't decide Terraform answers 400: undecided. */
|
|
222
|
+
export async function askTerraform(api, ask, extra, signal) {
|
|
223
|
+
const requestId = newRequestId();
|
|
224
|
+
const unreachable = { kind: "unreachable", late: [requestId] };
|
|
225
|
+
let response;
|
|
226
|
+
try {
|
|
227
|
+
response = await api(CP_DECIDE_PATH, {
|
|
228
|
+
method: "POST",
|
|
229
|
+
headers: { "content-type": "application/json" },
|
|
230
|
+
body: JSON.stringify({ ...terraformDecideBody(ask, extra), requestId }),
|
|
231
|
+
signal: AbortSignal.any([signal, AbortSignal.timeout(CP_DECIDE_TIMEOUT_MS)])
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
catch {
|
|
235
|
+
return unreachable;
|
|
236
|
+
}
|
|
237
|
+
if (response.status >= 500)
|
|
238
|
+
return unreachable;
|
|
239
|
+
if (NO_ANSWER_STATUSES.has(response.status))
|
|
240
|
+
return noAnswer(response, unreachable);
|
|
241
|
+
if (!response.ok) {
|
|
242
|
+
await response.body?.cancel().catch(() => undefined);
|
|
243
|
+
return { kind: "undecided" };
|
|
244
|
+
}
|
|
245
|
+
let body;
|
|
246
|
+
try {
|
|
247
|
+
body = await readBoundedJson(response);
|
|
248
|
+
}
|
|
249
|
+
catch {
|
|
250
|
+
return unreachable;
|
|
251
|
+
}
|
|
252
|
+
if (body.allow === true)
|
|
253
|
+
return { kind: "allow", eventId: typeof body.eventId === "string" ? body.eventId : null };
|
|
254
|
+
return refusalOf(body) ?? { kind: "undecided" };
|
|
255
|
+
}
|
|
256
|
+
/** The guard's question for a line's Terraform commands: the worst answer of its decides. */
|
|
257
|
+
export async function terraformLinePlan(command, where, open, extra, signal, session) {
|
|
258
|
+
const { asks, state } = await classifyTerraformLine(command, where, { state: session.state, planMs: session.planMs });
|
|
259
|
+
if (state !== session.state)
|
|
260
|
+
session.save(state);
|
|
261
|
+
if (!asks.length)
|
|
262
|
+
return null;
|
|
263
|
+
if (asks.length > MAX_TERRAFORM_COMMANDS)
|
|
264
|
+
return { answer: { kind: "block", message: TOO_MANY_TERRAFORM }, label: asks[0].found.summary };
|
|
265
|
+
const api = await open();
|
|
266
|
+
if (!api)
|
|
267
|
+
return null;
|
|
268
|
+
const answers = await Promise.all(asks.map((ask) => askTerraform(api, ask, extra, signal)));
|
|
269
|
+
return {
|
|
270
|
+
answer: worstAnswer(answers) ?? answers.at(-1) ?? { kind: "allow", eventId: null },
|
|
271
|
+
label: asks[0].found.summary
|
|
272
|
+
};
|
|
273
|
+
}
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
/**
|
|
8
8
|
* What an action Passport can't name hit, so the next one to name is known (2026-11-17): an API call's method and
|
|
9
9
|
* path template (`repos/{owner}/{repo}/actions/runs/{id}/cancel`), or a command line's program and subcommand words
|
|
10
|
-
* (`gh run watch`). Never an owner, repository, number, id, branch, query
|
|
10
|
+
* (`gh run watch`), or an MCP tool's name (`update_issue`). Never an owner, repository, number, id, branch, query
|
|
11
|
+
* string, body, flag or argument.
|
|
11
12
|
*/
|
|
12
13
|
export type UnnamedHit = {
|
|
13
14
|
via: "api";
|
|
@@ -16,6 +17,11 @@ export type UnnamedHit = {
|
|
|
16
17
|
} | {
|
|
17
18
|
via: "cli";
|
|
18
19
|
command: string;
|
|
20
|
+
}
|
|
21
|
+
/** An MCP tool the manifest doesn't name: the tool's own name (its vendor's vocabulary), never its arguments. */
|
|
22
|
+
| {
|
|
23
|
+
via: "mcp";
|
|
24
|
+
tool: string;
|
|
19
25
|
};
|
|
20
26
|
/** An app's action Passport can't name (`github.unclassified`). */
|
|
21
27
|
export declare const isUnclassifiedAction: (actionKey: string) => boolean;
|
|
@@ -30,6 +36,10 @@ export declare const UNNAMED_METHODS: readonly string[];
|
|
|
30
36
|
export declare const GITHUB_PATH_WORDS: ReadonlySet<string>;
|
|
31
37
|
/** Supabase's Management API path words (api.supabase.com/v1). */
|
|
32
38
|
export declare const SUPABASE_PATH_WORDS: ReadonlySet<string>;
|
|
39
|
+
/** Sentry's REST API path words (sentry.io/api/0). */
|
|
40
|
+
export declare const SENTRY_PATH_WORDS: ReadonlySet<string>;
|
|
41
|
+
/** Cloudflare API v4's path words (api.cloudflare.com/client/v4). */
|
|
42
|
+
export declare const CLOUDFLARE_PATH_WORDS: ReadonlySet<string>;
|
|
33
43
|
/** Railway is GraphQL: its path is one word. */
|
|
34
44
|
export declare const RAILWAY_PATH_WORDS: ReadonlySet<string>;
|
|
35
45
|
export declare function pathWordsFor(platform: string): ReadonlySet<string>;
|
|
@@ -40,14 +50,34 @@ export declare function pathWordsFor(platform: string): ReadonlySet<string>;
|
|
|
40
50
|
* `{branch}` after `branches`, `{sha}` for a commit hash, else `{id}`), a run of them collapsed into one.
|
|
41
51
|
*/
|
|
42
52
|
export declare function templatePath(raw: string, known: ReadonlySet<string>): string;
|
|
53
|
+
/** Programs whose own command words Passport knows (`unnamedCommand` keeps only those), so a hit may name a command
|
|
54
|
+
* the manifest doesn't. */
|
|
55
|
+
export declare const knowsCommandWords: (program: string) => program is "git" | "gh" | "wrangler";
|
|
43
56
|
/**
|
|
44
57
|
* A command line as its program and at most two subcommand words: each a CLI word (`^[a-z][a-z-]{0,30}$`) and, for
|
|
45
58
|
* `gh` and `git`, one that CLI has, so a positional argument (a branch, a remote, a repository, a number) never
|
|
46
|
-
* passes as a subcommand. Flags end it. Null when the program itself isn't a plain name.
|
|
59
|
+
* passes as a subcommand (`npm`, `pnpm` and `yarn` keep one word). Flags end it. Null when the program itself isn't a plain name.
|
|
47
60
|
*/
|
|
48
61
|
export declare function unnamedCommand(argv: readonly string[]): string | null;
|
|
49
62
|
/** An API call's hit: its method (one of the HTTP methods) and its path's template; either may be unknown. */
|
|
50
63
|
export declare function unnamedApi(platform: string, method: string | undefined, path?: string): UnnamedHit;
|
|
64
|
+
/** An MCP tool's hit: its name, when it reads as a tool name; undefined otherwise. */
|
|
65
|
+
export declare function unnamedMcp(tool: string): UnnamedHit | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* What an action Passport can't name says, in one shape for every app (2026-11-21), present tense as summaries are
|
|
68
|
+
* (Activity says it in the past, `pastUnnamed`): "Run a gh command Passport can't name in acme/api", "Run a wrangler
|
|
69
|
+
* command Passport can't name: containers delete", "Call a Cloudflare API route Passport can't name: DELETE
|
|
70
|
+
* zones/{id}/load_balancers/{id}", "Use a Cloudflare tool Passport can't name: workers_delete_all". Only the hit's
|
|
71
|
+
* coarse words: never an argument, id or value.
|
|
72
|
+
*/
|
|
73
|
+
export declare function unnamedSummary(app: string, hit: UnnamedHit | undefined, options?: {
|
|
74
|
+
program?: string;
|
|
75
|
+
tool?: string;
|
|
76
|
+
where?: string;
|
|
77
|
+
}): string;
|
|
78
|
+
/** An unnamed action's summary in the past tense, for Activity: "Ran a wrangler command Passport can't name: …". Null
|
|
79
|
+
* for a summary not in `unnamedSummary`'s shape. */
|
|
80
|
+
export declare function pastUnnamed(summary: string): string | null;
|
|
51
81
|
/** A command line's hit; undefined when nothing of it can be kept. */
|
|
52
82
|
export declare function unnamedCli(argv: readonly string[]): UnnamedHit | undefined;
|
|
53
83
|
/** Maximum length of a masked CLI invocation stored on an event and shown in the sidebar. */
|
|
@@ -67,3 +97,12 @@ export declare function sanitizeMaskedCommand(value: unknown): string | undefine
|
|
|
67
97
|
* dropped, never refused.
|
|
68
98
|
*/
|
|
69
99
|
export declare function sanitizeUnnamed(platform: string, value: unknown): UnnamedHit | undefined;
|
|
100
|
+
/**
|
|
101
|
+
* What an unnamed call hit, from its masked command line (`maskCommandArgv`) when the client sent no hit of its own
|
|
102
|
+
* (an older CLI, a decision rebuilt after it was late): `gh api`'s method and path template (POST when it sends a
|
|
103
|
+
* body, as gh does; GET otherwise), else the program and subcommand words. Undefined when nothing can be kept.
|
|
104
|
+
*/
|
|
105
|
+
export declare function unnamedFromCommand(platform: string, command: string | undefined): UnnamedHit | undefined;
|
|
106
|
+
/** The hit an event records: the client's when it says where (a path, a subcommand), else the one its masked command
|
|
107
|
+
* gives, else whatever the client sent (a method alone). */
|
|
108
|
+
export declare function unnamedHitOf(platform: string, sent: UnnamedHit | undefined, command: string | undefined): UnnamedHit | undefined;
|
|
@@ -39,6 +39,24 @@ export const SUPABASE_PATH_WORDS = words(`
|
|
|
39
39
|
vanity-subdomain restore pause unpause upgrade readonly health types typescript snippets sso providers
|
|
40
40
|
third-party-auth signing-keys billing addons apply push reset merge backups pitr settings members
|
|
41
41
|
`);
|
|
42
|
+
/** Sentry's REST API path words (sentry.io/api/0). */
|
|
43
|
+
export const SENTRY_PATH_WORDS = words(`
|
|
44
|
+
api 0 organizations projects teams issues events comments members org-auth-tokens integrations releases deploys
|
|
45
|
+
files assemble chunk-upload artifactbundle monitors detectors workflows alert-rules rules snooze dashboards keys
|
|
46
|
+
hooks environments spike-protections notifications actions forwarding repos code-mappings ownership codeowners
|
|
47
|
+
filters custom-inbound-filters symbol-sources replays user-feedback discover saved external-users external-teams
|
|
48
|
+
scim v2 Users Groups sentry-apps sentry-app-installations stats_v2 tags attachments autofix
|
|
49
|
+
`);
|
|
50
|
+
/** Cloudflare API v4's path words (api.cloudflare.com/client/v4). */
|
|
51
|
+
export const CLOUDFLARE_PATH_WORDS = words(`
|
|
52
|
+
client v4 accounts zones user tokens members roles settings purge_cache dns_records batch import export rulesets
|
|
53
|
+
rules phases entrypoint firewall access_rules workers scripts content v2 schedules subdomain secrets deployments
|
|
54
|
+
versions tails routes domains r2 buckets managed custom cors lifecycle storage kv namespaces keys values bulk
|
|
55
|
+
delete get d1 database query raw time_travel bookmark restore pages projects retry rollback purge_build_cache
|
|
56
|
+
queues purge consumers value verify permission_groups hyperdrive configs vectorize indexes ai email routing
|
|
57
|
+
load_balancers pools monitors certificates ssl custom_hostnames page_rules waiting_rooms logpush jobs
|
|
58
|
+
access apps policies groups gateway tunnels cfd_tunnel images stream
|
|
59
|
+
`);
|
|
42
60
|
/** Railway is GraphQL: its path is one word. */
|
|
43
61
|
export const RAILWAY_PATH_WORDS = words("graphql v2");
|
|
44
62
|
export function pathWordsFor(platform) {
|
|
@@ -48,6 +66,10 @@ export function pathWordsFor(platform) {
|
|
|
48
66
|
return SUPABASE_PATH_WORDS;
|
|
49
67
|
if (platform === "railway")
|
|
50
68
|
return RAILWAY_PATH_WORDS;
|
|
69
|
+
if (platform === "sentry")
|
|
70
|
+
return SENTRY_PATH_WORDS;
|
|
71
|
+
if (platform === "cloudflare")
|
|
72
|
+
return CLOUDFLARE_PATH_WORDS;
|
|
51
73
|
return new Set();
|
|
52
74
|
}
|
|
53
75
|
/** A root word whose next segments are names, in order: `repos/{owner}/{repo}`. */
|
|
@@ -156,18 +178,32 @@ const GH_COMMANDS = Object.fromEntries(Object.entries({
|
|
|
156
178
|
variable: "delete get list set",
|
|
157
179
|
workflow: "disable enable list run view"
|
|
158
180
|
}).map(([group, subs]) => [group, words(subs)]));
|
|
181
|
+
/** Wrangler's command words (4.x), so a name or a path given as an argument never passes as a subcommand. */
|
|
182
|
+
const WRANGLER_WORDS = words(`
|
|
183
|
+
deploy delete rollback versions deployments triggers secret tail dev whoami login logout types init docs check build
|
|
184
|
+
kv namespace key bulk r2 bucket object d1 pages queues vectorize hyperdrive workflows ai pipelines containers
|
|
185
|
+
dispatch-namespace mtls-certificate cert secrets-store cloudchamber telemetry setup complete upload view list
|
|
186
|
+
status put get create rename info execute export migrations apply time-travel restore project deployment functions
|
|
187
|
+
consumer add remove update purge pause-delivery resume-delivery dev-url enable disable domain cors lifecycle lock
|
|
188
|
+
sippy notification catalog models instances trigger describe insert query start
|
|
189
|
+
`);
|
|
159
190
|
/** Git's own commands; git takes one word. */
|
|
160
191
|
const GIT_COMMANDS = words(`
|
|
161
192
|
add am apply archive bisect blame branch bundle checkout cherry-pick clean clone commit config describe diff fetch
|
|
162
193
|
format-patch gc grep init log ls-files ls-remote merge mv notes pull push range-diff rebase reflog remote reset
|
|
163
194
|
restore revert rm shortlog show sparse-checkout stash status submodule switch tag worktree
|
|
164
195
|
`);
|
|
196
|
+
/** Programs whose own command words Passport knows (`unnamedCommand` keeps only those), so a hit may name a command
|
|
197
|
+
* the manifest doesn't. */
|
|
198
|
+
export const knowsCommandWords = (program) => program === "gh" || program === "git" || program === "wrangler";
|
|
199
|
+
/** The npm family: one subcommand word, never what follows it. */
|
|
200
|
+
const NPM_FAMILY = new Set(["npm", "pnpm", "yarn"]);
|
|
165
201
|
/** A program's name from its path: `/usr/bin/gh.exe` is `gh`. */
|
|
166
202
|
const programName = (argv0) => (argv0 ?? "").replace(/^.*[\\/]/, "").replace(/\.exe$/i, "");
|
|
167
203
|
/**
|
|
168
204
|
* A command line as its program and at most two subcommand words: each a CLI word (`^[a-z][a-z-]{0,30}$`) and, for
|
|
169
205
|
* `gh` and `git`, one that CLI has, so a positional argument (a branch, a remote, a repository, a number) never
|
|
170
|
-
* passes as a subcommand. Flags end it. Null when the program itself isn't a plain name.
|
|
206
|
+
* passes as a subcommand (`npm`, `pnpm` and `yarn` keep one word). Flags end it. Null when the program itself isn't a plain name.
|
|
171
207
|
*/
|
|
172
208
|
export function unnamedCommand(argv) {
|
|
173
209
|
const program = programName(argv[0]);
|
|
@@ -180,6 +216,11 @@ export function unnamedCommand(argv) {
|
|
|
180
216
|
break;
|
|
181
217
|
if (program === "git" && (out.length > 1 || !GIT_COMMANDS.has(word)))
|
|
182
218
|
break;
|
|
219
|
+
if (program === "wrangler" && !WRANGLER_WORDS.has(word))
|
|
220
|
+
break;
|
|
221
|
+
// npm, pnpm and yarn: the subcommand alone; a second word is a package, a user or a tag.
|
|
222
|
+
if (NPM_FAMILY.has(program) && out.length > 1)
|
|
223
|
+
break;
|
|
183
224
|
if (program === "gh") {
|
|
184
225
|
const group = out.length === 1 ? GH_COMMANDS[word] : GH_COMMANDS[out[1]];
|
|
185
226
|
if (out.length === 1 ? !Object.prototype.hasOwnProperty.call(GH_COMMANDS, word) : !group?.has(word))
|
|
@@ -199,6 +240,42 @@ export function unnamedApi(platform, method, path) {
|
|
|
199
240
|
...(template ? { path: template } : {})
|
|
200
241
|
};
|
|
201
242
|
}
|
|
243
|
+
/** An MCP tool's name as an MCP server spells one (`update_issue`, `delete-alert`). */
|
|
244
|
+
const TOOL_WORD = /^[a-z][a-z0-9_-]{0,63}$/;
|
|
245
|
+
/** An MCP tool's hit: its name, when it reads as a tool name; undefined otherwise. */
|
|
246
|
+
export function unnamedMcp(tool) {
|
|
247
|
+
return TOOL_WORD.test(tool) ? { via: "mcp", tool } : undefined;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* What an action Passport can't name says, in one shape for every app (2026-11-21), present tense as summaries are
|
|
251
|
+
* (Activity says it in the past, `pastUnnamed`): "Run a gh command Passport can't name in acme/api", "Run a wrangler
|
|
252
|
+
* command Passport can't name: containers delete", "Call a Cloudflare API route Passport can't name: DELETE
|
|
253
|
+
* zones/{id}/load_balancers/{id}", "Use a Cloudflare tool Passport can't name: workers_delete_all". Only the hit's
|
|
254
|
+
* coarse words: never an argument, id or value.
|
|
255
|
+
*/
|
|
256
|
+
export function unnamedSummary(app, hit, options = {}) {
|
|
257
|
+
const where = options.where ? ` in ${options.where}` : "";
|
|
258
|
+
if (hit?.via === "api") {
|
|
259
|
+
const call = [hit.method, hit.path].filter(Boolean).join(" ");
|
|
260
|
+
return `Call a ${app} API route Passport can't name${where}${call ? `: ${call}` : ""}`;
|
|
261
|
+
}
|
|
262
|
+
const tool = options.tool ?? (hit?.via === "mcp" ? hit.tool : undefined);
|
|
263
|
+
if (tool)
|
|
264
|
+
return `Use a ${app} tool Passport can't name${where}: ${tool}`;
|
|
265
|
+
const [program, ...words] = (hit?.via === "cli" ? hit.command : (options.program ?? "")).split(" ").filter(Boolean);
|
|
266
|
+
if (!program)
|
|
267
|
+
return `Do something on ${app} Passport can't name${where}`;
|
|
268
|
+
return `Run a ${program} command Passport can't name${where}${words.length ? `: ${words.join(" ")}` : ""}`;
|
|
269
|
+
}
|
|
270
|
+
/** An unnamed action's summary in the past tense, for Activity: "Ran a wrangler command Passport can't name: …". Null
|
|
271
|
+
* for a summary not in `unnamedSummary`'s shape. */
|
|
272
|
+
export function pastUnnamed(summary) {
|
|
273
|
+
const found = /^(Run|Call|Use|Do) (a |something )/.exec(summary);
|
|
274
|
+
if (!found)
|
|
275
|
+
return null;
|
|
276
|
+
const past = { Run: "Ran", Call: "Called", Use: "Used", Do: "Did" }[found[1]];
|
|
277
|
+
return `${past}${summary.slice(found[1].length)}`;
|
|
278
|
+
}
|
|
202
279
|
/** A command line's hit; undefined when nothing of it can be kept. */
|
|
203
280
|
export function unnamedCli(argv) {
|
|
204
281
|
const command = unnamedCommand(argv);
|
|
@@ -223,7 +300,11 @@ const KEEP_VALUE_FLAGS = new Set([
|
|
|
223
300
|
"--base",
|
|
224
301
|
"--head",
|
|
225
302
|
"--workflow",
|
|
226
|
-
"--hostname"
|
|
303
|
+
"--hostname",
|
|
304
|
+
// npm: where a publish goes and who sees it (a URL keeps only its host and plain path).
|
|
305
|
+
"--tag",
|
|
306
|
+
"--access",
|
|
307
|
+
"--registry"
|
|
227
308
|
]);
|
|
228
309
|
const KEY_VALUE_FLAGS = new Set(["-f", "-F", "--field", "--raw-field"]);
|
|
229
310
|
const BOOLEAN_FLAGS = new Set([
|
|
@@ -413,5 +494,70 @@ export function sanitizeUnnamed(platform, value) {
|
|
|
413
494
|
if (hit.via === "cli" && typeof hit.command === "string") {
|
|
414
495
|
return unnamedCli(hit.command.slice(0, 200).trim().split(/\s+/));
|
|
415
496
|
}
|
|
497
|
+
if (hit.via === "mcp" && typeof hit.tool === "string")
|
|
498
|
+
return unnamedMcp(hit.tool.slice(0, 64));
|
|
416
499
|
return undefined;
|
|
417
500
|
}
|
|
501
|
+
const GH_API_VALUE_FLAGS = new Set([
|
|
502
|
+
"-X",
|
|
503
|
+
"--method",
|
|
504
|
+
"-f",
|
|
505
|
+
"-F",
|
|
506
|
+
"--field",
|
|
507
|
+
"--raw-field",
|
|
508
|
+
"-H",
|
|
509
|
+
"--header",
|
|
510
|
+
"--input",
|
|
511
|
+
"-q",
|
|
512
|
+
"--jq",
|
|
513
|
+
"-t",
|
|
514
|
+
"--template",
|
|
515
|
+
"--hostname",
|
|
516
|
+
"--cache",
|
|
517
|
+
"-p",
|
|
518
|
+
"--preview"
|
|
519
|
+
]);
|
|
520
|
+
const GH_API_BODY_FLAGS = new Set(["-f", "-F", "--field", "--raw-field", "--input"]);
|
|
521
|
+
/**
|
|
522
|
+
* What an unnamed call hit, from its masked command line (`maskCommandArgv`) when the client sent no hit of its own
|
|
523
|
+
* (an older CLI, a decision rebuilt after it was late): `gh api`'s method and path template (POST when it sends a
|
|
524
|
+
* body, as gh does; GET otherwise), else the program and subcommand words. Undefined when nothing can be kept.
|
|
525
|
+
*/
|
|
526
|
+
export function unnamedFromCommand(platform, command) {
|
|
527
|
+
const words = sanitizeMaskedCommand(command)?.split(" ") ?? [];
|
|
528
|
+
if (!words.length)
|
|
529
|
+
return undefined;
|
|
530
|
+
if (programName(words[0]) !== "gh" || words[1] !== "api")
|
|
531
|
+
return unnamedCli(words);
|
|
532
|
+
let method;
|
|
533
|
+
let body = false;
|
|
534
|
+
let path;
|
|
535
|
+
for (let index = 2; index < words.length; index++) {
|
|
536
|
+
const word = words[index];
|
|
537
|
+
const flag = word.split("=", 1)[0];
|
|
538
|
+
const value = word.includes("=") && flag.startsWith("--") ? word.slice(flag.length + 1) : undefined;
|
|
539
|
+
if (GH_API_BODY_FLAGS.has(flag))
|
|
540
|
+
body = true;
|
|
541
|
+
if (flag === "-X" || flag === "--method")
|
|
542
|
+
method = value ?? words[index + 1];
|
|
543
|
+
else if (/^-X[A-Za-z]+$/.test(word))
|
|
544
|
+
method = word.slice(2);
|
|
545
|
+
if (GH_API_VALUE_FLAGS.has(flag)) {
|
|
546
|
+
if (value === undefined)
|
|
547
|
+
index++;
|
|
548
|
+
continue;
|
|
549
|
+
}
|
|
550
|
+
if (!word.startsWith("-") && path === undefined)
|
|
551
|
+
path = word;
|
|
552
|
+
}
|
|
553
|
+
return unnamedApi(platform, method ?? (body ? "POST" : "GET"), path);
|
|
554
|
+
}
|
|
555
|
+
/** The hit an event records: the client's when it says where (a path, a subcommand), else the one its masked command
|
|
556
|
+
* gives, else whatever the client sent (a method alone). */
|
|
557
|
+
export function unnamedHitOf(platform, sent, command) {
|
|
558
|
+
// An MCP tool's name is the whole hit.
|
|
559
|
+
const located = sent && (sent.via === "api" ? Boolean(sent.path) : sent.via === "mcp" ? true : sent.command.includes(" "));
|
|
560
|
+
if (located)
|
|
561
|
+
return sent;
|
|
562
|
+
return unnamedFromCommand(platform, command) ?? sent;
|
|
563
|
+
}
|
package/dist/cpCli.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export declare const CP_CLI_PATH = "/api/cp/cli";
|
|
|
12
12
|
export declare const CP_CLI_STALE_MS: number;
|
|
13
13
|
/** The hooks try at most this often, so an offline laptop pays nothing. */
|
|
14
14
|
export declare const CP_CLI_RETRY_MS: number;
|
|
15
|
-
declare const PLATFORMS: readonly ["github", "railway", "supabase"];
|
|
15
|
+
declare const PLATFORMS: readonly ["github", "railway", "supabase", "kubernetes", "terraform", "sentry", "cloudflare", "npm"];
|
|
16
16
|
type Platform = (typeof PLATFORMS)[number];
|
|
17
17
|
export type CpCli = {
|
|
18
18
|
platforms: Partial<Record<Platform, true>>;
|