passport-bridge 0.16.1 → 0.16.3
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 +84 -84
- package/dist/cliHook.d.ts +4 -2
- package/dist/cliHook.js +5 -16
- package/dist/cliHookInstall.d.ts +7 -0
- package/dist/cliHookInstall.js +27 -4
- package/dist/cliHookLocal.d.ts +3 -0
- package/dist/cliHookLocal.js +48 -8
- package/dist/cliHookLocalCode.d.ts +36 -0
- package/dist/cliHookLocalCode.js +211 -0
- package/dist/cliHookOpaque.d.ts +16 -0
- package/dist/cliHookOpaque.js +29 -0
- package/dist/cliKeys.js +7 -1
- package/dist/cliSetupOrg.js +2 -2
- package/dist/initInstall.d.ts +12 -0
- package/dist/initInstall.js +92 -11
- package/dist/initLocalSteps.js +2 -2
- package/dist/keysKeychain.d.ts +14 -0
- package/dist/keysKeychain.js +52 -0
- package/dist/keysLocal.d.ts +37 -2
- package/dist/keysLocal.js +117 -82
- package/dist/keysLocalEdit.d.ts +13 -0
- package/dist/keysLocalEdit.js +153 -0
- package/dist/localCommands.js +6 -3
- 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 +9 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -46,34 +46,34 @@ passport run github_search_issues '{"query":"SSO"}'
|
|
|
46
46
|
|
|
47
47
|
## Commands
|
|
48
48
|
|
|
49
|
-
| Command
|
|
50
|
-
|
|
|
51
|
-
| `init [--yes] [--move-keys] [--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`
|
|
53
|
-
| `logout`
|
|
54
|
-
| `profiles` / `use <name>`
|
|
55
|
-
| `status`
|
|
56
|
-
| `doctor`
|
|
57
|
-
| `ready`
|
|
58
|
-
| `search [query] [--app <key>]`
|
|
59
|
-
| `describe <tool>`
|
|
60
|
-
| `run <tool> [json]`
|
|
61
|
-
| `connect [app...] [--alias <name>] [--open] [--wait <s>]`
|
|
62
|
-
| `resources [uri] [--out <file>]`
|
|
63
|
-
| `prompts [name] [--set k=v] [--out <file>]`
|
|
64
|
-
| `scan [--path <dir>] [--verbose] [--check]`
|
|
65
|
-
| `discover`
|
|
66
|
-
| `hook`
|
|
67
|
-
| `wait <approval-id> [--timeout <s>]`
|
|
68
|
-
| `rules test "<command>" [--environment <kind>]`
|
|
69
|
-
| `sessions [--status running\|idle\|ended]`
|
|
70
|
-
| `undo <action-id>\|--last [--option <id>] [--yes]`
|
|
71
|
-
| `setup --org <pek_key> [--yes] [--clients <list>]`
|
|
72
|
-
| `setup`
|
|
73
|
-
| `session`
|
|
74
|
-
| `access`
|
|
75
|
-
| `completion <bash\|zsh\|fish>`
|
|
76
|
-
| `help [command]`, `version`
|
|
49
|
+
| Command | Purpose |
|
|
50
|
+
| --------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
51
|
+
| `init [--yes] [--move-keys] [--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. |
|
|
53
|
+
| `logout` | Revoke the credential and always remove the local profile (warns if revocation fails). |
|
|
54
|
+
| `profiles` / `use <name>` | List stored profiles / select the active one. Offline. |
|
|
55
|
+
| `status` | Workspace, member, agent, and app connection states, plus Autopilot presets, team floors, and how old this computer's copy of your rules is. |
|
|
56
|
+
| `doctor` | Check Node, credential-file safety, HTTPS policy, `/healthz`, auth, serverInfo, and CLI protocol. Exit 1 on a failed check, with the full report. |
|
|
57
|
+
| `ready` | Readiness preflight for automation; gate on its `ready` field and exit code. |
|
|
58
|
+
| `search [query] [--app <key>]` | Search permitted tools. Empty query lists the full catalog. |
|
|
59
|
+
| `describe <tool>` | One exact definition with its full parameter schema. |
|
|
60
|
+
| `run <tool> [json]` | Run a tool through Passport governance. |
|
|
61
|
+
| `connect [app...] [--alias <name>] [--open] [--wait <s>]` | Show member sign-in links and optionally wait for completion. |
|
|
62
|
+
| `resources [uri] [--out <file>]` | List or read MCP resources. |
|
|
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. |
|
|
65
|
+
| `discover` | Scan local MCP configuration and submit a privacy-minimized fleet report. Exit 5 on a managed-policy violation. |
|
|
66
|
+
| `hook` | Records the CLIs agents run and, with `--guard`, decides each one before it runs from your Autopilot rules (`install`, `uninstall`, `status`). |
|
|
67
|
+
| `wait <approval-id> [--timeout <s>]` | Wait for a person to decide an approval request (default 100 seconds). |
|
|
68
|
+
| `rules test "<command>" [--environment <kind>]` | What Autopilot decides for a command, why, and which environment it acts on. |
|
|
69
|
+
| `sessions [--status running\|idle\|ended]` | Your agents' recent sessions with what Passport decided. |
|
|
70
|
+
| `undo <action-id>\|--last [--option <id>] [--yes]` | Undo an action Passport took a backup before, within 7 days. See [Undo](#undo). |
|
|
71
|
+
| `setup --org <pek_key> [--yes] [--clients <list>]` | Set up every agent on this computer for your company without asking anything (MDM and scripts). See [Company rollout](#company-rollout). |
|
|
72
|
+
| `setup` | Install and maintain assigned team workflows as managed skills. |
|
|
73
|
+
| `session` | Run NDJSON commands over one authenticated MCP session. |
|
|
74
|
+
| `access` | Signed managed access: `keygen`, `actions`, `run`, `invoke`, `status`, `cancel`. |
|
|
75
|
+
| `completion <bash\|zsh\|fish>` | Print a completion script. Offline. |
|
|
76
|
+
| `help [command]`, `version` | Help; package version and local profile context. |
|
|
77
77
|
|
|
78
78
|
Global options: `--profile <name>`, `--json`, `--timeout <seconds>` (default 30), `--quiet`, `--caller <id>`.
|
|
79
79
|
|
|
@@ -137,7 +137,7 @@ Eight steps, each reusing the command that owns it:
|
|
|
137
137
|
4. **Keys**: for each CLI sign-in on this computer, the same question as `passport keys move`: `Store your Railway account token in Passport and sign the Railway CLI out on this computer? [y/n]`. It has no default: Enter asks again (`Type y or n.`). `--yes` never moves a key: the step prints `Keys stayed on this computer. Run passport keys move to move them.` Add `--move-keys` to move every key it finds unasked; the closing summary then says which (`Moved your Railway key into Passport and signed that CLI out on this computer.`). Quiet when there's nothing to move.
|
|
138
138
|
5. **Environments**: the environments Passport has placed for your apps, each with its kind: `Found 3 environments: production (Railway), preview (Vercel), qa (Railway)`. Anything Passport can't place counts as Production; change it any time in Rules. With no app connected yet it says `Environments appear once an app is connected.`
|
|
139
139
|
6. **Agents**: Passport's one MCP URL with this workspace as its hint (`https://passportmcp.com/mcp?ws=<workspace>`), with each agent's own browser sign-in; a server that doesn't serve `/mcp` yet (read from its OAuth protected-resource metadata) gets the workspace's own URL (`https://<host>/w/<workspace>/mcp`). An existing entry at either URL for this workspace counts as set up, 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.
|
|
140
|
-
7. **Guard**: asks `Apply your Autopilot rules before each shell command in <agents>? [Y/n]`, then runs `passport hook install --guard` for Claude Code, Codex, and Cursor (Codex: blocks only), 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.
|
|
140
|
+
7. **Guard**: asks `Apply your Autopilot rules before each shell command in <agents>? [Y/n]`, then runs `passport hook install --guard` for Claude Code, Codex, and Cursor (Codex: blocks only), pointing at the launcher `$PASSPORT_HOME/cli/bin/passport` (`passport.cmd` on Windows), which runs 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. An upgrade rewrites the launcher and the `cli/current` link in one rename each, so hooks follow without being edited; the launcher runs the recorded node, or the node on PATH once that one is removed. A hook from an older init that names a version folder is replaced where it stands, next to your other hooks. Once the new copy is in place, older copies are deleted unless a hook still runs them.
|
|
141
141
|
8. **Autopilot**: how much agents can do on their own, per environment:
|
|
142
142
|
|
|
143
143
|
```
|
|
@@ -152,15 +152,15 @@ Eight steps, each reusing the command that owns it:
|
|
|
152
152
|
|
|
153
153
|
What changes on disk, and how to undo it:
|
|
154
154
|
|
|
155
|
-
| Where
|
|
156
|
-
|
|
|
157
|
-
| `~/.passport/credentials.json`
|
|
158
|
-
| `~/.passport/cli/`
|
|
159
|
-
| `~/.claude.json`
|
|
160
|
-
| `~/.codex/config.toml`
|
|
161
|
-
| `~/.cursor/mcp.json`
|
|
162
|
-
| VS Code user `mcp.json`
|
|
163
|
-
| `~/.claude/settings.json`, `~/.codex/hooks.json`, `~/.cursor/hooks.json` | Passport's audit and guard hooks
|
|
155
|
+
| Where | What | Undo |
|
|
156
|
+
| ------------------------------------------------------------------------ | -------------------------------------------------------------------------------- | -------------------------------------------------- |
|
|
157
|
+
| `~/.passport/credentials.json` | A `cli@<workspace>` profile, as `passport login` writes | `passport logout` |
|
|
158
|
+
| `~/.passport/cli/` | A copy of this CLI, the `bin/passport` launchers hooks run, and a `current` link | Delete the folder (after removing the hooks) |
|
|
159
|
+
| `~/.claude.json` | A `passport` MCP server entry, via `claude mcp add` | `claude mcp remove --scope user passport` |
|
|
160
|
+
| `~/.codex/config.toml` | `[mcp_servers.passport]`, via `codex mcp add` | `codex mcp remove passport` |
|
|
161
|
+
| `~/.cursor/mcp.json` | `mcpServers.passport` | Delete that entry |
|
|
162
|
+
| VS Code user `mcp.json` | `servers.passport` | `MCP: List Servers`, then remove it |
|
|
163
|
+
| `~/.claude/settings.json`, `~/.codex/hooks.json`, `~/.cursor/hooks.json` | Passport's audit and guard hooks | `passport hook uninstall --client <agent> --apply` |
|
|
164
164
|
|
|
165
165
|
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. A question only takes keys typed after it appears, so an Enter pressed during a pause never answers it. Any wait longer than a moment shows what it's for in the step's row (`Sign in Checking your sign-in…`); off a terminal nothing extra prints. If Passport can't be reached, init says `Couldn't reach Passport at <origin>. Check your connection, then run passport init again.` and exits 1. 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.
|
|
166
166
|
|
|
@@ -212,20 +212,20 @@ Two hooks per agent. `passport hook` runs after each shell command and records t
|
|
|
212
212
|
- **Ask** or **deny** when any recognized command needs it. The strictest part of a compound command wins and names itself. `--help` and `--dry-run` never ask.
|
|
213
213
|
- Each reason names its cause in one line: `Passport: railway redeploy changes Production. Approve to run it.`, or `Blocked by Passport: Team rule, no deletes in Production. Ask an admin to run it, or request an exception in Passport.`
|
|
214
214
|
|
|
215
|
-
**Everyday commands** (`src/cliHookLocal.ts`, tables in `src/localCommands.ts`, `localTools.ts`, `localFiles.ts`, `localGit.ts`, `localNetwork.ts`). Local commands are placed by what they touch on this computer. The project folder (the git root, else the agent's folder; never `/` or the home folder) is Development: reads such as `ls`, `rg`, `git status`, test runners, linters, builds, and type checks are Reads; `git commit`, formatters with `--write`, package scripts, and `mv`/`cp` are Changes; `rm`, `git clean -fd`, and `git reset --hard` are Deletes. Package installs (`npm install`, `pip install`, `brew install`) are Changes in Other apps. `git push` to the default branch (origin's HEAD, else `main`/`master`) is a Change in Production, to any other branch a Change in Development; deleting a remote branch (`--delete`, `:branch`) is a Delete in Other apps because teammates share it. Temporary folders (`/tmp`, `$TMPDIR`) count as Development; deleting one whole is Irreversible. Outside the project: deleting the home folder, `/`, system paths, or the whole project is Irreversible; other writes are Changes and deletes are Deletes in Other apps; writes to keys, shell startup files, or an agent's own settings are Deletes, and reads of them are no decision. `curl`/`wget` GETs are Reads and anything that sends data is a Change, in Other apps (Development for localhost). docker `ps`/`logs` read, `run`/`build`/`compose up` change, `rm`/`prune` delete. `sudo` never runs silently. Symlinks are resolved before deciding, `cd` is followed through `&&`, `;`, and subshells, and redirects are writes where they land. The server keeps a generated copy of the tables (`node scripts/generate-local-commands.mjs`) for `rules test` on the web. Allowed project work and reads are counted on the machine ("Answered for you") rather than recorded one by one; installs, pushes, and anything that asks or blocks are recorded like vendor commands, with the environment kind and never a path.
|
|
215
|
+
**Everyday commands** (`src/cliHookLocal.ts`, tables in `src/localCommands.ts`, `localTools.ts`, `localFiles.ts`, `localGit.ts`, `localNetwork.ts`). Local commands are placed by what they touch on this computer. The project folder (the git root, else the agent's folder; never `/` or the home folder) is Development: reads such as `ls`, `rg`, `git status`, test runners, linters, builds, and type checks are Reads; `git commit`, formatters with `--write`, package scripts, and `mv`/`cp` are Changes; `rm`, `git clean -fd`, and `git reset --hard` are Deletes. Package installs (`npm install`, `pip install`, `brew install`) are Changes in Other apps. `git push` to the default branch (origin's HEAD, else `main`/`master`) is a Change in Production, to any other branch a Change in Development; deleting a remote branch (`--delete`, `:branch`) is a Delete in Other apps because teammates share it. Temporary folders (`/tmp`, `$TMPDIR`) count as Development; deleting one whole is Irreversible. Outside the project: deleting the home folder, `/`, system paths, or the whole project is Irreversible; other writes are Changes and deletes are Deletes in Other apps; writes to keys, shell startup files, or an agent's own settings are Deletes, and reads of them are no decision. `curl`/`wget` GETs are Reads and anything that sends data is a Change, in Other apps (Development for localhost). docker `ps`/`logs` read, `run`/`build`/`compose up` change, `rm`/`prune` delete. `sudo` never runs silently. The project's own code run directly (`node scripts/check.mjs`, `npx tsx scripts/x.ts`, `bash scripts/ci.sh`, `./scripts/ci.sh`, `make test`) is a Change in Development, like a package script; Passport can't read inside it, so it is never allowed and never recorded as opaque. `tsx --test` and `./node_modules/.bin/<tool>` are their tools, `bash -lc '…'` and `sh -c '…'` are read as the line inside, and Codex's `apply_patch <<'PATCH'` is a change to the files the patch names. A checkout an agent keeps for itself (`~/.codex/worktrees/…`, `~/.cursor/worktrees/…`) is the project, not the agent's settings. Symlinks are resolved before deciding, `cd` is followed through `&&`, `;`, and subshells, and redirects are writes where they land. The server keeps a generated copy of the tables (`node scripts/generate-local-commands.mjs`) for `rules test` on the web. Allowed project work and reads are counted on the machine ("Answered for you") rather than recorded one by one; installs, pushes, and anything that asks or blocks are recorded like vendor commands, with the environment kind and never a path.
|
|
216
216
|
|
|
217
217
|
The environment comes from each vendor's own flags (`src/cliHookEnvironment.ts`): Railway `-e/--environment`, Wrangler and Sentry `-e/--env`, Vercel `--prod`/`--target` (a deploy without either is a preview), Supabase `--local`/`--linked`/`--project-ref` (`db reset` is local unless `--linked`), Stripe `--live` (test mode otherwise), `git push <remote> <branch>`, `psql` hosts (`localhost` is Development), fly and Heroku `-a/--app`, kubectl `--context`/`-n`, helm `--kube-context`/`-n`, AWS `--profile`, gcloud `--project`, plus any flags the server adds. Names follow Passport's rules (`prod|production|live|main` → Production, `stag|qa|uat|preview` → Staging, `dev|local|test|sandbox|feature|branch` → Development), and the workspace's own placement of a name wins. Anything else, or no flag at all (a linked project the hook can't see), counts as Production, and the reason says `Environment unknown, treated as Production.`
|
|
218
218
|
|
|
219
|
-
**Attended or unattended** (`src/cliHookMode.ts`). With a person at the keyboard, an ask is the agent's own prompt with Passport's reason. With nobody there, the guard asks Passport instead (`POST /api/my/cli/decide`, inside the hook's budget): the server knows grants already given this session, every rule, and the workspace's environments. An allow from it runs the command (for example, a retry after approval); an ask becomes an approval request on the web and the person's phone, and the agent reads ``
|
|
219
|
+
**Attended or unattended** (`src/cliHookMode.ts`). With a person at the keyboard, an ask is the agent's own prompt with Passport's reason. With nobody there, the guard asks Passport instead (`POST /api/my/cli/decide`, inside the hook's budget): the server knows grants already given this session, every rule, and the workspace's environments. An allow from it runs the command (for example, a retry after approval); an ask becomes an approval request on the web and the person's phone, and the agent reads ``Waiting for approval from Ramish. Run `passport wait <id>` to wait, or continue with other work.`` If Passport can't answer in time, the local decision stands and the reason adds `Passport couldn't be reached, so this computer decided.` Signals, strongest first:
|
|
220
220
|
|
|
221
|
-
| Signal
|
|
222
|
-
|
|
|
223
|
-
| `PASSPORT_HOOK_MODE=attended\|unattended`
|
|
224
|
-
| Claude Code `CLAUDE_CODE_SESSION_ATTENDED` (`1`/`0`), passed to every hook
|
|
225
|
-
| Hook input `permission_mode` `dontAsk` or `bypassPermissions` (Claude Code, Codex)
|
|
226
|
-
| Cursor `is_background_agent: true`
|
|
227
|
-
| `CLAUDE_CODE_ENTRYPOINT` `sdk-cli` (`claude -p`), `sdk-ts`, `sdk-py`, `claude-code-github-action` | Unattended (older Claude Code builds)
|
|
228
|
-
| `CI`, `GITHUB_ACTIONS`, `GITLAB_CI`, `BUILDKITE`, `CIRCLECI`, `JENKINS_URL`, `TF_BUILD`
|
|
221
|
+
| Signal | Means |
|
|
222
|
+
| ------------------------------------------------------------------------------------------------- | --------------------------------------- |
|
|
223
|
+
| `PASSPORT_HOOK_MODE=attended\|unattended` | Override |
|
|
224
|
+
| Claude Code `CLAUDE_CODE_SESSION_ATTENDED` (`1`/`0`), passed to every hook | Attended / unattended |
|
|
225
|
+
| Hook input `permission_mode` `dontAsk` or `bypassPermissions` (Claude Code, Codex) | Unattended: prompts are suppressed |
|
|
226
|
+
| Cursor `is_background_agent: true` | Unattended: background and cloud agents |
|
|
227
|
+
| `CLAUDE_CODE_ENTRYPOINT` `sdk-cli` (`claude -p`), `sdk-ts`, `sdk-py`, `claude-code-github-action` | Unattended (older Claude Code builds) |
|
|
228
|
+
| `CI`, `GITHUB_ACTIONS`, `GITLAB_CI`, `BUILDKITE`, `CIRCLECI`, `JENKINS_URL`, `TF_BUILD` | Unattended |
|
|
229
229
|
|
|
230
230
|
Codex has no field for `codex exec`; its prompt-free modes count as unattended, where an ask blocks for now with the waiting line.
|
|
231
231
|
|
|
@@ -236,7 +236,7 @@ The guard decides from local data inside `HOOK_BUDGET_MS` (1.5 s) and prints fir
|
|
|
236
236
|
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"). An allow the server gave is parked the same way, so the run's row says `Approved earlier this session`. 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; asks and blocks the server decided are recorded by the server.
|
|
237
237
|
|
|
238
238
|
- 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).
|
|
239
|
-
- Codex: the same events in `~/.codex/hooks.json` (`CODEX_HOME` honored). Codex supports deny only (ask fails the hook, and its allow rewrites commands), so the guard only blocks there. Trust the hooks in Codex's `/hooks`.
|
|
239
|
+
- Codex: the same events in `~/.codex/hooks.json` (`CODEX_HOME` honored). Codex sends every shell command as `tool_name: "Bash"` with the model's raw command string in `tool_input.command` (never shell-wrapped), so it is read exactly like Claude Code's; its `apply_patch` tool is a file edit, not a shell command, and isn't recorded. Codex supports deny only (ask fails the hook, and its allow rewrites commands), so the guard only blocks there. Trust the hooks in Codex's `/hooks`.
|
|
240
240
|
- 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.
|
|
241
241
|
|
|
242
242
|
`src/cliPolicy.ts` caches the member's CLI policy (`GET /api/my/cli-policy`) at `$PASSPORT_HOME/cli-policy/<profile>.json` (mode 600). Servers with Autopilot send version 2 (`src/cliPolicyV2.ts`: presets, floors, CLI rules, irreversible and delete verbs, environment flags, placed environments); older servers send version 1, and then the guard keeps its earlier shape: ask or deny before destructive verbs, never allow, no server call, and reports without the Autopilot fields. `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.
|
|
@@ -272,7 +272,7 @@ passport keys add railway # store a key you paste (stdin, never echoed)
|
|
|
272
272
|
passport exec -- railway up -e staging
|
|
273
273
|
```
|
|
274
274
|
|
|
275
|
-
- `keys move` finds CLI sign-ins (Railway, GitHub CLI, Vercel, Wrangler API tokens, Supabase, Stripe test keys, the AWS `default` profile) and tokens in Claude Code's settings `env`. For each it asks `[y/n]` with no default (an empty answer asks again; `--yes` moves them all), stores the key in Passport (`POST /api/my/keys`), then signs that CLI out
|
|
275
|
+
- `keys move` finds CLI sign-ins (Railway, GitHub CLI, Vercel, Wrangler API tokens, Supabase, Stripe test keys, the AWS `default` profile) and tokens in Claude Code's settings `env`. For each it asks `[y/n]` with no default (an empty answer asks again; `--yes` moves them all), stores the key in Passport (`POST /api/my/keys`), then signs that CLI out by removing only the credential: the token fields of `~/.railway/config.json` (project links stay), `token` in Vercel's `auth.json` (not revoked; the current team stays), Wrangler's sign-in keys in `default.toml`, the Supabase `access-token` file and its keychain token (saved database passwords stay), the Stripe profile's API keys and its live key in the keychain (account, color, and other profiles stay), the AWS profile's key lines, or the one settings entry. Files are written atomically with their mode kept. Vendor sign-outs don't run because they do more (`railway logout` unlinks every project, `vercel logout` revokes the token Passport just stored); only the GitHub CLI's `gh auth logout --hostname github.com` runs, adding `--user <active>` when several accounts are signed in, so other hosts and accounts stay. Keychain items are deleted by exact service and account (`security delete-generic-password` on macOS, `secret-tool clear` on Linux); where that isn't possible the row says which keychain copy may stay. Wrangler OAuth tokens are removed locally, not revoked. A sign-out that fails leaves the key in Passport and says what's left on disk. `.env` files are never touched: "Used by your app, so Passport leaves it." Browser-session sign-ins (Railway, Vercel, Wrangler OAuth) can't move; the line says how to make a token instead. From the CLI, a different key than the one already in Passport is refused; rotate it in Apps. The scan report sent afterwards carries provider counts only.
|
|
276
276
|
- `exec -- <cli> …` runs railway, gh, vercel, wrangler, supabase, stripe, aws, neonctl, or flyctl from PATH. It classifies the command here, asks `POST /api/my/exec/authorize`, and on allow sets only that vendor's variables (`GH_TOKEN`, `RAILWAY_API_TOKEN`, `VERCEL_TOKEN`, `CLOUDFLARE_API_TOKEN`, `SUPABASE_ACCESS_TOKEN`, `STRIPE_API_KEY`, `AWS_*`, `NEON_API_KEY`, `FLY_API_TOKEN`) in the child's environment, removing Passport's own and any stray vendor tokens. Output and exit code pass through. Afterwards it reports the exit code and duration (`POST /api/my/exec/result`, best effort, two seconds at most) so the session row reads Ran or Failed. It refuses paths, shells, `env`, and subcommands that would print the key, sign in again, mint longer-lived tokens, or run another program with the key (`railway run`, `gh auth`, gh extensions, `aws configure`, `vercel dev`, `fly tokens`).
|
|
277
277
|
- Asks wait for your approval in Passport (web or push) when you're at the keyboard or with `--wait <sec>`; otherwise exit 4 with the approval id: run `passport wait <id>`, then the command again. An approval is used once. Blocked or declined: exit 5. No key, or it stopped working: exit 3 ("Your Railway key in Passport stopped working. Update it in Apps."). Offline: exit 1, nothing runs, and exec never uses a key on this computer instead.
|
|
278
278
|
- In Claude Code, the guard rewrites a plain vendor command whose key is in Passport to `passport exec` (PreToolUse `updatedInput` with allow; a block stays a deny). When the rules ask, or someone is at the keyboard, the rewrite adds `--wait 120`, so the agent holds while the person approves: "Approve it on your phone or in Passport." Codex and Cursor get no rewrite: use `passport exec` there.
|
|
@@ -392,43 +392,43 @@ const actions = await client.actions(); // or client.actions(delegationId)
|
|
|
392
392
|
|
|
393
393
|
With `--json`, stdout is exactly one JSON value; hints and warnings go to stderr.
|
|
394
394
|
|
|
395
|
-
| Command
|
|
396
|
-
|
|
|
397
|
-
| `login`
|
|
398
|
-
| `profiles`
|
|
399
|
-
| `use`
|
|
400
|
-
| `logout`
|
|
401
|
-
| `status`
|
|
402
|
-
| `wait`
|
|
403
|
-
| `rules`
|
|
404
|
-
| `sessions`
|
|
405
|
-
| `undo`
|
|
406
|
-
| `doctor`
|
|
407
|
-
| `ready`
|
|
408
|
-
| `search`
|
|
409
|
-
| `describe`
|
|
410
|
-
| `run`
|
|
411
|
-
| `connect`
|
|
412
|
-
| `resources`, `prompts` | MCP list, read, or get result
|
|
413
|
-
| `discover`
|
|
414
|
-
| `scan`
|
|
415
|
-
| `session`
|
|
416
|
-
| `access`
|
|
417
|
-
| `completion`
|
|
418
|
-
| `help`
|
|
419
|
-
| `version`
|
|
395
|
+
| Command | JSON value |
|
|
396
|
+
| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
397
|
+
| `login` | `{profile,endpoint,client,surface,active,workspaceId,workspaceName?,next}` (`workspaceName` after browser sign-in) |
|
|
398
|
+
| `profiles` | `{profiles:[{name,active,client?}],active?}` |
|
|
399
|
+
| `use` | `{profile,active:true}` |
|
|
400
|
+
| `logout` | `{profile,removed,revoked}` |
|
|
401
|
+
| `status` | `{workspace,member,endpoint,auth,profile?,client,mcps,autopilot?:{presets,floors,floorReason?,exceptions?,cache:{version,fetchedAt,ageMs}},next?}` |
|
|
402
|
+
| `wait` | `{approvalId,status:"approved",scope?,message}`; declined, expired, and still-waiting are errors with `approvalId` |
|
|
403
|
+
| `rules` | `{command,decision,cause?,explanation?,environment?,environmentAssumed?,actionClass?,source}` |
|
|
404
|
+
| `sessions` | `{sessions:[{id,client,folder,status,startedAt,lastActivityAt,counts,environments,waiting}],nextCursor}` |
|
|
405
|
+
| `undo` | `{actionId,status,message,steps:[{label,ok,detail?}],option,undoActionId?}`; without `--yes` off a terminal, `{actionId,status:"preview",preview,next}`; pending, blocked, and declined are errors |
|
|
406
|
+
| `doctor` | `{version,ok,auth,profile?,profileCount,endpointOrigin?,server?,checks}`, also on failure |
|
|
407
|
+
| `ready` | `{ready,version,ok,auth,profile?,profileCount,endpointOrigin?,server?,checks}` |
|
|
408
|
+
| `search` | Gateway payload with `results` or `catalog`, and `note` |
|
|
409
|
+
| `describe` | Tool definition (`tool`, `parameters`) plus `name`/`inputSchema` aliases |
|
|
410
|
+
| `run` | Full governed MCP tool result, including `structuredContent` |
|
|
411
|
+
| `connect` | Gateway payload with `connections` and optional `connectAllUrl` |
|
|
412
|
+
| `resources`, `prompts` | MCP list, read, or get result |
|
|
413
|
+
| `discover` | `{snapshot,report,compliant}` |
|
|
414
|
+
| `scan` | `{version:1,findings:[{id,provider,kind,label,severity,location,locations,blastRadius}],agents,unreadable,checked}` |
|
|
415
|
+
| `session` | NDJSON `{id?,ok,exitCode,result?}` or `{id?,ok:false,error,cause,exitCode,...}` |
|
|
416
|
+
| `access` | `keygen`: algorithm, paths, public JWK; `actions`: `{actions}`; `run`/`cancel`: `{run}`; `invoke`: governed result; `status`: `{receipt}` |
|
|
417
|
+
| `completion` | `{shell,script}` |
|
|
418
|
+
| `help` | `{command,help}` |
|
|
419
|
+
| `version` | `{version,profileCount,profileSelected,selectionSource,next,endpoint?,profile?}` |
|
|
420
420
|
|
|
421
421
|
Errors: `{"error":"...","cause":"blocked","exitCode":5,"app":"github"}`, optionally with `approvalId`, `hint`, `profiles`, `next` (`argv` plus description), `remediation`, `retry`, `requiredInput`, or `connectUrl`.
|
|
422
422
|
|
|
423
|
-
| Exit | Meaning
|
|
424
|
-
| ---: |
|
|
425
|
-
|
|
|
426
|
-
|
|
|
427
|
-
|
|
|
428
|
-
|
|
|
429
|
-
|
|
|
430
|
-
|
|
|
431
|
-
|
|
|
423
|
+
| Exit | Meaning |
|
|
424
|
+
| ---: | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
425
|
+
| 0 | Success |
|
|
426
|
+
| 1 | Network, timeout, server, or unsupported-content error. When Passport can't be reached: `Passport couldn't be reached at <host>. Check your connection and try again.` |
|
|
427
|
+
| 2 | Missing, expired, or revoked authentication |
|
|
428
|
+
| 3 | App needs member sign-in |
|
|
429
|
+
| 4 | Approval pending (including `wait` still waiting at its timeout) |
|
|
430
|
+
| 5 | Policy, guardrail, selection, or approval denial (including a declined or expired approval in `wait`) |
|
|
431
|
+
| 6 | Invalid usage or unknown tool/app |
|
|
432
432
|
|
|
433
433
|
## MCP stdio bridge
|
|
434
434
|
|
package/dist/cliHook.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ import { type ParsedArgs } from "./cliArgs.js";
|
|
|
18
18
|
import { type CliFinding } from "./cliHookClassify.js";
|
|
19
19
|
import { type DecidedFinding, type GuardDecision } from "./cliHookGuard.js";
|
|
20
20
|
import { type HookInput } from "./cliHookInput.js";
|
|
21
|
+
export { opaqueKind, opaqueProgram } from "./cliHookOpaque.js";
|
|
21
22
|
import { type CommandResult, type Env, type Runtime } from "./cliSupport.js";
|
|
22
23
|
/** Claude Code, Codex, and Cursor fail open on a slow hook, so the budget is ours. */
|
|
23
24
|
export declare const HOOK_BUDGET_MS = 1500;
|
|
@@ -33,6 +34,9 @@ export type CliHookReport = {
|
|
|
33
34
|
findings: ReportedFinding[];
|
|
34
35
|
opaque: boolean;
|
|
35
36
|
opaqueKinds?: string[];
|
|
37
|
+
/** The program of each part Passport couldn't check: its first word only
|
|
38
|
+
* (`python`, `make`, `npx`), never a script name or an argument. */
|
|
39
|
+
opaquePrograms?: string[];
|
|
36
40
|
/** What the guard answered before the command ran. "allow" only with a v2
|
|
37
41
|
* (Autopilot) policy; the server works out the cause and class itself. */
|
|
38
42
|
decision?: "allow" | "ask" | "deny";
|
|
@@ -84,8 +88,6 @@ type ShellEvent = {
|
|
|
84
88
|
/** Keep the shape of the verb, never its arguments: anything that could carry a
|
|
85
89
|
* path, an endpoint, or a value is dropped rather than truncated. */
|
|
86
90
|
export declare function safeVerb(raw: string | null): string;
|
|
87
|
-
/** Why a command could not be read. Never what it was. */
|
|
88
|
-
export declare function opaqueKind(finding: CliFinding): string;
|
|
89
91
|
/**
|
|
90
92
|
* Which agent sent this. An installed hook names its client with `--client`;
|
|
91
93
|
* Cursor is also recognised by its own event names and version field, which
|
package/dist/cliHook.js
CHANGED
|
@@ -22,7 +22,8 @@ import { decideGuard, guardMachineOf } from "./cliHookGuard.js";
|
|
|
22
22
|
import { detectMode } from "./cliHookMode.js";
|
|
23
23
|
import { readInput } from "./cliHookInput.js";
|
|
24
24
|
import { hookViaPlugin } from "./hookPlugin.js";
|
|
25
|
-
import {
|
|
25
|
+
import { opaqueParts } from "./cliHookOpaque.js";
|
|
26
|
+
export { opaqueKind, opaqueProgram } from "./cliHookOpaque.js";
|
|
26
27
|
import { hasExpired, holdAsk, takeAsk, takeExpired } from "./cliHookPending.js";
|
|
27
28
|
import { claimStaleRefresh, readCliPolicy } from "./cliPolicy.js";
|
|
28
29
|
import { readCreds } from "./credentials.js";
|
|
@@ -70,19 +71,6 @@ export function safeVerb(raw) {
|
|
|
70
71
|
.slice(0, 4);
|
|
71
72
|
return tokens.join(" ").slice(0, 80).trim() || "invoke";
|
|
72
73
|
}
|
|
73
|
-
/** Why a command could not be read. Never what it was. */
|
|
74
|
-
export function opaqueKind(finding) {
|
|
75
|
-
const via = finding.via[finding.via.length - 1] ?? "";
|
|
76
|
-
if (finding.vendor === "psql")
|
|
77
|
-
return "sql";
|
|
78
|
-
if (via === "make" || via === "just" || via === "task")
|
|
79
|
-
return "task-runner";
|
|
80
|
-
if (via === "source" || via.endsWith("<script>") || INTERPRETERS.has(via))
|
|
81
|
-
return "script";
|
|
82
|
-
if (via === "npx" || via === "bunx")
|
|
83
|
-
return "package-runner";
|
|
84
|
-
return "unknown";
|
|
85
|
-
}
|
|
86
74
|
function isCursorEvent(input) {
|
|
87
75
|
return input.hook_event_name === "beforeShellExecution" || input.hook_event_name === "afterShellExecution";
|
|
88
76
|
}
|
|
@@ -172,13 +160,14 @@ export function buildReport(input, findings, env, declared, decided = [], local
|
|
|
172
160
|
const governed = reportable(summary.governed, decided, local);
|
|
173
161
|
if (!governed.length && !summary.opaque)
|
|
174
162
|
return null;
|
|
175
|
-
const kinds =
|
|
163
|
+
const { kinds, programs } = opaqueParts(summary.unknown, MAX_OPAQUE_KINDS);
|
|
176
164
|
return {
|
|
177
165
|
...context(input, env, declared),
|
|
178
166
|
...outcomeOfInput(input),
|
|
179
167
|
findings: governed,
|
|
180
168
|
opaque: summary.opaque,
|
|
181
|
-
...(summary.opaque && kinds.length ? { opaqueKinds: kinds } : {})
|
|
169
|
+
...(summary.opaque && kinds.length ? { opaqueKinds: kinds } : {}),
|
|
170
|
+
...(summary.opaque && programs.length ? { opaquePrograms: programs } : {})
|
|
182
171
|
};
|
|
183
172
|
}
|
|
184
173
|
/** What the guard answered, and for which findings. The audit row that
|
package/dist/cliHookInstall.d.ts
CHANGED
|
@@ -32,6 +32,13 @@ export declare function isPassportGuardCommand(command: unknown): boolean;
|
|
|
32
32
|
export declare function hookCommand(env: Env, exists?: (path: string) => boolean, client?: HookClient, kind?: Kind, invocation?: string): string;
|
|
33
33
|
/** A shell-safe `node <entry>` prefix for a hook command. */
|
|
34
34
|
export declare function nodeInvocation(node: string, entry: string): string;
|
|
35
|
+
/** What hooks run for a stable install: its version-independent launcher, so
|
|
36
|
+
* an upgrade moves every hook; a global npm install by its own path. */
|
|
37
|
+
export declare function stableInvocation(stable: {
|
|
38
|
+
node: string;
|
|
39
|
+
entry: string;
|
|
40
|
+
launcher?: string;
|
|
41
|
+
}): string;
|
|
35
42
|
/** The Passport audit command registered in Claude Code settings, if any. */
|
|
36
43
|
export declare function registeredHookCommand(settings: Settings): string | null;
|
|
37
44
|
/** Add Passport's audit entry to Claude Code's Bash matcher, touching nothing else. */
|
package/dist/cliHookInstall.js
CHANGED
|
@@ -21,6 +21,8 @@ import { readCliPolicy } from "./cliPolicy.js";
|
|
|
21
21
|
import { coveredByPlugin, pluginInstalled } from "./hookPlugin.js";
|
|
22
22
|
import { syncNative } from "./nativeSync.js";
|
|
23
23
|
import { readCreds } from "./credentials.js";
|
|
24
|
+
import { credentialDir } from "./credentialStorage.js";
|
|
25
|
+
import { launcherPath } from "./initInstall.js";
|
|
24
26
|
import { failure, selectStoredProfile } from "./cliSupport.js";
|
|
25
27
|
export const HOOK_CLIENTS = ["claude-code", "codex", "cursor"];
|
|
26
28
|
const SETTINGS_MAX_BYTES = 1024 * 1024;
|
|
@@ -115,8 +117,17 @@ function ownInvocation() {
|
|
|
115
117
|
const entry = process.argv[1];
|
|
116
118
|
return entry ? `${quoted(process.execPath)} ${quoted(entry)}` : null;
|
|
117
119
|
}
|
|
118
|
-
/**
|
|
120
|
+
/** Passport's own launcher (`passport init` writes it), when it is there. */
|
|
121
|
+
function installedLauncher(exists) {
|
|
122
|
+
const launcher = launcherPath(join(credentialDir(), "cli", "bin"), process.platform);
|
|
123
|
+
return exists(launcher) ? launcher : null;
|
|
124
|
+
}
|
|
125
|
+
/** The launcher `passport init` installed, else `passport` when the CLI is on
|
|
126
|
+
* PATH, otherwise this exact process. */
|
|
119
127
|
function passportInvocation(env, exists) {
|
|
128
|
+
const launcher = installedLauncher(exists);
|
|
129
|
+
if (launcher)
|
|
130
|
+
return quoted(launcher);
|
|
120
131
|
if (onPath("passport", env, exists))
|
|
121
132
|
return "passport";
|
|
122
133
|
return ownInvocation() ?? "passport";
|
|
@@ -131,6 +142,11 @@ export function hookCommand(env, exists = executable, client, kind = "audit", in
|
|
|
131
142
|
export function nodeInvocation(node, entry) {
|
|
132
143
|
return `${quoted(node)} ${quoted(entry)}`;
|
|
133
144
|
}
|
|
145
|
+
/** What hooks run for a stable install: its version-independent launcher, so
|
|
146
|
+
* an upgrade moves every hook; a global npm install by its own path. */
|
|
147
|
+
export function stableInvocation(stable) {
|
|
148
|
+
return stable.launcher ? quoted(stable.launcher) : nodeInvocation(stable.node, stable.entry);
|
|
149
|
+
}
|
|
134
150
|
/** Write through a symlinked settings file (dotfile managers) to its target. */
|
|
135
151
|
function writablePath(path) {
|
|
136
152
|
try {
|
|
@@ -237,19 +253,26 @@ function withEntry(spec, settings, slot, command) {
|
|
|
237
253
|
const hooks = { ...hooksOf(settings) };
|
|
238
254
|
const list = [...listOf(settings, event)];
|
|
239
255
|
if (spec.format === "cursor") {
|
|
256
|
+
const at = list.findIndex((entry) => ours(entry?.command));
|
|
240
257
|
const kept = list.filter((entry) => !ours(entry?.command));
|
|
241
|
-
|
|
258
|
+
const fresh = { command, timeout: HOOK_TIMEOUT_SECONDS };
|
|
259
|
+
hooks[event] = at === -1 ? [...kept, fresh] : [...kept.slice(0, at), fresh, ...kept.slice(at)];
|
|
242
260
|
const version = typeof settings.version === "number" ? settings.version : 1;
|
|
243
261
|
return { ...settings, version, hooks };
|
|
244
262
|
}
|
|
245
263
|
const entry = { type: "command", command, timeout: HOOK_TIMEOUT_SECONDS };
|
|
246
264
|
const groups = list;
|
|
247
|
-
|
|
265
|
+
// An older Passport entry (another version's path) is replaced where it stands.
|
|
266
|
+
const owner = groups.findIndex((group) => group && Array.isArray(group.hooks) && group.hooks.some((candidate) => ours(candidate?.command)));
|
|
267
|
+
const index = owner !== -1 ? owner : groups.findIndex((group) => group && group.matcher === "Bash");
|
|
248
268
|
if (index === -1)
|
|
249
269
|
groups.push({ matcher: "Bash", hooks: [entry] });
|
|
250
270
|
else {
|
|
251
271
|
const existing = Array.isArray(groups[index].hooks) ? groups[index].hooks : [];
|
|
252
|
-
|
|
272
|
+
const at = existing.findIndex((candidate) => ours(candidate?.command));
|
|
273
|
+
const kept = existing.filter((candidate) => !ours(candidate?.command));
|
|
274
|
+
const hooks = at === -1 ? [...kept, entry] : [...kept.slice(0, at), entry, ...kept.slice(at)];
|
|
275
|
+
groups[index] = { ...groups[index], hooks };
|
|
253
276
|
}
|
|
254
277
|
hooks[event] = groups;
|
|
255
278
|
return { ...settings, hooks };
|
package/dist/cliHookLocal.d.ts
CHANGED
|
@@ -36,6 +36,9 @@ export type LocalMachine = {
|
|
|
36
36
|
temp: string[];
|
|
37
37
|
/** Extra folders whose contents are keys or agent settings. */
|
|
38
38
|
sensitive: string[];
|
|
39
|
+
/** Folders where agents keep their own checkouts of a project (Codex and
|
|
40
|
+
* Cursor worktrees). A project inside one is a project, not agent settings. */
|
|
41
|
+
worktrees?: string[];
|
|
39
42
|
fs: LocalFs;
|
|
40
43
|
};
|
|
41
44
|
export declare const NODE_FS: LocalFs;
|
package/dist/cliHookLocal.js
CHANGED
|
@@ -18,6 +18,7 @@ import { lstatSync, readFileSync, realpathSync, statSync } from "node:fs";
|
|
|
18
18
|
import { homedir, tmpdir } from "node:os";
|
|
19
19
|
import { posix } from "node:path";
|
|
20
20
|
import { classifyArgv, classifyNestedText } from "./cliHookClassify.js";
|
|
21
|
+
import { heredocBodies, projectCode } from "./cliHookLocalCode.js";
|
|
21
22
|
import { splitCommands } from "./cliHookParse.js";
|
|
22
23
|
import { VENDORS } from "./cliHookVendors.js";
|
|
23
24
|
import { databasePrefix } from "./envDatabase.js";
|
|
@@ -192,11 +193,27 @@ export function localMachine(cwd, env = process.env, fs = NODE_FS) {
|
|
|
192
193
|
else if (!tooBroad(working, home))
|
|
193
194
|
projectRoot = working;
|
|
194
195
|
}
|
|
195
|
-
|
|
196
|
+
const worktrees = [
|
|
197
|
+
posix.join(home, ".codex", "worktrees"),
|
|
198
|
+
posix.join(home, ".cursor", "worktrees"),
|
|
199
|
+
...[env.CODEX_HOME, env.PASSPORT_CURSOR_HOME]
|
|
200
|
+
.filter((value) => typeof value === "string" && value.startsWith("/"))
|
|
201
|
+
.map((value) => posix.join(canonical(value, fs), "worktrees"))
|
|
202
|
+
];
|
|
203
|
+
return { cwd: working, projectRoot, home, temp, sensitive, worktrees, fs };
|
|
204
|
+
}
|
|
205
|
+
/** A git checkout an agent made for itself (`~/.codex/worktrees/<id>/<repo>`):
|
|
206
|
+
* its own files are the project, even though the folder above holds settings. */
|
|
207
|
+
function agentWorktree(projectRoot, machine) {
|
|
208
|
+
if (!projectRoot)
|
|
209
|
+
return false;
|
|
210
|
+
return (machine.worktrees ?? []).some((folder) => projectRoot !== folder && within(projectRoot, folder));
|
|
196
211
|
}
|
|
197
212
|
/** Where a resolved, canonical path lands. */
|
|
198
213
|
export function placeOfPath(path, machine) {
|
|
199
214
|
const { home, projectRoot } = machine;
|
|
215
|
+
if (agentWorktree(projectRoot, machine) && within(path, projectRoot))
|
|
216
|
+
return projectPlace(path, projectRoot);
|
|
200
217
|
if (SENSITIVE_ABSOLUTE.some((folder) => within(path, folder)))
|
|
201
218
|
return "sensitive";
|
|
202
219
|
if (machine.sensitive.some((folder) => within(path, folder)))
|
|
@@ -207,13 +224,8 @@ export function placeOfPath(path, machine) {
|
|
|
207
224
|
return "root";
|
|
208
225
|
if (within(home, path))
|
|
209
226
|
return "home";
|
|
210
|
-
if (projectRoot && within(path, projectRoot))
|
|
211
|
-
|
|
212
|
-
return "sensitive";
|
|
213
|
-
if (path === projectRoot || path === posix.join(projectRoot, ".git"))
|
|
214
|
-
return "project-root";
|
|
215
|
-
return "project";
|
|
216
|
-
}
|
|
227
|
+
if (projectRoot && within(path, projectRoot))
|
|
228
|
+
return projectPlace(path, projectRoot);
|
|
217
229
|
// Home is personal even when it sits in a temporary folder (sandboxes).
|
|
218
230
|
if (within(path, home))
|
|
219
231
|
return "outside";
|
|
@@ -225,6 +237,13 @@ export function placeOfPath(path, machine) {
|
|
|
225
237
|
return "system";
|
|
226
238
|
return "outside";
|
|
227
239
|
}
|
|
240
|
+
function projectPlace(path, projectRoot) {
|
|
241
|
+
if (SENSITIVE_IN_PROJECT.some((entry) => within(path, posix.join(projectRoot, entry))))
|
|
242
|
+
return "sensitive";
|
|
243
|
+
if (path === projectRoot || path === posix.join(projectRoot, ".git"))
|
|
244
|
+
return "project-root";
|
|
245
|
+
return "project";
|
|
246
|
+
}
|
|
228
247
|
const EVERYTHING = new Set(["*", "**", ".*", "*.*", ".??*", ".[!.]*"]);
|
|
229
248
|
/** The path a word names, relative to `cwd`; null when it can't be known. */
|
|
230
249
|
export function resolveWord(word, cwd, machine) {
|
|
@@ -392,6 +411,24 @@ function vendorFindings(shape, outcome, walk, depth, cwd) {
|
|
|
392
411
|
if (!plain)
|
|
393
412
|
walk.complete = false;
|
|
394
413
|
}
|
|
414
|
+
/** The project's own code (`cliHookLocalCode.ts`): a script, a shell's quoted
|
|
415
|
+
* line, a patch. True when it was placed; the vendor map then has nothing to add. */
|
|
416
|
+
function ownCode(shape, at, machine, walk) {
|
|
417
|
+
const code = projectCode(shape.words, contextAt(at.cwd, machine), at.heredocs);
|
|
418
|
+
if (!code)
|
|
419
|
+
return false;
|
|
420
|
+
if ("line" in code) {
|
|
421
|
+
const inner = classifyLine(code.line, { ...machine, cwd: at.cwd }, at.depth + 1);
|
|
422
|
+
walk.findings.push(...inner.findings);
|
|
423
|
+
if (!inner.complete)
|
|
424
|
+
walk.complete = false;
|
|
425
|
+
return true;
|
|
426
|
+
}
|
|
427
|
+
walk.findings.push(...code.actions.map(localFinding));
|
|
428
|
+
if (!code.complete)
|
|
429
|
+
walk.complete = false;
|
|
430
|
+
return true;
|
|
431
|
+
}
|
|
395
432
|
/**
|
|
396
433
|
* Classify a whole command line run in `machine.cwd`. Vendor commands get the
|
|
397
434
|
* vendor map's findings; everyday commands get local findings; anything else
|
|
@@ -402,6 +439,7 @@ export function classifyLine(command, machine, depth = 0) {
|
|
|
402
439
|
if (depth > 4)
|
|
403
440
|
return { findings: [], complete: false };
|
|
404
441
|
const { shapes, nested, flags } = splitCommands(command);
|
|
442
|
+
const heredocs = heredocBodies(nested);
|
|
405
443
|
if (flags.braces || flags.processSubstitution || flags.heredoc || nested.length)
|
|
406
444
|
walk.complete = false;
|
|
407
445
|
const cwdAt = [machine.cwd];
|
|
@@ -440,6 +478,8 @@ export function classifyLine(command, machine, depth = 0) {
|
|
|
440
478
|
cwdAt[shape.depth] = nextDirectory(outcome.target, cwd, machine);
|
|
441
479
|
continue;
|
|
442
480
|
}
|
|
481
|
+
if (outcome.kind === "unknown" && ownCode(shape, { cwd, depth, heredocs }, machine, walk))
|
|
482
|
+
continue;
|
|
443
483
|
vendorFindings(shape, outcome, walk, depth, cwd);
|
|
444
484
|
}
|
|
445
485
|
for (const sub of nested) {
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The project's own code, run directly: the everyday commands a coding agent
|
|
3
|
+
* runs instead of `npm run` (Codex does this most).
|
|
4
|
+
*
|
|
5
|
+
* - `bash -lc '…'` and `sh -c '…'`: the quoted line, classified like any other.
|
|
6
|
+
* - `node scripts/check.mjs`, `npx tsx scripts/x.ts`, `bash scripts/ci.sh`,
|
|
7
|
+
* `./scripts/ci.sh`: a script file inside the project. Development work, the
|
|
8
|
+
* same as `npm run <script>`. Passport can't see what the script does, so the
|
|
9
|
+
* line stays incomplete: the guard never allows it, the agent's own prompt
|
|
10
|
+
* applies. It is not "opaque" in Activity either: it is the project's work.
|
|
11
|
+
* - `make test`, `just lint`: a target from the project's own task file, the
|
|
12
|
+
* same way.
|
|
13
|
+
* - `./node_modules/.bin/eslint .`: the tool itself.
|
|
14
|
+
* - `apply_patch <<'PATCH'` (Codex's patch format through the shell): a change
|
|
15
|
+
* to the files the patch names, placed like any other write.
|
|
16
|
+
*
|
|
17
|
+
* Anything else returns null and the caller's rules apply unchanged.
|
|
18
|
+
*/
|
|
19
|
+
import { type CommandContext, type LocalAction, type ShellWord } from "./localCommands.js";
|
|
20
|
+
export type CodeFindings = {
|
|
21
|
+
actions: LocalAction[];
|
|
22
|
+
complete: boolean;
|
|
23
|
+
} | {
|
|
24
|
+
line: string;
|
|
25
|
+
} | null;
|
|
26
|
+
/**
|
|
27
|
+
* What a command the everyday table didn't recognize does, when it runs the
|
|
28
|
+
* project's own code. `heredocs` are the bodies this line feeds, by program.
|
|
29
|
+
*/
|
|
30
|
+
export declare function projectCode(words: ShellWord[], ctx: CommandContext, heredocs: Map<string, string>): CodeFindings;
|
|
31
|
+
/** Bodies of the heredocs a line feeds, keyed by the program that reads them. */
|
|
32
|
+
export declare function heredocBodies(nested: Array<{
|
|
33
|
+
kind: string;
|
|
34
|
+
text: string;
|
|
35
|
+
target?: string;
|
|
36
|
+
}>): Map<string, string>;
|