passport-bridge 0.22.0 → 0.25.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 (138) hide show
  1. package/README.md +104 -60
  2. package/dist/cliArgs.d.ts +1 -1
  3. package/dist/cliArgs.js +21 -4
  4. package/dist/cliAutopilot.js +15 -4
  5. package/dist/cliAutopilotPolicy.d.ts +17 -0
  6. package/dist/cliAutopilotPolicy.js +23 -1
  7. package/dist/cliChanges.d.ts +80 -0
  8. package/dist/cliChanges.js +340 -0
  9. package/dist/cliClient.d.ts +5 -0
  10. package/dist/cliClient.js +15 -3
  11. package/dist/cliExec.js +5 -1
  12. package/dist/cliGuardHealth.js +1 -1
  13. package/dist/cliGuardState.js +2 -2
  14. package/dist/cliHook.d.ts +1 -1
  15. package/dist/cliHook.js +56 -41
  16. package/dist/cliHookAudit.d.ts +44 -0
  17. package/dist/cliHookAudit.js +57 -0
  18. package/dist/cliHookClassify.d.ts +4 -0
  19. package/dist/cliHookClients.d.ts +23 -0
  20. package/dist/cliHookClients.js +52 -0
  21. package/dist/cliHookDecide.d.ts +5 -1
  22. package/dist/cliHookDecide.js +8 -2
  23. package/dist/cliHookDeliver.d.ts +32 -8
  24. package/dist/cliHookDeliver.js +84 -2
  25. package/dist/cliHookExtras.d.ts +8 -3
  26. package/dist/cliHookExtras.js +16 -3
  27. package/dist/cliHookGuard.d.ts +21 -1
  28. package/dist/cliHookGuard.js +43 -16
  29. package/dist/cliHookInput.d.ts +8 -0
  30. package/dist/cliHookInput.js +13 -0
  31. package/dist/cliHookInstall.d.ts +6 -6
  32. package/dist/cliHookInstall.js +16 -40
  33. package/dist/cliHookLifecycle.d.ts +22 -0
  34. package/dist/cliHookLifecycle.js +101 -0
  35. package/dist/cliHookLocal.d.ts +6 -2
  36. package/dist/cliHookLocal.js +25 -4
  37. package/dist/cliHookLocalCode.d.ts +2 -0
  38. package/dist/cliHookLocalCode.js +1 -1
  39. package/dist/cliHookRepo.d.ts +20 -0
  40. package/dist/cliHookRepo.js +36 -0
  41. package/dist/cliHookRewrite.d.ts +17 -1
  42. package/dist/cliHookRewrite.js +51 -2
  43. package/dist/cliHookScripts.d.ts +1 -0
  44. package/dist/cliHookScripts.js +14 -6
  45. package/dist/cliHookStep.d.ts +19 -0
  46. package/dist/cliHookStep.js +76 -0
  47. package/dist/cliKeys.d.ts +6 -58
  48. package/dist/cliKeys.js +82 -41
  49. package/dist/cliKeysBack.d.ts +31 -15
  50. package/dist/cliKeysBack.js +70 -47
  51. package/dist/cliKeysKeep.d.ts +34 -0
  52. package/dist/cliKeysKeep.js +110 -0
  53. package/dist/cliKeysRotate.d.ts +24 -0
  54. package/dist/cliKeysRotate.js +149 -0
  55. package/dist/cliKeysSignOut.d.ts +33 -0
  56. package/dist/cliKeysSignOut.js +72 -0
  57. package/dist/cliKeysTypes.d.ts +74 -0
  58. package/dist/cliKeysTypes.js +1 -0
  59. package/dist/cliMain.js +56 -15
  60. package/dist/cliOutput.js +50 -8
  61. package/dist/cliPolicyV2.js +43 -2
  62. package/dist/cliProjectSummary.d.ts +9 -0
  63. package/dist/cliProjectSummary.js +134 -0
  64. package/dist/cliProtocol.d.ts +10 -0
  65. package/dist/cliProtocol.js +15 -0
  66. package/dist/cliRequest.d.ts +27 -0
  67. package/dist/cliRequest.js +92 -0
  68. package/dist/cliRestoreRequests.d.ts +57 -0
  69. package/dist/cliRestoreRequests.js +186 -0
  70. package/dist/cliScriptRead.d.ts +8 -1
  71. package/dist/cliScriptRead.js +22 -11
  72. package/dist/cliSeen.d.ts +77 -15
  73. package/dist/cliSeen.js +171 -34
  74. package/dist/cliSessions.d.ts +26 -45
  75. package/dist/cliSessions.js +158 -147
  76. package/dist/cliSessionsJson.d.ts +238 -0
  77. package/dist/cliSessionsJson.js +351 -0
  78. package/dist/cliSessionsRender.d.ts +40 -0
  79. package/dist/cliSessionsRender.js +359 -0
  80. package/dist/cliStatus.js +5 -1
  81. package/dist/cliStatusGuard.d.ts +5 -1
  82. package/dist/cliStatusGuard.js +4 -0
  83. package/dist/cliUndo.d.ts +1 -3
  84. package/dist/cliUndo.js +9 -15
  85. package/dist/cliUndoLocal.d.ts +27 -0
  86. package/dist/cliUndoLocal.js +105 -0
  87. package/dist/cliUpdate.d.ts +29 -0
  88. package/dist/cliUpdate.js +195 -0
  89. package/dist/cliUsage.d.ts +71 -0
  90. package/dist/cliUsage.js +333 -0
  91. package/dist/cliWait.js +2 -2
  92. package/dist/completion.js +8 -3
  93. package/dist/doctor.js +4 -0
  94. package/dist/execNoKey.d.ts +4 -4
  95. package/dist/execNoKey.js +17 -11
  96. package/dist/execVendors.d.ts +27 -2
  97. package/dist/execVendors.js +74 -23
  98. package/dist/gitBackup.d.ts +111 -0
  99. package/dist/gitBackup.js +391 -0
  100. package/dist/gitSnapshot.d.ts +82 -0
  101. package/dist/gitSnapshot.js +478 -0
  102. package/dist/hookFastPath.js +3 -2
  103. package/dist/initInstall.d.ts +22 -0
  104. package/dist/initInstall.js +70 -1
  105. package/dist/initKeysStep.js +1 -0
  106. package/dist/keysKept.d.ts +17 -0
  107. package/dist/keysKept.js +92 -0
  108. package/dist/keysLocal.d.ts +2 -0
  109. package/dist/keysLocal.js +6 -0
  110. package/dist/keysReport.d.ts +32 -0
  111. package/dist/keysReport.js +72 -0
  112. package/dist/localBackups.d.ts +102 -0
  113. package/dist/localBackups.js +233 -0
  114. package/dist/localGit.d.ts +24 -0
  115. package/dist/localGit.js +44 -0
  116. package/dist/localReach.d.ts +30 -0
  117. package/dist/localReach.js +94 -0
  118. package/dist/localRestore.d.ts +42 -0
  119. package/dist/localRestore.js +94 -0
  120. package/dist/localTrash.d.ts +97 -0
  121. package/dist/localTrash.js +394 -0
  122. package/dist/pluginPin.d.ts +1 -1
  123. package/dist/pluginPin.js +1 -1
  124. package/dist/plural.d.ts +2 -0
  125. package/dist/plural.js +13 -0
  126. package/dist/regenerable.d.ts +24 -0
  127. package/dist/regenerable.js +219 -0
  128. package/dist/scanStores.js +50 -2
  129. package/dist/selfUpdate.d.ts +92 -0
  130. package/dist/selfUpdate.js +361 -0
  131. package/dist/selfUpdateContract.d.ts +20 -0
  132. package/dist/selfUpdateContract.js +56 -0
  133. package/dist/updateTrigger.d.ts +18 -0
  134. package/dist/updateTrigger.js +77 -0
  135. package/dist/version.d.ts +1 -1
  136. package/dist/version.js +1 -1
  137. package/npm-shrinkwrap.json +55 -161
  138. package/package.json +1 -1
@@ -283,6 +283,27 @@ function accessCeiling(policy, facts) {
283
283
  /** The server's `decideAction`, minus grants (only the server knows them).
284
284
  * The access ceiling comes first and nothing lifts it; the second-person rule
285
285
  * turns a Production run into an ask the server owns. */
286
+ /** Checked copy of shared/undoContract.ts `UNDO_COPY.askCause` (cliAutopilotPolicy.test.ts). */
287
+ export const NO_BACKUP_CAUSE = "Couldn't take a backup first";
288
+ /**
289
+ * The backup rule for the shell (server `applyShellBackupGate`): a Delete the
290
+ * preset would run asks when nothing can back it up here, unless the person
291
+ * turned on "Run deletes without a backup" for that row. `facts.backup`:
292
+ * this computer takes one first (`localBackups.ts`). An exception or a floor
293
+ * decides as before.
294
+ */
295
+ function backupGate(policy, facts, decided) {
296
+ const rows = policy.withoutBackup;
297
+ if (!rows || decided.decision !== "allow" || facts.actionClass !== "delete")
298
+ return decided;
299
+ if (decided.cause.kind !== "preset" && decided.cause.kind !== "default")
300
+ return decided;
301
+ if (facts.backup)
302
+ return decided;
303
+ if (facts.environment !== "production" && rows[facts.environment] === true)
304
+ return decided;
305
+ return { decision: "ask", cause: { kind: decided.cause.kind, label: NO_BACKUP_CAUSE } };
306
+ }
286
307
  export function decideAction(policy, facts) {
287
308
  const ceiling = accessCeiling(policy, facts);
288
309
  if (ceiling)
@@ -290,7 +311,8 @@ export function decideAction(policy, facts) {
290
311
  const decided = decideByRules(policy, facts);
291
312
  const classes = policy.secondPerson?.classes ?? [];
292
313
  if (decided.decision !== "allow" || facts.environment !== "production" || !classes.includes(facts.actionClass)) {
293
- return decided;
314
+ // Someone else approving comes first; then the backup rule.
315
+ return backupGate(policy, facts, decided);
294
316
  }
295
317
  const label = facts.actionClass === "change" ? SECOND_PERSON_LABEL.change : SECOND_PERSON_LABEL.delete;
296
318
  return { decision: "ask", cause: { kind: "floor", label } };
@@ -0,0 +1,80 @@
1
+ /**
2
+ * `passport changes`: what changed in Production, the list Sessions ›
3
+ * Production changes shows. Every change, delete, and irreversible action
4
+ * that ran on confirmed Production in the window, grouped by app, newest
5
+ * first, with the agent, the person, the work item, the result, and undo.
6
+ *
7
+ * passport changes the last 24 hours
8
+ * passport changes --env production --since 1h
9
+ *
10
+ * Filters run on the server (`GET /api/my/production-changes`). `--json`
11
+ * prints `ChangesJson`, never the server's raw page.
12
+ */
13
+ import { type ParsedArgs } from "./cliArgs.js";
14
+ import { type AutopilotDependencies } from "./cliMemberCall.js";
15
+ import { type CommandResult, type Runtime } from "./cliSupport.js";
16
+ import { type Term } from "./term.js";
17
+ export type UndoJson = {
18
+ state: string;
19
+ label: string;
20
+ undoneBy: string | null;
21
+ };
22
+ export type ChangeJson = {
23
+ id: string;
24
+ ts: number | null;
25
+ person: string | null;
26
+ agent: string;
27
+ agentName: string;
28
+ appKey: string;
29
+ vendor: string;
30
+ appName: string;
31
+ command: string;
32
+ target: string | null;
33
+ actionClass: "change" | "delete" | "irreversible";
34
+ result: "ok" | "error";
35
+ approved: boolean;
36
+ sessionId: string | null;
37
+ project: string | null;
38
+ branch: string | null;
39
+ pull: {
40
+ number: number;
41
+ title: string;
42
+ url: string | null;
43
+ } | null;
44
+ undo: UndoJson | null;
45
+ };
46
+ /** `passport changes --json`. */
47
+ export type ChangesJson = {
48
+ view: "production-changes";
49
+ environment: "production";
50
+ sinceTs: number | null;
51
+ untilTs: number | null;
52
+ total: number;
53
+ unplaced: number;
54
+ complete: boolean;
55
+ apps: Array<{
56
+ vendor: string;
57
+ appName: string;
58
+ changes: ChangeJson[];
59
+ }>;
60
+ };
61
+ /** `--since` as the server reads it. */
62
+ export declare function changesSince(raw: string): string | null;
63
+ /** The server's page as `ChangesJson`: grouped by app (newest first), then time. */
64
+ export declare function changesOf(raw: unknown): ChangesJson;
65
+ /** "14:02" today, "Oct 19 14:02" before. */
66
+ export declare function changeTime(ms: number | null, now: number): string;
67
+ /** The row's part line: agent · person · PR (else branch) · result · undo.
68
+ * With changes from more than one repository, the repository comes first. */
69
+ export declare function changeParts(change: ChangeJson, projects?: boolean): string[];
70
+ /**
71
+ * Consecutive alike changes (same command, target, agent, person, and
72
+ * branch; newest first) as one line, the way the web folds them: 28 pushes
73
+ * read "git push -> main x28". `--json` keeps every change.
74
+ */
75
+ export declare function foldChanges(changes: readonly ChangeJson[]): ChangeJson[][];
76
+ export declare function renderChanges(page: ChangesJson, term: Term, now: number, since: string, links: {
77
+ environments: string | null;
78
+ more: string | null;
79
+ }): string;
80
+ export declare function changes(args: ParsedArgs, runtime: Runtime, deps?: AutopilotDependencies): Promise<CommandResult>;
@@ -0,0 +1,340 @@
1
+ /**
2
+ * `passport changes`: what changed in Production, the list Sessions ›
3
+ * Production changes shows. Every change, delete, and irreversible action
4
+ * that ran on confirmed Production in the window, grouped by app, newest
5
+ * first, with the agent, the person, the work item, the result, and undo.
6
+ *
7
+ * passport changes the last 24 hours
8
+ * passport changes --env production --since 1h
9
+ *
10
+ * Filters run on the server (`GET /api/my/production-changes`). `--json`
11
+ * prints `ChangesJson`, never the server's raw page.
12
+ */
13
+ import { value } from "./cliArgs.js";
14
+ import { api, json } from "./cliMemberCall.js";
15
+ import { failure, timeoutMs } from "./cliSupport.js";
16
+ import { appName, clientName, count, list, oneOf, record, text, time } from "./cliSessionsJson.js";
17
+ import { countOf } from "./plural.js";
18
+ import { joinParts, mark, visibleLength, wrap, termOf } from "./term.js";
19
+ import { hashLink } from "./webLinks.js";
20
+ const DATE = /^\d{4}-\d{2}-\d{2}$/;
21
+ const RANGES = ["1h", "6h", "24h", "7d", "30d", "today"];
22
+ const DEFAULT_SINCE = "24h";
23
+ const WINDOW_WORDS = {
24
+ "1h": "last hour",
25
+ "6h": "last 6 hours",
26
+ "24h": "last 24 hours",
27
+ "7d": "last 7 days",
28
+ "30d": "last 30 days",
29
+ today: "today"
30
+ };
31
+ /** A local date as this computer's midnight in epoch ms, the way the web sends it. */
32
+ function localMidnight(raw) {
33
+ const [year, month, day] = raw.split("-").map(Number);
34
+ const at = new Date(year, month - 1, day);
35
+ return at.getFullYear() === year && at.getMonth() === month - 1 && at.getDate() === day ? String(at.getTime()) : null;
36
+ }
37
+ /** `--since` as the server reads it. */
38
+ export function changesSince(raw) {
39
+ const value = raw.trim();
40
+ if (RANGES.includes(value))
41
+ return value;
42
+ return DATE.test(value) ? localMidnight(value) : null;
43
+ }
44
+ /** `--until` as the server reads it: a date (through its end) as written. */
45
+ function changesUntil(raw) {
46
+ const value = raw.trim();
47
+ return DATE.test(value) && localMidnight(value) ? value : null;
48
+ }
49
+ function filtersOf(args) {
50
+ const env = value(args, "env");
51
+ if (env !== undefined && env.trim().toLowerCase() !== "production")
52
+ return failure("Only --env production is supported for now.", 6, "usage");
53
+ const filters = {};
54
+ const since = value(args, "since") ?? DEFAULT_SINCE;
55
+ const parsedSince = changesSince(since);
56
+ if (!parsedSince)
57
+ return failure("--since must be 1h, 6h, 24h, 7d, 30d, today, or a date (YYYY-MM-DD).", 6, "usage");
58
+ filters.since = parsedSince;
59
+ const until = value(args, "until");
60
+ if (until !== undefined) {
61
+ const parsed = changesUntil(until);
62
+ if (!parsed)
63
+ return failure("--until must be a date (YYYY-MM-DD).", 6, "usage");
64
+ filters.until = parsed;
65
+ }
66
+ const project = value(args, "project");
67
+ if (project !== undefined) {
68
+ const name = text(project, 200);
69
+ if (!name)
70
+ return failure("--project needs a project name.", 6, "usage");
71
+ filters.project = name;
72
+ }
73
+ const pr = value(args, "pr");
74
+ if (pr !== undefined) {
75
+ const number = Number(pr.replace(/^#/, ""));
76
+ if (!Number.isSafeInteger(number) || number <= 0)
77
+ return failure("--pr must be a pull request number.", 6, "usage");
78
+ filters.pr = String(number);
79
+ }
80
+ const app = value(args, "app");
81
+ if (app !== undefined) {
82
+ const keys = text(app, 400);
83
+ if (!keys)
84
+ return failure("--app needs an app key.", 6, "usage");
85
+ filters.app = keys;
86
+ }
87
+ // `--agent` is read as `client` (cliArgs aliases).
88
+ const agent = value(args, "client");
89
+ if (agent !== undefined) {
90
+ const id = text(agent, 120);
91
+ if (!id)
92
+ return failure("--agent needs an agent name.", 6, "usage");
93
+ filters.agent = id;
94
+ }
95
+ return filters;
96
+ }
97
+ function query(params) {
98
+ const search = new URLSearchParams();
99
+ for (const [key, raw] of Object.entries(params))
100
+ if (raw)
101
+ search.set(key, raw);
102
+ const qs = search.toString();
103
+ return qs ? `?${qs}` : "";
104
+ }
105
+ /* -------------------------------- the JSON -------------------------------- */
106
+ function undoOf(raw) {
107
+ const undo = record(raw);
108
+ const state = text(undo.state, 40);
109
+ if (!state)
110
+ return null;
111
+ return { state, label: text(undo.label, 120) ?? state, undoneBy: text(undo.undoneBy, 120) ?? null };
112
+ }
113
+ function changeOf(raw) {
114
+ const entry = record(raw);
115
+ const id = text(entry.id, 128);
116
+ if (!id)
117
+ return null;
118
+ const appKey = text(entry.appKey, 80) ?? "";
119
+ const vendor = text(entry.vendor, 80) ?? appKey.replace(/^cli:/, "");
120
+ const tool = text(entry.tool, 160) ?? "";
121
+ const work = record(entry.work);
122
+ const pull = record(work.pull);
123
+ const pullNumber = count(pull.number);
124
+ const pullTitle = text(pull.title, 200);
125
+ const pullUrl = text(pull.url, 400);
126
+ const agent = text(entry.agent, 80) ?? "";
127
+ return {
128
+ id,
129
+ ts: time(entry.ts),
130
+ person: text(record(entry.person).name, 120) ?? null,
131
+ agent,
132
+ agentName: text(entry.agentName, 80) ?? clientName(agent),
133
+ appKey,
134
+ vendor,
135
+ appName: nameOf(text(entry.appName, 80), vendor),
136
+ command: text(entry.command, 200) ?? (appKey.startsWith("cli:") ? `${appKey.slice(4)} ${tool}` : tool),
137
+ target: text(entry.target, 160) ?? null,
138
+ actionClass: oneOf(entry.actionClass, ["change", "delete", "irreversible"]) ?? "change",
139
+ result: entry.result === "error" ? "error" : "ok",
140
+ approved: entry.approved === true,
141
+ sessionId: text(entry.sessionId, 128) ?? null,
142
+ project: text(work.project, 200) ?? null,
143
+ branch: text(work.branch, 200) ?? null,
144
+ pull: pullNumber && pullTitle
145
+ ? { number: pullNumber, title: pullTitle, url: pullUrl && /^https:\/\//.test(pullUrl) ? pullUrl : null }
146
+ : null,
147
+ undo: undoOf(entry.undo)
148
+ };
149
+ }
150
+ /** The server's app name, unless it's only the bare program ("git" reads "Git"). */
151
+ function nameOf(name, vendor) {
152
+ return name && name !== vendor ? name : appName(vendor);
153
+ }
154
+ /** The server's page as `ChangesJson`: grouped by app (newest first), then time. */
155
+ export function changesOf(raw) {
156
+ const page = record(raw);
157
+ const changes = list(page.changes)
158
+ .map(changeOf)
159
+ .filter((entry) => entry !== null);
160
+ const groups = new Map();
161
+ for (const change of changes) {
162
+ let group = groups.get(change.vendor);
163
+ if (!group) {
164
+ group = { vendor: change.vendor, appName: change.appName, changes: [], lastTs: 0 };
165
+ groups.set(change.vendor, group);
166
+ }
167
+ group.lastTs = Math.max(group.lastTs, change.ts ?? 0);
168
+ group.changes.push(change);
169
+ }
170
+ const apps = [...groups.values()]
171
+ .sort((a, b) => b.lastTs - a.lastTs || a.appName.localeCompare(b.appName))
172
+ .map(({ lastTs: _lastTs, ...group }) => ({
173
+ ...group,
174
+ changes: group.changes.sort((a, b) => (b.ts ?? 0) - (a.ts ?? 0) || a.id.localeCompare(b.id))
175
+ }));
176
+ return {
177
+ view: "production-changes",
178
+ environment: "production",
179
+ sinceTs: time(page.sinceTs),
180
+ untilTs: time(page.untilTs),
181
+ total: Math.max(count(page.total), changes.length),
182
+ unplaced: count(page.unplaced),
183
+ complete: page.complete !== false,
184
+ apps
185
+ };
186
+ }
187
+ /* -------------------------------- the text -------------------------------- */
188
+ function clock(ms) {
189
+ return new Date(ms).toLocaleTimeString("en-GB", { hour: "2-digit", minute: "2-digit" });
190
+ }
191
+ /** "14:02" today, "Oct 19 14:02" before. */
192
+ export function changeTime(ms, now) {
193
+ if (ms === null)
194
+ return "";
195
+ const date = new Date(ms);
196
+ if (new Date(now).toDateString() === date.toDateString())
197
+ return clock(ms);
198
+ return `${date.toLocaleDateString("en-US", { month: "short", day: "numeric" })} ${clock(ms)}`;
199
+ }
200
+ function undoPart(undo) {
201
+ if (!undo)
202
+ return null;
203
+ if (undo.state === "available" || undo.state === "conflict")
204
+ return "Undo available";
205
+ if (undo.state === "undone")
206
+ return `Undone by ${undo.undoneBy ?? "someone"}`;
207
+ if (undo.state === "expired")
208
+ return "Undo expired";
209
+ if (undo.state === "undoing")
210
+ return "Undoing";
211
+ if (undo.state === "partial")
212
+ return "Partly undone";
213
+ if (undo.state === "failed")
214
+ return "Undo failed";
215
+ return null;
216
+ }
217
+ /** The row's part line: agent · person · PR (else branch) · result · undo.
218
+ * With changes from more than one repository, the repository comes first. */
219
+ export function changeParts(change, projects = false) {
220
+ const parts = [change.agentName];
221
+ if (change.person)
222
+ parts.push(change.person);
223
+ if (projects && change.project && (change.pull || change.branch))
224
+ parts.push(change.project);
225
+ if (change.pull)
226
+ parts.push(`PR #${change.pull.number} ${change.pull.title}`);
227
+ else if (change.branch)
228
+ parts.push(change.branch);
229
+ if (change.result === "error")
230
+ parts.push("Failed");
231
+ if (change.approved)
232
+ parts.push("Approved");
233
+ const undo = undoPart(change.undo);
234
+ if (undo)
235
+ parts.push(undo);
236
+ return parts;
237
+ }
238
+ /** A change keeps its own line when it failed, was approved, or has an undo state worth seeing. */
239
+ function standsAlone(change) {
240
+ return change.result === "error" || change.approved || Boolean(change.undo && change.undo.state !== "expired");
241
+ }
242
+ function runKey(change) {
243
+ return JSON.stringify([change.command, change.target, change.agent, change.person, change.project, change.branch]);
244
+ }
245
+ /**
246
+ * Consecutive alike changes (same command, target, agent, person, and
247
+ * branch; newest first) as one line, the way the web folds them: 28 pushes
248
+ * read "git push -> main x28". `--json` keeps every change.
249
+ */
250
+ export function foldChanges(changes) {
251
+ const runs = [];
252
+ let open = null;
253
+ let openKey = "";
254
+ for (const change of changes) {
255
+ if (standsAlone(change)) {
256
+ runs.push([change]);
257
+ open = null;
258
+ continue;
259
+ }
260
+ const key = runKey(change);
261
+ if (open && key === openKey)
262
+ open.push(change);
263
+ else {
264
+ open = [change];
265
+ openKey = key;
266
+ runs.push(open);
267
+ }
268
+ }
269
+ return runs;
270
+ }
271
+ function windowWord(since, sinceTs, now) {
272
+ return WINDOW_WORDS[since] ?? (sinceTs ? `since ${changeTime(sinceTs, now)}` : `since ${since}`);
273
+ }
274
+ export function renderChanges(page, term, now, since, links) {
275
+ const arrow = term.unicode ? "→" : "->";
276
+ const lines = joinParts([
277
+ "Production changes",
278
+ windowWord(since, page.sinceTs, now),
279
+ `${countOf(page.total, "change")} on confirmed Production`
280
+ ], term.width);
281
+ if (!page.apps.length)
282
+ lines.push("", ...wrap("Nothing your agents ran changed a target you placed in Production in this window.", term.width));
283
+ const projects = new Set(page.apps.flatMap((app) => app.changes.map((change) => change.project)).filter(Boolean)).size > 1;
284
+ const times = term.unicode ? "×" : "x";
285
+ for (const app of page.apps) {
286
+ lines.push("", `${app.appName} · ${countOf(app.changes.length, "change")}`);
287
+ for (const run of foldChanges(app.changes)) {
288
+ const change = run[0];
289
+ const oldest = run[run.length - 1];
290
+ const title = change.target ? `${change.command} ${arrow} ${change.target}` : change.command;
291
+ const when = run.length > 1 ? `${changeTime(oldest.ts, now)}-${changeTime(change.ts, now)}` : changeTime(change.ts, now);
292
+ const count = run.length > 1 ? ` ${times}${run.length.toLocaleString("en-US")}` : "";
293
+ const head = `${mark(term, change.result === "error" ? "fail" : "warn")} ${when} ${title}${count}`;
294
+ lines.push(...(visibleLength(head) <= term.width ? [head] : wrap(head, term.width, "", " ")));
295
+ lines.push(...joinParts(changeParts(change, projects), term.width, " "));
296
+ }
297
+ }
298
+ if (!page.complete) {
299
+ lines.push("", ...wrap(`Showing the newest ${countOf(countRows(page), "change")}.`, term.width));
300
+ if (links.more)
301
+ lines.push(`See all: ${links.more}`);
302
+ }
303
+ if (page.unplaced) {
304
+ lines.push("", ...wrap(`${countOf(page.unplaced, "unplaced action")}, counted as Production until you place them.`, term.width));
305
+ if (links.environments)
306
+ lines.push(`Set environments: ${links.environments}`);
307
+ }
308
+ return lines.join("\n");
309
+ }
310
+ function countRows(page) {
311
+ return page.apps.reduce((sum, app) => sum + app.changes.length, 0);
312
+ }
313
+ /* -------------------------------- command -------------------------------- */
314
+ export async function changes(args, runtime, deps = {}) {
315
+ const now = (deps.now ?? Date.now)();
316
+ const filters = filtersOf(args);
317
+ const client = api(args, runtime, deps);
318
+ const term = termOf(runtime.stdout, runtime.env);
319
+ const response = await client.fetchApi(`/api/my/production-changes${query(filters)}`, {
320
+ method: "GET",
321
+ headers: { accept: "application/json" },
322
+ signal: AbortSignal.any([runtime.signal, AbortSignal.timeout(timeoutMs(args))])
323
+ });
324
+ const page = changesOf(await json(response, "This Passport server doesn't list Production changes yet. Run: passport sessions --production-changes"));
325
+ const since = value(args, "since")?.trim() ?? DEFAULT_SINCE;
326
+ const web = query({
327
+ view: "production",
328
+ since: filters.since,
329
+ until: filters.until,
330
+ project: filters.project,
331
+ pr: filters.pr
332
+ });
333
+ return {
334
+ json: page,
335
+ human: renderChanges(page, term, now, since, {
336
+ environments: hashLink(client.origin, "#rules?section=environments"),
337
+ more: hashLink(client.origin, `#sessions${web}`)
338
+ })
339
+ };
340
+ }
@@ -26,6 +26,10 @@ export type CliProtocolDiagnostics = {
26
26
  serverCompatible: boolean;
27
27
  tools: string[];
28
28
  toolsExact: boolean;
29
+ /** A matching server listed an agent's tools (an app's own tools, or the
30
+ * agent-only access request): the credential is an agent's, from
31
+ * `passport-bridge login`, not a CLI sign-in. */
32
+ agentSignIn: boolean;
29
33
  };
30
34
  type GatewayOptions = {
31
35
  auth: CliAuth;
@@ -48,6 +52,7 @@ export declare class CliGateway {
48
52
  private readonly signal?;
49
53
  private readonly apiFetch;
50
54
  readonly origin: string;
55
+ private readonly profileAuth;
51
56
  private closed;
52
57
  private constructor();
53
58
  static connect(options: GatewayOptions): Promise<CliGateway>;
package/dist/cliClient.js CHANGED
@@ -4,7 +4,7 @@ import { TokenManager } from "./bridge.js";
4
4
  import { CLI_EXCHANGE_ATTEMPT_MS, CLI_EXCHANGE_RETRY } from "./bridgeExchange.js";
5
5
  import { persistCurrentProfileRotation, recoverProfileRotation, withProfileLock } from "./credentials.js";
6
6
  import { VERSION } from "./version.js";
7
- import { SERVER_TOO_OLD } from "./cliProtocol.js";
7
+ import { AgentSignInError, SERVER_TOO_OLD } from "./cliProtocol.js";
8
8
  import { withCliDeadline } from "./cliDeadline.js";
9
9
  import { collectCliPages } from "./cliPagination.js";
10
10
  import { boundedMcpFetch } from "./boundedMcpFetch.js";
@@ -30,6 +30,10 @@ export function supportsCliServerInfo(info) {
30
30
  }
31
31
  return true;
32
32
  }
33
+ /** The CLI surface never lists app tools or the agent-only access request. */
34
+ function agentToolList(tools) {
35
+ return tools.some((name) => name === "passport_request_access" || !name.startsWith("passport_"));
36
+ }
33
37
  function decorateFetch(base, headersToAdd) {
34
38
  return (async (input, init) => {
35
39
  const headers = new Headers(input instanceof Request ? input.headers : undefined);
@@ -82,11 +86,13 @@ export class CliGateway {
82
86
  signal;
83
87
  apiFetch;
84
88
  origin;
89
+ profileAuth;
85
90
  closed = false;
86
91
  constructor(options) {
87
92
  this.timeoutMs = options.timeoutMs;
88
93
  this.signal = options.signal;
89
94
  this.origin = new URL(options.auth.endpoint).origin;
95
+ this.profileAuth = options.auth.kind === "profile";
90
96
  const authedFetch = authedFetchFor(options);
91
97
  this.apiFetch = authedFetch;
92
98
  this.transport = new StreamableHTTPClientTransport(new URL(options.auth.endpoint), {
@@ -112,6 +118,9 @@ export class CliGateway {
112
118
  // Check it before even listing tools so an older compact server cannot turn
113
119
  // an approval-pending result without structured cause into false success.
114
120
  const diagnostic = await this.protocolDiagnostics();
121
+ // Only a saved sign-in can be an agent's; an agent token always gets the CLI's four.
122
+ if (diagnostic.agentSignIn && this.profileAuth)
123
+ throw new AgentSignInError(this.origin);
115
124
  if (!diagnostic.serverCompatible || !diagnostic.toolsExact)
116
125
  throw new Error(SERVER_TOO_OLD);
117
126
  }
@@ -120,11 +129,14 @@ export class CliGateway {
120
129
  const info = this.client.getServerVersion();
121
130
  const tools = (await this.client.listTools({}, this.requestOptions())).tools.map((tool) => tool.name).sort();
122
131
  const required = [...CLI_PROTOCOL_TOOLS].sort();
132
+ const serverCompatible = supportsCliServerInfo(info);
133
+ const toolsExact = tools.length === required.length && required.every((name, index) => tools[index] === name);
123
134
  return {
124
135
  server: info ? { name: info.name, version: info.version } : undefined,
125
- serverCompatible: supportsCliServerInfo(info),
136
+ serverCompatible,
126
137
  tools,
127
- toolsExact: tools.length === required.length && required.every((name, index) => tools[index] === name)
138
+ toolsExact,
139
+ agentSignIn: serverCompatible && !toolsExact && agentToolList(tools)
128
140
  };
129
141
  }
130
142
  callTool(name, args, timeoutMs = this.timeoutMs) {
package/dist/cliExec.js CHANGED
@@ -33,7 +33,7 @@ import { execBackupTarget } from "./execBackupTarget.js";
33
33
  import { readCliPolicy } from "./cliPolicy.js";
34
34
  import { noteExecVendor } from "./execMarker.js";
35
35
  import { CliFailure, callerFrom, failure, readBoundedJson, resolveCliAuth, safeApiError, sleep, timeoutMs } from "./cliSupport.js";
36
- import { EXEC_ENV_NAMES, EXEC_PASSPORT_ENV, EXEC_SHADOWED_ENV, EXEC_VENDOR_NAMES, execVendorOf } from "./execVendors.js";
36
+ import { EXEC_ENV_NAMES, EXEC_PASSPORT_ENV, EXEC_SHADOWED_ENV, EXEC_VENDOR_NAMES, devLoopRefusal, execVendorOf } from "./execVendors.js";
37
37
  import { execTarget } from "./execTarget.js";
38
38
  import { maskChildOutput, secretNeedles } from "./execMask.js";
39
39
  import { findVendorBinary, removeShims } from "./execShims.js";
@@ -504,6 +504,10 @@ export async function exec(args, runtime, deps = {}) {
504
504
  return pendingFailure(decided, "Passport didn't allow this command yet.");
505
505
  const credential = checkedCredential(vendor, decided.credential?.env);
506
506
  remember(true);
507
+ // A dev loop runs only with a key that expires within minutes.
508
+ const devLoop = devLoopRefusal(vendor, args.positionals.slice(1), decided.credential?.issuance);
509
+ if (devLoop)
510
+ return failure(devLoop, 6, "exec_refused");
507
511
  if (bool(args, "verbose") && typeof decided.credential?.label === "string") {
508
512
  // "Your stored Railway key" reads "Passport: used your stored Railway key."
509
513
  const label = decided.credential.label.slice(0, 120);
@@ -149,6 +149,6 @@ export async function guardHeartbeat(api, profile, env, signal, now = Date.now()
149
149
  return null;
150
150
  const sent = await sendGuardHealth(api, profile, env, signal);
151
151
  // Once a day too: has a key `passport keys move` removed come back?
152
- await (await import("./cliKeysBack.js")).checkKeysBack(api, signal).catch(() => undefined);
152
+ await (await import("./cliKeysBack.js")).checkKeysBack(api, signal, process.env, profile).catch(() => undefined);
153
153
  return sent;
154
154
  }
@@ -79,9 +79,9 @@ export function problemFix(kind, client) {
79
79
  };
80
80
  case "coverage-drop":
81
81
  return {
82
- text: "Open the agent's sessions and look at what wasn't checked.",
82
+ text: "Open the agent's sessions and look at what Passport couldn't tell.",
83
83
  link: agent,
84
- docs: `${DOCS_BASE}/member/cli-hook#checked-and-not-checked`
84
+ docs: `${DOCS_BASE}/member/cli-hook#decided-placed-and-blind`
85
85
  };
86
86
  case "key-back":
87
87
  return {
package/dist/cliHook.d.ts CHANGED
@@ -48,7 +48,7 @@ export declare function outcomeOf(response: unknown): {
48
48
  exitCode?: number;
49
49
  durationMs?: number;
50
50
  };
51
- export declare function buildReport(input: HookInput, findings: CliFinding[], env: Env, declared?: string, decided?: DecidedFinding[], local?: boolean, scripts?: ScriptReader): CliHookReport | null;
51
+ export declare function buildReport(input: HookInput, findings: CliFinding[], env: Env, declared?: string, decided?: DecidedFinding[], local?: boolean, scripts?: ScriptReader, backedUp?: ReadonlySet<CliFinding>): CliHookReport | null;
52
52
  /** What the guard answered, and for which findings. The audit row that
53
53
  * follows a command that ran carries its outcome and any opaque parts. */
54
54
  export declare function buildDecisionReport(input: HookInput, decision: GuardDecision, env: Env, declared?: string, local?: boolean): CliHookReport | null;