passport-bridge 0.25.0 → 0.27.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 +5 -3
- package/dist/approvalNotice.d.ts +73 -0
- package/dist/approvalNotice.js +211 -0
- package/dist/blindKind.d.ts +15 -0
- package/dist/blindKind.js +5 -0
- package/dist/cliChanges.d.ts +12 -4
- package/dist/cliChanges.js +26 -15
- package/dist/cliExec.js +2 -2
- package/dist/cliGuardState.js +2 -2
- package/dist/cliHook.js +5 -0
- package/dist/cliHookBlind.d.ts +15 -0
- package/dist/cliHookBlind.js +65 -0
- package/dist/cliHookClients.d.ts +3 -1
- package/dist/cliHookClients.js +1 -1
- package/dist/cliHookLocal.d.ts +7 -16
- package/dist/cliHookLocal.js +75 -97
- package/dist/cliHookLocalCode.js +7 -1
- package/dist/cliHookLocalFs.d.ts +15 -0
- package/dist/cliHookLocalFs.js +77 -0
- package/dist/cliHookNotice.d.ts +22 -0
- package/dist/cliHookNotice.js +49 -0
- package/dist/cliHookScripts.d.ts +2 -1
- package/dist/cliOutput.js +2 -2
- package/dist/cliProjectSummary.d.ts +1 -1
- package/dist/cliProjectSummary.js +19 -8
- package/dist/cliScriptRead.d.ts +5 -4
- package/dist/cliScriptRead.js +3 -2
- package/dist/cliSeen.d.ts +24 -15
- package/dist/cliSeen.js +34 -16
- package/dist/cliSessions.js +20 -6
- package/dist/cliSessionsJson.d.ts +48 -0
- package/dist/cliSessionsJson.js +40 -10
- package/dist/cliSessionsRender.d.ts +4 -0
- package/dist/cliSessionsRender.js +42 -8
- 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/inlineCode.d.ts +35 -0
- package/dist/inlineCode.js +201 -0
- package/dist/inlineScan.d.ts +23 -0
- package/dist/inlineScan.js +389 -0
- package/dist/localCommands.d.ts +10 -3
- package/dist/localCommands.js +59 -37
- package/dist/localFiles.d.ts +38 -2
- package/dist/localFiles.js +453 -33
- package/dist/localGit.js +53 -17
- package/dist/localShared.d.ts +3 -0
- package/dist/pluginPin.d.ts +1 -1
- package/dist/pluginPin.js +1 -1
- 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,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a blind part of a command was, for coverage: the program that ran it
|
|
3
|
+
* (a plain name, never a path) and its kind, so Rules › Project scripts can
|
|
4
|
+
* tell inline code from a project script from a program Passport doesn't know.
|
|
5
|
+
*/
|
|
6
|
+
import { normalizeArgv } from "./cliHookParse.js";
|
|
7
|
+
const HOME_PATH = /^(?:\$HOME|\$\{HOME\})(?=\/|$)/;
|
|
8
|
+
const ASSIGNMENT = /^[A-Za-z_][A-Za-z0-9_]*=/;
|
|
9
|
+
/** The program a part ran, by name. A file run by path (`./x.sh`, `~/bin/tool`,
|
|
10
|
+
* `$HOME/bin/tool`, `node_modules/.bin/tsc`) is "script". */
|
|
11
|
+
export function programOf(argv) {
|
|
12
|
+
const normalized = normalizeArgv(argv);
|
|
13
|
+
if (normalized.via.includes("absolute-path"))
|
|
14
|
+
return "script";
|
|
15
|
+
const first = argv[argv.length - normalized.argv.length] ?? "";
|
|
16
|
+
return HOME_PATH.test(first) || first.startsWith("~") ? "script" : (normalized.argv[0] ?? "");
|
|
17
|
+
}
|
|
18
|
+
/** A program run from the home folder by `$HOME/…`: read like `~/…`, so its place is known. */
|
|
19
|
+
export function homeProgram(words) {
|
|
20
|
+
const index = words.findIndex((word) => !ASSIGNMENT.test(word.text));
|
|
21
|
+
const head = words[index];
|
|
22
|
+
if (!head?.expands || !HOME_PATH.test(head.text))
|
|
23
|
+
return words;
|
|
24
|
+
const rest = head.text.replace(HOME_PATH, "");
|
|
25
|
+
if (/[$`*?[]/.test(rest))
|
|
26
|
+
return words;
|
|
27
|
+
const copy = [...words];
|
|
28
|
+
copy[index] = { text: `~${rest}`, tilde: true };
|
|
29
|
+
return copy;
|
|
30
|
+
}
|
|
31
|
+
const RUNNERS = new Set([
|
|
32
|
+
"node",
|
|
33
|
+
"nodejs",
|
|
34
|
+
"tsx",
|
|
35
|
+
"ts-node",
|
|
36
|
+
"bun",
|
|
37
|
+
"deno",
|
|
38
|
+
"python",
|
|
39
|
+
"python2",
|
|
40
|
+
"python3",
|
|
41
|
+
"ruby",
|
|
42
|
+
"perl",
|
|
43
|
+
"bash",
|
|
44
|
+
"sh",
|
|
45
|
+
"zsh",
|
|
46
|
+
"dash",
|
|
47
|
+
"ksh",
|
|
48
|
+
"fish",
|
|
49
|
+
"php",
|
|
50
|
+
"osascript"
|
|
51
|
+
]);
|
|
52
|
+
const TASK_RUNNERS = new Set(["make", "just", "task", "source", "."]);
|
|
53
|
+
const PACKAGE_MANAGERS = new Set(["npm", "pnpm", "yarn", "bun"]);
|
|
54
|
+
/** Script: a file run by path or given to an interpreter, a task target, a package
|
|
55
|
+
* script Passport couldn't read. Program: anything else it doesn't know. */
|
|
56
|
+
export function blindKind(program, argv) {
|
|
57
|
+
if (program === "script" || TASK_RUNNERS.has(program))
|
|
58
|
+
return "script";
|
|
59
|
+
const rest = normalizeArgv(argv).argv.slice(1);
|
|
60
|
+
if (RUNNERS.has(program) && rest.some((word) => !word.startsWith("-")))
|
|
61
|
+
return "script";
|
|
62
|
+
if (PACKAGE_MANAGERS.has(program) && /^(run|run-script)$/.test(rest.find((word) => !word.startsWith("-")) ?? ""))
|
|
63
|
+
return "script";
|
|
64
|
+
return "program";
|
|
65
|
+
}
|
package/dist/cliHookClients.d.ts
CHANGED
|
@@ -13,7 +13,9 @@ export type ClientSpec = {
|
|
|
13
13
|
post: string;
|
|
14
14
|
/** Where a command that failed or was interrupted is reported, if separate. */
|
|
15
15
|
postFailure?: string;
|
|
16
|
-
/** Session
|
|
16
|
+
/** Session events the audit entry also runs on (no matcher): start and
|
|
17
|
+
* end, and for Claude Code each prompt, which carries a late approval's
|
|
18
|
+
* notice into the conversation (`approvalNotice.ts`). */
|
|
17
19
|
lifecycle?: string[];
|
|
18
20
|
path(env: Env): string;
|
|
19
21
|
};
|
package/dist/cliHookClients.js
CHANGED
|
@@ -29,7 +29,7 @@ export const CLIENTS = {
|
|
|
29
29
|
// Claude Code reports an interrupted or failed tool call here instead of
|
|
30
30
|
// PostToolUse, so an approved command that failed still counts as ran.
|
|
31
31
|
postFailure: "PostToolUseFailure",
|
|
32
|
-
lifecycle: ["SessionStart", "SessionEnd"],
|
|
32
|
+
lifecycle: ["SessionStart", "SessionEnd", "UserPromptSubmit"],
|
|
33
33
|
path: claudeSettingsPath
|
|
34
34
|
},
|
|
35
35
|
codex: {
|
package/dist/cliHookLocal.d.ts
CHANGED
|
@@ -15,21 +15,12 @@
|
|
|
15
15
|
* applies. Asks and blocks still come from whatever parts were understood.
|
|
16
16
|
*/
|
|
17
17
|
import { type CliFinding } from "./cliHookClassify.js";
|
|
18
|
-
import
|
|
18
|
+
import type { Blind } from "./blindKind.js";
|
|
19
|
+
import type { ScriptReader } from "./cliScriptRead.js";
|
|
20
|
+
import { type LocalFs } from "./cliHookLocalFs.js";
|
|
19
21
|
import type { DecidedFinding } from "./cliHookGuard.js";
|
|
20
22
|
import { type LocalAction, type Place, type ShellWord } from "./localCommands.js";
|
|
21
|
-
|
|
22
|
-
export type LocalFs = {
|
|
23
|
-
/** The canonical path, or null when it doesn't exist. */
|
|
24
|
-
realpath(path: string): string | null;
|
|
25
|
-
/** A small text file, or null. */
|
|
26
|
-
readText(path: string): string | null;
|
|
27
|
-
isDirectory(path: string): boolean;
|
|
28
|
-
isFile(path: string): boolean;
|
|
29
|
-
/** A script up to 256 KB with its time and size (script reading), or null. */
|
|
30
|
-
readScript?(path: string): ScriptFile | null;
|
|
31
|
-
statFile?(path: string): FileStat | null;
|
|
32
|
-
};
|
|
23
|
+
export { NODE_FS, type LocalFs } from "./cliHookLocalFs.js";
|
|
33
24
|
export type LocalMachine = {
|
|
34
25
|
/** The folder the agent's command starts in, canonical; null when unknown. */
|
|
35
26
|
cwd: string | null;
|
|
@@ -47,7 +38,6 @@ export type LocalMachine = {
|
|
|
47
38
|
/** Read the project's own scripts (`cliScriptRead.ts`). Absent: scripts stay unread. */
|
|
48
39
|
scripts?: ScriptReader;
|
|
49
40
|
};
|
|
50
|
-
export declare const NODE_FS: LocalFs;
|
|
51
41
|
/** Canonical form of a path that may not exist yet: resolve the deepest
|
|
52
42
|
* existing ancestor (following symlinks) and keep the rest as written. */
|
|
53
43
|
export declare function canonical(path: string, fs: LocalFs): string;
|
|
@@ -79,8 +69,9 @@ export type LineResult = {
|
|
|
79
69
|
/** Every part understood: the only lines Passport may allow. */
|
|
80
70
|
complete: boolean;
|
|
81
71
|
/** A part Passport couldn't tell anything about (an unknown program, a
|
|
82
|
-
* one-liner): the program that ran it
|
|
83
|
-
|
|
72
|
+
* one-liner it couldn't read): the program that ran it and its kind, for
|
|
73
|
+
* coverage's Blind count. */
|
|
74
|
+
blind?: Blind;
|
|
84
75
|
};
|
|
85
76
|
/** A local action as a finding the guard and reports understand. */
|
|
86
77
|
export declare function localFinding(action: LocalAction): CliFinding;
|
package/dist/cliHookLocal.js
CHANGED
|
@@ -14,91 +14,19 @@
|
|
|
14
14
|
* leaves the line incomplete, which means no allow: the agent's own prompt
|
|
15
15
|
* applies. Asks and blocks still come from whatever parts were understood.
|
|
16
16
|
*/
|
|
17
|
-
import { closeSync, fstatSync, lstatSync, openSync, readFileSync, readSync, realpathSync, statSync } from "node:fs";
|
|
18
17
|
import { homedir, tmpdir } from "node:os";
|
|
19
18
|
import { posix } from "node:path";
|
|
20
19
|
import { classifyArgv, classifyNestedText } from "./cliHookClassify.js";
|
|
21
20
|
import { heredocBodies, projectCode } from "./cliHookLocalCode.js";
|
|
22
|
-
import {
|
|
21
|
+
import { blindKind, homeProgram, programOf } from "./cliHookBlind.js";
|
|
22
|
+
import { inlineCode } from "./inlineCode.js";
|
|
23
|
+
import { NODE_FS } from "./cliHookLocalFs.js";
|
|
23
24
|
import { scriptReading } from "./cliHookScripts.js";
|
|
24
|
-
import { INTERPRETERS,
|
|
25
|
+
import { INTERPRETERS, splitCommands } from "./cliHookParse.js";
|
|
25
26
|
import { VENDORS } from "./cliHookVendors.js";
|
|
26
27
|
import { databasePrefix } from "./envDatabase.js";
|
|
27
28
|
import { classifyLocalCommand } from "./localCommands.js";
|
|
28
|
-
|
|
29
|
-
export const NODE_FS = {
|
|
30
|
-
realpath(path) {
|
|
31
|
-
try {
|
|
32
|
-
return realpathSync.native(path);
|
|
33
|
-
}
|
|
34
|
-
catch {
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
readText(path) {
|
|
39
|
-
try {
|
|
40
|
-
if (statSync(path).size > MAX_TEXT)
|
|
41
|
-
return null;
|
|
42
|
-
return readFileSync(path, "utf8");
|
|
43
|
-
}
|
|
44
|
-
catch {
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
isDirectory(path) {
|
|
49
|
-
try {
|
|
50
|
-
return statSync(path).isDirectory();
|
|
51
|
-
}
|
|
52
|
-
catch {
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
isFile(path) {
|
|
57
|
-
try {
|
|
58
|
-
return lstatSync(path).isFile() || statSync(path).isFile();
|
|
59
|
-
}
|
|
60
|
-
catch {
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
readScript(path) {
|
|
65
|
-
let descriptor;
|
|
66
|
-
try {
|
|
67
|
-
descriptor = openSync(path, "r");
|
|
68
|
-
const stat = fstatSync(descriptor);
|
|
69
|
-
if (!stat.isFile() || stat.size > SCRIPT_MAX_BYTES)
|
|
70
|
-
return null;
|
|
71
|
-
const buffer = Buffer.alloc(stat.size);
|
|
72
|
-
let offset = 0;
|
|
73
|
-
while (offset < stat.size) {
|
|
74
|
-
const read = readSync(descriptor, buffer, offset, stat.size - offset, offset);
|
|
75
|
-
if (read <= 0)
|
|
76
|
-
break;
|
|
77
|
-
offset += read;
|
|
78
|
-
}
|
|
79
|
-
// Binary files aren't scripts.
|
|
80
|
-
if (buffer.subarray(0, offset).includes(0))
|
|
81
|
-
return null;
|
|
82
|
-
return { text: buffer.toString("utf8", 0, offset), mtimeMs: stat.mtimeMs, size: stat.size };
|
|
83
|
-
}
|
|
84
|
-
catch {
|
|
85
|
-
return null;
|
|
86
|
-
}
|
|
87
|
-
finally {
|
|
88
|
-
if (descriptor !== undefined)
|
|
89
|
-
closeSync(descriptor);
|
|
90
|
-
}
|
|
91
|
-
},
|
|
92
|
-
statFile(path) {
|
|
93
|
-
try {
|
|
94
|
-
const stat = statSync(path);
|
|
95
|
-
return stat.isFile() ? { mtimeMs: stat.mtimeMs, size: stat.size } : null;
|
|
96
|
-
}
|
|
97
|
-
catch {
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
};
|
|
29
|
+
export { NODE_FS } from "./cliHookLocalFs.js";
|
|
102
30
|
/** Home-relative paths whose contents are keys, tokens, or an agent's own settings. */
|
|
103
31
|
const SENSITIVE_IN_HOME = [
|
|
104
32
|
".ssh",
|
|
@@ -375,16 +303,11 @@ export function localFinding(action) {
|
|
|
375
303
|
}
|
|
376
304
|
};
|
|
377
305
|
}
|
|
378
|
-
/** The program a part ran, by name. A path is never sent: a file run by path is "script". */
|
|
379
|
-
function programOf(argv) {
|
|
380
|
-
const normalized = normalizeArgv(argv);
|
|
381
|
-
return normalized.via.includes("absolute-path") ? "script" : (normalized.argv[0] ?? "");
|
|
382
|
-
}
|
|
383
306
|
function isVendor(program) {
|
|
384
307
|
return Object.hasOwn(VENDORS, program);
|
|
385
308
|
}
|
|
386
309
|
/** Interpreter flags whose code is on the line itself: a one-liner. */
|
|
387
|
-
const INLINE_CODE = /^(-e|-p|-c|--eval|--print)$/;
|
|
310
|
+
const INLINE_CODE = /^(-e|-E|-p|-c|--eval|--print)$/;
|
|
388
311
|
function contextAt(cwd, machine) {
|
|
389
312
|
const here = cwd ? placeOfPath(cwd, machine) : "unknown";
|
|
390
313
|
const branches = cwd && (here === "project" || here === "project-root") ? gitBranches(cwd, machine.fs) : null;
|
|
@@ -396,9 +319,21 @@ function contextAt(cwd, machine) {
|
|
|
396
319
|
},
|
|
397
320
|
isVendor,
|
|
398
321
|
currentBranch: branches?.current ?? null,
|
|
399
|
-
defaultBranch: branches?.defaultBranch ?? null
|
|
322
|
+
defaultBranch: branches?.defaultBranch ?? null,
|
|
323
|
+
sameRepository: (word) => {
|
|
324
|
+
const path = word ? resolveWord(word, cwd, machine) : cwd;
|
|
325
|
+
return path !== null && sharesRepository(path, machine);
|
|
326
|
+
}
|
|
400
327
|
};
|
|
401
328
|
}
|
|
329
|
+
/** `path` is in a checkout of the project's repository: the same common git folder. */
|
|
330
|
+
function sharesRepository(path, machine) {
|
|
331
|
+
if (!machine.projectRoot)
|
|
332
|
+
return false;
|
|
333
|
+
const there = gitLayout(path, machine.fs);
|
|
334
|
+
const ours = there && gitLayout(machine.projectRoot, machine.fs);
|
|
335
|
+
return Boolean(ours && canonical(there.commonDir, machine.fs) === canonical(ours.commonDir, machine.fs));
|
|
336
|
+
}
|
|
402
337
|
/** Redirections: writes are changes where they land; reads of keys are no decision. */
|
|
403
338
|
function redirections(shape, cwd, machine, walk) {
|
|
404
339
|
for (const redirect of shape.redirects) {
|
|
@@ -443,15 +378,39 @@ function nextDirectory(target, cwd, machine) {
|
|
|
443
378
|
return null;
|
|
444
379
|
return machine.fs.isDirectory(path) ? path : null;
|
|
445
380
|
}
|
|
446
|
-
|
|
381
|
+
/** Interpreter code on the line or in a heredoc (`inlineCode.ts`): true when it only reads. */
|
|
382
|
+
function inlineRead(shape, cwd, machine, heredocs, walk) {
|
|
383
|
+
const words = shape.words;
|
|
384
|
+
const key = posix.basename(words.find((word) => !/^\w+=/.test(word.text))?.text ?? "");
|
|
385
|
+
const body = shape.heredoc ? heredocs.bodies.get(key) : undefined;
|
|
386
|
+
const ctx = contextAt(cwd, machine);
|
|
387
|
+
const inline = inlineCode(words, body, {
|
|
388
|
+
ctx,
|
|
389
|
+
placePath: (path) => ctx.place({ text: path, ...(path.startsWith("~") ? { tilde: true } : {}) }),
|
|
390
|
+
shadowed: (module) => cwd !== null &&
|
|
391
|
+
(machine.fs.isFile(posix.join(cwd, `${module}.py`)) || machine.fs.isDirectory(posix.join(cwd, module))),
|
|
392
|
+
quotedHeredoc: heredocs.quoted
|
|
393
|
+
});
|
|
394
|
+
if (!inline || !("read" in inline))
|
|
395
|
+
return inline;
|
|
396
|
+
walk.findings.push(localFinding(inline.read));
|
|
397
|
+
if (body !== undefined)
|
|
398
|
+
heredocs.read.add(key);
|
|
399
|
+
return true;
|
|
400
|
+
}
|
|
401
|
+
function vendorFindings(shape, outcome, walk, at) {
|
|
402
|
+
const { depth, cwd } = at;
|
|
447
403
|
const argv = shape.words.map((word) => word.text);
|
|
404
|
+
const inline = outcome.kind === "vendor" ? null : inlineRead(shape, cwd, at.machine, at.heredocs, walk);
|
|
405
|
+
if (inline === true)
|
|
406
|
+
return;
|
|
448
407
|
// Where it runs, for folder links; database variables set in front of it.
|
|
449
408
|
const prefix = databasePrefix(argv);
|
|
450
|
-
const
|
|
409
|
+
const where = { cwd, ...(prefix ? { prefix } : {}) };
|
|
451
410
|
// Unrecognized here: keep only what the vendor map governs or can't see into.
|
|
452
411
|
const found = classifyArgv(argv, [], depth)
|
|
453
412
|
.filter((finding) => outcome.kind === "vendor" || (finding.risk !== "local" && finding.risk !== "http"))
|
|
454
|
-
.map((finding) => ({ ...finding, at }));
|
|
413
|
+
.map((finding) => ({ ...finding, at: where }));
|
|
455
414
|
const push = outcome.kind === "vendor" ? outcome.push : undefined;
|
|
456
415
|
const findings = push
|
|
457
416
|
? found.map((finding) => (finding.vendor === "git" ? { ...finding, pushEnvironment: push } : finding))
|
|
@@ -459,11 +418,14 @@ function vendorFindings(shape, outcome, walk, depth, cwd) {
|
|
|
459
418
|
walk.findings.push(...findings);
|
|
460
419
|
if (outcome.kind !== "vendor") {
|
|
461
420
|
walk.complete = false;
|
|
462
|
-
// Blind: nothing Passport knows ran here, or code
|
|
421
|
+
// Blind: nothing Passport knows ran here, or code it couldn't read.
|
|
463
422
|
const program = programOf(argv);
|
|
464
|
-
const
|
|
465
|
-
if (
|
|
466
|
-
|
|
423
|
+
const code = inline !== null || (INTERPRETERS.has(program) && (shape.heredoc || argv.some((word) => INLINE_CODE.test(word))));
|
|
424
|
+
if (code || findings.every((finding) => finding.risk === "unknown")) {
|
|
425
|
+
// A bare assignment that changes what runs (`PATH=…`) is the shell's own.
|
|
426
|
+
const name = program || "export";
|
|
427
|
+
walk.blind ??= { program: inline?.program ?? name, kind: code ? "inline" : blindKind(name, argv) };
|
|
428
|
+
}
|
|
467
429
|
return;
|
|
468
430
|
}
|
|
469
431
|
// A vendor part is understood when it is one confident, plain invocation.
|
|
@@ -517,11 +479,18 @@ export function classifyLine(command, machine, depth = 0) {
|
|
|
517
479
|
if (depth > 4)
|
|
518
480
|
return { findings: [], complete: false };
|
|
519
481
|
const { shapes, nested, flags } = splitCommands(command);
|
|
520
|
-
const
|
|
521
|
-
|
|
482
|
+
const bodies = heredocBodies(nested);
|
|
483
|
+
const heredocs = {
|
|
484
|
+
// Two bodies for one program can't be told apart: neither is read as code.
|
|
485
|
+
bodies: new Map([...bodies].filter(([key]) => nested.filter((sub) => heredocKey(sub) === key).length === 1)),
|
|
486
|
+
read: new Set(),
|
|
487
|
+
quoted: !/<<-?\s*[^\s'"<]/.test(command.replace(/<<</g, " "))
|
|
488
|
+
};
|
|
489
|
+
if (flags.braces || flags.processSubstitution || nested.some((sub) => sub.kind !== "heredoc"))
|
|
522
490
|
walk.complete = false;
|
|
523
491
|
const cwdAt = [machine.cwd];
|
|
524
492
|
let previous = null;
|
|
493
|
+
let heredocShapes = 0;
|
|
525
494
|
for (let index = 0; index < shapes.length; index++) {
|
|
526
495
|
const shape = shapes[index];
|
|
527
496
|
// Entering a subshell starts from the folder outside it; leaving one forgets its cd.
|
|
@@ -534,10 +503,11 @@ export function classifyLine(command, machine, depth = 0) {
|
|
|
534
503
|
const cwd = cwdAt[shape.depth] ?? null;
|
|
535
504
|
previous = shape;
|
|
536
505
|
if (shape.heredoc)
|
|
537
|
-
|
|
506
|
+
heredocShapes++;
|
|
538
507
|
redirections(shape, cwd, machine, walk);
|
|
539
508
|
if (!shape.words.length)
|
|
540
509
|
continue;
|
|
510
|
+
shape.words = homeProgram(shape.words);
|
|
541
511
|
const outcome = classifyLocalCommand(shape.words, contextAt(cwd, machine));
|
|
542
512
|
if (outcome.kind === "local") {
|
|
543
513
|
walk.findings.push(...outcome.actions.map(localFinding));
|
|
@@ -557,13 +527,21 @@ export function classifyLine(command, machine, depth = 0) {
|
|
|
557
527
|
cwdAt[shape.depth] = nextDirectory(outcome.target, cwd, machine);
|
|
558
528
|
continue;
|
|
559
529
|
}
|
|
560
|
-
if (outcome.kind === "unknown" && ownCode(shape, { cwd, depth, heredocs }, machine, walk))
|
|
530
|
+
if (outcome.kind === "unknown" && ownCode(shape, { cwd, depth, heredocs: bodies }, machine, walk))
|
|
561
531
|
continue;
|
|
562
|
-
vendorFindings(shape, outcome, walk, depth, cwd);
|
|
532
|
+
vendorFindings(shape, outcome, walk, { depth, cwd, machine, heredocs });
|
|
563
533
|
}
|
|
564
|
-
|
|
534
|
+
// A heredoc is hidden text unless inline code read it as a read.
|
|
535
|
+
const readBodies = nested.filter((sub) => sub.kind === "heredoc" && heredocs.read.has(heredocKey(sub)));
|
|
536
|
+
const heredocCount = nested.filter((sub) => sub.kind === "heredoc").length;
|
|
537
|
+
if ((flags.heredoc || heredocShapes) && (heredocCount > readBodies.length || heredocShapes > readBodies.length))
|
|
538
|
+
walk.complete = false;
|
|
539
|
+
nestedInto(nested.filter((sub) => !readBodies.includes(sub)), machine, depth, walk);
|
|
565
540
|
return walk;
|
|
566
541
|
}
|
|
542
|
+
function heredocKey(sub) {
|
|
543
|
+
return sub.kind === "heredoc" && sub.target ? posix.basename(sub.target) : "";
|
|
544
|
+
}
|
|
567
545
|
/** Substitutions and heredocs: their vendor findings, and a shell's local ones. */
|
|
568
546
|
function nestedInto(nested, machine, depth, walk) {
|
|
569
547
|
for (const sub of nested) {
|
package/dist/cliHookLocalCode.js
CHANGED
|
@@ -95,7 +95,7 @@ function shellLine(words) {
|
|
|
95
95
|
function scriptOperand(words) {
|
|
96
96
|
for (let index = 1; index < words.length; index++) {
|
|
97
97
|
const word = words[index];
|
|
98
|
-
if (INLINE.test(word.text))
|
|
98
|
+
if (INLINE.test(word.text) || bundledCode(words[0].text, word.text))
|
|
99
99
|
return null;
|
|
100
100
|
if (word.text === "run" && (words[0].text === "deno" || words[0].text === "bun"))
|
|
101
101
|
continue;
|
|
@@ -108,6 +108,12 @@ function scriptOperand(words) {
|
|
|
108
108
|
}
|
|
109
109
|
return null;
|
|
110
110
|
}
|
|
111
|
+
/** Code given in a flag bundle: `perl -ne`, `ruby -pe`, `python3 -Ic`. */
|
|
112
|
+
function bundledCode(program, flag) {
|
|
113
|
+
if (program === "perl" || program === "ruby")
|
|
114
|
+
return /^-[a-zA-Z0-9]*[eE]/.test(flag);
|
|
115
|
+
return program.startsWith("python") && /^-[a-zA-Z]*c/.test(flag);
|
|
116
|
+
}
|
|
111
117
|
function runScript(program) {
|
|
112
118
|
return {
|
|
113
119
|
vendor: program,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** The hook's view of this computer's files (`cliHookLocal.ts`): injected so tests never touch them. */
|
|
2
|
+
import { type FileStat, type ScriptFile } from "./cliScriptRead.js";
|
|
3
|
+
/** What the hook can read from the machine. Injected so tests never touch it. */
|
|
4
|
+
export type LocalFs = {
|
|
5
|
+
/** The canonical path, or null when it doesn't exist. */
|
|
6
|
+
realpath(path: string): string | null;
|
|
7
|
+
/** A small text file, or null. */
|
|
8
|
+
readText(path: string): string | null;
|
|
9
|
+
isDirectory(path: string): boolean;
|
|
10
|
+
isFile(path: string): boolean;
|
|
11
|
+
/** A script up to 256 KB with its time and size (script reading), or null. */
|
|
12
|
+
readScript?(path: string): ScriptFile | null;
|
|
13
|
+
statFile?(path: string): FileStat | null;
|
|
14
|
+
};
|
|
15
|
+
export declare const NODE_FS: LocalFs;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/** The hook's view of this computer's files (`cliHookLocal.ts`): injected so tests never touch them. */
|
|
2
|
+
import { closeSync, fstatSync, lstatSync, openSync, readFileSync, readSync, realpathSync, statSync } from "node:fs";
|
|
3
|
+
import { SCRIPT_MAX_BYTES } from "./cliScriptRead.js";
|
|
4
|
+
const MAX_TEXT = 4096;
|
|
5
|
+
export const NODE_FS = {
|
|
6
|
+
realpath(path) {
|
|
7
|
+
try {
|
|
8
|
+
return realpathSync.native(path);
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
readText(path) {
|
|
15
|
+
try {
|
|
16
|
+
if (statSync(path).size > MAX_TEXT)
|
|
17
|
+
return null;
|
|
18
|
+
return readFileSync(path, "utf8");
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
isDirectory(path) {
|
|
25
|
+
try {
|
|
26
|
+
return statSync(path).isDirectory();
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
isFile(path) {
|
|
33
|
+
try {
|
|
34
|
+
return lstatSync(path).isFile() || statSync(path).isFile();
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
readScript(path) {
|
|
41
|
+
let descriptor;
|
|
42
|
+
try {
|
|
43
|
+
descriptor = openSync(path, "r");
|
|
44
|
+
const stat = fstatSync(descriptor);
|
|
45
|
+
if (!stat.isFile() || stat.size > SCRIPT_MAX_BYTES)
|
|
46
|
+
return null;
|
|
47
|
+
const buffer = Buffer.alloc(stat.size);
|
|
48
|
+
let offset = 0;
|
|
49
|
+
while (offset < stat.size) {
|
|
50
|
+
const read = readSync(descriptor, buffer, offset, stat.size - offset, offset);
|
|
51
|
+
if (read <= 0)
|
|
52
|
+
break;
|
|
53
|
+
offset += read;
|
|
54
|
+
}
|
|
55
|
+
// Binary files aren't scripts.
|
|
56
|
+
if (buffer.subarray(0, offset).includes(0))
|
|
57
|
+
return null;
|
|
58
|
+
return { text: buffer.toString("utf8", 0, offset), mtimeMs: stat.mtimeMs, size: stat.size };
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
finally {
|
|
64
|
+
if (descriptor !== undefined)
|
|
65
|
+
closeSync(descriptor);
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
statFile(path) {
|
|
69
|
+
try {
|
|
70
|
+
const stat = statSync(path);
|
|
71
|
+
return stat.isFile() ? { mtimeMs: stat.mtimeMs, size: stat.size } : null;
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the hooks and `passport exec` meet late approvals (`approvalNotice.ts`):
|
|
3
|
+
* remember a session that opened a request a person answers later, and on
|
|
4
|
+
* that session's next prompt or resume, print what was approved meanwhile.
|
|
5
|
+
*/
|
|
6
|
+
import { type ParsedArgs } from "./cliArgs.js";
|
|
7
|
+
import type { GuardPlan } from "./cliHookDecide.js";
|
|
8
|
+
import type { HookDependencies } from "./cliHookDeliver.js";
|
|
9
|
+
import type { HookInput } from "./cliHookInput.js";
|
|
10
|
+
import type { Runtime } from "./cliSupport.js";
|
|
11
|
+
/** The guard opened a request a person answers later (not one approved during the hold). */
|
|
12
|
+
export declare function rememberGuardAsk(plan: GuardPlan, client: string, sessionId: string | undefined, now: number): Promise<void>;
|
|
13
|
+
/** `passport exec` opened a request: the same, from its request body. */
|
|
14
|
+
export declare function rememberExecAsk(approvalId: string, body: Record<string, unknown>, now: number): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* On Claude Code's SessionStart or UserPromptSubmit: context for the agent
|
|
17
|
+
* about approvals it missed, never more than the hook's budget. True when the
|
|
18
|
+
* event was a prompt, which the audit hook has nothing else to do for.
|
|
19
|
+
*/
|
|
20
|
+
export declare function tellApproved(input: HookInput, args: ParsedArgs, runtime: Runtime, deps: HookDependencies, budget: AbortSignal,
|
|
21
|
+
/** Managed settings run Passport's hooks instead: this copy stays quiet. */
|
|
22
|
+
managedElsewhere: () => boolean): Promise<boolean>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the hooks and `passport exec` meet late approvals (`approvalNotice.ts`):
|
|
3
|
+
* remember a session that opened a request a person answers later, and on
|
|
4
|
+
* that session's next prompt or resume, print what was approved meanwhile.
|
|
5
|
+
*/
|
|
6
|
+
import { value } from "./cliArgs.js";
|
|
7
|
+
/** The guard opened a request a person answers later (not one approved during the hold). */
|
|
8
|
+
export async function rememberGuardAsk(plan, client, sessionId, now) {
|
|
9
|
+
if (!plan.server?.approvalId || plan.server.decision !== "ask" || plan.held === "approved")
|
|
10
|
+
return;
|
|
11
|
+
(await import("./approvalNotice.js")).noteWaitingSession(client, sessionId, now);
|
|
12
|
+
}
|
|
13
|
+
/** `passport exec` opened a request: the same, from its request body. */
|
|
14
|
+
export async function rememberExecAsk(approvalId, body, now) {
|
|
15
|
+
if (approvalId && typeof body.runtime === "string" && typeof body.sessionId === "string") {
|
|
16
|
+
(await import("./approvalNotice.js")).noteWaitingSession(body.runtime, body.sessionId, now);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* On Claude Code's SessionStart or UserPromptSubmit: context for the agent
|
|
21
|
+
* about approvals it missed, never more than the hook's budget. True when the
|
|
22
|
+
* event was a prompt, which the audit hook has nothing else to do for.
|
|
23
|
+
*/
|
|
24
|
+
export async function tellApproved(input, args, runtime, deps, budget,
|
|
25
|
+
/** Managed settings run Passport's hooks instead: this copy stays quiet. */
|
|
26
|
+
managedElsewhere) {
|
|
27
|
+
const event = input.hook_event_name;
|
|
28
|
+
if (event !== "SessionStart" && event !== "UserPromptSubmit")
|
|
29
|
+
return false;
|
|
30
|
+
const prompt = event === "UserPromptSubmit";
|
|
31
|
+
const [{ localProfile, profileApi }, { approvalNotice }] = await Promise.all([
|
|
32
|
+
import("./cliHookDeliver.js"),
|
|
33
|
+
import("./approvalNotice.js")
|
|
34
|
+
]);
|
|
35
|
+
const profile = localProfile(args, runtime.env);
|
|
36
|
+
if (!profile || runtime.env.PASSPORT_AGENT_KEY || runtime.env.PASSPORT_ENDPOINT || managedElsewhere())
|
|
37
|
+
return prompt;
|
|
38
|
+
// Session events carry no tool-use id: an entry without `--client` is Claude Code's.
|
|
39
|
+
const named = (value(args, "client") ?? runtime.env.PASSPORT_HOOK_RUNTIME)?.trim().toLowerCase();
|
|
40
|
+
const output = await approvalNotice(input, {
|
|
41
|
+
runtime: named && named !== "claude-code" ? named : "claude-code",
|
|
42
|
+
openApi: () => profileApi(profile, budget, deps.fetch ?? fetch),
|
|
43
|
+
signal: budget,
|
|
44
|
+
now: deps.now ?? Date.now
|
|
45
|
+
});
|
|
46
|
+
if (output)
|
|
47
|
+
runtime.stdout.write(`${JSON.stringify(output)}\n`);
|
|
48
|
+
return prompt;
|
|
49
|
+
}
|
package/dist/cliHookScripts.d.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import type { CliFinding } from "./cliHookClassify.js";
|
|
9
9
|
import type { CodeScript } from "./cliHookLocalCode.js";
|
|
10
10
|
import type { CommandShape } from "./cliHookParse.js";
|
|
11
|
+
import type { Blind } from "./blindKind.js";
|
|
11
12
|
import { type ScriptFs, type ScriptReader, type ScriptSegment } from "./cliScriptRead.js";
|
|
12
13
|
import type { LocalAction, Place, ShellWord } from "./localCommands.js";
|
|
13
14
|
/** The parts of the classifier's machine script reading needs. */
|
|
@@ -24,7 +25,7 @@ export type ScriptMachine = {
|
|
|
24
25
|
type Walk = {
|
|
25
26
|
findings: CliFinding[];
|
|
26
27
|
complete: boolean;
|
|
27
|
-
blind?:
|
|
28
|
+
blind?: Blind;
|
|
28
29
|
};
|
|
29
30
|
/** The classifier's helpers, passed in. */
|
|
30
31
|
export type ScriptHost<M extends ScriptMachine> = {
|
package/dist/cliOutput.js
CHANGED
|
@@ -151,10 +151,10 @@ function helpText(verb) {
|
|
|
151
151
|
env: "passport env [--json]\npassport env set <vendor> <resource> <production|staging|development>\nShows where commands in this folder land, read the way each vendor's own CLI reads it: Railway, Vercel, Supabase, Wrangler, Netlify, Firebase, Convex, Neon, Fly, Heroku, kubectl, AWS, gcloud, Terraform, Stripe, and database URLs. One row per app: the resource, how Passport knows (linked, a flag, the vendor's default), and its environment. Anything Passport can't place counts as Production. Read on this computer; nothing is sent.\n set place a resource for the whole workspace. Admins choose any environment; everyone else can only say Production.\nJSON: {environments:[{vendor,resource,how,kind,assumed,note?}]}",
|
|
152
152
|
sessions:
|
|
153
153
|
// copy-style-allow double-space: help columns line up
|
|
154
|
-
"passport sessions [--all] [--running] [--production-changes] [--project <name>] [--pr <number>] [--since <when>] [--status running|ended]\npassport sessions <session-id>\nYour agents' work the way the Sessions page shows it: work items (a pull request or branch, every session on it rolled up) by project, each with its agents and what happened: actions, active time, failures, confirmed Production changes, unplaced changes, asks and how they ended, and how much Passport couldn't check. Notable work comes first; routine work folds into one line per project.\n --all every work item, routine ones too (pass one of --all, --running, --production-changes)\n --running work items with a running session\n --production-changes changes to confirmed Production, by app and target (7 days unless --since)\n --project <name> one project (repository, else folder)\n --pr <number> one pull request\n --since <when> today, 24h, 7d, 30d, 90d, or a date (YYYY-MM-DD)\n --status <status> running or ended sessions only\n <session-id> one session: its outcome and recent actions with what they acted on\nJSON: {view,groups:[{key,kind,label,apps,running,production,unplaced,items:[{key,title,project,branch,pull,agents,sessions,sessionIds,startedAt,lastActivityAt,activeMs,running,waiting,shape,reasons,severity,link}],routine}],totals,complete,nextCursor}; --production-changes: {view,sinceTs,untilTs,total,unplaced,apps:[{appKey,appName,count,lastTs,targets}]}; <session-id>: {view,session,outcome,approvals,timeline,nextCursor}",
|
|
154
|
+
"passport sessions [--all] [--running] [--production-changes] [--project <name>] [--pr <number>] [--since <when>] [--status running|ended]\npassport sessions <session-id>\nYour agents' work the way the Sessions page shows it: work items (a pull request or branch, every session on it rolled up) by project, each with its agents and what happened: actions, active time, failures, confirmed Production changes, unplaced changes, asks and how they ended, and how much Passport couldn't check. Notable work comes first; routine work folds into one line per project.\n --all every work item, routine ones too (pass one of --all, --running, --production-changes)\n --running work items with a running session\n --production-changes changes to confirmed Production, by app and target (7 days unless --since)\n --project <name> one project (repository, else folder)\n --pr <number> one pull request\n --since <when> today, 24h, 7d, 30d, 90d, or a date (YYYY-MM-DD)\n --status <status> running or ended sessions only\n <session-id> one session: its outcome and recent actions with what they acted on\nJSON: {view,groups:[{key,kind,label,apps,running,production,unplaced,items:[{key,title,project,branch,pull,agents,sessions,sessionIds,startedAt,lastActivityAt,activeMs,running,waiting,shape,reasons,severity,link}],routine}],totals,work,window,complete,nextCursor}; --production-changes: {view,sinceTs,untilTs,total,unplaced,window,apps:[{appKey,appName,count,lastTs,targets}]}; <session-id>: {view,session,outcome,approvals,timeline,nextCursor}",
|
|
155
155
|
changes:
|
|
156
156
|
// copy-style-allow double-space: help columns line up
|
|
157
|
-
"passport changes [--env production] [--since <when>] [--until <date>] [--project <name>] [--pr <number>] [--app <key>] [--agent <id>]\nWhat your agents changed in Production, the list Sessions › Production changes shows: every change, delete, and irreversible action that ran on confirmed Production in the window, grouped by app, newest first. Each row has its time and command, then the agent, the person, the pull request (else branch), Failed or Approved, and whether Passport can undo it. Blocked and declined actions never reached Production and aren't listed; changes to targets nobody placed are one count.\n --env <env> production (the only one for now)\n --since <when> 1h, 6h, 24h (default),
|
|
157
|
+
"passport changes [--env production] [--since <when>] [--until <date>] [--project <name>] [--pr <number>] [--app <key>] [--agent <id>]\nWhat your agents changed in Production, the list Sessions › Production changes shows: every change, delete, and irreversible action that ran on confirmed Production in the window, grouped by app, newest first. Each row has its time and command, then the agent, the person, the pull request (else branch), Failed or Approved, and whether Passport can undo it. Blocked and declined actions never reached Production and aren't listed; changes to targets nobody placed are one count.\n --env <env> production (the only one for now)\n --since <when> 1h, 6h, 24h, 7d (default), 30d, today, or a date (YYYY-MM-DD)\n --until <date> through the end of a date (YYYY-MM-DD)\n --project <name> one project (repository, else folder)\n --pr <number> one pull request\n --app <key> one app, or several separated by commas\n --agent <id> one agent (claude-code, codex, cursor)\nJSON: {view,environment,sinceTs,untilTs,total,unplaced,complete,window,apps:[{vendor,appName,changes:[{id,ts,person,agent,agentName,appKey,vendor,appName,command,target,actionClass,result,approved,sessionId,project,branch,pull,undo}]}]}",
|
|
158
158
|
// copy-style-allow double-space: help columns line up
|
|
159
159
|
exec: "passport exec [--wait <sec>] [--ask-again] [--verbose] [--mask | --no-masking] -- <cli> [args…]\nRuns railway, gh, vercel, wrangler, supabase, stripe, aws, neonctl, or flyctl with a key Passport holds, after your Autopilot rules decide. The key reaches only that command's environment, short-lived where the vendor allows (GitHub App tokens, 15-minute AWS sessions, 15-minute Cloudflare tokens). The exit code passes through unchanged.\n Output: when stdout isn't a terminal (an agent's shell, a pipe, a log), any copy of the key the CLI prints (raw, base64, or URL-encoded) reads <hidden by Passport>, since that output is kept and read later. In a terminal the CLI gets the terminal itself (colors, prompts), unmasked.\n --mask hide the key in a terminal too (the CLI then writes to a pipe)\n --no-masking never hide it (in a shim, set PASSPORT_EXEC_NO_MASKING=1)\n --verbose say which key was issued (on stderr)\n Asks: waits for your approval in Passport when you're at the keyboard or with --wait; otherwise exits 4 with the approval id. Run passport wait <id>, then the command again.\n Blocked or declined: exit 5 with the reason. A decline answers the same command for ten minutes; --ask-again requests it again.\n No key in Passport, or it stopped working: exit 3.\n Offline: nothing runs (exit 1); exec never uses a key on this computer.\n Refuses shells, env, and subcommands that would print the key or run another program with it.",
|
|
160
160
|
// copy-style-allow double-space: help columns line up
|
|
@@ -5,5 +5,5 @@ export declare function projectOf(raw: unknown, link: string | null): ProjectJso
|
|
|
5
5
|
/** Where each target is placed: "acme-api main Production, deploys on merge". */
|
|
6
6
|
export declare function environmentCells(env: ProjectEnvironmentJson): [string, string];
|
|
7
7
|
/** The summary block: name and counts, Environments, Rules, and Production
|
|
8
|
-
* changes
|
|
8
|
+
* changes, all over the server's window, each section only when it has something. */
|
|
9
9
|
export declare function renderProject(project: ProjectJson, term: Term): string;
|