passport-bridge 0.46.1 → 0.48.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cliExec.js +2 -2
- package/dist/cliGitCredential.js +3 -9
- 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 +12 -3
- package/dist/cliHookDecide.js +120 -11
- 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/connectorKit/engine.generated.js +16 -6
- package/dist/connectorKit/githubDecide.generated.d.ts +57 -0
- package/dist/connectorKit/githubDecide.generated.js +247 -0
- package/dist/{controlPlaneGithubCatalog.generated.d.ts → connectorKit/githubIds.generated.d.ts} +8 -12
- package/dist/{controlPlaneGithubCatalog.generated.js → connectorKit/githubIds.generated.js} +2 -33
- package/dist/connectorKit/http.generated.d.ts +33 -0
- package/dist/connectorKit/http.generated.js +399 -0
- package/dist/connectorKit/manifest.generated.d.ts +10 -1
- package/dist/connectorKit/manifests/github.generated.d.ts +1 -0
- package/dist/connectorKit/manifests/github.generated.js +39 -3
- package/dist/connectorKit/manifests/githubActionList.generated.d.ts +30 -0
- package/dist/connectorKit/manifests/githubActionList.generated.js +22 -0
- package/dist/connectorKit/manifests/githubCapture.generated.js +150 -84
- package/dist/connectorKit/manifests/githubGenerated.generated.d.ts +40 -0
- package/dist/connectorKit/manifests/githubGenerated.generated.js +143 -0
- package/dist/connectorKit/manifests/githubHooks.generated.d.ts +8 -0
- package/dist/connectorKit/manifests/githubHooks.generated.js +229 -29
- package/dist/connectorKit/manifests/githubReads.generated.js +23 -24
- package/dist/connectorKit/shadow.generated.d.ts +4 -10
- package/dist/connectorKit/shadow.generated.js +4 -40
- package/dist/connectorKit/sources/github/actions.generated.d.ts +35 -0
- package/dist/connectorKit/sources/github/actions.generated.js +2 -0
- package/dist/connectorKit/sources/github/catalog.generated.d.ts +2220 -0
- package/dist/connectorKit/sources/github/catalog.generated.js +2 -0
- package/dist/controlPlane.generated.d.ts +14 -32
- package/dist/controlPlane.generated.js +16 -5
- package/dist/controlPlaneCli.js +5 -2
- package/dist/controlPlaneGuard.d.ts +7 -7
- package/dist/controlPlaneGuard.js +37 -45
- 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 +1 -1
- package/dist/controlPlaneRoutes.generated.js +1 -1
- package/dist/controlPlaneSupabase.d.ts +7 -0
- package/dist/controlPlaneSupabase.js +16 -3
- package/dist/cpCli.d.ts +22 -0
- package/dist/cpCli.js +108 -1
- package/dist/cpRefusal.d.ts +8 -0
- package/dist/cpRefusal.js +13 -0
- package/dist/execGithubRepo.js +6 -5
- package/dist/gitPush.d.ts +1 -11
- package/dist/gitPush.js +2 -5
- package/dist/hookAdapters.d.ts +44 -0
- package/dist/hookAdapters.js +106 -0
- package/dist/kitShadow.d.ts +2 -11
- package/dist/kitShadow.js +2 -7
- 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
- package/dist/controlPlaneGithub.generated.d.ts +0 -45
- package/dist/controlPlaneGithub.generated.js +0 -101
- package/dist/controlPlaneGithubApi.generated.d.ts +0 -17
- package/dist/controlPlaneGithubApi.generated.js +0 -172
- package/dist/controlPlaneGithubCli.generated.d.ts +0 -104
- package/dist/controlPlaneGithubCli.generated.js +0 -367
- package/dist/controlPlaneGithubWebhook.generated.d.ts +0 -30
- package/dist/controlPlaneGithubWebhook.generated.js +0 -105
package/dist/cliExec.js
CHANGED
|
@@ -19,7 +19,7 @@ import { memberApi } from "./cliClient.js";
|
|
|
19
19
|
import { passportUnreachable } from "./cliOutput.js";
|
|
20
20
|
import { execControlPlaneRefusal, execIdsWanted, execRailwayScope, execSupabaseProject } from "./controlPlaneExec.js";
|
|
21
21
|
import { classifyCommand, UNRECOGNIZED_VERB } from "./cliHookClassify.js";
|
|
22
|
-
import {
|
|
22
|
+
import { ghApiMethod, ghValueFlags, parseArgs as parseGhArgs } from "./connectorKit/githubDecide.generated.js";
|
|
23
23
|
import { redactCommand } from "./cliHookRedact.js";
|
|
24
24
|
import { callerFrom, failure, readBoundedJson, resolveCliAuth, safeApiError, timeoutMs } from "./cliSupport.js";
|
|
25
25
|
import { EXEC_PASSPORT_ENV, EXEC_CARRIERS, EXEC_VENDOR_NAMES, execVendorOf } from "./execVendors.js";
|
|
@@ -64,7 +64,7 @@ export function execFinding(vendor, binary, args) {
|
|
|
64
64
|
// `gh api`: Passport reads the method (a read isn't decided; anything else is decided), never the endpoint.
|
|
65
65
|
if (vendor !== "gh" || carrier || finding.verb.split(" ")[0] !== "api")
|
|
66
66
|
return finding;
|
|
67
|
-
const parsed = parseGhArgs(args,
|
|
67
|
+
const parsed = parseGhArgs(args, ghValueFlags("api"));
|
|
68
68
|
if (parsed.pos[0] !== "api")
|
|
69
69
|
return finding;
|
|
70
70
|
const { method, read } = ghApiMethod(parsed);
|
package/dist/cliGitCredential.js
CHANGED
|
@@ -44,7 +44,7 @@ import { compareVersions } from "./launcherHealth.js";
|
|
|
44
44
|
import { VERSION } from "./version.js";
|
|
45
45
|
import { askingGitCommand, execGitCommand, isPush } from "./gitInvocation.js";
|
|
46
46
|
import { MAX_PUSH_REFS, planKey, planPush } from "./gitPush.js";
|
|
47
|
-
import {
|
|
47
|
+
import { shadowAlongside } from "./kitShadow.js";
|
|
48
48
|
import { takePushDecisions } from "./gitPushDecisions.js";
|
|
49
49
|
import { helperLine, helperProgram, installGitCredential, probeHelper, readGitCredentialState, removeGitCredential } from "./gitCredentialSetup.js";
|
|
50
50
|
import { GIT_OFF, issuesCredentials, offResult } from "./offInV1.js";
|
|
@@ -285,12 +285,10 @@ async function get(args, runtime, deps, input) {
|
|
|
285
285
|
}
|
|
286
286
|
// A push: what it changes, ref by ref. Only the classification leaves this computer.
|
|
287
287
|
const [owner, name] = repo.split("/");
|
|
288
|
-
const lines = [];
|
|
289
288
|
const plan = planPush(asking, {
|
|
290
289
|
cwd: deps.cwd ?? process.cwd(),
|
|
291
290
|
env: runtime.env,
|
|
292
291
|
repo: { owner, repo: name },
|
|
293
|
-
onLine: (line) => void lines.push(line),
|
|
294
292
|
...(deps.run ? { run: deps.run } : {})
|
|
295
293
|
});
|
|
296
294
|
if (!plan)
|
|
@@ -301,14 +299,10 @@ async function get(args, runtime, deps, input) {
|
|
|
301
299
|
if (got.kind !== "refused" || got.code !== "undecided")
|
|
302
300
|
return got.kind === "token" ? answer(got.minted) : refused(got);
|
|
303
301
|
// Passport would issue a push token once it decides the push: every ref, and
|
|
304
|
-
// a block on any stops git here.
|
|
305
|
-
|
|
306
|
-
for (const line of lines)
|
|
307
|
-
shadowGithubLine(line.argv, line.place, line.found);
|
|
308
|
-
// The shadow's counts ride along with these decisions, never waited on: stopped once they're answered.
|
|
302
|
+
// a block on any stops git here.
|
|
303
|
+
// The shadow's counts (Railway's, from earlier lines) ride along with these decisions, never waited on.
|
|
309
304
|
const stopShadow = shadowAlongside(api, runtime.signal);
|
|
310
305
|
const decided = await decidePush(api, plan.classifications, runtime, deps, left).finally(stopShadow);
|
|
311
|
-
shadowAfterDecision();
|
|
312
306
|
if (decided.kind === "block")
|
|
313
307
|
return "quit=1\n";
|
|
314
308
|
if (decided.kind === "own")
|
package/dist/cliGuardHealth.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { type CodexTrust } from "./cliCodexTrust.js";
|
|
|
12
12
|
import type { Env } from "./cliSupport.js";
|
|
13
13
|
export declare const GUARD_CLIENTS: readonly ["claude-code", "codex", "cursor"];
|
|
14
14
|
export type GuardClient = (typeof GUARD_CLIENTS)[number];
|
|
15
|
+
export declare const isGuardClient: (value: unknown) => value is GuardClient;
|
|
15
16
|
export declare const GUARD_CLIENT_LABEL: Readonly<Record<GuardClient, string>>;
|
|
16
17
|
export type { CodexTrust };
|
|
17
18
|
export type GuardMode = "audit+guard" | "audit" | "guard" | "plugin" | "none" | "unreadable";
|
|
@@ -23,10 +24,14 @@ export type GuardClientReport = {
|
|
|
23
24
|
plugin: boolean;
|
|
24
25
|
codexTrust?: CodexTrust;
|
|
25
26
|
locked?: boolean;
|
|
27
|
+
/** The guard that runs fails closed (the agent refuses the command when the hook can't run). Codex can't. */
|
|
28
|
+
failClosed?: boolean;
|
|
26
29
|
disabledEnv?: boolean;
|
|
27
30
|
/** Hook events Passport's entry should be on but isn't. */
|
|
28
31
|
missing?: string[];
|
|
29
32
|
};
|
|
33
|
+
/** Agents with a setting that makes a hook fail closed (Claude Code `onFailure`, Cursor `failClosed`). */
|
|
34
|
+
export declare const CAN_FAIL_CLOSED: ReadonlySet<GuardClient>;
|
|
30
35
|
export type GuardHealthReport = {
|
|
31
36
|
cliVersion: string;
|
|
32
37
|
launcherTarget?: string;
|
package/dist/cliGuardHealth.js
CHANGED
|
@@ -12,17 +12,20 @@ import { closeSync, constants, mkdirSync, openSync, readFileSync, statSync, utim
|
|
|
12
12
|
import { join } from "node:path";
|
|
13
13
|
import { readBoundedJson } from "./boundedResponse.js";
|
|
14
14
|
import { codexGuardTrust } from "./cliCodexTrust.js";
|
|
15
|
-
import { managedPassportHook } from "./managedHooks.js";
|
|
15
|
+
import { managedFailClosed, managedPassportHook } from "./managedHooks.js";
|
|
16
16
|
import { credentialDir, ensurePrivateDirectory } from "./credentialStorage.js";
|
|
17
17
|
import { assertProfileName } from "./credentials.js";
|
|
18
18
|
import { VERSION } from "./version.js";
|
|
19
19
|
/* ---- Guard states and their fixes, in the web's words: On · Off · Outdated · Not trusted · Locked ---- */
|
|
20
20
|
export const GUARD_CLIENTS = ["claude-code", "codex", "cursor"];
|
|
21
|
+
export const isGuardClient = (value) => typeof value === "string" && GUARD_CLIENTS.includes(value);
|
|
21
22
|
export const GUARD_CLIENT_LABEL = {
|
|
22
23
|
"claude-code": "Claude Code",
|
|
23
24
|
codex: "Codex",
|
|
24
25
|
cursor: "Cursor"
|
|
25
26
|
};
|
|
27
|
+
/** Agents with a setting that makes a hook fail closed (Claude Code `onFailure`, Cursor `failClosed`). */
|
|
28
|
+
export const CAN_FAIL_CLOSED = new Set(["claude-code", "cursor"]);
|
|
26
29
|
export const GUARD_STATE_LABEL = {
|
|
27
30
|
on: "On",
|
|
28
31
|
locked: "Locked",
|
|
@@ -146,6 +149,7 @@ export async function guardClientReports(env) {
|
|
|
146
149
|
return GUARD_CLIENTS.map((client) => {
|
|
147
150
|
const status = agentHookStatus(client, env);
|
|
148
151
|
const locked = managedGuard(client, env);
|
|
152
|
+
const failClosed = locked ? managedFailClosed(client, env) === true : status.failClosed === true;
|
|
149
153
|
const codexTrust = client === "codex" && status.guardCommand && !status.plugin
|
|
150
154
|
? codexGuardTrust(codexHooksPath(env), isPassportGuardCommand)
|
|
151
155
|
: undefined;
|
|
@@ -157,6 +161,7 @@ export async function guardClientReports(env) {
|
|
|
157
161
|
plugin: status.plugin,
|
|
158
162
|
...(codexTrust ? { codexTrust } : {}),
|
|
159
163
|
...(locked ? { locked: true } : {}),
|
|
164
|
+
...(failClosed ? { failClosed: true } : {}),
|
|
160
165
|
...(env.PASSPORT_HOOK_DISABLED === "1" ? { disabledEnv: true } : {}),
|
|
161
166
|
// Slots an older install never got: the agent reads as Partly set up.
|
|
162
167
|
...(status.missing.length && !locked ? { missing: status.missing } : {})
|
package/dist/cliHook.d.ts
CHANGED
|
@@ -12,27 +12,19 @@
|
|
|
12
12
|
*
|
|
13
13
|
* Both work inside `HOOK_BUDGET_MS`, and neither ever sends the command line,
|
|
14
14
|
* its arguments, the output, the full working directory, or the environment.
|
|
15
|
-
*
|
|
16
|
-
* this hook going wrong.
|
|
15
|
+
* The guard refuses a payload it can't read (exit 2, `hookAdapters.ts`); any
|
|
16
|
+
* other failure is silent: the agent must never notice this hook going wrong.
|
|
17
17
|
*/
|
|
18
18
|
import { type ParsedArgs } from "./cliArgs.js";
|
|
19
19
|
import { type CliFinding } from "./cliHookClassify.js";
|
|
20
20
|
import { type GuardClient } from "./cliHookGuard.js";
|
|
21
21
|
import { type HookInput } from "./cliHookInput.js";
|
|
22
|
+
export { shellEvent } from "./hookAdapters.js";
|
|
22
23
|
import { type ApiCall, type CliHookReport, type HookDependencies, type HookRuntime } from "./cliHookDeliver.js";
|
|
23
24
|
export { HOOK_BUDGET_MS, HOOK_RUNTIMES, type CliHookReport, type HookDependencies, type HookRuntime, type ReportedFinding } from "./cliHookDeliver.js";
|
|
24
25
|
export { outcomeOf } from "./cliHookOutcome.js";
|
|
25
26
|
import type { CommandResult, Env, Runtime } from "./cliSupport.js";
|
|
26
27
|
export type { HookInput };
|
|
27
|
-
/** One shell command, whichever agent format it arrived in. */
|
|
28
|
-
type ShellEvent = {
|
|
29
|
-
phase: "pre" | "post";
|
|
30
|
-
command: string;
|
|
31
|
-
/** Cursor's own beforeShellExecution / afterShellExecution. */
|
|
32
|
-
cursorNative: boolean;
|
|
33
|
-
/** Cursor running a hook it imported from Claude Code settings. */
|
|
34
|
-
cursorImported: boolean;
|
|
35
|
-
};
|
|
36
28
|
/** Keep the shape of the verb, never its arguments: anything that could carry a
|
|
37
29
|
* path, an endpoint, or a value is dropped rather than truncated. */
|
|
38
30
|
export declare function safeVerb(raw: string | null): string;
|
|
@@ -45,8 +37,6 @@ export declare function safeVerb(raw: string | null): string;
|
|
|
45
37
|
export declare function detectRuntime(input: HookInput, env: Env, declared?: string): HookRuntime;
|
|
46
38
|
/** One row for a line that ran vendor commands; null for any other line. */
|
|
47
39
|
export declare function buildReport(input: HookInput, findings: CliFinding[], env: Env, declared?: string): CliHookReport | null;
|
|
48
|
-
/** Normalise one stdin event into the command and when it runs. */
|
|
49
|
-
export declare function shellEvent(input: HookInput): ShellEvent | null;
|
|
50
40
|
/** `passport exec` records its own action, with its decision and credential. */
|
|
51
41
|
export declare function isPassportExec(command: string): boolean;
|
|
52
42
|
/** Calls that name the agent (`x-passport-caller`): its kind only. */
|
package/dist/cliHook.js
CHANGED
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
*
|
|
13
13
|
* Both work inside `HOOK_BUDGET_MS`, and neither ever sends the command line,
|
|
14
14
|
* its arguments, the output, the full working directory, or the environment.
|
|
15
|
-
*
|
|
16
|
-
* this hook going wrong.
|
|
15
|
+
* The guard refuses a payload it can't read (exit 2, `hookAdapters.ts`); any
|
|
16
|
+
* other failure is silent: the agent must never notice this hook going wrong.
|
|
17
17
|
*/
|
|
18
18
|
import { value } from "./cliArgs.js";
|
|
19
19
|
import { summarize, unknownVerb, UNRECOGNIZED_VERB } from "./cliHookClassify.js";
|
|
@@ -23,15 +23,17 @@ import { localRefusal, planGuard } from "./cliHookDecide.js";
|
|
|
23
23
|
import { denyOutput } from "./cliHookGuard.js";
|
|
24
24
|
import { localIrreversibleVerbs } from "./localIrreversible.js";
|
|
25
25
|
import { permissionModeOf } from "./cliHookMode.js";
|
|
26
|
-
import {
|
|
26
|
+
import { readInput, readRaw, record, subagentOf } from "./cliHookInput.js";
|
|
27
|
+
import { parsePayload, shellEvent, unreadableMessage } from "./hookAdapters.js";
|
|
28
|
+
export { shellEvent } from "./hookAdapters.js";
|
|
27
29
|
import { budgetSignal, HOOK_BUDGET_MS, HOOK_RUNTIMES, leftovers, localProfile, localSelection, agentKeyApi, profileApi, queueAfterCommand, reportSender, runFlush, startFlushIfDue } from "./cliHookDeliver.js";
|
|
28
30
|
export { HOOK_BUDGET_MS, HOOK_RUNTIMES } from "./cliHookDeliver.js";
|
|
29
31
|
import { readCpCli } from "./cpCli.js";
|
|
30
32
|
import { standDownForManaged } from "./managedHooks.js";
|
|
31
33
|
import { isCursorEvent, outcomeOfInput } from "./cliHookOutcome.js";
|
|
34
|
+
import { isGuardClient } from "./cliGuardHealth.js";
|
|
32
35
|
export { outcomeOf } from "./cliHookOutcome.js";
|
|
33
36
|
const MAX_FINDINGS = 8;
|
|
34
|
-
const SHELL_TOOLS = new Set(["Bash", "bash", "shell", "Shell"]);
|
|
35
37
|
const VERB_TOKEN = /^-{0,2}[A-Za-z0-9][A-Za-z0-9._:+-]{0,39}$/;
|
|
36
38
|
const VENDOR_NAME = /^[a-z0-9._-]{1,40}$/;
|
|
37
39
|
function text(candidate, max) {
|
|
@@ -122,32 +124,6 @@ export function buildReport(input, findings, env, declared) {
|
|
|
122
124
|
opaque: summary.opaque
|
|
123
125
|
};
|
|
124
126
|
}
|
|
125
|
-
/** Normalise one stdin event into the command and when it runs. */
|
|
126
|
-
export function shellEvent(input) {
|
|
127
|
-
if (isCursorEvent(input)) {
|
|
128
|
-
if (typeof input.command !== "string")
|
|
129
|
-
return null;
|
|
130
|
-
return {
|
|
131
|
-
phase: input.hook_event_name === "beforeShellExecution" ? "pre" : "post",
|
|
132
|
-
command: input.command,
|
|
133
|
-
cursorNative: true,
|
|
134
|
-
cursorImported: false
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
if (typeof input.tool_name !== "string" || !SHELL_TOOLS.has(input.tool_name))
|
|
138
|
-
return null;
|
|
139
|
-
const command = commandText(record(input.tool_input).command);
|
|
140
|
-
if (command === null)
|
|
141
|
-
return null;
|
|
142
|
-
const phase = input.hook_event_name === "PreToolUse"
|
|
143
|
-
? "pre"
|
|
144
|
-
: input.hook_event_name === "PostToolUse" || input.hook_event_name === "PostToolUseFailure"
|
|
145
|
-
? "post"
|
|
146
|
-
: null;
|
|
147
|
-
if (!phase)
|
|
148
|
-
return null;
|
|
149
|
-
return { phase, command, cursorNative: false, cursorImported: typeof input.cursor_version === "string" };
|
|
150
|
-
}
|
|
151
127
|
/** Cursor imports Claude Code's hooks by default. When Passport's own Cursor
|
|
152
128
|
* entry is registered too, the imported copy stays quiet so nothing is
|
|
153
129
|
* recorded twice. */
|
|
@@ -202,8 +178,12 @@ async function runAudit(args, runtime, deps) {
|
|
|
202
178
|
const profile = localProfile(args, runtime.env);
|
|
203
179
|
const now = (deps.now ?? Date.now)();
|
|
204
180
|
// It ran: a decision the guard couldn't wait for may still have been recorded as a block (controlPlaneLateHold).
|
|
205
|
-
if (profile)
|
|
206
|
-
|
|
181
|
+
if (profile) {
|
|
182
|
+
const [sessionId, toolUseId] = [sessionOfInput(input), text(input.tool_use_id, 128)];
|
|
183
|
+
await (await import("./controlPlaneLateHold.js")).releaseLate(profile, sessionId, toolUseId, now);
|
|
184
|
+
// Ran while Passport couldn't be reached and no rules were known: Passport is told what it was.
|
|
185
|
+
await (await import("./controlPlaneOffline.js")).releaseOffline(profile, sessionId, toolUseId, now);
|
|
186
|
+
}
|
|
207
187
|
const declared = value(args, "client");
|
|
208
188
|
const runtimeName = detectRuntime(input, runtime.env, declared);
|
|
209
189
|
const after = await import("./cliHookAfter.js");
|
|
@@ -242,21 +222,32 @@ function outputClient(event, runtime) {
|
|
|
242
222
|
}
|
|
243
223
|
/** Leave room after the server call to print and exit inside the budget. */
|
|
244
224
|
const PRINT_RESERVE_MS = 200;
|
|
225
|
+
/** The guard refuses a payload it can't read (any of the three agents reads exit 2 as deny), unless managed
|
|
226
|
+
* settings run the guard for this agent too: that copy decides. */
|
|
227
|
+
function refuseUnreadable(args, runtime) {
|
|
228
|
+
const declared = (value(args, "client") ?? runtime.env.PASSPORT_HOOK_RUNTIME)?.trim().toLowerCase();
|
|
229
|
+
const client = isGuardClient(declared) ? declared : undefined;
|
|
230
|
+
if (client && standDownForManaged(client, runtime.env))
|
|
231
|
+
return undefined;
|
|
232
|
+
runtime.stderr.write(`${unreadableMessage(client)}\n`);
|
|
233
|
+
return 2;
|
|
234
|
+
}
|
|
245
235
|
async function runGuard(args, runtime, deps) {
|
|
246
236
|
if (runtime.env.PASSPORT_HOOK_DISABLED === "1")
|
|
247
|
-
return;
|
|
237
|
+
return undefined;
|
|
248
238
|
const clock = deps.now ?? Date.now;
|
|
249
239
|
const startedAt = clock();
|
|
250
240
|
const budget = budgetSignal(runtime, deps);
|
|
251
|
-
const
|
|
252
|
-
if (!
|
|
253
|
-
return;
|
|
241
|
+
const parsed = parsePayload(await readRaw(runtime, budget));
|
|
242
|
+
if (!parsed.ok)
|
|
243
|
+
return refuseUnreadable(args, runtime);
|
|
244
|
+
const input = parsed.input;
|
|
254
245
|
const event = hookEvent(input, "pre", args, runtime);
|
|
255
246
|
if (!event)
|
|
256
|
-
return;
|
|
247
|
+
return undefined;
|
|
257
248
|
// Cursor runs the hook it imported from Claude Code too: with Passport's own Cursor entry there, that one decides.
|
|
258
249
|
if (event.cursorImported && (await cursorHasOwnEntry(runtime, "guard")))
|
|
259
|
-
return;
|
|
250
|
+
return undefined;
|
|
260
251
|
const machine = localMachine(workingFolder(input), runtime.env);
|
|
261
252
|
const line = classifyLine(event.command, machine);
|
|
262
253
|
const declared = value(args, "client");
|
|
@@ -269,8 +260,35 @@ async function runGuard(args, runtime, deps) {
|
|
|
269
260
|
if (local[0])
|
|
270
261
|
runtime.stdout.write(`${JSON.stringify(denyOutput(client, localRefusal(local[0], "unreachable")))}\n`);
|
|
271
262
|
};
|
|
272
|
-
|
|
273
|
-
|
|
263
|
+
// Passport never asked (out of time, or a failure before the answer): what a cached Block rule covers is refused.
|
|
264
|
+
const unasked = async () => {
|
|
265
|
+
const { profile } = localSelection(args, runtime.env);
|
|
266
|
+
const cp = profile ? readCpCli(profile) : null;
|
|
267
|
+
const offline = await (await import("./cliHookDecide.js")).planUnreachable({
|
|
268
|
+
client,
|
|
269
|
+
canAsk: Boolean(profile),
|
|
270
|
+
cp,
|
|
271
|
+
...(profile ? { profile } : {}),
|
|
272
|
+
openApi: async () => null,
|
|
273
|
+
report: context(input, runtime.env, declared),
|
|
274
|
+
command: event.command,
|
|
275
|
+
findings: line.findings,
|
|
276
|
+
cwd: machine.cwd,
|
|
277
|
+
env: runtime.env,
|
|
278
|
+
budget,
|
|
279
|
+
deadline: 0,
|
|
280
|
+
now: clock
|
|
281
|
+
});
|
|
282
|
+
if (offline)
|
|
283
|
+
runtime.stdout.write(`${JSON.stringify(offline)}\n`);
|
|
284
|
+
};
|
|
285
|
+
if (budget.aborted) {
|
|
286
|
+
if (local[0])
|
|
287
|
+
return void refuseLocal();
|
|
288
|
+
await unasked().catch(() => undefined);
|
|
289
|
+
return undefined;
|
|
290
|
+
}
|
|
291
|
+
let answered = false;
|
|
274
292
|
try {
|
|
275
293
|
await guardLine({
|
|
276
294
|
args,
|
|
@@ -287,10 +305,15 @@ async function runGuard(args, runtime, deps) {
|
|
|
287
305
|
budget,
|
|
288
306
|
startedAt
|
|
289
307
|
});
|
|
308
|
+
answered = true;
|
|
290
309
|
}
|
|
291
310
|
catch {
|
|
292
|
-
|
|
311
|
+
if (local[0])
|
|
312
|
+
refuseLocal();
|
|
313
|
+
else if (!answered)
|
|
314
|
+
await unasked().catch(() => undefined);
|
|
293
315
|
}
|
|
316
|
+
return undefined;
|
|
294
317
|
}
|
|
295
318
|
/** Calls that name the agent (`x-passport-caller`): its kind only. */
|
|
296
319
|
export function asCaller(api, client) {
|
|
@@ -332,6 +355,7 @@ async function guardLine(at) {
|
|
|
332
355
|
client,
|
|
333
356
|
canAsk: canReport || agentApi !== null,
|
|
334
357
|
cp,
|
|
358
|
+
...(profile ? { profile } : {}),
|
|
335
359
|
openApi,
|
|
336
360
|
report: context(input, runtime.env, declared),
|
|
337
361
|
command: event.command,
|
|
@@ -388,9 +412,10 @@ export async function hook(args, runtime, deps = {}) {
|
|
|
388
412
|
const unknown = unknownSubcommand("hook", action, ["install", "uninstall", "status"]);
|
|
389
413
|
return failure(unknown.message, 6, "usage", unknown.next ? { next: unknown.next } : {});
|
|
390
414
|
}
|
|
415
|
+
let exitCode;
|
|
391
416
|
try {
|
|
392
417
|
if (action === "guard")
|
|
393
|
-
await runGuard(args, runtime, deps);
|
|
418
|
+
exitCode = await runGuard(args, runtime, deps);
|
|
394
419
|
else if (action === "flush")
|
|
395
420
|
await runFlush(args, runtime, deps);
|
|
396
421
|
else
|
|
@@ -399,5 +424,5 @@ export async function hook(args, runtime, deps = {}) {
|
|
|
399
424
|
catch {
|
|
400
425
|
/* Best effort. The agent must never notice this hook failing. */
|
|
401
426
|
}
|
|
402
|
-
return { json: { ok: true }, silent: true };
|
|
427
|
+
return { json: { ok: true }, silent: true, ...(exitCode ? { exitCode } : {}) };
|
|
403
428
|
}
|
package/dist/cliHookClients.d.ts
CHANGED
|
@@ -17,6 +17,9 @@ export type ClientSpec = {
|
|
|
17
17
|
* end, and for Claude Code each prompt (an entry older versions installed;
|
|
18
18
|
* a prompt now ends at once, `hookPromptFast.ts`). */
|
|
19
19
|
lifecycle?: string[];
|
|
20
|
+
/** What makes the guard entry fail closed (the agent refuses the command when the hook can't run or times out);
|
|
21
|
+
* absent where the agent has no such setting (Codex: a failed hook lets the command continue). */
|
|
22
|
+
failClosed?: Readonly<Record<string, unknown>>;
|
|
20
23
|
path(env: Env): string;
|
|
21
24
|
};
|
|
22
25
|
export declare function claudeSettingsPath(env: Env): string;
|
package/dist/cliHookClients.js
CHANGED
|
@@ -30,6 +30,8 @@ export const CLIENTS = {
|
|
|
30
30
|
// PostToolUse, so an approved command that failed still counts as ran.
|
|
31
31
|
postFailure: "PostToolUseFailure",
|
|
32
32
|
lifecycle: ["SessionStart", "SessionEnd", "UserPromptSubmit"],
|
|
33
|
+
// code.claude.com/docs/en/hooks: with "block", a failure does what exit code 2 does (Claude Code 2.1.295+).
|
|
34
|
+
failClosed: { onFailure: "block" },
|
|
33
35
|
path: claudeSettingsPath
|
|
34
36
|
},
|
|
35
37
|
codex: {
|
|
@@ -47,6 +49,8 @@ export const CLIENTS = {
|
|
|
47
49
|
format: "cursor",
|
|
48
50
|
pre: "beforeShellExecution",
|
|
49
51
|
post: "afterShellExecution",
|
|
52
|
+
// cursor.com/docs/agent/hooks: `failClosed` is off by default.
|
|
53
|
+
failClosed: { failClosed: true },
|
|
50
54
|
path: cursorHooksPath
|
|
51
55
|
}
|
|
52
56
|
};
|
package/dist/cliHookDecide.d.ts
CHANGED
|
@@ -11,9 +11,10 @@
|
|
|
11
11
|
* "local", whether or not any platform is connected.
|
|
12
12
|
*
|
|
13
13
|
* Any block refuses the command at once with Passport's own words; nothing waits for a person. Unanswered in time,
|
|
14
|
-
* the command runs as it would without Passport, and once it ran Passport is told so (`controlPlaneLate.ts`);
|
|
15
|
-
* command that can't be undone
|
|
16
|
-
*
|
|
14
|
+
* the command runs as it would without Passport, and once it ran Passport is told so (`controlPlaneLate.ts`); two
|
|
15
|
+
* exceptions: a command that can't be undone runs only on Passport's allow, and an action a Block rule covers, by
|
|
16
|
+
* this computer's copy of the rules from the last 7 days, is refused (`controlPlaneOffline.ts`). With no such copy,
|
|
17
|
+
* what ran is recorded as "decided offline, no rules known". Anything else gets no answer at all.
|
|
17
18
|
*/
|
|
18
19
|
import type { CliFinding } from "./cliHookClassify.js";
|
|
19
20
|
import { type GuardClient } from "./cliHookGuard.js";
|
|
@@ -29,6 +30,8 @@ export type GuardContext = {
|
|
|
29
30
|
/** Signed in with a member profile that may ask Passport. */
|
|
30
31
|
canAsk: boolean;
|
|
31
32
|
cp: CachedCpCli | null;
|
|
33
|
+
/** The signed-in profile whose copy `cp` is (the workspace its signed rules must name). */
|
|
34
|
+
profile?: string | null;
|
|
32
35
|
openApi: () => Promise<ApiCall | null>;
|
|
33
36
|
report: {
|
|
34
37
|
runtime?: string;
|
|
@@ -47,6 +50,7 @@ export type GuardContext = {
|
|
|
47
50
|
deadline: number;
|
|
48
51
|
now: () => number;
|
|
49
52
|
};
|
|
53
|
+
export declare function githubWord(command: string, hosts?: readonly string[]): boolean;
|
|
50
54
|
/** A vendor command's verb in the shape the server reads, or null. */
|
|
51
55
|
export declare function cliVerbOf(finding: CliFinding): string | null;
|
|
52
56
|
/** The basic-platform verbs of a line: a write or delete of a vendor in `vendors`, each once. */
|
|
@@ -55,4 +59,9 @@ export declare function vendorVerbs(findings: readonly CliFinding[], vendors: re
|
|
|
55
59
|
export declare function localRefusal(verb: LocalIrreversibleVerb, why: "signed-out" | "unreachable"): string;
|
|
56
60
|
/** What the guard answers: a block's refusal, or nothing. */
|
|
57
61
|
export declare function planGuard(context: GuardContext): Promise<GuardPlan>;
|
|
62
|
+
/** The guard never got to ask (its budget ran out first, or something failed before it answered): every platform the
|
|
63
|
+
* line would have asked about counts as unreachable, so a covered action is refused and the rest is recorded. */
|
|
64
|
+
export declare function planUnreachable(context: GuardContext): Promise<Record<string, unknown> | null>;
|
|
65
|
+
/** What the agent reads when the guard couldn't even classify a line Passport didn't answer for. */
|
|
66
|
+
export declare const UNCHECKED_REFUSAL = "Passport couldn't be reached or check this command, so it didn't run.";
|
|
58
67
|
export {};
|
package/dist/cliHookDecide.js
CHANGED
|
@@ -11,9 +11,10 @@
|
|
|
11
11
|
* "local", whether or not any platform is connected.
|
|
12
12
|
*
|
|
13
13
|
* Any block refuses the command at once with Passport's own words; nothing waits for a person. Unanswered in time,
|
|
14
|
-
* the command runs as it would without Passport, and once it ran Passport is told so (`controlPlaneLate.ts`);
|
|
15
|
-
* command that can't be undone
|
|
16
|
-
*
|
|
14
|
+
* the command runs as it would without Passport, and once it ran Passport is told so (`controlPlaneLate.ts`); two
|
|
15
|
+
* exceptions: a command that can't be undone runs only on Passport's allow, and an action a Block rule covers, by
|
|
16
|
+
* this computer's copy of the rules from the last 7 days, is refused (`controlPlaneOffline.ts`). With no such copy,
|
|
17
|
+
* what ran is recorded as "decided offline, no rules known". Anything else gets no answer at all.
|
|
17
18
|
*/
|
|
18
19
|
import { homedir } from "node:os";
|
|
19
20
|
import { denyOutput } from "./cliHookGuard.js";
|
|
@@ -22,6 +23,19 @@ import { setShadowDeadline } from "./kitShadowBudget.js";
|
|
|
22
23
|
import { shadowAfterDecision } from "./kitShadow.js";
|
|
23
24
|
/** A cheap check before a classifier loads: `gh …`, a `git … push`, or `railway …`. Every other command pays nothing. */
|
|
24
25
|
const GITHUB_WORD = /(?:^|[\s;&|(/])(?:gh\s|git\s(?:[^;&|]*\s)?push\b)/;
|
|
26
|
+
/** A curl, wget or httpie line that mentions GitHub anywhere (`github`, a `GH_*` variable such as GH_TOKEN or
|
|
27
|
+
* GH_ENTERPRISE_TOKEN, or a configured Enterprise host), quotes and backslashes gone: the classifier decides. */
|
|
28
|
+
const HTTP_WORD = /(?:^|[\s;&|(/])(?:curl|wget|https?)(?:\.exe)?(?:\s|$)/i;
|
|
29
|
+
const GITHUB_SIGNAL = /github|\bGH_[A-Z0-9_]+/i;
|
|
30
|
+
export function githubWord(command, hosts = []) {
|
|
31
|
+
if (GITHUB_WORD.test(command))
|
|
32
|
+
return true;
|
|
33
|
+
const bare = command.replace(/["'\\]/g, "");
|
|
34
|
+
if (GITHUB_WORD.test(bare))
|
|
35
|
+
return true;
|
|
36
|
+
const lower = bare.toLowerCase();
|
|
37
|
+
return HTTP_WORD.test(bare) && (GITHUB_SIGNAL.test(bare) || hosts.some((host) => lower.includes(host.toLowerCase())));
|
|
38
|
+
}
|
|
25
39
|
/** Anywhere, once quotes and backslashes are gone (`"railway"`, `\railway`, `r''ailway`, `npx @railway/cli`):
|
|
26
40
|
* the classifier, which reads the line as the shell would, decides what is really railway. */
|
|
27
41
|
const railwayWord = (command) => /railway/i.test(command.replace(/["'\\]/g, ""));
|
|
@@ -70,7 +84,7 @@ export function localRefusal(verb, why) {
|
|
|
70
84
|
function asking(context, local) {
|
|
71
85
|
const { cp, command } = context;
|
|
72
86
|
return {
|
|
73
|
-
github: Boolean(cp?.platforms.github) &&
|
|
87
|
+
github: Boolean(cp?.platforms.github) && githubWord(command, cp?.githubHosts),
|
|
74
88
|
railway: Boolean(cp?.platforms.railway) && railwayWord(command),
|
|
75
89
|
supabase: Boolean(cp?.platforms.supabase) && supabaseWord(command),
|
|
76
90
|
verbs: [
|
|
@@ -89,8 +103,11 @@ export async function planGuard(context) {
|
|
|
89
103
|
return local[0] ? refuse(local[0], "signed-out") : { output: null };
|
|
90
104
|
const { github, railway, supabase, verbs } = asking(context, local);
|
|
91
105
|
const left = context.deadline - context.now();
|
|
92
|
-
if (left <= 0)
|
|
93
|
-
|
|
106
|
+
if (left <= 0) {
|
|
107
|
+
if (local[0])
|
|
108
|
+
return refuse(local[0], "unreachable");
|
|
109
|
+
return { output: await whenUnreachable(context, { github, railway, supabase }, []) };
|
|
110
|
+
}
|
|
94
111
|
if (!github && !railway && !supabase && !verbs.length)
|
|
95
112
|
return { output: null };
|
|
96
113
|
// The kit's shadow run (`kitShadow.ts`) stops before the guard's deadline.
|
|
@@ -99,11 +116,17 @@ export async function planGuard(context) {
|
|
|
99
116
|
const open = async () => (api ??= (await context.openApi()) ?? undefined) ?? null;
|
|
100
117
|
const signal = AbortSignal.any([context.budget, AbortSignal.timeout(left)]);
|
|
101
118
|
const extra = context.report?.sessionId ? { sessionId: context.report.sessionId } : {};
|
|
102
|
-
// A step that fails is no answer from its platform
|
|
119
|
+
// A step that fails is no answer from its platform (it counts as unreachable for the offline rules below); it never
|
|
120
|
+
// drops another's block or a local refusal.
|
|
121
|
+
const threw = { github: false, railway: false, supabase: false };
|
|
122
|
+
const failed = (platform) => () => {
|
|
123
|
+
threw[platform] = true;
|
|
124
|
+
return null;
|
|
125
|
+
};
|
|
103
126
|
const [githubLine, railwayAnswer, supabaseAnswer, verbAnswers] = await Promise.all([
|
|
104
|
-
github ? githubLinePlan(context, open, extra, signal).catch(()
|
|
105
|
-
railway ? railwayLine(context, open, extra, signal).catch(()
|
|
106
|
-
supabase ? supabaseLine(context, open, extra, signal).catch(()
|
|
127
|
+
github ? githubLinePlan(context, open, extra, signal).catch(failed("github")) : null,
|
|
128
|
+
railway ? railwayLine(context, open, extra, signal).catch(failed("railway")) : null,
|
|
129
|
+
supabase ? supabaseLine(context, open, extra, signal).catch(failed("supabase")) : null,
|
|
107
130
|
askVerbs(verbs, open, extra, signal).catch(() => [])
|
|
108
131
|
]);
|
|
109
132
|
// Decided: the kit's shadow run reads what was asked about, off the decision's path.
|
|
@@ -113,6 +136,11 @@ export async function planGuard(context) {
|
|
|
113
136
|
const blocked = answers.find((answer) => answer?.kind === "block");
|
|
114
137
|
if (blocked)
|
|
115
138
|
return withApi(denyOutput(context.client, blocked.message));
|
|
139
|
+
const late = answers.flatMap((answer) => (answer?.kind === "unreachable" ? (answer.late ?? []) : []));
|
|
140
|
+
const missed = missedPlatforms({ github, railway, supabase }, threw, githubLine, railwayAnswer?.answer, supabaseAnswer?.answer);
|
|
141
|
+
const offline = await whenUnreachable(context, missed, late);
|
|
142
|
+
if (offline)
|
|
143
|
+
return withApi(offline);
|
|
116
144
|
// A command that can't be undone runs only on Passport's allow.
|
|
117
145
|
const localAnswers = verbAnswers.length === verbs.length ? verbAnswers.slice(verbs.length - local.length) : [];
|
|
118
146
|
const unanswered = local.find((_verb, at) => localAnswers[at]?.kind !== "allow");
|
|
@@ -140,11 +168,16 @@ async function askVerbs(verbs, open, extra, signal) {
|
|
|
140
168
|
const { askCliVerb } = await import("./controlPlaneCli.js");
|
|
141
169
|
return Promise.all(verbs.map(([vendor, verb]) => askCliVerb(api, vendor, verb, extra, signal)));
|
|
142
170
|
}
|
|
171
|
+
/** The folder's repository and branch, and the workspace's Enterprise hosts (Passport's copy). */
|
|
172
|
+
function placeOf(cp, context) {
|
|
173
|
+
const hosts = context.cp?.githubHosts;
|
|
174
|
+
return { ...cp.gitPlace(context.cwd), ...(hosts?.length ? { apiHosts: hosts } : {}) };
|
|
175
|
+
}
|
|
143
176
|
/** GitHub's part of a line. Every `git push` is decided here, ref by ref, resolved as git will in this folder. */
|
|
144
177
|
async function githubLinePlan(context, open, extra, signal) {
|
|
145
178
|
const cp = await import("./controlPlaneGuard.js");
|
|
146
179
|
const where = context.cwd ? { cwd: context.cwd } : undefined;
|
|
147
|
-
const commands = cp.classifyCommands(context.command, cp
|
|
180
|
+
const commands = cp.classifyCommands(context.command, placeOf(cp, context), where);
|
|
148
181
|
const label = commands.flatMap((entry) => entry.classifications)[0]?.summary;
|
|
149
182
|
const api = label === undefined ? null : await open();
|
|
150
183
|
return { label, decided: api ? await cp.decideCommands(api, commands, extra, signal) : null };
|
|
@@ -164,3 +197,79 @@ async function leaveDecisions(github, railway, context, others) {
|
|
|
164
197
|
await railway.leave();
|
|
165
198
|
await holdLate([github?.answer, railway?.answer, ...others], context.report, context.now());
|
|
166
199
|
}
|
|
200
|
+
/** The platforms asked and not answered: Passport couldn't be reached for them. Every non-answer counts: no response,
|
|
201
|
+
* a 401, 403, 404, 429 or 5xx, a timeout, a 200 that isn't Passport's JSON (each reads as unreachable), or a step
|
|
202
|
+
* that threw. An `undecided` from Passport itself is an answer. */
|
|
203
|
+
function missedPlatforms(asked, threw, github, railway, supabase) {
|
|
204
|
+
// A real `undecided` (Passport answered, and doesn't decide this) keeps today's behavior: it isn't offline.
|
|
205
|
+
const missed = (answer) => !answer || answer.kind === "unreachable";
|
|
206
|
+
return {
|
|
207
|
+
github: asked.github && (threw.github || (Boolean(github?.label) && missed(github?.decided?.answer))),
|
|
208
|
+
railway: asked.railway && (threw.railway || missed(railway)),
|
|
209
|
+
supabase: asked.supabase && (threw.supabase || missed(supabase))
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
/** What the line does on each platform Passport didn't answer for, classified on this computer. */
|
|
213
|
+
async function foundOffline(context, missed) {
|
|
214
|
+
const found = [];
|
|
215
|
+
if (missed.github) {
|
|
216
|
+
const cp = await import("./controlPlaneGuard.js");
|
|
217
|
+
const where = context.cwd ? { cwd: context.cwd } : undefined;
|
|
218
|
+
for (const entry of cp.classifyCommands(context.command, placeOf(cp, context), where)) {
|
|
219
|
+
for (const one of entry.classifications) {
|
|
220
|
+
found.push({ platform: "github", nodeId: one.nodeId, actionKey: one.actionKey, summary: one.summary });
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
if (missed.railway) {
|
|
225
|
+
const where = { cwd: context.cwd, env: context.env ?? process.env, home: homedir() };
|
|
226
|
+
found.push(...(await (await import("./controlPlaneRailwayGuard.js")).railwayFound(context.command, where)));
|
|
227
|
+
}
|
|
228
|
+
if (missed.supabase) {
|
|
229
|
+
const where = { cwd: context.cwd ?? null, env: context.env ?? process.env };
|
|
230
|
+
found.push(...(await import("./controlPlaneSupabase.js")).supabaseFound(context.command, where));
|
|
231
|
+
}
|
|
232
|
+
return found;
|
|
233
|
+
}
|
|
234
|
+
/** The guard never got to ask (its budget ran out first, or something failed before it answered): every platform the
|
|
235
|
+
* line would have asked about counts as unreachable, so a covered action is refused and the rest is recorded. */
|
|
236
|
+
export async function planUnreachable(context) {
|
|
237
|
+
const { github, railway, supabase } = asking(context, []);
|
|
238
|
+
return whenUnreachable(context, { github, railway, supabase }, []);
|
|
239
|
+
}
|
|
240
|
+
/** What the agent reads when the guard couldn't even classify a line Passport didn't answer for. */
|
|
241
|
+
export const UNCHECKED_REFUSAL = "Passport couldn't be reached or check this command, so it didn't run.";
|
|
242
|
+
/**
|
|
243
|
+
* Passport couldn't be reached for part of the line (`controlPlaneOffline.ts`). The line is classified on this
|
|
244
|
+
* computer, and every outcome is recorded as decided offline: with rules from the last 7 days, an action a Block rule
|
|
245
|
+
* covers is refused (recorded at once: it won't run), anything else runs (recorded once it ran); with none, it runs
|
|
246
|
+
* (recorded as no rules known). Anything that throws here refuses: a covered action is never allowed by an error.
|
|
247
|
+
*/
|
|
248
|
+
async function whenUnreachable(context, missed, late) {
|
|
249
|
+
if (!missed.github && !missed.railway && !missed.supabase)
|
|
250
|
+
return null;
|
|
251
|
+
try {
|
|
252
|
+
const found = await foundOffline(context, missed);
|
|
253
|
+
if (!found.length)
|
|
254
|
+
return null;
|
|
255
|
+
const offline = await import("./controlPlaneOffline.js");
|
|
256
|
+
const now = context.now();
|
|
257
|
+
const report = { sessionId: context.report?.sessionId, toolUseId: context.report?.toolUseId };
|
|
258
|
+
const blocks = offline.usableBlocks(context.cp, context.profile ?? null, now);
|
|
259
|
+
if (!blocks) {
|
|
260
|
+
offline.holdOffline(report.sessionId, report.toolUseId, found, late, "no_rules", now);
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
const covered = offline.coveredOffline(found, blocks)[0];
|
|
264
|
+
if (!covered) {
|
|
265
|
+
offline.holdOffline(report.sessionId, report.toolUseId, found, late, "allowed", now);
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
if (context.profile)
|
|
269
|
+
offline.queueOffline(context.profile, report.sessionId, found, late, "blocked", now);
|
|
270
|
+
return denyOutput(context.client, offline.offlineRefusal(covered));
|
|
271
|
+
}
|
|
272
|
+
catch {
|
|
273
|
+
return denyOutput(context.client, UNCHECKED_REFUSAL);
|
|
274
|
+
}
|
|
275
|
+
}
|
package/dist/cliHookDeliver.js
CHANGED
|
@@ -289,11 +289,13 @@ 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
|
-
const
|
|
292
|
+
const offlineNotices = await import("./controlPlaneOffline.js");
|
|
293
|
+
const { offline, rest } = offlineNotices.splitOffline(queued);
|
|
294
|
+
const { late: lateIds, reports } = late.splitLate(rest);
|
|
293
295
|
const refresh = claimStaleRefresh(profile, readCpCli(profile), now);
|
|
294
296
|
const extras = await import("./cliHookExtras.js");
|
|
295
297
|
const heartbeat = await extras.heartbeatDue(profile, now);
|
|
296
|
-
if (!reports.length && !lateIds.length && !refresh && !heartbeat)
|
|
298
|
+
if (!reports.length && !lateIds.length && !offline.length && !refresh && !heartbeat)
|
|
297
299
|
return;
|
|
298
300
|
const api = context.api ?? (await profileApi(profile, budget, deps.fetch ?? fetch));
|
|
299
301
|
if (!api)
|
|
@@ -304,6 +306,7 @@ export async function leftovers(queued, context) {
|
|
|
304
306
|
await Promise.allSettled([
|
|
305
307
|
...reports.map((entry) => send(entry)),
|
|
306
308
|
lateIds.length ? late.tellLate(api, lateIds, budget) : null,
|
|
309
|
+
offline.length ? offlineNotices.tellOffline(api, offline, budget) : null,
|
|
307
310
|
heartbeat ? extras.heartbeat(api, profile, context.runtime.env, budget, now) : null,
|
|
308
311
|
refresh ? refreshCpCli(profile, budget, { api, ...(deps.now ? { now: deps.now } : {}) }) : null
|
|
309
312
|
]);
|