passport-bridge 0.13.2 → 0.14.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 +92 -17
- package/dist/cli.js +4 -3
- package/dist/cliArgs.d.ts +1 -1
- package/dist/cliArgs.js +21 -5
- package/dist/cliAutopilot.d.ts +60 -0
- package/dist/cliAutopilot.js +389 -0
- package/dist/cliAutopilotPolicy.d.ts +94 -0
- package/dist/cliAutopilotPolicy.js +193 -0
- package/dist/cliClient.d.ts +7 -0
- package/dist/cliClient.js +36 -19
- package/dist/cliHook.d.ts +20 -9
- package/dist/cliHook.js +125 -32
- package/dist/cliHookClassify.d.ts +3 -0
- package/dist/cliHookClassify.js +2 -1
- package/dist/cliHookDecide.d.ts +89 -0
- package/dist/cliHookDecide.js +167 -0
- package/dist/cliHookEnvironment.d.ts +55 -0
- package/dist/cliHookEnvironment.js +219 -0
- package/dist/cliHookGuard.d.ts +61 -12
- package/dist/cliHookGuard.js +211 -24
- package/dist/cliHookInstall.js +19 -4
- package/dist/cliHookMode.d.ts +31 -0
- package/dist/cliHookMode.js +50 -0
- package/dist/cliHookRedact.d.ts +16 -0
- package/dist/cliHookRedact.js +136 -0
- package/dist/cliInit.d.ts +4 -1
- package/dist/cliInit.js +10 -3
- package/dist/cliLogin.js +18 -2
- package/dist/cliOffline.js +9 -9
- package/dist/cliOutput.js +11 -5
- package/dist/cliPolicy.d.ts +11 -3
- package/dist/cliPolicy.js +5 -2
- package/dist/cliPolicyV2.d.ts +18 -0
- package/dist/cliPolicyV2.js +234 -0
- package/dist/cliSetupOrg.d.ts +15 -0
- package/dist/cliSetupOrg.js +241 -0
- package/dist/cliSupport.d.ts +4 -0
- package/dist/cliSupport.js +12 -9
- package/dist/completion.js +12 -3
- package/dist/doctor.js +3 -3
- package/dist/enrollment.d.ts +18 -0
- package/dist/enrollment.js +79 -0
- package/dist/hookPlugin.d.ts +7 -0
- package/dist/hookPlugin.js +54 -0
- package/dist/initAgents.d.ts +3 -1
- package/dist/initAgents.js +7 -3
- package/dist/initAutopilotStep.d.ts +24 -0
- package/dist/initAutopilotStep.js +257 -0
- package/dist/initLocalSteps.d.ts +3 -0
- package/dist/initLocalSteps.js +30 -5
- package/dist/initState.d.ts +24 -0
- package/dist/initUi.js +5 -0
- package/dist/passport.js +27 -3
- package/dist/pluginPin.d.ts +7 -0
- package/dist/pluginPin.js +7 -0
- package/dist/universalUrl.d.ts +28 -0
- package/dist/universalUrl.js +59 -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
package/dist/cliHookGuard.js
CHANGED
|
@@ -1,15 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The guard's decision and the one line each agent shows for it.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* With a v2 (Autopilot) policy the guard answers allow, ask, or deny:
|
|
5
|
+
*
|
|
6
|
+
* - **allow** only when every command in the line is a vendor command Passport
|
|
7
|
+
* recognizes and every one is allowed. Anything it can't read (a script, a
|
|
8
|
+
* pipe into another program, a substitution, a redirect) means no decision,
|
|
9
|
+
* so the agent's own permission rules apply. Codex can't receive allow.
|
|
10
|
+
* - **ask** or **deny** when any recognized command needs it; the strictest
|
|
11
|
+
* wins and names itself.
|
|
12
|
+
*
|
|
13
|
+
* With a v1 policy (an older server) or none at all, the guard keeps its old
|
|
14
|
+
* shape: ask or deny, never allow.
|
|
9
15
|
*/
|
|
16
|
+
import { decideAction, decisionRank } from "./cliAutopilotPolicy.js";
|
|
17
|
+
import { ENV_LABEL, environmentHintWith, reportedEnvironment } from "./cliHookEnvironment.js";
|
|
18
|
+
import { normalizeArgv, splitCommands } from "./cliHookParse.js";
|
|
10
19
|
import { VENDORS } from "./cliHookVendors.js";
|
|
11
|
-
const RANK = { ask: 1, deny: 2 };
|
|
20
|
+
const RANK = { allow: 0, ask: 1, deny: 2 };
|
|
12
21
|
const LABEL_TOKEN = /^-{0,2}[A-Za-z0-9][A-Za-z0-9._:+-]{0,39}$/;
|
|
22
|
+
/** Shell features that hide what will run. Any of them: no allow. */
|
|
23
|
+
const OPAQUE_SHELL = /[<>`$\\\n]|\$\(/;
|
|
24
|
+
/** Built in, whatever the server sends: these can't be taken back. */
|
|
25
|
+
const BUILT_IN_IRREVERSIBLE = { gh: ["repo delete"] };
|
|
26
|
+
/** Classes the guard decides; anything else (http, api, sql, local) is no decision. */
|
|
27
|
+
const CLASS_OF_RISK = { read: "read", write: "change", destructive: "delete" };
|
|
13
28
|
/** `fly` and `flyctl` share one map; the server may key either spelling. */
|
|
14
29
|
function vendorKeys(vendor) {
|
|
15
30
|
const spec = Object.hasOwn(VENDORS, vendor) ? VENDORS[vendor] : undefined;
|
|
@@ -37,8 +52,12 @@ export function guardLabel(finding) {
|
|
|
37
52
|
function speculative(finding) {
|
|
38
53
|
return finding.note?.includes("spawn call not confirmed") === true;
|
|
39
54
|
}
|
|
40
|
-
function
|
|
41
|
-
|
|
55
|
+
function decidable(finding) {
|
|
56
|
+
return Boolean(finding.vendor && finding.verb) && !finding.inert && !speculative(finding);
|
|
57
|
+
}
|
|
58
|
+
// ---- v1: ask or deny, never allow -------------------------------------------
|
|
59
|
+
function verdictV1(finding, policy) {
|
|
60
|
+
if (!decidable(finding))
|
|
42
61
|
return null;
|
|
43
62
|
if (finding.risk === "local" || finding.risk === "unknown")
|
|
44
63
|
return null;
|
|
@@ -51,11 +70,10 @@ function verdictOf(finding, policy) {
|
|
|
51
70
|
return "ask";
|
|
52
71
|
return null;
|
|
53
72
|
}
|
|
54
|
-
|
|
55
|
-
export function decideGuard(findings, policy) {
|
|
73
|
+
function decideV1(findings, policy) {
|
|
56
74
|
const decided = [];
|
|
57
75
|
for (const finding of findings) {
|
|
58
|
-
const verdict =
|
|
76
|
+
const verdict = verdictV1(finding, policy);
|
|
59
77
|
if (verdict)
|
|
60
78
|
decided.push({ finding, verdict });
|
|
61
79
|
}
|
|
@@ -72,56 +90,225 @@ export function decideGuard(findings, policy) {
|
|
|
72
90
|
destructive: top.finding.risk === "destructive"
|
|
73
91
|
};
|
|
74
92
|
}
|
|
93
|
+
// ---- v2: Autopilot ----------------------------------------------------------
|
|
94
|
+
function listed(map, vendor, verb) {
|
|
95
|
+
if (!map)
|
|
96
|
+
return false;
|
|
97
|
+
return vendorKeys(vendor).some((key) => Object.hasOwn(map, key) && map[key].includes(verb));
|
|
98
|
+
}
|
|
99
|
+
/** Read, Change, Delete, or Irreversible, as the server's packs define them. */
|
|
100
|
+
function classOf(policy, finding, verb, environment) {
|
|
101
|
+
const { autopilot } = policy;
|
|
102
|
+
// The server's `cliActionClass`: a read is a read, whatever lists it.
|
|
103
|
+
if (finding.risk === "read")
|
|
104
|
+
return "read";
|
|
105
|
+
if (listed(autopilot.irreversible, finding.vendor, verb) || listed(BUILT_IN_IRREVERSIBLE, finding.vendor, verb)) {
|
|
106
|
+
return "irreversible";
|
|
107
|
+
}
|
|
108
|
+
if (environment === "production" && listed(autopilot.irreversibleInProduction, finding.vendor, verb)) {
|
|
109
|
+
return "irreversible";
|
|
110
|
+
}
|
|
111
|
+
// Force-pushing the default branch rewrites history others already have.
|
|
112
|
+
if (finding.vendor === "git" && verb === "push --force" && environment === "production")
|
|
113
|
+
return "irreversible";
|
|
114
|
+
const base = CLASS_OF_RISK[finding.risk] ?? "delete";
|
|
115
|
+
return base === "change" && listed(autopilot.deletes, finding.vendor, verb) ? "delete" : base;
|
|
116
|
+
}
|
|
117
|
+
/** One recognized command's decision, or null when Autopilot has no opinion. */
|
|
118
|
+
export function decideFinding(finding, policy) {
|
|
119
|
+
if (!decidable(finding))
|
|
120
|
+
return null;
|
|
121
|
+
// SQL is read from a regex; only a destructive statement gets an opinion.
|
|
122
|
+
if (finding.vendor === "psql" ? finding.risk !== "destructive" : !CLASS_OF_RISK[finding.risk])
|
|
123
|
+
return null;
|
|
124
|
+
const hint = environmentHintWith(finding.vendor, finding.args ?? [], {
|
|
125
|
+
flags: policy.autopilot.environmentFlags,
|
|
126
|
+
known: policy.autopilot.environments
|
|
127
|
+
});
|
|
128
|
+
const verb = finding.verbKey ?? finding.verb;
|
|
129
|
+
const actionClass = classOf(policy, finding, verb, hint.kind);
|
|
130
|
+
const { decision, cause } = decideAction(policy.autopilot, {
|
|
131
|
+
vendor: finding.vendor,
|
|
132
|
+
verb,
|
|
133
|
+
actionClass,
|
|
134
|
+
environment: hint.kind
|
|
135
|
+
});
|
|
136
|
+
const reported = reportedEnvironment(hint);
|
|
137
|
+
return {
|
|
138
|
+
finding,
|
|
139
|
+
decision,
|
|
140
|
+
cause,
|
|
141
|
+
environment: hint.kind,
|
|
142
|
+
environmentSource: hint.source,
|
|
143
|
+
...(reported ? { reported } : {}),
|
|
144
|
+
actionClass
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Every simple command in the line is a vendor command the classifier read
|
|
149
|
+
* with confidence, with nothing hidden from it: no substitutions, redirects,
|
|
150
|
+
* variables, wrappers, heredocs, or environment prefixes.
|
|
151
|
+
*/
|
|
152
|
+
export function fullyRecognized(command, findings) {
|
|
153
|
+
if (OPAQUE_SHELL.test(command))
|
|
154
|
+
return false;
|
|
155
|
+
const { commands, nested } = splitCommands(command);
|
|
156
|
+
if (nested.length || !commands.length || commands.length !== findings.length)
|
|
157
|
+
return false;
|
|
158
|
+
for (const raw of commands) {
|
|
159
|
+
const { argv, via, envInjected } = normalizeArgv(raw);
|
|
160
|
+
if (!argv.length || envInjected.length || via.some((step) => step !== "absolute-path"))
|
|
161
|
+
return false;
|
|
162
|
+
if (!Object.hasOwn(VENDORS, argv[0]))
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
return findings.every((finding) => decidable(finding) &&
|
|
166
|
+
finding.confidence !== "low" &&
|
|
167
|
+
finding.via.every((step) => step === "absolute-path") &&
|
|
168
|
+
Boolean(CLASS_OF_RISK[finding.risk]) &&
|
|
169
|
+
finding.vendor !== "psql");
|
|
170
|
+
}
|
|
171
|
+
function verdictOf(decision) {
|
|
172
|
+
return decision === "block" ? "deny" : decision;
|
|
173
|
+
}
|
|
174
|
+
function decideV2(command, findings, policy) {
|
|
175
|
+
const decided = findings.map((finding) => decideFinding(finding, policy)).filter((entry) => entry !== null);
|
|
176
|
+
if (!decided.length)
|
|
177
|
+
return null;
|
|
178
|
+
const strictest = decided
|
|
179
|
+
.map((entry, index) => ({ entry, index }))
|
|
180
|
+
.sort((a, b) => decisionRank(b.entry.decision) - decisionRank(a.entry.decision) || a.index - b.index)[0].entry;
|
|
181
|
+
// Allow only when the whole line is understood and every part is allowed.
|
|
182
|
+
if (strictest.decision === "allow" && !fullyRecognized(command, findings))
|
|
183
|
+
return null;
|
|
184
|
+
if (strictest.decision === "allow" && decided.length !== findings.length)
|
|
185
|
+
return null;
|
|
186
|
+
// Strictest first; an allow lists every command, anything else only the ones that carried it.
|
|
187
|
+
const ordered = [...decided]
|
|
188
|
+
.filter((entry) => strictest.decision === "allow" || entry.decision !== "allow")
|
|
189
|
+
.sort((a, b) => decisionRank(b.decision) - decisionRank(a.decision));
|
|
190
|
+
return {
|
|
191
|
+
verdict: verdictOf(strictest.decision),
|
|
192
|
+
label: guardLabel(strictest.finding),
|
|
193
|
+
findings: ordered.map((entry) => entry.finding),
|
|
194
|
+
destructive: strictest.finding.risk === "destructive",
|
|
195
|
+
cause: strictest.cause,
|
|
196
|
+
environment: strictest.environment,
|
|
197
|
+
environmentSource: strictest.environmentSource,
|
|
198
|
+
actionClass: strictest.actionClass,
|
|
199
|
+
decided
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
/** The strictest verdict across every command in the line wins. */
|
|
203
|
+
export function decideGuard(findings, policy, command = "") {
|
|
204
|
+
if (policy?.version === 2)
|
|
205
|
+
return decideV2(command, findings, policy);
|
|
206
|
+
return decideV1(findings, policy);
|
|
207
|
+
}
|
|
208
|
+
// ---- What the agent shows ---------------------------------------------------
|
|
209
|
+
const EFFECT = {
|
|
210
|
+
read: (env) => `reads ${env}`,
|
|
211
|
+
change: (env) => `changes ${env}`,
|
|
212
|
+
delete: (env) => `deletes from ${env}`,
|
|
213
|
+
irreversible: (env) => `can't be undone in ${env}`
|
|
214
|
+
};
|
|
215
|
+
function assumedNote(decision) {
|
|
216
|
+
return decision.environmentSource === "assumed" ? " Environment unknown, treated as Production." : "";
|
|
217
|
+
}
|
|
75
218
|
export function askMessage(decision) {
|
|
219
|
+
if (decision.cause && decision.environment && decision.actionClass) {
|
|
220
|
+
const effect = EFFECT[decision.actionClass](ENV_LABEL[decision.environment]);
|
|
221
|
+
const because = decision.cause.kind === "preset" ? "" : ` ${decision.cause.label}.`;
|
|
222
|
+
return `Passport: ${decision.label} ${effect}.${because}${assumedNote(decision)} Approve to run it.`;
|
|
223
|
+
}
|
|
76
224
|
return decision.destructive
|
|
77
225
|
? `Passport: ${decision.label} is destructive. Run it only if you meant to.`
|
|
78
226
|
: `Passport: your safety settings ask before ${decision.label}. Run it only if you meant to.`;
|
|
79
227
|
}
|
|
80
|
-
export function denyMessage(decision) {
|
|
228
|
+
export function denyMessage(decision, owner) {
|
|
229
|
+
if (decision.cause) {
|
|
230
|
+
const mine = decision.cause.label.startsWith("Your rule");
|
|
231
|
+
const next = mine
|
|
232
|
+
? "Change it in Passport Rules."
|
|
233
|
+
: `${owner ? `Ask ${owner} to run it` : "Ask an admin to run it"}, or request an exception in Passport.`;
|
|
234
|
+
return `Blocked by Passport: ${decision.cause.label}. ${next}`;
|
|
235
|
+
}
|
|
81
236
|
return `Passport: your safety settings block ${decision.label}. Change this in Passport Settings → Safety.`;
|
|
82
237
|
}
|
|
238
|
+
export function allowReason(decision) {
|
|
239
|
+
return `Passport: ${decision.cause?.label ?? "allowed by your rules"}.`;
|
|
240
|
+
}
|
|
83
241
|
export const DENY_AGENT_MESSAGE = "Blocked by Passport safety settings. Ask the user to run this command themselves.";
|
|
242
|
+
/** What the agent reads when an unattended ask became an approval request. */
|
|
243
|
+
export function waitingMessage(approvalId, approver) {
|
|
244
|
+
return `Waiting for approval from ${approver ?? "your approver"}. Run \`passport wait ${approvalId}\` to wait, or continue with other work.`;
|
|
245
|
+
}
|
|
246
|
+
/** Appended when the server couldn't be reached and this machine decided. */
|
|
247
|
+
export const OFFLINE_NOTE = "Passport couldn't be reached, so this computer decided.";
|
|
248
|
+
function withNote(text, note) {
|
|
249
|
+
return note ? `${text} ${note}` : text;
|
|
250
|
+
}
|
|
84
251
|
/**
|
|
85
252
|
* The exact stdout each agent reads, or null for nothing at all.
|
|
86
253
|
*
|
|
87
254
|
* - Claude Code shows an ask reason in its permission prompt; a deny reason
|
|
88
255
|
* goes to the model, so the person gets the deny line as a system message.
|
|
89
|
-
*
|
|
90
|
-
*
|
|
256
|
+
* An allow skips the prompt.
|
|
257
|
+
* - Codex supports deny only. It parses "ask" and fails the hook, and its allow
|
|
258
|
+
* is for rewriting a command, so the guard stays silent otherwise and
|
|
259
|
+
* Codex's own approval policy applies.
|
|
91
260
|
* - Cursor's beforeShellExecution takes a flat, snake_case response.
|
|
92
261
|
*/
|
|
93
|
-
export function guardOutput(client, decision) {
|
|
262
|
+
export function guardOutput(client, decision, options = {}) {
|
|
263
|
+
const verdict = options.waiting ? "deny" : decision.verdict;
|
|
264
|
+
const deny = withNote(options.waiting ?? denyMessage(decision, options.owner), options.note);
|
|
265
|
+
const agentDeny = options.waiting ?? (decision.cause ? deny : DENY_AGENT_MESSAGE);
|
|
94
266
|
if (client === "cursor") {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
267
|
+
if (verdict === "allow")
|
|
268
|
+
return { permission: "allow" };
|
|
269
|
+
return verdict === "deny"
|
|
270
|
+
? { permission: "deny", user_message: deny, agent_message: agentDeny }
|
|
271
|
+
: { permission: "ask", user_message: withNote(askMessage(decision), options.note) };
|
|
98
272
|
}
|
|
99
273
|
if (client === "codex") {
|
|
100
|
-
if (
|
|
274
|
+
if (verdict !== "deny")
|
|
101
275
|
return null;
|
|
102
276
|
return {
|
|
103
277
|
hookSpecificOutput: {
|
|
104
278
|
hookEventName: "PreToolUse",
|
|
105
279
|
permissionDecision: "deny",
|
|
106
280
|
// Codex has no separate line for the person, so the model relays both.
|
|
107
|
-
permissionDecisionReason:
|
|
281
|
+
permissionDecisionReason: options.waiting
|
|
282
|
+
? deny
|
|
283
|
+
: decision.cause
|
|
284
|
+
? deny
|
|
285
|
+
: `${denyMessage(decision)} Ask the user to run it themselves.`
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
if (verdict === "allow") {
|
|
290
|
+
return {
|
|
291
|
+
hookSpecificOutput: {
|
|
292
|
+
hookEventName: "PreToolUse",
|
|
293
|
+
permissionDecision: "allow",
|
|
294
|
+
permissionDecisionReason: allowReason(decision)
|
|
108
295
|
}
|
|
109
296
|
};
|
|
110
297
|
}
|
|
111
|
-
return
|
|
298
|
+
return verdict === "deny"
|
|
112
299
|
? {
|
|
113
|
-
systemMessage:
|
|
300
|
+
systemMessage: deny,
|
|
114
301
|
hookSpecificOutput: {
|
|
115
302
|
hookEventName: "PreToolUse",
|
|
116
303
|
permissionDecision: "deny",
|
|
117
|
-
permissionDecisionReason:
|
|
304
|
+
permissionDecisionReason: agentDeny
|
|
118
305
|
}
|
|
119
306
|
}
|
|
120
307
|
: {
|
|
121
308
|
hookSpecificOutput: {
|
|
122
309
|
hookEventName: "PreToolUse",
|
|
123
310
|
permissionDecision: "ask",
|
|
124
|
-
permissionDecisionReason: askMessage(decision)
|
|
311
|
+
permissionDecisionReason: withNote(askMessage(decision), options.note)
|
|
125
312
|
}
|
|
126
313
|
};
|
|
127
314
|
}
|
package/dist/cliHookInstall.js
CHANGED
|
@@ -18,6 +18,7 @@ import { homedir } from "node:os";
|
|
|
18
18
|
import { dirname, join } from "node:path";
|
|
19
19
|
import { bool } from "./cliArgs.js";
|
|
20
20
|
import { readCliPolicy } from "./cliPolicy.js";
|
|
21
|
+
import { coveredByPlugin, pluginInstalled } from "./hookPlugin.js";
|
|
21
22
|
import { readCreds } from "./credentials.js";
|
|
22
23
|
import { failure, selectStoredProfile } from "./cliSupport.js";
|
|
23
24
|
export const HOOK_CLIENTS = ["claude-code", "codex", "cursor"];
|
|
@@ -359,6 +360,14 @@ export function applyGuardInstall(plan, env, invocation) {
|
|
|
359
360
|
}
|
|
360
361
|
function installClient(spec, args, runtime) {
|
|
361
362
|
const path = spec.path(runtime.env);
|
|
363
|
+
// The plugin runs the same hooks; adding them here would record twice.
|
|
364
|
+
if (pluginInstalled(spec.id, runtime.env)) {
|
|
365
|
+
return {
|
|
366
|
+
json: { ok: true, action: "install", client: spec.id, path, changed: false, coveredByPlugin: true },
|
|
367
|
+
human: coveredByPlugin(spec.name),
|
|
368
|
+
essential: true
|
|
369
|
+
};
|
|
370
|
+
}
|
|
362
371
|
const { settings } = readSettings(path);
|
|
363
372
|
const guard = bool(args, "guard");
|
|
364
373
|
const wanted = wantedEntries(spec, runtime.env, guard);
|
|
@@ -437,12 +446,17 @@ function clientStatus(spec, env) {
|
|
|
437
446
|
catch {
|
|
438
447
|
mode = "unreadable";
|
|
439
448
|
}
|
|
449
|
+
// The plugin's hooks live in the agent's plugin folder, not this file.
|
|
450
|
+
const plugin = pluginInstalled(spec.id, env);
|
|
451
|
+
if (plugin && mode !== "audit + guard")
|
|
452
|
+
mode = "via plugin";
|
|
440
453
|
return {
|
|
441
454
|
client: spec.id,
|
|
442
455
|
name: spec.name,
|
|
443
456
|
mode,
|
|
444
|
-
registered: audit !== null,
|
|
445
|
-
guard: guard !== null,
|
|
457
|
+
registered: audit !== null || plugin,
|
|
458
|
+
guard: guard !== null || plugin,
|
|
459
|
+
plugin,
|
|
446
460
|
command: audit,
|
|
447
461
|
guardCommand: guard,
|
|
448
462
|
path,
|
|
@@ -477,14 +491,15 @@ function policyStatus(args, env, now) {
|
|
|
477
491
|
? "Safety settings: built-in, asks before destructive commands (not signed in)."
|
|
478
492
|
: !cached
|
|
479
493
|
? "Safety settings: built-in until synced. Run passport status to sync."
|
|
480
|
-
:
|
|
494
|
+
: `${cached.version === 2 ? "Autopilot rules" : "Safety settings"}: synced ${ageText(ageMs ?? 0)} for ${profile}.`;
|
|
481
495
|
return {
|
|
482
496
|
json: {
|
|
483
497
|
profile: profile ?? null,
|
|
484
498
|
source: cached ? "synced" : "built-in",
|
|
485
499
|
fetchedAt: cached?.fetchedAt ?? null,
|
|
486
500
|
ageMs,
|
|
487
|
-
safetyProfile: cached?.profile
|
|
501
|
+
safetyProfile: cached?.version === 1 ? cached.profile : null,
|
|
502
|
+
policyVersion: cached?.version ?? null
|
|
488
503
|
},
|
|
489
504
|
line
|
|
490
505
|
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Is a person at the keyboard to answer a prompt? Attended runs get the
|
|
3
|
+
* agent's own prompt with Passport's reason; unattended runs get an approval
|
|
4
|
+
* request someone answers on the web or their phone.
|
|
5
|
+
*
|
|
6
|
+
* Signals, strongest first (each verified against the client's own docs or
|
|
7
|
+
* build, October 2026):
|
|
8
|
+
*
|
|
9
|
+
* - `PASSPORT_HOOK_MODE=attended|unattended` overrides everything.
|
|
10
|
+
* - Claude Code passes `CLAUDE_CODE_SESSION_ATTENDED` ("1" or "0") to every
|
|
11
|
+
* hook. Older builds don't, so `CLAUDE_CODE_ENTRYPOINT` of `sdk-cli`
|
|
12
|
+
* (`claude -p`), `sdk-ts`, `sdk-py`, or `claude-code-github-action` means
|
|
13
|
+
* headless. Hook input `permission_mode` of `dontAsk` or
|
|
14
|
+
* `bypassPermissions` suppresses prompts (Claude Code and Codex).
|
|
15
|
+
* - Codex has no ask at all and no field for `codex exec`; its prompt-free
|
|
16
|
+
* modes (`dontAsk`, `bypassPermissions`) count as unattended.
|
|
17
|
+
* - Cursor sets `is_background_agent: true` for background and cloud agents,
|
|
18
|
+
* where ask is not enforced.
|
|
19
|
+
* - `CI` (or a CI provider's own variable) means nobody is watching.
|
|
20
|
+
*/
|
|
21
|
+
import type { Env } from "./cliSupport.js";
|
|
22
|
+
export type HookMode = "attended" | "unattended";
|
|
23
|
+
export type ModeSignal = "override" | "claude-attended" | "claude-entrypoint" | "permission-mode" | "background-agent" | "ci" | "default";
|
|
24
|
+
export type ModeInput = {
|
|
25
|
+
permission_mode?: unknown;
|
|
26
|
+
is_background_agent?: unknown;
|
|
27
|
+
};
|
|
28
|
+
export declare function detectMode(input: ModeInput, env: Env): {
|
|
29
|
+
mode: HookMode;
|
|
30
|
+
signal: ModeSignal;
|
|
31
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Is a person at the keyboard to answer a prompt? Attended runs get the
|
|
3
|
+
* agent's own prompt with Passport's reason; unattended runs get an approval
|
|
4
|
+
* request someone answers on the web or their phone.
|
|
5
|
+
*
|
|
6
|
+
* Signals, strongest first (each verified against the client's own docs or
|
|
7
|
+
* build, October 2026):
|
|
8
|
+
*
|
|
9
|
+
* - `PASSPORT_HOOK_MODE=attended|unattended` overrides everything.
|
|
10
|
+
* - Claude Code passes `CLAUDE_CODE_SESSION_ATTENDED` ("1" or "0") to every
|
|
11
|
+
* hook. Older builds don't, so `CLAUDE_CODE_ENTRYPOINT` of `sdk-cli`
|
|
12
|
+
* (`claude -p`), `sdk-ts`, `sdk-py`, or `claude-code-github-action` means
|
|
13
|
+
* headless. Hook input `permission_mode` of `dontAsk` or
|
|
14
|
+
* `bypassPermissions` suppresses prompts (Claude Code and Codex).
|
|
15
|
+
* - Codex has no ask at all and no field for `codex exec`; its prompt-free
|
|
16
|
+
* modes (`dontAsk`, `bypassPermissions`) count as unattended.
|
|
17
|
+
* - Cursor sets `is_background_agent: true` for background and cloud agents,
|
|
18
|
+
* where ask is not enforced.
|
|
19
|
+
* - `CI` (or a CI provider's own variable) means nobody is watching.
|
|
20
|
+
*/
|
|
21
|
+
const HEADLESS_ENTRYPOINTS = new Set(["sdk-cli", "sdk-ts", "sdk-py", "claude-code-github-action"]);
|
|
22
|
+
const PROMPT_FREE_MODES = new Set(["dontAsk", "bypassPermissions"]);
|
|
23
|
+
const CI_VARIABLES = ["GITHUB_ACTIONS", "GITLAB_CI", "BUILDKITE", "CIRCLECI", "JENKINS_URL", "TF_BUILD"];
|
|
24
|
+
function truthy(value) {
|
|
25
|
+
if (value === undefined)
|
|
26
|
+
return false;
|
|
27
|
+
const normalized = value.trim().toLowerCase();
|
|
28
|
+
return normalized !== "" && normalized !== "0" && normalized !== "false" && normalized !== "no";
|
|
29
|
+
}
|
|
30
|
+
export function detectMode(input, env) {
|
|
31
|
+
const override = env.PASSPORT_HOOK_MODE?.trim().toLowerCase();
|
|
32
|
+
if (override === "attended" || override === "unattended")
|
|
33
|
+
return { mode: override, signal: "override" };
|
|
34
|
+
if (input.is_background_agent === true)
|
|
35
|
+
return { mode: "unattended", signal: "background-agent" };
|
|
36
|
+
if (typeof input.permission_mode === "string" && PROMPT_FREE_MODES.has(input.permission_mode)) {
|
|
37
|
+
return { mode: "unattended", signal: "permission-mode" };
|
|
38
|
+
}
|
|
39
|
+
const attended = env.CLAUDE_CODE_SESSION_ATTENDED?.trim();
|
|
40
|
+
if (attended === "0")
|
|
41
|
+
return { mode: "unattended", signal: "claude-attended" };
|
|
42
|
+
if (attended === "1")
|
|
43
|
+
return { mode: "attended", signal: "claude-attended" };
|
|
44
|
+
const entrypoint = env.CLAUDE_CODE_ENTRYPOINT?.trim();
|
|
45
|
+
if (entrypoint && HEADLESS_ENTRYPOINTS.has(entrypoint))
|
|
46
|
+
return { mode: "unattended", signal: "claude-entrypoint" };
|
|
47
|
+
if (truthy(env.CI) || CI_VARIABLES.some((name) => truthy(env[name])))
|
|
48
|
+
return { mode: "unattended", signal: "ci" };
|
|
49
|
+
return { mode: "attended", signal: "default" };
|
|
50
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The command summary an approver sees, with secrets removed on this machine.
|
|
3
|
+
*
|
|
4
|
+
* This is the only form in which any part of a command line leaves the
|
|
5
|
+
* machine, and only for an approval request. It prefers hiding too much over
|
|
6
|
+
* too little: anything that looks like a key, a token, a password, a long
|
|
7
|
+
* opaque value, a credential in a URL, or a heredoc body is replaced with
|
|
8
|
+
* `[hidden]`. Recognized key formats come from `passport scan`'s own rules.
|
|
9
|
+
*/
|
|
10
|
+
export declare const HIDDEN = "[hidden]";
|
|
11
|
+
export declare const SUMMARY_MAX = 300;
|
|
12
|
+
/**
|
|
13
|
+
* One line an approver can read: the command with every secret replaced,
|
|
14
|
+
* heredoc bodies dropped, and the length bounded. Never throws.
|
|
15
|
+
*/
|
|
16
|
+
export declare function redactCommand(command: string): string;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The command summary an approver sees, with secrets removed on this machine.
|
|
3
|
+
*
|
|
4
|
+
* This is the only form in which any part of a command line leaves the
|
|
5
|
+
* machine, and only for an approval request. It prefers hiding too much over
|
|
6
|
+
* too little: anything that looks like a key, a token, a password, a long
|
|
7
|
+
* opaque value, a credential in a URL, or a heredoc body is replaced with
|
|
8
|
+
* `[hidden]`. Recognized key formats come from `passport scan`'s own rules.
|
|
9
|
+
*/
|
|
10
|
+
import { kindOfNamedValue, kindOfValue, URL_TOKEN_PARAMS } from "./scanRules.js";
|
|
11
|
+
export const HIDDEN = "[hidden]";
|
|
12
|
+
export const SUMMARY_MAX = 300;
|
|
13
|
+
/** Names whose value is a secret whatever it looks like. */
|
|
14
|
+
const SECRET_NAME = /(?:token|secret|passw(?:or)?d|\bpwd\b|passphrase|api[-_]?key|apikey|access[-_]?key|private[-_]?key|client[-_]?secret|auth|credential|cookie|session|signature|bearer|dsn|connection[-_]?string|database[-_]?url|_url$|^key$|[-_]key$)/i;
|
|
15
|
+
/** Flags whose next word (or `=value`) is a secret. */
|
|
16
|
+
const SECRET_LONG_FLAG = /^--?[a-z0-9-]*(?:token|secret|password|passwd|pass|api-key|apikey|key|auth|credential|cookie|header|dsn|db-url|database-url|connection-string|private-key)[a-z0-9-]*$/i;
|
|
17
|
+
/** curl -H/-u, mysql -p/-u: short flags that carry credentials. */
|
|
18
|
+
const SECRET_SHORT_FLAG = new Set(["-H", "-u", "-p"]);
|
|
19
|
+
function secretFlag(word) {
|
|
20
|
+
return SECRET_SHORT_FLAG.has(word) || SECRET_LONG_FLAG.test(word);
|
|
21
|
+
}
|
|
22
|
+
/** Well-known key prefixes, matched anywhere: a last sweep after the rules. */
|
|
23
|
+
const KEY_PREFIX = /(?:gh[pousr]_|github_pat_|[sr]k_(?:live|test)_|xox[abprs]-|sk-ant-|sk-(?:proj|svcacct|admin)-|sk-[A-Za-z0-9]{20}|re_[A-Za-z0-9]{8}|sbp_|sb_secret_|npm_|vcp_|cf[ua]t_|cfk_|AKIA|ASIA|eyJ[A-Za-z0-9_-]{8,}\.|glpat-|dop_v1_|shpat_|SG\.|AIza)[A-Za-z0-9_\-./+=]{4,}/g;
|
|
24
|
+
/** A long opaque value: one token-shaped run of letters and digits mixed. */
|
|
25
|
+
function opaqueSegment(segment) {
|
|
26
|
+
return (segment.length >= 16 &&
|
|
27
|
+
/^[A-Za-z0-9_\-+=.~]+$/.test(segment) &&
|
|
28
|
+
/[A-Za-z]/.test(segment) &&
|
|
29
|
+
/[0-9]/.test(segment) &&
|
|
30
|
+
!/^[a-z]+(?:[-_.][a-z0-9]+)*$/.test(segment));
|
|
31
|
+
}
|
|
32
|
+
function opaque(word) {
|
|
33
|
+
const bare = word.replace(/^['"]|['"]$/g, "");
|
|
34
|
+
if (bare.length < 16 || bare.includes("://"))
|
|
35
|
+
return false;
|
|
36
|
+
// Paths and repo names are split; a key with "/" in it still has a long run.
|
|
37
|
+
return bare.split("/").some(opaqueSegment);
|
|
38
|
+
}
|
|
39
|
+
function redactUrl(word) {
|
|
40
|
+
return word
|
|
41
|
+
.replace(/([a-z][a-z0-9+.-]*:\/\/)([^\s@'"]+)@/gi, `$1${HIDDEN}@`)
|
|
42
|
+
.replace(/([?&])([^=&\s]+)=([^&\s'"]*)/g, (match, lead, name, _value) => URL_TOKEN_PARAMS.has(name.toLowerCase()) || SECRET_NAME.test(name) ? `${lead}${name}=${HIDDEN}` : match);
|
|
43
|
+
}
|
|
44
|
+
/** JSON-ish `"password": "…"` and `password=…` pairs inside a word. */
|
|
45
|
+
function redactPairs(word) {
|
|
46
|
+
return word
|
|
47
|
+
.replace(/(["']?)([A-Za-z0-9_.-]{1,64})\1(\s*:\s*)(["'])([^"']*)\4/g, (match, quote, name, sep, q) => SECRET_NAME.test(name) ? `${quote}${name}${quote}${sep}${q}${HIDDEN}${q}` : match)
|
|
48
|
+
.replace(/\b(authorization|x-api-key|api-key|cookie)(\s*:\s*)([^'"]+)/gi, `$1$2${HIDDEN}`)
|
|
49
|
+
.replace(/\b(bearer|basic|token)\s+[A-Za-z0-9._~+/=-]{6,}/gi, `$1 ${HIDDEN}`);
|
|
50
|
+
}
|
|
51
|
+
function redactWord(word) {
|
|
52
|
+
// NAME=value: env prefixes, --flag=value, key=value arguments, quoted or not.
|
|
53
|
+
const quote = /^(['"])(.*)\1$/s.exec(word);
|
|
54
|
+
if (quote && /^-{0,2}[A-Za-z_][A-Za-z0-9_.-]*=/.test(quote[2])) {
|
|
55
|
+
return `${quote[1]}${redactWord(quote[2])}${quote[1]}`;
|
|
56
|
+
}
|
|
57
|
+
const assignment = /^(-{0,2}[A-Za-z_][A-Za-z0-9_.-]*)=(.*)$/s.exec(word);
|
|
58
|
+
if (assignment) {
|
|
59
|
+
const [, name, raw] = assignment;
|
|
60
|
+
const value = raw.replace(/^['"]|['"]$/g, "");
|
|
61
|
+
const flag = name.startsWith("-");
|
|
62
|
+
if ((flag && secretFlag(name)) ||
|
|
63
|
+
(!flag && SECRET_NAME.test(name)) ||
|
|
64
|
+
kindOfValue(value) ||
|
|
65
|
+
(!flag && kindOfNamedValue(name, value)) ||
|
|
66
|
+
opaque(value)) {
|
|
67
|
+
return `${name}=${HIDDEN}`;
|
|
68
|
+
}
|
|
69
|
+
return `${name}=${redactUrl(redactPairs(raw))}`;
|
|
70
|
+
}
|
|
71
|
+
if (kindOfValue(word) || opaque(word))
|
|
72
|
+
return HIDDEN;
|
|
73
|
+
return redactUrl(redactPairs(word));
|
|
74
|
+
}
|
|
75
|
+
/** Split into words, keeping quoted runs together and shell operators as words. */
|
|
76
|
+
function words(command) {
|
|
77
|
+
const out = [];
|
|
78
|
+
let current = "";
|
|
79
|
+
let quote = null;
|
|
80
|
+
for (let index = 0; index < command.length; index++) {
|
|
81
|
+
const char = command[index];
|
|
82
|
+
if (quote) {
|
|
83
|
+
current += char;
|
|
84
|
+
if (char === quote)
|
|
85
|
+
quote = null;
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (char === "'" || char === '"') {
|
|
89
|
+
quote = char;
|
|
90
|
+
current += char;
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if (/\s/.test(char)) {
|
|
94
|
+
if (current)
|
|
95
|
+
out.push(current);
|
|
96
|
+
current = "";
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
current += char;
|
|
100
|
+
}
|
|
101
|
+
if (current)
|
|
102
|
+
out.push(current);
|
|
103
|
+
return out;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* One line an approver can read: the command with every secret replaced,
|
|
107
|
+
* heredoc bodies dropped, and the length bounded. Never throws.
|
|
108
|
+
*/
|
|
109
|
+
export function redactCommand(command) {
|
|
110
|
+
try {
|
|
111
|
+
// A heredoc body can hold anything; keep only the line that starts it.
|
|
112
|
+
const firstLine = command.split("\n")[0] ?? "";
|
|
113
|
+
const hasMore = command.includes("\n");
|
|
114
|
+
const tokens = words(firstLine.replace(/[\u0000-\u001f\u007f]/g, " "));
|
|
115
|
+
const out = [];
|
|
116
|
+
for (let index = 0; index < tokens.length; index++) {
|
|
117
|
+
const token = tokens[index];
|
|
118
|
+
const bare = token.replace(/^['"]|['"]$/g, "");
|
|
119
|
+
if (secretFlag(bare) && !bare.includes("=") && index + 1 < tokens.length) {
|
|
120
|
+
out.push(bare, HIDDEN);
|
|
121
|
+
index++;
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
out.push(redactWord(token));
|
|
125
|
+
}
|
|
126
|
+
let summary = out.join(" ").replace(KEY_PREFIX, HIDDEN);
|
|
127
|
+
if (hasMore)
|
|
128
|
+
summary += " …";
|
|
129
|
+
if (summary.length > SUMMARY_MAX)
|
|
130
|
+
summary = `${summary.slice(0, SUMMARY_MAX - 1)}…`;
|
|
131
|
+
return summary;
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
return "";
|
|
135
|
+
}
|
|
136
|
+
}
|
package/dist/cliInit.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { type CommandResult, type Env, type Runtime } from "./cliSupport.js";
|
|
|
6
6
|
import { type Profile } from "./credentials.js";
|
|
7
7
|
import { type AgentId } from "./initAgents.js";
|
|
8
8
|
import { type StableCommand } from "./initInstall.js";
|
|
9
|
-
import { APP_LABELS, INIT_APPS, PASSPORT_CLOUD, type Gateway, type InitApp, type InitDependencies, type InitSession, type StepStatus, type Summary } from "./initState.js";
|
|
9
|
+
import { APP_LABELS, INIT_APPS, PASSPORT_CLOUD, type Gateway, type AutopilotView, type InitApp, type InitDependencies, type InitSession, type StepStatus, type Summary } from "./initState.js";
|
|
10
10
|
import { InitScreen, type InitTerminal } from "./initUi.js";
|
|
11
11
|
import { type ScanResult } from "./scan.js";
|
|
12
12
|
export { APP_LABELS, INIT_APPS, PASSPORT_CLOUD, type InitApp, type InitDependencies, type StepStatus };
|
|
@@ -36,6 +36,9 @@ export declare class Init implements InitSession {
|
|
|
36
36
|
agentsReady: AgentId[];
|
|
37
37
|
newlyAddedClaudeCode: boolean;
|
|
38
38
|
stable?: StableCommand;
|
|
39
|
+
autopilot?: AutopilotView | null;
|
|
40
|
+
autopilotSummary?: string;
|
|
41
|
+
mcpUrl?: string;
|
|
39
42
|
exitCode: number;
|
|
40
43
|
constructor(args: ParsedArgs, runtime: Runtime, deps: InitDependencies, terminal: InitTerminal);
|
|
41
44
|
get signal(): AbortSignal;
|