passport-bridge 0.24.0 → 0.26.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.
Files changed (97) hide show
  1. package/README.md +72 -31
  2. package/dist/approvalNotice.d.ts +73 -0
  3. package/dist/approvalNotice.js +211 -0
  4. package/dist/cliArgs.d.ts +1 -1
  5. package/dist/cliArgs.js +17 -6
  6. package/dist/cliAutopilot.js +15 -4
  7. package/dist/cliAutopilotPolicy.d.ts +8 -0
  8. package/dist/cliAutopilotPolicy.js +23 -1
  9. package/dist/cliChanges.d.ts +80 -0
  10. package/dist/cliChanges.js +340 -0
  11. package/dist/cliClient.d.ts +5 -0
  12. package/dist/cliClient.js +15 -3
  13. package/dist/cliExec.js +2 -2
  14. package/dist/cliHook.d.ts +1 -1
  15. package/dist/cliHook.js +40 -35
  16. package/dist/cliHookAudit.d.ts +44 -0
  17. package/dist/cliHookAudit.js +57 -0
  18. package/dist/cliHookClients.d.ts +3 -1
  19. package/dist/cliHookClients.js +1 -1
  20. package/dist/cliHookDecide.js +3 -1
  21. package/dist/cliHookDeliver.d.ts +8 -0
  22. package/dist/cliHookDeliver.js +25 -0
  23. package/dist/cliHookGuard.d.ts +16 -1
  24. package/dist/cliHookGuard.js +31 -10
  25. package/dist/cliHookInput.d.ts +3 -0
  26. package/dist/cliHookInput.js +13 -0
  27. package/dist/cliHookLocal.d.ts +3 -2
  28. package/dist/cliHookLocal.js +5 -2
  29. package/dist/cliHookNotice.d.ts +22 -0
  30. package/dist/cliHookNotice.js +49 -0
  31. package/dist/cliHookRewrite.d.ts +2 -0
  32. package/dist/cliHookRewrite.js +1 -1
  33. package/dist/cliKeys.js +11 -1
  34. package/dist/cliKeysRotate.d.ts +24 -0
  35. package/dist/cliKeysRotate.js +149 -0
  36. package/dist/cliMain.js +56 -15
  37. package/dist/cliOutput.js +41 -5
  38. package/dist/cliPolicyV2.js +14 -0
  39. package/dist/cliProjectSummary.d.ts +9 -0
  40. package/dist/cliProjectSummary.js +134 -0
  41. package/dist/cliProtocol.d.ts +10 -0
  42. package/dist/cliProtocol.js +15 -0
  43. package/dist/cliRequest.d.ts +27 -0
  44. package/dist/cliRequest.js +92 -0
  45. package/dist/cliRestoreRequests.d.ts +57 -0
  46. package/dist/cliRestoreRequests.js +186 -0
  47. package/dist/cliSessions.d.ts +3 -0
  48. package/dist/cliSessions.js +24 -1
  49. package/dist/cliSessionsJson.d.ts +48 -2
  50. package/dist/cliSessionsJson.js +7 -9
  51. package/dist/cliSessionsRender.d.ts +8 -3
  52. package/dist/cliSessionsRender.js +16 -7
  53. package/dist/cliUndo.d.ts +1 -3
  54. package/dist/cliUndo.js +9 -15
  55. package/dist/cliUndoLocal.d.ts +27 -0
  56. package/dist/cliUndoLocal.js +105 -0
  57. package/dist/cliUpdate.d.ts +29 -0
  58. package/dist/cliUpdate.js +195 -0
  59. package/dist/cliWait.js +2 -2
  60. package/dist/completion.js +6 -1
  61. package/dist/doctor.js +4 -0
  62. package/dist/execNoKey.d.ts +4 -4
  63. package/dist/execNoKey.js +17 -11
  64. package/dist/gitBackup.d.ts +111 -0
  65. package/dist/gitBackup.js +391 -0
  66. package/dist/gitSnapshot.d.ts +82 -0
  67. package/dist/gitSnapshot.js +478 -0
  68. package/dist/holdNotice.js +7 -1
  69. package/dist/hookMain.js +10 -1
  70. package/dist/hookPromptFast.d.ts +26 -0
  71. package/dist/hookPromptFast.js +82 -0
  72. package/dist/initInstall.d.ts +22 -0
  73. package/dist/initInstall.js +70 -1
  74. package/dist/localBackups.d.ts +102 -0
  75. package/dist/localBackups.js +233 -0
  76. package/dist/localGit.d.ts +24 -0
  77. package/dist/localGit.js +44 -0
  78. package/dist/localRestore.d.ts +42 -0
  79. package/dist/localRestore.js +94 -0
  80. package/dist/localTrash.d.ts +97 -0
  81. package/dist/localTrash.js +394 -0
  82. package/dist/pluginPin.d.ts +1 -1
  83. package/dist/pluginPin.js +1 -1
  84. package/dist/plural.d.ts +2 -0
  85. package/dist/plural.js +13 -0
  86. package/dist/regenerable.d.ts +24 -0
  87. package/dist/regenerable.js +219 -0
  88. package/dist/selfUpdate.d.ts +92 -0
  89. package/dist/selfUpdate.js +361 -0
  90. package/dist/selfUpdateContract.d.ts +20 -0
  91. package/dist/selfUpdateContract.js +56 -0
  92. package/dist/updateTrigger.d.ts +18 -0
  93. package/dist/updateTrigger.js +77 -0
  94. package/dist/version.d.ts +1 -1
  95. package/dist/version.js +1 -1
  96. package/npm-shrinkwrap.json +2 -2
  97. package/package.json +1 -1
@@ -0,0 +1,44 @@
1
+ /**
2
+ * The audit hook's pieces for local backups and the decision it records:
3
+ * which command a row stands for (an rm the guard sent to its trash is the
4
+ * agent's own rm, with the backup's id), what the guard backed up before it,
5
+ * and the same decision the guard made.
6
+ */
7
+ import type { CliFinding } from "./cliHookClassify.js";
8
+ import type { CliHookReport } from "./cliHookDeliver.js";
9
+ import { decideEach, type DecidedFinding, type GuardDecision } from "./cliHookGuard.js";
10
+ import type { CachedCliPolicy } from "./cliPolicy.js";
11
+ import type { BackupKey } from "./gitBackup.js";
12
+ /** `passport exec` records its own action, with its decision and credential. */
13
+ export declare function isPassportExec(command: string): boolean;
14
+ /**
15
+ * The command the audit hook records, or null for a rewrite that records its
16
+ * own action (`passport exec`). An rm the guard sent to its trash is recorded
17
+ * as the agent's own rm, with the backup's id.
18
+ */
19
+ export declare function auditedCommand(command: string): {
20
+ command: string;
21
+ trashed?: {
22
+ key: string;
23
+ };
24
+ } | null;
25
+ /**
26
+ * What the guard backed up before this exact command (for the decision), and
27
+ * the findings whose row is where an Undo lives: real backups, not folders a
28
+ * build makes again.
29
+ */
30
+ export declare function auditBackups(findings: CliFinding[], key: BackupKey, trashed: boolean): {
31
+ taken: {
32
+ backups: Set<CliFinding>;
33
+ regenerable: Set<CliFinding>;
34
+ };
35
+ backedUp: Set<CliFinding>;
36
+ };
37
+ /** v2: the same decision the guard made, and where each command landed even without one. */
38
+ export declare function auditDecision(findings: CliFinding[], policy: CachedCliPolicy | null, command: string, complete: boolean, guardAt: Parameters<typeof decideEach>[2]): {
39
+ decision: GuardDecision | null;
40
+ local: boolean;
41
+ decided?: DecidedFinding[];
42
+ };
43
+ /** The rm went to Passport's trash: its row says the backup was taken, and where. */
44
+ export declare function markTrashed(report: CliHookReport, key: string): CliHookReport;
@@ -0,0 +1,57 @@
1
+ /**
2
+ * The audit hook's pieces for local backups and the decision it records:
3
+ * which command a row stands for (an rm the guard sent to its trash is the
4
+ * agent's own rm, with the backup's id), what the guard backed up before it,
5
+ * and the same decision the guard made.
6
+ */
7
+ import { decideEach, decideGuard } from "./cliHookGuard.js";
8
+ import { takenLocalBackups } from "./localBackups.js";
9
+ import { trashedLine } from "./localTrash.js";
10
+ /** `passport exec` records its own action, with its decision and credential. */
11
+ export function isPassportExec(command) {
12
+ // The guard's own rewrites: passport exec, and rm through the trash.
13
+ return /^\s*(?:\S*\/)?passport\s+(?:exec\b|hook trash --)|^\s*'[^']*'\s+'[^']*'\s+(?:exec\b|hook trash --)/.test(command);
14
+ }
15
+ /**
16
+ * The command the audit hook records, or null for a rewrite that records its
17
+ * own action (`passport exec`). An rm the guard sent to its trash is recorded
18
+ * as the agent's own rm, with the backup's id.
19
+ */
20
+ export function auditedCommand(command) {
21
+ const trashed = trashedLine(command);
22
+ if (trashed)
23
+ return { command: trashed.command, trashed: { key: trashed.key } };
24
+ return isPassportExec(command) ? null : { command };
25
+ }
26
+ /**
27
+ * What the guard backed up before this exact command (for the decision), and
28
+ * the findings whose row is where an Undo lives: real backups, not folders a
29
+ * build makes again.
30
+ */
31
+ export function auditBackups(findings, key, trashed) {
32
+ const taken = takenLocalBackups(findings, key);
33
+ if (trashed)
34
+ for (const finding of findings)
35
+ if (finding.vendor === "rm")
36
+ taken.backups.add(finding);
37
+ const backedUp = new Set([...taken.backups].filter((finding) => !taken.regenerable.has(finding)));
38
+ return { taken, backedUp };
39
+ }
40
+ /** v2: the same decision the guard made, and where each command landed even without one. */
41
+ export function auditDecision(findings, policy, command, complete, guardAt) {
42
+ if (policy?.version !== 2)
43
+ return { decision: null, local: false };
44
+ const decision = decideGuard(findings, policy, command, complete, guardAt);
45
+ return {
46
+ decision,
47
+ local: policy.autopilot.localCommands === true,
48
+ decided: decision?.decided ?? decideEach(findings, policy, guardAt)
49
+ };
50
+ }
51
+ /** The rm went to Passport's trash: its row says the backup was taken, and where. */
52
+ export function markTrashed(report, key) {
53
+ return {
54
+ ...report,
55
+ findings: report.findings.map((finding) => finding.vendor === "rm" ? { ...finding, backup: "taken", backupId: key } : finding)
56
+ };
57
+ }
@@ -13,7 +13,9 @@ export type ClientSpec = {
13
13
  post: string;
14
14
  /** Where a command that failed or was interrupted is reported, if separate. */
15
15
  postFailure?: string;
16
- /** Session start and end events the audit entry also runs on (no matcher). */
16
+ /** Session events the audit entry also runs on (no matcher): start and
17
+ * end, and for Claude Code each prompt, which carries a late approval's
18
+ * notice into the conversation (`approvalNotice.ts`). */
17
19
  lifecycle?: string[];
18
20
  path(env: Env): string;
19
21
  };
@@ -29,7 +29,7 @@ export const CLIENTS = {
29
29
  // Claude Code reports an interrupted or failed tool call here instead of
30
30
  // PostToolUse, so an approved command that failed still counts as ran.
31
31
  postFailure: "PostToolUseFailure",
32
- lifecycle: ["SessionStart", "SessionEnd"],
32
+ lifecycle: ["SessionStart", "SessionEnd", "UserPromptSubmit"],
33
33
  path: claudeSettingsPath
34
34
  },
35
35
  codex: {
@@ -96,7 +96,9 @@ export function decideRequest(decision, context, command, local = false) {
96
96
  verb: safeVerbOf(entry.finding.verbKey ?? entry.finding.verb ?? unknownVerb(entry.finding.args)),
97
97
  risk: entry.finding.risk,
98
98
  ...(entry.reported ? { environment: entry.reported } : {}),
99
- ...entry.placement
99
+ ...entry.placement,
100
+ // Only to a server that asks without a backup (it sent `withoutBackup`).
101
+ ...(entry.backup ? { backup: entry.backup } : {})
100
102
  }));
101
103
  const summary = redactCommand(command);
102
104
  const key = commandKey(command);
@@ -99,6 +99,10 @@ export type ReportedFinding = {
99
99
  from?: string;
100
100
  /** The project action that classified it. */
101
101
  projectAction?: string;
102
+ /** The guard backed it up right before it ran, or it removed only regenerable folders. */
103
+ backup?: "taken" | "regenerable" | "partial";
104
+ /** A backup's id on this computer (`passport undo --local <id>`). */
105
+ backupId?: string;
102
106
  };
103
107
  export type HookDependencies = {
104
108
  /** Deliver one report. The default posts it to the signed-in workspace. */
@@ -134,6 +138,10 @@ export declare function legacyReport(report: CliHookReport): CliHookReport | nul
134
138
  /** The report a server from before session markers (bridge 0.23.0) accepts,
135
139
  * or null: a start marker alone has nothing it knows. */
136
140
  export declare function withoutSessionFacts(report: CliHookReport): CliHookReport | null;
141
+ /** The report a server from before local git backups accepts. */
142
+ export declare function withoutBackups(report: CliHookReport): CliHookReport;
143
+ /** The report a server from before one-tap undo accepts: the mark, without the backup's id. */
144
+ export declare function withoutBackupIds(report: CliHookReport): CliHookReport;
137
145
  /** The report a server from before project grouping accepts (bridge 0.21.0). */
138
146
  export declare function withoutProject(report: CliHookReport): CliHookReport;
139
147
  type Send = (report: CliHookReport) => Promise<void>;
@@ -63,6 +63,17 @@ export function withoutSessionFacts(report) {
63
63
  const { sessionStarted: _started, model: _model, attended: _attended, ...rest } = report;
64
64
  return rest.sessionEnded || rest.findings.length || rest.opaque ? rest : null;
65
65
  }
66
+ /** The report a server from before local git backups accepts. */
67
+ export function withoutBackups(report) {
68
+ return {
69
+ ...report,
70
+ findings: report.findings.map(({ backup: _backup, backupId: _backupId, ...finding }) => finding)
71
+ };
72
+ }
73
+ /** The report a server from before one-tap undo accepts: the mark, without the backup's id. */
74
+ export function withoutBackupIds(report) {
75
+ return { ...report, findings: report.findings.map(({ backupId: _backupId, ...finding }) => finding) };
76
+ }
66
77
  /** The report a server from before project grouping accepts (bridge 0.21.0). */
67
78
  export function withoutProject(report) {
68
79
  const { project: _project, branch: _branch, ...rest } = report;
@@ -96,6 +107,18 @@ async function postWith(api, initial, signal) {
96
107
  response = await post(report);
97
108
  await response.body?.cancel().catch(() => undefined);
98
109
  }
110
+ // A server from before one-tap undo refuses the backup's id: keep the mark.
111
+ if (response.status === 400 && report.findings.some((finding) => finding.backupId !== undefined)) {
112
+ report = withoutBackupIds(report);
113
+ response = await post(report);
114
+ await response.body?.cancel().catch(() => undefined);
115
+ }
116
+ // A server from before local git backups refuses the mark: the row matters more.
117
+ if (response.status === 400 && report.findings.some((finding) => finding.backup !== undefined)) {
118
+ report = withoutBackups(report);
119
+ response = await post(report);
120
+ await response.body?.cancel().catch(() => undefined);
121
+ }
99
122
  // A server from before session markers (bridge 0.23.0) refuses their facts.
100
123
  if (response.status === 400 && hasSessionFacts(report)) {
101
124
  const older = withoutSessionFacts(report);
@@ -253,6 +276,8 @@ export async function runFlush(args, runtime, deps) {
253
276
  deps
254
277
  });
255
278
  fast.refreshFastPath(profile, readCliPolicy(profile), byDefault, clock());
279
+ // A requested update installs from its own detached process, never here.
280
+ (await import("./updateTrigger.js")).maybeStartUpdateCheck(value(args, "profile"), runtime.env, clock());
256
281
  }
257
282
  finally {
258
283
  // Done: nothing it started (an aborted socket, a keep-alive pool) keeps it alive.
@@ -31,12 +31,17 @@ export type DecidedFinding = {
31
31
  /** What the server is told about the environment (a name or a kind). */
32
32
  reported?: string;
33
33
  actionClass: ActionClass;
34
+ /** A change its safety pack raises ("railway variables --set"): the rules
35
+ * decide it like a Delete, but it deletes nothing, so it reads as a change. */
36
+ treatedAs?: "delete";
34
37
  /** Where a vendor command lands and how Passport knows (Phase 4.5). */
35
38
  target?: EnvTarget;
36
39
  /** What the server is told about that, when it reads placements. */
37
40
  placement?: Record<string, string>;
38
41
  /** Blocked by the person's pass for the app this CLI acts on: what they read. */
39
42
  access?: AppAccessBlock;
43
+ /** A Delete, for a server that asks without a backup: whether it has one here. */
44
+ backup?: "taken" | "none" | "regenerable";
40
45
  };
41
46
  /** "You don't have access to Railway in Passport. Ask an admin." and the app's Access link. */
42
47
  export type AppAccessBlock = AccessBlock;
@@ -53,6 +58,8 @@ export type GuardDecision = {
53
58
  environment?: ActionEnv;
54
59
  environmentSource?: EnvSource;
55
60
  actionClass?: ActionClass;
61
+ /** v2: the deciding command is a change the rules decide like a Delete. */
62
+ treatedAs?: "delete";
56
63
  /** v2 only: every recognized command, in line order. */
57
64
  decided?: DecidedFinding[];
58
65
  /** The deciding finding, when it is an everyday command or a push. */
@@ -72,6 +79,10 @@ export type GuardMachine = {
72
79
  home: string;
73
80
  env: Record<string, string | undefined>;
74
81
  fs: LinkFs;
82
+ /** The findings that will have a local backup if they run (`localBackups.ts`). */
83
+ backups?: ReadonlySet<CliFinding>;
84
+ /** Of those, the ones with nothing to back up: they remove only regenerable folders. */
85
+ regenerable?: ReadonlySet<CliFinding>;
75
86
  };
76
87
  /** This machine for folder links: the command's folder (canonical, and as
77
88
  * the agent named it), the project, home, and the agent's shell. */
@@ -92,7 +103,11 @@ export declare function guardLabel(finding: CliFinding): string;
92
103
  export declare function classOf(policy: CachedCliPolicyV2, finding: CliFinding & {
93
104
  vendor: string;
94
105
  }, verb: string, environment: ActionEnv): ActionClass;
95
- /** One recognized command's decision, or null when Autopilot has no opinion. */
106
+ /**
107
+ * One recognized command's decision, or null when Autopilot has no opinion.
108
+ * A Delete says whether it will have a backup on this computer, for a server
109
+ * that asks before a Hands-off delete without one (it sends `withoutBackup`).
110
+ */
96
111
  export declare function decideFinding(finding: CliFinding, policy: CachedCliPolicyV2, machine?: GuardMachine): DecidedFinding | null;
97
112
  /**
98
113
  * Every simple command in the line is a vendor command the classifier read
@@ -13,7 +13,7 @@
13
13
  * With a v1 policy (an older server) or none at all, the guard keeps its old
14
14
  * shape: ask or deny, never allow.
15
15
  */
16
- import { CLASS_EFFECT, CLASS_EFFECT_OTHER, CLASS_OF_RISK as CLASS_OF_HOOK_RISK, causeSentence, decideAction, decisionRank, envLabel } from "./cliAutopilotPolicy.js";
16
+ import { CLASS_EFFECT, CLASS_EFFECT_OTHER, CLASS_OF_RISK as CLASS_OF_HOOK_RISK, causeSentence, decideAction, NO_BACKUP_CAUSE, decisionRank, envLabel } from "./cliAutopilotPolicy.js";
17
17
  import { reportedEnvironment } from "./cliHookEnvironment.js";
18
18
  import { placementOf, resolveTarget, targetNote } from "./envResolve.js";
19
19
  import { repositoryHint } from "./cliHookRepo.js";
@@ -157,15 +157,18 @@ export function classOf(policy, finding, verb, environment) {
157
157
  /** Commands run as administrator never run silently. */
158
158
  const SUDO_CAUSE = { kind: "default", label: "Commands run with sudo always ask" };
159
159
  /** An everyday command: its class and environment come from what it touches. */
160
- function decideLocal(finding, policy) {
160
+ function decideLocal(finding, policy, backup) {
161
161
  const facts = finding.local;
162
162
  const decided = decideAction(policy.autopilot, {
163
163
  vendor: finding.vendor,
164
164
  verb: finding.verb,
165
165
  actionClass: facts.actionClass,
166
- environment: facts.environment
166
+ environment: facts.environment,
167
+ backup
167
168
  });
168
- const sudo = facts.sudo && decided.decision === "allow" && decided.cause.kind !== "rule";
169
+ // The server asks for sudo before the backup rule, so its cause names sudo.
170
+ const ran = decided.decision === "allow" || decided.cause.label === NO_BACKUP_CAUSE;
171
+ const sudo = facts.sudo && ran && decided.cause.kind !== "rule";
169
172
  return {
170
173
  finding,
171
174
  decision: sudo ? "ask" : decided.decision,
@@ -201,12 +204,24 @@ function decideProject(finding, policy) {
201
204
  actionClass: facts.actionClass
202
205
  };
203
206
  }
204
- /** One recognized command's decision, or null when Autopilot has no opinion. */
207
+ /**
208
+ * One recognized command's decision, or null when Autopilot has no opinion.
209
+ * A Delete says whether it will have a backup on this computer, for a server
210
+ * that asks before a Hands-off delete without one (it sends `withoutBackup`).
211
+ */
205
212
  export function decideFinding(finding, policy, machine) {
213
+ const backup = machine?.backups?.has(finding) === true;
214
+ const decided = decideOne(finding, policy, machine, backup);
215
+ if (!decided || !policy.autopilot.withoutBackup || decided.actionClass !== "delete")
216
+ return decided;
217
+ const word = machine?.regenerable?.has(finding) ? "regenerable" : backup ? "taken" : "none";
218
+ return { ...decided, backup: word };
219
+ }
220
+ function decideOne(finding, policy, machine, backup) {
206
221
  if (!decidable(finding))
207
222
  return null;
208
223
  if (finding.local)
209
- return decideLocal(finding, policy);
224
+ return decideLocal(finding, policy, backup);
210
225
  if (finding.project)
211
226
  return decideProject(finding, policy);
212
227
  // SQL is read from a regex; only a destructive statement gets an opinion.
@@ -233,7 +248,8 @@ export function decideFinding(finding, policy, machine) {
233
248
  vendor: finding.vendor,
234
249
  verb,
235
250
  actionClass,
236
- environment: hint.kind
251
+ environment: hint.kind,
252
+ backup
237
253
  });
238
254
  const reported = repo ? repo.reported : (finding.pushEnvironment ?? reportedEnvironment(hint));
239
255
  return {
@@ -245,6 +261,8 @@ export function decideFinding(finding, policy, machine) {
245
261
  environmentSource: hint.source,
246
262
  ...(reported ? { reported } : {}),
247
263
  actionClass,
264
+ // A write only a safety pack raises is decided like a Delete, not one.
265
+ ...(finding.risk === "write" && actionClass === "delete" ? { treatedAs: "delete" } : {}),
248
266
  ...(target ? { target } : {}),
249
267
  // Only a server that sends placed resources reads where a finding lands.
250
268
  ...(target && policy.autopilot.resources ? { placement: placementOf(target, finding.vendor) } : {})
@@ -305,6 +323,7 @@ function decideV2(command, findings, policy, complete, machine) {
305
323
  environment: strictest.environment,
306
324
  environmentSource: strictest.environmentSource,
307
325
  actionClass: strictest.actionClass,
326
+ ...(strictest.treatedAs ? { treatedAs: strictest.treatedAs } : {}),
308
327
  decided,
309
328
  ...(strictest.finding.local || strictest.finding.pushEnvironment ? { deciding: strictest.finding } : {}),
310
329
  ...(strictest.target ? { target: strictest.target } : {}),
@@ -383,10 +402,12 @@ export function askMessage(decision) {
383
402
  }
384
403
  if (decision.cause && decision.environment && decision.actionClass) {
385
404
  const branch = decision.deciding?.pushEnvironment === "production" ? " (the default branch)" : "";
386
- const effect = `${CLASS_EFFECT[decision.actionClass]} ${envLabel(decision.environment)}${branch}`;
405
+ // A change a safety pack raises says what it does, then how it's decided.
406
+ const effect = `${CLASS_EFFECT[decision.treatedAs ? "change" : decision.actionClass]} ${envLabel(decision.environment)}${branch}`;
407
+ const treated = decision.treatedAs ? " Rules decide it like a delete." : "";
387
408
  const because = decision.cause.kind === "preset" ? "" : ` ${decision.cause.label}.`;
388
409
  const notes = sourceNotes(decision);
389
- return `Passport: ${decision.label} ${effect}${notes.aside}.${because}${notes.sentence} Approve to run it.`;
410
+ return `Passport: ${decision.label} ${effect}${notes.aside}.${treated}${because}${notes.sentence} Approve to run it.`;
390
411
  }
391
412
  return decision.destructive
392
413
  ? `Passport: ${decision.label} ${CLASS_EFFECT_OTHER.delete}. Run it only if you meant to.`
@@ -395,7 +416,7 @@ export function askMessage(decision) {
395
416
  export function denyMessage(decision, owner) {
396
417
  // The app's access, in the words exec uses, with where an admin changes it.
397
418
  if (decision.access)
398
- return decision.access.link ? `${decision.access.message} ${decision.access.link}` : decision.access.message;
419
+ return decision.access.link ? `${decision.access.message}\n${decision.access.link}` : decision.access.message;
399
420
  // The server's access block without its message: no rule or exception lifts it.
400
421
  if (decision.cause?.kind === "access")
401
422
  return `${decision.cause.label}. Ask an admin for access.`;
@@ -29,4 +29,7 @@ export type HookInput = {
29
29
  * numbers (`cliUsage.ts`), never by the hook itself. */
30
30
  transcript_path?: unknown;
31
31
  };
32
+ /** A shell string as-is, or an argv array (`["bash", "-lc", "…"]`) re-quoted
33
+ * so the classifier reads the same words the shell will. */
34
+ export declare function commandText(candidate: unknown): string | null;
32
35
  export declare function readInput(runtime: Runtime, signal: AbortSignal): Promise<HookInput | null>;
@@ -36,6 +36,19 @@ async function readStdin(runtime, signal) {
36
36
  signal.removeEventListener("abort", onAbort);
37
37
  }
38
38
  }
39
+ /** A shell string as-is, or an argv array (`["bash", "-lc", "…"]`) re-quoted
40
+ * so the classifier reads the same words the shell will. */
41
+ export function commandText(candidate) {
42
+ if (typeof candidate === "string")
43
+ return candidate;
44
+ if (!Array.isArray(candidate) || !candidate.length || candidate.length > 256)
45
+ return null;
46
+ if (!candidate.every((part) => typeof part === "string"))
47
+ return null;
48
+ return candidate
49
+ .map((part) => (/^[A-Za-z0-9_@%+=:,./-]+$/.test(part) ? part : `'${part.replaceAll("'", `'\\''`)}'`))
50
+ .join(" ");
51
+ }
39
52
  export async function readInput(runtime, signal) {
40
53
  try {
41
54
  const parsed = JSON.parse(await readStdin(runtime, signal));
@@ -98,6 +98,7 @@ export declare function workingFolder(input: {
98
98
  /**
99
99
  * Everyday commands are reported only to a server that places them, and only
100
100
  * when they matter: allowed project work and reads are counted on this
101
- * machine ("Answered for you"), never sent one by one.
101
+ * machine ("Answered for you"), never sent one by one. A delete the guard
102
+ * backed up on this computer is the exception: its row is where Undo lives.
102
103
  */
103
- export declare function worthReporting(finding: CliFinding, decided: DecidedFinding[], local: boolean): boolean;
104
+ export declare function worthReporting(finding: CliFinding, decided: DecidedFinding[], local: boolean, backedUp?: ReadonlySet<CliFinding>): boolean;
@@ -585,13 +585,16 @@ export function workingFolder(input) {
585
585
  /**
586
586
  * Everyday commands are reported only to a server that places them, and only
587
587
  * when they matter: allowed project work and reads are counted on this
588
- * machine ("Answered for you"), never sent one by one.
588
+ * machine ("Answered for you"), never sent one by one. A delete the guard
589
+ * backed up on this computer is the exception: its row is where Undo lives.
589
590
  */
590
- export function worthReporting(finding, decided, local) {
591
+ export function worthReporting(finding, decided, local, backedUp) {
591
592
  if (!finding.local)
592
593
  return true;
593
594
  if (!local)
594
595
  return false;
596
+ if (backedUp?.has(finding))
597
+ return true;
595
598
  const entry = decided.find((candidate) => candidate.finding === finding);
596
599
  return !(finding.local.quiet && (!entry || entry.decision === "allow"));
597
600
  }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Where the hooks and `passport exec` meet late approvals (`approvalNotice.ts`):
3
+ * remember a session that opened a request a person answers later, and on
4
+ * that session's next prompt or resume, print what was approved meanwhile.
5
+ */
6
+ import { type ParsedArgs } from "./cliArgs.js";
7
+ import type { GuardPlan } from "./cliHookDecide.js";
8
+ import type { HookDependencies } from "./cliHookDeliver.js";
9
+ import type { HookInput } from "./cliHookInput.js";
10
+ import type { Runtime } from "./cliSupport.js";
11
+ /** The guard opened a request a person answers later (not one approved during the hold). */
12
+ export declare function rememberGuardAsk(plan: GuardPlan, client: string, sessionId: string | undefined, now: number): Promise<void>;
13
+ /** `passport exec` opened a request: the same, from its request body. */
14
+ export declare function rememberExecAsk(approvalId: string, body: Record<string, unknown>, now: number): Promise<void>;
15
+ /**
16
+ * On Claude Code's SessionStart or UserPromptSubmit: context for the agent
17
+ * about approvals it missed, never more than the hook's budget. True when the
18
+ * event was a prompt, which the audit hook has nothing else to do for.
19
+ */
20
+ export declare function tellApproved(input: HookInput, args: ParsedArgs, runtime: Runtime, deps: HookDependencies, budget: AbortSignal,
21
+ /** Managed settings run Passport's hooks instead: this copy stays quiet. */
22
+ managedElsewhere: () => boolean): Promise<boolean>;
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Where the hooks and `passport exec` meet late approvals (`approvalNotice.ts`):
3
+ * remember a session that opened a request a person answers later, and on
4
+ * that session's next prompt or resume, print what was approved meanwhile.
5
+ */
6
+ import { value } from "./cliArgs.js";
7
+ /** The guard opened a request a person answers later (not one approved during the hold). */
8
+ export async function rememberGuardAsk(plan, client, sessionId, now) {
9
+ if (!plan.server?.approvalId || plan.server.decision !== "ask" || plan.held === "approved")
10
+ return;
11
+ (await import("./approvalNotice.js")).noteWaitingSession(client, sessionId, now);
12
+ }
13
+ /** `passport exec` opened a request: the same, from its request body. */
14
+ export async function rememberExecAsk(approvalId, body, now) {
15
+ if (approvalId && typeof body.runtime === "string" && typeof body.sessionId === "string") {
16
+ (await import("./approvalNotice.js")).noteWaitingSession(body.runtime, body.sessionId, now);
17
+ }
18
+ }
19
+ /**
20
+ * On Claude Code's SessionStart or UserPromptSubmit: context for the agent
21
+ * about approvals it missed, never more than the hook's budget. True when the
22
+ * event was a prompt, which the audit hook has nothing else to do for.
23
+ */
24
+ export async function tellApproved(input, args, runtime, deps, budget,
25
+ /** Managed settings run Passport's hooks instead: this copy stays quiet. */
26
+ managedElsewhere) {
27
+ const event = input.hook_event_name;
28
+ if (event !== "SessionStart" && event !== "UserPromptSubmit")
29
+ return false;
30
+ const prompt = event === "UserPromptSubmit";
31
+ const [{ localProfile, profileApi }, { approvalNotice }] = await Promise.all([
32
+ import("./cliHookDeliver.js"),
33
+ import("./approvalNotice.js")
34
+ ]);
35
+ const profile = localProfile(args, runtime.env);
36
+ if (!profile || runtime.env.PASSPORT_AGENT_KEY || runtime.env.PASSPORT_ENDPOINT || managedElsewhere())
37
+ return prompt;
38
+ // Session events carry no tool-use id: an entry without `--client` is Claude Code's.
39
+ const named = (value(args, "client") ?? runtime.env.PASSPORT_HOOK_RUNTIME)?.trim().toLowerCase();
40
+ const output = await approvalNotice(input, {
41
+ runtime: named && named !== "claude-code" ? named : "claude-code",
42
+ openApi: () => profileApi(profile, budget, deps.fetch ?? fetch),
43
+ signal: budget,
44
+ now: deps.now ?? Date.now
45
+ });
46
+ if (output)
47
+ runtime.stdout.write(`${JSON.stringify(output)}\n`);
48
+ return prompt;
49
+ }
@@ -57,3 +57,5 @@ export type GuardRewriteInput = {
57
57
  /** The guard's rewrite to `passport exec`, or the allow for an exec the agent
58
58
  * wrote. Only vendor commands are rewritten, so everyday commands never are. */
59
59
  export declare function guardRewrite(input: GuardRewriteInput): Promise<Record<string, unknown> | null>;
60
+ /** `passport` when it's on PATH, else this exact CLI through node. */
61
+ export declare function passportInvocation(env: Env): Promise<string>;
@@ -174,7 +174,7 @@ export async function guardRewrite(input) {
174
174
  });
175
175
  }
176
176
  /** `passport` when it's on PATH, else this exact CLI through node. */
177
- async function passportInvocation(env) {
177
+ export async function passportInvocation(env) {
178
178
  const { findOnPath } = await import("./initInstall.js");
179
179
  if (findOnPath("passport", env, process.platform))
180
180
  return "passport";
package/dist/cliKeys.js CHANGED
@@ -4,6 +4,7 @@
4
4
  * passport keys [list] what Passport holds, and what's still here
5
5
  * passport keys move [--yes] confirm each key, store it, sign that CLI out
6
6
  * passport keys add <cli> store a key you paste (stdin, never echoed)
7
+ * passport keys rotate <app> replace a key Passport holds, checked first (cliKeysRotate.ts)
7
8
  *
8
9
  * A key is stored first and removed from this computer second, so nothing is
9
10
  * ever lost: a sign-out that fails leaves the key in Passport and says what is
@@ -28,6 +29,7 @@ import { SIGNED_OUT_OFF, SIGNED_OUT_ON, heldKeys, keep, signedOut } from "./cliK
28
29
  import { beforeStoring, signOutHere } from "./cliKeysSignOut.js";
29
30
  import { listOf, processTerminal } from "./initUi.js";
30
31
  import { readSecret } from "./keysSecret.js";
32
+ import { rotateKey } from "./cliKeysRotate.js";
31
33
  import { unknownSubcommand } from "./cliSuggest.js";
32
34
  import { ago, layout, mark, promptRows, table, termOf } from "./term.js";
33
35
  import { pathLines } from "./pathLines.js";
@@ -553,6 +555,14 @@ export async function keys(args, runtime, deps = {}) {
553
555
  return move(args, runtime, deps);
554
556
  if (action === "add")
555
557
  return add(args, runtime, deps);
558
+ if (action === "rotate") {
559
+ return rotateKey(args, runtime, {
560
+ api: () => apiFor(args, runtime, deps),
561
+ terminal: deps.terminal ?? processTerminal(runtime, process.platform, bool(args, "json")),
562
+ readSecret: deps.readSecret ?? ((text) => readSecret(runtime, text)),
563
+ computer: () => deps.computer ?? computerName()
564
+ });
565
+ }
556
566
  if (action === "shim")
557
567
  return shim(args, runtime, deps, profileOf(args, runtime));
558
568
  if (action === "keep" || action === "signed-out") {
@@ -566,6 +576,6 @@ export async function keys(args, runtime, deps = {}) {
566
576
  };
567
577
  return action === "keep" ? keep(args, context) : signedOut(args, context);
568
578
  }
569
- const unknown = unknownSubcommand("keys", action, ["list", "move", "add", "shim", "keep", "signed-out"], "Remove a key Passport holds in Passport › Apps › Keys.");
579
+ const unknown = unknownSubcommand("keys", action, ["list", "move", "add", "rotate", "shim", "keep", "signed-out"], "Remove a key Passport holds in Passport › Apps › Keys.");
570
580
  return failure(unknown.message, 6, "usage", unknown.next ? { next: unknown.next } : {});
571
581
  }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * `passport keys rotate <app>`: replace a key Passport holds with a new one.
3
+ *
4
+ * Only a person at a terminal: the new key is typed or pasted into a hidden
5
+ * prompt (never echoed), sent once to Passport, which checks it with one
6
+ * harmless read at the provider before it swaps anything. A refused or
7
+ * unchecked key leaves the old one in place. The old value stays restorable
8
+ * in Passport for seven days, and the owner and admins get an alert with an
9
+ * Undo, like every replace from the CLI. No flag answers for a person, and no
10
+ * value is ever printed, logged, or put in --json.
11
+ */
12
+ import type { ParsedArgs } from "./cliArgs.js";
13
+ import { type CommandResult, type Runtime } from "./cliSupport.js";
14
+ import type { Api } from "./cliKeysTypes.js";
15
+ import { type ExecVendor } from "./execVendors.js";
16
+ import type { InitTerminal } from "./initUi.js";
17
+ export declare function rotateVendorOf(typed: string): ExecVendor | undefined;
18
+ export type RotateDependencies = {
19
+ api: () => Api;
20
+ terminal: InitTerminal;
21
+ readSecret: (prompt: string) => Promise<string>;
22
+ computer: () => string;
23
+ };
24
+ export declare function rotateKey(args: ParsedArgs, runtime: Runtime, deps: RotateDependencies): Promise<CommandResult>;