passport-bridge 0.16.6 → 0.16.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/README.md +32 -20
  2. package/dist/bridgeExchange.d.ts +1 -1
  3. package/dist/bridgeExchange.js +1 -1
  4. package/dist/cli.js +6 -6
  5. package/dist/cliActions.d.ts +28 -0
  6. package/dist/cliActions.js +224 -0
  7. package/dist/cliApprovalLink.d.ts +5 -0
  8. package/dist/cliApprovalLink.js +21 -0
  9. package/dist/cliArgs.d.ts +1 -1
  10. package/dist/cliArgs.js +17 -7
  11. package/dist/cliAutopilot.d.ts +3 -1
  12. package/dist/cliAutopilot.js +13 -2
  13. package/dist/cliAutopilotPolicy.d.ts +13 -0
  14. package/dist/cliExec.js +3 -3
  15. package/dist/cliGuardHealth.d.ts +3 -1
  16. package/dist/cliGuardHealth.js +6 -43
  17. package/dist/cliHook.d.ts +2 -1
  18. package/dist/cliHook.js +52 -14
  19. package/dist/cliHookClassify.d.ts +12 -0
  20. package/dist/cliHookDeliver.d.ts +16 -0
  21. package/dist/cliHookDeliver.js +12 -2
  22. package/dist/cliHookGuard.d.ts +1 -1
  23. package/dist/cliHookGuard.js +50 -7
  24. package/dist/cliHookInstall.js +1 -1
  25. package/dist/cliHookLocal.d.ts +6 -0
  26. package/dist/cliHookLocal.js +56 -3
  27. package/dist/cliHookLocalCode.d.ts +11 -0
  28. package/dist/cliHookLocalCode.js +18 -5
  29. package/dist/cliHookScripts.d.ts +51 -0
  30. package/dist/cliHookScripts.js +247 -0
  31. package/dist/cliHookStatus.js +4 -4
  32. package/dist/cliInit.js +1 -1
  33. package/dist/cliLogin.js +1 -1
  34. package/dist/cliOpaqueId.d.ts +10 -0
  35. package/dist/cliOpaqueId.js +48 -0
  36. package/dist/cliOutput.js +18 -10
  37. package/dist/cliPolicyV2.js +54 -2
  38. package/dist/cliScan.js +3 -3
  39. package/dist/cliScriptRead.d.ts +199 -0
  40. package/dist/cliScriptRead.js +512 -0
  41. package/dist/cliScriptText.d.ts +78 -0
  42. package/dist/cliScriptText.js +412 -0
  43. package/dist/cliSession.d.ts +1 -0
  44. package/dist/cliSession.js +2 -0
  45. package/dist/cliSetup.js +3 -3
  46. package/dist/cliSetupLock.d.ts +37 -0
  47. package/dist/cliSetupLock.js +330 -0
  48. package/dist/cliSetupOrg.d.ts +2 -0
  49. package/dist/cliSetupOrg.js +28 -2
  50. package/dist/cliSupport.d.ts +4 -0
  51. package/dist/completion.js +8 -4
  52. package/dist/hookFastPath.js +0 -5
  53. package/dist/initLocalSteps.js +7 -7
  54. package/dist/launcherFastPath.d.ts +4 -1
  55. package/dist/launcherFastPath.js +4 -7
  56. package/dist/lockedHooks.d.ts +99 -0
  57. package/dist/lockedHooks.js +178 -0
  58. package/dist/managedHooks.d.ts +10 -0
  59. package/dist/managedHooks.js +80 -0
  60. package/dist/managedSkills.js +4 -4
  61. package/dist/passport.js +5 -4
  62. package/dist/pluginPin.d.ts +1 -1
  63. package/dist/pluginPin.js +1 -1
  64. package/dist/recoveryIdentity.js +2 -2
  65. package/dist/version.d.ts +1 -1
  66. package/dist/version.js +1 -1
  67. package/dist/webLinks.d.ts +5 -0
  68. package/dist/webLinks.js +49 -0
  69. package/npm-shrinkwrap.json +2 -2
  70. package/package.json +1 -1
@@ -21,8 +21,10 @@ import { NODE_LINK_FS } from "./envLinkFs.js";
21
21
  import { resolveTarget } from "./envResolve.js";
22
22
  // `passport env` lives in cliEnv.ts; the dispatcher reaches it through here.
23
23
  export { env } from "./cliEnv.js";
24
+ export { actions } from "./cliActions.js";
24
25
  import { looseningLines } from "./cliLoosening.js";
25
26
  import { readCliPolicy } from "./cliPolicy.js";
27
+ import { ruleLink, sessionLink } from "./webLinks.js";
26
28
  import { callerFrom, failure, readBoundedJson, resolveCliAuth, safeApiError, sanitize, sleep, timeoutMs } from "./cliSupport.js";
27
29
  /** Long enough to be useful, short enough for an agent's default 2-minute
28
30
  * command timeout. */
@@ -377,7 +379,12 @@ export async function sessions(args, runtime, deps = {}) {
377
379
  const rows = (Array.isArray(page.sessions) ? page.sessions : []).slice(0, 50);
378
380
  const now = (deps.now ?? Date.now)();
379
381
  const human = rows.length
380
- ? rows.map((row) => sessionLine(row, now)).join("\n")
382
+ ? rows
383
+ .map((row) => {
384
+ const link = sessionLink(client.origin, typeof row.id === "string" ? row.id : undefined);
385
+ return link ? `${sessionLine(row, now)}\n ${link}` : sessionLine(row, now);
386
+ })
387
+ .join("\n")
381
388
  : "No sessions yet. Start your agent and its actions will show up here.";
382
389
  return { json: { sessions: rows, nextCursor: page.nextCursor ?? null }, human };
383
390
  }
@@ -467,7 +474,8 @@ export async function autopilotStatus(fetchApi, profile, signal, now = Date.now(
467
474
  return { presets: null, floors: null, cache };
468
475
  }
469
476
  }
470
- export function autopilotLines(status) {
477
+ /** `passport status` lines; with the web origin, a link to change the rules. */
478
+ export function autopilotLines(status, webOrigin) {
471
479
  const lines = [];
472
480
  if (status.presets) {
473
481
  const presets = status.presets;
@@ -477,6 +485,9 @@ export function autopilotLines(status) {
477
485
  if (floors.length)
478
486
  lines.push(`Team floors: ${floors.join(" · ")}${status.floorReason ? ` (${sanitize(status.floorReason)})` : ""}`);
479
487
  lines.push(...(status.exceptions ?? []));
488
+ const rules = ruleLink(webOrigin);
489
+ if (rules)
490
+ lines.push(`Change your rules: ${rules}`);
480
491
  }
481
492
  const { cache } = status;
482
493
  lines.push(cache.fetchedAt === null
@@ -109,6 +109,19 @@ export type AutopilotPolicy = {
109
109
  /** The label came from the connected app, not from a link file. */
110
110
  confirmed?: boolean;
111
111
  }>;
112
+ /** Known project scripts (Batch A item 5), vendor `project`: they set class
113
+ * and environment only, never an allow. */
114
+ project?: {
115
+ actions: Array<{
116
+ id: string;
117
+ repo?: string;
118
+ program: string;
119
+ args: string;
120
+ environment: EnvKind;
121
+ actionClass: ActionClass;
122
+ contentHash?: string;
123
+ }>;
124
+ };
112
125
  };
113
126
  /** The platform a vendor CLI acts on, so its rules and environments line up
114
127
  * with the same platform's MCP app (server `cliPlatform`). */
package/dist/cliExec.js CHANGED
@@ -121,12 +121,12 @@ export function checkedCredential(vendor, raw) {
121
121
  const allowed = new Set(EXEC_ENV_NAMES[vendor]);
122
122
  const env = raw && typeof raw === "object" && !Array.isArray(raw) ? raw : null;
123
123
  if (!env || !Object.keys(env).length) {
124
- return failure("Passport returned no credential for this command. Nothing ran.", 1, "invalid_server_response");
124
+ return failure("Passport returned no key for this command. Nothing ran.", 1, "invalid_server_response");
125
125
  }
126
126
  const out = {};
127
127
  for (const [name, entry] of Object.entries(env)) {
128
128
  if (!allowed.has(name) || typeof entry !== "string" || !entry || entry.length > 8192 || /[\0\r\n]/.test(entry)) {
129
- return failure("Passport returned a credential this CLI can't use. Nothing ran.", 1, "invalid_server_response");
129
+ return failure("Passport returned a key this CLI can't use. Nothing ran.", 1, "invalid_server_response");
130
130
  }
131
131
  out[name] = entry;
132
132
  }
@@ -276,7 +276,7 @@ function prepare(args, runtime, deps, auth) {
276
276
  }
277
277
  const declared = value(args, "client");
278
278
  if (declared !== undefined && !RUNTIME.test(declared))
279
- return failure("--client must be an agent name.", 6, "usage");
279
+ return failure("--agent must be an agent name.", 6, "usage");
280
280
  const waitSeconds = waitSecondsFor(args, runtime, deps);
281
281
  const policy = auth.kind === "profile" ? readCliPolicy(auth.profile) : null;
282
282
  const rest = args.positionals.slice(1);
@@ -11,7 +11,9 @@ import { type GuardClient, type GuardClientReport, type GuardHealthReport, type
11
11
  import type { Env } from "./cliSupport.js";
12
12
  export declare const GUARD_HEALTH_PATH = "/api/my/guard-health";
13
13
  type ApiCall = (path: string, init: RequestInit) => Promise<Response>;
14
- /** Managed settings hold Passport's guard for this agent. */
14
+ /** Managed settings hold Passport's guard for this agent: one reader for
15
+ * guard health and the hooks' stand-down (`managedHooks.ts`, which
16
+ * `passport setup --org --lock` writes for). */
15
17
  export declare function managedGuard(client: GuardClient, env: Env): boolean;
16
18
  /** Each agent on this computer, as the report sends it. */
17
19
  export declare function guardClientReports(env: Env): Promise<GuardClientReport[]>;
@@ -7,58 +7,21 @@
7
7
  * Sent from a guard run that has 300 ms of its budget left, from
8
8
  * `passport exec`, and from `passport status`.
9
9
  */
10
- import { closeSync, constants, mkdirSync, openSync, readdirSync, readFileSync, statSync, utimesSync } from "node:fs";
10
+ import { closeSync, constants, mkdirSync, openSync, readFileSync, statSync, utimesSync } from "node:fs";
11
11
  import { join } from "node:path";
12
12
  import { readBoundedJson } from "./boundedResponse.js";
13
13
  import { codexGuardTrust } from "./cliCodexTrust.js";
14
+ import { managedPassportHook } from "./managedHooks.js";
14
15
  import { GUARD_CLIENTS, GUARD_HEARTBEAT_MS } from "./cliGuardState.js";
15
16
  import { credentialDir, ensurePrivateDirectory } from "./credentialStorage.js";
16
17
  import { assertProfileName } from "./credentials.js";
17
18
  import { VERSION } from "./version.js";
18
19
  export const GUARD_HEALTH_PATH = "/api/my/guard-health";
19
- const MANAGED_MAX_BYTES = 1024 * 1024;
20
- const PASSPORT_GUARD = /passport[^\s"']*["']?\s+hook\s+guard\b/i;
21
- /** Managed settings the person can't turn off, per agent. Tests point
22
- * PASSPORT_MANAGED_ROOT at a sandbox; otherwise they are the system's own. */
23
- function managedPaths(client, env) {
24
- const root = env.PASSPORT_MANAGED_ROOT?.trim() || "/";
25
- const at = (...parts) => join(root, ...parts);
26
- if (client === "claude-code") {
27
- const dirs = [at("Library", "Application Support", "ClaudeCode"), at("etc", "claude-code")];
28
- return dirs.flatMap((dir) => [join(dir, "managed-settings.json"), ...listJson(join(dir, "managed-settings.d"))]);
29
- }
30
- if (client === "codex") {
31
- return [
32
- at("etc", "codex", "requirements.toml"),
33
- at("Library", "Application Support", "Codex", "requirements.toml")
34
- ];
35
- }
36
- return [at("Library", "Application Support", "Cursor", "hooks.json"), at("etc", "cursor", "hooks.json")];
37
- }
38
- function listJson(dir) {
39
- try {
40
- return readdirSync(dir)
41
- .filter((name) => name.endsWith(".json"))
42
- .slice(0, 20)
43
- .map((name) => join(dir, name));
44
- }
45
- catch {
46
- return [];
47
- }
48
- }
49
- /** Managed settings hold Passport's guard for this agent. */
20
+ /** Managed settings hold Passport's guard for this agent: one reader for
21
+ * guard health and the hooks' stand-down (`managedHooks.ts`, which
22
+ * `passport setup --org --lock` writes for). */
50
23
  export function managedGuard(client, env) {
51
- for (const path of managedPaths(client, env)) {
52
- try {
53
- const raw = readFileSync(path, "utf8");
54
- if (Buffer.byteLength(raw) <= MANAGED_MAX_BYTES && PASSPORT_GUARD.test(raw))
55
- return true;
56
- }
57
- catch {
58
- /* Not there, or not readable: not locked by this file. */
59
- }
60
- }
61
- return false;
24
+ return managedPassportHook(client, env);
62
25
  }
63
26
  const MODES = {
64
27
  "audit + guard": "audit+guard",
package/dist/cliHook.d.ts CHANGED
@@ -21,6 +21,7 @@ import { type HookInput } from "./cliHookInput.js";
21
21
  import { type CliHookReport, type HookDependencies, type HookRuntime } from "./cliHookDeliver.js";
22
22
  export { HOOK_BUDGET_MS, HOOK_RUNTIMES, legacyReport, type CliHookReport, type HookDependencies, type HookRuntime, type ReportedFinding } from "./cliHookDeliver.js";
23
23
  export { opaqueKind, opaqueProgram } from "./cliHookOpaque.js";
24
+ import { type ScriptReader } from "./cliScriptRead.js";
24
25
  import type { CommandResult, Env, Runtime } from "./cliSupport.js";
25
26
  export type { HookInput };
26
27
  /** One shell command, whichever agent format it arrived in. */
@@ -47,7 +48,7 @@ export declare function outcomeOf(response: unknown): {
47
48
  exitCode?: number;
48
49
  durationMs?: number;
49
50
  };
50
- export declare function buildReport(input: HookInput, findings: CliFinding[], env: Env, declared?: string, decided?: DecidedFinding[], local?: boolean): CliHookReport | null;
51
+ export declare function buildReport(input: HookInput, findings: CliFinding[], env: Env, declared?: string, decided?: DecidedFinding[], local?: boolean, scripts?: ScriptReader): CliHookReport | null;
51
52
  /** What the guard answered, and for which findings. The audit row that
52
53
  * follows a command that ran carries its outcome and any opaque parts. */
53
54
  export declare function buildDecisionReport(input: HookInput, decision: GuardDecision, env: Env, declared?: string, local?: boolean): CliHookReport | null;
package/dist/cliHook.js CHANGED
@@ -28,6 +28,8 @@ import { opaqueParts } from "./cliHookOpaque.js";
28
28
  export { opaqueKind, opaqueProgram } from "./cliHookOpaque.js";
29
29
  import { hasExpired, holdAsk, takeAsk } from "./cliHookPending.js";
30
30
  import { readCliPolicy } from "./cliPolicy.js";
31
+ import { saveScriptCache, scriptReader, scriptReport } from "./cliScriptRead.js";
32
+ import { standDownForManaged } from "./managedHooks.js";
31
33
  const MAX_FINDINGS = 8;
32
34
  const MAX_OPAQUE_KINDS = 6;
33
35
  const SHELL_TOOLS = new Set(["Bash", "bash", "shell", "Shell"]);
@@ -141,7 +143,10 @@ function reportable(findings, decided = [], local = false) {
141
143
  verb: safeVerb(finding.verb),
142
144
  risk: finding.risk,
143
145
  ...(entry?.reported ? { environment: entry.reported } : {}),
144
- ...entry?.placement
146
+ ...entry?.placement,
147
+ // Read from a project script: its name, never its contents (item 6).
148
+ ...(finding.from ? { from: finding.from } : {}),
149
+ ...(finding.project && !finding.project.repoFile ? { projectAction: finding.project.id } : {})
145
150
  };
146
151
  });
147
152
  }
@@ -149,12 +154,14 @@ function reportable(findings, decided = [], local = false) {
149
154
  function autopilotDecision(decision) {
150
155
  return decision?.cause ? { decision: decision.verdict } : {};
151
156
  }
152
- export function buildReport(input, findings, env, declared, decided = [], local = false) {
157
+ export function buildReport(input, findings, env, declared, decided = [], local = false, scripts) {
153
158
  const summary = summarize(findings);
154
- if (!summary.governed.length && !summary.opaque)
159
+ const extra = scriptReport(scripts);
160
+ // A script that changed under a project action is worth a row of its own.
161
+ if (!summary.governed.length && !summary.opaque && !extra.projectChanged && !extra.drift)
155
162
  return null;
156
163
  const governed = reportable(summary.governed, decided, local);
157
- if (!governed.length && !summary.opaque)
164
+ if (!governed.length && !summary.opaque && !extra.projectChanged && !extra.drift)
158
165
  return null;
159
166
  const { kinds, programs } = opaqueParts(summary.unknown, MAX_OPAQUE_KINDS);
160
167
  return {
@@ -163,9 +170,14 @@ export function buildReport(input, findings, env, declared, decided = [], local
163
170
  findings: governed,
164
171
  opaque: summary.opaque,
165
172
  ...(summary.opaque && kinds.length ? { opaqueKinds: kinds } : {}),
166
- ...(summary.opaque && programs.length ? { opaquePrograms: programs } : {})
173
+ ...(summary.opaque && programs.length ? { opaquePrograms: programs } : {}),
174
+ ...extra
167
175
  };
168
176
  }
177
+ /** The project scripts this policy knows, for the script reader. */
178
+ function projectContext(policy) {
179
+ return policy?.version === 2 ? (policy.autopilot.project ?? null) : null;
180
+ }
169
181
  /** What the guard answered, and for which findings. The audit row that
170
182
  * follows a command that ran carries its outcome and any opaque parts. */
171
183
  export function buildDecisionReport(input, decision, env, declared, local = false) {
@@ -238,6 +250,25 @@ async function cursorHasOwnEntry(runtime, kind) {
238
250
  return false;
239
251
  }
240
252
  }
253
+ /**
254
+ * Locked hooks (item 4): when managed settings run Passport's guard for this
255
+ * agent, the copy in the person's own settings (or the plugin) stands down,
256
+ * so nothing is decided or recorded twice. The managed one runs through the
257
+ * root-owned launcher, which sets `PASSPORT_HOOK_VIA=managed`.
258
+ */
259
+ function managedElsewhere(input, args, runtime) {
260
+ const agent = detectRuntime(input, runtime.env, value(args, "client"));
261
+ if (agent !== "claude-code" && agent !== "codex" && agent !== "cursor")
262
+ return false;
263
+ return standDownForManaged(agent, runtime.env);
264
+ }
265
+ /** This hook's shell event, unless it's for the other phase or managed settings run it. */
266
+ function hookEvent(input, phase, args, runtime) {
267
+ const event = shellEvent(input);
268
+ if (!event || event.phase !== phase)
269
+ return null;
270
+ return managedElsewhere(input, args, runtime) ? null : event;
271
+ }
241
272
  /** `passport exec` records its own action, with its decision and credential. */
242
273
  function isPassportExec(command) {
243
274
  return /^\s*(?:\S*\/)?passport\s+exec\b/.test(command) || /^\s*'[^']*'\s+'[^']*'\s+exec\b/.test(command);
@@ -249,25 +280,29 @@ async function runAudit(args, runtime, deps) {
249
280
  const input = await readInput(runtime, budget);
250
281
  if (!input)
251
282
  return;
252
- const event = shellEvent(input);
253
283
  // A PreToolUse event gets no opinion from the audit hook: that is the guard's job.
254
- if (!event || event.phase !== "post")
284
+ const event = hookEvent(input, "post", args, runtime);
285
+ if (!event)
255
286
  return;
256
287
  if (isPassportExec(event.command))
257
288
  return;
258
289
  if (event.cursorImported && (await cursorHasOwnEntry(runtime, "audit")))
259
290
  return;
260
- const machine = localMachine(workingFolder(input), runtime.env);
261
- const line = classifyLine(event.command, machine);
262
- const findings = line.findings;
263
291
  const profile = localProfile(args, runtime.env);
264
292
  const policy = profile ? readCliPolicy(profile) : null;
293
+ // The post-hook reads the same scripts again: a change since the guard's
294
+ // check is drift (item 6).
295
+ const scripts = scriptReader({ phase: "post", project: projectContext(policy) });
296
+ const machine = { ...localMachine(workingFolder(input), runtime.env), scripts };
297
+ const line = classifyLine(event.command, machine);
298
+ const findings = line.findings;
299
+ saveScriptCache(scripts);
265
300
  // v2: the same decision the guard made, so the row says why it ran.
266
301
  const decision = policy?.version === 2
267
302
  ? decideGuard(findings, policy, event.command, line.complete, guardMachineOf(machine, workingFolder(input), runtime.env))
268
303
  : null;
269
304
  const local = policy?.version === 2 && policy.autopilot.localCommands === true;
270
- let report = buildReport(input, findings, runtime.env, value(args, "client"), decision?.decided, local);
305
+ let report = buildReport(input, findings, runtime.env, value(args, "client"), decision?.decided, local, scripts);
271
306
  if (report && policy?.version === 2) {
272
307
  report = { ...report, ...autopilotDecision(decision) };
273
308
  }
@@ -399,14 +434,16 @@ async function runGuard(args, runtime, deps) {
399
434
  const input = await readInput(runtime, budget);
400
435
  if (!input || budget.aborted)
401
436
  return;
402
- const event = shellEvent(input);
403
- if (!event || event.phase !== "pre")
437
+ const event = hookEvent(input, "pre", args, runtime);
438
+ if (!event)
404
439
  return;
405
440
  const readAt = clock();
406
441
  // Decide from local data first. Only an unattended ask may ask the server.
407
442
  const { profile, byDefault } = localSelection(args, runtime.env);
408
443
  const policy = profile ? readCliPolicy(profile) : null;
409
- const machine = localMachine(workingFolder(input), runtime.env);
444
+ // The project's own scripts are read inside the budget (item 6).
445
+ const scripts = scriptReader({ phase: "pre", project: projectContext(policy) });
446
+ const machine = { ...localMachine(workingFolder(input), runtime.env), scripts };
410
447
  const line = classifyLine(event.command, machine);
411
448
  const decision = decideGuard(line.findings, policy, event.command, line.complete, guardMachineOf(machine, workingFolder(input), runtime.env));
412
449
  const local = policy?.version === 2 && policy.autopilot.localCommands === true;
@@ -443,6 +480,7 @@ async function runGuard(args, runtime, deps) {
443
480
  });
444
481
  if (plan.output)
445
482
  runtime.stdout.write(`${JSON.stringify(plan.output)}\n`);
483
+ saveScriptCache(scripts);
446
484
  const runtimeName = detectRuntime(input, runtime.env, declared);
447
485
  // Coverage: count what the guard saw, once even when Cursor runs both copies.
448
486
  await (await import("./cliHookExtras.js")).countSeen(profile, runtimeName, line.findings, clock(), () => event.cursorImported ? cursorHasOwnEntry(runtime, "guard") : Promise.resolve(false));
@@ -39,6 +39,18 @@ export type CliFinding = {
39
39
  cwd: string | null;
40
40
  prefix?: Record<string, string>;
41
41
  };
42
+ /** Read from the project's own script (`cliScriptRead.ts`): its name as a
43
+ * person knows it, "deploy.sh" or "make deploy". Reported as provenance. */
44
+ from?: string;
45
+ /** A known project script (item 5): the server's project action that
46
+ * classifies it. It sets class and environment only; it never allows. */
47
+ project?: {
48
+ id: string;
49
+ actionClass: LocalFacts["actionClass"];
50
+ environment: LocalFacts["environment"];
51
+ /** From the repository's `.passport/actions.toml`: it can only make things stricter. */
52
+ repoFile?: true;
53
+ };
42
54
  };
43
55
  /** What an everyday command does, worked out on this machine. */
44
56
  export type LocalFacts = {
@@ -42,6 +42,18 @@ export type CliHookReport = {
42
42
  batch: string;
43
43
  clients: unknown[];
44
44
  };
45
+ /** Project scripts in this command (item 6): how many parts were fully and
46
+ * partly checked. Counts only. */
47
+ scripts?: {
48
+ checked: number;
49
+ partly: number;
50
+ };
51
+ /** Keyed hashes of the partly checked parts (item 5), never their names. */
52
+ opaqueIds?: string[];
53
+ /** Project actions whose script changed since they were set. Ids only. */
54
+ projectChanged?: string[];
55
+ /** A script changed between the guard's check and the run. */
56
+ drift?: true;
45
57
  /** Coverage: what the guard saw for this agent on one day (`cliSeen.ts`). Counts only. */
46
58
  seen?: {
47
59
  batch: string;
@@ -66,6 +78,10 @@ export type ReportedFinding = {
66
78
  platform?: string;
67
79
  flag?: string;
68
80
  via?: string;
81
+ /** The project script it was read from: "deploy.sh", "make deploy". */
82
+ from?: string;
83
+ /** The project action that classified it. */
84
+ projectAction?: string;
69
85
  };
70
86
  export type HookDependencies = {
71
87
  /** Deliver one report. The default posts it to the signed-in workspace. */
@@ -48,11 +48,21 @@ export async function profileApi(profile, signal, fetcher) {
48
48
  export function legacyReport(report) {
49
49
  if (report.decision === "allow")
50
50
  return null;
51
- return { ...report, findings: report.findings.map(({ vendor, verb, risk }) => ({ vendor, verb, risk })) };
51
+ const { scripts: _scripts, opaqueIds: _ids, projectChanged: _changed, drift: _drift, ...rest } = report;
52
+ if (!rest.findings.length && !rest.opaque)
53
+ return null;
54
+ return { ...rest, findings: report.findings.map(({ vendor, verb, risk }) => ({ vendor, verb, risk })) };
52
55
  }
53
56
  function hasAutopilotFields(report) {
54
57
  return (report.decision === "allow" ||
55
- report.findings.some((finding) => finding.environment !== undefined || finding.kind !== undefined));
58
+ report.scripts !== undefined ||
59
+ report.opaqueIds !== undefined ||
60
+ report.projectChanged !== undefined ||
61
+ report.drift !== undefined ||
62
+ report.findings.some((finding) => finding.environment !== undefined ||
63
+ finding.kind !== undefined ||
64
+ finding.from !== undefined ||
65
+ finding.projectAction !== undefined));
56
66
  }
57
67
  async function postWith(api, report, signal) {
58
68
  const post = (body) => api(CLI_ACTIVITY_PATH, {
@@ -87,7 +87,7 @@ export declare function decideGuard(findings: CliFinding[], policy: CachedCliPol
87
87
  export declare function askMessage(decision: GuardDecision): string;
88
88
  export declare function denyMessage(decision: GuardDecision, owner?: string): string;
89
89
  export declare function allowReason(decision: GuardDecision): string;
90
- export declare const DENY_AGENT_MESSAGE = "Blocked by Passport safety settings. Ask the user to run this command themselves.";
90
+ export declare const DENY_AGENT_MESSAGE = "Blocked by your Passport rules. Ask the user to run this command themselves.";
91
91
  /** What the agent reads when an unattended ask became an approval request. */
92
92
  export declare function waitingMessage(approvalId: string, approver?: string): string;
93
93
  /** Appended when the server couldn't be reached and this machine decided. */
@@ -71,6 +71,9 @@ function policyDecision(policy, vendor, verb) {
71
71
  export function guardLabel(finding) {
72
72
  if (finding.local && finding.vendor === "redirect")
73
73
  return "> file";
74
+ // A known project script goes by the name the person gave it.
75
+ if (finding.project && finding.from)
76
+ return finding.from;
74
77
  const tokens = (finding.verbKey ?? finding.verb ?? "").split(/\s+/).filter((token) => LABEL_TOKEN.test(token));
75
78
  // An everyday command's place word ("rm -r home") is said by its message instead.
76
79
  if (finding.local && PLACE_WORDS.has(tokens.at(-1) ?? ""))
@@ -179,12 +182,37 @@ function decideLocal(finding, policy) {
179
182
  actionClass: facts.actionClass
180
183
  };
181
184
  }
185
+ /** A known project script (item 5): the project action sets its class and
186
+ * environment; presets, floors, and exceptions decide, as for any command. A
187
+ * repository's own `.passport/actions.toml` may only ask or block. */
188
+ function decideProject(finding, policy) {
189
+ const facts = finding.project;
190
+ const { decision, cause } = decideAction(policy.autopilot, {
191
+ vendor: "project",
192
+ verb: finding.verb,
193
+ actionClass: facts.actionClass,
194
+ environment: facts.environment
195
+ });
196
+ if (facts.repoFile && decision === "allow")
197
+ return null;
198
+ return {
199
+ finding,
200
+ decision,
201
+ cause,
202
+ environment: facts.environment,
203
+ environmentSource: "mapping",
204
+ reported: facts.environment,
205
+ actionClass: facts.actionClass
206
+ };
207
+ }
182
208
  /** One recognized command's decision, or null when Autopilot has no opinion. */
183
209
  export function decideFinding(finding, policy, machine) {
184
210
  if (!decidable(finding))
185
211
  return null;
186
212
  if (finding.local)
187
213
  return decideLocal(finding, policy);
214
+ if (finding.project)
215
+ return decideProject(finding, policy);
188
216
  // SQL is read from a regex; only a destructive statement gets an opinion.
189
217
  if (finding.vendor === "psql" ? finding.risk !== "destructive" : !CLASS_OF_RISK[finding.risk])
190
218
  return null;
@@ -300,6 +328,18 @@ const EFFECT = {
300
328
  * (" (linked in this folder)") or a sentence at the end (" Environment
301
329
  * unknown, treated as Production."). */
302
330
  function sourceNotes(decision) {
331
+ const deciding = decision.findings[0];
332
+ const notes = targetNotes(decision);
333
+ // Read from a project script: say which (item 6). A known script already says its name.
334
+ if (!deciding?.from || deciding.project)
335
+ return notes;
336
+ const aside = /^ \((.+)\)$/.exec(notes.aside);
337
+ return {
338
+ aside: aside ? ` (${aside[1]}, in ${deciding.from})` : `${notes.aside} (from ${deciding.from})`,
339
+ sentence: notes.sentence
340
+ };
341
+ }
342
+ function targetNotes(decision) {
303
343
  if (decision.target) {
304
344
  const note = targetNote(decision.target, decision.findings[0]?.vendor ?? "");
305
345
  if (!note)
@@ -315,12 +355,13 @@ function sourceNotes(decision) {
315
355
  function localAskMessage(decision, finding) {
316
356
  const facts = finding.local;
317
357
  const where = decision.environment ? envLabel(decision.environment) : "";
358
+ const from = finding.from ? ` (from ${finding.from})` : "";
318
359
  if (facts.sudo && decision.cause?.kind === "default") {
319
- return `Passport: ${decision.label} runs as administrator, so Passport asks. Approve to run it.`;
360
+ return `Passport: ${decision.label}${from} runs as administrator, so Passport asks. Approve to run it.`;
320
361
  }
321
362
  const deletes = DELETING.test(`${finding.vendor} ${finding.verb}`);
322
363
  if (decision.actionClass === "irreversible") {
323
- return `Passport: ${decision.label} ${deletes ? "deletes" : "changes"} ${facts.touches} and can't be undone. Approve to run it.`;
364
+ return `Passport: ${decision.label}${from} ${deletes ? "deletes" : "changes"} ${facts.touches} and can't be undone. Approve to run it.`;
324
365
  }
325
366
  const verb = decision.actionClass === "read"
326
367
  ? "reads"
@@ -332,7 +373,7 @@ function localAskMessage(decision, finding) {
332
373
  const because = decision.cause && decision.cause.kind !== "preset" && decision.cause.kind !== "default"
333
374
  ? ` ${decision.cause.label}.`
334
375
  : "";
335
- return `Passport: ${decision.label} ${verb} ${facts.touches} (${where}).${because} Approve to run it.`;
376
+ return `Passport: ${decision.label}${from} ${verb} ${facts.touches} (${where}).${because} Approve to run it.`;
336
377
  }
337
378
  export function askMessage(decision) {
338
379
  if (decision.deciding?.local && decision.cause)
@@ -350,7 +391,7 @@ export function askMessage(decision) {
350
391
  }
351
392
  return decision.destructive
352
393
  ? `Passport: ${decision.label} is destructive. Run it only if you meant to.`
353
- : `Passport: your safety settings ask before ${decision.label}. Run it only if you meant to.`;
394
+ : `Passport: your Autopilot rules ask before ${decision.label}. Run it only if you meant to.`;
354
395
  }
355
396
  export function denyMessage(decision, owner) {
356
397
  if (decision.cause) {
@@ -358,16 +399,18 @@ export function denyMessage(decision, owner) {
358
399
  const next = mine
359
400
  ? "Change it in Passport Rules."
360
401
  : `${owner ? `Ask ${owner} to run it` : "Ask an admin to run it"}, or request an exception in Passport.`;
361
- return `Blocked by Passport: ${decision.cause.label}. ${next}`;
402
+ const deciding = decision.findings[0];
403
+ const from = deciding?.from && !deciding.project ? ` (${decision.label}, from ${deciding.from})` : "";
404
+ return `Blocked by Passport: ${decision.cause.label}${from}. ${next}`;
362
405
  }
363
- return `Passport: your safety settings block ${decision.label}. Change this in Passport Settings → Safety.`;
406
+ return `Passport: your Autopilot rules block ${decision.label}. Change this in Passport › Rules.`;
364
407
  }
365
408
  export function allowReason(decision) {
366
409
  const note = decision.target ? targetNote(decision.target, decision.findings[0]?.vendor ?? "") : "";
367
410
  const how = note.startsWith("(") ? ` ${note}` : "";
368
411
  return `Passport: ${decision.cause?.label ?? "allowed by your rules"}${how}.`;
369
412
  }
370
- export const DENY_AGENT_MESSAGE = "Blocked by Passport safety settings. Ask the user to run this command themselves.";
413
+ export const DENY_AGENT_MESSAGE = "Blocked by your Passport rules. Ask the user to run this command themselves.";
371
414
  /** What the agent reads when an unattended ask became an approval request. */
372
415
  export function waitingMessage(approvalId, approver) {
373
416
  return `Waiting for approval from ${approver ?? "your approver"}. Run \`passport wait ${approvalId}\` to wait, or continue with other work.`;
@@ -511,7 +511,7 @@ export function hookRegistration(action, client, args, runtime) {
511
511
  }
512
512
  const chosen = client ?? "claude-code";
513
513
  if (!HOOK_CLIENTS.includes(chosen)) {
514
- return failure("Choose --client claude-code, --client codex, or --client cursor.", 6, "usage");
514
+ return failure("Choose --agent claude-code, --agent codex, or --agent cursor.", 6, "usage");
515
515
  }
516
516
  const spec = CLIENTS[chosen];
517
517
  return action === "install" ? installClient(spec, args, runtime) : uninstallClient(spec, args, runtime);
@@ -15,6 +15,7 @@
15
15
  * applies. Asks and blocks still come from whatever parts were understood.
16
16
  */
17
17
  import { type CliFinding } from "./cliHookClassify.js";
18
+ import { type FileStat, type ScriptFile, type ScriptReader } from "./cliScriptRead.js";
18
19
  import type { DecidedFinding } from "./cliHookGuard.js";
19
20
  import { type LocalAction, type Place, type ShellWord } from "./localCommands.js";
20
21
  /** What the hook can read from the machine. Injected so tests never touch it. */
@@ -25,6 +26,9 @@ export type LocalFs = {
25
26
  readText(path: string): string | null;
26
27
  isDirectory(path: string): boolean;
27
28
  isFile(path: string): boolean;
29
+ /** A script up to 256 KB with its time and size (script reading), or null. */
30
+ readScript?(path: string): ScriptFile | null;
31
+ statFile?(path: string): FileStat | null;
28
32
  };
29
33
  export type LocalMachine = {
30
34
  /** The folder the agent's command starts in, canonical; null when unknown. */
@@ -40,6 +44,8 @@ export type LocalMachine = {
40
44
  * Cursor worktrees). A project inside one is a project, not agent settings. */
41
45
  worktrees?: string[];
42
46
  fs: LocalFs;
47
+ /** Read the project's own scripts (`cliScriptRead.ts`). Absent: scripts stay unread. */
48
+ scripts?: ScriptReader;
43
49
  };
44
50
  export declare const NODE_FS: LocalFs;
45
51
  /** Canonical form of a path that may not exist yet: resolve the deepest