passport-bridge 0.31.1 → 0.32.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cliAutopilotPolicy.d.ts +2 -0
- package/dist/cliChanges.d.ts +2 -0
- package/dist/cliChanges.js +6 -2
- package/dist/cliExec.js +10 -26
- package/dist/cliHook.d.ts +1 -1
- package/dist/cliHook.js +23 -22
- package/dist/cliHookAfter.d.ts +8 -3
- package/dist/cliHookAfter.js +39 -18
- package/dist/cliHookAudit.d.ts +4 -4
- package/dist/cliHookAudit.js +8 -6
- package/dist/cliHookDeliver.d.ts +3 -0
- package/dist/cliHookDeliver.js +13 -1
- package/dist/cliHookExtras.d.ts +3 -2
- package/dist/cliHookExtras.js +5 -5
- package/dist/cliHookLifecycle.d.ts +1 -1
- package/dist/cliHookLifecycle.js +7 -6
- package/dist/cliHookLinks.d.ts +45 -0
- package/dist/cliHookLinks.js +301 -0
- package/dist/cliHookOpaque.d.ts +7 -0
- package/dist/cliHookOpaque.js +6 -0
- package/dist/cliHookProject.d.ts +2 -0
- package/dist/cliHookProject.js +14 -0
- package/dist/cliPolicyV2.js +2 -0
- package/dist/cliSessionsJson.d.ts +4 -0
- package/dist/cliSessionsJson.js +7 -1
- package/dist/cliSessionsRender.js +6 -3
- package/dist/execLinks.d.ts +66 -0
- package/dist/execLinks.js +124 -0
- package/dist/externalLinks.d.ts +51 -0
- package/dist/externalLinks.js +332 -0
- package/dist/hookFastPath.js +1 -1
- package/dist/launcherFastAnswers.d.ts +26 -0
- package/dist/launcherFastAnswers.js +44 -0
- package/dist/launcherFastPath.d.ts +1 -21
- package/dist/launcherFastPath.js +2 -39
- package/dist/localBackups.js +4 -1
- package/dist/localBackupsGate.d.ts +15 -0
- package/dist/localBackupsGate.js +24 -0
- package/dist/pluginPin.d.ts +1 -1
- package/dist/pluginPin.js +1 -1
- package/dist/signInFailure.d.ts +6 -2
- package/dist/signInFailure.js +6 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -162,6 +162,8 @@ export type AutopilotPolicy = {
|
|
|
162
162
|
/** The server keeps what the after-hook learns (cli-policy v2 `afterFacts`):
|
|
163
163
|
* a sign-in that failed, what a command created or removed, a retry streak. */
|
|
164
164
|
reportsAfterFacts?: boolean;
|
|
165
|
+
/** The server keeps links to what a command acted on (cli-policy v2 `links`). */
|
|
166
|
+
reportsLinks?: boolean;
|
|
165
167
|
/** "Stop retry loops" is on for this person (cli-policy v2 `retryLoops`):
|
|
166
168
|
* the guard asks before a command that failed 5 times in a row runs again. */
|
|
167
169
|
retryLoops?: boolean;
|
package/dist/cliChanges.d.ts
CHANGED
|
@@ -48,6 +48,8 @@ export type ChangeJson = {
|
|
|
48
48
|
undo: UndoJson | null;
|
|
49
49
|
/** A deploy-like change: what Passport saw in the 15 minutes after it. */
|
|
50
50
|
watch: WatchJson | null;
|
|
51
|
+
/** Where it landed in the vendor's own app: allowlisted URLs, the thing itself first. */
|
|
52
|
+
links: string[];
|
|
51
53
|
};
|
|
52
54
|
export type WatchJson = {
|
|
53
55
|
state: "watching" | "healthy" | "errors" | "unchecked";
|
package/dist/cliChanges.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
import { value } from "./cliArgs.js";
|
|
15
15
|
import { api, json } from "./cliMemberCall.js";
|
|
16
16
|
import { failure, timeoutMs } from "./cliSupport.js";
|
|
17
|
-
import { appName, clientName, count, list, oneOf, record, text, time, windowOf } from "./cliSessionsJson.js";
|
|
17
|
+
import { appName, clientName, count, linkUrls, list, oneOf, record, text, time, windowOf } from "./cliSessionsJson.js";
|
|
18
18
|
import { countOf } from "./plural.js";
|
|
19
19
|
import { joinParts, mark, visibleLength, wrap, termOf } from "./term.js";
|
|
20
20
|
import { APPS_LINK, hashLink, workLink } from "./webLinks.js";
|
|
@@ -147,7 +147,8 @@ function changeOf(raw) {
|
|
|
147
147
|
? { number: pullNumber, title: pullTitle, url: pullUrl && /^https:\/\//.test(pullUrl) ? pullUrl : null }
|
|
148
148
|
: null,
|
|
149
149
|
undo: undoOf(entry.undo),
|
|
150
|
-
watch: watchOf(entry.watch)
|
|
150
|
+
watch: watchOf(entry.watch),
|
|
151
|
+
links: linkUrls(entry.links)
|
|
151
152
|
};
|
|
152
153
|
}
|
|
153
154
|
function watchOf(raw) {
|
|
@@ -264,6 +265,9 @@ export function changeParts(change, projects = false) {
|
|
|
264
265
|
const watch = watchPart(change.watch);
|
|
265
266
|
if (watch)
|
|
266
267
|
parts.push(watch);
|
|
268
|
+
// Its primary link, last: a terminal opens it.
|
|
269
|
+
if (change.links[0])
|
|
270
|
+
parts.push(change.links[0]);
|
|
267
271
|
return parts;
|
|
268
272
|
}
|
|
269
273
|
/** A change keeps its own line when it failed, was approved, or has an undo state worth seeing. */
|
package/dist/cliExec.js
CHANGED
|
@@ -186,7 +186,6 @@ export function spawnVendor(command, args, options, mask) {
|
|
|
186
186
|
});
|
|
187
187
|
});
|
|
188
188
|
}
|
|
189
|
-
const defaultSpawn = (command, args, options) => spawnVendor(command, args, options);
|
|
190
189
|
/**
|
|
191
190
|
* Masking is on when stdout isn't a terminal: an agent's shell, a pipe, a CI
|
|
192
191
|
* log, a transcript, where a printed key would be kept and read later. In a
|
|
@@ -516,8 +515,12 @@ export async function exec(args, runtime, deps = {}) {
|
|
|
516
515
|
let code;
|
|
517
516
|
const startedAt = (deps.now ?? Date.now)();
|
|
518
517
|
const needles = maskingWanted(args, runtime.env, runtime.stdout) ? secretNeedles(credential) : [];
|
|
518
|
+
// Links (bridge 0.32.0): a bounded copy of what it prints, only when that isn't a terminal.
|
|
519
|
+
const wanted = linksWanted(auth.kind === "profile" ? readCliPolicy(auth.profile) : null);
|
|
520
|
+
const capture = execCapture(wanted, runtime.stdout);
|
|
521
|
+
const piped = outputTarget(runtime, needles, capture);
|
|
519
522
|
const options = {
|
|
520
|
-
stdio:
|
|
523
|
+
stdio: piped ? ["inherit", "pipe", "pipe"] : "inherit",
|
|
521
524
|
env: childEnvironment(runtime.env, credential),
|
|
522
525
|
shell: false,
|
|
523
526
|
cwd: prepared.cwd
|
|
@@ -527,13 +530,7 @@ export async function exec(args, runtime, deps = {}) {
|
|
|
527
530
|
try {
|
|
528
531
|
code = deps.spawn
|
|
529
532
|
? await deps.spawn(prepared.executable, prepared.rest, options)
|
|
530
|
-
:
|
|
531
|
-
? await spawnVendor(prepared.executable, prepared.rest, options, {
|
|
532
|
-
needles,
|
|
533
|
-
stdout: runtime.stdout,
|
|
534
|
-
stderr: runtime.stderr
|
|
535
|
-
})
|
|
536
|
-
: await defaultSpawn(prepared.executable, prepared.rest, options);
|
|
533
|
+
: await spawnVendor(prepared.executable, prepared.rest, options, piped);
|
|
537
534
|
}
|
|
538
535
|
catch {
|
|
539
536
|
return failure(`${binary} couldn't start.`, 1, "not_installed");
|
|
@@ -542,7 +539,9 @@ export async function exec(args, runtime, deps = {}) {
|
|
|
542
539
|
await lease.stop();
|
|
543
540
|
}
|
|
544
541
|
if (typeof decided.actionId === "string") {
|
|
545
|
-
|
|
542
|
+
const durationMs = Math.max(0, Math.round((deps.now ?? Date.now)() - startedAt));
|
|
543
|
+
const links = execLinks(wanted, prepared, capture, deps.home);
|
|
544
|
+
await reportExecResult(client, { actionId: decided.actionId, exitCode: code, durationMs }, links, runtime);
|
|
546
545
|
}
|
|
547
546
|
const line = backupLine(decided, code);
|
|
548
547
|
if (line && !bool(args, "quiet"))
|
|
@@ -550,20 +549,5 @@ export async function exec(args, runtime, deps = {}) {
|
|
|
550
549
|
return { json: { exitCode: code }, silent: true, exitCode: code };
|
|
551
550
|
}
|
|
552
551
|
import { backupLine } from "./execBackupLine.js";
|
|
552
|
+
import { execCapture, execLinks, linksWanted, outputTarget, reportExecResult } from "./execLinks.js";
|
|
553
553
|
export { backupLine };
|
|
554
|
-
/** How the command ended, so its session row reads Ran or Failed. Best
|
|
555
|
-
* effort: two seconds at most, silent on failure, never the exit code. */
|
|
556
|
-
async function reportResult(client, actionId, exitCode, durationMs, runtime) {
|
|
557
|
-
try {
|
|
558
|
-
const response = await client.fetchApi(EXEC_RESULT_PATH, {
|
|
559
|
-
method: "POST",
|
|
560
|
-
headers: { "content-type": "application/json", accept: "application/json" },
|
|
561
|
-
body: JSON.stringify({ actionId, exitCode, durationMs: Math.max(0, Math.round(durationMs)) }),
|
|
562
|
-
signal: AbortSignal.any([runtime.signal, AbortSignal.timeout(2_000)])
|
|
563
|
-
});
|
|
564
|
-
await response.body?.cancel().catch(() => undefined);
|
|
565
|
-
}
|
|
566
|
-
catch {
|
|
567
|
-
/* the command already ran; its exit code is what matters */
|
|
568
|
-
}
|
|
569
|
-
}
|
package/dist/cliHook.d.ts
CHANGED
|
@@ -45,7 +45,7 @@ export declare function safeVerb(raw: string | null): string;
|
|
|
45
45
|
* hooks by default.
|
|
46
46
|
*/
|
|
47
47
|
export declare function detectRuntime(input: HookInput, env: Env, declared?: string): HookRuntime;
|
|
48
|
-
export declare function buildReport(input: HookInput, findings: CliFinding[], env: Env, declared?: string, decided?: DecidedFinding[], local?: boolean, scripts?: ScriptReader, backedUp?: ReadonlySet<CliFinding>): CliHookReport | null
|
|
48
|
+
export declare function buildReport(input: HookInput, findings: CliFinding[], env: Env, declared?: string, decided?: DecidedFinding[], local?: boolean, scripts?: ScriptReader, backedUp?: ReadonlySet<CliFinding>): Promise<CliHookReport | null>;
|
|
49
49
|
/** What the guard answered, and for which findings. The audit row that
|
|
50
50
|
* follows a command that ran carries its outcome and any opaque parts. */
|
|
51
51
|
export declare function buildDecisionReport(input: HookInput, decision: GuardDecision, env: Env, declared?: string, local?: boolean): CliHookReport | null;
|
package/dist/cliHook.js
CHANGED
|
@@ -21,17 +21,13 @@ import { projectOf } from "./cliHookProject.js";
|
|
|
21
21
|
import { codexAskBlocked, planGuard } from "./cliHookDecide.js";
|
|
22
22
|
import { guardMachineOf } from "./cliHookGuard.js";
|
|
23
23
|
import { detectMode } from "./cliHookMode.js";
|
|
24
|
-
import { cappedHold, holdSeconds } from "./cliHookHold.js";
|
|
25
24
|
import { commandText, readInput } from "./cliHookInput.js";
|
|
26
25
|
import { pairingId, withPairing, withParked } from "./cliHookPairing.js";
|
|
27
26
|
export { pairingId } from "./cliHookPairing.js";
|
|
28
27
|
import { budgetSignal, expiredAsks, HOOK_BUDGET_MS, HOOK_RUNTIMES, leftovers, localProfile, localSelection, profileApi, queueAfterCommand, reportSender, runFlush, startFlushIfDue } from "./cliHookDeliver.js";
|
|
29
28
|
export { HOOK_BUDGET_MS, HOOK_RUNTIMES, legacyReport } from "./cliHookDeliver.js";
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
32
|
-
import { auditBackups, auditDecision, auditedCommand, markTrashed } from "./cliHookAudit.js";
|
|
33
|
-
import { uncheckedNames } from "./cliHookUncheckedName.js";
|
|
34
|
-
import { opaqueParts } from "./cliHookOpaque.js";
|
|
29
|
+
import { guardBackups, mayBackUp } from "./localBackupsGate.js";
|
|
30
|
+
import { opaqueNames } from "./cliHookOpaque.js";
|
|
35
31
|
export { opaqueKind, opaqueProgram } from "./cliHookOpaque.js";
|
|
36
32
|
import { hasExpired, holdAsk } from "./cliHookPending.js";
|
|
37
33
|
import { readCliPolicy } from "./cliPolicy.js";
|
|
@@ -144,7 +140,7 @@ function reportable(findings, decided = [], local = false, backedUp) {
|
|
|
144
140
|
function autopilotDecision(decision) {
|
|
145
141
|
return decision?.cause ? { decision: decision.verdict } : {};
|
|
146
142
|
}
|
|
147
|
-
export function buildReport(input, findings, env, declared, decided = [], local = false, scripts, backedUp) {
|
|
143
|
+
export async function buildReport(input, findings, env, declared, decided = [], local = false, scripts, backedUp) {
|
|
148
144
|
const summary = summarize(findings);
|
|
149
145
|
const extra = scriptReport(scripts);
|
|
150
146
|
// A script that changed under a project action is worth a row of its own.
|
|
@@ -153,17 +149,19 @@ export function buildReport(input, findings, env, declared, decided = [], local
|
|
|
153
149
|
const governed = reportable(summary.governed, decided, local, backedUp);
|
|
154
150
|
if (!governed.length && !summary.opaque && !extra.projectChanged && !extra.drift)
|
|
155
151
|
return null;
|
|
156
|
-
|
|
157
|
-
const names =
|
|
152
|
+
// What couldn't be read is named only when there is some (`cliHookOpaque.ts`, `cliHookUncheckedName.ts`).
|
|
153
|
+
const { kinds, programs, names } = summary.opaque
|
|
154
|
+
? await opaqueNames(summary.unknown, MAX_OPAQUE_KINDS)
|
|
155
|
+
: { kinds: [], programs: [], names: [] };
|
|
158
156
|
const where = context(input, env, declared);
|
|
159
157
|
return {
|
|
160
158
|
...where,
|
|
161
159
|
...outcomeOfInput(input),
|
|
162
|
-
findings: markLocalBackups(governed, where),
|
|
160
|
+
findings: mayBackUp(governed) ? (await import("./localBackups.js")).markLocalBackups(governed, where) : governed,
|
|
163
161
|
opaque: summary.opaque,
|
|
164
|
-
...(
|
|
165
|
-
...(
|
|
166
|
-
...(
|
|
162
|
+
...(kinds.length ? { opaqueKinds: kinds } : {}),
|
|
163
|
+
...(programs.length ? { opaquePrograms: programs } : {}),
|
|
164
|
+
...(names.length ? { opaqueNames: names } : {}),
|
|
167
165
|
...extra
|
|
168
166
|
};
|
|
169
167
|
}
|
|
@@ -208,7 +206,7 @@ export function shellEvent(input) {
|
|
|
208
206
|
/** Only hold an ask when the audit hook will be there to claim it. */
|
|
209
207
|
async function claudeAuditRegistered(runtime) {
|
|
210
208
|
// The Passport plugin ships the audit hook alongside this guard.
|
|
211
|
-
if (hookViaPlugin(runtime.env))
|
|
209
|
+
if ((await import("./hookPlugin.js")).hookViaPlugin(runtime.env))
|
|
212
210
|
return true;
|
|
213
211
|
try {
|
|
214
212
|
const { registeredEntries } = await import("./cliHookInstall.js");
|
|
@@ -272,11 +270,13 @@ async function runAudit(args, runtime, deps) {
|
|
|
272
270
|
const profile = localProfile(args, runtime.env);
|
|
273
271
|
const policy = profile ? readCliPolicy(profile) : null;
|
|
274
272
|
const now = (deps.now ?? Date.now)();
|
|
275
|
-
const
|
|
273
|
+
const declared = value(args, "client");
|
|
274
|
+
const runtimeName = detectRuntime(input, runtime.env, declared);
|
|
276
275
|
const after = await import("./cliHookAfter.js");
|
|
277
276
|
const facts = { input, profile, policy, runtimeName, cursorImported: event.cursorImported, now };
|
|
278
277
|
const base = () => context(input, runtime.env, value(args, "client"));
|
|
279
|
-
const
|
|
278
|
+
const audit = await import("./cliHookAudit.js");
|
|
279
|
+
const audited = await audit.auditedCommand(event.command);
|
|
280
280
|
// `passport exec` records its own row; what it created or kept failing at still counts.
|
|
281
281
|
if (!audited)
|
|
282
282
|
return void (await after.afterExec({ ...facts, command: event.command, args, runtime, deps, base }));
|
|
@@ -290,17 +290,17 @@ async function runAudit(args, runtime, deps) {
|
|
|
290
290
|
saveScriptCache(scripts);
|
|
291
291
|
// v2: the same decision the guard made, so the row says why it ran.
|
|
292
292
|
const key = withPairing(context(input, runtime.env, value(args, "client")), input, event.command);
|
|
293
|
-
const { taken, backedUp } = auditBackups(findings, key, Boolean(trashed));
|
|
293
|
+
const { taken, backedUp } = await audit.auditBackups(findings, key, Boolean(trashed));
|
|
294
294
|
const guardAt = { ...guardAtFor(machine, input, runtime.env), ...taken };
|
|
295
|
-
const { decision, local, decided } = auditDecision(findings, policy, command, line.complete, guardAt);
|
|
296
|
-
let report = buildReport(input, findings, runtime.env,
|
|
295
|
+
const { decision, local, decided } = audit.auditDecision(findings, policy, command, line.complete, guardAt);
|
|
296
|
+
let report = await buildReport(input, findings, runtime.env, declared, decided, local, scripts, backedUp);
|
|
297
297
|
if (report && trashed)
|
|
298
|
-
report = markTrashed(report, trashed.key);
|
|
298
|
+
report = audit.markTrashed(report, trashed.key);
|
|
299
299
|
if (report && policy?.version === 2) {
|
|
300
300
|
report = withStep({ ...report, ...autopilotDecision(decision) }, input, policy);
|
|
301
301
|
}
|
|
302
302
|
// A sign-in that expired, what it created, a retry loop: the report, and what Claude Code reads.
|
|
303
|
-
const told = after.afterCommand({ ...facts, command, findings, report, base });
|
|
303
|
+
const told = await after.afterCommand({ ...facts, command, findings, report, base });
|
|
304
304
|
report = told.report;
|
|
305
305
|
if (told.output)
|
|
306
306
|
runtime.stdout.write(`${JSON.stringify(told.output)}\n`);
|
|
@@ -463,7 +463,7 @@ async function runGuard(args, runtime, deps) {
|
|
|
463
463
|
const client = outputClient(event, detectRuntime(input, runtime.env, declared));
|
|
464
464
|
// Which deletes will have a backup on this computer, so the rules decide knowing it.
|
|
465
465
|
const key = withPairing(context(input, runtime.env, declared), input, event.command);
|
|
466
|
-
const backups =
|
|
466
|
+
const backups = await guardBackups(event.command, line, policy, {
|
|
467
467
|
...{ ...guardAtFor(machine, input, runtime.env), machine, key },
|
|
468
468
|
rewrite: client === "claude-code" && !event.cursorImported
|
|
469
469
|
});
|
|
@@ -507,6 +507,7 @@ async function runGuard(args, runtime, deps) {
|
|
|
507
507
|
deadline: startedAt + HOOK_BUDGET_MS - PRINT_RESERVE_MS,
|
|
508
508
|
now: deps.now ?? Date.now,
|
|
509
509
|
hold: async () => {
|
|
510
|
+
const { cappedHold, holdSeconds } = await import("./cliHookHold.js");
|
|
510
511
|
const seconds = holdSeconds(value(args, "hold"), runtime.env);
|
|
511
512
|
if (seconds <= 0)
|
|
512
513
|
return 0;
|
package/dist/cliHookAfter.d.ts
CHANGED
|
@@ -9,7 +9,9 @@
|
|
|
9
9
|
* - how many times in a row the same command failed (`cliHookSessionState.ts`);
|
|
10
10
|
* - the non-default branch a `git push` that succeeded sent (`cliHookPushed.ts`),
|
|
11
11
|
* for the session's title, to any server (an older one refuses it and the
|
|
12
|
-
* report goes again without it)
|
|
12
|
+
* report goes again without it);
|
|
13
|
+
* - links to what it acted on in the vendor's own app (`cliHookLinks.ts`):
|
|
14
|
+
* allowlisted URLs only, to a server whose cli-policy says `links`.
|
|
13
15
|
*
|
|
14
16
|
* The report carries only the vendor, kinds, names, and counts, and only to
|
|
15
17
|
* a server that keeps them (cli-policy v2 `afterFacts`). The agent hears
|
|
@@ -23,6 +25,7 @@ import type { HookInput } from "./cliHookInput.js";
|
|
|
23
25
|
import type { CachedCliPolicy } from "./cliPolicy.js";
|
|
24
26
|
import type { Runtime } from "./cliSupport.js";
|
|
25
27
|
import { type ExecVendor } from "./execVendors.js";
|
|
28
|
+
import type { LinksMachine } from "./cliHookLinks.js";
|
|
26
29
|
/** The agent hears about a retry loop from this many failures in a row. */
|
|
27
30
|
export declare const RETRY_TELL_AT = 3;
|
|
28
31
|
/** What Claude Code reads when the sign-in expired. */
|
|
@@ -43,16 +46,18 @@ type AfterContext = {
|
|
|
43
46
|
now: number;
|
|
44
47
|
/** `passport exec` ran it with the key Passport holds: a sign-in here isn't the cause. */
|
|
45
48
|
exec?: true;
|
|
49
|
+
/** Where links are read from. Tests only; the computer's own files otherwise. */
|
|
50
|
+
linksMachine?: LinksMachine;
|
|
46
51
|
};
|
|
47
52
|
/**
|
|
48
53
|
* After a command: the report with what the hook learned, and what Claude
|
|
49
54
|
* Code should read (or null). Codex and Cursor are told by the guard on the
|
|
50
55
|
* next try, from this session's state.
|
|
51
56
|
*/
|
|
52
|
-
export declare function afterCommand(context: AfterContext): {
|
|
57
|
+
export declare function afterCommand(context: AfterContext): Promise<{
|
|
53
58
|
report: CliHookReport | null;
|
|
54
59
|
output: Record<string, unknown> | null;
|
|
55
|
-
}
|
|
60
|
+
}>;
|
|
56
61
|
/**
|
|
57
62
|
* `passport exec` records its own action, so the after-hook sends no row for
|
|
58
63
|
* it; what the command inside it created, removed, or kept failing at is
|
package/dist/cliHookAfter.js
CHANGED
|
@@ -9,24 +9,20 @@
|
|
|
9
9
|
* - how many times in a row the same command failed (`cliHookSessionState.ts`);
|
|
10
10
|
* - the non-default branch a `git push` that succeeded sent (`cliHookPushed.ts`),
|
|
11
11
|
* for the session's title, to any server (an older one refuses it and the
|
|
12
|
-
* report goes again without it)
|
|
12
|
+
* report goes again without it);
|
|
13
|
+
* - links to what it acted on in the vendor's own app (`cliHookLinks.ts`):
|
|
14
|
+
* allowlisted URLs only, to a server whose cli-policy says `links`.
|
|
13
15
|
*
|
|
14
16
|
* The report carries only the vendor, kinds, names, and counts, and only to
|
|
15
17
|
* a server that keeps them (cli-policy v2 `afterFacts`). The agent hears
|
|
16
18
|
* about a sign-in or a retry loop in its own words: Claude Code as
|
|
17
19
|
* `additionalContext` now; Codex and Cursor from the guard on their next try.
|
|
18
20
|
*/
|
|
19
|
-
import { resourcesOf } from "./cliHookCreates.js";
|
|
20
21
|
import { classifyLine, localMachine, workingFolder } from "./cliHookLocal.js";
|
|
21
22
|
import { execInner } from "./cliHookRewrite.js";
|
|
22
23
|
import { nextRetry, readSessionState, writeSessionState } from "./cliHookSessionState.js";
|
|
23
|
-
import { readExecVendors } from "./execMarker.js";
|
|
24
24
|
import { EXEC_VENDOR_NAMES, vendorCommand } from "./execVendors.js";
|
|
25
|
-
import { readKeysChoices } from "./keysKept.js";
|
|
26
|
-
import { outputTail, signInFailureOf } from "./signInFailure.js";
|
|
27
25
|
import { outcomeOfInput } from "./cliHookOutcome.js";
|
|
28
|
-
import { pushedOf } from "./cliHookPushed.js";
|
|
29
|
-
import { RETRY_ASK_AT } from "./cliHookStuck.js";
|
|
30
26
|
/** The agent hears about a retry loop from this many failures in a row. */
|
|
31
27
|
export const RETRY_TELL_AT = 3;
|
|
32
28
|
/** What Claude Code reads when the sign-in expired. */
|
|
@@ -45,21 +41,32 @@ export function retryContext(streak, program, asksNext) {
|
|
|
45
41
|
}
|
|
46
42
|
/** Whether Passport holds a key for this vendor (this computer's list, or the
|
|
47
43
|
* rules Passport sent), and whether the guard sends the CLI through it. */
|
|
48
|
-
function heldKey(profile, policy, vendor) {
|
|
44
|
+
async function heldKey(profile, policy, vendor) {
|
|
49
45
|
if (!profile)
|
|
50
46
|
return { held: false, rerouted: false };
|
|
47
|
+
const [{ readExecVendors }, { readKeysChoices }] = await Promise.all([
|
|
48
|
+
import("./execMarker.js"),
|
|
49
|
+
import("./keysKept.js")
|
|
50
|
+
]);
|
|
51
51
|
const marked = readExecVendors(profile).has(vendor);
|
|
52
52
|
const told = policy?.version === 2 && (policy.autopilot.heldKeys ?? []).includes(vendor);
|
|
53
53
|
return { held: marked || told, rerouted: marked && !readKeysChoices(profile).kept[vendor] };
|
|
54
54
|
}
|
|
55
|
-
|
|
55
|
+
/** Each fact's code loads only when the command could carry it: a sign-in
|
|
56
|
+
* only after a failure, resources and a pushed branch only after a success. */
|
|
57
|
+
async function learn(context, state) {
|
|
56
58
|
const { exitCode } = outcomeOfInput(context.input);
|
|
57
59
|
const failed = exitCode !== undefined && exitCode !== 0;
|
|
58
|
-
const signIn = failed && !context.exec
|
|
59
|
-
|
|
60
|
+
const signIn = failed && !context.exec
|
|
61
|
+
? await import("./signInFailure.js").then(({ outputTail, signInFailureOf }) => signInFailureOf(context.findings, outputTail(context.input), exitCode))
|
|
62
|
+
: null;
|
|
63
|
+
const resources = failed || !context.findings.length
|
|
64
|
+
? { creates: [], removes: [] }
|
|
65
|
+
: (await import("./cliHookCreates.js")).resourcesOf(context.findings);
|
|
60
66
|
const retry = nextRetry(state, context.command, exitCode, context.now);
|
|
61
67
|
const program = retry.state.retry?.program;
|
|
62
|
-
const
|
|
68
|
+
const pushes = context.findings.some((finding) => finding.vendor === "git" && finding.verb === "push");
|
|
69
|
+
const pushed = failed || !pushes ? undefined : (await import("./cliHookPushed.js")).pushedOf(context.findings);
|
|
63
70
|
return {
|
|
64
71
|
learned: {
|
|
65
72
|
signIn,
|
|
@@ -95,17 +102,29 @@ function withFacts(context, learned) {
|
|
|
95
102
|
return context.report;
|
|
96
103
|
return { ...(context.report ?? { ...context.base(), findings: [], opaque: false }), ...facts };
|
|
97
104
|
}
|
|
105
|
+
/** Links to what the command acted on, on its own row, for a server that keeps them. */
|
|
106
|
+
async function withLinks(context, report) {
|
|
107
|
+
if (!report?.findings.length || context.exec)
|
|
108
|
+
return report;
|
|
109
|
+
if (context.policy?.version !== 2 || !context.policy.autopilot.reportsLinks)
|
|
110
|
+
return report;
|
|
111
|
+
// A `passport exec` part in the line sends its own command's links with its result.
|
|
112
|
+
const execPart = /\bpassport'?\s+'?exec\b/.test(context.command);
|
|
113
|
+
const { linksOf } = await import("./cliHookLinks.js");
|
|
114
|
+
const links = linksOf(context.findings, context.input, context.linksMachine, execPart);
|
|
115
|
+
return links.length ? { ...report, links } : report;
|
|
116
|
+
}
|
|
98
117
|
/**
|
|
99
118
|
* After a command: the report with what the hook learned, and what Claude
|
|
100
119
|
* Code should read (or null). Codex and Cursor are told by the guard on the
|
|
101
120
|
* next try, from this session's state.
|
|
102
121
|
*/
|
|
103
|
-
export function afterCommand(context) {
|
|
122
|
+
export async function afterCommand(context) {
|
|
104
123
|
const sessionId = context.report?.sessionId ?? context.base().sessionId;
|
|
105
124
|
const before = readSessionState(context.runtimeName, sessionId, context.now);
|
|
106
|
-
const { learned, state } = learn(context, before);
|
|
125
|
+
const { learned, state } = await learn(context, before);
|
|
107
126
|
const key = learned.signIn
|
|
108
|
-
? heldKey(context.profile, context.policy, learned.signIn)
|
|
127
|
+
? await heldKey(context.profile, context.policy, learned.signIn)
|
|
109
128
|
: { held: false, rerouted: false };
|
|
110
129
|
const claude = context.runtimeName === "claude-code" && !context.cursorImported;
|
|
111
130
|
const next = learned.signIn && !claude
|
|
@@ -113,14 +132,16 @@ export function afterCommand(context) {
|
|
|
113
132
|
: state;
|
|
114
133
|
if (JSON.stringify(next) !== JSON.stringify(before))
|
|
115
134
|
writeSessionState(context.runtimeName, sessionId, next);
|
|
116
|
-
const report = withPushed(context, withFacts(context, learned), learned.pushed);
|
|
135
|
+
const report = await withLinks(context, withPushed(context, withFacts(context, learned), learned.pushed));
|
|
117
136
|
if (!claude)
|
|
118
137
|
return { report, output: null };
|
|
119
138
|
const asksNext = context.policy?.version === 2 && context.policy.autopilot.retryLoops === true;
|
|
139
|
+
// The loop's ask threshold (`cliHookStuck.ts`) matters only once the agent is told.
|
|
140
|
+
const askAt = learned.streak >= RETRY_TELL_AT ? (await import("./cliHookStuck.js")).RETRY_ASK_AT : Infinity;
|
|
120
141
|
const lines = [
|
|
121
142
|
...(learned.signIn ? [signInContext(learned.signIn, key.held, key.rerouted && claude)] : []),
|
|
122
143
|
...(learned.streak >= RETRY_TELL_AT
|
|
123
|
-
? [retryContext(learned.streak, learned.program, asksNext && learned.streak >=
|
|
144
|
+
? [retryContext(learned.streak, learned.program, asksNext && learned.streak >= askAt)]
|
|
124
145
|
: [])
|
|
125
146
|
];
|
|
126
147
|
const event = typeof context.input.hook_event_name === "string" ? context.input.hook_event_name : "PostToolUse";
|
|
@@ -140,7 +161,7 @@ export async function afterExec(context) {
|
|
|
140
161
|
return;
|
|
141
162
|
const machine = localMachine(workingFolder(context.input), context.runtime.env);
|
|
142
163
|
const findings = classifyLine(inner, machine).findings;
|
|
143
|
-
const { report, output } = afterCommand({ ...context, command: inner, findings, report: null, exec: true });
|
|
164
|
+
const { report, output } = await afterCommand({ ...context, command: inner, findings, report: null, exec: true });
|
|
144
165
|
if (output)
|
|
145
166
|
context.runtime.stdout.write(`${JSON.stringify(output)}\n`);
|
|
146
167
|
if (!report)
|
package/dist/cliHookAudit.d.ts
CHANGED
|
@@ -16,24 +16,24 @@ export declare function isPassportExec(command: string): boolean;
|
|
|
16
16
|
* own action (`passport exec`). An rm the guard sent to its trash is recorded
|
|
17
17
|
* as the agent's own rm, with the backup's id.
|
|
18
18
|
*/
|
|
19
|
-
export declare function auditedCommand(command: string): {
|
|
19
|
+
export declare function auditedCommand(command: string): Promise<{
|
|
20
20
|
command: string;
|
|
21
21
|
trashed?: {
|
|
22
22
|
key: string;
|
|
23
23
|
};
|
|
24
|
-
} | null
|
|
24
|
+
} | null>;
|
|
25
25
|
/**
|
|
26
26
|
* What the guard backed up before this exact command (for the decision), and
|
|
27
27
|
* the findings whose row is where an Undo lives: real backups, not folders a
|
|
28
28
|
* build makes again.
|
|
29
29
|
*/
|
|
30
|
-
export declare function auditBackups(findings: CliFinding[], key: BackupKey, trashed: boolean): {
|
|
30
|
+
export declare function auditBackups(findings: CliFinding[], key: BackupKey, trashed: boolean): Promise<{
|
|
31
31
|
taken: {
|
|
32
32
|
backups: Set<CliFinding>;
|
|
33
33
|
regenerable: Set<CliFinding>;
|
|
34
34
|
};
|
|
35
35
|
backedUp: Set<CliFinding>;
|
|
36
|
-
}
|
|
36
|
+
}>;
|
|
37
37
|
/** v2: the same decision the guard made, and where each command landed even without one. */
|
|
38
38
|
export declare function auditDecision(findings: CliFinding[], policy: CachedCliPolicy | null, command: string, complete: boolean, guardAt: Parameters<typeof decideEach>[2]): {
|
|
39
39
|
decision: GuardDecision | null;
|
package/dist/cliHookAudit.js
CHANGED
|
@@ -5,8 +5,7 @@
|
|
|
5
5
|
* and the same decision the guard made.
|
|
6
6
|
*/
|
|
7
7
|
import { decideEach, decideGuard } from "./cliHookGuard.js";
|
|
8
|
-
import {
|
|
9
|
-
import { trashedLine } from "./localTrash.js";
|
|
8
|
+
import { mayBackUp } from "./localBackupsGate.js";
|
|
10
9
|
/** `passport exec` records its own action, with its decision and credential. */
|
|
11
10
|
export function isPassportExec(command) {
|
|
12
11
|
// The guard's own rewrites: passport exec, and rm through the trash.
|
|
@@ -17,8 +16,9 @@ export function isPassportExec(command) {
|
|
|
17
16
|
* own action (`passport exec`). An rm the guard sent to its trash is recorded
|
|
18
17
|
* as the agent's own rm, with the backup's id.
|
|
19
18
|
*/
|
|
20
|
-
export function auditedCommand(command) {
|
|
21
|
-
|
|
19
|
+
export async function auditedCommand(command) {
|
|
20
|
+
// Only the trash's own line is read by `localTrash.ts`.
|
|
21
|
+
const trashed = command.includes("hook trash -- ") ? (await import("./localTrash.js")).trashedLine(command) : null;
|
|
22
22
|
if (trashed)
|
|
23
23
|
return { command: trashed.command, trashed: { key: trashed.key } };
|
|
24
24
|
return isPassportExec(command) ? null : { command };
|
|
@@ -28,8 +28,10 @@ export function auditedCommand(command) {
|
|
|
28
28
|
* the findings whose row is where an Undo lives: real backups, not folders a
|
|
29
29
|
* build makes again.
|
|
30
30
|
*/
|
|
31
|
-
export function auditBackups(findings, key, trashed) {
|
|
32
|
-
const taken =
|
|
31
|
+
export async function auditBackups(findings, key, trashed) {
|
|
32
|
+
const taken = mayBackUp(findings)
|
|
33
|
+
? (await import("./localBackups.js")).takenLocalBackups(findings, key)
|
|
34
|
+
: { backups: new Set(), regenerable: new Set() };
|
|
33
35
|
if (trashed)
|
|
34
36
|
for (const finding of findings)
|
|
35
37
|
if (finding.vendor === "rm")
|
package/dist/cliHookDeliver.d.ts
CHANGED
|
@@ -112,6 +112,9 @@ export type CliHookReport = {
|
|
|
112
112
|
branch: string;
|
|
113
113
|
project?: string;
|
|
114
114
|
};
|
|
115
|
+
/** Links to what it acted on in the vendor's own app (`cliHookLinks.ts`):
|
|
116
|
+
* allowlisted URLs only, at most three, the thing itself first. */
|
|
117
|
+
links?: string[];
|
|
115
118
|
};
|
|
116
119
|
/** One governed command as reported: never its arguments. v2 adds the
|
|
117
120
|
* environment: a short name the flags gave, or a kind. */
|
package/dist/cliHookDeliver.js
CHANGED
|
@@ -102,6 +102,18 @@ async function postWith(api, initial, signal) {
|
|
|
102
102
|
body: JSON.stringify(body),
|
|
103
103
|
signal
|
|
104
104
|
});
|
|
105
|
+
if (initial.links === undefined)
|
|
106
|
+
return postFallbacks(post, initial);
|
|
107
|
+
// A server from before links (bridge 0.32.0) refuses the field: the rest goes again without it.
|
|
108
|
+
const response = await post(initial);
|
|
109
|
+
await response.body?.cancel().catch(() => undefined);
|
|
110
|
+
if (response.status !== 400)
|
|
111
|
+
return;
|
|
112
|
+
const { links: _links, ...rest } = initial;
|
|
113
|
+
return postFallbacks(post, rest);
|
|
114
|
+
}
|
|
115
|
+
/** One report, and again without each field an older server refuses. */
|
|
116
|
+
async function postFallbacks(post, initial) {
|
|
105
117
|
let report = initial;
|
|
106
118
|
let response = await post(report);
|
|
107
119
|
await response.body?.cancel().catch(() => undefined);
|
|
@@ -359,7 +371,7 @@ export async function leftovers(queued, context) {
|
|
|
359
371
|
// can expire), and the computer's daily guard report.
|
|
360
372
|
const extras = await import("./cliHookExtras.js");
|
|
361
373
|
const seen = extras.claimSeen(profile, now);
|
|
362
|
-
const heartbeat = extras.heartbeatDue(profile, now);
|
|
374
|
+
const heartbeat = await extras.heartbeatDue(profile, now);
|
|
363
375
|
// Token numbers, read here from transcripts the hooks noted: never on a hook's path.
|
|
364
376
|
const usage = await import("./cliUsage.js");
|
|
365
377
|
const keepsUsage = context.policy?.version === 2 && context.policy.autopilot.reportsUsage === true;
|
package/dist/cliHookExtras.d.ts
CHANGED
|
@@ -21,8 +21,9 @@ sessionId?: string): Promise<void>;
|
|
|
21
21
|
export declare function claimSeen(profile: string, now: number): Claimed | null;
|
|
22
22
|
/** A batch as servers from before the buckets take it: `opaque` already is the blind count. */
|
|
23
23
|
export declare function legacySeen(seen: SeenBatch): LegacySeen;
|
|
24
|
-
/** A guard run's first report waits a day; later ones go when due.
|
|
25
|
-
|
|
24
|
+
/** A guard run's first report waits a day; later ones go when due. The
|
|
25
|
+
* report's code (`cliGuardHealth.ts`) loads only here, never on a guard's own path. */
|
|
26
|
+
export declare function heartbeatDue(profile: string, now: number): Promise<boolean>;
|
|
26
27
|
/** Send one coverage batch under its agent; it counts as sent once Passport took it. */
|
|
27
28
|
export declare function sendSeen(claimed: Claimed, post: (batch: {
|
|
28
29
|
seen: SeenBatch;
|
package/dist/cliHookExtras.js
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
* an agent down).
|
|
6
6
|
*/
|
|
7
7
|
import { claimSeenBatch, noteSeen, seenMark, settleSeenBatch } from "./cliSeen.js";
|
|
8
|
-
import { guardHeartbeat, guardHeartbeatDue } from "./cliGuardHealth.js";
|
|
9
8
|
export const HEARTBEAT_MIN_LEFT_MS = 300;
|
|
10
9
|
const HOOK_RUNTIMES = new Set(["claude-code", "codex", "copilot", "cursor", "other"]);
|
|
11
10
|
/** Count what the guard saw, once even when Cursor runs its imported copy of
|
|
@@ -30,9 +29,10 @@ export function legacySeen(seen) {
|
|
|
30
29
|
: {})
|
|
31
30
|
};
|
|
32
31
|
}
|
|
33
|
-
/** A guard run's first report waits a day; later ones go when due.
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
/** A guard run's first report waits a day; later ones go when due. The
|
|
33
|
+
* report's code (`cliGuardHealth.ts`) loads only here, never on a guard's own path. */
|
|
34
|
+
export async function heartbeatDue(profile, now) {
|
|
35
|
+
return (await import("./cliGuardHealth.js")).guardHeartbeatDue(profile, now, true);
|
|
36
36
|
}
|
|
37
37
|
/** Send one coverage batch under its agent; it counts as sent once Passport took it. */
|
|
38
38
|
export async function sendSeen(claimed, post, profile, now) {
|
|
@@ -43,5 +43,5 @@ export async function sendSeen(claimed, post, profile, now) {
|
|
|
43
43
|
settleSeenBatch(profile, claimed.batch, now);
|
|
44
44
|
}
|
|
45
45
|
export async function heartbeat(api, profile, env, signal, now) {
|
|
46
|
-
await guardHeartbeat(api, profile, env, signal, now);
|
|
46
|
+
await (await import("./cliGuardHealth.js")).guardHeartbeat(api, profile, env, signal, now);
|
|
47
47
|
}
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
import { type ParsedArgs } from "./cliArgs.js";
|
|
15
15
|
import type { CliHookReport, HookDependencies, HookRuntime } from "./cliHookDeliver.js";
|
|
16
16
|
import type { HookInput } from "./cliHookInput.js";
|
|
17
|
-
import {
|
|
17
|
+
import type { RepoRuleReport } from "./repoRules.js";
|
|
18
18
|
import type { Env, Runtime } from "./cliSupport.js";
|
|
19
19
|
export declare function isLifecycleEvent(input: HookInput): boolean;
|
|
20
20
|
/** The marker for one lifecycle event, or null (no session id, or not one).
|
package/dist/cliHookLifecycle.js
CHANGED
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
import { value } from "./cliArgs.js";
|
|
15
15
|
import { detectMode } from "./cliHookMode.js";
|
|
16
16
|
import { gitRootOf, projectOf } from "./cliHookProject.js";
|
|
17
|
-
import { markRepoRulesSeen, repoRulesAt } from "./repoRules.js";
|
|
18
17
|
const MODEL = /^[A-Za-z0-9][A-Za-z0-9._:@/[\]-]{0,79}$/;
|
|
19
18
|
const SESSION_ID = /^[A-Za-z0-9._:-]{1,128}$/;
|
|
20
19
|
export function isLifecycleEvent(input) {
|
|
@@ -66,12 +65,13 @@ export function lifecycleReport(input, runtime, env, repoRules = []) {
|
|
|
66
65
|
...(started && repoRules.length ? { repoRules: [...repoRules] } : {})
|
|
67
66
|
};
|
|
68
67
|
}
|
|
69
|
-
/** A start's repo rules: read from the repository's root, new versions only.
|
|
70
|
-
|
|
68
|
+
/** A start's repo rules: read from the repository's root, new versions only.
|
|
69
|
+
* `repoRules.ts` loads only for a start. */
|
|
70
|
+
async function repoRulesOf(input) {
|
|
71
71
|
if (input.hook_event_name !== "SessionStart")
|
|
72
72
|
return { fresh: [], seen: [] };
|
|
73
73
|
const { project } = projectOf(input.cwd);
|
|
74
|
-
return repoRulesAt(gitRootOf(input.cwd) ?? null, project);
|
|
74
|
+
return (await import("./repoRules.js")).repoRulesAt(gitRootOf(input.cwd) ?? null, project);
|
|
75
75
|
}
|
|
76
76
|
/** Which agent: the installed entry names it (`--client codex`); Claude
|
|
77
77
|
* Code's entry is unqualified. */
|
|
@@ -84,11 +84,12 @@ export async function lifecycle(input, args, runtime, deps) {
|
|
|
84
84
|
if (!isLifecycleEvent(input))
|
|
85
85
|
return false;
|
|
86
86
|
const name = runtimeOf(args, runtime.env);
|
|
87
|
-
const rules = repoRulesOf(input);
|
|
87
|
+
const rules = await repoRulesOf(input);
|
|
88
88
|
const report = lifecycleReport(input, name, runtime.env, rules.fresh);
|
|
89
89
|
if (!report)
|
|
90
90
|
return true;
|
|
91
|
-
|
|
91
|
+
if (rules.seen.length)
|
|
92
|
+
(await import("./repoRules.js")).markRepoRulesSeen(rules.seen);
|
|
92
93
|
const deliver = await import("./cliHookDeliver.js");
|
|
93
94
|
const now = (deps.now ?? Date.now)();
|
|
94
95
|
await noteUsage(input, runtime.env, name, deliver.profileAuth(args, runtime.env));
|