passport-bridge 0.48.1 → 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/cliClient.js +46 -2
- package/dist/cliExec.js +34 -18
- 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/githubDecide.generated.d.ts +2 -1
- package/dist/connectorKit/githubDecide.generated.js +33 -2
- 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/githubHooks.generated.js +2 -2
- 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/github/actions.generated.d.ts +0 -1
- package/dist/connectorKit/sources/github/actions.generated.js +1 -1
- 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 +13 -2
- package/dist/controlPlaneActions.generated.d.ts +68 -13
- package/dist/controlPlaneActions.generated.js +68 -17
- package/dist/controlPlaneCloudflare.d.ts +70 -0
- package/dist/controlPlaneCloudflare.js +188 -0
- package/dist/controlPlaneExec.d.ts +4 -0
- package/dist/controlPlaneExec.js +30 -0
- package/dist/controlPlaneGuard.d.ts +8 -2
- package/dist/controlPlaneGuard.js +38 -30
- 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 +3 -3
- package/dist/controlPlaneRailwayCli.generated.d.ts +1 -1
- package/dist/controlPlaneRailwayCli.generated.js +28 -9
- package/dist/controlPlaneRailwayGuard.d.ts +2 -0
- package/dist/controlPlaneRailwayGuard.js +5 -1
- 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/controlPlaneSupabase.d.ts +1 -0
- package/dist/controlPlaneSupabase.js +17 -5
- package/dist/controlPlaneTerraform.d.ts +86 -0
- package/dist/controlPlaneTerraform.js +273 -0
- package/dist/controlPlaneUnnamed.generated.d.ts +52 -2
- package/dist/controlPlaneUnnamed.generated.js +339 -1
- package/dist/cpCli.d.ts +1 -1
- package/dist/cpCli.js +1 -1
- package/dist/execGithubRepo.d.ts +8 -1
- package/dist/execGithubRepo.js +61 -13
- 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 +2 -2
package/dist/cliClient.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
2
|
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
3
3
|
import { TokenManager } from "./bridge.js";
|
|
4
|
-
import { CLI_EXCHANGE_ATTEMPT_MS, CLI_EXCHANGE_RETRY } from "./bridgeExchange.js";
|
|
4
|
+
import { BridgeCredentialError, CLI_EXCHANGE_ATTEMPT_MS, CLI_EXCHANGE_RETRY } from "./bridgeExchange.js";
|
|
5
|
+
import { dropCachedAccess, readCachedAccess, refreshFingerprint, writeCachedAccess } from "./accessTokenCache.js";
|
|
5
6
|
import { persistCurrentProfileRotation, recoverProfileRotation, withProfileLock } from "./credentials.js";
|
|
6
7
|
import { VERSION } from "./version.js";
|
|
7
8
|
import { AgentSignInError, SERVER_TOO_OLD } from "./cliProtocol.js";
|
|
@@ -59,7 +60,50 @@ function authedFetchFor(options) {
|
|
|
59
60
|
reload: () => recoverProfileRotation(profile)?.refreshToken,
|
|
60
61
|
lock: (fn) => withProfileLock(profile, fn)
|
|
61
62
|
}, Math.min(options.timeoutMs, CLI_EXCHANGE_ATTEMPT_MS), options.signal, fetch, { retry: CLI_EXCHANGE_RETRY, quietRetries: true });
|
|
62
|
-
|
|
63
|
+
const binding = () => ({ endpoint, refresh: refreshFingerprint(manager.currentRefreshToken()) });
|
|
64
|
+
const initial = readCachedAccess(profile, binding(), Date.now());
|
|
65
|
+
let cached = initial;
|
|
66
|
+
let savedToken;
|
|
67
|
+
const cacheCurrent = () => {
|
|
68
|
+
const held = manager.heldAccessToken();
|
|
69
|
+
if (!held || held.token === savedToken)
|
|
70
|
+
return;
|
|
71
|
+
savedToken = held.token;
|
|
72
|
+
try {
|
|
73
|
+
writeCachedAccess(profile, binding(), held);
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
/* Best effort: the next invocation exchanges instead. */
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const send = (input, init, token) => {
|
|
80
|
+
const headers = new Headers(input instanceof Request ? input.headers : undefined);
|
|
81
|
+
new Headers(init?.headers).forEach((value, name) => headers.set(name, value));
|
|
82
|
+
headers.set("authorization", `Bearer ${token}`);
|
|
83
|
+
return fetch(input, { ...init, headers, redirect: "error" });
|
|
84
|
+
};
|
|
85
|
+
const cachedFetch = (async (input, init) => {
|
|
86
|
+
const presented = cached ?? (await manager.accessToken());
|
|
87
|
+
if (!cached)
|
|
88
|
+
cacheCurrent();
|
|
89
|
+
let res = await send(input, init, presented);
|
|
90
|
+
if (res.status === 401) {
|
|
91
|
+
await res.body?.cancel().catch(() => undefined);
|
|
92
|
+
if (presented === cached)
|
|
93
|
+
cached = undefined;
|
|
94
|
+
dropCachedAccess(profile, presented);
|
|
95
|
+
const fresh = await manager.accessToken(presented !== initial);
|
|
96
|
+
cacheCurrent();
|
|
97
|
+
res = await send(input, init, fresh);
|
|
98
|
+
if (res.status === 401) {
|
|
99
|
+
await res.body?.cancel().catch(() => undefined);
|
|
100
|
+
dropCachedAccess(profile, fresh);
|
|
101
|
+
throw new BridgeCredentialError(401, "request");
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return res;
|
|
105
|
+
});
|
|
106
|
+
return decorateFetch(cachedFetch, {
|
|
63
107
|
"x-passport-surface": "cli",
|
|
64
108
|
...(options.caller ? { "x-passport-caller": options.caller } : {})
|
|
65
109
|
});
|
package/dist/cliExec.js
CHANGED
|
@@ -17,7 +17,7 @@ import { basename } from "node:path";
|
|
|
17
17
|
import { bool, value } from "./cliArgs.js";
|
|
18
18
|
import { memberApi } from "./cliClient.js";
|
|
19
19
|
import { passportUnreachable } from "./cliOutput.js";
|
|
20
|
-
import { execControlPlaneRefusal, execIdsWanted, execRailwayScope, execSupabaseProject } from "./controlPlaneExec.js";
|
|
20
|
+
import { execControlPlaneRefusal, execGithubDecide, execIdsWanted, execRailwayScope, execSupabaseProject } from "./controlPlaneExec.js";
|
|
21
21
|
import { classifyCommand, UNRECOGNIZED_VERB } from "./cliHookClassify.js";
|
|
22
22
|
import { ghApiMethod, ghValueFlags, parseArgs as parseGhArgs } from "./connectorKit/githubDecide.generated.js";
|
|
23
23
|
import { redactCommand } from "./cliHookRedact.js";
|
|
@@ -68,7 +68,11 @@ export function execFinding(vendor, binary, args) {
|
|
|
68
68
|
if (parsed.pos[0] !== "api")
|
|
69
69
|
return finding;
|
|
70
70
|
const { method, read } = ghApiMethod(parsed);
|
|
71
|
-
return {
|
|
71
|
+
return {
|
|
72
|
+
...finding,
|
|
73
|
+
risk: read ? "read" : finding.risk === "read" ? "write" : finding.risk,
|
|
74
|
+
method: read ? method : method === "GET" || method === "HEAD" ? "POST" : method
|
|
75
|
+
};
|
|
72
76
|
}
|
|
73
77
|
/** The child's environment: this shell's own, with the person's own sign-ins, minus Passport's own sign-in. */
|
|
74
78
|
export function childEnvironment(base) {
|
|
@@ -81,23 +85,34 @@ function offline(binary) {
|
|
|
81
85
|
return failure(`Passport couldn't be reached, so ${binary} didn't run.`, 1, "offline");
|
|
82
86
|
}
|
|
83
87
|
async function post(client, body, runtime, ms, binary) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
88
|
+
const send = async (payload) => {
|
|
89
|
+
try {
|
|
90
|
+
return await client.fetchApi(EXEC_AUTHORIZE_PATH, {
|
|
91
|
+
method: "POST",
|
|
92
|
+
headers: { "content-type": "application/json", accept: "application/json" },
|
|
93
|
+
body: JSON.stringify(payload),
|
|
94
|
+
signal: AbortSignal.any([runtime.signal, AbortSignal.timeout(ms)])
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
if (runtime.signal.aborted)
|
|
99
|
+
throw error;
|
|
100
|
+
const message = error instanceof Error ? error.message : "";
|
|
101
|
+
if (!passportUnreachable(error) && /token exchange failed|invalid_or_revoked|unauthori[sz]ed/i.test(message)) {
|
|
102
|
+
return failure("Passport refused this sign-in. Nothing ran.", 2, "auth", { hint: "Run: passport login" });
|
|
103
|
+
}
|
|
104
|
+
return offline(binary);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
let response = await send(body);
|
|
108
|
+
// An older server refuses fields added after it shipped (`Unexpected field "githubDecide".`): retry once without it.
|
|
109
|
+
if (response.status === 400 && body.githubDecide !== undefined) {
|
|
110
|
+
const message = await safeApiError(response.clone(), "");
|
|
111
|
+
if (message.includes("githubDecide")) {
|
|
112
|
+
await response.body?.cancel().catch(() => undefined);
|
|
113
|
+
const { githubDecide: _dropped, ...compat } = body;
|
|
114
|
+
response = await send(compat);
|
|
99
115
|
}
|
|
100
|
-
return offline(binary);
|
|
101
116
|
}
|
|
102
117
|
if (response.status === 403) {
|
|
103
118
|
const refused = await (await import("./cliExecGuard.js")).guardRequiredFailure(response.clone());
|
|
@@ -204,6 +219,7 @@ export async function exec(args, runtime, deps = {}) {
|
|
|
204
219
|
const auth = resolveCliAuth(args, runtime.env);
|
|
205
220
|
const caller = execCaller(args, runtime.env, auth, deps);
|
|
206
221
|
const prepared = prepare(args, runtime, deps, auth, caller);
|
|
222
|
+
await execGithubDecide(prepared, runtime.env);
|
|
207
223
|
await execRailwayScope(prepared, auth, runtime.env, deps.home, value(args, "decision"));
|
|
208
224
|
await execSupabaseProject(prepared, runtime.env);
|
|
209
225
|
const { vendor, binary } = prepared;
|
package/dist/cliHookAfter.js
CHANGED
|
@@ -51,6 +51,15 @@ async function heldKey(profile, vendor) {
|
|
|
51
51
|
const marked = readExecVendors(profile).has(vendor);
|
|
52
52
|
return { held: marked, rerouted: marked && !readKeysChoices(profile).kept[vendor] };
|
|
53
53
|
}
|
|
54
|
+
/** A `terraform plan -out` that ran: its plan read now (counts and resource-type names only) and remembered for the
|
|
55
|
+
* session, so the apply that follows is decided on it at once (`terraformPlans.ts`). */
|
|
56
|
+
async function withTerraformPlans(context, state, failed) {
|
|
57
|
+
if (failed || !/(?:terraform|tofu)\b[^;&|]*\bplan\b[^;&|]*-out/.test(context.command))
|
|
58
|
+
return state;
|
|
59
|
+
const { rememberTerraformPlans } = await import("./controlPlaneTerraform.js");
|
|
60
|
+
const where = { cwd: workingFolder(context.input) ?? null, env: process.env };
|
|
61
|
+
return rememberTerraformPlans(context.command, where, state).catch(() => state);
|
|
62
|
+
}
|
|
54
63
|
/** Each fact's code loads only when the command could carry it: a sign-in
|
|
55
64
|
* only after a failure, resources and a pushed branch only after a success. */
|
|
56
65
|
async function learn(context, state) {
|
|
@@ -62,7 +71,7 @@ async function learn(context, state) {
|
|
|
62
71
|
const resources = failed || !context.findings.length
|
|
63
72
|
? { creates: [], removes: [] }
|
|
64
73
|
: (await import("./cliHookCreates.js")).resourcesOf(context.findings);
|
|
65
|
-
const retry = nextRetry(state, context.command, exitCode, context.now);
|
|
74
|
+
const retry = nextRetry(await withTerraformPlans(context, state, failed), context.command, exitCode, context.now);
|
|
66
75
|
const program = retry.state.retry?.program;
|
|
67
76
|
const pushes = context.findings.some((finding) => finding.vendor === "git" && finding.verb === "push");
|
|
68
77
|
const pushed = failed || !pushes ? undefined : (await import("./cliHookPushed.js")).pushedOf(context.findings);
|
package/dist/cliHookDecide.d.ts
CHANGED
|
@@ -2,9 +2,15 @@
|
|
|
2
2
|
* The guard's decision, only through the control plane (docs/design/control-plane.md). What it asks about, all at
|
|
3
3
|
* once inside the hook's budget:
|
|
4
4
|
*
|
|
5
|
-
* - a consequential `gh`, `git push`, `railway` or `supabase` command on a connected platform
|
|
6
|
-
* `platforms`): `POST /api/cp/decide`,
|
|
7
|
-
* `controlPlaneRailwayGuard.ts`, `controlPlaneSupabase.ts
|
|
5
|
+
* - a consequential `gh`, `git push`, `railway` or `supabase` command on a connected platform, or a `kubectl` or
|
|
6
|
+
* `helm` command (Kubernetes has nothing to connect) (`GET /api/cp/cli` `platforms`): `POST /api/cp/decide`,
|
|
7
|
+
* through the classifiers (`controlPlaneGuard.ts`, `controlPlaneRailwayGuard.ts`, `controlPlaneSupabase.ts`,
|
|
8
|
+
* `controlPlaneKubernetes.ts`); a `terraform` or `tofu` command (Terraform has no setup either), through
|
|
9
|
+
* `controlPlaneTerraform.ts`;
|
|
10
|
+
* - a `sentry-cli` command or a curl to Sentry's API (Sentry needs no setup either): the same, through
|
|
11
|
+
* `controlPlaneSentry.ts`;
|
|
12
|
+
* - an `npm`, `pnpm` or `yarn` command that acts on a registry (npm has nothing to connect): the same, through
|
|
13
|
+
* `controlPlaneNpmGuard.ts`;
|
|
8
14
|
* - a recognized write or delete verb of a vendor CLI that is a basic platform for this person (`vendors`):
|
|
9
15
|
* `POST /api/cp/decide/cli` with the verb only (`controlPlaneCli.ts`);
|
|
10
16
|
* - a command that can't be undone on this computer (`localIrreversible.ts`): `POST /api/cp/decide/cli` as vendor
|
package/dist/cliHookDecide.js
CHANGED
|
@@ -2,9 +2,15 @@
|
|
|
2
2
|
* The guard's decision, only through the control plane (docs/design/control-plane.md). What it asks about, all at
|
|
3
3
|
* once inside the hook's budget:
|
|
4
4
|
*
|
|
5
|
-
* - a consequential `gh`, `git push`, `railway` or `supabase` command on a connected platform
|
|
6
|
-
* `platforms`): `POST /api/cp/decide`,
|
|
7
|
-
* `controlPlaneRailwayGuard.ts`, `controlPlaneSupabase.ts
|
|
5
|
+
* - a consequential `gh`, `git push`, `railway` or `supabase` command on a connected platform, or a `kubectl` or
|
|
6
|
+
* `helm` command (Kubernetes has nothing to connect) (`GET /api/cp/cli` `platforms`): `POST /api/cp/decide`,
|
|
7
|
+
* through the classifiers (`controlPlaneGuard.ts`, `controlPlaneRailwayGuard.ts`, `controlPlaneSupabase.ts`,
|
|
8
|
+
* `controlPlaneKubernetes.ts`); a `terraform` or `tofu` command (Terraform has no setup either), through
|
|
9
|
+
* `controlPlaneTerraform.ts`;
|
|
10
|
+
* - a `sentry-cli` command or a curl to Sentry's API (Sentry needs no setup either): the same, through
|
|
11
|
+
* `controlPlaneSentry.ts`;
|
|
12
|
+
* - an `npm`, `pnpm` or `yarn` command that acts on a registry (npm has nothing to connect): the same, through
|
|
13
|
+
* `controlPlaneNpmGuard.ts`;
|
|
8
14
|
* - a recognized write or delete verb of a vendor CLI that is a basic platform for this person (`vendors`):
|
|
9
15
|
* `POST /api/cp/decide/cli` with the verb only (`controlPlaneCli.ts`);
|
|
10
16
|
* - a command that can't be undone on this computer (`localIrreversible.ts`): `POST /api/cp/decide/cli` as vendor
|
|
@@ -41,6 +47,16 @@ export function githubWord(command, hosts = []) {
|
|
|
41
47
|
const railwayWord = (command) => /railway/i.test(command.replace(/["'\\]/g, ""));
|
|
42
48
|
/** The same for `supabase` (and a `curl` to Supabase's API): the kit's resolver decides what is really Supabase. */
|
|
43
49
|
const supabaseWord = (command) => /supabase/i.test(command.replace(/["'\\]/g, ""));
|
|
50
|
+
/** `kubectl` or `helm` anywhere: the classifier decides what really runs one. */
|
|
51
|
+
const kubernetesWord = (command) => /kubectl|helm/i.test(command.replace(/["'\\]/g, ""));
|
|
52
|
+
/** The same for `terraform` and `tofu`. */
|
|
53
|
+
const terraformWord = (command) => /terraform|tofu/i.test(command.replace(/["'\\]/g, ""));
|
|
54
|
+
/** The same for `sentry-cli` (and a call to Sentry's API, sentry.io). */
|
|
55
|
+
const sentryWord = (command) => /sentry/i.test(command.replace(/["'\\]/g, ""));
|
|
56
|
+
/** The same for `wrangler` (and a raw HTTP call to Cloudflare's API). */
|
|
57
|
+
const cloudflareWord = (command) => /wrangler|api\.cloudflare\.com/i.test(command.replace(/["'\\]/g, ""));
|
|
58
|
+
/** The same for `npm`, `pnpm` and `yarn`: the npm classifier decides what acts on a registry. */
|
|
59
|
+
const npmWord = (command) => /(?:^|[^a-z0-9_-])(?:npm|pnpm|yarn)(?:$|[^a-z0-9_-])/i.test(command.replace(/["'\\]/g, ""));
|
|
44
60
|
/** A verb as the server reads it (`CLI_VERB` in server/src/controlPlane/cliRoutes.ts): never an argument. */
|
|
45
61
|
const CLI_VERB = /^-{0,2}[a-z0-9][a-z0-9_:-]*(?: -{0,2}[a-z0-9][a-z0-9_:-]*){0,3}$/;
|
|
46
62
|
const VERB_TOKEN = /^-{0,2}[A-Za-z0-9][A-Za-z0-9._:+-]{0,39}$/;
|
|
@@ -87,6 +103,11 @@ function asking(context, local) {
|
|
|
87
103
|
github: Boolean(cp?.platforms.github) && githubWord(command, cp?.githubHosts),
|
|
88
104
|
railway: Boolean(cp?.platforms.railway) && railwayWord(command),
|
|
89
105
|
supabase: Boolean(cp?.platforms.supabase) && supabaseWord(command),
|
|
106
|
+
kubernetes: Boolean(cp?.platforms.kubernetes) && kubernetesWord(command),
|
|
107
|
+
terraform: Boolean(cp?.platforms.terraform) && terraformWord(command),
|
|
108
|
+
sentry: Boolean(cp?.platforms.sentry) && sentryWord(command),
|
|
109
|
+
cloudflare: Boolean(cp?.platforms.cloudflare) && cloudflareWord(command),
|
|
110
|
+
npm: Boolean(cp?.platforms.npm) && npmWord(command),
|
|
90
111
|
verbs: [
|
|
91
112
|
...vendorVerbs(context.findings, cp?.vendors ?? []),
|
|
92
113
|
...local.map((verb) => [LOCAL_VENDOR, verb])
|
|
@@ -101,14 +122,15 @@ export async function planGuard(context) {
|
|
|
101
122
|
});
|
|
102
123
|
if (!context.canAsk)
|
|
103
124
|
return local[0] ? refuse(local[0], "signed-out") : { output: null };
|
|
104
|
-
const { github, railway, supabase, verbs } = asking(context, local);
|
|
125
|
+
const { github, railway, supabase, kubernetes, terraform, sentry, cloudflare, npm, verbs } = asking(context, local);
|
|
105
126
|
const left = context.deadline - context.now();
|
|
106
127
|
if (left <= 0) {
|
|
107
128
|
if (local[0])
|
|
108
129
|
return refuse(local[0], "unreachable");
|
|
109
|
-
|
|
130
|
+
const asked = { github, railway, supabase, kubernetes, terraform, sentry, cloudflare, npm };
|
|
131
|
+
return { output: await whenUnreachable(context, asked, []) };
|
|
110
132
|
}
|
|
111
|
-
if (!github
|
|
133
|
+
if (![github, railway, supabase, kubernetes, terraform, sentry, cloudflare, npm].some(Boolean) && !verbs.length)
|
|
112
134
|
return { output: null };
|
|
113
135
|
// The kit's shadow run (`kitShadow.ts`) stops before the guard's deadline.
|
|
114
136
|
setShadowDeadline(context.deadline, context.now);
|
|
@@ -116,28 +138,36 @@ export async function planGuard(context) {
|
|
|
116
138
|
const open = async () => (api ??= (await context.openApi()) ?? undefined) ?? null;
|
|
117
139
|
const signal = AbortSignal.any([context.budget, AbortSignal.timeout(left)]);
|
|
118
140
|
const extra = context.report?.sessionId ? { sessionId: context.report.sessionId } : {};
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
const threw = { github: false, railway: false, supabase: false };
|
|
122
|
-
const failed = (platform) => () => {
|
|
123
|
-
threw[platform] = true;
|
|
124
|
-
return null;
|
|
125
|
-
};
|
|
126
|
-
const [githubLine, railwayAnswer, supabaseAnswer, verbAnswers] = await Promise.all([
|
|
127
|
-
github ? githubLinePlan(context, open, extra, signal).catch(failed("github")) : null,
|
|
128
|
-
railway ? railwayLine(context, open, extra, signal).catch(failed("railway")) : null,
|
|
129
|
-
supabase ? supabaseLine(context, open, extra, signal).catch(failed("supabase")) : null,
|
|
130
|
-
askVerbs(verbs, open, extra, signal).catch(() => [])
|
|
131
|
-
]);
|
|
141
|
+
const asked = { github, railway, supabase, kubernetes, terraform, sentry, cloudflare, npm };
|
|
142
|
+
const { threw, githubLine, railwayAnswer, supabaseAnswer, kubernetesAnswer, terraformAnswer, sentryAnswer, cloudflareAnswer, npmAnswer, verbAnswers } = await askAll(context, asked, verbs, { open, extra, signal });
|
|
132
143
|
// Decided: the kit's shadow run reads what was asked about, off the decision's path.
|
|
133
144
|
shadowAfterDecision();
|
|
134
145
|
const withApi = (output) => ({ output, ...(api ? { api } : {}) });
|
|
135
|
-
const answers = [
|
|
146
|
+
const answers = [
|
|
147
|
+
githubLine?.decided?.answer,
|
|
148
|
+
railwayAnswer?.answer,
|
|
149
|
+
supabaseAnswer?.answer,
|
|
150
|
+
kubernetesAnswer?.answer,
|
|
151
|
+
terraformAnswer?.answer,
|
|
152
|
+
sentryAnswer?.answer,
|
|
153
|
+
cloudflareAnswer?.answer,
|
|
154
|
+
npmAnswer?.answer,
|
|
155
|
+
...verbAnswers
|
|
156
|
+
];
|
|
136
157
|
const blocked = answers.find((answer) => answer?.kind === "block");
|
|
137
158
|
if (blocked)
|
|
138
159
|
return withApi(denyOutput(context.client, blocked.message));
|
|
139
160
|
const late = answers.flatMap((answer) => (answer?.kind === "unreachable" ? (answer.late ?? []) : []));
|
|
140
|
-
const
|
|
161
|
+
const others = {
|
|
162
|
+
railwayAnswer,
|
|
163
|
+
supabaseAnswer,
|
|
164
|
+
kubernetesAnswer,
|
|
165
|
+
terraformAnswer,
|
|
166
|
+
sentryAnswer,
|
|
167
|
+
cloudflareAnswer,
|
|
168
|
+
npmAnswer
|
|
169
|
+
};
|
|
170
|
+
const missed = missedPlatforms(asked, threw, githubLine, othersOf(others));
|
|
141
171
|
const offline = await whenUnreachable(context, missed, late);
|
|
142
172
|
if (offline)
|
|
143
173
|
return withApi(offline);
|
|
@@ -148,9 +178,83 @@ export async function planGuard(context) {
|
|
|
148
178
|
return withApi(refuse(unanswered, "unreachable").output);
|
|
149
179
|
// The whole line is allowed: each decision is left for what spends it, and the unanswered ones for the after-hook.
|
|
150
180
|
await supabaseAnswer?.leave();
|
|
151
|
-
await leaveDecisions(githubLine?.decided ?? null, railwayAnswer, context, [
|
|
181
|
+
await leaveDecisions(githubLine?.decided ?? null, railwayAnswer, context, [
|
|
182
|
+
supabaseAnswer?.answer,
|
|
183
|
+
kubernetesAnswer?.answer,
|
|
184
|
+
terraformAnswer?.answer,
|
|
185
|
+
sentryAnswer?.answer,
|
|
186
|
+
cloudflareAnswer?.answer,
|
|
187
|
+
npmAnswer?.answer,
|
|
188
|
+
...verbAnswers
|
|
189
|
+
]);
|
|
152
190
|
return withApi(null);
|
|
153
191
|
}
|
|
192
|
+
/** Each platform's answer but GitHub's (which is the line's), for the offline rules. */
|
|
193
|
+
function othersOf(answers) {
|
|
194
|
+
return {
|
|
195
|
+
railway: answers.railwayAnswer?.answer,
|
|
196
|
+
supabase: answers.supabaseAnswer?.answer,
|
|
197
|
+
kubernetes: answers.kubernetesAnswer?.answer,
|
|
198
|
+
terraform: answers.terraformAnswer?.answer,
|
|
199
|
+
sentry: answers.sentryAnswer?.answer,
|
|
200
|
+
cloudflare: answers.cloudflareAnswer?.answer,
|
|
201
|
+
npm: answers.npmAnswer?.answer
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
/** Every platform's part of a line, asked at once. A step that fails is no answer from its platform (it counts as
|
|
205
|
+
* unreachable for the offline rules); it never drops another's block or a local refusal. */
|
|
206
|
+
async function askAll(context, asked, verbs, how) {
|
|
207
|
+
const { open, extra, signal } = how;
|
|
208
|
+
const threw = {
|
|
209
|
+
github: false,
|
|
210
|
+
railway: false,
|
|
211
|
+
supabase: false,
|
|
212
|
+
kubernetes: false,
|
|
213
|
+
terraform: false,
|
|
214
|
+
sentry: false,
|
|
215
|
+
cloudflare: false,
|
|
216
|
+
npm: false
|
|
217
|
+
};
|
|
218
|
+
const failed = (platform) => () => {
|
|
219
|
+
threw[platform] = true;
|
|
220
|
+
return null;
|
|
221
|
+
};
|
|
222
|
+
const [githubLine, railwayAnswer, supabaseAnswer, kubernetesAnswer, terraformAnswer, sentryAnswer, cloudflareAnswer, npmAnswer, verbAnswers] = await Promise.all([
|
|
223
|
+
asked.github ? githubLinePlan(context, open, extra, signal).catch(failed("github")) : null,
|
|
224
|
+
asked.railway ? railwayLine(context, open, extra, signal).catch(failed("railway")) : null,
|
|
225
|
+
asked.supabase ? supabaseLine(context, open, extra, signal).catch(failed("supabase")) : null,
|
|
226
|
+
asked.kubernetes ? kubernetesLine(context, open, extra, signal).catch(failed("kubernetes")) : null,
|
|
227
|
+
asked.terraform ? terraformLine(context, open, extra, signal).catch(failed("terraform")) : null,
|
|
228
|
+
asked.sentry ? sentryLine(context, open, extra, signal).catch(failed("sentry")) : null,
|
|
229
|
+
asked.cloudflare ? cloudflareLine(context, open, extra, signal).catch(failed("cloudflare")) : null,
|
|
230
|
+
asked.npm ? npmLine(context, open, extra, signal).catch(failed("npm")) : null,
|
|
231
|
+
askVerbs(verbs, open, extra, signal).catch(() => [])
|
|
232
|
+
]);
|
|
233
|
+
return {
|
|
234
|
+
threw,
|
|
235
|
+
githubLine,
|
|
236
|
+
railwayAnswer,
|
|
237
|
+
supabaseAnswer,
|
|
238
|
+
kubernetesAnswer,
|
|
239
|
+
terraformAnswer,
|
|
240
|
+
sentryAnswer,
|
|
241
|
+
cloudflareAnswer,
|
|
242
|
+
npmAnswer,
|
|
243
|
+
verbAnswers
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
async function npmLine(context, open, extra, signal) {
|
|
247
|
+
const where = { cwd: context.cwd ?? null, env: context.env ?? process.env, home: homedir() };
|
|
248
|
+
return (await import("./controlPlaneNpmGuard.js")).npmLinePlan(context.command, where, open, extra, signal);
|
|
249
|
+
}
|
|
250
|
+
async function cloudflareLine(context, open, extra, signal) {
|
|
251
|
+
const where = { cwd: context.cwd ?? null, env: context.env ?? process.env };
|
|
252
|
+
return (await import("./controlPlaneCloudflare.js")).cloudflareLinePlan(context.command, where, open, extra, signal);
|
|
253
|
+
}
|
|
254
|
+
async function sentryLine(context, open, extra, signal) {
|
|
255
|
+
const where = { cwd: context.cwd ?? null, env: context.env ?? process.env };
|
|
256
|
+
return (await import("./controlPlaneSentry.js")).sentryLinePlan(context.command, where, open, extra, signal);
|
|
257
|
+
}
|
|
154
258
|
async function railwayLine(context, open, extra, signal) {
|
|
155
259
|
const where = { cwd: context.cwd, env: context.env ?? process.env, home: homedir() };
|
|
156
260
|
return (await import("./controlPlaneRailwayGuard.js")).railwayLinePlan(context.command, where, open, extra, signal);
|
|
@@ -159,6 +263,29 @@ async function supabaseLine(context, open, extra, signal) {
|
|
|
159
263
|
const where = { cwd: context.cwd ?? null, env: context.env ?? process.env };
|
|
160
264
|
return (await import("./controlPlaneSupabase.js")).supabaseLinePlan(context.command, where, open, extra, signal);
|
|
161
265
|
}
|
|
266
|
+
async function kubernetesLine(context, open, extra, signal) {
|
|
267
|
+
const where = { cwd: context.cwd ?? null, env: context.env ?? process.env, home: homedir() };
|
|
268
|
+
return (await import("./controlPlaneKubernetes.js")).kubernetesLinePlan(context.command, where, open, extra, signal);
|
|
269
|
+
}
|
|
270
|
+
/** Terraform's part of a line, with the session's plans (`terraformPlans.ts`) and what is left of the budget for
|
|
271
|
+
* reading one. */
|
|
272
|
+
async function terraformLine(context, open, extra, signal) {
|
|
273
|
+
const where = { cwd: context.cwd ?? null, env: context.env ?? process.env };
|
|
274
|
+
const [{ terraformLinePlan }, sessions] = await Promise.all([
|
|
275
|
+
import("./controlPlaneTerraform.js"),
|
|
276
|
+
import("./cliHookSessionState.js")
|
|
277
|
+
]);
|
|
278
|
+
const runtime = context.report?.runtime;
|
|
279
|
+
const sessionId = context.report?.sessionId;
|
|
280
|
+
const state = runtime ? sessions.readSessionState(runtime, sessionId, context.now()) : {};
|
|
281
|
+
// Half of what is left reads a plan; the rest asks Passport.
|
|
282
|
+
const planMs = Math.max(0, Math.floor((context.deadline - context.now()) / 2));
|
|
283
|
+
const save = (next) => {
|
|
284
|
+
if (runtime)
|
|
285
|
+
sessions.writeSessionState(runtime, sessionId, next);
|
|
286
|
+
};
|
|
287
|
+
return terraformLinePlan(context.command, where, open, extra, signal, { state, planMs, save });
|
|
288
|
+
}
|
|
162
289
|
async function askVerbs(verbs, open, extra, signal) {
|
|
163
290
|
if (!verbs.length)
|
|
164
291
|
return [];
|
|
@@ -200,13 +327,20 @@ async function leaveDecisions(github, railway, context, others) {
|
|
|
200
327
|
/** The platforms asked and not answered: Passport couldn't be reached for them. Every non-answer counts: no response,
|
|
201
328
|
* a 401, 403, 404, 429 or 5xx, a timeout, a 200 that isn't Passport's JSON (each reads as unreachable), or a step
|
|
202
329
|
* that threw. An `undecided` from Passport itself is an answer. */
|
|
203
|
-
function missedPlatforms(asked, threw, github,
|
|
330
|
+
function missedPlatforms(asked, threw, github, others) {
|
|
204
331
|
// A real `undecided` (Passport answered, and doesn't decide this) keeps today's behavior: it isn't offline.
|
|
205
332
|
const missed = (answer) => !answer || answer.kind === "unreachable";
|
|
206
333
|
return {
|
|
207
334
|
github: asked.github && (threw.github || (Boolean(github?.label) && missed(github?.decided?.answer))),
|
|
208
|
-
railway: asked.railway && (threw.railway || missed(railway)),
|
|
209
|
-
supabase: asked.supabase && (threw.supabase || missed(supabase))
|
|
335
|
+
railway: asked.railway && (threw.railway || missed(others.railway)),
|
|
336
|
+
supabase: asked.supabase && (threw.supabase || missed(others.supabase)),
|
|
337
|
+
// A line with no kubectl or helm write asks nothing: no answer to miss.
|
|
338
|
+
kubernetes: asked.kubernetes && (threw.kubernetes || (others.kubernetes !== null && missed(others.kubernetes))),
|
|
339
|
+
terraform: asked.terraform && (threw.terraform || missed(others.terraform)),
|
|
340
|
+
sentry: asked.sentry && (threw.sentry || missed(others.sentry)),
|
|
341
|
+
// A line with no consequential wrangler command asks nothing: no answer to miss.
|
|
342
|
+
cloudflare: asked.cloudflare && (threw.cloudflare || (others.cloudflare !== null && missed(others.cloudflare))),
|
|
343
|
+
npm: asked.npm && (threw.npm || missed(others.npm))
|
|
210
344
|
};
|
|
211
345
|
}
|
|
212
346
|
/** What the line does on each platform Passport didn't answer for, classified on this computer. */
|
|
@@ -229,13 +363,33 @@ async function foundOffline(context, missed) {
|
|
|
229
363
|
const where = { cwd: context.cwd ?? null, env: context.env ?? process.env };
|
|
230
364
|
found.push(...(await import("./controlPlaneSupabase.js")).supabaseFound(context.command, where));
|
|
231
365
|
}
|
|
366
|
+
if (missed.kubernetes) {
|
|
367
|
+
const where = { cwd: context.cwd ?? null, env: context.env ?? process.env, home: homedir() };
|
|
368
|
+
found.push(...(await import("./controlPlaneKubernetes.js")).kubernetesFound(context.command, where));
|
|
369
|
+
}
|
|
370
|
+
if (missed.terraform) {
|
|
371
|
+
const where = { cwd: context.cwd ?? null, env: context.env ?? process.env };
|
|
372
|
+
found.push(...(await (await import("./controlPlaneTerraform.js")).terraformFound(context.command, where)));
|
|
373
|
+
}
|
|
374
|
+
if (missed.sentry) {
|
|
375
|
+
const where = { cwd: context.cwd ?? null, env: context.env ?? process.env };
|
|
376
|
+
found.push(...(await import("./controlPlaneSentry.js")).sentryFound(context.command, where));
|
|
377
|
+
}
|
|
378
|
+
if (missed.cloudflare) {
|
|
379
|
+
const where = { cwd: context.cwd ?? null, env: context.env ?? process.env };
|
|
380
|
+
found.push(...(await import("./controlPlaneCloudflare.js")).cloudflareFound(context.command, where));
|
|
381
|
+
}
|
|
382
|
+
if (missed.npm) {
|
|
383
|
+
const where = { cwd: context.cwd ?? null, env: context.env ?? process.env, home: homedir() };
|
|
384
|
+
found.push(...(await import("./controlPlaneNpmGuard.js")).npmFound(context.command, where));
|
|
385
|
+
}
|
|
232
386
|
return found;
|
|
233
387
|
}
|
|
234
388
|
/** The guard never got to ask (its budget ran out first, or something failed before it answered): every platform the
|
|
235
389
|
* line would have asked about counts as unreachable, so a covered action is refused and the rest is recorded. */
|
|
236
390
|
export async function planUnreachable(context) {
|
|
237
|
-
const { github, railway, supabase } = asking(context, []);
|
|
238
|
-
return whenUnreachable(context, { github, railway, supabase }, []);
|
|
391
|
+
const { github, railway, supabase, kubernetes, terraform, sentry, cloudflare, npm } = asking(context, []);
|
|
392
|
+
return whenUnreachable(context, { github, railway, supabase, kubernetes, terraform, sentry, cloudflare, npm }, []);
|
|
239
393
|
}
|
|
240
394
|
/** What the agent reads when the guard couldn't even classify a line Passport didn't answer for. */
|
|
241
395
|
export const UNCHECKED_REFUSAL = "Passport couldn't be reached or check this command, so it didn't run.";
|
|
@@ -246,7 +400,7 @@ export const UNCHECKED_REFUSAL = "Passport couldn't be reached or check this com
|
|
|
246
400
|
* (recorded as no rules known). Anything that throws here refuses: a covered action is never allowed by an error.
|
|
247
401
|
*/
|
|
248
402
|
async function whenUnreachable(context, missed, late) {
|
|
249
|
-
if (!
|
|
403
|
+
if (!Object.values(missed).some(Boolean))
|
|
250
404
|
return null;
|
|
251
405
|
try {
|
|
252
406
|
const found = await foundOffline(context, missed);
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* Cursor on their next try. One small owner-only file per session, named by a
|
|
7
7
|
* digest of the agent and session id; bounded in count and age. Never throws.
|
|
8
8
|
*/
|
|
9
|
+
import type { PlanMemo } from "./terraformPlans.js";
|
|
9
10
|
/** A session quiet this long starts over. */
|
|
10
11
|
export declare const STATE_MAX_AGE_MS: number;
|
|
11
12
|
/** A sign-in failure is told to Codex or Cursor on a try within this long. */
|
|
@@ -21,11 +22,13 @@ export type SignInState = {
|
|
|
21
22
|
held: boolean;
|
|
22
23
|
at: number;
|
|
23
24
|
};
|
|
24
|
-
/** `created`: folders this session made itself (`sessionCreated.ts`), canonical paths.
|
|
25
|
+
/** `created`: folders this session made itself (`sessionCreated.ts`), canonical paths. `terraformPlans`: the plans
|
|
26
|
+
* this session made or read, reduced to counts and resource-type names (`terraformPlans.ts`). */
|
|
25
27
|
export type SessionState = {
|
|
26
28
|
retry?: RetryState;
|
|
27
29
|
signIn?: SignInState;
|
|
28
30
|
created?: string[];
|
|
31
|
+
terraformPlans?: PlanMemo[];
|
|
29
32
|
};
|
|
30
33
|
/** The same command, however it was spaced, and the command inside a
|
|
31
34
|
* `passport exec` rewrite, so the guard's and the after-hook's agree. */
|
|
@@ -70,7 +70,7 @@ export function writeSessionState(runtime, sessionId, state) {
|
|
|
70
70
|
if (!path)
|
|
71
71
|
return;
|
|
72
72
|
try {
|
|
73
|
-
if (!state.retry && !state.signIn && !state.created?.length) {
|
|
73
|
+
if (!state.retry && !state.signIn && !state.created?.length && !state.terraformPlans?.length) {
|
|
74
74
|
rmSync(path, { force: true });
|
|
75
75
|
return;
|
|
76
76
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Effect, EffectVerb, ObjectType } from "../controlPlaneActions.generated.js";
|
|
2
|
+
/**
|
|
3
|
+
* Per-call effects for the kit's apps (docs/design/control-plane.md, "Action model", Layer 2 inputs): what the
|
|
4
|
+
* operation a classifier named does, from its summary template ("Restart {where}", "Delete branch {name}"), which the
|
|
5
|
+
* kit renders from the call's arguments and both sides send. The server reads them for the gateway and the guard
|
|
6
|
+
* alike, so no bridge release is needed for a new entry. A summary no template matches keeps its action's defaults.
|
|
7
|
+
*/
|
|
8
|
+
/** One reviewed operation: the action key it is classified as (the classifier's own, before `REMOVED_ACTIONS`), its
|
|
9
|
+
* summary template, and its effects. */
|
|
10
|
+
export type CallEffectEntry = readonly [actionKey: string, template: string, effects: readonly Effect[]];
|
|
11
|
+
/** A summary template as a pattern: each `{param}` matches any text, and the kit's own asides (" (staged)", "(run SQL
|
|
12
|
+
* on project x)") may follow. */
|
|
13
|
+
export declare function templatePattern(template: string): RegExp;
|
|
14
|
+
export type CallEffectsOf = (keys: readonly string[], summary: string) => Effect[] | undefined;
|
|
15
|
+
/** A lookup over reviewed entries: the most specific template of one of `keys` (the classification's key and the
|
|
16
|
+
* catalog key it is recorded as) that matches the summary. */
|
|
17
|
+
export declare function callEffectsTable(entries: readonly CallEffectEntry[]): CallEffectsOf;
|
|
18
|
+
/** The verb an operation's first word says; anything else changes something. */
|
|
19
|
+
export declare function verbOf(words: string): EffectVerb;
|
|
20
|
+
export declare function objectOf(words: string): ObjectType;
|
|
21
|
+
/** The derivation: the words' verb on their object type, a run created when the words start code. */
|
|
22
|
+
export declare function deriveEffects(words: string): Effect[];
|
|
23
|
+
/** Something stops working: Destructive beside whatever else the call does. */
|
|
24
|
+
export declare const OUTAGE: Effect;
|
|
25
|
+
/** It may stop something working (a restart under load, a key some app may still use). */
|
|
26
|
+
export declare const MAY_OUTAGE: Effect;
|
|
27
|
+
/** Starts code running now. */
|
|
28
|
+
export declare const RUN: Effect;
|
|
29
|
+
/** May start code running later (a variable change Railway redeploys on, a trigger). */
|
|
30
|
+
export declare const MAY_RUN_LATER: Effect;
|
|
31
|
+
/** Reachable from the internet (a domain, a TCP proxy, a public bucket). */
|
|
32
|
+
export declare const PUBLIC_DATA: Effect;
|
|
33
|
+
/** An invitation emails the person invited. */
|
|
34
|
+
export declare const EMAILS_OUTSIDE: Effect;
|
|
35
|
+
/** It changes what the workspace pays (an add-on, compute, a usage limit). */
|
|
36
|
+
export declare const BILLING: Effect;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
const escape = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2
|
+
/** A summary template as a pattern: each `{param}` matches any text, and the kit's own asides (" (staged)", "(run SQL
|
|
3
|
+
* on project x)") may follow. */
|
|
4
|
+
export function templatePattern(template) {
|
|
5
|
+
const literal = template.split(/\{[^}]*\}/).map(escape);
|
|
6
|
+
return new RegExp(`^${literal.join(".+?")}(?: \\(.*\\))?$`, "s");
|
|
7
|
+
}
|
|
8
|
+
/** How many literal characters a template has: the more, the more specific. */
|
|
9
|
+
const specificity = (template) => template.replace(/\{[^}]*\}/g, "").length;
|
|
10
|
+
/** A lookup over reviewed entries: the most specific template of one of `keys` (the classification's key and the
|
|
11
|
+
* catalog key it is recorded as) that matches the summary. */
|
|
12
|
+
export function callEffectsTable(entries) {
|
|
13
|
+
const compiled = [...entries]
|
|
14
|
+
.sort((a, b) => specificity(b[1]) - specificity(a[1]))
|
|
15
|
+
.map(([key, template, effects]) => ({ key, pattern: templatePattern(template), effects }));
|
|
16
|
+
return (keys, summary) => {
|
|
17
|
+
const text = summary.trim();
|
|
18
|
+
const found = compiled.find((entry) => keys.includes(entry.key) && entry.pattern.test(text));
|
|
19
|
+
return found ? found.effects.map((effect) => ({ ...effect })) : undefined;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
const DELETE_WORDS = /^(delete|remove|drop|empty|purge|destroy)\b/i;
|
|
23
|
+
const CREATE_WORDS = /^(create|add|invite|upload|seed|import|accept|generate|define|record)\b/i;
|
|
24
|
+
/** The verb an operation's first word says; anything else changes something. */
|
|
25
|
+
export function verbOf(words) {
|
|
26
|
+
if (DELETE_WORDS.test(words))
|
|
27
|
+
return "delete";
|
|
28
|
+
if (CREATE_WORDS.test(words))
|
|
29
|
+
return "create";
|
|
30
|
+
return "change";
|
|
31
|
+
}
|
|
32
|
+
/** Object type by an operation's words, first match wins (shared by Railway and Supabase). */
|
|
33
|
+
const OBJECT_RULES = [
|
|
34
|
+
[
|
|
35
|
+
/secret|api key|jwt|signing key|token|password|role|privilege|grant|member|access|sign-in|sso|saml|auth|ssl|network|claim|encryption|variable|credential|sign-ups|policy/i,
|
|
36
|
+
"access"
|
|
37
|
+
],
|
|
38
|
+
[/deploy|redeploy|restart|rollback|run |shell|ssh|session/i, "run"],
|
|
39
|
+
[/function|code|source/i, "code"],
|
|
40
|
+
[/notebook|history entry|migration history|from history/i, "record"],
|
|
41
|
+
[/table|rows|data|bucket|object|migration|backup|restore|branch|database|volume|dump|seed/i, "data"]
|
|
42
|
+
];
|
|
43
|
+
export function objectOf(words) {
|
|
44
|
+
for (const [pattern, object] of OBJECT_RULES)
|
|
45
|
+
if (pattern.test(words))
|
|
46
|
+
return object;
|
|
47
|
+
return "service";
|
|
48
|
+
}
|
|
49
|
+
/** The derivation: the words' verb on their object type, a run created when the words start code. */
|
|
50
|
+
export function deriveEffects(words) {
|
|
51
|
+
const verb = verbOf(words);
|
|
52
|
+
const object = objectOf(words);
|
|
53
|
+
if (object === "run")
|
|
54
|
+
return verb === "delete" ? [{ verb: "change", object: "run" }] : [{ verb: "create", object }];
|
|
55
|
+
return [{ verb, object }];
|
|
56
|
+
}
|
|
57
|
+
/* ------------------------------------------------------------------ */
|
|
58
|
+
/* Effects the reviews reuse */
|
|
59
|
+
/* ------------------------------------------------------------------ */
|
|
60
|
+
/** Something stops working: Destructive beside whatever else the call does. */
|
|
61
|
+
export const OUTAGE = { verb: "change", object: "service", disrupts: true };
|
|
62
|
+
/** It may stop something working (a restart under load, a key some app may still use). */
|
|
63
|
+
export const MAY_OUTAGE = { verb: "change", object: "service", disrupts: true, possible: true };
|
|
64
|
+
/** Starts code running now. */
|
|
65
|
+
export const RUN = { verb: "create", object: "run" };
|
|
66
|
+
/** May start code running later (a variable change Railway redeploys on, a trigger). */
|
|
67
|
+
export const MAY_RUN_LATER = { verb: "create", object: "run", when: "later", possible: true };
|
|
68
|
+
/** Reachable from the internet (a domain, a TCP proxy, a public bucket). */
|
|
69
|
+
export const PUBLIC_DATA = { verb: "change", object: "data", audience: "public" };
|
|
70
|
+
/** An invitation emails the person invited. */
|
|
71
|
+
export const EMAILS_OUTSIDE = { verb: "create", object: "message", audience: "outside" };
|
|
72
|
+
/** It changes what the workspace pays (an add-on, compute, a usage limit). */
|
|
73
|
+
export const BILLING = { verb: "change", object: "money" };
|