passport-bridge 0.46.0 → 0.47.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/cliGitCredential.d.ts +2 -0
- package/dist/cliGitCredential.js +15 -7
- package/dist/cliGuardHealth.d.ts +5 -0
- package/dist/cliGuardHealth.js +6 -1
- package/dist/cliHook.d.ts +3 -13
- package/dist/cliHook.js +68 -43
- package/dist/cliHookClients.d.ts +3 -0
- package/dist/cliHookClients.js +4 -0
- package/dist/cliHookDecide.d.ts +11 -3
- package/dist/cliHookDecide.js +100 -9
- package/dist/cliHookDeliver.js +5 -2
- package/dist/cliHookInput.d.ts +2 -0
- package/dist/cliHookInput.js +10 -0
- package/dist/cliHookInstall.d.ts +6 -1
- package/dist/cliHookInstall.js +36 -9
- package/dist/cliHookStatus.d.ts +13 -0
- package/dist/cliHookStatus.js +54 -5
- package/dist/cliSetupLock.d.ts +1 -1
- package/dist/cliSetupLock.js +4 -3
- package/dist/cliSigningKeys.d.ts +10 -0
- package/dist/cliSigningKeys.js +10 -0
- package/dist/cliStatus.d.ts +5 -0
- package/dist/cliStatus.js +15 -5
- package/dist/controlPlane.generated.d.ts +12 -27
- package/dist/controlPlane.generated.js +11 -2
- package/dist/controlPlaneCli.js +5 -2
- package/dist/controlPlaneGuard.js +9 -5
- package/dist/controlPlaneModel.generated.js +3 -0
- package/dist/controlPlaneOffline.d.ts +67 -0
- package/dist/controlPlaneOffline.js +213 -0
- package/dist/controlPlanePeople.generated.d.ts +9 -0
- package/dist/controlPlaneRailwayGuard.d.ts +7 -0
- package/dist/controlPlaneRailwayGuard.js +15 -2
- package/dist/controlPlaneRoutes.generated.d.ts +63 -0
- package/dist/controlPlaneRoutes.generated.js +111 -0
- package/dist/controlPlaneSupabase.d.ts +7 -0
- package/dist/controlPlaneSupabase.js +16 -3
- package/dist/cpCli.d.ts +20 -0
- package/dist/cpCli.js +102 -1
- package/dist/cpRefusal.d.ts +8 -0
- package/dist/cpRefusal.js +13 -0
- package/dist/gitCredentialRetire.d.ts +25 -0
- package/dist/gitCredentialRetire.js +143 -0
- package/dist/hookAdapters.d.ts +44 -0
- package/dist/hookAdapters.js +106 -0
- package/dist/lockedHooks.d.ts +13 -11
- package/dist/lockedHooks.js +19 -16
- package/dist/managedHooks.d.ts +2 -0
- package/dist/managedHooks.js +24 -3
- package/dist/pluginPin.d.ts +1 -1
- package/dist/pluginPin.js +1 -1
- package/dist/testHookEnv.d.ts +2 -0
- package/dist/testHookEnv.js +26 -0
- package/dist/testSigning.d.ts +5 -0
- package/dist/testSigning.js +19 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* When the guard can't reach Passport (`docs/design/v22/visibility.md`, B4, approved 2026-11-17, hardened 2026-11-18):
|
|
3
|
+
*
|
|
4
|
+
* - Any non-answer counts: no response, a 401, 403, 404, 429 or 5xx, a timeout, an exhausted budget, a 200 that isn't
|
|
5
|
+
* Passport's JSON, or a step that threw.
|
|
6
|
+
* - With a copy of the rules Passport signed for this workspace in the last 7 days (`GET /api/cp/cli` `blocks` and
|
|
7
|
+
* `blocksSignature`, verified against a key this CLI ships), an action a Block rule covers is refused (nearer Allows
|
|
8
|
+
* ignored on purpose). Anything else runs.
|
|
9
|
+
* - With no usable copy (none, unsigned, tampered, another workspace's, older than 7 days, or older than the newest
|
|
10
|
+
* signed copy this computer has seen), the command runs.
|
|
11
|
+
* - Every one of these is recorded as decided offline (`POST /api/cp/decide/offline`): a refusal at once (it won't
|
|
12
|
+
* run), anything that ran once the after-hook for the same tool use says so. "No rules known" is a gap on Home.
|
|
13
|
+
*
|
|
14
|
+
* Classifications only leave this computer: the node, the catalog action and its fixed summary. Never the command.
|
|
15
|
+
* `$PASSPORT_HOME/hook-offline/<key>.json` holds a notice until its command ran; every function here never throws.
|
|
16
|
+
*/
|
|
17
|
+
import { type CachedCpCli } from "./cpCli.js";
|
|
18
|
+
type ApiCall = (path: string, init: RequestInit) => Promise<Response>;
|
|
19
|
+
export declare const CP_DECIDE_OFFLINE_PATH = "/api/cp/decide/offline";
|
|
20
|
+
/** A copy of the rules older than this says nothing: treated as missing. */
|
|
21
|
+
export declare const BLOCKS_MAX_AGE_MS: number;
|
|
22
|
+
export type OfflinePlatform = "github" | "railway" | "supabase";
|
|
23
|
+
/** One thing a line does, as its classifier named it. */
|
|
24
|
+
export type Found = {
|
|
25
|
+
platform: OfflinePlatform;
|
|
26
|
+
nodeId: string;
|
|
27
|
+
actionKey: string;
|
|
28
|
+
summary: string;
|
|
29
|
+
};
|
|
30
|
+
/** How the guard decided offline: refused by a cached Block rule, let run with rules known, or run with none known. */
|
|
31
|
+
export type OfflineDecision = "blocked" | "allowed" | "no_rules";
|
|
32
|
+
export type OfflineNotice = {
|
|
33
|
+
offlineId: string;
|
|
34
|
+
decision: OfflineDecision;
|
|
35
|
+
actions: Found[];
|
|
36
|
+
requestIds?: string[];
|
|
37
|
+
sessionId?: string;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* The rules the guard may use offline: the cached `blocks`, only when Passport signed them for this profile's
|
|
41
|
+
* workspace less than 7 days ago with a key this CLI ships (`cliSigningKeys.ts`), and no older than the newest signed
|
|
42
|
+
* copy this computer has seen (a copy from before a Block rule was added can't be swapped back in). Unsigned,
|
|
43
|
+
* tampered, another workspace's, too old, superseded, or from the future: null (missing). Never throws.
|
|
44
|
+
*/
|
|
45
|
+
export declare function usableBlocks(cached: CachedCpCli | null, profile: string | null, now: number, keys?: Readonly<Record<string, string>>): CachedCpCli["blocks"] | null;
|
|
46
|
+
/** What a line does that a Block rule covers, by the cached rules. */
|
|
47
|
+
export declare function coveredOffline(found: readonly Found[], blocks: NonNullable<CachedCpCli["blocks"]>): Found[];
|
|
48
|
+
/** What the agent reads when a covered action is refused offline. */
|
|
49
|
+
export declare function offlineRefusal(found: Found): string;
|
|
50
|
+
/** The guard: a line it refused offline didn't run, so its notice goes to the outbox at once. Never throws. */
|
|
51
|
+
export declare function queueOffline(profile: string, sessionId: string | undefined, found: readonly Found[], requestIds: readonly string[], decision: OfflineDecision, now?: number): void;
|
|
52
|
+
/** The guard: hold how an offline line was decided until the command is known to have run. */
|
|
53
|
+
export declare function holdOffline(sessionId: string | undefined, toolUseId: string | undefined, found: readonly Found[], requestIds: readonly string[], decision: OfflineDecision, now?: number): void;
|
|
54
|
+
/** The after-hook: the command ran, so its held notice is queued for the flush. */
|
|
55
|
+
export declare function releaseOffline(profile: string, sessionId: string | undefined, toolUseId: string | undefined, now?: number): Promise<void>;
|
|
56
|
+
/** The flush's side: the queued offline notices, and everything else. */
|
|
57
|
+
export declare function splitOffline<T extends object>(queued: readonly T[]): {
|
|
58
|
+
offline: Array<OfflineNotice & {
|
|
59
|
+
ranAt: number;
|
|
60
|
+
}>;
|
|
61
|
+
rest: T[];
|
|
62
|
+
};
|
|
63
|
+
/** Tell Passport what ran offline with no rules known. Never throws. */
|
|
64
|
+
export declare function tellOffline(api: ApiCall, notices: ReadonlyArray<OfflineNotice & {
|
|
65
|
+
ranAt: number;
|
|
66
|
+
}>, signal?: AbortSignal): Promise<void>;
|
|
67
|
+
export {};
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* When the guard can't reach Passport (`docs/design/v22/visibility.md`, B4, approved 2026-11-17, hardened 2026-11-18):
|
|
3
|
+
*
|
|
4
|
+
* - Any non-answer counts: no response, a 401, 403, 404, 429 or 5xx, a timeout, an exhausted budget, a 200 that isn't
|
|
5
|
+
* Passport's JSON, or a step that threw.
|
|
6
|
+
* - With a copy of the rules Passport signed for this workspace in the last 7 days (`GET /api/cp/cli` `blocks` and
|
|
7
|
+
* `blocksSignature`, verified against a key this CLI ships), an action a Block rule covers is refused (nearer Allows
|
|
8
|
+
* ignored on purpose). Anything else runs.
|
|
9
|
+
* - With no usable copy (none, unsigned, tampered, another workspace's, older than 7 days, or older than the newest
|
|
10
|
+
* signed copy this computer has seen), the command runs.
|
|
11
|
+
* - Every one of these is recorded as decided offline (`POST /api/cp/decide/offline`): a refusal at once (it won't
|
|
12
|
+
* run), anything that ran once the after-hook for the same tool use says so. "No rules known" is a gap on Home.
|
|
13
|
+
*
|
|
14
|
+
* Classifications only leave this computer: the node, the catalog action and its fixed summary. Never the command.
|
|
15
|
+
* `$PASSPORT_HOME/hook-offline/<key>.json` holds a notice until its command ran; every function here never throws.
|
|
16
|
+
*/
|
|
17
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
18
|
+
import { mkdirSync, readdirSync, renameSync, rmSync, statSync } from "node:fs";
|
|
19
|
+
import { join } from "node:path";
|
|
20
|
+
import { readBoundedUtf8File } from "./boundedFile.js";
|
|
21
|
+
import { credentialDir, ensurePrivateDirectory, writePrivateAtomic } from "./credentialStorage.js";
|
|
22
|
+
import { CLI_SIGNING_KEYS } from "./cliSigningKeys.js";
|
|
23
|
+
import { noteSeenBlocks, seenBlocksAt, signedByPassport } from "./cpCli.js";
|
|
24
|
+
import { getProfile } from "./credentials.js";
|
|
25
|
+
import { queueReports } from "./hookOutbox.js";
|
|
26
|
+
export const CP_DECIDE_OFFLINE_PATH = "/api/cp/decide/offline";
|
|
27
|
+
/** A copy of the rules older than this says nothing: treated as missing. */
|
|
28
|
+
export const BLOCKS_MAX_AGE_MS = 7 * 24 * 60 * 60_000;
|
|
29
|
+
const HOLD_MS = 60 * 60_000;
|
|
30
|
+
const MAX_HELD = 64;
|
|
31
|
+
const MAX_ACTIONS = 16;
|
|
32
|
+
const MAX_BYTES = 16 * 1024;
|
|
33
|
+
const REQUEST_ID = /^[0-9a-f]{32}$/;
|
|
34
|
+
/** An outbox line that holds an offline notice, not an Activity report. */
|
|
35
|
+
const KEY = "cpDecideOffline";
|
|
36
|
+
const DECISIONS = ["blocked", "allowed", "no_rules"];
|
|
37
|
+
/** A signature dated this far ahead of the computer's clock still counts (clock skew). */
|
|
38
|
+
const SKEW_MS = 5 * 60_000;
|
|
39
|
+
/** The workspace a signed-in profile belongs to: its endpoint's `/w/<ws>/`, else the name after "@". */
|
|
40
|
+
function workspaceOf(profile) {
|
|
41
|
+
try {
|
|
42
|
+
const endpoint = getProfile(profile)?.endpoint ?? "";
|
|
43
|
+
return /\/w\/([A-Za-z0-9_-]{1,64})(?:\/|$)/.exec(endpoint)?.[1] ?? profile.split("@")[1] ?? null;
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The rules the guard may use offline: the cached `blocks`, only when Passport signed them for this profile's
|
|
51
|
+
* workspace less than 7 days ago with a key this CLI ships (`cliSigningKeys.ts`), and no older than the newest signed
|
|
52
|
+
* copy this computer has seen (a copy from before a Block rule was added can't be swapped back in). Unsigned,
|
|
53
|
+
* tampered, another workspace's, too old, superseded, or from the future: null (missing). Never throws.
|
|
54
|
+
*/
|
|
55
|
+
export function usableBlocks(cached, profile, now, keys = CLI_SIGNING_KEYS) {
|
|
56
|
+
const blocks = cached?.blocks;
|
|
57
|
+
const signed = cached?.blocksSignature;
|
|
58
|
+
if (!blocks || !signed || !profile)
|
|
59
|
+
return null;
|
|
60
|
+
if (signed.at > now + SKEW_MS || now - signed.at > BLOCKS_MAX_AGE_MS)
|
|
61
|
+
return null;
|
|
62
|
+
if (signed.ws !== workspaceOf(profile))
|
|
63
|
+
return null;
|
|
64
|
+
if (signed.at < seenBlocksAt(profile))
|
|
65
|
+
return null;
|
|
66
|
+
if (!signedByPassport(blocks, signed, keys))
|
|
67
|
+
return null;
|
|
68
|
+
noteSeenBlocks(profile, signed.at);
|
|
69
|
+
return blocks;
|
|
70
|
+
}
|
|
71
|
+
/** What a line does that a Block rule covers, by the cached rules. */
|
|
72
|
+
export function coveredOffline(found, blocks) {
|
|
73
|
+
return found.filter((entry) => blocks[entry.platform]?.includes(entry.actionKey));
|
|
74
|
+
}
|
|
75
|
+
/** What the agent reads when a covered action is refused offline. */
|
|
76
|
+
export function offlineRefusal(found) {
|
|
77
|
+
return `Passport couldn't be reached, so this didn't run: a Block rule covers "${found.summary}".`;
|
|
78
|
+
}
|
|
79
|
+
const directory = () => join(credentialDir(), "hook-offline");
|
|
80
|
+
function keyOf(sessionId, toolUseId) {
|
|
81
|
+
return createHash("sha256")
|
|
82
|
+
.update(`${sessionId ?? ""}\u0000${toolUseId}`)
|
|
83
|
+
.digest("hex")
|
|
84
|
+
.slice(0, 40);
|
|
85
|
+
}
|
|
86
|
+
function held() {
|
|
87
|
+
try {
|
|
88
|
+
return readdirSync(directory()).filter((name) => /^[0-9a-f]{40}\.json$/.test(name));
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return [];
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function prune(now) {
|
|
95
|
+
for (const name of held()) {
|
|
96
|
+
const path = join(directory(), name);
|
|
97
|
+
try {
|
|
98
|
+
if (now - statSync(path).mtimeMs > HOLD_MS)
|
|
99
|
+
rmSync(path, { force: true });
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
// Best effort.
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/** The guard: hold what an offline line was classified as until the command is known to have run. */
|
|
107
|
+
function noticeOf(sessionId, found, requestIds, decision) {
|
|
108
|
+
return {
|
|
109
|
+
offlineId: randomBytes(16).toString("hex"),
|
|
110
|
+
decision,
|
|
111
|
+
actions: found.slice(0, MAX_ACTIONS),
|
|
112
|
+
...(requestIds.length ? { requestIds: [...new Set(requestIds)].slice(0, MAX_ACTIONS) } : {}),
|
|
113
|
+
...(sessionId ? { sessionId: sessionId.slice(0, 200) } : {})
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
/** The guard: a line it refused offline didn't run, so its notice goes to the outbox at once. Never throws. */
|
|
117
|
+
export function queueOffline(profile, sessionId, found, requestIds, decision, now = Date.now()) {
|
|
118
|
+
if (!found.length)
|
|
119
|
+
return;
|
|
120
|
+
try {
|
|
121
|
+
queueReports(profile, [{ [KEY]: { ...noticeOf(sessionId, found, requestIds, decision), ranAt: now } }], now);
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
// Best effort: the refusal stands either way.
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/** The guard: hold how an offline line was decided until the command is known to have run. */
|
|
128
|
+
export function holdOffline(sessionId, toolUseId, found, requestIds, decision, now = Date.now()) {
|
|
129
|
+
if (!toolUseId || !found.length)
|
|
130
|
+
return;
|
|
131
|
+
try {
|
|
132
|
+
prune(now);
|
|
133
|
+
if (held().length >= MAX_HELD)
|
|
134
|
+
return;
|
|
135
|
+
ensurePrivateDirectory(true);
|
|
136
|
+
mkdirSync(directory(), { recursive: true, mode: 0o700 });
|
|
137
|
+
const notice = noticeOf(sessionId, found, requestIds, decision);
|
|
138
|
+
const contents = JSON.stringify({ heldAt: now, notice });
|
|
139
|
+
if (Buffer.byteLength(contents) > MAX_BYTES)
|
|
140
|
+
return;
|
|
141
|
+
writePrivateAtomic(join(directory(), `${keyOf(sessionId, toolUseId)}.json`), ".hook-offline", contents, "notice");
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
// Best effort: without it the platform's own log still shows the action.
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
function validNotice(value) {
|
|
148
|
+
const notice = value;
|
|
149
|
+
if (!notice || typeof notice.offlineId !== "string" || !REQUEST_ID.test(notice.offlineId))
|
|
150
|
+
return null;
|
|
151
|
+
if (!DECISIONS.includes(notice.decision))
|
|
152
|
+
return null;
|
|
153
|
+
if (!Array.isArray(notice.actions) || !notice.actions.length)
|
|
154
|
+
return null;
|
|
155
|
+
return notice;
|
|
156
|
+
}
|
|
157
|
+
/** The after-hook: the command ran, so its held notice is queued for the flush. */
|
|
158
|
+
export async function releaseOffline(profile, sessionId, toolUseId, now = Date.now()) {
|
|
159
|
+
if (!toolUseId)
|
|
160
|
+
return;
|
|
161
|
+
const path = join(directory(), `${keyOf(sessionId, toolUseId)}.json`);
|
|
162
|
+
const claimed = `${path}.${randomBytes(6).toString("hex")}.claimed`;
|
|
163
|
+
try {
|
|
164
|
+
renameSync(path, claimed);
|
|
165
|
+
}
|
|
166
|
+
catch {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
let notice = null;
|
|
170
|
+
try {
|
|
171
|
+
const parsed = JSON.parse(readBoundedUtf8File(claimed, MAX_BYTES));
|
|
172
|
+
if (typeof parsed.heldAt === "number" && now - parsed.heldAt <= HOLD_MS)
|
|
173
|
+
notice = validNotice(parsed.notice);
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
notice = null;
|
|
177
|
+
}
|
|
178
|
+
finally {
|
|
179
|
+
rmSync(claimed, { force: true });
|
|
180
|
+
}
|
|
181
|
+
if (notice)
|
|
182
|
+
queueReports(profile, [{ [KEY]: { ...notice, ranAt: now } }], now);
|
|
183
|
+
}
|
|
184
|
+
/** The flush's side: the queued offline notices, and everything else. */
|
|
185
|
+
export function splitOffline(queued) {
|
|
186
|
+
const offline = [];
|
|
187
|
+
const rest = [];
|
|
188
|
+
for (const entry of queued) {
|
|
189
|
+
const value = entry[KEY];
|
|
190
|
+
if (value === undefined)
|
|
191
|
+
rest.push(entry);
|
|
192
|
+
else if (validNotice(value) && typeof value.ranAt === "number")
|
|
193
|
+
offline.push(value);
|
|
194
|
+
}
|
|
195
|
+
return { offline, rest };
|
|
196
|
+
}
|
|
197
|
+
/** Tell Passport what ran offline with no rules known. Never throws. */
|
|
198
|
+
export async function tellOffline(api, notices, signal) {
|
|
199
|
+
await Promise.all(notices.map(async (notice) => {
|
|
200
|
+
try {
|
|
201
|
+
const response = await api(CP_DECIDE_OFFLINE_PATH, {
|
|
202
|
+
method: "POST",
|
|
203
|
+
headers: { "content-type": "application/json" },
|
|
204
|
+
body: JSON.stringify(notice),
|
|
205
|
+
...(signal ? { signal } : {})
|
|
206
|
+
});
|
|
207
|
+
await response.body?.cancel().catch(() => undefined);
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
/* Best effort: the platform's own log still shows the action. */
|
|
211
|
+
}
|
|
212
|
+
}));
|
|
213
|
+
}
|
|
@@ -24,6 +24,8 @@ export type CpCoverageGap = {
|
|
|
24
24
|
export type CpPersonCoverage = {
|
|
25
25
|
state: "covered" | "partly" | "not_set_up";
|
|
26
26
|
guard: "on" | "off" | "outdated" | "not_set_up" | "chat_only" | "none";
|
|
27
|
+
/** Locked and fails closed, over every guarded agent on every computer (`CpGuardHardness`). */
|
|
28
|
+
hardness?: CpGuardHardness;
|
|
27
29
|
/** Computers with a guarded agent, and how many have every agent's guard on ("On 1 of 2"). */
|
|
28
30
|
computers: number;
|
|
29
31
|
computersOn: number;
|
|
@@ -108,6 +110,13 @@ export type CpAgentV21 = {
|
|
|
108
110
|
lastSeenTs?: number;
|
|
109
111
|
version?: string;
|
|
110
112
|
program?: true;
|
|
113
|
+
} & CpGuardHardness;
|
|
114
|
+
/** How hard the guard is to get around (2026-11-17, `docs/design/v22/visibility.md`): locked by managed settings, and
|
|
115
|
+
* failing closed (the agent refuses a command when the guard can't run; false where it fails open or can't). Absent
|
|
116
|
+
* where nothing was reported. On a person: true only when every guarded agent on every computer is. */
|
|
117
|
+
export type CpGuardHardness = {
|
|
118
|
+
locked?: boolean;
|
|
119
|
+
failClosed?: boolean;
|
|
111
120
|
};
|
|
112
121
|
/** v21 fields on `CpPersonRow`: coverage, the newest setup link, and (only with `?left=1`) leaving. */
|
|
113
122
|
export type CpPersonV21 = {
|
|
@@ -148,6 +148,13 @@ type RailwayWhere = {
|
|
|
148
148
|
env: Record<string, string | undefined>;
|
|
149
149
|
home: string;
|
|
150
150
|
};
|
|
151
|
+
/** What a line's railway commands do, classified locally (for when Passport can't be reached). */
|
|
152
|
+
export declare function railwayFound(command: string, where: RailwayWhere): Promise<{
|
|
153
|
+
platform: "railway";
|
|
154
|
+
nodeId: string;
|
|
155
|
+
actionKey: string;
|
|
156
|
+
summary: string;
|
|
157
|
+
}[]>;
|
|
151
158
|
/** The guard's question for a line's railway commands: classified in the link of the folder each runs in, asked once
|
|
152
159
|
* each, marked when it certainly reaches `passport exec`. */
|
|
153
160
|
export declare function railwayLinePlan(command: string, where: RailwayWhere, api: () => Promise<ApiCall | null>, extra: {
|
|
@@ -46,7 +46,7 @@ import { readBoundedJson } from "./boundedResponse.js";
|
|
|
46
46
|
import { isDecisionId } from "./railwayDecisions.js";
|
|
47
47
|
import { beginShadowLine, shadowAlongside, shadowRailwayLine, spoolShadow } from "./kitShadow.js";
|
|
48
48
|
import { cdTarget, changesPath, runnerFolder } from "./controlPlaneRailwayReach.js";
|
|
49
|
-
import { refusalOf } from "./cpRefusal.js";
|
|
49
|
+
import { NO_ANSWER_STATUSES, noAnswer, refusalOf } from "./cpRefusal.js";
|
|
50
50
|
/** Set by `passport exec` in what a railway command starts: the id of the credential Passport minted for it
|
|
51
51
|
* (`controlPlaneExec.ts` sets it under the same name). */
|
|
52
52
|
export const EXEC_CREDENTIAL_ENV = "PASSPORT_EXEC_CREDENTIAL";
|
|
@@ -424,6 +424,8 @@ export async function askRailway(api, bundle, ask, signal) {
|
|
|
424
424
|
}
|
|
425
425
|
if (response.status >= 500)
|
|
426
426
|
return unreachable;
|
|
427
|
+
if (NO_ANSWER_STATUSES.has(response.status))
|
|
428
|
+
return noAnswer(response, unreachable);
|
|
427
429
|
if (!response.ok)
|
|
428
430
|
return { kind: "undecided" };
|
|
429
431
|
let body;
|
|
@@ -431,7 +433,8 @@ export async function askRailway(api, bundle, ask, signal) {
|
|
|
431
433
|
body = await readBoundedJson(response);
|
|
432
434
|
}
|
|
433
435
|
catch {
|
|
434
|
-
|
|
436
|
+
// A 200 that isn't Passport's JSON (a captive portal, a proxy): no answer.
|
|
437
|
+
return unreachable;
|
|
435
438
|
}
|
|
436
439
|
if (body.allow === true) {
|
|
437
440
|
return {
|
|
@@ -489,6 +492,16 @@ async function readLine(command, where) {
|
|
|
489
492
|
const place = where.cwd ? { cwd: where.cwd, home: where.home, linkFor } : undefined;
|
|
490
493
|
return { linked, read: readRailwayLine(command, linked, place) };
|
|
491
494
|
}
|
|
495
|
+
/** What a line's railway commands do, classified locally (for when Passport can't be reached). */
|
|
496
|
+
export async function railwayFound(command, where) {
|
|
497
|
+
const { read } = await readLine(command, where);
|
|
498
|
+
return read.bundles.flatMap((bundle) => bundle.found.map((found) => ({
|
|
499
|
+
platform: "railway",
|
|
500
|
+
nodeId: found.nodeId,
|
|
501
|
+
actionKey: found.actionKey,
|
|
502
|
+
summary: found.summary.slice(0, MAX_SUMMARY)
|
|
503
|
+
})));
|
|
504
|
+
}
|
|
492
505
|
/** The guard's question for a line's railway commands: classified in the link of the folder each runs in, asked once
|
|
493
506
|
* each, marked when it certainly reaches `passport exec`. */
|
|
494
507
|
export async function railwayLinePlan(command, where, api, extra, signal) {
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Coverage per route (decided 2026-11-17, `docs/design/v22/visibility.md`): how each action reached an app, so an
|
|
3
|
+
* app's one coverage number splits into the door that is open. Pure; part of the contract with `controlPlane.ts`,
|
|
4
|
+
* changed only through the orchestrating session.
|
|
5
|
+
*/
|
|
6
|
+
import type { UnnamedHit } from "./controlPlaneUnnamed.generated.js";
|
|
7
|
+
/** `Interface` and the event fields read here, spelled out so `controlPlane.ts` can import this file. */
|
|
8
|
+
type Via = "mcp" | "cli" | "api" | "platform";
|
|
9
|
+
/**
|
|
10
|
+
* How an action reached the app. `gh`, `git`: the CLI the event says it came from; `cli`: any other CLI (railway,
|
|
11
|
+
* supabase). `platform`: seen only in the app's own log, so the route is unknown ("Outside").
|
|
12
|
+
*/
|
|
13
|
+
export declare const ROUTES: readonly ["gh", "git", "cli", "mcp", "api", "platform"];
|
|
14
|
+
export type Route = (typeof ROUTES)[number];
|
|
15
|
+
/** One route of a deep app over the coverage window, counted as `managedCoverageOf` counts (app traffic and events
|
|
16
|
+
* on an account Passport isn't connected to left out). The routes' totals add up to the app's `coverage.total`. */
|
|
17
|
+
export type CpRouteCoverage = {
|
|
18
|
+
route: Route;
|
|
19
|
+
total: number;
|
|
20
|
+
/** Managed and Followed. */
|
|
21
|
+
through: number;
|
|
22
|
+
/** Unmanaged. */
|
|
23
|
+
outside: number;
|
|
24
|
+
/** Of `total`, actions Passport can't name yet (`*.unclassified`). */
|
|
25
|
+
unnamed: number;
|
|
26
|
+
/** Rounded percent of `total` through Passport; null when `total` is 0. */
|
|
27
|
+
percent: number | null;
|
|
28
|
+
/** Whose Unmanaged actions these were, most first, at most 3 (member ids): for Home's "To raise it", which names
|
|
29
|
+
* people and agents, never routes. Absent when none is known. */
|
|
30
|
+
people?: string[];
|
|
31
|
+
};
|
|
32
|
+
/** The actions a `git push` records: each ref moved, a tag, a workflow file in the pushed commits. */
|
|
33
|
+
export declare const GIT_PUSH_ACTIONS: ReadonlySet<string>;
|
|
34
|
+
export type RouteInput = {
|
|
35
|
+
platform: string;
|
|
36
|
+
interface: Via;
|
|
37
|
+
actionKey: string;
|
|
38
|
+
outcome?: string;
|
|
39
|
+
unnamed?: UnnamedHit;
|
|
40
|
+
};
|
|
41
|
+
/** The route of one event (the spec's rules, in order). */
|
|
42
|
+
export declare function routeOf(event: RouteInput): Route;
|
|
43
|
+
/** Each route's counts, in `ROUTES` order, routes with nothing left out. Pure. */
|
|
44
|
+
export declare function routeCoverage(rows: Iterable<{
|
|
45
|
+
route: Route;
|
|
46
|
+
cls: "managed" | "followed" | "unmanaged";
|
|
47
|
+
unnamed: boolean;
|
|
48
|
+
count: number;
|
|
49
|
+
personId?: string;
|
|
50
|
+
}>): CpRouteCoverage[];
|
|
51
|
+
/** Coverage per route straight from events (the web's example data; the server groups in its store): each event's
|
|
52
|
+
* class as `managedCoverageOf` decides it, app traffic and events on an account not connected left out. Pure. */
|
|
53
|
+
export declare function routesOfEvents(events: readonly (RouteInput & {
|
|
54
|
+
through: "passport" | "outside" | "offline";
|
|
55
|
+
surface?: string;
|
|
56
|
+
cause?: {
|
|
57
|
+
through: string;
|
|
58
|
+
platform: string;
|
|
59
|
+
};
|
|
60
|
+
notConnected?: boolean;
|
|
61
|
+
personId?: string;
|
|
62
|
+
})[]): CpRouteCoverage[];
|
|
63
|
+
export {};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// Generated by scripts/generate-control-plane-classifier.mjs. Do not edit.
|
|
2
|
+
/**
|
|
3
|
+
* Coverage per route (decided 2026-11-17, `docs/design/v22/visibility.md`): how each action reached an app, so an
|
|
4
|
+
* app's one coverage number splits into the door that is open. Pure; part of the contract with `controlPlane.ts`,
|
|
5
|
+
* changed only through the orchestrating session.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* How an action reached the app. `gh`, `git`: the CLI the event says it came from; `cli`: any other CLI (railway,
|
|
9
|
+
* supabase). `platform`: seen only in the app's own log, so the route is unknown ("Outside").
|
|
10
|
+
*/
|
|
11
|
+
export const ROUTES = ["gh", "git", "cli", "mcp", "api", "platform"];
|
|
12
|
+
/** People a route names at most. */
|
|
13
|
+
const MAX_PEOPLE = 3;
|
|
14
|
+
/** The actions a `git push` records: each ref moved, a tag, a workflow file in the pushed commits. */
|
|
15
|
+
export const GIT_PUSH_ACTIONS = new Set([
|
|
16
|
+
"github.branch.push",
|
|
17
|
+
"github.branch.force",
|
|
18
|
+
"github.branch.delete",
|
|
19
|
+
"github.repo.tag",
|
|
20
|
+
"github.repo.workflow"
|
|
21
|
+
]);
|
|
22
|
+
/** The CLI a command-line action came from. */
|
|
23
|
+
function programOf(platform, actionKey, unnamed) {
|
|
24
|
+
if (unnamed?.via === "cli") {
|
|
25
|
+
const program = unnamed.command.split(" ")[0];
|
|
26
|
+
return program === "gh" || program === "git" ? program : "cli";
|
|
27
|
+
}
|
|
28
|
+
if (platform !== "github")
|
|
29
|
+
return "cli";
|
|
30
|
+
// The guard asks GitHub about `gh` and `git push` lines only; an unnamed API call on a command line is `gh api`.
|
|
31
|
+
return GIT_PUSH_ACTIONS.has(actionKey) ? "git" : "gh";
|
|
32
|
+
}
|
|
33
|
+
/** The route of one event (the spec's rules, in order). */
|
|
34
|
+
export function routeOf(event) {
|
|
35
|
+
const via = event.interface;
|
|
36
|
+
if (via === "mcp" || via === "api")
|
|
37
|
+
return via;
|
|
38
|
+
if (via === "cli")
|
|
39
|
+
return programOf(event.platform, event.actionKey, event.unnamed);
|
|
40
|
+
// Passport's own credential with no decision: something used Passport's connection directly.
|
|
41
|
+
return event.outcome === "undecided" ? "api" : "platform";
|
|
42
|
+
}
|
|
43
|
+
/** Each route's counts, in `ROUTES` order, routes with nothing left out. Pure. */
|
|
44
|
+
export function routeCoverage(rows) {
|
|
45
|
+
const byRoute = new Map();
|
|
46
|
+
const peopleOf = new Map();
|
|
47
|
+
for (const row of rows) {
|
|
48
|
+
if (row.count <= 0)
|
|
49
|
+
continue;
|
|
50
|
+
const entry = byRoute.get(row.route) ?? {
|
|
51
|
+
route: row.route,
|
|
52
|
+
total: 0,
|
|
53
|
+
through: 0,
|
|
54
|
+
outside: 0,
|
|
55
|
+
unnamed: 0,
|
|
56
|
+
percent: null
|
|
57
|
+
};
|
|
58
|
+
entry.total += row.count;
|
|
59
|
+
if (row.cls === "unmanaged") {
|
|
60
|
+
entry.outside += row.count;
|
|
61
|
+
if (row.personId) {
|
|
62
|
+
const people = peopleOf.get(row.route) ?? new Map();
|
|
63
|
+
people.set(row.personId, (people.get(row.personId) ?? 0) + row.count);
|
|
64
|
+
peopleOf.set(row.route, people);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else
|
|
68
|
+
entry.through += row.count;
|
|
69
|
+
if (row.unnamed)
|
|
70
|
+
entry.unnamed += row.count;
|
|
71
|
+
byRoute.set(row.route, entry);
|
|
72
|
+
}
|
|
73
|
+
return ROUTES.flatMap((route) => {
|
|
74
|
+
const entry = byRoute.get(route);
|
|
75
|
+
if (!entry)
|
|
76
|
+
return [];
|
|
77
|
+
const people = [...(peopleOf.get(route) ?? new Map())]
|
|
78
|
+
.sort((a, b) => b[1] - a[1] || (a[0] < b[0] ? -1 : 1))
|
|
79
|
+
.slice(0, MAX_PEOPLE)
|
|
80
|
+
.map(([id]) => id);
|
|
81
|
+
return [
|
|
82
|
+
{
|
|
83
|
+
...entry,
|
|
84
|
+
percent: entry.total ? Math.round((entry.through / entry.total) * 100) : null,
|
|
85
|
+
...(people.length ? { people } : {})
|
|
86
|
+
}
|
|
87
|
+
];
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/** Coverage per route straight from events (the web's example data; the server groups in its store): each event's
|
|
91
|
+
* class as `managedCoverageOf` decides it, app traffic and events on an account not connected left out. Pure. */
|
|
92
|
+
export function routesOfEvents(events) {
|
|
93
|
+
return routeCoverage(events.flatMap((event) => {
|
|
94
|
+
if (event.notConnected === true || event.surface === "app" || event.outcome === "offline_blocked")
|
|
95
|
+
return [];
|
|
96
|
+
const cls = event.through === "passport" && event.outcome !== "undecided"
|
|
97
|
+
? "managed"
|
|
98
|
+
: event.cause?.through === "passport" && event.cause.platform === event.platform
|
|
99
|
+
? "followed"
|
|
100
|
+
: "unmanaged";
|
|
101
|
+
return [
|
|
102
|
+
{
|
|
103
|
+
route: routeOf(event),
|
|
104
|
+
cls,
|
|
105
|
+
unnamed: event.actionKey.endsWith(".unclassified"),
|
|
106
|
+
count: 1,
|
|
107
|
+
...(event.personId ? { personId: event.personId } : {})
|
|
108
|
+
}
|
|
109
|
+
];
|
|
110
|
+
}));
|
|
111
|
+
}
|
|
@@ -51,6 +51,13 @@ export declare function curlRequest(argv: readonly string[]): Extract<Request, {
|
|
|
51
51
|
}> | null;
|
|
52
52
|
/** Every Supabase command of a line, each with what it does: `supabase` commands as the kit's resolver reads them,
|
|
53
53
|
* then `curl` calls to the Management API. Reads leave nothing. */
|
|
54
|
+
/** What a line's Supabase commands do, classified locally (for when Passport can't be reached). */
|
|
55
|
+
export declare function supabaseFound(command: string, where: SupabaseWhere): {
|
|
56
|
+
platform: "supabase";
|
|
57
|
+
nodeId: string;
|
|
58
|
+
actionKey: string;
|
|
59
|
+
summary: string;
|
|
60
|
+
}[];
|
|
54
61
|
export declare function classifySupabaseLine(command: string, where: SupabaseWhere): SupabaseBundle[];
|
|
55
62
|
/** One `supabase …` command exec runs, as one bundle; null when it only reads. */
|
|
56
63
|
export declare function classifySupabaseArgv(argv: readonly string[], where: SupabaseWhere): SupabaseBundle | null;
|
|
@@ -31,7 +31,7 @@ import { SUPABASE } from "./connectorKit/manifests/supabase.generated.js";
|
|
|
31
31
|
import { resolveCommand } from "./connectorKit/shell.generated.js";
|
|
32
32
|
import { CP_DECIDE_PATH, CP_DECIDE_TIMEOUT_MS, targetDigest, worstAnswer } from "./controlPlaneGuard.js";
|
|
33
33
|
import { newRequestId } from "./controlPlaneLate.js";
|
|
34
|
-
import { refusalOf } from "./cpRefusal.js";
|
|
34
|
+
import { NO_ANSWER_STATUSES, noAnswer, refusalOf } from "./cpRefusal.js";
|
|
35
35
|
/** At most this many Supabase commands in one line are asked about; a line doing more is refused. */
|
|
36
36
|
export const MAX_SUPABASE_COMMANDS = 8;
|
|
37
37
|
/** A bundle holds at most this many actions (the server's bound). */
|
|
@@ -145,6 +145,15 @@ export function curlRequest(argv) {
|
|
|
145
145
|
}
|
|
146
146
|
/** Every Supabase command of a line, each with what it does: `supabase` commands as the kit's resolver reads them,
|
|
147
147
|
* then `curl` calls to the Management API. Reads leave nothing. */
|
|
148
|
+
/** What a line's Supabase commands do, classified locally (for when Passport can't be reached). */
|
|
149
|
+
export function supabaseFound(command, where) {
|
|
150
|
+
return classifySupabaseLine(command, where).flatMap((bundle) => bundle.found.map((found) => ({
|
|
151
|
+
platform: "supabase",
|
|
152
|
+
nodeId: found.nodeId,
|
|
153
|
+
actionKey: found.actionKey,
|
|
154
|
+
summary: found.summary.slice(0, MAX_SUMMARY)
|
|
155
|
+
})));
|
|
156
|
+
}
|
|
148
157
|
export function classifySupabaseLine(command, where) {
|
|
149
158
|
const bundles = [];
|
|
150
159
|
const guard = supabaseGuard(where);
|
|
@@ -232,8 +241,11 @@ export async function askSupabase(api, bundle, ask, signal) {
|
|
|
232
241
|
catch {
|
|
233
242
|
return answered({ kind: "unreachable", late: [requestId] });
|
|
234
243
|
}
|
|
244
|
+
const unreachable = { kind: "unreachable", late: [requestId] };
|
|
235
245
|
if (response.status >= 500)
|
|
236
|
-
return answered(
|
|
246
|
+
return answered(unreachable);
|
|
247
|
+
if (NO_ANSWER_STATUSES.has(response.status))
|
|
248
|
+
return answered(await noAnswer(response, unreachable));
|
|
237
249
|
if (!response.ok) {
|
|
238
250
|
await response.body?.cancel().catch(() => undefined);
|
|
239
251
|
return answered({ kind: "undecided" });
|
|
@@ -243,7 +255,8 @@ export async function askSupabase(api, bundle, ask, signal) {
|
|
|
243
255
|
body = await readBoundedJson(response);
|
|
244
256
|
}
|
|
245
257
|
catch {
|
|
246
|
-
|
|
258
|
+
// A 200 that isn't Passport's JSON (a captive portal, a proxy): no answer.
|
|
259
|
+
return answered(unreachable);
|
|
247
260
|
}
|
|
248
261
|
if (body.allow === true)
|
|
249
262
|
return answered({ kind: "allow", eventId: typeof body.eventId === "string" ? body.eventId : null });
|
package/dist/cpCli.d.ts
CHANGED
|
@@ -17,7 +17,27 @@ type Platform = (typeof PLATFORMS)[number];
|
|
|
17
17
|
export type CpCli = {
|
|
18
18
|
platforms: Partial<Record<Platform, true>>;
|
|
19
19
|
vendors: string[];
|
|
20
|
+
/** Per platform, the action keys a Block rule could decide: kept for when Passport can't be reached
|
|
21
|
+
* (`controlPlaneOffline.ts`). Absent: the server didn't say, so the rules are unknown. */
|
|
22
|
+
blocks?: Partial<Record<Platform, string[]>>;
|
|
23
|
+
/** `blocks`' signature (Ed25519 by Passport's CLI signing key): verified before the copy is used. */
|
|
24
|
+
blocksSignature?: BlocksSignature;
|
|
20
25
|
};
|
|
26
|
+
/** Who signed `blocks`, for which workspace and when (epoch ms), and the signature (base64url). */
|
|
27
|
+
export type BlocksSignature = {
|
|
28
|
+
ws: string;
|
|
29
|
+
at: number;
|
|
30
|
+
kid: string;
|
|
31
|
+
sig: string;
|
|
32
|
+
};
|
|
33
|
+
/** The exact bytes `blocks` are signed over: a checked copy of shared/cpCli.ts `blocksSigningInput`. */
|
|
34
|
+
export declare function blocksSigningInput(ws: string, at: number, blocks: Partial<Record<Platform, readonly string[]>>): string;
|
|
35
|
+
/** Whether Passport signed these `blocks` with a key this CLI ships. Never throws. */
|
|
36
|
+
export declare function signedByPassport(blocks: Partial<Record<Platform, readonly string[]>>, signed: BlocksSignature, keys?: Readonly<Record<string, string>>): boolean;
|
|
37
|
+
/** The newest signed time of rules this computer has seen for a profile (0 when none). Never throws. */
|
|
38
|
+
export declare function seenBlocksAt(profile: string): number;
|
|
39
|
+
/** Remember the newest signed rules seen, so a copy from before can't be swapped back in. Never throws. */
|
|
40
|
+
export declare function noteSeenBlocks(profile: string, at: number): void;
|
|
21
41
|
export type CachedCpCli = CpCli & {
|
|
22
42
|
fetchedAt: number;
|
|
23
43
|
};
|