passport-bridge 0.11.3 → 0.13.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 +76 -10
- package/dist/cli.js +24 -0
- package/dist/cliArgs.d.ts +1 -1
- package/dist/cliArgs.js +14 -2
- package/dist/cliHook.d.ts +54 -11
- package/dist/cliHook.js +317 -75
- package/dist/cliHookClassify.d.ts +6 -0
- package/dist/cliHookClassify.js +23 -1
- package/dist/cliHookGuard.d.ts +39 -0
- package/dist/cliHookGuard.js +127 -0
- package/dist/cliHookInstall.d.ts +54 -21
- package/dist/cliHookInstall.js +397 -119
- package/dist/cliHookPending.d.ts +31 -0
- package/dist/cliHookPending.js +141 -0
- package/dist/cliInit.d.ts +74 -0
- package/dist/cliInit.js +477 -0
- package/dist/cliLogin.d.ts +15 -1
- package/dist/cliLogin.js +219 -41
- package/dist/cliOutput.js +10 -4
- package/dist/cliPolicy.d.ts +63 -0
- package/dist/cliPolicy.js +216 -0
- package/dist/cliScan.d.ts +21 -0
- package/dist/cliScan.js +220 -0
- package/dist/cliSupport.d.ts +2 -0
- package/dist/completion.js +8 -3
- package/dist/discover.d.ts +9 -0
- package/dist/discover.js +18 -11
- package/dist/initAgents.d.ts +83 -0
- package/dist/initAgents.js +503 -0
- package/dist/initAppsStep.d.ts +22 -0
- package/dist/initAppsStep.js +346 -0
- package/dist/initInstall.d.ts +58 -0
- package/dist/initInstall.js +372 -0
- package/dist/initLocalSteps.d.ts +7 -0
- package/dist/initLocalSteps.js +313 -0
- package/dist/initState.d.ts +112 -0
- package/dist/initState.js +80 -0
- package/dist/initUi.d.ts +73 -0
- package/dist/initUi.js +273 -0
- package/dist/nodeVersion.d.ts +13 -0
- package/dist/nodeVersion.js +42 -0
- package/dist/passport.d.ts +1 -0
- package/dist/passport.js +21 -1
- package/dist/scan.d.ts +3 -0
- package/dist/scan.js +274 -0
- package/dist/scanCore.d.ts +139 -0
- package/dist/scanCore.js +386 -0
- package/dist/scanParse.d.ts +36 -0
- package/dist/scanParse.js +275 -0
- package/dist/scanRules.d.ts +246 -0
- package/dist/scanRules.js +402 -0
- package/dist/scanStores.d.ts +3 -0
- package/dist/scanStores.js +221 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/npm-shrinkwrap.json +8 -8
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -13,21 +13,33 @@ Member profiles get the same tool access, agent selection, guardrails, approvals
|
|
|
13
13
|
npm install --global passport-bridge
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
-
Requires Node.js 22.23.2 or newer. The CLI makes no background registry request, telemetry, or self-update; check with `npm view passport-bridge version` and upgrade with `npm install --global passport-bridge@latest`.
|
|
16
|
+
Requires Node.js 22.23.2 or newer. `npx passport-bridge scan` and `npx passport-bridge init` need no install and run on Node.js 20 or newer; `scan` also needs no account. The CLI makes no background registry request, telemetry, or self-update; check with `npm view passport-bridge version` and upgrade with `npm install --global passport-bridge@latest`.
|
|
17
17
|
|
|
18
18
|
## Quick start
|
|
19
19
|
|
|
20
|
+
New here? One command sets everything up:
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
npx passport-bridge init
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
It scans for keys your agents can reach, signs you in (or up), connects the apps it found, adds Passport to your agents, turns on the guard, and makes destructive actions ask first. See [Set up with init](#set-up-with-init).
|
|
27
|
+
|
|
28
|
+
Or step by step:
|
|
29
|
+
|
|
20
30
|
```sh
|
|
21
|
-
passport login
|
|
31
|
+
passport login
|
|
22
32
|
passport status
|
|
23
33
|
passport search "open issues"
|
|
24
34
|
passport describe github_search_issues
|
|
25
35
|
passport run github_search_issues '{"query":"SSO"}'
|
|
26
36
|
```
|
|
27
37
|
|
|
28
|
-
-
|
|
38
|
+
- First time? Bare `passport login` opens `/cli` in your browser. Sign in with Google, GitHub, or an emailed code, then connect a workspace you belong to or create one. No workspace id needed.
|
|
39
|
+
- Confirm that the code in the browser matches the one in your terminal. Nothing connects until you click Connect.
|
|
29
40
|
- Re-signing in? Bare `passport login` reuses the workspace of the active profile, the sole CLI profile, or the one workspace all saved profiles share. With several workspaces saved it lists them and asks for `--workspace`.
|
|
30
|
-
- `--
|
|
41
|
+
- `--workspace ws_example` signs in to one known workspace (the device flow). Self-hosted: add `--cloud https://passport.example.com` (origin only). A server without browser sign-in keeps asking for `--workspace`.
|
|
42
|
+
- `--no-open` (or `PASSPORT_NO_OPEN=1`) prints the sign-in link instead of opening a browser. Use it over SSH and in headless sessions; open the link on any device.
|
|
31
43
|
- Remote servers must use HTTPS. Plain HTTP works only on `localhost`, `127.0.0.0/8`, or `::1`.
|
|
32
44
|
- Requires a gateway reporting serverInfo `passport` 0.5.0 or newer with the four-tool CLI protocol; older servers fail before any tool call.
|
|
33
45
|
- `passport help [command]` documents every option. `help`, `version`, `profiles`, `use`, and `completion` work offline.
|
|
@@ -36,7 +48,8 @@ passport run github_search_issues '{"query":"SSO"}'
|
|
|
36
48
|
|
|
37
49
|
| Command | Purpose |
|
|
38
50
|
| --- | --- |
|
|
39
|
-
| `
|
|
51
|
+
| `init [--yes] [--no-open] [--cloud <origin>] [--skip-apps\|--skip-agents\|--skip-guard] [--verbose] [--json]` | Set up Passport for this computer's agents in one pass. Every step asks first, can be skipped, and is safe to run again. |
|
|
52
|
+
| `login` | Browser sign-in or sign-up (or device sign-in with `--workspace`); saves a rotating CLI credential and makes the profile active. |
|
|
40
53
|
| `logout` | Revoke the credential and always remove the local profile (warns if revocation fails). |
|
|
41
54
|
| `profiles` / `use <name>` | List stored profiles / select the active one. Offline. |
|
|
42
55
|
| `status` | Workspace, member, agent, and app connection states. |
|
|
@@ -48,8 +61,9 @@ passport run github_search_issues '{"query":"SSO"}'
|
|
|
48
61
|
| `connect [app...] [--alias <name>] [--open] [--wait <s>]` | Show member sign-in links and optionally wait for completion. |
|
|
49
62
|
| `resources [uri] [--out <file>]` | List or read MCP resources. |
|
|
50
63
|
| `prompts [name] [--set k=v] [--out <file>]` | List or get MCP prompts. |
|
|
64
|
+
| `scan [--path <dir>] [--verbose] [--check]` | Find keys your agents can reach on this computer and what each can do. Local only, no account. `--check` scans files only (not the shell environment) and exits 5 on a high or medium key. |
|
|
51
65
|
| `discover` | Scan local MCP configuration and submit a privacy-minimized fleet report. Exit 5 on a managed-policy violation. |
|
|
52
|
-
| `hook` |
|
|
66
|
+
| `hook` | Records the CLIs agents run and, with `--guard`, asks before recognized destructive ones (`install`, `uninstall`, `status`). |
|
|
53
67
|
| `setup` | Install and maintain assigned team workflows as managed skills. |
|
|
54
68
|
| `session` | Run NDJSON commands over one authenticated MCP session. |
|
|
55
69
|
| `access` | Signed managed access: `keygen`, `actions`, `run`, `invoke`, `status`, `cancel`. |
|
|
@@ -91,6 +105,47 @@ passport prompts github_summarize --set note=welcome
|
|
|
91
105
|
|
|
92
106
|
Human mode prints text content. Binary content needs `--out <file>` or `--json`.
|
|
93
107
|
|
|
108
|
+
### Key scan
|
|
109
|
+
|
|
110
|
+
```sh
|
|
111
|
+
npx passport-bridge scan # or: passport scan
|
|
112
|
+
passport scan --path ../api --verbose
|
|
113
|
+
passport scan --check # CI and pre-commit: files only, exit 5 on a high or medium key
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Reads agent MCP configs (Claude Desktop, Claude Code, Cursor, VS Code, Codex), CLI sign-in files (GitHub CLI, Railway, Vercel, Wrangler, AWS, Stripe CLI, Supabase, npm), well-known shell variable names, and `.env*` files up to three folders deep in the project. It never prints or saves any part of a key, opens no network connection, needs no profile, and skips `.env` files in your home folder. Sign-ins held by the OS keychain are named but not flagged. `passport-bridge scan` and `passport-bridge init` run the `passport` CLI's own implementation.
|
|
117
|
+
|
|
118
|
+
### Set up with init
|
|
119
|
+
|
|
120
|
+
```sh
|
|
121
|
+
npx passport-bridge init # or: passport init
|
|
122
|
+
npx passport-bridge init --yes # accept every default; needed without a terminal
|
|
123
|
+
npx passport-bridge init --yes --json # one summary object with each step's status
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Six steps, each reusing the command that owns it:
|
|
127
|
+
|
|
128
|
+
1. **Scan**: the same local scan as `passport scan`, as one summary line (`--verbose` prints the table).
|
|
129
|
+
2. **Sign in**: reuses the active or only CLI profile, asks which one when there are several, or runs the browser sign-in from `passport login`.
|
|
130
|
+
3. **Apps**: Railway, Vercel, Supabase, Cloudflare, GitHub, and Stripe, when the scan found a key or its CLI is on PATH. Missing apps are added through the same catalog rules as the web (an app your workspace reviews first says `! Stripe needs approval from your admin.`), then one sign-in page covers the rest. In a terminal init waits until they connect (Enter stops waiting); without one it prints the page and `Next: passport connect --wait 300` and moves on.
|
|
131
|
+
4. **Agents**: the workspace's remote MCP URL (`https://<host>/w/<workspace>/mcp`) with each agent's own browser sign-in, so no token lands in a config file. Claude Code and Codex through their own CLIs (`claude mcp add --transport http --scope user`, `codex mcp add --url`), Cursor through `~/.cursor/mcp.json`, VS Code through `code --add-mcp` or its user `mcp.json`. Claude Desktop connects through Settings → Connectors, so init prints that step.
|
|
132
|
+
5. **Guard**: `passport hook install --guard` for Claude Code, Codex, and Cursor, pointing at a stable copy of the CLI in `$PASSPORT_HOME/cli/<version>/` (never npm's cache), or at a global `passport-bridge` of the same version or newer. Once the new copy is in place, older copies are deleted unless a hook still runs them.
|
|
133
|
+
6. **Safety**: when production safety is off, asks `Ask before destructive actions in <apps>? [Y/n]` (`--yes` turns it on). Ask first, Block, or a stricter team setting is shown and left as is.
|
|
134
|
+
|
|
135
|
+
What changes on disk, and how to undo it:
|
|
136
|
+
|
|
137
|
+
| Where | What | Undo |
|
|
138
|
+
| --- | --- | --- |
|
|
139
|
+
| `~/.passport/credentials.json` | A `cli@<workspace>` profile, as `passport login` writes | `passport logout` |
|
|
140
|
+
| `~/.passport/cli/` | A copy of this CLI and `bin/passport` launchers | Delete the folder (after removing the hooks) |
|
|
141
|
+
| `~/.claude.json` | A `passport` MCP server entry, via `claude mcp add` | `claude mcp remove --scope user passport` |
|
|
142
|
+
| `~/.codex/config.toml` | `[mcp_servers.passport]`, via `codex mcp add` | `codex mcp remove passport` |
|
|
143
|
+
| `~/.cursor/mcp.json` | `mcpServers.passport` | Delete that entry |
|
|
144
|
+
| VS Code user `mcp.json` | `servers.passport` | `MCP: List Servers`, then remove it |
|
|
145
|
+
| `~/.claude/settings.json`, `~/.codex/hooks.json`, `~/.cursor/hooks.json` | Passport's audit and guard hooks | `passport hook uninstall --client <agent> --apply` |
|
|
146
|
+
|
|
147
|
+
Before editing a file it didn't create, init says which file and keeps one copy of the original as `<file>.passport-backup`. It changes only Passport's own entries, writes atomically, refuses a malformed file with one line, and leaves an existing Passport entry alone unless it points at npm's cache or a file that's gone. Ctrl-C at any point stops cleanly; run init again to pick up where it left off. Without a terminal, `init` needs `--yes` (exit 6 otherwise), and `--json` needs `--yes`. It never edits your shell profile: it prints the one `PATH` line to add if you want `passport` everywhere.
|
|
148
|
+
|
|
94
149
|
### Team workflows
|
|
95
150
|
|
|
96
151
|
Codex and Claude Code on macOS and Linux. Requires a member profile.
|
|
@@ -109,12 +164,22 @@ Changes preview unless `--apply` is passed. Personal edits are preserved. `insta
|
|
|
109
164
|
### Shell hook
|
|
110
165
|
|
|
111
166
|
```sh
|
|
112
|
-
passport hook install --client claude-code --apply
|
|
167
|
+
passport hook install --client claude-code --guard --apply # or codex, cursor
|
|
113
168
|
passport hook status
|
|
114
|
-
passport hook uninstall --client claude-code --apply
|
|
169
|
+
passport hook uninstall --client claude-code --guard --apply # guard only
|
|
115
170
|
```
|
|
116
171
|
|
|
117
|
-
|
|
172
|
+
Two hooks per agent. `passport hook` runs after each shell command and records the vendor, a coarse verb, and a risk class in Activity. `passport hook guard` runs before it: for a destructive verb in `src/cliHookVendors.ts` it answers ask, or deny when the member's safety settings block it, and otherwise prints nothing so the agent's own permission rules apply. It never answers allow. The strictest finding in a compound command wins; scripts, aliases, `make`, and `npm run` get no decision, and `--help` or `--dry-run` never trigger it.
|
|
173
|
+
|
|
174
|
+
The guard decides from local data inside `HOOK_BUDGET_MS` (1.5 s) and prints first. With the budget left, it reports its `decision` and, at most every ten minutes, refreshes a policy cache older than an hour. Any failure is silent and fails open. Neither hook sends the command line, output, folder path, or environment.
|
|
175
|
+
|
|
176
|
+
An ask becomes one Activity row. In Claude Code, with the audit hook registered, the guard parks its report in `$PASSPORT_HOME/hook-pending/` (`src/cliHookPending.ts`, mode 600, claimed by atomic rename). The audit hook for the same tool-use id sends the run with `decision: "ask", ran: true` ("asked first, then ran"). An ask nobody claims within 30 minutes (no agent fires a hook for a declined prompt) is sent by the next hook run as `ran: false` ("asked first, not run"). Cursor has no tool-use id to match, so its asks are sent at once as their own "asked first" row. Denies are always sent at once.
|
|
177
|
+
|
|
178
|
+
- Claude Code: `PreToolUse`, plus `PostToolUse` and `PostToolUseFailure` (failed or interrupted calls, recorded as ran with a non-zero exit), in `~/.claude/settings.json` (`CLAUDE_CONFIG_DIR` honored).
|
|
179
|
+
- Codex: the same events in `~/.codex/hooks.json` (`CODEX_HOME` honored). Codex doesn't support ask yet, so the guard only denies there. Trust the hooks in Codex's `/hooks`.
|
|
180
|
+
- Cursor: `beforeShellExecution`/`afterShellExecution` in `~/.cursor/hooks.json`. Cursor also imports Claude Code's hooks by default; that imported copy records nothing when Passport's own Cursor entry exists, so rows aren't doubled.
|
|
181
|
+
|
|
182
|
+
`src/cliPolicy.ts` caches the member's CLI policy (`GET /api/my/cli-policy`) at `$PASSPORT_HOME/cli-policy/<profile>.json` (mode 600). `passport login` and `passport status` refresh it and `passport logout` removes it. A 404 or error keeps the previous copy; with no copy the guard asks before every destructive verb. `PASSPORT_HOOK_DISABLED=1` turns both hooks off.
|
|
118
183
|
|
|
119
184
|
### Persistent sessions
|
|
120
185
|
|
|
@@ -221,7 +286,7 @@ With `--json`, stdout is exactly one JSON value; hints and warnings go to stderr
|
|
|
221
286
|
|
|
222
287
|
| Command | JSON value |
|
|
223
288
|
| --- | --- |
|
|
224
|
-
| `login` | `{profile,endpoint,client,surface,active,next}` |
|
|
289
|
+
| `login` | `{profile,endpoint,client,surface,active,workspaceId,workspaceName?,next}` (`workspaceName` after browser sign-in) |
|
|
225
290
|
| `profiles` | `{profiles:[{name,active,client?}],active?}` |
|
|
226
291
|
| `use` | `{profile,active:true}` |
|
|
227
292
|
| `logout` | `{profile,removed,revoked}` |
|
|
@@ -234,6 +299,7 @@ With `--json`, stdout is exactly one JSON value; hints and warnings go to stderr
|
|
|
234
299
|
| `connect` | Gateway payload with `connections` and optional `connectAllUrl` |
|
|
235
300
|
| `resources`, `prompts` | MCP list, read, or get result |
|
|
236
301
|
| `discover` | `{snapshot,report,compliant}` |
|
|
302
|
+
| `scan` | `{version:1,findings:[{id,provider,kind,label,severity,location,locations,blastRadius}],agents,unreadable,checked}` |
|
|
237
303
|
| `session` | NDJSON `{id?,ok,exitCode,result?}` or `{id?,ok:false,error,cause,exitCode,...}` |
|
|
238
304
|
| `access` | `keygen`: algorithm, paths, public JWK; `actions`: `{actions}`; `run`/`cancel`: `{run}`; `invoke`: governed result; `status`: `{receipt}` |
|
|
239
305
|
| `completion` | `{shell,script}` |
|
package/dist/cli.js
CHANGED
|
@@ -10,6 +10,7 @@ import { LEGACY_REQUEST_TIMEOUT_MS, legacyCloudOrigin, legacyCredentialEndpoint,
|
|
|
10
10
|
import { VERSION } from "./version.js";
|
|
11
11
|
import { recoveryIdentity } from "./recoveryIdentity.js";
|
|
12
12
|
import { revokeIssuedRecoveryCredential } from "./recoveryCleanup.js";
|
|
13
|
+
import { ensureOneLinerRuntime, oneLinerNodeProblem } from "./nodeVersion.js";
|
|
13
14
|
/**
|
|
14
15
|
* passport-bridge — the local tier.
|
|
15
16
|
*
|
|
@@ -26,8 +27,29 @@ function arg(flag, fallback = "") {
|
|
|
26
27
|
const i = process.argv.indexOf(flag);
|
|
27
28
|
return i >= 0 && process.argv[i + 1] ? process.argv[i + 1] : fallback;
|
|
28
29
|
}
|
|
30
|
+
/** `npx passport-bridge scan` and `npx passport-bridge init` run the `passport`
|
|
31
|
+
* CLI's own implementation, so both bins behave identically. */
|
|
32
|
+
const PASSPORT_ONE_LINERS = new Set(["scan", "init"]);
|
|
33
|
+
async function passportOneLiner() {
|
|
34
|
+
const problem = oneLinerNodeProblem();
|
|
35
|
+
if (problem) {
|
|
36
|
+
process.stderr.write(`${problem}\n`);
|
|
37
|
+
process.exitCode = 1;
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
ensureOneLinerRuntime();
|
|
41
|
+
const { main: passport } = await import("./passport.js");
|
|
42
|
+
process.exitCode = await passport(process.argv.slice(2), process.env, {
|
|
43
|
+
stdin: process.stdin,
|
|
44
|
+
stdout: process.stdout,
|
|
45
|
+
stderr: process.stderr,
|
|
46
|
+
invokedAs: "passport-bridge"
|
|
47
|
+
});
|
|
48
|
+
}
|
|
29
49
|
async function main() {
|
|
30
50
|
const command = process.argv[2] ?? "serve";
|
|
51
|
+
if (PASSPORT_ONE_LINERS.has(command))
|
|
52
|
+
return passportOneLiner();
|
|
31
53
|
if (command === "managed-skills") {
|
|
32
54
|
const { managedSkillsIpcMain } = await import("./managedSkillsIpc.js");
|
|
33
55
|
return managedSkillsIpcMain();
|
|
@@ -57,6 +79,8 @@ Commands:
|
|
|
57
79
|
login Sign in and save a rotating bridge credential
|
|
58
80
|
status Check saved bridge profiles
|
|
59
81
|
logout Revoke and remove a saved profile
|
|
82
|
+
scan Find keys your agents can reach. Local, no account
|
|
83
|
+
init Set up Passport for your agents, step by step
|
|
60
84
|
|
|
61
85
|
Options:
|
|
62
86
|
--profile <name> Use a named profile (default: default)
|
package/dist/cliArgs.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const COMMANDS: readonly ["login", "logout", "profiles", "use", "status", "doctor", "ready", "search", "describe", "run", "connect", "resources", "prompts", "discover", "hook", "setup", "session", "access", "completion", "help", "version"];
|
|
1
|
+
export declare const COMMANDS: readonly ["init", "login", "logout", "profiles", "use", "status", "doctor", "ready", "search", "describe", "run", "connect", "resources", "prompts", "discover", "scan", "hook", "setup", "session", "access", "completion", "help", "version"];
|
|
2
2
|
export type Command = (typeof COMMANDS)[number];
|
|
3
3
|
export declare class ArgError extends Error {
|
|
4
4
|
}
|
package/dist/cliArgs.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export const COMMANDS = [
|
|
2
|
+
"init",
|
|
2
3
|
"login",
|
|
3
4
|
"logout",
|
|
4
5
|
"profiles",
|
|
@@ -13,6 +14,7 @@ export const COMMANDS = [
|
|
|
13
14
|
"resources",
|
|
14
15
|
"prompts",
|
|
15
16
|
"discover",
|
|
17
|
+
"scan",
|
|
16
18
|
"hook",
|
|
17
19
|
"setup",
|
|
18
20
|
"session",
|
|
@@ -28,11 +30,16 @@ const FLAGS = {
|
|
|
28
30
|
quiet: { kind: "boolean" },
|
|
29
31
|
caller: { kind: "value" },
|
|
30
32
|
help: { kind: "boolean" },
|
|
31
|
-
cloud: { kind: "value", commands: ["login"] },
|
|
33
|
+
cloud: { kind: "value", commands: ["login", "init"] },
|
|
32
34
|
workspace: { kind: "value", commands: ["login", "access"] },
|
|
33
35
|
client: { kind: "value", commands: ["login", "setup", "hook"] },
|
|
34
36
|
apply: { kind: "boolean", commands: ["setup", "hook"] },
|
|
35
|
-
|
|
37
|
+
guard: { kind: "boolean", commands: ["hook"] },
|
|
38
|
+
"no-open": { kind: "boolean", commands: ["login", "init"] },
|
|
39
|
+
yes: { kind: "boolean", commands: ["init"] },
|
|
40
|
+
"skip-apps": { kind: "boolean", commands: ["init"] },
|
|
41
|
+
"skip-agents": { kind: "boolean", commands: ["init"] },
|
|
42
|
+
"skip-guard": { kind: "boolean", commands: ["init"] },
|
|
36
43
|
app: { kind: "value", commands: ["search"] },
|
|
37
44
|
args: { kind: "value", commands: ["run"] },
|
|
38
45
|
set: { kind: "repeat", commands: ["run", "prompts"] },
|
|
@@ -41,6 +48,9 @@ const FLAGS = {
|
|
|
41
48
|
alias: { kind: "value", commands: ["connect"] },
|
|
42
49
|
open: { kind: "boolean", commands: ["connect"] },
|
|
43
50
|
out: { kind: "value", commands: ["resources", "prompts"] },
|
|
51
|
+
verbose: { kind: "boolean", commands: ["scan", "init"] },
|
|
52
|
+
path: { kind: "value", commands: ["scan"] },
|
|
53
|
+
check: { kind: "boolean", commands: ["scan"] },
|
|
44
54
|
input: { kind: "value", commands: ["access"] },
|
|
45
55
|
algorithm: { kind: "value", commands: ["access"] },
|
|
46
56
|
"private-key-file": { kind: "value", commands: ["access"] },
|
|
@@ -135,6 +145,7 @@ export function parseArgs(argv) {
|
|
|
135
145
|
}
|
|
136
146
|
function validateShape(command, positionals) {
|
|
137
147
|
const max = {
|
|
148
|
+
init: 0,
|
|
138
149
|
login: 0,
|
|
139
150
|
logout: 0,
|
|
140
151
|
profiles: 0,
|
|
@@ -147,6 +158,7 @@ function validateShape(command, positionals) {
|
|
|
147
158
|
resources: 1,
|
|
148
159
|
prompts: 1,
|
|
149
160
|
discover: 0,
|
|
161
|
+
scan: 0,
|
|
150
162
|
hook: 1,
|
|
151
163
|
setup: 3,
|
|
152
164
|
session: 0,
|
package/dist/cliHook.d.ts
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `passport hook
|
|
2
|
+
* `passport hook`: the shell hooks an agent runs around each command.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
4
|
+
* - `passport hook` (audit) runs after a command. It classifies the command
|
|
5
|
+
* locally, keeps the vendor, a coarse verb and a risk class, and records that
|
|
6
|
+
* as one Activity row per governed invocation.
|
|
7
|
+
* - `passport hook guard` runs before a command. For a destructive verb it
|
|
8
|
+
* recognises, it asks the person to confirm, or blocks when their safety
|
|
9
|
+
* settings say so. Otherwise it says nothing and the agent's own permission
|
|
10
|
+
* rules apply. It never answers "allow".
|
|
11
|
+
*
|
|
12
|
+
* Both decide from local data only, inside `HOOK_BUDGET_MS`, and neither ever
|
|
13
|
+
* sends the command line, its arguments, the output, the full working
|
|
14
|
+
* directory, or the environment. A failure of any kind is silent and fails
|
|
15
|
+
* open: the agent must never notice this hook going wrong.
|
|
10
16
|
*/
|
|
11
17
|
import { type ParsedArgs } from "./cliArgs.js";
|
|
12
18
|
import { type CliFinding } from "./cliHookClassify.js";
|
|
19
|
+
import { type GuardDecision } from "./cliHookGuard.js";
|
|
13
20
|
import { type CommandResult, type Env, type Runtime } from "./cliSupport.js";
|
|
14
|
-
/** Claude Code and
|
|
21
|
+
/** Claude Code, Codex, and Cursor fail open on a slow hook, so the budget is ours. */
|
|
15
22
|
export declare const HOOK_BUDGET_MS = 1500;
|
|
16
23
|
export declare const HOOK_RUNTIMES: readonly ["claude-code", "codex", "copilot", "cursor", "other"];
|
|
17
24
|
export type HookRuntime = (typeof HOOK_RUNTIMES)[number];
|
|
@@ -29,6 +36,12 @@ export type CliHookReport = {
|
|
|
29
36
|
}>;
|
|
30
37
|
opaque: boolean;
|
|
31
38
|
opaqueKinds?: string[];
|
|
39
|
+
/** What the guard answered before the command ran. */
|
|
40
|
+
decision?: "ask" | "deny";
|
|
41
|
+
/** With decision "ask": true when the command then ran (one row, "asked
|
|
42
|
+
* first, then ran"), false when no run followed (a declined prompt).
|
|
43
|
+
* Absent when the agent gives no tool-use id to match on (Cursor). */
|
|
44
|
+
ran?: boolean;
|
|
32
45
|
};
|
|
33
46
|
export type HookInput = {
|
|
34
47
|
session_id?: unknown;
|
|
@@ -38,23 +51,53 @@ export type HookInput = {
|
|
|
38
51
|
tool_input?: unknown;
|
|
39
52
|
tool_use_id?: unknown;
|
|
40
53
|
tool_response?: unknown;
|
|
54
|
+
/** Claude Code PostToolUseFailure: the call was interrupted, not an error. */
|
|
55
|
+
is_interrupt?: unknown;
|
|
56
|
+
/** Cursor's native shell events. */
|
|
57
|
+
command?: unknown;
|
|
58
|
+
conversation_id?: unknown;
|
|
59
|
+
cursor_version?: unknown;
|
|
60
|
+
duration?: unknown;
|
|
61
|
+
workspace_roots?: unknown;
|
|
41
62
|
};
|
|
42
63
|
export type HookDependencies = {
|
|
43
64
|
/** Deliver one report. The default posts it to the signed-in workspace. */
|
|
44
65
|
send?: (report: CliHookReport, signal: AbortSignal, runtime: Runtime, args: ParsedArgs) => Promise<void>;
|
|
45
|
-
/** Network seam for the default delivery. */
|
|
66
|
+
/** Network seam for the default delivery and the policy refresh. */
|
|
46
67
|
fetch?: typeof fetch;
|
|
68
|
+
now?: () => number;
|
|
69
|
+
};
|
|
70
|
+
/** One shell command, whichever agent format it arrived in. */
|
|
71
|
+
type ShellEvent = {
|
|
72
|
+
phase: "pre" | "post";
|
|
73
|
+
command: string;
|
|
74
|
+
/** Cursor's own beforeShellExecution / afterShellExecution. */
|
|
75
|
+
cursorNative: boolean;
|
|
76
|
+
/** Cursor running a hook it imported from Claude Code settings. */
|
|
77
|
+
cursorImported: boolean;
|
|
47
78
|
};
|
|
48
79
|
/** Keep the shape of the verb, never its arguments: anything that could carry a
|
|
49
80
|
* path, an endpoint, or a value is dropped rather than truncated. */
|
|
50
81
|
export declare function safeVerb(raw: string | null): string;
|
|
51
82
|
/** Why a command could not be read. Never what it was. */
|
|
52
83
|
export declare function opaqueKind(finding: CliFinding): string;
|
|
53
|
-
|
|
84
|
+
/**
|
|
85
|
+
* Which agent sent this. An installed hook names its client with `--client`;
|
|
86
|
+
* Cursor is also recognised by its own event names and version field, which
|
|
87
|
+
* wins even over `--client claude-code` because Cursor imports Claude Code's
|
|
88
|
+
* hooks by default.
|
|
89
|
+
*/
|
|
90
|
+
export declare function detectRuntime(input: HookInput, env: Env, declared?: string): HookRuntime;
|
|
54
91
|
/** Exit status of the command the agent ran, when the runtime reports one. */
|
|
55
92
|
export declare function outcomeOf(response: unknown): {
|
|
56
93
|
exitCode?: number;
|
|
57
94
|
durationMs?: number;
|
|
58
95
|
};
|
|
59
|
-
export declare function buildReport(input: HookInput, findings: CliFinding[], env: Env): CliHookReport | null;
|
|
96
|
+
export declare function buildReport(input: HookInput, findings: CliFinding[], env: Env, declared?: string): CliHookReport | null;
|
|
97
|
+
/** What the guard answered, and for which findings. The audit row that
|
|
98
|
+
* follows a command that ran carries its outcome and any opaque parts. */
|
|
99
|
+
export declare function buildDecisionReport(input: HookInput, decision: GuardDecision, env: Env, declared?: string): CliHookReport | null;
|
|
100
|
+
/** Normalise one stdin event into the command and when it runs. */
|
|
101
|
+
export declare function shellEvent(input: HookInput): ShellEvent | null;
|
|
60
102
|
export declare function hook(args: ParsedArgs, runtime: Runtime, deps?: HookDependencies): Promise<CommandResult>;
|
|
103
|
+
export {};
|