passport-bridge 0.47.0 → 0.48.1
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/cliExec.js +2 -2
- package/dist/cliGitCredential.js +3 -9
- package/dist/cliHook.js +21 -3
- package/dist/cliHookDecide.d.ts +1 -0
- package/dist/cliHookDecide.js +21 -3
- package/dist/connectorKit/engine.generated.js +16 -6
- package/dist/connectorKit/githubCallEffects.generated.d.ts +23 -0
- package/dist/connectorKit/githubCallEffects.generated.js +99 -0
- package/dist/connectorKit/githubDecide.generated.d.ts +57 -0
- package/dist/connectorKit/githubDecide.generated.js +263 -0
- package/dist/{controlPlaneGithubCatalog.generated.d.ts → connectorKit/githubIds.generated.d.ts} +15 -12
- package/dist/{controlPlaneGithubCatalog.generated.js → connectorKit/githubIds.generated.js} +2 -33
- package/dist/connectorKit/http.generated.d.ts +33 -0
- package/dist/connectorKit/http.generated.js +399 -0
- package/dist/connectorKit/manifest.generated.d.ts +10 -1
- package/dist/connectorKit/manifests/github.generated.d.ts +1 -0
- package/dist/connectorKit/manifests/github.generated.js +39 -3
- package/dist/connectorKit/manifests/githubActionList.generated.d.ts +37 -0
- package/dist/connectorKit/manifests/githubActionList.generated.js +28 -0
- package/dist/connectorKit/manifests/githubCapture.generated.js +150 -84
- package/dist/connectorKit/manifests/githubGenerated.generated.d.ts +40 -0
- package/dist/connectorKit/manifests/githubGenerated.generated.js +143 -0
- package/dist/connectorKit/manifests/githubHooks.generated.d.ts +8 -0
- package/dist/connectorKit/manifests/githubHooks.generated.js +229 -29
- package/dist/connectorKit/manifests/githubReads.generated.js +23 -24
- package/dist/connectorKit/shadow.generated.d.ts +4 -10
- package/dist/connectorKit/shadow.generated.js +4 -40
- package/dist/connectorKit/sources/github/actions.generated.d.ts +306 -0
- package/dist/connectorKit/sources/github/actions.generated.js +2 -0
- package/dist/connectorKit/sources/github/catalog.generated.d.ts +2220 -0
- package/dist/connectorKit/sources/github/catalog.generated.js +2 -0
- package/dist/controlPlane.generated.d.ts +20 -17
- package/dist/controlPlane.generated.js +14 -27
- package/dist/controlPlaneActions.generated.d.ts +144 -0
- package/dist/controlPlaneActions.generated.js +169 -0
- package/dist/controlPlaneGuard.d.ts +7 -7
- package/dist/controlPlaneGuard.js +28 -40
- package/dist/cpCli.d.ts +2 -0
- package/dist/cpCli.js +7 -1
- package/dist/execGithubRepo.js +6 -5
- package/dist/gitPush.d.ts +11 -11
- package/dist/gitPush.js +21 -7
- package/dist/kitShadow.d.ts +2 -11
- package/dist/kitShadow.js +2 -7
- package/dist/launcherFastPath.js +2 -0
- package/dist/pluginPin.d.ts +1 -1
- package/dist/pluginPin.js +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/dist/controlPlaneGithub.generated.d.ts +0 -45
- package/dist/controlPlaneGithub.generated.js +0 -101
- package/dist/controlPlaneGithubApi.generated.d.ts +0 -17
- package/dist/controlPlaneGithubApi.generated.js +0 -172
- package/dist/controlPlaneGithubCli.generated.d.ts +0 -104
- package/dist/controlPlaneGithubCli.generated.js +0 -367
- package/dist/controlPlaneGithubWebhook.generated.d.ts +0 -30
- package/dist/controlPlaneGithubWebhook.generated.js +0 -105
package/dist/cliExec.js
CHANGED
|
@@ -19,7 +19,7 @@ import { memberApi } from "./cliClient.js";
|
|
|
19
19
|
import { passportUnreachable } from "./cliOutput.js";
|
|
20
20
|
import { execControlPlaneRefusal, execIdsWanted, execRailwayScope, execSupabaseProject } from "./controlPlaneExec.js";
|
|
21
21
|
import { classifyCommand, UNRECOGNIZED_VERB } from "./cliHookClassify.js";
|
|
22
|
-
import {
|
|
22
|
+
import { ghApiMethod, ghValueFlags, parseArgs as parseGhArgs } from "./connectorKit/githubDecide.generated.js";
|
|
23
23
|
import { redactCommand } from "./cliHookRedact.js";
|
|
24
24
|
import { callerFrom, failure, readBoundedJson, resolveCliAuth, safeApiError, timeoutMs } from "./cliSupport.js";
|
|
25
25
|
import { EXEC_PASSPORT_ENV, EXEC_CARRIERS, EXEC_VENDOR_NAMES, execVendorOf } from "./execVendors.js";
|
|
@@ -64,7 +64,7 @@ export function execFinding(vendor, binary, args) {
|
|
|
64
64
|
// `gh api`: Passport reads the method (a read isn't decided; anything else is decided), never the endpoint.
|
|
65
65
|
if (vendor !== "gh" || carrier || finding.verb.split(" ")[0] !== "api")
|
|
66
66
|
return finding;
|
|
67
|
-
const parsed = parseGhArgs(args,
|
|
67
|
+
const parsed = parseGhArgs(args, ghValueFlags("api"));
|
|
68
68
|
if (parsed.pos[0] !== "api")
|
|
69
69
|
return finding;
|
|
70
70
|
const { method, read } = ghApiMethod(parsed);
|
package/dist/cliGitCredential.js
CHANGED
|
@@ -44,7 +44,7 @@ import { compareVersions } from "./launcherHealth.js";
|
|
|
44
44
|
import { VERSION } from "./version.js";
|
|
45
45
|
import { askingGitCommand, execGitCommand, isPush } from "./gitInvocation.js";
|
|
46
46
|
import { MAX_PUSH_REFS, planKey, planPush } from "./gitPush.js";
|
|
47
|
-
import {
|
|
47
|
+
import { shadowAlongside } from "./kitShadow.js";
|
|
48
48
|
import { takePushDecisions } from "./gitPushDecisions.js";
|
|
49
49
|
import { helperLine, helperProgram, installGitCredential, probeHelper, readGitCredentialState, removeGitCredential } from "./gitCredentialSetup.js";
|
|
50
50
|
import { GIT_OFF, issuesCredentials, offResult } from "./offInV1.js";
|
|
@@ -285,12 +285,10 @@ async function get(args, runtime, deps, input) {
|
|
|
285
285
|
}
|
|
286
286
|
// A push: what it changes, ref by ref. Only the classification leaves this computer.
|
|
287
287
|
const [owner, name] = repo.split("/");
|
|
288
|
-
const lines = [];
|
|
289
288
|
const plan = planPush(asking, {
|
|
290
289
|
cwd: deps.cwd ?? process.cwd(),
|
|
291
290
|
env: runtime.env,
|
|
292
291
|
repo: { owner, repo: name },
|
|
293
|
-
onLine: (line) => void lines.push(line),
|
|
294
292
|
...(deps.run ? { run: deps.run } : {})
|
|
295
293
|
});
|
|
296
294
|
if (!plan)
|
|
@@ -301,14 +299,10 @@ async function get(args, runtime, deps, input) {
|
|
|
301
299
|
if (got.kind !== "refused" || got.code !== "undecided")
|
|
302
300
|
return got.kind === "token" ? answer(got.minted) : refused(got);
|
|
303
301
|
// Passport would issue a push token once it decides the push: every ref, and
|
|
304
|
-
// a block on any stops git here.
|
|
305
|
-
|
|
306
|
-
for (const line of lines)
|
|
307
|
-
shadowGithubLine(line.argv, line.place, line.found);
|
|
308
|
-
// The shadow's counts ride along with these decisions, never waited on: stopped once they're answered.
|
|
302
|
+
// a block on any stops git here.
|
|
303
|
+
// The shadow's counts (Railway's, from earlier lines) ride along with these decisions, never waited on.
|
|
309
304
|
const stopShadow = shadowAlongside(api, runtime.signal);
|
|
310
305
|
const decided = await decidePush(api, plan.classifications, runtime, deps, left).finally(stopShadow);
|
|
311
|
-
shadowAfterDecision();
|
|
312
306
|
if (decided.kind === "block")
|
|
313
307
|
return "quit=1\n";
|
|
314
308
|
if (decided.kind === "own")
|
package/dist/cliHook.js
CHANGED
|
@@ -232,7 +232,9 @@ function refuseUnreadable(args, runtime) {
|
|
|
232
232
|
runtime.stderr.write(`${unreadableMessage(client)}\n`);
|
|
233
233
|
return 2;
|
|
234
234
|
}
|
|
235
|
-
|
|
235
|
+
/** Cursor has no "no decision" answer, and a fail-closed hook that prints nothing blocks the command. */
|
|
236
|
+
const CURSOR_NO_DECISION = { permission: "allow" };
|
|
237
|
+
async function runGuard(args, runtime, deps, seen = { cursor: false }) {
|
|
236
238
|
if (runtime.env.PASSPORT_HOOK_DISABLED === "1")
|
|
237
239
|
return undefined;
|
|
238
240
|
const clock = deps.now ?? Date.now;
|
|
@@ -253,6 +255,7 @@ async function runGuard(args, runtime, deps) {
|
|
|
253
255
|
const declared = value(args, "client");
|
|
254
256
|
const runtimeName = detectRuntime(input, runtime.env, declared);
|
|
255
257
|
const client = outputClient(event, runtimeName);
|
|
258
|
+
seen.cursor = client === "cursor";
|
|
256
259
|
// A command that can't be undone runs only on Passport's allow: out of time or failing, it is refused.
|
|
257
260
|
const local = localIrreversibleVerbs(event.command, machine);
|
|
258
261
|
deps.budget?.read?.();
|
|
@@ -414,8 +417,23 @@ export async function hook(args, runtime, deps = {}) {
|
|
|
414
417
|
}
|
|
415
418
|
let exitCode;
|
|
416
419
|
try {
|
|
417
|
-
if (action === "guard")
|
|
418
|
-
|
|
420
|
+
if (action === "guard") {
|
|
421
|
+
// Cursor reads no output as a failure: when Passport has nothing to say, the guard says allow.
|
|
422
|
+
let wrote = false;
|
|
423
|
+
const seen = { cursor: false };
|
|
424
|
+
const watched = {
|
|
425
|
+
...runtime,
|
|
426
|
+
stdout: {
|
|
427
|
+
write: (chunk) => {
|
|
428
|
+
wrote = true;
|
|
429
|
+
return runtime.stdout.write(chunk);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
exitCode = await runGuard(args, watched, deps, seen);
|
|
434
|
+
if (seen.cursor && !wrote && !exitCode)
|
|
435
|
+
runtime.stdout.write(`${JSON.stringify(CURSOR_NO_DECISION)}\n`);
|
|
436
|
+
}
|
|
419
437
|
else if (action === "flush")
|
|
420
438
|
await runFlush(args, runtime, deps);
|
|
421
439
|
else
|
package/dist/cliHookDecide.d.ts
CHANGED
|
@@ -50,6 +50,7 @@ export type GuardContext = {
|
|
|
50
50
|
deadline: number;
|
|
51
51
|
now: () => number;
|
|
52
52
|
};
|
|
53
|
+
export declare function githubWord(command: string, hosts?: readonly string[]): boolean;
|
|
53
54
|
/** A vendor command's verb in the shape the server reads, or null. */
|
|
54
55
|
export declare function cliVerbOf(finding: CliFinding): string | null;
|
|
55
56
|
/** The basic-platform verbs of a line: a write or delete of a vendor in `vendors`, each once. */
|
package/dist/cliHookDecide.js
CHANGED
|
@@ -23,6 +23,19 @@ import { setShadowDeadline } from "./kitShadowBudget.js";
|
|
|
23
23
|
import { shadowAfterDecision } from "./kitShadow.js";
|
|
24
24
|
/** A cheap check before a classifier loads: `gh …`, a `git … push`, or `railway …`. Every other command pays nothing. */
|
|
25
25
|
const GITHUB_WORD = /(?:^|[\s;&|(/])(?:gh\s|git\s(?:[^;&|]*\s)?push\b)/;
|
|
26
|
+
/** A curl, wget or httpie line that mentions GitHub anywhere (`github`, a `GH_*` variable such as GH_TOKEN or
|
|
27
|
+
* GH_ENTERPRISE_TOKEN, or a configured Enterprise host), quotes and backslashes gone: the classifier decides. */
|
|
28
|
+
const HTTP_WORD = /(?:^|[\s;&|(/])(?:curl|wget|https?)(?:\.exe)?(?:\s|$)/i;
|
|
29
|
+
const GITHUB_SIGNAL = /github|\bGH_[A-Z0-9_]+/i;
|
|
30
|
+
export function githubWord(command, hosts = []) {
|
|
31
|
+
if (GITHUB_WORD.test(command))
|
|
32
|
+
return true;
|
|
33
|
+
const bare = command.replace(/["'\\]/g, "");
|
|
34
|
+
if (GITHUB_WORD.test(bare))
|
|
35
|
+
return true;
|
|
36
|
+
const lower = bare.toLowerCase();
|
|
37
|
+
return HTTP_WORD.test(bare) && (GITHUB_SIGNAL.test(bare) || hosts.some((host) => lower.includes(host.toLowerCase())));
|
|
38
|
+
}
|
|
26
39
|
/** Anywhere, once quotes and backslashes are gone (`"railway"`, `\railway`, `r''ailway`, `npx @railway/cli`):
|
|
27
40
|
* the classifier, which reads the line as the shell would, decides what is really railway. */
|
|
28
41
|
const railwayWord = (command) => /railway/i.test(command.replace(/["'\\]/g, ""));
|
|
@@ -71,7 +84,7 @@ export function localRefusal(verb, why) {
|
|
|
71
84
|
function asking(context, local) {
|
|
72
85
|
const { cp, command } = context;
|
|
73
86
|
return {
|
|
74
|
-
github: Boolean(cp?.platforms.github) &&
|
|
87
|
+
github: Boolean(cp?.platforms.github) && githubWord(command, cp?.githubHosts),
|
|
75
88
|
railway: Boolean(cp?.platforms.railway) && railwayWord(command),
|
|
76
89
|
supabase: Boolean(cp?.platforms.supabase) && supabaseWord(command),
|
|
77
90
|
verbs: [
|
|
@@ -155,11 +168,16 @@ async function askVerbs(verbs, open, extra, signal) {
|
|
|
155
168
|
const { askCliVerb } = await import("./controlPlaneCli.js");
|
|
156
169
|
return Promise.all(verbs.map(([vendor, verb]) => askCliVerb(api, vendor, verb, extra, signal)));
|
|
157
170
|
}
|
|
171
|
+
/** The folder's repository and branch, and the workspace's Enterprise hosts (Passport's copy). */
|
|
172
|
+
function placeOf(cp, context) {
|
|
173
|
+
const hosts = context.cp?.githubHosts;
|
|
174
|
+
return { ...cp.gitPlace(context.cwd), ...(hosts?.length ? { apiHosts: hosts } : {}) };
|
|
175
|
+
}
|
|
158
176
|
/** GitHub's part of a line. Every `git push` is decided here, ref by ref, resolved as git will in this folder. */
|
|
159
177
|
async function githubLinePlan(context, open, extra, signal) {
|
|
160
178
|
const cp = await import("./controlPlaneGuard.js");
|
|
161
179
|
const where = context.cwd ? { cwd: context.cwd } : undefined;
|
|
162
|
-
const commands = cp.classifyCommands(context.command, cp
|
|
180
|
+
const commands = cp.classifyCommands(context.command, placeOf(cp, context), where);
|
|
163
181
|
const label = commands.flatMap((entry) => entry.classifications)[0]?.summary;
|
|
164
182
|
const api = label === undefined ? null : await open();
|
|
165
183
|
return { label, decided: api ? await cp.decideCommands(api, commands, extra, signal) : null };
|
|
@@ -197,7 +215,7 @@ async function foundOffline(context, missed) {
|
|
|
197
215
|
if (missed.github) {
|
|
198
216
|
const cp = await import("./controlPlaneGuard.js");
|
|
199
217
|
const where = context.cwd ? { cwd: context.cwd } : undefined;
|
|
200
|
-
for (const entry of cp.classifyCommands(context.command, cp
|
|
218
|
+
for (const entry of cp.classifyCommands(context.command, placeOf(cp, context), where)) {
|
|
201
219
|
for (const one of entry.classifications) {
|
|
202
220
|
found.push({ platform: "github", nodeId: one.nodeId, actionKey: one.actionKey, summary: one.summary });
|
|
203
221
|
}
|
|
@@ -277,7 +277,8 @@ function listWhereOne(m, part, params, each) {
|
|
|
277
277
|
...typeChain(m, part.on).flatMap((t) => [m.nodes[t].key].flat()),
|
|
278
278
|
part.target?.key,
|
|
279
279
|
part.target?.name,
|
|
280
|
-
part.summary
|
|
280
|
+
part.summary,
|
|
281
|
+
...(part.summaryElse ?? [])
|
|
281
282
|
].filter((t) => typeof t === "string");
|
|
282
283
|
return templates
|
|
283
284
|
.flatMap(placeholders)
|
|
@@ -299,7 +300,7 @@ function buildSql(m, part, p, at, out) {
|
|
|
299
300
|
? SQL_LABEL[finding.category]
|
|
300
301
|
: m.actions.find((a) => a.key === actionKey).label;
|
|
301
302
|
const t = finding.table ? { type: "table", key: finding.table, name: finding.table } : undefined;
|
|
302
|
-
const where = part.summary ?
|
|
303
|
+
const where = part.summary ? summaryOf(part, part.summary, p) : "";
|
|
303
304
|
out.push({
|
|
304
305
|
nodeId: at.nodeId,
|
|
305
306
|
actionKey,
|
|
@@ -318,7 +319,8 @@ function build(m, part, params, context, hooks, each) {
|
|
|
318
319
|
p[name] = p[source];
|
|
319
320
|
if (listWhereOne(m, part, p, each))
|
|
320
321
|
return UNCLASSIFIED;
|
|
321
|
-
|
|
322
|
+
// "platform": the platform's own node (an account-level operation: keys, gists, notifications).
|
|
323
|
+
const at = part.on === "platform" ? { nodeId: nodeId(m.platform), chain: [] } : nodeChain(m, part.on, p, context, hooks);
|
|
322
324
|
if (at.unresolved)
|
|
323
325
|
return UNCLASSIFIED;
|
|
324
326
|
const out = [];
|
|
@@ -328,12 +330,17 @@ function build(m, part, params, context, hooks, each) {
|
|
|
328
330
|
out.push({
|
|
329
331
|
nodeId: at.nodeId,
|
|
330
332
|
actionKey: part.action,
|
|
331
|
-
summary:
|
|
333
|
+
summary: summaryOf(part, part.summary ?? m.actions.find((a) => a.key === part.action)?.label ?? part.action, p),
|
|
332
334
|
nodes: at.chain,
|
|
333
335
|
...(t ? { target: t } : {})
|
|
334
336
|
});
|
|
335
337
|
return out;
|
|
336
338
|
}
|
|
339
|
+
/** A rule's summary: the first template that fills, else the last rendered with "(unknown)" for what doesn't. */
|
|
340
|
+
function summaryOf(part, summary, p) {
|
|
341
|
+
const all = [summary, ...(part.summaryElse ?? [])];
|
|
342
|
+
return fill(all, p) ?? render(all[all.length - 1], p);
|
|
343
|
+
}
|
|
337
344
|
/** What an unnamed request hit, coarse (`controlPlaneUnnamed.ts`): an API call's method and path template, a command
|
|
338
345
|
* line's program and the words the CLI itself uses, up to the first it doesn't. Nothing for an MCP tool. */
|
|
339
346
|
function unnamedOf(m, n, ops) {
|
|
@@ -408,10 +415,13 @@ function decideRequest(m, n, context, hooks, override) {
|
|
|
408
415
|
found: [unclassified(m, n, canonical(m, n, rule, context, override).params, context, hooks, problem ?? n.problem)],
|
|
409
416
|
via: "failed"
|
|
410
417
|
});
|
|
411
|
-
if (n.problem)
|
|
412
|
-
return failed();
|
|
413
418
|
const spec = m.capture[n.iface];
|
|
414
419
|
const candidates = spec.rules.filter((rule) => rule.match === n.op);
|
|
420
|
+
// "none": an op it doesn't know names nothing, and nor does a listed read whatever its flags.
|
|
421
|
+
if (spec.unknown === "none" && n.op && candidates.length === 0)
|
|
422
|
+
return Object.hasOwn(spec.reads, n.op) ? { found: [], via: "read" } : { found: [], via: "none" };
|
|
423
|
+
if (n.problem)
|
|
424
|
+
return failed();
|
|
415
425
|
if (candidates.length === 0)
|
|
416
426
|
return Object.hasOwn(spec.reads, n.op) ? { found: [], via: "read" } : failed();
|
|
417
427
|
if (n.iface === "cli" && n.local)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Effect } from "../controlPlaneActions.generated.js";
|
|
2
|
+
/**
|
|
3
|
+
* One GitHub call's effects from its arguments (docs/design/control-plane.md, "Action model", Layer 2 inputs): they
|
|
4
|
+
* replace the action's defaults for that call. Only what the arguments settle is decided here; anything unread keeps
|
|
5
|
+
* the defaults, which already assume the worst (a possible public audience, a possible later run). Reads names and
|
|
6
|
+
* flags only, never values beyond the few words that decide (visibility, role).
|
|
7
|
+
*/
|
|
8
|
+
/** What a call's arguments say, from whichever interface sent it. `flags` are gh's (`--public`), `fields` a body's. */
|
|
9
|
+
export type CallArgs = {
|
|
10
|
+
fields?: Record<string, unknown>;
|
|
11
|
+
flags?: readonly string[];
|
|
12
|
+
};
|
|
13
|
+
/** What decide reads from a call beyond its effects: the deployment environment it names, for production. */
|
|
14
|
+
export type CallFacts = {
|
|
15
|
+
effects?: Effect[];
|
|
16
|
+
environment?: string;
|
|
17
|
+
/** Grants admin or owner: it reaches everything beneath where it is granted, so it counts as production. */
|
|
18
|
+
elevated?: true;
|
|
19
|
+
};
|
|
20
|
+
/** gh's words as call arguments: its flags by name, and `-f`/`-F` fields (`gh api`) with true and false read. */
|
|
21
|
+
export declare function ghCallArgs(argv: readonly string[]): CallArgs;
|
|
22
|
+
/** This call's facts; `effects` absent when its arguments change nothing about the defaults. */
|
|
23
|
+
export declare function githubCallFacts(actionKey: string, args: CallArgs, bodyRead: boolean): CallFacts;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { GITHUB_EFFECTS } from "./manifests/githubActionList.generated.js";
|
|
2
|
+
/** New repositories: public unless the call says private or internal (the REST default is `private: false`). */
|
|
3
|
+
const CREATES_REPO = new Set([
|
|
4
|
+
"github.repos.create_for_authenticated_user",
|
|
5
|
+
"github.repos.create_in_org",
|
|
6
|
+
"github.repos.create_using_template",
|
|
7
|
+
"github.codespaces.publish_for_authenticated_user"
|
|
8
|
+
]);
|
|
9
|
+
/** Updates that can't make a repository public when the body is read: a public one is `github.repo.public`. */
|
|
10
|
+
const UPDATES_REPO = new Set(["github.repos.update"]);
|
|
11
|
+
/** Grants that hand someone a role: admin or owner is the most access GitHub gives. */
|
|
12
|
+
const GRANTS_ROLE = new Set([
|
|
13
|
+
"github.org.invite",
|
|
14
|
+
"github.org.owner",
|
|
15
|
+
"github.repo.collaborator",
|
|
16
|
+
"github.team.member",
|
|
17
|
+
"github.team.repo",
|
|
18
|
+
"github.orgs.update_membership_for_authenticated_user"
|
|
19
|
+
]);
|
|
20
|
+
const ELEVATED = new Set(["admin", "owner", "maintain"]);
|
|
21
|
+
/** Calls that name a deployment environment, read for production. */
|
|
22
|
+
const NAMES_ENVIRONMENT = new Set(["github.repos.create_deployment", "github.repos.create_or_update_environment"]);
|
|
23
|
+
const text = (value) => (typeof value === "string" ? value.trim().toLowerCase() : undefined);
|
|
24
|
+
const hasFlag = (args, ...names) => names.some((name) => args.flags?.includes(name));
|
|
25
|
+
/** Whether a new repository or gist is public: true, false, or unknown when nothing says. */
|
|
26
|
+
function publicOf(args) {
|
|
27
|
+
const fields = args.fields ?? {};
|
|
28
|
+
const visibility = text(fields.visibility);
|
|
29
|
+
if (visibility === "public" || fields.private === false || fields.public === true)
|
|
30
|
+
return true;
|
|
31
|
+
if (visibility === "private" || visibility === "internal" || fields.private === true)
|
|
32
|
+
return false;
|
|
33
|
+
if (hasFlag(args, "--public", "-p"))
|
|
34
|
+
return true;
|
|
35
|
+
if (hasFlag(args, "--private", "--internal"))
|
|
36
|
+
return false;
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
/** The defaults with their possible public audience settled one way or the other. */
|
|
40
|
+
function settleAudience(defaults, isPublic) {
|
|
41
|
+
return defaults.map((effect) => {
|
|
42
|
+
if (!effect.audience || !effect.possible)
|
|
43
|
+
return effect;
|
|
44
|
+
const { audience: _audience, possible: _possible, ...rest } = effect;
|
|
45
|
+
return isPublic ? { ...rest, audience: "public" } : rest;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/** gh's words as call arguments: its flags by name, and `-f`/`-F` fields (`gh api`) with true and false read. */
|
|
49
|
+
export function ghCallArgs(argv) {
|
|
50
|
+
const flags = [];
|
|
51
|
+
const fields = {};
|
|
52
|
+
for (let index = 0; index < argv.length; index++) {
|
|
53
|
+
const word = argv[index];
|
|
54
|
+
if (!word.startsWith("-"))
|
|
55
|
+
continue;
|
|
56
|
+
const name = word.split("=", 1)[0];
|
|
57
|
+
flags.push(name);
|
|
58
|
+
if (["-f", "-F", "--field", "--raw-field"].includes(name)) {
|
|
59
|
+
const pair = word.includes("=") && name.startsWith("--") ? word.slice(name.length + 1) : argv[++index];
|
|
60
|
+
const at = pair?.indexOf("=") ?? -1;
|
|
61
|
+
if (pair && at > 0) {
|
|
62
|
+
const value = pair.slice(at + 1);
|
|
63
|
+
fields[pair.slice(0, at)] = value === "true" ? true : value === "false" ? false : value;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return { flags, fields };
|
|
68
|
+
}
|
|
69
|
+
/** This call's facts; `effects` absent when its arguments change nothing about the defaults. */
|
|
70
|
+
export function githubCallFacts(actionKey, args, bodyRead) {
|
|
71
|
+
const defaults = GITHUB_EFFECTS.get(actionKey) ?? [];
|
|
72
|
+
const facts = {};
|
|
73
|
+
const environment = NAMES_ENVIRONMENT.has(actionKey) ? text(args.fields?.environment) : undefined;
|
|
74
|
+
if (environment)
|
|
75
|
+
facts.environment = environment;
|
|
76
|
+
if (CREATES_REPO.has(actionKey)) {
|
|
77
|
+
// gh asks for a visibility; the REST and MCP default is public.
|
|
78
|
+
const isPublic = publicOf(args) ?? (bodyRead && !args.flags ? true : undefined);
|
|
79
|
+
if (isPublic !== undefined)
|
|
80
|
+
facts.effects = settleAudience(defaults, isPublic);
|
|
81
|
+
}
|
|
82
|
+
else if (UPDATES_REPO.has(actionKey) && bodyRead) {
|
|
83
|
+
facts.effects = settleAudience(defaults, publicOf(args) === true);
|
|
84
|
+
}
|
|
85
|
+
else if (actionKey === "github.gists.create" && publicOf(args) === true) {
|
|
86
|
+
facts.effects = [{ verb: "create", object: "code", audience: "public" }];
|
|
87
|
+
}
|
|
88
|
+
else if (GRANTS_ROLE.has(actionKey)) {
|
|
89
|
+
const role = text(args.fields?.role) ?? text(args.fields?.permission);
|
|
90
|
+
// Admin or owner reaches everything beneath where it is granted: a change of access, decided as production.
|
|
91
|
+
if (role && ELEVATED.has(role)) {
|
|
92
|
+
facts.elevated = true;
|
|
93
|
+
if (!defaults.some((effect) => effect.object === "access")) {
|
|
94
|
+
facts.effects = [...defaults, { verb: "create", object: "access" }];
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return facts;
|
|
99
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GitHub's decision through the kit (docs/design/v23/github-kit.md, Phase 1): what one request does, by the kit's
|
|
3
|
+
* GitHub manifest (`manifests/github.ts`) and its hooks (`manifests/githubHooks.ts`), in the shape the guard, the
|
|
4
|
+
* credential helper, `passport exec` and the gateway read. Pure and synchronous; the bridge ships a copy.
|
|
5
|
+
*
|
|
6
|
+
* `context` is what the inventory knows of a repository's branches (the server). Without one (the guard on a
|
|
7
|
+
* computer) every named branch is its own node, which the server maps to its pattern node.
|
|
8
|
+
*
|
|
9
|
+
* A target is the canonical string (`githubTarget`): JSON of the named fields, the kit's `ActionTarget.key`, so a
|
|
10
|
+
* decision records the same digest whichever side classified it.
|
|
11
|
+
*/
|
|
12
|
+
import type { GithubClassification, GithubContext, GithubRepo, GithubRequest } from "./githubIds.generated.js";
|
|
13
|
+
export type { GithubClassification, GithubContext, GithubRepo, GithubRequest } from "./githubIds.generated.js";
|
|
14
|
+
/**
|
|
15
|
+
* Every consequential thing one request does, in order: one entry, except a `git push` naming several refs (one per
|
|
16
|
+
* ref, worst first). Empty when nothing is consequential. Enforcement decides each and blocks when any one is.
|
|
17
|
+
*/
|
|
18
|
+
export declare function classifyGithubAll(request: GithubRequest, context?: GithubContext): GithubClassification[];
|
|
19
|
+
/** A push's order: a delete, then a force-push, a tag, a push (anything else ranks before them). */
|
|
20
|
+
export declare const pushRank: (found: Pick<GithubClassification, "actionKey">) => number;
|
|
21
|
+
/** The single most consequential thing a request does, or null. For a command line, use `classifyGithubAll`. */
|
|
22
|
+
export declare function classifyGithub(request: GithubRequest, context?: GithubContext): GithubClassification | null;
|
|
23
|
+
export type GithubCliArgs = {
|
|
24
|
+
argv: string[];
|
|
25
|
+
cwdRepo?: GithubRepo;
|
|
26
|
+
currentBranch?: string;
|
|
27
|
+
};
|
|
28
|
+
/** Whether a command line is `git push` (git's own options before it don't count). */
|
|
29
|
+
export declare function isGitPush(argv: readonly string[]): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Every ref a `git push` moves, one classification each, worst first, with the worst case for what it can't name;
|
|
32
|
+
* null when it isn't a push to GitHub (or is a dry run).
|
|
33
|
+
*/
|
|
34
|
+
export declare function classifyGitPushRefs(args: GithubCliArgs, context?: GithubContext): GithubClassification[] | null;
|
|
35
|
+
/** The worst a push to branches it doesn't name can do: force-push and delete, on the repository. */
|
|
36
|
+
export declare function worstCasePush(r: GithubRepo, why: string): GithubClassification[];
|
|
37
|
+
export type Parsed = {
|
|
38
|
+
pos: string[];
|
|
39
|
+
opts: Array<[string, string | true]>;
|
|
40
|
+
};
|
|
41
|
+
/** The options of a gh command that take a value, as `-x` and `--long`, from the kit's flag table. */
|
|
42
|
+
export declare function ghValueFlags(command: string): ReadonlySet<string>;
|
|
43
|
+
/** Words and options of one command. `valueFlags` are the options that take the next word as their value. */
|
|
44
|
+
export declare function parseArgs(args: readonly string[], valueFlags: ReadonlySet<string>): Parsed;
|
|
45
|
+
export declare const values: (parsed: Parsed, ...names: string[]) => string[];
|
|
46
|
+
export declare const lastValue: (parsed: Parsed, ...names: string[]) => string | undefined;
|
|
47
|
+
export declare const hasFlag: (parsed: Parsed, ...names: string[]) => boolean;
|
|
48
|
+
/**
|
|
49
|
+
* How `gh api` is read when only its method matters: GET or HEAD (no method, or one of those, and with no method no
|
|
50
|
+
* fields, as gh then sends a POST) is a read; any other method, or a body from `--input`, is a write.
|
|
51
|
+
*/
|
|
52
|
+
export declare function ghApiMethod(parsed: Parsed): {
|
|
53
|
+
method: string;
|
|
54
|
+
read: boolean;
|
|
55
|
+
};
|
|
56
|
+
/** A REST path's segments, decoded, without the host, query or fragment. */
|
|
57
|
+
export declare function apiSegments(path: string): string[];
|