passport-bridge 0.35.1 → 0.36.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/cliAutopilotPolicy.d.ts +2 -0
- package/dist/cliExec.d.ts +1 -2
- package/dist/cliExec.js +17 -38
- package/dist/cliGitCredential.js +28 -10
- package/dist/cliHookDecide.js +36 -16
- package/dist/cliPolicyV2.js +6 -4
- package/dist/connectorKit/cli.generated.d.ts +15 -0
- package/dist/connectorKit/cli.generated.js +244 -0
- package/dist/connectorKit/engine.generated.d.ts +50 -0
- package/dist/connectorKit/engine.generated.js +475 -0
- package/dist/connectorKit/manifest.generated.d.ts +317 -0
- package/dist/connectorKit/manifest.generated.js +18 -0
- package/dist/connectorKit/manifests/flagSpec.generated.d.ts +6 -0
- package/dist/connectorKit/manifests/flagSpec.generated.js +20 -0
- package/dist/connectorKit/manifests/github.generated.d.ts +17 -0
- package/dist/connectorKit/manifests/github.generated.js +82 -0
- package/dist/connectorKit/manifests/githubCapture.generated.d.ts +2 -0
- package/dist/connectorKit/manifests/githubCapture.generated.js +307 -0
- package/dist/connectorKit/manifests/githubHooks.generated.d.ts +23 -0
- package/dist/connectorKit/manifests/githubHooks.generated.js +401 -0
- package/dist/connectorKit/manifests/githubReads.generated.d.ts +6 -0
- package/dist/connectorKit/manifests/githubReads.generated.js +200 -0
- package/dist/connectorKit/manifests/railway.generated.d.ts +6 -0
- package/dist/connectorKit/manifests/railway.generated.js +121 -0
- package/dist/connectorKit/manifests/railwayCapture.generated.d.ts +3 -0
- package/dist/connectorKit/manifests/railwayCapture.generated.js +375 -0
- package/dist/connectorKit/manifests/railwayHooks.generated.d.ts +25 -0
- package/dist/connectorKit/manifests/railwayHooks.generated.js +487 -0
- package/dist/connectorKit/manifests/supabase.generated.d.ts +3 -0
- package/dist/connectorKit/manifests/supabase.generated.js +34 -0
- package/dist/connectorKit/manifests/supabaseApi.generated.d.ts +3 -0
- package/dist/connectorKit/manifests/supabaseApi.generated.js +632 -0
- package/dist/connectorKit/manifests/supabaseCapture.generated.d.ts +9 -0
- package/dist/connectorKit/manifests/supabaseCapture.generated.js +421 -0
- package/dist/connectorKit/manifests/supabaseCatalog.generated.d.ts +11 -0
- package/dist/connectorKit/manifests/supabaseCatalog.generated.js +70 -0
- package/dist/connectorKit/manifests/supabaseCli.generated.d.ts +10 -0
- package/dist/connectorKit/manifests/supabaseCli.generated.js +581 -0
- package/dist/connectorKit/manifests/supabasePlatform.generated.d.ts +7 -0
- package/dist/connectorKit/manifests/supabasePlatform.generated.js +283 -0
- package/dist/connectorKit/manifests/supabaseProbes.generated.d.ts +5 -0
- package/dist/connectorKit/manifests/supabaseProbes.generated.js +580 -0
- package/dist/connectorKit/params.generated.d.ts +25 -0
- package/dist/connectorKit/params.generated.js +193 -0
- package/dist/connectorKit/pgParser.d.ts +9 -0
- package/dist/connectorKit/pgParser.js +13 -0
- package/dist/connectorKit/shadow.generated.d.ts +58 -0
- package/dist/connectorKit/shadow.generated.js +184 -0
- package/dist/connectorKit/shell.generated.d.ts +73 -0
- package/dist/connectorKit/shell.generated.js +516 -0
- package/dist/connectorKit/sourcegen.generated.d.ts +50 -0
- package/dist/connectorKit/sourcegen.generated.js +208 -0
- package/dist/connectorKit/sources/supabase/api-operations.generated.d.ts +187 -0
- package/dist/connectorKit/sources/supabase/api-operations.generated.js +2 -0
- package/dist/connectorKit/sources/supabase/cli-flags.generated.d.ts +1236 -0
- package/dist/connectorKit/sources/supabase/cli-flags.generated.js +2 -0
- package/dist/connectorKit/sources/supabase/mcp-tools.generated.d.ts +35 -0
- package/dist/connectorKit/sources/supabase/mcp-tools.generated.js +2 -0
- package/dist/connectorKit/sql.generated.d.ts +29 -0
- package/dist/connectorKit/sql.generated.js +420 -0
- package/dist/connectorKit/sqlFingerprint.generated.d.ts +8 -0
- package/dist/connectorKit/sqlFingerprint.generated.js +105 -0
- package/dist/connectorKit/template.generated.d.ts +21 -0
- package/dist/connectorKit/template.generated.js +89 -0
- package/dist/connectorKit/types.generated.d.ts +81 -0
- package/dist/connectorKit/types.generated.js +6 -0
- package/dist/controlPlane.generated.d.ts +46 -2
- package/dist/controlPlane.generated.js +10 -1
- package/dist/controlPlaneExec.d.ts +21 -2
- package/dist/controlPlaneExec.js +83 -5
- package/dist/controlPlaneGithub.generated.js +4 -8
- package/dist/controlPlaneGuard.js +29 -4
- package/dist/controlPlaneIds.d.ts +39 -0
- package/dist/controlPlaneIds.js +175 -0
- package/dist/controlPlaneModel.generated.d.ts +67 -0
- package/dist/controlPlaneModel.generated.js +153 -0
- package/dist/controlPlaneRailwayGuard.js +13 -3
- package/dist/controlPlaneSupabase.d.ts +84 -0
- package/dist/controlPlaneSupabase.js +278 -0
- package/dist/execGithubRepo.d.ts +2 -0
- package/dist/execGithubRepo.js +30 -0
- package/dist/gitPush.d.ts +20 -0
- package/dist/gitPush.js +45 -7
- package/dist/kitShadow.d.ts +90 -0
- package/dist/kitShadow.js +261 -0
- package/dist/kitShadowBudget.d.ts +10 -0
- package/dist/kitShadowBudget.js +15 -0
- package/dist/pluginPin.d.ts +1 -1
- package/dist/pluginPin.js +1 -1
- package/dist/supabaseDecisions.d.ts +9 -0
- package/dist/supabaseDecisions.js +98 -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
|
@@ -236,6 +236,8 @@ export type AutopilotPolicy = {
|
|
|
236
236
|
controlPlaneGithub?: boolean;
|
|
237
237
|
/** The control plane: Railway is connected (cli-policy v2 `controlPlane.railway`). */
|
|
238
238
|
controlPlaneRailway?: boolean;
|
|
239
|
+
/** The control plane: Supabase is connected (cli-policy v2 `controlPlane.supabase`). */
|
|
240
|
+
controlPlaneSupabase?: boolean;
|
|
239
241
|
/** Known project scripts (Batch A item 5), vendor `project`: they set class
|
|
240
242
|
* and environment only, never an allow. */
|
|
241
243
|
project?: {
|
package/dist/cliExec.d.ts
CHANGED
|
@@ -42,6 +42,7 @@ export type ExecDependencies = {
|
|
|
42
42
|
home?: string;
|
|
43
43
|
};
|
|
44
44
|
export { execTarget };
|
|
45
|
+
export { githubRepo } from "./execGithubRepo.js";
|
|
45
46
|
/** The classified finding the server decides on: vendor, verb, risk, environment. */
|
|
46
47
|
export declare function execFinding(vendor: ExecVendor, binary: string, args: readonly string[], policy: ReturnType<typeof readCliPolicy>, where?: WhereContext): {
|
|
47
48
|
vendor: string;
|
|
@@ -49,8 +50,6 @@ export declare function execFinding(vendor: ExecVendor, binary: string, args: re
|
|
|
49
50
|
risk: string;
|
|
50
51
|
environment?: string;
|
|
51
52
|
} & Record<string, string>;
|
|
52
|
-
/** gh acts on `--repo owner/name`, or the folder's GitHub origin. */
|
|
53
|
-
export declare function githubRepo(args: readonly string[], cwd: string): string | undefined;
|
|
54
53
|
/** Only the vendor's own variables, as plain single-line strings. None for a Railway read Passport sends with the
|
|
55
54
|
* person's own sign-in (`ownSignIn`: Passport mints only for actions). */
|
|
56
55
|
export declare function checkedCredential(vendor: ExecVendor, raw: unknown, ownSignIn?: unknown): Record<string, string>;
|
package/dist/cliExec.js
CHANGED
|
@@ -18,13 +18,12 @@
|
|
|
18
18
|
* with it are refused before anything is sent.
|
|
19
19
|
*/
|
|
20
20
|
import { projectOf } from "./cliHookProject.js";
|
|
21
|
-
import { readFileSync } from "node:fs";
|
|
22
21
|
import { homedir } from "node:os";
|
|
23
|
-
import { basename
|
|
22
|
+
import { basename } from "node:path";
|
|
24
23
|
import { bool, value } from "./cliArgs.js";
|
|
25
24
|
import { memberApi } from "./cliClient.js";
|
|
26
25
|
import { passportUnreachable } from "./cliOutput.js";
|
|
27
|
-
import { execControlPlaneRefusal, execRailwayScope, execRelease } from "./controlPlaneExec.js";
|
|
26
|
+
import { execControlPlaneRefusal, execIdsWanted, execRailwayScope, execRelease } from "./controlPlaneExec.js";
|
|
28
27
|
import { classifyCommand, UNRECOGNIZED_VERB } from "./cliHookClassify.js";
|
|
29
28
|
import { reportedEnvironment } from "./cliHookEnvironment.js";
|
|
30
29
|
import { localMachine } from "./cliHookLocal.js";
|
|
@@ -40,6 +39,7 @@ import { execTarget } from "./execTarget.js";
|
|
|
40
39
|
import { carrierOf, ownFinding, withExecPlan } from "./execPlan.js";
|
|
41
40
|
import { secretNeedles } from "./execMask.js";
|
|
42
41
|
import { spawnVendor } from "./execSpawn.js";
|
|
42
|
+
import { shadowAfterDecision } from "./kitShadow.js";
|
|
43
43
|
export { spawnVendor } from "./execSpawn.js";
|
|
44
44
|
import { findVendorBinary, removeShims } from "./execShims.js";
|
|
45
45
|
import { approvalLink, hashLink } from "./webLinks.js";
|
|
@@ -52,8 +52,9 @@ export const EXEC_WAIT_DEFAULT_SECONDS = 100;
|
|
|
52
52
|
const WAIT_POLL_SECONDS = 30;
|
|
53
53
|
const SESSION = /^[A-Za-z0-9._:-]{1,128}$/;
|
|
54
54
|
const RUNTIME = /^[a-z0-9-]{1,24}$/;
|
|
55
|
-
const REPO = /^[A-Za-z0-9_.-]{1,100}\/[A-Za-z0-9_.-]{1,100}$/;
|
|
56
55
|
export { execTarget };
|
|
56
|
+
export { githubRepo } from "./execGithubRepo.js";
|
|
57
|
+
import { githubRepo } from "./execGithubRepo.js";
|
|
57
58
|
function quote(part) {
|
|
58
59
|
return /^[A-Za-z0-9_@%+=:,./-]+$/.test(part) ? part : `'${part.replaceAll("'", `'\\''`)}'`;
|
|
59
60
|
}
|
|
@@ -108,33 +109,6 @@ function execWhere(cwd, env) {
|
|
|
108
109
|
fs: NODE_LINK_FS
|
|
109
110
|
};
|
|
110
111
|
}
|
|
111
|
-
/** gh acts on `--repo owner/name`, or the folder's GitHub origin. */
|
|
112
|
-
export function githubRepo(args, cwd) {
|
|
113
|
-
for (let index = 0; index < args.length; index++) {
|
|
114
|
-
const arg = args[index];
|
|
115
|
-
const inline = arg.match(/^(?:--repo|-R)=(.+)$/);
|
|
116
|
-
const candidate = inline ? inline[1] : arg === "--repo" || arg === "-R" ? args[index + 1] : undefined;
|
|
117
|
-
if (candidate)
|
|
118
|
-
return REPO.test(candidate) ? candidate : undefined;
|
|
119
|
-
}
|
|
120
|
-
let dir = resolve(cwd);
|
|
121
|
-
for (let depth = 0; depth < 20; depth++) {
|
|
122
|
-
try {
|
|
123
|
-
const text = readFileSync(join(dir, ".git", "config"), "utf8").slice(0, 64 * 1024);
|
|
124
|
-
const origin = text.match(/\[remote "origin"\][^[]*?url\s*=\s*(\S+)/);
|
|
125
|
-
const match = origin?.[1]?.match(/github\.com[:/]([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+?)(?:\.git)?$/);
|
|
126
|
-
const repo = match ? `${match[1]}/${match[2]}` : undefined;
|
|
127
|
-
return repo && REPO.test(repo) ? repo : undefined;
|
|
128
|
-
}
|
|
129
|
-
catch {
|
|
130
|
-
const parent = dirname(dir);
|
|
131
|
-
if (parent === dir)
|
|
132
|
-
return undefined;
|
|
133
|
-
dir = parent;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return undefined;
|
|
137
|
-
}
|
|
138
112
|
/** Only the vendor's own variables, as plain single-line strings. None for a Railway read Passport sends with the
|
|
139
113
|
* person's own sign-in (`ownSignIn`: Passport mints only for actions). */
|
|
140
114
|
export function checkedCredential(vendor, raw, ownSignIn) {
|
|
@@ -489,14 +463,15 @@ export async function exec(args, runtime, deps = {}) {
|
|
|
489
463
|
const startedAt = (deps.now ?? Date.now)();
|
|
490
464
|
// Links (bridge 0.32.0): a bounded copy of what it prints, only when that isn't a terminal.
|
|
491
465
|
const wanted = linksWanted(auth.kind === "profile" ? readCliPolicy(auth.profile) : null);
|
|
492
|
-
const capture = execCapture(wanted, runtime.stdout);
|
|
466
|
+
const capture = execCapture(execIdsWanted(vendor, decided, wanted), runtime.stdout);
|
|
493
467
|
try {
|
|
494
468
|
const credential = checkedCredential(vendor, decided.credential?.env, decided.credential?.ownSignIn);
|
|
495
469
|
remember(true);
|
|
496
|
-
// The control plane
|
|
497
|
-
await execControlPlaneRefusal(client.fetchApi, prepared, decided, timeoutMs(args), {
|
|
470
|
+
// The control plane decides a gh command with its token's id, and a supabase command (unless the guard did).
|
|
471
|
+
const ids = await execControlPlaneRefusal(client.fetchApi, prepared, decided, timeoutMs(args), {
|
|
498
472
|
...(runtime.signal ? { signal: runtime.signal } : {}),
|
|
499
|
-
asks: auth.kind === "profile"
|
|
473
|
+
asks: auth.kind === "profile",
|
|
474
|
+
env: runtime.env
|
|
500
475
|
});
|
|
501
476
|
// A dev loop runs only with a key that expires within minutes.
|
|
502
477
|
const devLoop = devLoopRefusal(vendor, args.positionals.slice(1), decided.credential?.issuance);
|
|
@@ -519,9 +494,12 @@ export async function exec(args, runtime, deps = {}) {
|
|
|
519
494
|
// One deploy at a time: renew the lease Passport took while it runs, release it after.
|
|
520
495
|
const lease = (await import("./execLease.js")).keepLease(client.fetchApi, decided.leaseId);
|
|
521
496
|
try {
|
|
522
|
-
|
|
523
|
-
?
|
|
524
|
-
:
|
|
497
|
+
const running = deps.spawn
|
|
498
|
+
? deps.spawn(prepared.executable, prepared.rest, options)
|
|
499
|
+
: spawnVendor(prepared.executable, prepared.rest, options, piped);
|
|
500
|
+
// Decided and started: the kit's shadow run reads the command now (`kitShadow.ts`), off both.
|
|
501
|
+
shadowAfterDecision();
|
|
502
|
+
code = await running;
|
|
525
503
|
}
|
|
526
504
|
catch {
|
|
527
505
|
return failure(`${binary} couldn't start.`, 1, "not_installed");
|
|
@@ -530,6 +508,7 @@ export async function exec(args, runtime, deps = {}) {
|
|
|
530
508
|
await lease.stop();
|
|
531
509
|
await handed.stop();
|
|
532
510
|
}
|
|
511
|
+
await ids.report(capture, code);
|
|
533
512
|
}
|
|
534
513
|
finally {
|
|
535
514
|
await issued.release();
|
package/dist/cliGitCredential.js
CHANGED
|
@@ -37,6 +37,7 @@ import { compareVersions } from "./launcherHealth.js";
|
|
|
37
37
|
import { VERSION } from "./version.js";
|
|
38
38
|
import { askingGitCommand, execGitCommand, isPush } from "./gitInvocation.js";
|
|
39
39
|
import { MAX_PUSH_REFS, planKey, planPush } from "./gitPush.js";
|
|
40
|
+
import { beginShadowLine, shadowAfterDecision, shadowAlongside, shadowGithubLine } from "./kitShadow.js";
|
|
40
41
|
import { takePushDecisions } from "./gitPushDecisions.js";
|
|
41
42
|
import { helperLine, helperProgram, installGitCredential, probeHelper, readGitCredentialState, removeGitCredential } from "./gitCredentialSetup.js";
|
|
42
43
|
export const GIT_CREDENTIAL_PATH = "/api/my/github/git-credential";
|
|
@@ -268,10 +269,12 @@ async function get(args, runtime, deps, input) {
|
|
|
268
269
|
}
|
|
269
270
|
// A push: what it changes, ref by ref. Only the classification leaves this computer.
|
|
270
271
|
const [owner, name] = repo.split("/");
|
|
272
|
+
const lines = [];
|
|
271
273
|
const plan = planPush(asking, {
|
|
272
274
|
cwd: deps.cwd ?? process.cwd(),
|
|
273
275
|
env: runtime.env,
|
|
274
276
|
repo: { owner, repo: name },
|
|
277
|
+
onLine: (line) => void lines.push(line),
|
|
275
278
|
...(deps.run ? { run: deps.run } : {})
|
|
276
279
|
});
|
|
277
280
|
if (!plan)
|
|
@@ -282,26 +285,41 @@ async function get(args, runtime, deps, input) {
|
|
|
282
285
|
if (got.kind !== "refused" || got.code !== "undecided")
|
|
283
286
|
return got.kind === "token" ? answer(got.minted) : refused(got);
|
|
284
287
|
// Passport would issue a push token once it decides the push: every ref, and
|
|
285
|
-
// a block on any stops git here.
|
|
286
|
-
|
|
287
|
-
for (const
|
|
288
|
+
// a block on any stops git here. Deciding it here (no guard did), the shadow run reads it too.
|
|
289
|
+
beginShadowLine();
|
|
290
|
+
for (const line of lines)
|
|
291
|
+
shadowGithubLine(line.argv, line.place, line.found);
|
|
292
|
+
// The shadow's counts ride along with these decisions, never waited on: stopped once they're answered.
|
|
293
|
+
const stopShadow = shadowAlongside(api, runtime.signal);
|
|
294
|
+
const decided = await decidePush(api, plan.classifications, runtime, deps, left).finally(stopShadow);
|
|
295
|
+
shadowAfterDecision();
|
|
296
|
+
if (decided.kind === "block")
|
|
297
|
+
return "quit=1\n";
|
|
298
|
+
if (decided.kind === "own")
|
|
299
|
+
return ownSignIn(decided.why);
|
|
300
|
+
got = await mint(api, repo, "write", runtime.signal, left(), { decisionIds: decided.ids });
|
|
301
|
+
return got.kind === "token" ? answer(got.minted) : refused(got);
|
|
302
|
+
}
|
|
303
|
+
/** Every ref of a push decided, in order: its decision ids, a block (git stops), or why it runs with the person's own sign-in. */
|
|
304
|
+
async function decidePush(api, classifications, runtime, deps, left) {
|
|
305
|
+
const ids = [];
|
|
306
|
+
for (const classification of classifications.slice(0, MAX_PUSH_REFS)) {
|
|
288
307
|
const wait = Math.min(deps.decideTimeoutMs ?? DECIDE_TIMEOUT_MS, left());
|
|
289
308
|
if (wait <= 0)
|
|
290
|
-
return
|
|
309
|
+
return { kind: "own", why: "Passport couldn't decide this push in time, so" };
|
|
291
310
|
const decided = await within(wait, runtime.signal, (bounded) => askControlPlane(api, classification, {}, bounded));
|
|
292
311
|
if (decided.kind === "block") {
|
|
293
312
|
runtime.stderr.write(`passport: ${decided.message.replace(/\s*\n\s*/g, " ")}\n`);
|
|
294
313
|
// quit=1: git stops here, without trying another helper or asking for a password.
|
|
295
|
-
return "
|
|
314
|
+
return { kind: "block" };
|
|
296
315
|
}
|
|
297
316
|
if (decided.kind !== "allow")
|
|
298
|
-
return
|
|
317
|
+
return { kind: "own", why: "Passport couldn't decide this push in time, so" };
|
|
299
318
|
if (!decided.decisionId)
|
|
300
|
-
return
|
|
301
|
-
|
|
319
|
+
return { kind: "own", why: "Passport didn't record a decision for this push, so" };
|
|
320
|
+
ids.push(decided.decisionId);
|
|
302
321
|
}
|
|
303
|
-
|
|
304
|
-
return got.kind === "token" ? answer(got.minted) : refused(got);
|
|
322
|
+
return { kind: "ids", ids };
|
|
305
323
|
}
|
|
306
324
|
/**
|
|
307
325
|
* The asker is unknown: a read-only token, which Passport records as an
|
package/dist/cliHookDecide.js
CHANGED
|
@@ -24,6 +24,8 @@ import { endedSessionLine, haltOnEnded, haltsOnEnd } from "./cliHookSessionEnd.j
|
|
|
24
24
|
import { decideRequest, requestPlace } from "./cliHookDecideRequest.js";
|
|
25
25
|
export { decideRequest };
|
|
26
26
|
import { decideOnServer } from "./cliHookServerDecision.js";
|
|
27
|
+
import { setShadowDeadline } from "./kitShadowBudget.js";
|
|
28
|
+
import { shadowAfterDecision } from "./kitShadow.js";
|
|
27
29
|
export { CLI_DECIDE_PATH, decideOnServer, parseServerDecision } from "./cliHookServerDecision.js";
|
|
28
30
|
/** Codex can't ask from a hook, so an ask it read is recorded as the block it was. */
|
|
29
31
|
export function codexAskBlocked(report) {
|
|
@@ -203,10 +205,13 @@ const GITHUB_WORD = /(?:^|[\s;&|(/])(?:gh\s|git\s(?:[^;&|]*\s)?push\b)/;
|
|
|
203
205
|
* the classifier, which reads the line as the shell would, decides what is really railway. */
|
|
204
206
|
const RAILWAY_WORD = /railway/i;
|
|
205
207
|
const railwayWord = (command) => RAILWAY_WORD.test(command.replace(/["'\\]/g, ""));
|
|
208
|
+
/** The same for `supabase` (and a `curl` to Supabase's API): the kit's resolver decides what is really Supabase. */
|
|
209
|
+
const supabaseWord = (command) => /supabase/i.test(command.replace(/["'\\]/g, ""));
|
|
206
210
|
/**
|
|
207
|
-
* The control plane (GitHub or
|
|
208
|
-
* `git push` or `
|
|
209
|
-
* asked about once more (`controlPlaneGuard.ts`,
|
|
211
|
+
* The control plane (GitHub, Railway or Supabase connected): a consequential
|
|
212
|
+
* `gh`, `git push`, `railway` or `supabase` command that the rest of the plan
|
|
213
|
+
* lets through is asked about once more (`controlPlaneGuard.ts`,
|
|
214
|
+
* `controlPlaneRailwayGuard.ts`, `controlPlaneSupabase.ts`).
|
|
210
215
|
* A block replaces the plan with the exact block message. Unanswered in time,
|
|
211
216
|
* the plan stands, as for any guard decision without Passport, and when the
|
|
212
217
|
* command runs Passport is told so (`controlPlaneLate.ts`).
|
|
@@ -217,30 +222,32 @@ async function controlPlanePlan(plan, decision, policy, context) {
|
|
|
217
222
|
// Only once the platform is connected (cli-policy `controlPlane`): no request otherwise.
|
|
218
223
|
const github = Boolean(policy.autopilot.controlPlaneGithub) && GITHUB_WORD.test(context.command);
|
|
219
224
|
const railway = Boolean(policy.autopilot.controlPlaneRailway) && railwayWord(context.command);
|
|
225
|
+
const supabase = Boolean(policy.autopilot.controlPlaneSupabase) && supabaseWord(context.command);
|
|
220
226
|
const left = context.deadline - context.now();
|
|
221
|
-
if ((!github && !railway) || left <= 0)
|
|
227
|
+
if ((!github && !railway && !supabase) || left <= 0)
|
|
222
228
|
return plan;
|
|
229
|
+
// The kit's shadow run (`kitShadow.ts`) stops before the guard's deadline.
|
|
230
|
+
setShadowDeadline(context.deadline, context.now);
|
|
223
231
|
let api = plan.api;
|
|
224
232
|
const open = async () => (api ??= (await context.openApi()) ?? undefined) ?? null;
|
|
225
233
|
const signal = AbortSignal.any([context.budget, AbortSignal.timeout(left)]);
|
|
226
234
|
const extra = { sessionId: context.report?.sessionId };
|
|
227
|
-
const [githubLine, railwayAnswer] = await
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
? (await import("./controlPlaneRailwayGuard.js")).railwayLinePlan(context.command, { cwd: context.cwd, env: context.env ?? process.env, home: homedir() }, open, extra, signal)
|
|
231
|
-
: null
|
|
232
|
-
]);
|
|
235
|
+
const [githubLine, railwayAnswer, supabaseAnswer] = await askPlatforms({ github, railway, supabase }, context, open, extra, signal);
|
|
236
|
+
// Decided: the kit's shadow run reads what was asked about, off the decision's path.
|
|
237
|
+
shadowAfterDecision();
|
|
233
238
|
const githubAnswer = githubLine?.decided?.answer;
|
|
234
|
-
const blocked = githubAnswer?.kind === "block"
|
|
239
|
+
const blocked = [githubAnswer, railwayAnswer?.answer, supabaseAnswer?.answer].find((answer) => answer?.kind === "block");
|
|
235
240
|
if (blocked?.kind !== "block") {
|
|
236
241
|
// Only once the whole line is allowed (nothing in it blocked, nothing left to ask) is a decision left for exec.
|
|
237
|
-
if (!decision || runs(plan, decision))
|
|
238
|
-
await
|
|
242
|
+
if (!decision || runs(plan, decision)) {
|
|
243
|
+
await supabaseAnswer?.leave();
|
|
244
|
+
await leaveDecisions(githubLine?.decided ?? null, railwayAnswer, context, supabaseAnswer?.answer);
|
|
245
|
+
}
|
|
239
246
|
return api ? { ...plan, api } : plan;
|
|
240
247
|
}
|
|
241
248
|
const fallback = {
|
|
242
249
|
verdict: "deny",
|
|
243
|
-
label: githubLine?.label ?? railwayAnswer?.label ?? "",
|
|
250
|
+
label: githubLine?.label ?? railwayAnswer?.label ?? supabaseAnswer?.label ?? "",
|
|
244
251
|
findings: [],
|
|
245
252
|
destructive: true
|
|
246
253
|
};
|
|
@@ -252,6 +259,19 @@ async function controlPlanePlan(plan, decision, policy, context) {
|
|
|
252
259
|
offline: false
|
|
253
260
|
};
|
|
254
261
|
}
|
|
262
|
+
/** Each connected platform's part of a line, asked at once. */
|
|
263
|
+
async function askPlatforms(asking, context, open, extra, signal) {
|
|
264
|
+
const { github, railway, supabase } = asking;
|
|
265
|
+
return Promise.all([
|
|
266
|
+
github ? githubLinePlan(context, open, extra, signal) : null,
|
|
267
|
+
railway
|
|
268
|
+
? (await import("./controlPlaneRailwayGuard.js")).railwayLinePlan(context.command, { cwd: context.cwd, env: context.env ?? process.env, home: homedir() }, open, extra, signal)
|
|
269
|
+
: null,
|
|
270
|
+
supabase
|
|
271
|
+
? (await import("./controlPlaneSupabase.js")).supabaseLinePlan(context.command, { cwd: context.cwd ?? null, env: context.env ?? process.env }, open, extra, signal)
|
|
272
|
+
: null
|
|
273
|
+
]);
|
|
274
|
+
}
|
|
255
275
|
/** GitHub's part of a line. Every `git push` is decided here, ref by ref, resolved as git will in this folder; with
|
|
256
276
|
* `passport git-credential` set up, the helper spends these decisions on the push token instead of asking again. */
|
|
257
277
|
async function githubLinePlan(context, open, extra, signal) {
|
|
@@ -271,7 +291,7 @@ async function holdLate(answers, report, now) {
|
|
|
271
291
|
}
|
|
272
292
|
/** An allowed line that runs: Railway's decision waits for exec, each push's for `passport git-credential` when it is
|
|
273
293
|
* set up (`gitPushDecisions.ts`), and the ids of decides left unanswered for the after-hook. */
|
|
274
|
-
async function leaveDecisions(github, railway, context) {
|
|
294
|
+
async function leaveDecisions(github, railway, context, supabase) {
|
|
275
295
|
if (railway)
|
|
276
296
|
await railway.leave();
|
|
277
297
|
if (github?.pushes.length) {
|
|
@@ -283,7 +303,7 @@ async function leaveDecisions(github, railway, context) {
|
|
|
283
303
|
for (const push of github.pushes)
|
|
284
304
|
leavePushDecisions(push.key, push.decisionIds);
|
|
285
305
|
}
|
|
286
|
-
await holdLate([github?.answer, railway?.answer], context.report, context.now());
|
|
306
|
+
await holdLate([github?.answer, railway?.answer, supabase], context.report, context.now());
|
|
287
307
|
}
|
|
288
308
|
/** Whether the command runs after this plan, as far as the guard decides it. */
|
|
289
309
|
function runs(plan, decision) {
|
package/dist/cliPolicyV2.js
CHANGED
|
@@ -584,14 +584,15 @@ function productionKeys(value) {
|
|
|
584
584
|
const vendors = value.filter((entry) => typeof entry === "string" && VENDOR_KEY.test(entry));
|
|
585
585
|
return vendors.length ? [...new Set(vendors)].slice(0, MAX_VENDORS) : undefined;
|
|
586
586
|
}
|
|
587
|
-
/** The control plane's gates as cli-policy sends them: `railway` only when true. */
|
|
587
|
+
/** The control plane's gates as cli-policy sends them: `railway` and `supabase` only when true. */
|
|
588
588
|
function controlPlaneOut(autopilot) {
|
|
589
|
-
if (!autopilot.controlPlaneGithub && !autopilot.controlPlaneRailway)
|
|
589
|
+
if (!autopilot.controlPlaneGithub && !autopilot.controlPlaneRailway && !autopilot.controlPlaneSupabase)
|
|
590
590
|
return {};
|
|
591
591
|
return {
|
|
592
592
|
controlPlane: {
|
|
593
593
|
github: Boolean(autopilot.controlPlaneGithub),
|
|
594
|
-
...(autopilot.controlPlaneRailway ? { railway: true } : {})
|
|
594
|
+
...(autopilot.controlPlaneRailway ? { railway: true } : {}),
|
|
595
|
+
...(autopilot.controlPlaneSupabase ? { supabase: true } : {})
|
|
595
596
|
}
|
|
596
597
|
};
|
|
597
598
|
}
|
|
@@ -603,7 +604,8 @@ function taskScope(body) {
|
|
|
603
604
|
...(allowances ? { allowances } : {}),
|
|
604
605
|
...(body.leases === true ? { leases: true } : {}),
|
|
605
606
|
...(gate?.github === true ? { controlPlaneGithub: true } : {}),
|
|
606
|
-
...(gate?.railway === true ? { controlPlaneRailway: true } : {})
|
|
607
|
+
...(gate?.railway === true ? { controlPlaneRailway: true } : {}),
|
|
608
|
+
...(gate?.supabase === true ? { controlPlaneSupabase: true } : {})
|
|
607
609
|
};
|
|
608
610
|
}
|
|
609
611
|
export function parseCliPolicyV2(value) {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A CLI line, normalized: the program found behind its launchers, the command
|
|
3
|
+
* (aliases resolved), flags parsed with the vendor's own tables the way its
|
|
4
|
+
* framework does, positional arguments as $1..$n. Anything the vendor's spec
|
|
5
|
+
* wouldn't accept is a `problem`: the request fails closed.
|
|
6
|
+
*/
|
|
7
|
+
import type { Manifest } from "./manifest.generated.js";
|
|
8
|
+
import type { Normalized, Value } from "./types.generated.js";
|
|
9
|
+
/** Every command the manifest knows, longest first. */
|
|
10
|
+
export declare function knownOps(m: Manifest): string[];
|
|
11
|
+
export declare const present: (value: Value | undefined) => boolean;
|
|
12
|
+
export declare const programName: (word: string) => string;
|
|
13
|
+
/** Strip what runs a program without changing it: env assignments, env, sudo, time, package runners. */
|
|
14
|
+
export declare function stripLaunchers(words: string[], programs: readonly string[]): void;
|
|
15
|
+
export declare function normalizeCli(m: Manifest, argv: readonly string[], given?: string): Normalized | null;
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
// Generated by scripts/generate-control-plane-classifier.mjs. Do not edit.
|
|
2
|
+
/**
|
|
3
|
+
* A CLI line, normalized: the program found behind its launchers, the command
|
|
4
|
+
* (aliases resolved), flags parsed with the vendor's own tables the way its
|
|
5
|
+
* framework does, positional arguments as $1..$n. Anything the vendor's spec
|
|
6
|
+
* wouldn't accept is a `problem`: the request fails closed.
|
|
7
|
+
*/
|
|
8
|
+
const COBRA_TRUE = new Set(["1", "t", "T", "true", "TRUE", "True"]);
|
|
9
|
+
const COBRA_FALSE = new Set(["0", "f", "F", "false", "FALSE", "False"]);
|
|
10
|
+
const tables = new WeakMap();
|
|
11
|
+
/** A CLI's command list and flag table, built once per manifest. */
|
|
12
|
+
function tablesOf(m) {
|
|
13
|
+
const cli = m.capture.cli;
|
|
14
|
+
const hit = tables.get(cli);
|
|
15
|
+
if (hit)
|
|
16
|
+
return hit;
|
|
17
|
+
const ops = [
|
|
18
|
+
...new Set([...Object.keys(cli.flags.commands), ...cli.rules.map((r) => r.match), ...Object.keys(cli.reads)])
|
|
19
|
+
].sort((a, b) => b.split(" ").length - a.split(" ").length);
|
|
20
|
+
// Any flag that takes a value anywhere consumes its value while looking for the command.
|
|
21
|
+
const anyFlags = new Map();
|
|
22
|
+
for (const spec of [...cli.flags.global, ...(cli.legacyFlags ?? []), ...Object.values(cli.flags.commands).flat()])
|
|
23
|
+
if (!anyFlags.has(spec.long) || spec.value === "required")
|
|
24
|
+
anyFlags.set(spec.long, spec);
|
|
25
|
+
const built = { ops, topWords: new Set(ops.map((op) => op.split(" ")[0])), anyFlags: [...anyFlags.values()] };
|
|
26
|
+
tables.set(cli, built);
|
|
27
|
+
return built;
|
|
28
|
+
}
|
|
29
|
+
/** Every command the manifest knows, longest first. */
|
|
30
|
+
export function knownOps(m) {
|
|
31
|
+
return tablesOf(m).ops;
|
|
32
|
+
}
|
|
33
|
+
function flagTable(specs) {
|
|
34
|
+
const long = new Map();
|
|
35
|
+
const short = new Map();
|
|
36
|
+
for (const spec of specs) {
|
|
37
|
+
long.set(spec.long, spec);
|
|
38
|
+
if (spec.short)
|
|
39
|
+
short.set(spec.short, spec);
|
|
40
|
+
}
|
|
41
|
+
return { long, short };
|
|
42
|
+
}
|
|
43
|
+
/** Parse argv with one flag table, the way cobra (or Vercel's arg) does. */
|
|
44
|
+
function parseArgs(words, specs, strict, framework) {
|
|
45
|
+
const { long, short } = flagTable(specs);
|
|
46
|
+
const out = { positional: [], flags: {} };
|
|
47
|
+
const fail = (problem) => {
|
|
48
|
+
out.problem ??= problem;
|
|
49
|
+
};
|
|
50
|
+
const set = (spec, value) => {
|
|
51
|
+
if (spec.value === "optional" && value === "") {
|
|
52
|
+
fail(`--${spec.long}= is empty`);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (spec.value !== "none") {
|
|
56
|
+
const earlier = out.flags[spec.long];
|
|
57
|
+
if (spec.repeat && typeof value === "string")
|
|
58
|
+
out.flags[spec.long] = [
|
|
59
|
+
...(Array.isArray(earlier) ? earlier : typeof earlier === "string" ? [earlier] : []),
|
|
60
|
+
value
|
|
61
|
+
];
|
|
62
|
+
else
|
|
63
|
+
out.flags[spec.long] = value;
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (value === true)
|
|
67
|
+
out.flags[spec.long] = true;
|
|
68
|
+
else if (framework === "arg")
|
|
69
|
+
fail(`--${spec.long} takes no value`);
|
|
70
|
+
else if (COBRA_TRUE.has(value))
|
|
71
|
+
out.flags[spec.long] = true;
|
|
72
|
+
else if (COBRA_FALSE.has(value))
|
|
73
|
+
out.flags[spec.long] = false;
|
|
74
|
+
else
|
|
75
|
+
fail(`--${spec.long} takes true or false`);
|
|
76
|
+
};
|
|
77
|
+
for (let i = 0; i < words.length; i++) {
|
|
78
|
+
const word = words[i];
|
|
79
|
+
if (word === "--") {
|
|
80
|
+
out.positional.push(...words.slice(i + 1));
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
if (word.startsWith("--")) {
|
|
84
|
+
const eq = word.indexOf("=");
|
|
85
|
+
const name = eq < 0 ? word.slice(2) : word.slice(2, eq);
|
|
86
|
+
const spec = long.get(name);
|
|
87
|
+
if (!spec) {
|
|
88
|
+
if (strict)
|
|
89
|
+
fail(`unknown flag --${name}`);
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (eq >= 0)
|
|
93
|
+
set(spec, word.slice(eq + 1));
|
|
94
|
+
else if (spec.value === "required") {
|
|
95
|
+
if (i + 1 >= words.length)
|
|
96
|
+
fail(`--${name} needs a value`);
|
|
97
|
+
else
|
|
98
|
+
set(spec, words[++i]);
|
|
99
|
+
}
|
|
100
|
+
else
|
|
101
|
+
set(spec, true);
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
if (word.startsWith("-") && word.length > 1) {
|
|
105
|
+
const letters = word.slice(1);
|
|
106
|
+
for (let j = 0; j < letters.length; j++) {
|
|
107
|
+
const spec = short.get(letters[j]);
|
|
108
|
+
if (!spec) {
|
|
109
|
+
if (strict)
|
|
110
|
+
fail(`unknown flag -${letters[j]}`);
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
if (spec.value === "none") {
|
|
114
|
+
if (letters[j + 1] === "=") {
|
|
115
|
+
set(spec, letters.slice(j + 2));
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
set(spec, true);
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
const inline = letters.slice(j + 1).replace(/^=/, "");
|
|
122
|
+
if (inline)
|
|
123
|
+
set(spec, inline);
|
|
124
|
+
else if (i + 1 >= words.length)
|
|
125
|
+
fail(`-${letters[j]} needs a value`);
|
|
126
|
+
else
|
|
127
|
+
set(spec, words[++i]);
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
out.positional.push(word);
|
|
133
|
+
}
|
|
134
|
+
return out;
|
|
135
|
+
}
|
|
136
|
+
export const present = (value) => value !== undefined && value !== false && value !== "" && !(Array.isArray(value) && !value.length);
|
|
137
|
+
/** Command words with the vendor's aliases replaced, a level at a time ("projects rm" -> "project remove"). */
|
|
138
|
+
function canonicalWords(words, aliases) {
|
|
139
|
+
const out = [...words];
|
|
140
|
+
for (let depth = 1; depth <= Math.min(4, out.length); depth++) {
|
|
141
|
+
// Own keys only: a command word like "constructor" is no alias.
|
|
142
|
+
const key = out.slice(0, depth).join(" ");
|
|
143
|
+
const found = Object.hasOwn(aliases, key) ? aliases[key] : undefined;
|
|
144
|
+
if (found)
|
|
145
|
+
out.splice(0, depth, ...found.split(" "));
|
|
146
|
+
}
|
|
147
|
+
return out;
|
|
148
|
+
}
|
|
149
|
+
export const programName = (word) => word
|
|
150
|
+
.split(/[\\/]/)
|
|
151
|
+
.pop()
|
|
152
|
+
.replace(/@.*$/, "")
|
|
153
|
+
.replace(/\.(exe|cmd|ps1)$/i, "");
|
|
154
|
+
/** Strip what runs a program without changing it: env assignments, env, sudo, time, package runners. */
|
|
155
|
+
export function stripLaunchers(words, programs) {
|
|
156
|
+
const runners = /^(npx|bunx|pnpx|env|sudo|doas|time|nohup|command|exec|nice)$/;
|
|
157
|
+
for (let guard = 0; guard < 32 && words.length; guard++) {
|
|
158
|
+
const first = words[0];
|
|
159
|
+
if (programs.includes(programName(first)))
|
|
160
|
+
return;
|
|
161
|
+
if (/^[A-Za-z_][A-Za-z0-9_]*=/.test(first))
|
|
162
|
+
words.shift();
|
|
163
|
+
else if (/^(npm|pnpm|yarn)$/.test(first) && /^(exec|x|dlx)$/.test(words[1] ?? ""))
|
|
164
|
+
words.splice(0, 2);
|
|
165
|
+
else if (runners.test(first))
|
|
166
|
+
words.shift();
|
|
167
|
+
else if (first === "--" || /^-/.test(first)) {
|
|
168
|
+
// A runner's own option, and its value when it takes one (npx -p supabase, sudo -u admin).
|
|
169
|
+
const valued = /^(-p|--package|-u|--user|-g|--group|-C|--chdir|-n)$/.test(first);
|
|
170
|
+
words.shift();
|
|
171
|
+
if (valued)
|
|
172
|
+
words.shift();
|
|
173
|
+
}
|
|
174
|
+
else
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/** The command the words name (aliases resolved), or the CLI's default command when the first word isn't one. */
|
|
179
|
+
function findOp(m, words) {
|
|
180
|
+
const cli = m.capture.cli;
|
|
181
|
+
const { ops, topWords, anyFlags } = tablesOf(m);
|
|
182
|
+
const named = canonicalWords(parseArgs(words, anyFlags, false, cli.framework).positional, cli.aliases ?? {});
|
|
183
|
+
const op = ops.find((candidate) => candidate.split(" ").every((part, i) => named[i] === part));
|
|
184
|
+
if (op)
|
|
185
|
+
return { op, defaulted: false };
|
|
186
|
+
const defaulted = cli.defaultCommand !== undefined && (named.length === 0 || !topWords.has(named[0]));
|
|
187
|
+
return { op: defaulted ? cli.defaultCommand : undefined, defaulted };
|
|
188
|
+
}
|
|
189
|
+
/** More arguments than the vendor's usage line allows means something we can't read rides along. */
|
|
190
|
+
function tooManyArgs(usage, count) {
|
|
191
|
+
if (usage === undefined || usage.includes("..."))
|
|
192
|
+
return false;
|
|
193
|
+
return count > (usage.match(/[<[][^>\]]+[>\]]/g) ?? []).filter((p) => !/flags/.test(p)).length;
|
|
194
|
+
}
|
|
195
|
+
export function normalizeCli(m, argv, given) {
|
|
196
|
+
const cli = m.capture.cli;
|
|
197
|
+
const programs = [...cli.programs, ...(cli.aliasPrograms ?? [])];
|
|
198
|
+
const words = [...argv];
|
|
199
|
+
stripLaunchers(words, programs);
|
|
200
|
+
if (!programs.includes(programName(words.shift() ?? ""))) {
|
|
201
|
+
// A known program anywhere in the line, behind a launcher we don't know: never call it a read.
|
|
202
|
+
if (argv.some((word) => programs.includes(programName(word))))
|
|
203
|
+
return { iface: "cli", op: "", params: {}, local: false, remote: false, problem: "unrecognised launcher" };
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
const { op, defaulted } = findOp(m, words);
|
|
207
|
+
const own = op ? (cli.flags.commands[op] ?? []) : [];
|
|
208
|
+
// Deprecated target flags (--linked, --local, --db-url) still work only where the command takes a target.
|
|
209
|
+
const legacy = own.some((flag) => flag.long === "remote") ? (cli.legacyFlags ?? []) : [];
|
|
210
|
+
const exact = parseArgs(words, [...cli.flags.global, ...legacy, ...own], true, cli.framework);
|
|
211
|
+
const opWords = op && !defaulted ? op.split(" ") : [];
|
|
212
|
+
const positional = canonicalWords(exact.positional, cli.aliases ?? {});
|
|
213
|
+
const args = positional.slice(opWords.length);
|
|
214
|
+
const params = { ...exact.flags };
|
|
215
|
+
args.forEach((value, index) => (params[`$${index + 1}`] = value));
|
|
216
|
+
const localFlagsUsed = cli.localFlags.filter((flag) => exact.flags[flag] === true);
|
|
217
|
+
const remote = cli.remoteFlags.some((flag) => present(exact.flags[flag]));
|
|
218
|
+
const problem = given ??
|
|
219
|
+
exact.problem ??
|
|
220
|
+
(op && !opWords.every((part, i) => positional[i] === part) ? "flags moved the command" : undefined) ??
|
|
221
|
+
(op && tooManyArgs(cli.usage?.[op], args.length) ? "more arguments than the command takes" : undefined) ??
|
|
222
|
+
(remote && localFlagsUsed.some((flag) => flag === "local" || !own.some((spec) => spec.long === flag))
|
|
223
|
+
? "remote and local together"
|
|
224
|
+
: undefined);
|
|
225
|
+
// Another folder: its link, not this folder's, decides the target.
|
|
226
|
+
const contextFlag = (cli.contextFlags ?? []).find((flag) => typeof exact.flags[flag] === "string");
|
|
227
|
+
const folderIndex = op ? cli.folderArgs?.[op] : undefined;
|
|
228
|
+
const folder = contextFlag
|
|
229
|
+
? exact.flags[contextFlag]
|
|
230
|
+
: folderIndex !== undefined
|
|
231
|
+
? args[folderIndex]
|
|
232
|
+
: undefined;
|
|
233
|
+
const info = (cli.infoFlags ?? []).some((flag) => exact.flags[flag] === true);
|
|
234
|
+
return {
|
|
235
|
+
iface: "cli",
|
|
236
|
+
op: op ?? positional.slice(0, 2).join(" "),
|
|
237
|
+
params,
|
|
238
|
+
local: info || localFlagsUsed.length > 0,
|
|
239
|
+
remote,
|
|
240
|
+
...(localFlagsUsed.length ? { localFlagsUsed } : {}),
|
|
241
|
+
...(folder ? { folder } : {}),
|
|
242
|
+
...(problem ? { problem } : {})
|
|
243
|
+
};
|
|
244
|
+
}
|