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.
- package/README.md +72 -31
- package/dist/approvalNotice.d.ts +73 -0
- package/dist/approvalNotice.js +211 -0
- package/dist/cliArgs.d.ts +1 -1
- package/dist/cliArgs.js +17 -6
- package/dist/cliAutopilot.js +15 -4
- package/dist/cliAutopilotPolicy.d.ts +8 -0
- package/dist/cliAutopilotPolicy.js +23 -1
- package/dist/cliChanges.d.ts +80 -0
- package/dist/cliChanges.js +340 -0
- package/dist/cliClient.d.ts +5 -0
- package/dist/cliClient.js +15 -3
- package/dist/cliExec.js +2 -2
- package/dist/cliHook.d.ts +1 -1
- package/dist/cliHook.js +40 -35
- package/dist/cliHookAudit.d.ts +44 -0
- package/dist/cliHookAudit.js +57 -0
- package/dist/cliHookClients.d.ts +3 -1
- package/dist/cliHookClients.js +1 -1
- package/dist/cliHookDecide.js +3 -1
- package/dist/cliHookDeliver.d.ts +8 -0
- package/dist/cliHookDeliver.js +25 -0
- package/dist/cliHookGuard.d.ts +16 -1
- package/dist/cliHookGuard.js +31 -10
- package/dist/cliHookInput.d.ts +3 -0
- package/dist/cliHookInput.js +13 -0
- package/dist/cliHookLocal.d.ts +3 -2
- package/dist/cliHookLocal.js +5 -2
- package/dist/cliHookNotice.d.ts +22 -0
- package/dist/cliHookNotice.js +49 -0
- package/dist/cliHookRewrite.d.ts +2 -0
- package/dist/cliHookRewrite.js +1 -1
- package/dist/cliKeys.js +11 -1
- package/dist/cliKeysRotate.d.ts +24 -0
- package/dist/cliKeysRotate.js +149 -0
- package/dist/cliMain.js +56 -15
- package/dist/cliOutput.js +41 -5
- package/dist/cliPolicyV2.js +14 -0
- package/dist/cliProjectSummary.d.ts +9 -0
- package/dist/cliProjectSummary.js +134 -0
- package/dist/cliProtocol.d.ts +10 -0
- package/dist/cliProtocol.js +15 -0
- package/dist/cliRequest.d.ts +27 -0
- package/dist/cliRequest.js +92 -0
- package/dist/cliRestoreRequests.d.ts +57 -0
- package/dist/cliRestoreRequests.js +186 -0
- package/dist/cliSessions.d.ts +3 -0
- package/dist/cliSessions.js +24 -1
- package/dist/cliSessionsJson.d.ts +48 -2
- package/dist/cliSessionsJson.js +7 -9
- package/dist/cliSessionsRender.d.ts +8 -3
- package/dist/cliSessionsRender.js +16 -7
- package/dist/cliUndo.d.ts +1 -3
- package/dist/cliUndo.js +9 -15
- package/dist/cliUndoLocal.d.ts +27 -0
- package/dist/cliUndoLocal.js +105 -0
- package/dist/cliUpdate.d.ts +29 -0
- package/dist/cliUpdate.js +195 -0
- package/dist/cliWait.js +2 -2
- package/dist/completion.js +6 -1
- package/dist/doctor.js +4 -0
- package/dist/execNoKey.d.ts +4 -4
- package/dist/execNoKey.js +17 -11
- package/dist/gitBackup.d.ts +111 -0
- package/dist/gitBackup.js +391 -0
- package/dist/gitSnapshot.d.ts +82 -0
- package/dist/gitSnapshot.js +478 -0
- package/dist/holdNotice.js +7 -1
- package/dist/hookMain.js +10 -1
- package/dist/hookPromptFast.d.ts +26 -0
- package/dist/hookPromptFast.js +82 -0
- package/dist/initInstall.d.ts +22 -0
- package/dist/initInstall.js +70 -1
- package/dist/localBackups.d.ts +102 -0
- package/dist/localBackups.js +233 -0
- package/dist/localGit.d.ts +24 -0
- package/dist/localGit.js +44 -0
- package/dist/localRestore.d.ts +42 -0
- package/dist/localRestore.js +94 -0
- package/dist/localTrash.d.ts +97 -0
- package/dist/localTrash.js +394 -0
- package/dist/pluginPin.d.ts +1 -1
- package/dist/pluginPin.js +1 -1
- package/dist/plural.d.ts +2 -0
- package/dist/plural.js +13 -0
- package/dist/regenerable.d.ts +24 -0
- package/dist/regenerable.js +219 -0
- package/dist/selfUpdate.d.ts +92 -0
- package/dist/selfUpdate.js +361 -0
- package/dist/selfUpdateContract.d.ts +20 -0
- package/dist/selfUpdateContract.js +56 -0
- package/dist/updateTrigger.d.ts +18 -0
- package/dist/updateTrigger.js +77 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Late approvals, told to the agent. When a guarded command waits for a
|
|
3
|
+
* person and the agent stops waiting (its turn ended, the session closed),
|
|
4
|
+
* the person can still approve it for a day. That leaves a one-time pass for
|
|
5
|
+
* the same command in the same session, used on the agent's next try.
|
|
6
|
+
*
|
|
7
|
+
* So the agent knows, Claude Code's next hook in that session (SessionStart
|
|
8
|
+
* when it is resumed, or UserPromptSubmit when the person types again) asks
|
|
9
|
+
* Passport what was approved and adds one line of context per approval: what,
|
|
10
|
+
* by whom (a display name), and when. Passport marks each one told, so the
|
|
11
|
+
* agent hears about it once. Nothing runs here: the agent decides whether to
|
|
12
|
+
* run the command again.
|
|
13
|
+
*
|
|
14
|
+
* Every prompt runs this hook, so it asks Passport only for a session this
|
|
15
|
+
* computer saw wait for a person: the guard (and `passport exec`) leaves a
|
|
16
|
+
* small marker per session when it opens a request, and the hook removes it
|
|
17
|
+
* once nothing in the session waits or is left to tell. Codex and Cursor have
|
|
18
|
+
* no such context: their pass is used when the agent tries the command again.
|
|
19
|
+
*
|
|
20
|
+
* Markers are owner-only files named by a digest of the agent and session id,
|
|
21
|
+
* hold only a time, and are bounded in count and age. Never throws.
|
|
22
|
+
*/
|
|
23
|
+
import { createHash } from "node:crypto";
|
|
24
|
+
import { lstatSync, mkdirSync, readdirSync, rmSync, statSync } from "node:fs";
|
|
25
|
+
import { basename, join } from "node:path";
|
|
26
|
+
import { readBoundedJson } from "./boundedResponse.js";
|
|
27
|
+
import { credentialDir, enforceOwner, ensurePrivateDirectory, writePrivateAtomic } from "./credentialStorage.js";
|
|
28
|
+
export const CLI_APPROVED_PATH = "/api/my/cli/approved";
|
|
29
|
+
/** A request stays open a day, and its pass a day after approval. */
|
|
30
|
+
export const MARKER_MAX_AGE_MS = 48 * 60 * 60 * 1000;
|
|
31
|
+
const MAX_MARKERS = 200;
|
|
32
|
+
const MAX_NOTICES = 5;
|
|
33
|
+
const MAX_RESPONSE_BYTES = 16 * 1024;
|
|
34
|
+
const DIRECTORY = "hook-approvals";
|
|
35
|
+
const SESSION = /^[A-Za-z0-9._:-]{1,128}$/;
|
|
36
|
+
const ID = /^[A-Za-z0-9_-]{1,80}$/;
|
|
37
|
+
/** The hook events that can carry context into the agent. */
|
|
38
|
+
export const NOTICE_EVENTS = new Set(["SessionStart", "UserPromptSubmit"]);
|
|
39
|
+
function directory() {
|
|
40
|
+
return join(credentialDir(), DIRECTORY);
|
|
41
|
+
}
|
|
42
|
+
function markerPath(runtime, sessionId) {
|
|
43
|
+
const key = createHash("sha256").update(`${runtime}\u0000${sessionId}`).digest("hex").slice(0, 40);
|
|
44
|
+
return join(directory(), `${key}.json`);
|
|
45
|
+
}
|
|
46
|
+
/** The guard or `passport exec` opened a request a person answers: remember
|
|
47
|
+
* the session, so its next prompt asks Passport. False when it couldn't. */
|
|
48
|
+
export function noteWaitingSession(runtime, sessionId, now = Date.now()) {
|
|
49
|
+
if (runtime !== "claude-code" || !sessionId || !SESSION.test(sessionId))
|
|
50
|
+
return false;
|
|
51
|
+
try {
|
|
52
|
+
ensurePrivateDirectory(true);
|
|
53
|
+
try {
|
|
54
|
+
mkdirSync(directory(), { mode: 0o700 });
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
if (error.code !== "EEXIST")
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
const stat = lstatSync(directory());
|
|
61
|
+
if (stat.isSymbolicLink() || !stat.isDirectory())
|
|
62
|
+
return false;
|
|
63
|
+
enforceOwner(stat, "hook approvals directory");
|
|
64
|
+
const names = readdirSync(directory()).filter((name) => /^[0-9a-f]{40}\.json$/.test(name));
|
|
65
|
+
const path = markerPath(runtime, sessionId);
|
|
66
|
+
if (names.length >= MAX_MARKERS && !names.includes(basename(path)))
|
|
67
|
+
return false;
|
|
68
|
+
writePrivateAtomic(path, ".hook-approval", JSON.stringify({ at: now }), "hook approval");
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/** Whether this session left a marker recently enough to ask about. */
|
|
76
|
+
export function sessionWaited(runtime, sessionId, now = Date.now()) {
|
|
77
|
+
try {
|
|
78
|
+
const stat = statSync(markerPath(runtime, sessionId));
|
|
79
|
+
if (now - stat.mtimeMs <= MARKER_MAX_AGE_MS)
|
|
80
|
+
return true;
|
|
81
|
+
forgetSession(runtime, sessionId);
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
export function forgetSession(runtime, sessionId) {
|
|
89
|
+
try {
|
|
90
|
+
rmSync(markerPath(runtime, sessionId), { force: true });
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
/* Asked again next time: harmless. */
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function text(raw, max) {
|
|
97
|
+
if (typeof raw !== "string")
|
|
98
|
+
return undefined;
|
|
99
|
+
const cleaned = raw
|
|
100
|
+
.replace(/[\u0000-\u001f\u007f-\u009f`]/g, " ")
|
|
101
|
+
.replace(/\s+/g, " ")
|
|
102
|
+
.trim();
|
|
103
|
+
return cleaned ? cleaned.slice(0, max) : undefined;
|
|
104
|
+
}
|
|
105
|
+
function time(raw) {
|
|
106
|
+
return typeof raw === "number" && Number.isSafeInteger(raw) && raw > 0 ? raw : undefined;
|
|
107
|
+
}
|
|
108
|
+
/** Validate what Passport said. Anything unexpected is no answer. */
|
|
109
|
+
export function parseApproved(raw) {
|
|
110
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
|
111
|
+
return null;
|
|
112
|
+
const body = raw;
|
|
113
|
+
if (!Array.isArray(body.approved))
|
|
114
|
+
return null;
|
|
115
|
+
const waiting = typeof body.waiting === "number" && Number.isSafeInteger(body.waiting) ? body.waiting : 0;
|
|
116
|
+
const approved = [];
|
|
117
|
+
for (const entry of body.approved.slice(0, MAX_NOTICES)) {
|
|
118
|
+
if (!entry || typeof entry !== "object")
|
|
119
|
+
continue;
|
|
120
|
+
const item = entry;
|
|
121
|
+
const action = text(item.action, 80);
|
|
122
|
+
const approvedBy = text(item.approvedBy, 80);
|
|
123
|
+
const approvedAt = time(item.approvedAt);
|
|
124
|
+
const expiresAt = time(item.expiresAt);
|
|
125
|
+
if (typeof item.approvalId !== "string" || !ID.test(item.approvalId) || !action || !approvedBy)
|
|
126
|
+
continue;
|
|
127
|
+
if (!approvedAt || !expiresAt)
|
|
128
|
+
continue;
|
|
129
|
+
const command = text(item.command, 200);
|
|
130
|
+
approved.push({
|
|
131
|
+
approvalId: item.approvalId,
|
|
132
|
+
action,
|
|
133
|
+
...(command ? { command } : {}),
|
|
134
|
+
approvedBy: approvedBy.includes("@") ? "a person in your workspace" : approvedBy,
|
|
135
|
+
approvedAt,
|
|
136
|
+
expiresAt
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
return { approved, waiting: Math.max(0, waiting) };
|
|
140
|
+
}
|
|
141
|
+
/** Ask Passport, or null when it couldn't answer in time. Never throws. */
|
|
142
|
+
export async function fetchApproved(api, runtime, sessionId, signal) {
|
|
143
|
+
try {
|
|
144
|
+
const response = await api(CLI_APPROVED_PATH, {
|
|
145
|
+
method: "POST",
|
|
146
|
+
headers: { "content-type": "application/json", accept: "application/json", "x-passport-surface": "cli" },
|
|
147
|
+
body: JSON.stringify({ runtime, sessionId }),
|
|
148
|
+
signal
|
|
149
|
+
});
|
|
150
|
+
if (!response.ok) {
|
|
151
|
+
await response.body?.cancel().catch(() => undefined);
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
return parseApproved(await readBoundedJson(response, MAX_RESPONSE_BYTES));
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/** "40 minutes", "3 hours" (at least a minute). */
|
|
161
|
+
export function span(ms) {
|
|
162
|
+
const minutes = Math.max(1, Math.round(ms / 60_000));
|
|
163
|
+
if (minutes < 90)
|
|
164
|
+
return `${minutes} minute${minutes === 1 ? "" : "s"}`;
|
|
165
|
+
const hours = Math.round(minutes / 60);
|
|
166
|
+
return `${hours} hour${hours === 1 ? "" : "s"}`;
|
|
167
|
+
}
|
|
168
|
+
/** What the agent reads: one line per approval, and what to do about it. */
|
|
169
|
+
export function noticeContext(notices, now) {
|
|
170
|
+
const lines = notices.map((notice) => {
|
|
171
|
+
const what = notice.command ? `${notice.action} (\`${notice.command}\`)` : notice.action;
|
|
172
|
+
const when = new Date(notice.approvedAt).toISOString().slice(0, 16).replace("T", " ");
|
|
173
|
+
return `- ${what}: approved by ${notice.approvedBy} ${span(now - notice.approvedAt)} ago (${when} UTC). The approval lapses in ${span(notice.expiresAt - now)}.`;
|
|
174
|
+
});
|
|
175
|
+
const lead = notices.length === 1
|
|
176
|
+
? "Passport: a command this session asked about earlier was approved after you stopped waiting. It hasn't run."
|
|
177
|
+
: "Passport: commands this session asked about earlier were approved after you stopped waiting. They haven't run.";
|
|
178
|
+
return [
|
|
179
|
+
lead,
|
|
180
|
+
...lines,
|
|
181
|
+
"If it's still needed, run the exact same command again; the approval lets it run once. Otherwise, ignore this."
|
|
182
|
+
].join("\n");
|
|
183
|
+
}
|
|
184
|
+
/** Claude Code's shape for context a hook adds to the conversation. */
|
|
185
|
+
export function contextOutput(event, context) {
|
|
186
|
+
return { hookSpecificOutput: { hookEventName: event, additionalContext: context } };
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* The notice for one hook event, or null. Asks Passport only for a Claude
|
|
190
|
+
* Code session that waited for a person, inside the hook's budget.
|
|
191
|
+
*/
|
|
192
|
+
export async function approvalNotice(input, context) {
|
|
193
|
+
const event = typeof input.hook_event_name === "string" ? input.hook_event_name : "";
|
|
194
|
+
if (!NOTICE_EVENTS.has(event) || context.runtime !== "claude-code" || input.cursor_version !== undefined)
|
|
195
|
+
return null;
|
|
196
|
+
const sessionId = typeof input.session_id === "string" && SESSION.test(input.session_id) ? input.session_id : "";
|
|
197
|
+
if (!sessionId || !sessionWaited(context.runtime, sessionId, context.now()))
|
|
198
|
+
return null;
|
|
199
|
+
const api = await context.openApi().catch(() => null);
|
|
200
|
+
if (!api || context.signal.aborted)
|
|
201
|
+
return null;
|
|
202
|
+
const answer = await fetchApproved(api, context.runtime, sessionId, context.signal);
|
|
203
|
+
if (!answer)
|
|
204
|
+
return null;
|
|
205
|
+
// Nothing waits and nothing is left to tell: stop asking for this session.
|
|
206
|
+
if (answer.waiting === 0 && answer.approved.length < MAX_NOTICES)
|
|
207
|
+
forgetSession(context.runtime, sessionId);
|
|
208
|
+
if (!answer.approved.length)
|
|
209
|
+
return null;
|
|
210
|
+
return contextOutput(event, noticeContext(answer.approved, context.now()));
|
|
211
|
+
}
|
package/dist/cliArgs.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const COMMANDS: readonly ["init", "login", "logout", "profiles", "use", "status", "doctor", "ready", "search", "describe", "run", "connect", "resources", "prompts", "discover", "scan", "hook", "wait", "rules", "actions", "sessions", "env", "sync", "exec", "undo", "keys", "setup", "session", "access", "completion", "help", "version"];
|
|
1
|
+
export declare const COMMANDS: readonly ["init", "login", "logout", "profiles", "use", "status", "doctor", "ready", "search", "describe", "run", "connect", "request", "resources", "prompts", "discover", "scan", "hook", "wait", "rules", "actions", "sessions", "changes", "env", "sync", "exec", "undo", "keys", "setup", "session", "access", "update", "completion", "help", "version"];
|
|
2
2
|
export type Command = (typeof COMMANDS)[number];
|
|
3
3
|
/** Old names that still run for one release, left out of help, completion,
|
|
4
4
|
* and suggestions. `discover` is part of `scan` now. */
|
package/dist/cliArgs.js
CHANGED
|
@@ -12,6 +12,7 @@ export const COMMANDS = [
|
|
|
12
12
|
"describe",
|
|
13
13
|
"run",
|
|
14
14
|
"connect",
|
|
15
|
+
"request",
|
|
15
16
|
"resources",
|
|
16
17
|
"prompts",
|
|
17
18
|
"discover",
|
|
@@ -21,6 +22,7 @@ export const COMMANDS = [
|
|
|
21
22
|
"rules",
|
|
22
23
|
"actions",
|
|
23
24
|
"sessions",
|
|
25
|
+
"changes",
|
|
24
26
|
"env",
|
|
25
27
|
"sync",
|
|
26
28
|
"exec",
|
|
@@ -29,6 +31,7 @@ export const COMMANDS = [
|
|
|
29
31
|
"setup",
|
|
30
32
|
"session",
|
|
31
33
|
"access",
|
|
34
|
+
"update",
|
|
32
35
|
"completion",
|
|
33
36
|
"help",
|
|
34
37
|
"version"
|
|
@@ -47,7 +50,7 @@ const FLAGS = {
|
|
|
47
50
|
help: { kind: "boolean" },
|
|
48
51
|
cloud: { kind: "value", commands: ["login", "init", "setup"] },
|
|
49
52
|
workspace: { kind: "value", commands: ["login", "access"] },
|
|
50
|
-
client: { kind: "value", commands: ["login", "setup", "hook", "exec"] },
|
|
53
|
+
client: { kind: "value", commands: ["login", "setup", "hook", "exec", "changes"] },
|
|
51
54
|
apply: { kind: "boolean", commands: ["setup", "hook"] },
|
|
52
55
|
guard: { kind: "boolean", commands: ["hook"] },
|
|
53
56
|
hold: { kind: "value", commands: ["hook"] },
|
|
@@ -64,7 +67,7 @@ const FLAGS = {
|
|
|
64
67
|
"move-keys": { kind: "boolean", commands: ["init"] },
|
|
65
68
|
"dry-run": { kind: "boolean", commands: ["init"] },
|
|
66
69
|
"ask-again": { kind: "boolean", commands: ["exec"] },
|
|
67
|
-
app: { kind: "value", commands: ["search"] },
|
|
70
|
+
app: { kind: "value", commands: ["search", "changes"] },
|
|
68
71
|
args: { kind: "value", commands: ["run", "actions"] },
|
|
69
72
|
id: { kind: "value", commands: ["actions"] },
|
|
70
73
|
class: { kind: "value", commands: ["actions"] },
|
|
@@ -94,12 +97,19 @@ const FLAGS = {
|
|
|
94
97
|
all: { kind: "boolean", commands: ["sessions"] },
|
|
95
98
|
running: { kind: "boolean", commands: ["sessions"] },
|
|
96
99
|
"production-changes": { kind: "boolean", commands: ["sessions"] },
|
|
97
|
-
project: { kind: "value", commands: ["sessions"] },
|
|
98
|
-
pr: { kind: "value", commands: ["sessions"] },
|
|
99
|
-
since: { kind: "value", commands: ["sessions"] },
|
|
100
|
+
project: { kind: "value", commands: ["sessions", "changes"] },
|
|
101
|
+
pr: { kind: "value", commands: ["sessions", "changes"] },
|
|
102
|
+
since: { kind: "value", commands: ["sessions", "changes"] },
|
|
103
|
+
until: { kind: "value", commands: ["changes"] },
|
|
104
|
+
env: { kind: "value", commands: ["changes"] },
|
|
100
105
|
remove: { kind: "boolean", commands: ["sync", "keys"] },
|
|
101
106
|
last: { kind: "boolean", commands: ["undo"] },
|
|
102
|
-
|
|
107
|
+
local: { kind: "boolean", commands: ["undo"] },
|
|
108
|
+
// The detached check the CLI and hooks start; not for people to type.
|
|
109
|
+
background: { kind: "boolean", commands: ["update"] },
|
|
110
|
+
option: { kind: "value", commands: ["undo"] },
|
|
111
|
+
reason: { kind: "value", commands: ["request"] },
|
|
112
|
+
full: { kind: "boolean", commands: ["request"] }
|
|
103
113
|
};
|
|
104
114
|
/** `--agent` is the documented name; `--client` keeps working everywhere. */
|
|
105
115
|
const FLAG_ALIASES = { agent: "client", agents: "clients" };
|
|
@@ -261,6 +271,7 @@ function validateShape(command, positionals) {
|
|
|
261
271
|
wait: 1,
|
|
262
272
|
rules: 2,
|
|
263
273
|
sessions: 1,
|
|
274
|
+
changes: 0,
|
|
264
275
|
env: 4,
|
|
265
276
|
sync: 0,
|
|
266
277
|
undo: 1,
|
package/dist/cliAutopilot.js
CHANGED
|
@@ -61,10 +61,17 @@ function ruleTestLines(term, label, result, source) {
|
|
|
61
61
|
label,
|
|
62
62
|
` ${mark(term, DECISION_MARKS[result.decision])} ${explanation}`,
|
|
63
63
|
...(environment ? [` Environment: ${environment}`] : []),
|
|
64
|
-
...(result.actionClass ? [` Class: ${
|
|
64
|
+
...(result.actionClass ? [` Class: ${classLine(result)}`] : []),
|
|
65
65
|
...indented(source)
|
|
66
66
|
];
|
|
67
67
|
}
|
|
68
|
+
/** "Change", or "Change, decided like a Delete" for one a safety pack raises.
|
|
69
|
+
* An older server sends a raised change as a Delete with no `treatedAs`. */
|
|
70
|
+
function classLine(result) {
|
|
71
|
+
if (result.treatedAs)
|
|
72
|
+
return `${CLASS_LABEL.change}, decided like a ${CLASS_LABEL.delete}`;
|
|
73
|
+
return CLASS_LABEL[result.actionClass];
|
|
74
|
+
}
|
|
68
75
|
/** Place every finding in the environment the person picked. */
|
|
69
76
|
function inEnvironment(findings, environment) {
|
|
70
77
|
if (!environment)
|
|
@@ -84,7 +91,11 @@ function localTest(command, findings, complete, policy, machine) {
|
|
|
84
91
|
...(decision.cause ? { cause: decision.cause } : {}),
|
|
85
92
|
...(decision.environment ? { environment: decision.environment } : {}),
|
|
86
93
|
...(decision.environmentSource === "assumed" ? { environmentAssumed: true } : {}),
|
|
87
|
-
...(decision.
|
|
94
|
+
...(decision.treatedAs
|
|
95
|
+
? { actionClass: "change", treatedAs: decision.treatedAs }
|
|
96
|
+
: decision.actionClass
|
|
97
|
+
? { actionClass: decision.actionClass }
|
|
98
|
+
: {})
|
|
88
99
|
};
|
|
89
100
|
}
|
|
90
101
|
/**
|
|
@@ -194,7 +205,7 @@ export async function rules(args, runtime, deps = {}) {
|
|
|
194
205
|
// The server knows grants, every rule, and the workspace's environments.
|
|
195
206
|
const asked = profile || deps.api ? await askServer(testBody(lead, label, target, environment), args, runtime, deps) : null;
|
|
196
207
|
let result = asked;
|
|
197
|
-
let source = result ? "Decided by your workspace's rules." : "";
|
|
208
|
+
let source = result ? (result.decision === "none" ? "" : "Decided by your workspace's rules.") : "";
|
|
198
209
|
if (!result) {
|
|
199
210
|
result = local ?? { decision: "none" };
|
|
200
211
|
source = cached
|
|
@@ -204,7 +215,7 @@ export async function rules(args, runtime, deps = {}) {
|
|
|
204
215
|
: "Decided on this computer from built-in rules. Sign in to use yours.\nRun: passport login";
|
|
205
216
|
}
|
|
206
217
|
return {
|
|
207
|
-
json: { command: label, ...result, source:
|
|
218
|
+
json: { command: label, ...result, source: asked ? "server" : "local" },
|
|
208
219
|
human: ruleTestLines(termOf(runtime.stdout, runtime.env), label, result, source).join("\n")
|
|
209
220
|
};
|
|
210
221
|
}
|
|
@@ -175,6 +175,10 @@ export type AutopilotPolicy = {
|
|
|
175
175
|
* repository name (lowercase): Production for one that deploys on merge.
|
|
176
176
|
* Present only when the server places git and gh by reach (`localReach.ts`). */
|
|
177
177
|
repos?: Record<string, EnvKind>;
|
|
178
|
+
/** Rows where this person's Hands-off deletes run without a backup. Present
|
|
179
|
+
* only when the server asks before a Hands-off shell delete nothing can
|
|
180
|
+
* back up (`backupGate`); an older server sends nothing and nothing changes. */
|
|
181
|
+
withoutBackup?: Partial<Record<"staging" | "development" | "other", true>>;
|
|
178
182
|
/** Known project scripts (Batch A item 5), vendor `project`: they set class
|
|
179
183
|
* and environment only, never an allow. */
|
|
180
184
|
project?: {
|
|
@@ -211,6 +215,8 @@ export type ActionFacts = {
|
|
|
211
215
|
verb: string;
|
|
212
216
|
actionClass: ActionClass;
|
|
213
217
|
environment: ActionEnv;
|
|
218
|
+
/** This computer takes a backup first (`localBackups.ts`). */
|
|
219
|
+
backup?: boolean;
|
|
214
220
|
};
|
|
215
221
|
export type LocalDecision = {
|
|
216
222
|
decision: Decision;
|
|
@@ -223,6 +229,8 @@ export declare function accessRecordFor(policy: AutopilotPolicy, vendor: string)
|
|
|
223
229
|
/** The server's `decideAction`, minus grants (only the server knows them).
|
|
224
230
|
* The access ceiling comes first and nothing lifts it; the second-person rule
|
|
225
231
|
* turns a Production run into an ask the server owns. */
|
|
232
|
+
/** Checked copy of shared/undoContract.ts `UNDO_COPY.askCause` (cliAutopilotPolicy.test.ts). */
|
|
233
|
+
export declare const NO_BACKUP_CAUSE = "Couldn't take a backup first";
|
|
226
234
|
export declare function decideAction(policy: AutopilotPolicy, facts: ActionFacts): LocalDecision;
|
|
227
235
|
/** Whether an ask needs someone other than the person at the keyboard. */
|
|
228
236
|
export declare function needsSecondPerson(cause: Cause | undefined): boolean;
|
|
@@ -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
|
-
|
|
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>;
|