passport-bridge 0.49.0 → 0.50.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/cliHook.js +13 -0
- package/dist/cliHookDecide.js +3 -0
- package/dist/cliHookDeliver.d.ts +2 -2
- package/dist/cliHookDeliver.js +8 -4
- package/dist/controlPlaneAnswer.d.ts +35 -0
- package/dist/controlPlaneAnswer.js +23 -0
- package/dist/controlPlaneCli.d.ts +1 -1
- package/dist/controlPlaneCloudflare.d.ts +1 -1
- package/dist/controlPlaneCloudflare.js +1 -1
- package/dist/controlPlaneGuard.d.ts +6 -31
- package/dist/controlPlaneGuard.js +17 -24
- package/dist/controlPlaneKubernetes.d.ts +1 -1
- package/dist/controlPlaneKubernetes.js +1 -1
- package/dist/controlPlaneNpmGuard.d.ts +1 -1
- package/dist/controlPlaneNpmGuard.js +1 -1
- package/dist/controlPlaneRailwayGuard.d.ts +1 -1
- package/dist/controlPlaneRailwayGuard.js +1 -1
- package/dist/controlPlaneSentry.d.ts +1 -1
- package/dist/controlPlaneSentry.js +1 -1
- package/dist/controlPlaneSupabase.d.ts +1 -1
- package/dist/controlPlaneSupabase.js +1 -1
- package/dist/controlPlaneTerraform.d.ts +1 -1
- package/dist/controlPlaneTerraform.js +1 -1
- package/dist/gitPush.d.ts +8 -3
- package/dist/gitPush.js +37 -12
- package/dist/githubMergeHold.d.ts +42 -0
- package/dist/githubMergeHold.js +134 -0
- package/dist/githubMergeIds.d.ts +18 -0
- package/dist/githubMergeIds.js +51 -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/cliHook.js
CHANGED
|
@@ -183,6 +183,19 @@ async function runAudit(args, runtime, deps) {
|
|
|
183
183
|
await (await import("./controlPlaneLateHold.js")).releaseLate(profile, sessionId, toolUseId, now);
|
|
184
184
|
// Ran while Passport couldn't be reached and no rules were known: Passport is told what it was.
|
|
185
185
|
await (await import("./controlPlaneOffline.js")).releaseOffline(profile, sessionId, toolUseId, now);
|
|
186
|
+
// A merge that didn't name its pull request: its number, from gh's output read here, goes to its decision. Only a
|
|
187
|
+
// line that merges can have one held, so nothing else loads this.
|
|
188
|
+
const merged = /\bmerge\b/.test(event.command)
|
|
189
|
+
? await (await import("./githubMergeHold.js")).releaseMerges(profile, {
|
|
190
|
+
sessionId,
|
|
191
|
+
toolUseId,
|
|
192
|
+
exitCode: outcomeOfInput(input).exitCode,
|
|
193
|
+
output: async () => (await import("./signInFailure.js")).outputTail(input)
|
|
194
|
+
}, now)
|
|
195
|
+
: 0;
|
|
196
|
+
// Sent by the detached flush, as every after-hook report is (tests inject `send`/`fetch` and start none).
|
|
197
|
+
if (merged && !deps.send && !deps.fetch)
|
|
198
|
+
await startFlushIfDue(profile, args, detectRuntime(input, runtime.env, value(args, "client")), now);
|
|
186
199
|
}
|
|
187
200
|
const declared = value(args, "client");
|
|
188
201
|
const runtimeName = detectRuntime(input, runtime.env, declared);
|
package/dist/cliHookDecide.js
CHANGED
|
@@ -322,6 +322,9 @@ async function leaveDecisions(github, railway, context, others) {
|
|
|
322
322
|
// A push's decisions are no longer left for `passport git-credential`: it issues no token in v1 (2026-11-16).
|
|
323
323
|
if (railway)
|
|
324
324
|
await railway.leave();
|
|
325
|
+
// A merge that didn't name its pull request: the after-hook names it from gh's output (`githubMergeHold.ts`).
|
|
326
|
+
if (github?.merges.length)
|
|
327
|
+
(await import("./githubMergeHold.js")).holdMerges(context.report?.sessionId, context.report?.toolUseId, github.merges, context.now());
|
|
325
328
|
await holdLate([github?.answer, railway?.answer, ...others], context.report, context.now());
|
|
326
329
|
}
|
|
327
330
|
/** The platforms asked and not answered: Passport couldn't be reached for them. Every non-answer counts: no response,
|
package/dist/cliHookDeliver.d.ts
CHANGED
|
@@ -156,8 +156,8 @@ export declare function flushDeadline(release: () => void, exit?: (code: number)
|
|
|
156
156
|
* process nobody waits for. Only one runs at a time per profile, and a
|
|
157
157
|
* detached one always exits by FLUSH_DEADLINE_MS. */
|
|
158
158
|
export declare function runFlush(args: ParsedArgs, runtime: Runtime, deps: HookDependencies): Promise<void>;
|
|
159
|
-
/** Leftover budget: Activity reports, late notices, the computer's daily
|
|
160
|
-
* report, and, at most hourly, a refresh of what the control plane decides. */
|
|
159
|
+
/** Leftover budget: Activity reports, late notices, a merge's pull request for its decision, the computer's daily
|
|
160
|
+
* guard report, and, at most hourly, a refresh of what the control plane decides. */
|
|
161
161
|
export declare function leftovers(queued: CliHookReport[], context: {
|
|
162
162
|
profile: string;
|
|
163
163
|
api?: ApiCall;
|
package/dist/cliHookDeliver.js
CHANGED
|
@@ -283,19 +283,22 @@ export async function runFlush(args, runtime, deps) {
|
|
|
283
283
|
release();
|
|
284
284
|
}
|
|
285
285
|
}
|
|
286
|
-
/** Leftover budget: Activity reports, late notices, the computer's daily
|
|
287
|
-
* report, and, at most hourly, a refresh of what the control plane decides. */
|
|
286
|
+
/** Leftover budget: Activity reports, late notices, a merge's pull request for its decision, the computer's daily
|
|
287
|
+
* guard report, and, at most hourly, a refresh of what the control plane decides. */
|
|
288
288
|
export async function leftovers(queued, context) {
|
|
289
289
|
const { profile, budget, deps } = context;
|
|
290
290
|
const now = (deps.now ?? Date.now)();
|
|
291
291
|
const late = await import("./controlPlaneLate.js");
|
|
292
292
|
const offlineNotices = await import("./controlPlaneOffline.js");
|
|
293
293
|
const { offline, rest } = offlineNotices.splitOffline(queued);
|
|
294
|
-
|
|
294
|
+
// A merge's pull request for its decision (`githubMergeHold.ts`), loaded only when one is queued.
|
|
295
|
+
const merges = rest.some((entry) => "cpDecideIds" in entry) ? await import("./githubMergeHold.js") : null;
|
|
296
|
+
const { ids: decisionIds, rest: unsplit } = merges ? merges.splitDecisionIds(rest) : { ids: [], rest };
|
|
297
|
+
const { late: lateIds, reports } = late.splitLate(unsplit);
|
|
295
298
|
const refresh = claimStaleRefresh(profile, readCpCli(profile), now);
|
|
296
299
|
const extras = await import("./cliHookExtras.js");
|
|
297
300
|
const heartbeat = await extras.heartbeatDue(profile, now);
|
|
298
|
-
if (!reports.length && !lateIds.length && !offline.length && !refresh && !heartbeat)
|
|
301
|
+
if (!reports.length && !lateIds.length && !decisionIds.length && !offline.length && !refresh && !heartbeat)
|
|
299
302
|
return;
|
|
300
303
|
const api = context.api ?? (await profileApi(profile, budget, deps.fetch ?? fetch));
|
|
301
304
|
if (!api)
|
|
@@ -306,6 +309,7 @@ export async function leftovers(queued, context) {
|
|
|
306
309
|
await Promise.allSettled([
|
|
307
310
|
...reports.map((entry) => send(entry)),
|
|
308
311
|
lateIds.length ? late.tellLate(api, lateIds, budget) : null,
|
|
312
|
+
merges && decisionIds.length ? merges.sendDecisionIds(api, decisionIds, budget) : null,
|
|
309
313
|
offline.length ? offlineNotices.tellOffline(api, offline, budget) : null,
|
|
310
314
|
heartbeat ? extras.heartbeat(api, profile, context.runtime.env, budget, now) : null,
|
|
311
315
|
refresh ? refreshCpCli(profile, budget, { api, ...(deps.now ? { now: deps.now } : {}) }) : null
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What every platform's guard shares when it asks `POST /api/cp/decide`: the path, how long each request waits, the
|
|
3
|
+
* answer's shape, the target's digest, and which of a line's answers wins. Apart from `controlPlaneGuard.ts` so a
|
|
4
|
+
* Railway, Supabase or other line never loads GitHub's classifier (its manifest is most of the guard's CPU).
|
|
5
|
+
*/
|
|
6
|
+
export declare const CP_DECIDE_PATH = "/api/cp/decide";
|
|
7
|
+
/** Each request waits at most this long. */
|
|
8
|
+
export declare const CP_DECIDE_TIMEOUT_MS = 2000;
|
|
9
|
+
export type CpAnswer =
|
|
10
|
+
/** `decisionId`: an allow that may be spent once: a Railway allow `passport exec` spends instead of deciding
|
|
11
|
+
* again, or an allow on a repository a push token may be issued against. */
|
|
12
|
+
{
|
|
13
|
+
kind: "allow";
|
|
14
|
+
eventId: string | null;
|
|
15
|
+
decisionId?: string;
|
|
16
|
+
requestId?: string;
|
|
17
|
+
} | {
|
|
18
|
+
kind: "block";
|
|
19
|
+
message: string;
|
|
20
|
+
}
|
|
21
|
+
/** No answer: the server couldn't be reached in time. `late`: the request ids of the decides left unanswered,
|
|
22
|
+
* which Passport may still record (`controlPlaneLate.ts`). */
|
|
23
|
+
| {
|
|
24
|
+
kind: "unreachable";
|
|
25
|
+
late?: string[];
|
|
26
|
+
}
|
|
27
|
+
/** The server doesn't decide this (an older server, or a refusal of the request itself). */
|
|
28
|
+
| {
|
|
29
|
+
kind: "undecided";
|
|
30
|
+
};
|
|
31
|
+
/** The SHA-256 of a classifier target: the server hashes the same digest of what its gateway classifies. */
|
|
32
|
+
export declare function targetDigest(target: string): string;
|
|
33
|
+
/** The first answer of the worst kind (a block, then no answer, then undecided); no answer names every decide left
|
|
34
|
+
* unanswered. */
|
|
35
|
+
export declare function worstAnswer(answers: readonly CpAnswer[]): CpAnswer | null;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What every platform's guard shares when it asks `POST /api/cp/decide`: the path, how long each request waits, the
|
|
3
|
+
* answer's shape, the target's digest, and which of a line's answers wins. Apart from `controlPlaneGuard.ts` so a
|
|
4
|
+
* Railway, Supabase or other line never loads GitHub's classifier (its manifest is most of the guard's CPU).
|
|
5
|
+
*/
|
|
6
|
+
import { createHash } from "node:crypto";
|
|
7
|
+
export const CP_DECIDE_PATH = "/api/cp/decide";
|
|
8
|
+
/** Each request waits at most this long. */
|
|
9
|
+
export const CP_DECIDE_TIMEOUT_MS = 2_000;
|
|
10
|
+
/** The SHA-256 of a classifier target: the server hashes the same digest of what its gateway classifies. */
|
|
11
|
+
export function targetDigest(target) {
|
|
12
|
+
return createHash("sha256").update(target, "utf8").digest("hex");
|
|
13
|
+
}
|
|
14
|
+
/** The first answer of the worst kind (a block, then no answer, then undecided); no answer names every decide left
|
|
15
|
+
* unanswered. */
|
|
16
|
+
export function worstAnswer(answers) {
|
|
17
|
+
if (answers.some((answer) => answer.kind === "block"))
|
|
18
|
+
return answers.find((answer) => answer.kind === "block");
|
|
19
|
+
const late = answers.flatMap((answer) => (answer.kind === "unreachable" ? (answer.late ?? []) : []));
|
|
20
|
+
if (answers.some((answer) => answer.kind === "unreachable"))
|
|
21
|
+
return { kind: "unreachable", ...(late.length ? { late } : {}) };
|
|
22
|
+
return answers.find((answer) => answer.kind === "undecided") ?? null;
|
|
23
|
+
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* that can't be undone here (`localIrreversible.ts`, vendor "local"). Only the vendor and the verb leave this
|
|
5
5
|
* computer, never an argument: Passport classifies the verb from its own tables.
|
|
6
6
|
*/
|
|
7
|
-
import type { CpAnswer } from "./
|
|
7
|
+
import type { CpAnswer } from "./controlPlaneAnswer.js";
|
|
8
8
|
type ApiCall = (path: string, init: RequestInit) => Promise<Response>;
|
|
9
9
|
export declare const CP_DECIDE_CLI_PATH = "/api/cp/decide/cli";
|
|
10
10
|
/** Ask Passport about one verb. Never throws. */
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
import type { Classification } from "./controlPlane.generated.js";
|
|
15
15
|
import { type Request } from "./connectorKit/engine.generated.js";
|
|
16
16
|
import { type Guard } from "./connectorKit/shell.generated.js";
|
|
17
|
-
import { type CpAnswer } from "./
|
|
17
|
+
import { type CpAnswer } from "./controlPlaneAnswer.js";
|
|
18
18
|
type ApiCall = (path: string, init: RequestInit) => Promise<Response>;
|
|
19
19
|
/** At most this many Cloudflare commands in one line are asked about; a line doing more is refused. */
|
|
20
20
|
export declare const MAX_CLOUDFLARE_COMMANDS = 8;
|
|
@@ -18,7 +18,7 @@ import { explain } from "./connectorKit/engine.generated.js";
|
|
|
18
18
|
import { httpLineOf, urlParts } from "./connectorKit/http.generated.js";
|
|
19
19
|
import { CLOUDFLARE } from "./connectorKit/manifests/cloudflare.generated.js";
|
|
20
20
|
import { resolveCommand } from "./connectorKit/shell.generated.js";
|
|
21
|
-
import { CP_DECIDE_PATH, CP_DECIDE_TIMEOUT_MS, targetDigest, worstAnswer } from "./
|
|
21
|
+
import { CP_DECIDE_PATH, CP_DECIDE_TIMEOUT_MS, targetDigest, worstAnswer } from "./controlPlaneAnswer.js";
|
|
22
22
|
import { maskCommandArgv } from "./controlPlaneUnnamed.generated.js";
|
|
23
23
|
import { newRequestId } from "./controlPlaneLate.js";
|
|
24
24
|
import { NO_ANSWER_STATUSES, noAnswer, refusalOf } from "./cpRefusal.js";
|
|
@@ -23,14 +23,14 @@
|
|
|
23
23
|
import { type GithubClassification } from "./connectorKit/githubDecide.generated.js";
|
|
24
24
|
import type { GitEnv, RunGit } from "./gitCredentialSetup.js";
|
|
25
25
|
import { type PushPlan } from "./gitPush.js";
|
|
26
|
-
|
|
26
|
+
import type { HeldMerge } from "./githubMergeHold.js";
|
|
27
|
+
import { CP_DECIDE_PATH, CP_DECIDE_TIMEOUT_MS, targetDigest, worstAnswer, type CpAnswer } from "./controlPlaneAnswer.js";
|
|
28
|
+
export { CP_DECIDE_PATH, CP_DECIDE_TIMEOUT_MS, targetDigest, worstAnswer, type CpAnswer };
|
|
27
29
|
/** At most this many things one line does are asked about; a line doing more is refused. */
|
|
28
30
|
export declare const MAX_ASKED = 16;
|
|
29
31
|
export declare const TOO_MANY_MESSAGE = "Blocked by Passport: this command changes more than 16 things on GitHub at once. Split it up so each can be checked.";
|
|
30
32
|
/** The server's bound on a summary (the classifier's templates stay well under it). */
|
|
31
33
|
export declare const MAX_SUMMARY = 200;
|
|
32
|
-
/** Each request waits at most this long. */
|
|
33
|
-
export declare const CP_DECIDE_TIMEOUT_MS = 2000;
|
|
34
34
|
type Repo = {
|
|
35
35
|
owner: string;
|
|
36
36
|
repo: string;
|
|
@@ -68,29 +68,6 @@ export declare function classifyCommands(command: string, place: GitPlace, git?:
|
|
|
68
68
|
}): LineCommand[];
|
|
69
69
|
/** Every action of every consequential command in a line. */
|
|
70
70
|
export declare function classifyLine(command: string, place: GitPlace): GithubClassification[];
|
|
71
|
-
export type CpAnswer =
|
|
72
|
-
/** `decisionId`: an allow that may be spent once: a Railway allow `passport exec` spends instead of deciding
|
|
73
|
-
* again, or an allow on a repository a push token may be issued against. */
|
|
74
|
-
{
|
|
75
|
-
kind: "allow";
|
|
76
|
-
eventId: string | null;
|
|
77
|
-
decisionId?: string;
|
|
78
|
-
} | {
|
|
79
|
-
kind: "block";
|
|
80
|
-
message: string;
|
|
81
|
-
}
|
|
82
|
-
/** No answer: the server couldn't be reached in time. `late`: the request ids of the decides left unanswered,
|
|
83
|
-
* which Passport may still record (`controlPlaneLate.ts`). */
|
|
84
|
-
| {
|
|
85
|
-
kind: "unreachable";
|
|
86
|
-
late?: string[];
|
|
87
|
-
}
|
|
88
|
-
/** The server doesn't decide this (an older server, or a refusal of the request itself). */
|
|
89
|
-
| {
|
|
90
|
-
kind: "undecided";
|
|
91
|
-
};
|
|
92
|
-
/** The SHA-256 of a classifier target: the server hashes the same digest of what its gateway classifies. */
|
|
93
|
-
export declare function targetDigest(target: string): string;
|
|
94
71
|
/**
|
|
95
72
|
* Ask Passport about one classification. A server from before targets
|
|
96
73
|
* refuses fields it doesn't know (a 400 with a bare error): asked once more
|
|
@@ -103,9 +80,6 @@ export declare function askControlPlane(api: ApiCall, classification: GithubClas
|
|
|
103
80
|
sessionId?: string;
|
|
104
81
|
command?: string;
|
|
105
82
|
}, signal: AbortSignal): Promise<CpAnswer>;
|
|
106
|
-
/** The first answer of the worst kind (a block, then no answer, then undecided); no answer names every decide left
|
|
107
|
-
* unanswered. */
|
|
108
|
-
export declare function worstAnswer(answers: readonly CpAnswer[]): CpAnswer | null;
|
|
109
83
|
/** A push's decisions, every one an allow with a decision id: what its token is issued against. */
|
|
110
84
|
export type PushDecisions = {
|
|
111
85
|
key: string;
|
|
@@ -116,7 +90,8 @@ export type PushDecisions = {
|
|
|
116
90
|
* in line order wins, then no answer, then an undecided one, else the last
|
|
117
91
|
* allow. A line doing more than `MAX_ASKED` things is refused here, unasked.
|
|
118
92
|
* For each push whose every ref was allowed with a decision id, those ids
|
|
119
|
-
* (for `passport git-credential`)
|
|
93
|
+
* (for `passport git-credential`); and each allowed merge that didn't name its pull request, by request id, for the
|
|
94
|
+
* after-hook to name it once gh has (`githubMergeIds.ts`).
|
|
120
95
|
*/
|
|
121
96
|
export declare function decideCommands(api: ApiCall, commands: readonly LineCommand[], extra: {
|
|
122
97
|
credentialId?: string;
|
|
@@ -125,6 +100,7 @@ export declare function decideCommands(api: ApiCall, commands: readonly LineComm
|
|
|
125
100
|
}, signal: AbortSignal): Promise<{
|
|
126
101
|
answer: CpAnswer;
|
|
127
102
|
pushes: PushDecisions[];
|
|
103
|
+
merges: HeldMerge[];
|
|
128
104
|
}>;
|
|
129
105
|
/** `decideCommands` for classifications alone. */
|
|
130
106
|
export declare function decideLine(api: ApiCall, classifications: readonly GithubClassification[], extra: {
|
|
@@ -150,4 +126,3 @@ export declare function execControlPlane(api: ApiCall, command: {
|
|
|
150
126
|
message: string;
|
|
151
127
|
cause: "blocked";
|
|
152
128
|
} | null>;
|
|
153
|
-
export {};
|
|
@@ -20,7 +20,6 @@
|
|
|
20
20
|
* event only as a keyed hash. Never the command line,
|
|
21
21
|
* never the target itself.
|
|
22
22
|
*/
|
|
23
|
-
import { createHash } from "node:crypto";
|
|
24
23
|
import { readFileSync } from "node:fs";
|
|
25
24
|
import { join } from "node:path";
|
|
26
25
|
import { classifyGitPushRefs, classifyGithubAll } from "./connectorKit/githubDecide.generated.js";
|
|
@@ -30,16 +29,17 @@ import { readBoundedJson } from "./boundedResponse.js";
|
|
|
30
29
|
import { newRequestId } from "./controlPlaneLate.js";
|
|
31
30
|
import { gitDirs } from "./execGithubRepo.js";
|
|
32
31
|
import { planKey, planPush, pushPlan } from "./gitPush.js";
|
|
32
|
+
import { mergeRepo, withMergeIds } from "./githubMergeIds.js";
|
|
33
33
|
import { shadowAlongside } from "./kitShadow.js";
|
|
34
34
|
import { NO_ANSWER_STATUSES, noAnswer, refusalOf } from "./cpRefusal.js";
|
|
35
|
-
|
|
35
|
+
import { CP_DECIDE_PATH, CP_DECIDE_TIMEOUT_MS, targetDigest, worstAnswer } from "./controlPlaneAnswer.js";
|
|
36
|
+
// Every platform's guard shares these; they live apart so a Railway or Supabase line never loads GitHub's classifier.
|
|
37
|
+
export { CP_DECIDE_PATH, CP_DECIDE_TIMEOUT_MS, targetDigest, worstAnswer };
|
|
36
38
|
/** At most this many things one line does are asked about; a line doing more is refused. */
|
|
37
39
|
export const MAX_ASKED = 16;
|
|
38
40
|
export const TOO_MANY_MESSAGE = `Blocked by Passport: this command changes more than ${MAX_ASKED} things on GitHub at once. Split it up so each can be checked.`;
|
|
39
41
|
/** The server's bound on a summary (the classifier's templates stay well under it). */
|
|
40
42
|
export const MAX_SUMMARY = 200;
|
|
41
|
-
/** Each request waits at most this long. */
|
|
42
|
-
export const CP_DECIDE_TIMEOUT_MS = 2_000;
|
|
43
43
|
const GITHUB_ORIGIN = /github\.com[:/]([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+?)(?:\.git)?\/?$/;
|
|
44
44
|
/** The folder's GitHub origin and checked-out branch, read from `.git` (worktrees included; no git process). */
|
|
45
45
|
export function gitPlace(cwd) {
|
|
@@ -128,7 +128,7 @@ export function classifyCommands(command, place, git) {
|
|
|
128
128
|
found.push({ classifications: plan.classifications, push: plan, ...(masked ? { command: masked } : {}) });
|
|
129
129
|
}
|
|
130
130
|
else {
|
|
131
|
-
const classified = classifyArgv(argv, place, stdin);
|
|
131
|
+
const classified = withMergeIds(classifyArgv(argv, place, stdin));
|
|
132
132
|
if (classified.length)
|
|
133
133
|
found.push({ classifications: classified, ...(masked ? { command: masked } : {}) });
|
|
134
134
|
}
|
|
@@ -146,10 +146,6 @@ function platformIdsOf(classification) {
|
|
|
146
146
|
const ids = classification.platformIds;
|
|
147
147
|
return Array.isArray(ids) ? ids : [];
|
|
148
148
|
}
|
|
149
|
-
/** The SHA-256 of a classifier target: the server hashes the same digest of what its gateway classifies. */
|
|
150
|
-
export function targetDigest(target) {
|
|
151
|
-
return createHash("sha256").update(target, "utf8").digest("hex");
|
|
152
|
-
}
|
|
153
149
|
/**
|
|
154
150
|
* Ask Passport about one classification. A server from before targets
|
|
155
151
|
* refuses fields it doesn't know (a 400 with a bare error): asked once more
|
|
@@ -232,39 +228,31 @@ async function askOnce(api, classification, extra, signal, requestId) {
|
|
|
232
228
|
return {
|
|
233
229
|
kind: "allow",
|
|
234
230
|
eventId: typeof body.eventId === "string" ? body.eventId : null,
|
|
235
|
-
...(decisionId ? { decisionId } : {})
|
|
231
|
+
...(decisionId ? { decisionId } : {}),
|
|
232
|
+
...(requestId ? { requestId } : {})
|
|
236
233
|
};
|
|
237
234
|
}
|
|
238
235
|
return refusalOf(body) ?? { kind: "undecided" };
|
|
239
236
|
}
|
|
240
|
-
/** The first answer of the worst kind (a block, then no answer, then undecided); no answer names every decide left
|
|
241
|
-
* unanswered. */
|
|
242
|
-
export function worstAnswer(answers) {
|
|
243
|
-
if (answers.some((answer) => answer.kind === "block"))
|
|
244
|
-
return answers.find((answer) => answer.kind === "block");
|
|
245
|
-
const late = answers.flatMap((answer) => (answer.kind === "unreachable" ? (answer.late ?? []) : []));
|
|
246
|
-
if (answers.some((answer) => answer.kind === "unreachable"))
|
|
247
|
-
return { kind: "unreachable", ...(late.length ? { late } : {}) };
|
|
248
|
-
return answers.find((answer) => answer.kind === "undecided") ?? null;
|
|
249
|
-
}
|
|
250
237
|
/**
|
|
251
238
|
* Every action of a line decided at once (one event each): the first block
|
|
252
239
|
* in line order wins, then no answer, then an undecided one, else the last
|
|
253
240
|
* allow. A line doing more than `MAX_ASKED` things is refused here, unasked.
|
|
254
241
|
* For each push whose every ref was allowed with a decision id, those ids
|
|
255
|
-
* (for `passport git-credential`)
|
|
242
|
+
* (for `passport git-credential`); and each allowed merge that didn't name its pull request, by request id, for the
|
|
243
|
+
* after-hook to name it once gh has (`githubMergeIds.ts`).
|
|
256
244
|
*/
|
|
257
245
|
export async function decideCommands(api, commands, extra, signal) {
|
|
258
246
|
const all = commands.flatMap((command) => command.classifications.map((classification) => ({ classification, command: command.command ?? extra.command })));
|
|
259
247
|
if (all.length > MAX_ASKED)
|
|
260
|
-
return { answer: { kind: "block", message: TOO_MANY_MESSAGE }, pushes: [] };
|
|
248
|
+
return { answer: { kind: "block", message: TOO_MANY_MESSAGE }, pushes: [], merges: [] };
|
|
261
249
|
const asked = Promise.all(all.map(({ classification, command }) => askControlPlane(api, classification, command ? { ...extra, command } : extra, signal)));
|
|
262
250
|
// The shadow run's counts ride along with these requests, never waited on: stopped once they're answered.
|
|
263
251
|
const stopShadow = shadowAlongside(api, signal);
|
|
264
252
|
const answers = await asked.finally(stopShadow);
|
|
265
253
|
const worst = worstAnswer(answers);
|
|
266
254
|
if (worst)
|
|
267
|
-
return { answer: worst, pushes: [] };
|
|
255
|
+
return { answer: worst, pushes: [], merges: [] };
|
|
268
256
|
const pushes = [];
|
|
269
257
|
let at = 0;
|
|
270
258
|
for (const command of commands) {
|
|
@@ -273,7 +261,12 @@ export async function decideCommands(api, commands, extra, signal) {
|
|
|
273
261
|
if (command.push && ids.length === mine.length)
|
|
274
262
|
pushes.push({ key: planKey(command.push), decisionIds: ids });
|
|
275
263
|
}
|
|
276
|
-
|
|
264
|
+
const merges = all.flatMap(({ classification }, index) => {
|
|
265
|
+
const answer = answers[index];
|
|
266
|
+
const repo = platformIdsOf(classification).length ? undefined : mergeRepo(classification);
|
|
267
|
+
return repo && answer?.kind === "allow" && answer.requestId ? [{ requestId: answer.requestId, repo }] : [];
|
|
268
|
+
});
|
|
269
|
+
return { answer: answers.at(-1) ?? { kind: "allow", eventId: null }, pushes, merges };
|
|
277
270
|
}
|
|
278
271
|
/** `decideCommands` for classifications alone. */
|
|
279
272
|
export async function decideLine(api, classifications, extra, signal) {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
import type { Classification } from "./controlPlane.generated.js";
|
|
15
15
|
import { type ManifestRead } from "./connectorKit/manifests/kubernetesObjects.generated.js";
|
|
16
16
|
import type { KubeContextName } from "./connectorKit/manifests/kubernetes.generated.js";
|
|
17
|
-
import { type CpAnswer } from "./
|
|
17
|
+
import { type CpAnswer } from "./controlPlaneAnswer.js";
|
|
18
18
|
import { type LinkFs } from "./envLinkFs.js";
|
|
19
19
|
type ApiCall = (path: string, init: RequestInit) => Promise<Response>;
|
|
20
20
|
/** At most this many kubectl or helm commands in one line are asked about; a line doing more is refused. */
|
|
@@ -18,7 +18,7 @@ import { normalizeArgv, splitCommands } from "./cliHookParse.js";
|
|
|
18
18
|
import { readBoundedJson } from "./boundedResponse.js";
|
|
19
19
|
import { classifyKube, isKubeProgram } from "./connectorKit/manifests/kubernetesCli.generated.js";
|
|
20
20
|
import { MAX_MANIFEST_OBJECTS, readManifest } from "./connectorKit/manifests/kubernetesObjects.generated.js";
|
|
21
|
-
import { CP_DECIDE_PATH, CP_DECIDE_TIMEOUT_MS, worstAnswer } from "./
|
|
21
|
+
import { CP_DECIDE_PATH, CP_DECIDE_TIMEOUT_MS, worstAnswer } from "./controlPlaneAnswer.js";
|
|
22
22
|
import { maskCommandArgv } from "./controlPlaneUnnamed.generated.js";
|
|
23
23
|
import { newRequestId } from "./controlPlaneLate.js";
|
|
24
24
|
import { NO_ANSWER_STATUSES, noAnswer, refusalOf } from "./cpRefusal.js";
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* replaced). `.npmrc` is read for `registry` lines only: a token or password in it is never kept or sent.
|
|
10
10
|
*/
|
|
11
11
|
import type { Classification } from "./controlPlane.generated.js";
|
|
12
|
-
import { type CpAnswer } from "./
|
|
12
|
+
import { type CpAnswer } from "./controlPlaneAnswer.js";
|
|
13
13
|
import type { Found } from "./controlPlaneOffline.js";
|
|
14
14
|
type ApiCall = (path: string, init: RequestInit) => Promise<Response>;
|
|
15
15
|
/** At most this many npm commands in one line are asked about; a line doing more is refused. */
|
|
@@ -14,7 +14,7 @@ import { resolve } from "node:path";
|
|
|
14
14
|
import { basename, normalizeArgv, splitCommands } from "./cliHookParse.js";
|
|
15
15
|
import { readBoundedJson } from "./boundedResponse.js";
|
|
16
16
|
import { classifyNpm, NPM_PROGRAMS } from "./controlPlaneNpmCommands.generated.js";
|
|
17
|
-
import { CP_DECIDE_PATH, CP_DECIDE_TIMEOUT_MS, worstAnswer } from "./
|
|
17
|
+
import { CP_DECIDE_PATH, CP_DECIDE_TIMEOUT_MS, worstAnswer } from "./controlPlaneAnswer.js";
|
|
18
18
|
import { maskCommandArgv } from "./controlPlaneUnnamed.generated.js";
|
|
19
19
|
import { newRequestId } from "./controlPlaneLate.js";
|
|
20
20
|
import { cdTarget } from "./controlPlaneRailwayReach.js";
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
*/
|
|
41
41
|
import type { Classification } from "./controlPlane.generated.js";
|
|
42
42
|
import { type RailwayContext } from "./controlPlaneRailway.generated.js";
|
|
43
|
-
import { type CpAnswer } from "./
|
|
43
|
+
import { type CpAnswer } from "./controlPlaneAnswer.js";
|
|
44
44
|
import { type ExecReach, type RailwayRun } from "./controlPlaneRailwayReach.js";
|
|
45
45
|
import type { RailwayLinked } from "./railwayLink.js";
|
|
46
46
|
type ApiCall = (path: string, init: RequestInit) => Promise<Response>;
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
* `eval '…'`, `env -S '…'`, a command substitution, or `passport exec -- railway …`.
|
|
40
40
|
*/
|
|
41
41
|
import { classifyRailway, railwayIndex, railwayNeedsContext, railwayNodeIds as ids } from "./controlPlaneRailway.generated.js";
|
|
42
|
-
import { CP_DECIDE_PATH, CP_DECIDE_TIMEOUT_MS, worstAnswer } from "./
|
|
42
|
+
import { CP_DECIDE_PATH, CP_DECIDE_TIMEOUT_MS, worstAnswer } from "./controlPlaneAnswer.js";
|
|
43
43
|
import { maskCommandArgv } from "./controlPlaneUnnamed.generated.js";
|
|
44
44
|
import { newRequestId } from "./controlPlaneLate.js";
|
|
45
45
|
import { basename, normalizeArgv, splitCommands } from "./cliHookParse.js";
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
import type { Classification } from "./controlPlane.generated.js";
|
|
14
14
|
import { type Request } from "./connectorKit/engine.generated.js";
|
|
15
15
|
import { type Guard } from "./connectorKit/shell.generated.js";
|
|
16
|
-
import { type CpAnswer } from "./
|
|
16
|
+
import { type CpAnswer } from "./controlPlaneAnswer.js";
|
|
17
17
|
type ApiCall = (path: string, init: RequestInit) => Promise<Response>;
|
|
18
18
|
/** At most this many Sentry commands in one line are asked about; a line doing more is refused. */
|
|
19
19
|
export declare const MAX_SENTRY_COMMANDS = 8;
|
|
@@ -17,7 +17,7 @@ import { explain } from "./connectorKit/engine.generated.js";
|
|
|
17
17
|
import { httpLineOf, urlParts } from "./connectorKit/http.generated.js";
|
|
18
18
|
import { SENTRY } from "./connectorKit/manifests/sentry.generated.js";
|
|
19
19
|
import { resolveCommand } from "./connectorKit/shell.generated.js";
|
|
20
|
-
import { CP_DECIDE_PATH, CP_DECIDE_TIMEOUT_MS, targetDigest, worstAnswer } from "./
|
|
20
|
+
import { CP_DECIDE_PATH, CP_DECIDE_TIMEOUT_MS, targetDigest, worstAnswer } from "./controlPlaneAnswer.js";
|
|
21
21
|
import { maskCommandArgv, unnamedApi } from "./controlPlaneUnnamed.generated.js";
|
|
22
22
|
import { newRequestId } from "./controlPlaneLate.js";
|
|
23
23
|
import { NO_ANSWER_STATUSES, noAnswer, refusalOf } from "./cpRefusal.js";
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
import type { Classification } from "./controlPlane.generated.js";
|
|
26
26
|
import { type Request } from "./connectorKit/engine.generated.js";
|
|
27
27
|
import { type Guard } from "./connectorKit/shell.generated.js";
|
|
28
|
-
import { type CpAnswer } from "./
|
|
28
|
+
import { type CpAnswer } from "./controlPlaneAnswer.js";
|
|
29
29
|
type ApiCall = (path: string, init: RequestInit) => Promise<Response>;
|
|
30
30
|
/** At most this many Supabase commands in one line are asked about; a line doing more is refused. */
|
|
31
31
|
export declare const MAX_SUPABASE_COMMANDS = 8;
|
|
@@ -29,7 +29,7 @@ import { explain, normalize } from "./connectorKit/engine.generated.js";
|
|
|
29
29
|
import { sqlDigests } from "./connectorKit/sqlFingerprint.generated.js";
|
|
30
30
|
import { SUPABASE } from "./connectorKit/manifests/supabase.generated.js";
|
|
31
31
|
import { resolveCommand } from "./connectorKit/shell.generated.js";
|
|
32
|
-
import { CP_DECIDE_PATH, CP_DECIDE_TIMEOUT_MS, targetDigest, worstAnswer } from "./
|
|
32
|
+
import { CP_DECIDE_PATH, CP_DECIDE_TIMEOUT_MS, targetDigest, worstAnswer } from "./controlPlaneAnswer.js";
|
|
33
33
|
import { maskCommandArgv } from "./controlPlaneUnnamed.generated.js";
|
|
34
34
|
import { newRequestId } from "./controlPlaneLate.js";
|
|
35
35
|
import { NO_ANSWER_STATUSES, noAnswer, refusalOf } from "./cpRefusal.js";
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import type { Classification } from "./controlPlane.generated.js";
|
|
16
16
|
import { type Guard } from "./connectorKit/shell.generated.js";
|
|
17
|
-
import { type CpAnswer } from "./
|
|
17
|
+
import { type CpAnswer } from "./controlPlaneAnswer.js";
|
|
18
18
|
import type { SessionState } from "./cliHookSessionState.js";
|
|
19
19
|
import { type PlanReader } from "./terraformPlans.js";
|
|
20
20
|
type ApiCall = (path: string, init: RequestInit) => Promise<Response>;
|
|
@@ -20,7 +20,7 @@ import { TERRAFORM } from "./connectorKit/manifests/terraform.generated.js";
|
|
|
20
20
|
import { productionHint, terraformLink } from "./connectorKit/manifests/terraformLink.generated.js";
|
|
21
21
|
import { APPLY_KEY, DESTROY_KEY, finishTerraform } from "./connectorKit/manifests/terraformPlan.generated.js";
|
|
22
22
|
import { joinPath, resolveCommand } from "./connectorKit/shell.generated.js";
|
|
23
|
-
import { CP_DECIDE_PATH, CP_DECIDE_TIMEOUT_MS, worstAnswer } from "./
|
|
23
|
+
import { CP_DECIDE_PATH, CP_DECIDE_TIMEOUT_MS, worstAnswer } from "./controlPlaneAnswer.js";
|
|
24
24
|
import { newRequestId } from "./controlPlaneLate.js";
|
|
25
25
|
import { NO_ANSWER_STATUSES, noAnswer, refusalOf } from "./cpRefusal.js";
|
|
26
26
|
import { readBoundedJson } from "./boundedResponse.js";
|
package/dist/gitPush.d.ts
CHANGED
|
@@ -31,15 +31,20 @@ export declare function tagSpecs(specs: readonly string[], at: {
|
|
|
31
31
|
cwd: string;
|
|
32
32
|
env: GitEnv;
|
|
33
33
|
}): string[];
|
|
34
|
+
/** The sha GitHub reports for a ref a push deleted (git's own null sha). */
|
|
35
|
+
export declare const DELETED_SHA: string;
|
|
34
36
|
/**
|
|
35
|
-
* Each
|
|
36
|
-
*
|
|
37
|
-
*
|
|
37
|
+
* Each ref a push moves, with the platform id GitHub's own report of it carries, so Passport matches that report to
|
|
38
|
+
* this decision exactly: a branch push or force-push `<owner>/<repo>:refs/heads/<branch>@<sha>` (the commit, read from
|
|
39
|
+
* git here before the push runs; `HEAD` is the checked-out branch), a branch delete `…@<null sha>` (GitHub's delete
|
|
40
|
+
* event), a tag `<owner>/<repo>:refs/tags/<tag>` (GitHub's tag event names no commit). A ref git can't resolve, or a
|
|
41
|
+
* push it can't name ref by ref, gets none.
|
|
38
42
|
*/
|
|
39
43
|
export declare function withPushIds(repo: Repo, found: GithubClassification[] | null, specs: readonly string[], at: {
|
|
40
44
|
run: RunGit;
|
|
41
45
|
cwd: string;
|
|
42
46
|
env: GitEnv;
|
|
47
|
+
branch?: string | undefined;
|
|
43
48
|
}, wholeRepo?: boolean): GithubClassification[] | null;
|
|
44
49
|
/** A push's plan; more than `MAX_PUSH_REFS` refs is decided as the worst case on the repository. */
|
|
45
50
|
export declare function pushPlan(repo: Repo, classifications: GithubClassification[] | null): PushPlan | null;
|
package/dist/gitPush.js
CHANGED
|
@@ -135,7 +135,7 @@ export function planPush(argv, input) {
|
|
|
135
135
|
const at = { run, cwd: parsed.cwd, env };
|
|
136
136
|
if (specs.length || wholeRepo) {
|
|
137
137
|
const named = tagSpecs(specs, at);
|
|
138
|
-
return pushPlan(repo, withPushIds(repo, classify(named), named, at, wholeRepo));
|
|
138
|
+
return pushPlan(repo, withPushIds(repo, classify(named), named, { ...at, branch }, wholeRepo));
|
|
139
139
|
}
|
|
140
140
|
if (!branch)
|
|
141
141
|
return pushPlan(repo, worst("branch not named"));
|
|
@@ -154,7 +154,7 @@ export function planPush(argv, input) {
|
|
|
154
154
|
if (!destination)
|
|
155
155
|
return pushPlan(repo, worst(mode === "matching" ? "matching branches" : "branch not named"));
|
|
156
156
|
const spec = `${branch}:${destination}`;
|
|
157
|
-
return pushPlan(repo, withPushIds(repo, classify([spec]), [spec], at));
|
|
157
|
+
return pushPlan(repo, withPushIds(repo, classify([spec]), [spec], { ...at, branch }));
|
|
158
158
|
}
|
|
159
159
|
/**
|
|
160
160
|
* A bare name that is a local tag is pushed as that tag, as git resolves it (tags before branches):
|
|
@@ -173,10 +173,25 @@ export function tagSpecs(specs, at) {
|
|
|
173
173
|
}
|
|
174
174
|
const PUSHES = new Set(["github.branch.push", "github.branch.force"]);
|
|
175
175
|
const SHA = /^[0-9a-f]{40}(?:[0-9a-f]{24})?$/;
|
|
176
|
+
/** The sha GitHub reports for a ref a push deleted (git's own null sha). */
|
|
177
|
+
export const DELETED_SHA = "0".repeat(40);
|
|
178
|
+
/** The tag a classification names (`[["tag","v1"]]`), if any. */
|
|
179
|
+
function tagOf(target) {
|
|
180
|
+
try {
|
|
181
|
+
const pairs = JSON.parse(target ?? "[]");
|
|
182
|
+
const found = Array.isArray(pairs) ? pairs.find((pair) => Array.isArray(pair) && pair[0] === "tag") : undefined;
|
|
183
|
+
return typeof found?.[1] === "string" && found[1] ? found[1] : undefined;
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
return undefined;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
176
189
|
/**
|
|
177
|
-
* Each
|
|
178
|
-
*
|
|
179
|
-
*
|
|
190
|
+
* Each ref a push moves, with the platform id GitHub's own report of it carries, so Passport matches that report to
|
|
191
|
+
* this decision exactly: a branch push or force-push `<owner>/<repo>:refs/heads/<branch>@<sha>` (the commit, read from
|
|
192
|
+
* git here before the push runs; `HEAD` is the checked-out branch), a branch delete `…@<null sha>` (GitHub's delete
|
|
193
|
+
* event), a tag `<owner>/<repo>:refs/tags/<tag>` (GitHub's tag event names no commit). A ref git can't resolve, or a
|
|
194
|
+
* push it can't name ref by ref, gets none.
|
|
180
195
|
*/
|
|
181
196
|
export function withPushIds(repo, found, specs, at, wholeRepo = false) {
|
|
182
197
|
if (!found || wholeRepo)
|
|
@@ -186,23 +201,33 @@ export function withPushIds(repo, found, specs, at, wholeRepo = false) {
|
|
|
186
201
|
const spec = raw.replace(/^\+/, "");
|
|
187
202
|
const colon = spec.indexOf(":");
|
|
188
203
|
const src = colon === -1 ? spec : spec.slice(0, colon);
|
|
189
|
-
|
|
204
|
+
let dst = (colon === -1 ? spec : spec.slice(colon + 1)).replace(/^refs\/heads\//, "");
|
|
205
|
+
if (dst === "HEAD" && at.branch)
|
|
206
|
+
dst = at.branch;
|
|
190
207
|
if (src && dst && !dst.startsWith("refs/") && !/[*\s]/.test(spec))
|
|
191
208
|
sources.set(dst, src);
|
|
192
209
|
}
|
|
193
210
|
const full = `${repo.owner}/${repo.repo}`.toLowerCase();
|
|
194
211
|
// The classifier names the repository in lower case; the branch as given.
|
|
195
|
-
const
|
|
212
|
+
const branchNode = `github/repos/branch:${full}@`;
|
|
213
|
+
const withId = (entry, id) => ({ ...entry, platformIds: [{ type: "push", id }] });
|
|
196
214
|
return found.map((entry) => {
|
|
197
|
-
|
|
215
|
+
const node = entry.nodeId.toLowerCase();
|
|
216
|
+
if (entry.actionKey === "github.repo.tag" && node === `github/repos/repo:${full}`) {
|
|
217
|
+
const tag = tagOf(entry.target);
|
|
218
|
+
return tag && !/[\s@]/.test(tag) ? withId(entry, `${full}:refs/tags/${tag}`) : entry;
|
|
219
|
+
}
|
|
220
|
+
if (!node.startsWith(branchNode))
|
|
221
|
+
return entry;
|
|
222
|
+
const branch = entry.nodeId.slice(branchNode.length);
|
|
223
|
+
if (entry.actionKey === "github.branch.delete")
|
|
224
|
+
return withId(entry, `${full}:refs/heads/${branch}@${DELETED_SHA}`);
|
|
225
|
+
if (!PUSHES.has(entry.actionKey))
|
|
198
226
|
return entry;
|
|
199
|
-
const branch = entry.nodeId.slice(prefix.length);
|
|
200
227
|
const src = sources.get(branch);
|
|
201
228
|
const got = src ? at.run(["-C", at.cwd, "rev-parse", "--verify", "--quiet", `${src}^{commit}`], at.env) : null;
|
|
202
229
|
const sha = got?.ok ? got.stdout.trim() : "";
|
|
203
|
-
return SHA.test(sha)
|
|
204
|
-
? { ...entry, platformIds: [{ type: "push", id: `${full}:refs/heads/${branch}@${sha}` }] }
|
|
205
|
-
: entry;
|
|
230
|
+
return SHA.test(sha) ? withId(entry, `${full}:refs/heads/${branch}@${sha}`) : entry;
|
|
206
231
|
});
|
|
207
232
|
}
|
|
208
233
|
/** A push's plan; more than `MAX_PUSH_REFS` refs is decided as the worst case on the repository. */
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A `gh pr merge` with no number, from the guard to Passport (`githubMergeIds.ts`): the guard holds that decide's
|
|
3
|
+
* request id under the tool use (`$PASSPORT_HOME/hook-merges/<key>.json`, owner-only, request ids and the repository
|
|
4
|
+
* only); the after-hook for the same tool use reads the number from the output on this computer and queues
|
|
5
|
+
* `{requestId, platformIds}` in the hook outbox, which the detached flush sends to `POST /api/cp/decide/ids`. Only
|
|
6
|
+
* the id leaves this computer, never the output. Loaded only when a merge was held or an id was queued. Nothing here
|
|
7
|
+
* throws.
|
|
8
|
+
*/
|
|
9
|
+
import type { PlatformId } from "./controlPlaneIds.js";
|
|
10
|
+
/** An after-hook comes within the command's own run; an hour covers a slow merge queue. */
|
|
11
|
+
export declare const MERGE_HOLD_MS: number;
|
|
12
|
+
/** An outbox line that holds ids for a decision, not an Activity report. */
|
|
13
|
+
export declare const DECISION_IDS_KEY = "cpDecideIds";
|
|
14
|
+
export type HeldMerge = {
|
|
15
|
+
requestId: string;
|
|
16
|
+
repo: string;
|
|
17
|
+
};
|
|
18
|
+
/** The guard: hold the request ids of merges that didn't name their pull request, until the command ran. */
|
|
19
|
+
export declare function holdMerges(sessionId: string | undefined, toolUseId: string | undefined, merges: readonly HeldMerge[], now?: number): void;
|
|
20
|
+
/** The after-hook: take the merges held for this tool use (each goes once). */
|
|
21
|
+
export declare function takeMerges(sessionId: string | undefined, toolUseId: string | undefined, now?: number): HeldMerge[];
|
|
22
|
+
export type QueuedIds = {
|
|
23
|
+
requestId: string;
|
|
24
|
+
platformIds: PlatformId[];
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* The after-hook: a merge that ran (exit 0) and whose pull request gh's output names gets that id queued for its
|
|
28
|
+
* decision. Returns how many were queued.
|
|
29
|
+
*/
|
|
30
|
+
export declare function releaseMerges(profile: string, at: {
|
|
31
|
+
sessionId: string | undefined;
|
|
32
|
+
toolUseId: string | undefined;
|
|
33
|
+
exitCode: number | undefined;
|
|
34
|
+
output: () => Promise<string>;
|
|
35
|
+
}, now?: number): Promise<number>;
|
|
36
|
+
/** The flush's side: the queued decision ids, and everything else around them. */
|
|
37
|
+
export declare function splitDecisionIds<T extends object>(queued: readonly T[]): {
|
|
38
|
+
ids: QueuedIds[];
|
|
39
|
+
rest: T[];
|
|
40
|
+
};
|
|
41
|
+
/** The flush sends each queued decision's ids (`POST /api/cp/decide/ids`). Never throws. */
|
|
42
|
+
export declare function sendDecisionIds(api: (path: string, init: RequestInit) => Promise<Response>, queued: readonly QueuedIds[], signal: AbortSignal): Promise<void>;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A `gh pr merge` with no number, from the guard to Passport (`githubMergeIds.ts`): the guard holds that decide's
|
|
3
|
+
* request id under the tool use (`$PASSPORT_HOME/hook-merges/<key>.json`, owner-only, request ids and the repository
|
|
4
|
+
* only); the after-hook for the same tool use reads the number from the output on this computer and queues
|
|
5
|
+
* `{requestId, platformIds}` in the hook outbox, which the detached flush sends to `POST /api/cp/decide/ids`. Only
|
|
6
|
+
* the id leaves this computer, never the output. Loaded only when a merge was held or an id was queued. Nothing here
|
|
7
|
+
* throws.
|
|
8
|
+
*/
|
|
9
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
10
|
+
import { mkdirSync, readdirSync, renameSync, rmSync, statSync } from "node:fs";
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
import { readBoundedUtf8File } from "./boundedFile.js";
|
|
13
|
+
import { credentialDir, ensurePrivateDirectory, writePrivateAtomic } from "./credentialStorage.js";
|
|
14
|
+
import { mergedPullId } from "./githubMergeIds.js";
|
|
15
|
+
const REQUEST_ID = /^[0-9a-f]{32}$/;
|
|
16
|
+
/** An after-hook comes within the command's own run; an hour covers a slow merge queue. */
|
|
17
|
+
export const MERGE_HOLD_MS = 60 * 60_000;
|
|
18
|
+
const MAX_HELD = 64;
|
|
19
|
+
const MAX_BYTES = 4 * 1024;
|
|
20
|
+
/** An outbox line that holds ids for a decision, not an Activity report. */
|
|
21
|
+
export const DECISION_IDS_KEY = "cpDecideIds";
|
|
22
|
+
const KEY = DECISION_IDS_KEY;
|
|
23
|
+
const directory = () => join(credentialDir(), "hook-merges");
|
|
24
|
+
function keyOf(sessionId, toolUseId) {
|
|
25
|
+
return createHash("sha256")
|
|
26
|
+
.update(`${sessionId ?? ""}\u0000${toolUseId}`)
|
|
27
|
+
.digest("hex")
|
|
28
|
+
.slice(0, 40);
|
|
29
|
+
}
|
|
30
|
+
function prune(now) {
|
|
31
|
+
let left = 0;
|
|
32
|
+
let names = [];
|
|
33
|
+
try {
|
|
34
|
+
names = readdirSync(directory()).filter((name) => /^[0-9a-f]{40}\.json$/.test(name));
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return 0;
|
|
38
|
+
}
|
|
39
|
+
for (const name of names) {
|
|
40
|
+
const path = join(directory(), name);
|
|
41
|
+
try {
|
|
42
|
+
if (now - statSync(path).mtimeMs > MERGE_HOLD_MS)
|
|
43
|
+
rmSync(path, { force: true });
|
|
44
|
+
else
|
|
45
|
+
left += 1;
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
// Best effort.
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return left;
|
|
52
|
+
}
|
|
53
|
+
/** The guard: hold the request ids of merges that didn't name their pull request, until the command ran. */
|
|
54
|
+
export function holdMerges(sessionId, toolUseId, merges, now = Date.now()) {
|
|
55
|
+
const valid = merges.filter((merge) => REQUEST_ID.test(merge.requestId) && /^[a-z0-9_.-]+\/[a-z0-9_.-]+$/.test(merge.repo));
|
|
56
|
+
if (!toolUseId || !valid.length)
|
|
57
|
+
return;
|
|
58
|
+
try {
|
|
59
|
+
if (prune(now) >= MAX_HELD)
|
|
60
|
+
return;
|
|
61
|
+
ensurePrivateDirectory(true);
|
|
62
|
+
mkdirSync(directory(), { recursive: true, mode: 0o700 });
|
|
63
|
+
const contents = JSON.stringify({ heldAt: now, merges: valid.slice(0, 16) });
|
|
64
|
+
if (Buffer.byteLength(contents) > MAX_BYTES)
|
|
65
|
+
return;
|
|
66
|
+
writePrivateAtomic(join(directory(), `${keyOf(sessionId, toolUseId)}.json`), ".hook-merges", contents, "merge ids");
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
// Best effort: without it the merge is still decided, only not matched to GitHub's report.
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/** The after-hook: take the merges held for this tool use (each goes once). */
|
|
73
|
+
export function takeMerges(sessionId, toolUseId, now = Date.now()) {
|
|
74
|
+
if (!toolUseId)
|
|
75
|
+
return [];
|
|
76
|
+
const path = join(directory(), `${keyOf(sessionId, toolUseId)}.json`);
|
|
77
|
+
const claimed = `${path}.${randomBytes(6).toString("hex")}.claimed`;
|
|
78
|
+
try {
|
|
79
|
+
renameSync(path, claimed);
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return [];
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
const parsed = JSON.parse(readBoundedUtf8File(claimed, MAX_BYTES));
|
|
86
|
+
if (typeof parsed.heldAt !== "number" || now - parsed.heldAt > MERGE_HOLD_MS || !Array.isArray(parsed.merges))
|
|
87
|
+
return [];
|
|
88
|
+
return parsed.merges.filter((merge) => !!merge && REQUEST_ID.test(String(merge.requestId)) && typeof merge.repo === "string");
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return [];
|
|
92
|
+
}
|
|
93
|
+
finally {
|
|
94
|
+
rmSync(claimed, { force: true });
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* The after-hook: a merge that ran (exit 0) and whose pull request gh's output names gets that id queued for its
|
|
99
|
+
* decision. Returns how many were queued.
|
|
100
|
+
*/
|
|
101
|
+
export async function releaseMerges(profile, at, now = Date.now()) {
|
|
102
|
+
const merges = takeMerges(at.sessionId, at.toolUseId, now);
|
|
103
|
+
if (!merges.length || (at.exitCode !== undefined && at.exitCode !== 0))
|
|
104
|
+
return 0;
|
|
105
|
+
const output = await at.output();
|
|
106
|
+
const queued = merges.flatMap((merge) => {
|
|
107
|
+
const id = mergedPullId(output, merge.repo);
|
|
108
|
+
return id ? [{ requestId: merge.requestId, platformIds: [id] }] : [];
|
|
109
|
+
});
|
|
110
|
+
if (!queued.length)
|
|
111
|
+
return 0;
|
|
112
|
+
(await import("./hookOutbox.js")).queueReports(profile, queued.map((entry) => ({ [KEY]: entry })), now);
|
|
113
|
+
return queued.length;
|
|
114
|
+
}
|
|
115
|
+
/** The flush's side: the queued decision ids, and everything else around them. */
|
|
116
|
+
export function splitDecisionIds(queued) {
|
|
117
|
+
const ids = [];
|
|
118
|
+
const rest = [];
|
|
119
|
+
for (const entry of queued) {
|
|
120
|
+
const value = entry[KEY];
|
|
121
|
+
if (value && typeof value === "object") {
|
|
122
|
+
if (typeof value.requestId === "string" && REQUEST_ID.test(value.requestId) && Array.isArray(value.platformIds))
|
|
123
|
+
ids.push({ requestId: value.requestId, platformIds: value.platformIds });
|
|
124
|
+
}
|
|
125
|
+
else
|
|
126
|
+
rest.push(entry);
|
|
127
|
+
}
|
|
128
|
+
return { ids, rest };
|
|
129
|
+
}
|
|
130
|
+
/** The flush sends each queued decision's ids (`POST /api/cp/decide/ids`). Never throws. */
|
|
131
|
+
export async function sendDecisionIds(api, queued, signal) {
|
|
132
|
+
const { reportPlatformIds } = await import("./controlPlaneIds.js");
|
|
133
|
+
await Promise.all(queued.map((entry) => reportPlatformIds(api, { requestId: entry.requestId }, entry.platformIds, signal)));
|
|
134
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pull request a merge decision is for, so Passport matches GitHub's report of the merge to it exactly
|
|
3
|
+
* (docs/design/control-plane.md, Part 1 "Platform ids"), whoever's sign-in ran the command.
|
|
4
|
+
*
|
|
5
|
+
* - Before it runs: a merge that names its pull request (`gh pr merge 12`, a pull request URL,
|
|
6
|
+
* `gh api -X PUT repos/o/r/pulls/12/merge`) carries `pull_request o/r#12` on its decide.
|
|
7
|
+
* - After it ran: `gh pr merge` with no number merges the folder's branch's pull request, which only gh's output
|
|
8
|
+
* names (`mergedPullId`); `githubMergeHold.ts` carries it from the guard to the after-hook and on to Passport.
|
|
9
|
+
* Pure and small: the guard loads it only for a GitHub line.
|
|
10
|
+
*/
|
|
11
|
+
import type { GithubClassification } from "./connectorKit/githubDecide.generated.js";
|
|
12
|
+
import type { PlatformId } from "./controlPlaneIds.js";
|
|
13
|
+
/** The repository a merge decision is on (`o/r`, lower case), or undefined. */
|
|
14
|
+
export declare function mergeRepo(classification: Pick<GithubClassification, "nodeId" | "actionKey">): string | undefined;
|
|
15
|
+
/** Each merge that names its pull request, with `pull_request o/r#N` for its decide. */
|
|
16
|
+
export declare function withMergeIds(found: readonly GithubClassification[]): GithubClassification[];
|
|
17
|
+
/** The merged pull request gh's output names, as an id on `repo` (or the repository the output names). */
|
|
18
|
+
export declare function mergedPullId(output: string, repo: string): PlatformId | null;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pull request a merge decision is for, so Passport matches GitHub's report of the merge to it exactly
|
|
3
|
+
* (docs/design/control-plane.md, Part 1 "Platform ids"), whoever's sign-in ran the command.
|
|
4
|
+
*
|
|
5
|
+
* - Before it runs: a merge that names its pull request (`gh pr merge 12`, a pull request URL,
|
|
6
|
+
* `gh api -X PUT repos/o/r/pulls/12/merge`) carries `pull_request o/r#12` on its decide.
|
|
7
|
+
* - After it ran: `gh pr merge` with no number merges the folder's branch's pull request, which only gh's output
|
|
8
|
+
* names (`mergedPullId`); `githubMergeHold.ts` carries it from the guard to the after-hook and on to Passport.
|
|
9
|
+
* Pure and small: the guard loads it only for a GitHub line.
|
|
10
|
+
*/
|
|
11
|
+
const MERGE = "github.repo.merge";
|
|
12
|
+
const REPO_NODE = /^github\/repos\/repo:([A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+)$/;
|
|
13
|
+
/** gh's own words: "✓ Merged pull request o/r#12 (title)", "✓ Squashed and merged pull request #12", "✓ Rebased and
|
|
14
|
+
* merged …", or for `--auto`, "Pull request o/r#12 will be automatically merged …". */
|
|
15
|
+
const MERGED = [
|
|
16
|
+
/\bmerged pull request (?:([A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+))?#(\d{1,9})\b/i,
|
|
17
|
+
/\bpull request (?:([A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+))?#(\d{1,9}) will be automatically merged\b/i
|
|
18
|
+
];
|
|
19
|
+
/** The repository a merge decision is on (`o/r`, lower case), or undefined. */
|
|
20
|
+
export function mergeRepo(classification) {
|
|
21
|
+
if (classification.actionKey !== MERGE)
|
|
22
|
+
return undefined;
|
|
23
|
+
return REPO_NODE.exec(classification.nodeId)?.[1]?.toLowerCase();
|
|
24
|
+
}
|
|
25
|
+
/** The pull request number the classifier's target names (`[["pull","12"]]`), if any. */
|
|
26
|
+
function pullOf(target) {
|
|
27
|
+
try {
|
|
28
|
+
const pairs = JSON.parse(target ?? "[]");
|
|
29
|
+
const found = Array.isArray(pairs) ? pairs.find((pair) => Array.isArray(pair) && pair[0] === "pull") : undefined;
|
|
30
|
+
return typeof found?.[1] === "string" && /^\d{1,9}$/.test(found[1]) ? found[1] : undefined;
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** Each merge that names its pull request, with `pull_request o/r#N` for its decide. */
|
|
37
|
+
export function withMergeIds(found) {
|
|
38
|
+
return found.map((entry) => {
|
|
39
|
+
const repo = mergeRepo(entry);
|
|
40
|
+
const pull = repo ? pullOf(entry.target) : undefined;
|
|
41
|
+
return repo && pull ? { ...entry, platformIds: [{ type: "pull_request", id: `${repo}#${pull}` }] } : entry;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/** The merged pull request gh's output names, as an id on `repo` (or the repository the output names). */
|
|
45
|
+
export function mergedPullId(output, repo) {
|
|
46
|
+
const match = MERGED.map((pattern) => pattern.exec(output)).find(Boolean);
|
|
47
|
+
if (!match)
|
|
48
|
+
return null;
|
|
49
|
+
const named = (match[1] ?? repo).toLowerCase();
|
|
50
|
+
return named === repo ? { type: "pull_request", id: `${repo}#${match[2]}` } : null;
|
|
51
|
+
}
|
package/dist/pluginPin.d.ts
CHANGED
package/dist/pluginPin.js
CHANGED
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.50.0";
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Keep in lockstep with bridge/package.json.
|
|
2
|
-
export const VERSION = "0.
|
|
2
|
+
export const VERSION = "0.50.0";
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "passport-bridge",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.50.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "passport-bridge",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.50.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@modelcontextprotocol/sdk": "1.32.1"
|