passport-bridge 0.47.0 → 0.48.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.
Files changed (53) hide show
  1. package/dist/cliExec.js +2 -2
  2. package/dist/cliGitCredential.js +3 -9
  3. package/dist/cliHookDecide.d.ts +1 -0
  4. package/dist/cliHookDecide.js +21 -3
  5. package/dist/connectorKit/engine.generated.js +16 -6
  6. package/dist/connectorKit/githubDecide.generated.d.ts +57 -0
  7. package/dist/connectorKit/githubDecide.generated.js +247 -0
  8. package/dist/{controlPlaneGithubCatalog.generated.d.ts → connectorKit/githubIds.generated.d.ts} +8 -12
  9. package/dist/{controlPlaneGithubCatalog.generated.js → connectorKit/githubIds.generated.js} +2 -33
  10. package/dist/connectorKit/http.generated.d.ts +33 -0
  11. package/dist/connectorKit/http.generated.js +399 -0
  12. package/dist/connectorKit/manifest.generated.d.ts +10 -1
  13. package/dist/connectorKit/manifests/github.generated.d.ts +1 -0
  14. package/dist/connectorKit/manifests/github.generated.js +39 -3
  15. package/dist/connectorKit/manifests/githubActionList.generated.d.ts +30 -0
  16. package/dist/connectorKit/manifests/githubActionList.generated.js +22 -0
  17. package/dist/connectorKit/manifests/githubCapture.generated.js +150 -84
  18. package/dist/connectorKit/manifests/githubGenerated.generated.d.ts +40 -0
  19. package/dist/connectorKit/manifests/githubGenerated.generated.js +143 -0
  20. package/dist/connectorKit/manifests/githubHooks.generated.d.ts +8 -0
  21. package/dist/connectorKit/manifests/githubHooks.generated.js +229 -29
  22. package/dist/connectorKit/manifests/githubReads.generated.js +23 -24
  23. package/dist/connectorKit/shadow.generated.d.ts +4 -10
  24. package/dist/connectorKit/shadow.generated.js +4 -40
  25. package/dist/connectorKit/sources/github/actions.generated.d.ts +35 -0
  26. package/dist/connectorKit/sources/github/actions.generated.js +2 -0
  27. package/dist/connectorKit/sources/github/catalog.generated.d.ts +2220 -0
  28. package/dist/connectorKit/sources/github/catalog.generated.js +2 -0
  29. package/dist/controlPlane.generated.d.ts +5 -8
  30. package/dist/controlPlane.generated.js +5 -3
  31. package/dist/controlPlaneGuard.d.ts +7 -7
  32. package/dist/controlPlaneGuard.js +28 -40
  33. package/dist/cpCli.d.ts +2 -0
  34. package/dist/cpCli.js +7 -1
  35. package/dist/execGithubRepo.js +6 -5
  36. package/dist/gitPush.d.ts +1 -11
  37. package/dist/gitPush.js +2 -5
  38. package/dist/kitShadow.d.ts +2 -11
  39. package/dist/kitShadow.js +2 -7
  40. package/dist/pluginPin.d.ts +1 -1
  41. package/dist/pluginPin.js +1 -1
  42. package/dist/version.d.ts +1 -1
  43. package/dist/version.js +1 -1
  44. package/npm-shrinkwrap.json +2 -2
  45. package/package.json +1 -1
  46. package/dist/controlPlaneGithub.generated.d.ts +0 -45
  47. package/dist/controlPlaneGithub.generated.js +0 -101
  48. package/dist/controlPlaneGithubApi.generated.d.ts +0 -17
  49. package/dist/controlPlaneGithubApi.generated.js +0 -172
  50. package/dist/controlPlaneGithubCli.generated.d.ts +0 -104
  51. package/dist/controlPlaneGithubCli.generated.js +0 -367
  52. package/dist/controlPlaneGithubWebhook.generated.d.ts +0 -30
  53. 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 { GH_VALUES, ghApiMethod, parseArgs as parseGhArgs } from "./controlPlaneGithubCli.generated.js";
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, GH_VALUES.api);
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);
@@ -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 { beginShadowLine, shadowAfterDecision, shadowAlongside, shadowGithubLine } from "./kitShadow.js";
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. Deciding it here (no guard did), the shadow run reads it too.
305
- beginShadowLine();
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")
@@ -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. */
@@ -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) && GITHUB_WORD.test(command),
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.gitPlace(context.cwd), where);
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.gitPlace(context.cwd), where)) {
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 ? render(part.summary, p) : "";
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
- const at = nodeChain(m, part.on, p, context, hooks);
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: render(part.summary ?? m.actions.find((a) => a.key === part.action)?.label ?? part.action, p),
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,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[];
@@ -0,0 +1,247 @@
1
+ // Generated by scripts/generate-control-plane-classifier.mjs. Do not edit.
2
+ /**
3
+ * GitHub's decision through the kit (docs/design/v23/github-kit.md, Phase 1): what one request does, by the kit's
4
+ * GitHub manifest (`manifests/github.ts`) and its hooks (`manifests/githubHooks.ts`), in the shape the guard, the
5
+ * credential helper, `passport exec` and the gateway read. Pure and synchronous; the bridge ships a copy.
6
+ *
7
+ * `context` is what the inventory knows of a repository's branches (the server). Without one (the guard on a
8
+ * computer) every named branch is its own node, which the server maps to its pattern node.
9
+ *
10
+ * A target is the canonical string (`githubTarget`): JSON of the named fields, the kit's `ActionTarget.key`, so a
11
+ * decision records the same digest whichever side classified it.
12
+ */
13
+ import { classify } from "./engine.generated.js";
14
+ import { httpLineOf, urlParts } from "./http.generated.js";
15
+ import { GITHUB } from "./manifests/github.generated.js";
16
+ import { githubHooks, worstCasePush as kitWorstCase } from "./manifests/githubHooks.generated.js";
17
+ import { GH_COMMANDS } from "./manifests/githubReads.generated.js";
18
+ /** Without branches the hooks hold nothing per call: built once. */
19
+ let exactHooks;
20
+ function asKit(request, org) {
21
+ if (request.interface === "mcp")
22
+ return { request, context: {} };
23
+ if (request.interface === "api")
24
+ return {
25
+ request: {
26
+ interface: "api",
27
+ method: request.method,
28
+ url: request.path,
29
+ ...(request.body ? { body: request.body } : {})
30
+ },
31
+ context: {}
32
+ };
33
+ const linked = {};
34
+ if (request.cwdRepo)
35
+ Object.assign(linked, { owner: request.cwdRepo.owner, repo: request.cwdRepo.repo });
36
+ if (request.currentBranch)
37
+ linked.branch = request.currentBranch;
38
+ if (org)
39
+ linked.org = org;
40
+ return { request: { interface: "cli", argv: request.argv }, context: { linked } };
41
+ }
42
+ function asGithub(found) {
43
+ return {
44
+ nodeId: found.nodeId,
45
+ actionKey: found.actionKey,
46
+ summary: found.summary,
47
+ ...(found.target ? { target: found.target.key } : {}),
48
+ ...(found.unnamed ? { unnamed: found.unnamed } : {})
49
+ };
50
+ }
51
+ /**
52
+ * Every consequential thing one request does, in order: one entry, except a `git push` naming several refs (one per
53
+ * ref, worst first). Empty when nothing is consequential. Enforcement decides each and blocks when any one is.
54
+ */
55
+ export function classifyGithubAll(request, context) {
56
+ const hooks = context
57
+ ? githubHooks(GITHUB, { known: context.knownBranches, defaultBranch: context.defaultBranch })
58
+ : (exactHooks ??= githubHooks(GITHUB));
59
+ if (request.interface === "cli") {
60
+ const line = httpLineOf(request.argv, request.stdin === true);
61
+ if (line)
62
+ return githubHttp(line, request.argv, [...(request.apiHosts ?? []), ...(context?.apiHosts ?? [])], hooks);
63
+ }
64
+ const kit = asKit(request, context?.org);
65
+ const found = classify(GITHUB, kit.request, kit.context, hooks);
66
+ return (found === null ? [] : Array.isArray(found) ? found : [found]).map(asGithub);
67
+ }
68
+ /* ------------------------------------------------------------------ */
69
+ /* Raw HTTP to GitHub's API (Phase 3): curl, wget, httpie */
70
+ /* ------------------------------------------------------------------ */
71
+ /** GitHub.com's API hosts (release assets upload to their own); an Enterprise Server's come from the connection
72
+ * (`GithubContext.apiHosts`). */
73
+ const API_HOST = "api.github.com";
74
+ const DOTCOM_HOSTS = [API_HOST, "uploads.github.com"];
75
+ /** A word that says a line is about GitHub even when its URL can't be read: `github` anywhere (`$GITHUB_TOKEN`, an
76
+ * Accept header, a host) or a `GH_*` variable (`$GH_TOKEN`, `$GH_ENTERPRISE_TOKEN`). Without one, it isn't claimed. */
77
+ const GITHUB_SIGNAL = /github|\bGH_[A-Z0-9_]+/i;
78
+ /** A request Passport can't place: Unclassified on GitHub's own node, naming only the tool. */
79
+ function targetUnknown(line) {
80
+ const command = line.tool === "httpie" ? "http" : line.tool;
81
+ return {
82
+ nodeId: "github",
83
+ actionKey: "github.unclassified",
84
+ summary: `Unclassified action: ${command} (target unknown)`,
85
+ unnamed: { via: "cli", command }
86
+ };
87
+ }
88
+ /** The API path a URL names on one of GitHub's API hosts (`/api/v3` and `/api/graphql` on an Enterprise Server). */
89
+ function apiPath(url, hosts) {
90
+ const parts = urlParts(url);
91
+ if (!parts || !hosts.includes(parts.host))
92
+ return null;
93
+ if (DOTCOM_HOSTS.includes(parts.host))
94
+ return parts.path;
95
+ if (parts.path === "/api/graphql")
96
+ return "/graphql";
97
+ return parts.path.startsWith("/api/v3/") ? parts.path.slice("/api/v3".length) : null;
98
+ }
99
+ /** API rules whose condition reads the body (`body` and a `when`): a body that can't be read may decide which action
100
+ * it is. A condition on the path (a workflow file) is read either way. */
101
+ const bodyRules = GITHUB.capture.api.rules
102
+ .filter((rule) => rule.body?.length && rule.when && Object.keys(rule.when).some((name) => name !== "path"))
103
+ .map((rule) => {
104
+ const [method, template] = rule.match.split(" ");
105
+ return { method, re: new RegExp(`^${template.replace(/\{\w+\}/g, "[^/]+")}$`) };
106
+ });
107
+ const bodyDecides = (method, path) => bodyRules.some((rule) => rule.method === method && rule.re.test(path.replace(/\/+$/, "")));
108
+ /**
109
+ * A curl, wget or httpie line: decided as the API request it sends, by the same rules and generated catalog as every
110
+ * route, so one rule covers `gh`, MCP and raw HTTP. Headers, cookies and query strings are never read. A line whose
111
+ * URL can't be read (a variable, several URLs) fails closed when it is about GitHub; a body that can't be read names
112
+ * no exact target, and fails closed where the body decides the action.
113
+ */
114
+ function githubHttp(line, argv, enterprise, hooks) {
115
+ const hosts = [...DOTCOM_HOSTS, ...enterprise.map((host) => host.toLowerCase().replace(/\.$/, ""))];
116
+ const about = argv.some((word) => GITHUB_SIGNAL.test(word) || hosts.some((host) => word.toLowerCase().includes(host)));
117
+ // A line about GitHub whose target can't be read (no URL, a variable, several, a config file) fails closed.
118
+ if (line.problem)
119
+ return about ? [targetUnknown(line)] : [];
120
+ if (!urlParts(line.url))
121
+ return about ? [targetUnknown(line)] : [];
122
+ const path = apiPath(line.url, hosts);
123
+ // A GitHub API host, but a path outside its API (an Enterprise Server's web pages): Passport can't place it.
124
+ if (path === null)
125
+ return hosts.includes(urlParts(line.url).host) ? [targetUnknown(line)] : [];
126
+ if ((line.method === "GET" || line.method === "HEAD") && !line.opaque)
127
+ return [];
128
+ if (line.opaque && (path === "/graphql" || bodyDecides(line.method, path)))
129
+ return [targetUnknown(line)];
130
+ const found = classify(GITHUB, {
131
+ interface: "api",
132
+ method: line.method,
133
+ url: path,
134
+ ...(line.opaque ? { body: { force: true } } : line.body ? { body: line.body } : {})
135
+ }, {}, hooks);
136
+ const list = (found === null ? [] : [found].flat()).map(asGithub);
137
+ // A body that can't be read names no exact target.
138
+ return line.opaque ? list.map(({ target: _target, ...rest }) => rest) : list;
139
+ }
140
+ const PUSH_ORDER = ["github.branch.delete", "github.branch.force", "github.repo.tag", "github.branch.push"];
141
+ /** A push's order: a delete, then a force-push, a tag, a push (anything else ranks before them). */
142
+ export const pushRank = (found) => PUSH_ORDER.indexOf(found.actionKey);
143
+ /** The single most consequential thing a request does, or null. For a command line, use `classifyGithubAll`. */
144
+ export function classifyGithub(request, context) {
145
+ return [...classifyGithubAll(request, context)].sort((a, b) => pushRank(a) - pushRank(b))[0] ?? null;
146
+ }
147
+ const programOf = (word) => (word ?? "").replace(/^.*\//, "").replace(/\.exe$/i, "");
148
+ const GIT_GLOBAL_VALUES = new Set(["-C", "-c", "--git-dir", "--work-tree", "--namespace"]);
149
+ /** Whether a command line is `git push` (git's own options before it don't count). */
150
+ export function isGitPush(argv) {
151
+ if (programOf(argv[0]) !== "git")
152
+ return false;
153
+ let index = 1;
154
+ while ((argv[index] ?? "").startsWith("-"))
155
+ index += GIT_GLOBAL_VALUES.has(argv[index]) ? 2 : 1;
156
+ return argv[index] === "push";
157
+ }
158
+ /**
159
+ * Every ref a `git push` moves, one classification each, worst first, with the worst case for what it can't name;
160
+ * null when it isn't a push to GitHub (or is a dry run).
161
+ */
162
+ export function classifyGitPushRefs(args, context) {
163
+ if (!isGitPush(args.argv))
164
+ return null;
165
+ const found = classifyGithubAll({ interface: "cli", ...args }, context);
166
+ return found.length ? found : null;
167
+ }
168
+ /** The worst a push to branches it doesn't name can do: force-push and delete, on the repository. */
169
+ export function worstCasePush(r, why) {
170
+ return kitWorstCase(r, why).map(asGithub);
171
+ }
172
+ /** The options of a gh command that take a value, as `-x` and `--long`, from the kit's flag table. */
173
+ export function ghValueFlags(command) {
174
+ const flags = Object.hasOwn(GH_COMMANDS, command) ? GH_COMMANDS[command] : [];
175
+ const out = new Set(["-R", "--repo"]);
176
+ for (const flag of flags) {
177
+ if (flag.value !== "required")
178
+ continue;
179
+ out.add(`--${flag.long}`);
180
+ if (flag.short)
181
+ out.add(`-${flag.short}`);
182
+ }
183
+ return out;
184
+ }
185
+ /** Words and options of one command. `valueFlags` are the options that take the next word as their value. */
186
+ export function parseArgs(args, valueFlags) {
187
+ const parsed = { pos: [], opts: [] };
188
+ for (let index = 0; index < args.length; index++) {
189
+ const arg = args[index];
190
+ if (arg === "--") {
191
+ parsed.pos.push(...args.slice(index + 1));
192
+ break;
193
+ }
194
+ if (arg.startsWith("--")) {
195
+ const eq = arg.indexOf("=");
196
+ const name = eq === -1 ? arg : arg.slice(0, eq);
197
+ if (eq !== -1)
198
+ parsed.opts.push([name, arg.slice(eq + 1)]);
199
+ else if (valueFlags.has(name))
200
+ parsed.opts.push([name, args[++index] ?? ""]);
201
+ else
202
+ parsed.opts.push([name, true]);
203
+ }
204
+ else if (arg.length > 1 && arg.startsWith("-")) {
205
+ const short = arg.slice(0, 2);
206
+ if (valueFlags.has(short))
207
+ parsed.opts.push([short, arg.length > 2 ? arg.slice(2).replace(/^=/, "") : (args[++index] ?? "")]);
208
+ else
209
+ for (const letter of arg.slice(1))
210
+ parsed.opts.push([`-${letter}`, true]);
211
+ }
212
+ else
213
+ parsed.pos.push(arg);
214
+ }
215
+ return parsed;
216
+ }
217
+ export const values = (parsed, ...names) => parsed.opts.flatMap(([name, value]) => (names.includes(name) && value !== true ? [value] : []));
218
+ export const lastValue = (parsed, ...names) => values(parsed, ...names).pop();
219
+ export const hasFlag = (parsed, ...names) => parsed.opts.some(([name]) => names.includes(name));
220
+ /**
221
+ * How `gh api` is read when only its method matters: GET or HEAD (no method, or one of those, and with no method no
222
+ * fields, as gh then sends a POST) is a read; any other method, or a body from `--input`, is a write.
223
+ */
224
+ export function ghApiMethod(parsed) {
225
+ const explicit = lastValue(parsed, "-X", "--method")?.toUpperCase();
226
+ const fields = hasFlag(parsed, "-f", "--raw-field", "-F", "--field");
227
+ const input = hasFlag(parsed, "--input");
228
+ const method = explicit ?? (fields || input ? "POST" : "GET");
229
+ return { method, read: (method === "GET" || method === "HEAD") && !input };
230
+ }
231
+ /** A REST path's segments, decoded, without the host, query or fragment. */
232
+ export function apiSegments(path) {
233
+ return path
234
+ .trim()
235
+ .replace(/^https?:\/\/api\.github\.com/i, "")
236
+ .replace(/[?#].*$/, "")
237
+ .split("/")
238
+ .filter(Boolean)
239
+ .map((segment) => {
240
+ try {
241
+ return decodeURIComponent(segment);
242
+ }
243
+ catch {
244
+ return segment;
245
+ }
246
+ });
247
+ }
@@ -1,5 +1,5 @@
1
- /** The GitHub classifier's node ids, builders (the only places summaries are written) and small readers. Part of controlPlaneGithub.ts. */
2
- import type { UnnamedHit } from "./controlPlaneUnnamed.generated.js";
1
+ /** GitHub node ids, branch matching, and the builders the webhook mapping writes summaries with (`manifests/githubEvents.ts`). Requests are classified by the kit (`githubDecide.ts`). */
2
+ import type { UnnamedHit } from "../controlPlaneUnnamed.generated.js";
3
3
  export declare const lower: (value: string) => string;
4
4
  export declare const githubNodeIds: {
5
5
  platform: string;
@@ -42,6 +42,10 @@ export type GithubRequest = {
42
42
  repo: string;
43
43
  };
44
44
  currentBranch?: string;
45
+ /** The command reads standard input (a pipe into it, `<`, a heredoc): httpie sends it as the body. */
46
+ stdin?: true;
47
+ /** A GitHub Enterprise Server's API hosts (the connection's), beside api.github.com, for raw HTTP lines. */
48
+ apiHosts?: readonly string[];
45
49
  } | {
46
50
  interface: "api";
47
51
  method: string;
@@ -52,6 +56,8 @@ export type GithubContext = {
52
56
  knownBranches: (owner: string, repo: string) => readonly string[];
53
57
  defaultBranch: (owner: string, repo: string) => string | null;
54
58
  org?: string;
59
+ /** A GitHub Enterprise Server's hosts (the connection's), beside api.github.com, for raw HTTP lines. */
60
+ apiHosts?: readonly string[];
55
61
  };
56
62
  export type GithubClassification = {
57
63
  nodeId: string;
@@ -77,14 +83,10 @@ export type TargetFields = Record<string, string | number | null | undefined>;
77
83
  */
78
84
  export declare function githubTarget(fields: TargetFields, primary: string): string | undefined;
79
85
  export declare const withTarget: (found: GithubClassification, target: string | undefined) => GithubClassification;
80
- export declare function withoutTarget(found: GithubClassification): GithubClassification;
81
86
  export declare const onRepo: (r: Repo, actionKey: string, summary: string, target?: string) => GithubClassification;
82
87
  /** A `gh` command Passport can't name: the Unclassified action (its own kind, 2026-11-17) on its repository (on
83
88
  * Repositories when none is known), with what it hit. No target narrower than the node. */
84
89
  export declare const unclassifiedGh: (r: Repo | null, unnamed?: UnnamedHit) => GithubClassification;
85
- /** The repository writes named since 2026-11-17 (workflows, runs, pull requests, issues, comments, labels): on the
86
- * repository, no exact target. `what` is the summary's verb phrase ("Run a workflow"). */
87
- export declare const repoWrite: (r: Repo, actionKey: string, what: string) => GithubClassification;
88
90
  /** The branch's own node, its most specific pattern node, or the repository when no node matches. */
89
91
  export declare function branchTarget(r: Repo, branch: string, context: BranchContext): string;
90
92
  export type BranchVerb = "push" | "force" | "delete";
@@ -115,8 +117,6 @@ export declare const collaborator: (r: Repo, login: string, permission?: string
115
117
  /** A branch (or pattern) names its own target; a repository ruleset is targeted by its id when the path has one. */
116
118
  export declare function protection(r: Repo, branch: string | null, context: BranchContext, ruleset?: string | null): GithubClassification;
117
119
  export declare const orgProtection: (org: string, ruleset?: string | null) => GithubClassification;
118
- /** GitHub stores secret names upper case. An environment's secret names its environment too. */
119
- export declare const changeSecret: (name: string | null, owner: string, repo: string | null, environment?: string | null) => GithubClassification;
120
120
  /** The invitee is a user id or an email address (hashed, never kept), with the role GitHub defaults to. */
121
121
  export declare const invite: (org: string, login: string | null, invitee?: string | null, role?: string | null) => GithubClassification;
122
122
  export type Bag = Record<string, unknown>;
@@ -124,11 +124,7 @@ export declare const isBag: (value: unknown) => value is Bag;
124
124
  export declare const bagAt: (value: unknown, key: string) => Bag | undefined;
125
125
  export declare const text: (value: unknown) => string | null;
126
126
  export declare const textAt: (value: unknown, key: string) => string | null;
127
- export declare const isTrue: (value: unknown) => value is true | "true";
128
- export declare const isFalse: (value: unknown) => value is false | "false";
129
127
  export declare function numberOf(value: unknown): number | null;
130
- export declare function firstNumber(args: Bag, ...keys: string[]): number | null;
131
- export declare function firstText(args: Bag, ...keys: string[]): string | null;
132
128
  /** "owner/repo", a github.com URL (with or without .git), or a bare name under the context's organization. */
133
129
  export declare function parseRepoRef(ref: string, org?: string): Repo | null;
134
130
  export declare const NO_BRANCHES: BranchContext;
@@ -1,6 +1,6 @@
1
1
  // Generated by scripts/generate-control-plane-classifier.mjs. Do not edit.
2
- /** The GitHub classifier's node ids, builders (the only places summaries are written) and small readers. Part of controlPlaneGithub.ts. */
3
- import { nodeId } from "./controlPlane.generated.js";
2
+ /** GitHub node ids, branch matching, and the builders the webhook mapping writes summaries with (`manifests/githubEvents.ts`). Requests are classified by the kit (`githubDecide.ts`). */
3
+ import { nodeId } from "../controlPlane.generated.js";
4
4
  /* ------------------------------------------------------------------ */
5
5
  /* Node ids */
6
6
  /* ------------------------------------------------------------------ */
@@ -124,10 +124,6 @@ export function githubTarget(fields, primary) {
124
124
  return JSON.stringify(entries.map(([key, entry]) => [key, String(entry)]));
125
125
  }
126
126
  export const withTarget = (found, target) => target === undefined ? found : { ...found, target };
127
- export function withoutTarget(found) {
128
- const { target: _target, ...rest } = found;
129
- return rest;
130
- }
131
127
  export const onRepo = (r, actionKey, summary, target) => withTarget({ nodeId: repoNode(r.owner, r.repo), actionKey, summary }, target);
132
128
  /** A `gh` command Passport can't name: the Unclassified action (its own kind, 2026-11-17) on its repository (on
133
129
  * Repositories when none is known), with what it hit. No target narrower than the node. */
@@ -145,9 +141,6 @@ export const unclassifiedGh = (r, unnamed) => ({
145
141
  }),
146
142
  ...(unnamed ? { unnamed } : {})
147
143
  });
148
- /** The repository writes named since 2026-11-17 (workflows, runs, pull requests, issues, comments, labels): on the
149
- * repository, no exact target. `what` is the summary's verb phrase ("Run a workflow"). */
150
- export const repoWrite = (r, actionKey, what) => onRepo(r, actionKey, `${what} in ${slug(r)}`);
151
144
  /** The branch's own node, its most specific pattern node, or the repository when no node matches. */
152
145
  export function branchTarget(r, branch, context) {
153
146
  const known = [...context.knownBranches(r.owner, r.repo)];
@@ -214,12 +207,6 @@ export function protection(r, branch, context, ruleset) {
214
207
  }, githubTarget({ branch }, "branch"));
215
208
  }
216
209
  export const orgProtection = (org, ruleset) => withTarget({ nodeId: orgNode(org), actionKey: "github.branch.protection", summary: `Change protection on ${lower(org)}` }, githubTarget({ ruleset }, "ruleset"));
217
- /** GitHub stores secret names upper case. An environment's secret names its environment too. */
218
- export const changeSecret = (name, owner, repo, environment) => withTarget({
219
- nodeId: secretsNode(owner, repo ?? undefined),
220
- actionKey: "github.secret.change",
221
- summary: name === null ? "Change secrets" : `Change secret ${name}`
222
- }, githubTarget({ name: name === null ? null : name.toUpperCase(), environment }, "name"));
223
210
  /** The invitee is a user id or an email address (hashed, never kept), with the role GitHub defaults to. */
224
211
  export const invite = (org, login, invitee, role) => withTarget({
225
212
  nodeId: orgNode(org),
@@ -230,29 +217,11 @@ export const isBag = (value) => typeof value === "object" && value !== null && !
230
217
  export const bagAt = (value, key) => isBag(value) && isBag(value[key]) ? value[key] : undefined;
231
218
  export const text = (value) => (typeof value === "string" && value !== "" ? value : null);
232
219
  export const textAt = (value, key) => text(isBag(value) ? value[key] : undefined);
233
- export const isTrue = (value) => value === true || value === "true";
234
- export const isFalse = (value) => value === false || value === "false";
235
220
  export function numberOf(value) {
236
221
  if (typeof value === "number" && Number.isInteger(value) && value > 0)
237
222
  return value;
238
223
  return typeof value === "string" && /^\d+$/.test(value) ? Number(value) : null;
239
224
  }
240
- export function firstNumber(args, ...keys) {
241
- for (const key of keys) {
242
- const found = numberOf(args[key]);
243
- if (found !== null)
244
- return found;
245
- }
246
- return null;
247
- }
248
- export function firstText(args, ...keys) {
249
- for (const key of keys) {
250
- const found = text(args[key]);
251
- if (found !== null)
252
- return found;
253
- }
254
- return null;
255
- }
256
225
  /** "owner/repo", a github.com URL (with or without .git), or a bare name under the context's organization. */
257
226
  export function parseRepoRef(ref, org) {
258
227
  const parts = ref