passport-bridge 0.13.2 → 0.15.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 +113 -17
- package/dist/cli.js +4 -3
- package/dist/cliAnswered.d.ts +38 -0
- package/dist/cliAnswered.js +217 -0
- package/dist/cliArgs.d.ts +1 -1
- package/dist/cliArgs.js +44 -8
- package/dist/cliAutopilot.d.ts +77 -0
- package/dist/cliAutopilot.js +490 -0
- package/dist/cliAutopilotPolicy.d.ts +106 -0
- package/dist/cliAutopilotPolicy.js +209 -0
- package/dist/cliClient.d.ts +7 -0
- package/dist/cliClient.js +36 -19
- package/dist/cliExec.d.ts +62 -0
- package/dist/cliExec.js +409 -0
- package/dist/cliHook.d.ts +25 -27
- package/dist/cliHook.js +199 -86
- package/dist/cliHookClassify.d.ts +26 -0
- package/dist/cliHookClassify.js +12 -1
- package/dist/cliHookDecide.d.ts +91 -0
- package/dist/cliHookDecide.js +173 -0
- package/dist/cliHookEnvironment.d.ts +55 -0
- package/dist/cliHookEnvironment.js +219 -0
- package/dist/cliHookGuard.d.ts +63 -12
- package/dist/cliHookGuard.js +290 -29
- package/dist/cliHookInput.d.ts +27 -0
- package/dist/cliHookInput.js +47 -0
- package/dist/cliHookInstall.js +35 -4
- package/dist/cliHookLocal.d.ts +79 -0
- package/dist/cliHookLocal.js +467 -0
- package/dist/cliHookMode.d.ts +31 -0
- package/dist/cliHookMode.js +50 -0
- package/dist/cliHookParse.d.ts +33 -0
- package/dist/cliHookParse.js +144 -30
- package/dist/cliHookRedact.d.ts +16 -0
- package/dist/cliHookRedact.js +136 -0
- package/dist/cliHookRewrite.d.ts +45 -0
- package/dist/cliHookRewrite.js +135 -0
- package/dist/cliInit.d.ts +4 -1
- package/dist/cliInit.js +11 -3
- package/dist/cliKeys.d.ts +67 -0
- package/dist/cliKeys.js +426 -0
- package/dist/cliLogin.js +19 -3
- package/dist/cliOffline.js +9 -9
- package/dist/cliOutput.js +17 -5
- package/dist/cliPolicy.d.ts +13 -3
- package/dist/cliPolicy.js +5 -2
- package/dist/cliPolicyRefresh.d.ts +7 -0
- package/dist/cliPolicyRefresh.js +20 -0
- package/dist/cliPolicyV2.d.ts +18 -0
- package/dist/cliPolicyV2.js +257 -0
- package/dist/cliSetupOrg.d.ts +15 -0
- package/dist/cliSetupOrg.js +253 -0
- package/dist/cliSupport.d.ts +4 -0
- package/dist/cliSupport.js +12 -9
- package/dist/cliSync.d.ts +14 -0
- package/dist/cliSync.js +63 -0
- package/dist/completion.js +19 -3
- package/dist/doctor.js +3 -3
- package/dist/enrollment.d.ts +18 -0
- package/dist/enrollment.js +79 -0
- package/dist/execMarker.d.ts +7 -0
- package/dist/execMarker.js +66 -0
- package/dist/execVendors.d.ts +34 -0
- package/dist/execVendors.js +221 -0
- package/dist/hookPlugin.d.ts +7 -0
- package/dist/hookPlugin.js +54 -0
- package/dist/initAgents.d.ts +3 -1
- package/dist/initAgents.js +7 -3
- package/dist/initAutopilotStep.d.ts +24 -0
- package/dist/initAutopilotStep.js +283 -0
- package/dist/initKeysStep.d.ts +2 -0
- package/dist/initKeysStep.js +67 -0
- package/dist/initLocalSteps.d.ts +3 -0
- package/dist/initLocalSteps.js +31 -6
- package/dist/initState.d.ts +24 -0
- package/dist/initUi.js +5 -0
- package/dist/keysLocal.d.ts +56 -0
- package/dist/keysLocal.js +494 -0
- package/dist/localCommands.d.ts +39 -0
- package/dist/localCommands.js +534 -0
- package/dist/localFiles.d.ts +22 -0
- package/dist/localFiles.js +272 -0
- package/dist/localGit.d.ts +24 -0
- package/dist/localGit.js +270 -0
- package/dist/localNetwork.d.ts +16 -0
- package/dist/localNetwork.js +185 -0
- package/dist/localShared.d.ts +99 -0
- package/dist/localShared.js +173 -0
- package/dist/localTools.d.ts +52 -0
- package/dist/localTools.js +643 -0
- package/dist/nativeSync.d.ts +89 -0
- package/dist/nativeSync.js +376 -0
- package/dist/passport.js +42 -5
- package/dist/pluginPin.d.ts +7 -0
- package/dist/pluginPin.js +7 -0
- package/dist/universalUrl.d.ts +28 -0
- package/dist/universalUrl.js +59 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ New here? One command sets everything up:
|
|
|
23
23
|
npx passport-bridge@latest init
|
|
24
24
|
```
|
|
25
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
|
|
26
|
+
It scans for keys your agents can reach, signs you in (or up), connects the apps it found, shows the environments Passport placed, adds Passport to your agents, turns on the guard, and sets Autopilot: how much agents can do on their own. See [Set up with init](#set-up-with-init).
|
|
27
27
|
|
|
28
28
|
Or step by step:
|
|
29
29
|
|
|
@@ -52,7 +52,7 @@ passport run github_search_issues '{"query":"SSO"}'
|
|
|
52
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
53
|
| `logout` | Revoke the credential and always remove the local profile (warns if revocation fails). |
|
|
54
54
|
| `profiles` / `use <name>` | List stored profiles / select the active one. Offline. |
|
|
55
|
-
| `status` | Workspace, member, agent, and app connection states. |
|
|
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
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
57
|
| `ready` | Readiness preflight for automation; gate on its `ready` field and exit code. |
|
|
58
58
|
| `search [query] [--app <key>]` | Search permitted tools. Empty query lists the full catalog. |
|
|
@@ -63,7 +63,11 @@ passport run github_search_issues '{"query":"SSO"}'
|
|
|
63
63
|
| `prompts [name] [--set k=v] [--out <file>]` | List or get MCP prompts. |
|
|
64
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
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`,
|
|
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
|
+
| `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). |
|
|
67
71
|
| `setup` | Install and maintain assigned team workflows as managed skills. |
|
|
68
72
|
| `session` | Run NDJSON commands over one authenticated MCP session. |
|
|
69
73
|
| `access` | Signed managed access: `keygen`, `actions`, `run`, `invoke`, `status`, `cancel`. |
|
|
@@ -123,14 +127,25 @@ npx passport-bridge@latest init --yes # accept every default; needed with
|
|
|
123
127
|
npx passport-bridge@latest init --yes --json # one summary object with each step's status
|
|
124
128
|
```
|
|
125
129
|
|
|
126
|
-
|
|
130
|
+
Seven steps, each reusing the command that owns it:
|
|
127
131
|
|
|
128
132
|
1. **Scan**: the same local scan as `passport scan`, as one summary line (`--verbose` prints the table).
|
|
129
133
|
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
134
|
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. **
|
|
132
|
-
5. **
|
|
133
|
-
6. **
|
|
135
|
+
4. **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.`
|
|
136
|
+
5. **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.
|
|
137
|
+
6. **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.
|
|
138
|
+
7. **Autopilot**: how much agents can do on their own, per environment:
|
|
139
|
+
|
|
140
|
+
```
|
|
141
|
+
Autopilot How much can agents do on their own?
|
|
142
|
+
Production Careful reads run, changes ask
|
|
143
|
+
Staging Balanced reads and changes run, deletes ask
|
|
144
|
+
Development Hands-off everything except irreversible runs
|
|
145
|
+
Keep these? [Y/n]
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
`n` chooses per environment; `--yes` keeps the defaults. A team floor stricter than a default is shown with why (`Your team requires Careful or stricter in Staging.`), and choices below it aren't offered. A CLI credential can only make presets stricter; a looser pick says so in one line and keeps the current ones. A re-run shows the presets `(already set up)` without asking. The closing summary says what will ask: `Autopilot on. You'll be asked only for Production changes, deletes outside Development, and irreversible actions.` A server without Autopilot gets the earlier Safety step instead.
|
|
134
149
|
|
|
135
150
|
What changes on disk, and how to undo it:
|
|
136
151
|
|
|
@@ -146,6 +161,25 @@ What changes on disk, and how to undo it:
|
|
|
146
161
|
|
|
147
162
|
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
163
|
|
|
164
|
+
### Company rollout
|
|
165
|
+
|
|
166
|
+
```sh
|
|
167
|
+
npx passport-bridge@latest setup --org pek_example --yes # Jamf, Kandji, Intune, or any script
|
|
168
|
+
npx passport-bridge@latest setup --org pek_example --clients claude-code,codex
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
`init` for MDM: it never asks anything and never signs in. It installs the stable copy of the CLI, adds Passport to every detected agent (Claude Code, Cursor, Codex, VS Code; Claude Desktop gets the connector step) at the one URL with the enrollment key as its hint (`https://passportmcp.com/mcp?enroll=pek_…`), turns on the guard and audit hooks for Claude Code, Codex, and Cursor, and records the key in `$PASSPORT_HOME/enrollment.json` (mode 600). It prints one line per agent:
|
|
172
|
+
|
|
173
|
+
```
|
|
174
|
+
Passport setup for passportmcp.com (enrollment pek_…mple)
|
|
175
|
+
Claude Code ✓ Passport added · guard on
|
|
176
|
+
Cursor ✓ Passport already set up · guard on
|
|
177
|
+
Codex ✓ Passport added · sign in: codex mcp login passport · guard on
|
|
178
|
+
Each agent asks you to sign in to Passport the first time it connects.
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
The first line names the workspace the key pre-selects (`GET /api/auth/enrollment/<key>`, public, no credential). It exits 0 even with no agents (`No supported agents found. Nothing to set up.`), so an MDM run never fails a computer without them. A malformed key or `--clients` list exits 6, and so does a key the server doesn't know or has revoked, with the server's one line (`This enrollment key isn't valid.` or `This enrollment key was revoked. Ask your admin for a new one.`) before anything changes. `passport login` on that computer later passes the recorded key: as the browser sign-in hint (`POST /api/auth/cli/start { enroll }`) and for rollout attribution when the CLI credential is minted (`enrollmentKey`). A server that doesn't serve the one URL yet still gets the CLI, hooks, and key, and the agents wait for `passport init`. Run it again any time: it changes nothing that's in place and repairs what drifted (a removed hook, an entry pointing at npm's cache). The enrollment key is a workspace hint, not a credential: people still sign in as themselves. `--cloud <origin>` (or `PASSPORT_CLOUD`) points it at a self-hosted Passport. `--json` prints `{version,origin,universal,url?,workspace?:{id,name},enrollment,clients:[{agent,name,mcp,guard,message?,next?}]}`.
|
|
182
|
+
|
|
149
183
|
### Team workflows
|
|
150
184
|
|
|
151
185
|
Codex and Claude Code on macOS and Linux. Requires a member profile.
|
|
@@ -169,17 +203,74 @@ passport hook status
|
|
|
169
203
|
passport hook uninstall --client claude-code --guard --apply # guard only
|
|
170
204
|
```
|
|
171
205
|
|
|
172
|
-
Two hooks per agent. `passport hook` runs after each shell command and records the vendor, a coarse verb,
|
|
206
|
+
Two hooks per agent. `passport hook` runs after each shell command and records the vendor, a coarse verb, a risk class, and (with Autopilot) the environment name the flags gave and the guard's decision in Activity; the server works out the class and cause. `passport hook guard` runs before it and decides from the member's Autopilot rules (`src/cliHookGuard.ts`):
|
|
207
|
+
|
|
208
|
+
- **Allow** (Claude Code `permissionDecision: "allow"`, Cursor `permission: "allow"`) only when every part of the line is understood and allowed: vendor commands in `src/cliHookVendors.ts` read with confidence, and everyday commands (below). Substitutions, heredocs, variables in a path, unknown wrappers or environment prefixes, scripts, aliases, `make`, and programs Passport doesn't know mean no decision, so the agent's own permission rules apply. Codex can't receive allow; its own approvals apply (see `passport sync`).
|
|
209
|
+
- **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.
|
|
210
|
+
- 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.`
|
|
173
211
|
|
|
174
|
-
|
|
212
|
+
**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.
|
|
213
|
+
|
|
214
|
+
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.`
|
|
215
|
+
|
|
216
|
+
**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:
|
|
217
|
+
|
|
218
|
+
| Signal | Means |
|
|
219
|
+
| --- | --- |
|
|
220
|
+
| `PASSPORT_HOOK_MODE=attended\|unattended` | Override |
|
|
221
|
+
| Claude Code `CLAUDE_CODE_SESSION_ATTENDED` (`1`/`0`), passed to every hook | Attended / unattended |
|
|
222
|
+
| Hook input `permission_mode` `dontAsk` or `bypassPermissions` (Claude Code, Codex) | Unattended: prompts are suppressed |
|
|
223
|
+
| Cursor `is_background_agent: true` | Unattended: background and cloud agents |
|
|
224
|
+
| `CLAUDE_CODE_ENTRYPOINT` `sdk-cli` (`claude -p`), `sdk-ts`, `sdk-py`, `claude-code-github-action` | Unattended (older Claude Code builds) |
|
|
225
|
+
| `CI`, `GITHUB_ACTIONS`, `GITLAB_CI`, `BUILDKITE`, `CIRCLECI`, `JENKINS_URL`, `TF_BUILD` | Unattended |
|
|
175
226
|
|
|
176
|
-
|
|
227
|
+
Codex has no field for `codex exec`; its prompt-free modes count as unattended, where an ask blocks for now with the waiting line.
|
|
228
|
+
|
|
229
|
+
The approval request carries a command summary with secrets removed on this computer (`src/cliHookRedact.ts`, using `passport scan`'s key formats plus secret-named flags, variables, JSON fields, URL credentials, and long opaque values; heredoc bodies are dropped). It is the only part of a command line that ever leaves the machine, and only approvers see it.
|
|
230
|
+
|
|
231
|
+
The guard decides from local data inside `HOOK_BUDGET_MS` (1.5 s) and prints first; only an unattended ask waits for the server, within the same budget. 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 raw command line, output, folder path, or environment.
|
|
232
|
+
|
|
233
|
+
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.
|
|
177
234
|
|
|
178
235
|
- 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
|
|
236
|
+
- 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`.
|
|
180
237
|
- 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
238
|
|
|
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.
|
|
239
|
+
`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.
|
|
240
|
+
|
|
241
|
+
The Passport plugin (`rsyed94/passport-plugins`) runs the same two hooks from the agent's plugin folder, with `PASSPORT_HOOK_VIA=plugin`. `passport hook status` shows those agents as `via plugin`, and `hook install`, `init`, and `setup --org` skip them (`Claude Code: already covered by the Passport plugin.`) so nothing is recorded twice. The plugin pins the CLI version in `src/pluginPin.ts`.
|
|
242
|
+
|
|
243
|
+
### Autopilot from the terminal
|
|
244
|
+
|
|
245
|
+
```sh
|
|
246
|
+
passport rules test "railway redeploy -e staging"
|
|
247
|
+
passport rules test "rm -rf ~/"
|
|
248
|
+
passport wait apr_123
|
|
249
|
+
passport sessions
|
|
250
|
+
passport sync # or: passport sync --remove
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
- `rules test` classifies the command here and sends only its app and verb (and the environment kind) to `POST /api/my/rules/test`, never the command line. An everyday command goes as a finding (`{finding: {vendor, verb, risk, environment}}`), because only this computer can place its paths. It prints the decision, its cause, the environment, and the class. Without a server answer it decides from this computer's copy and says how old it is. `--environment` picks one when the flags don't say.
|
|
254
|
+
- `wait` long-polls `GET /api/my/approvals/<id>/wait`. Approved: `Approved by Ramish. Run the command again.` (exit 0). Declined: the note for the agent, `Declined by Ramish: <note>` (exit 5, cause `approval_denied`). Expired: `Expired. The agent can ask again.` (exit 5, cause `approval_expired`). Still waiting at `--timeout` (default 100 seconds, under an agent's 2-minute command limit): exit 4 with the same command as `next`.
|
|
255
|
+
- `sessions` lists recent sessions (`GET /api/my/agent-sessions`): status, agent, folder, start, `42 ran · 2 asked · 1 blocked`, environments touched, and `Waiting for you` when approvals are pending.
|
|
256
|
+
- `sync` writes the allows Passport is sure of into each agent's own permission settings, so those prompts disappear offline and in Codex (`src/nativeSync.ts`). Only reads, test runners, builds and type checks, linters that only check, `git status`, `git add`, and `git commit`, checked against the person's rules. Formatters, fixing linters, `mv`/`cp`, and package scripts stay with the hook, which sees what they touch; deletes, installs, pushes, and Production never sync. Claude Code: `Bash(npm test *)` in `permissions.allow` of `~/.claude/settings.json`. Codex: `prefix_rule(pattern = ["npm", "test"], decision = "allow")` in `~/.codex/rules/passport.rules`, a file Passport owns. Cursor CLI: `Shell(npm:test*)` in `permissions.allow` of `~/.cursor/cli-config.json`. Cursor: `npm test` in `terminalAllowlist` of `~/.cursor/permissions.json`, only when that list already exists there (defining it replaces Cursor's in-app list). Entries Passport added are listed in `$PASSPORT_HOME/native-sync.json`; an entry you had before is never claimed or removed, and a file Passport can't parse exactly (JSONC) is left alone. Sync runs on `init`, `setup --org`, every rules refresh, and `passport sync`; `hook uninstall`, `sync --remove`, and signing out of the last profile take the entries out.
|
|
257
|
+
- `status` adds `Answered for you: N prompts today` (allows the hook gave in Claude Code and Cursor, and Codex commands Passport synced, counted only when the agent would have prompted) and which agents' allowlists are synced. Counts are appended locally (`$PASSPORT_HOME/answered/`) and sent in batches at most every five minutes as `answered: {batch, count}` on `POST /api/my/cli-activity`.
|
|
258
|
+
- `rules test`, `sessions`, and `sync` need a member profile. `wait` also works for a cloud agent's key, on the approval its own `passport exec` opened.
|
|
259
|
+
|
|
260
|
+
### Keys and passport exec
|
|
261
|
+
|
|
262
|
+
```sh
|
|
263
|
+
passport keys move # confirm each key, store it in Passport, sign that CLI out here
|
|
264
|
+
passport keys # what Passport holds, and what's still on this computer
|
|
265
|
+
passport keys add railway # store a key you paste (stdin, never echoed)
|
|
266
|
+
passport exec -- railway up -e staging
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
- `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, stores the key in Passport (`POST /api/my/keys`), then signs that CLI out with its own command (`railway logout`, `gh auth logout`, `vercel logout`, `wrangler logout`, `supabase logout`, `stripe logout`) or removes only that entry. 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.
|
|
270
|
+
- `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`).
|
|
271
|
+
- 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.
|
|
272
|
+
- 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.
|
|
273
|
+
- Cloud agents (Agents → Cloud agents) run exec and MCP with `PASSPORT_AGENT_KEY` and `PASSPORT_ENDPOINT`: the owner's rules decide, the owner's keys are used, and approvals go to the owner.
|
|
183
274
|
|
|
184
275
|
### Persistent sessions
|
|
185
276
|
|
|
@@ -237,7 +328,7 @@ passport ready --json
|
|
|
237
328
|
passport search "deployment status" --json
|
|
238
329
|
```
|
|
239
330
|
|
|
240
|
-
Set both variables together. Environment auth overrides stored profiles, persists nothing, and cannot be combined with `--profile` or `login`/`logout`. Agent keys skip member approval prompts; use a member profile for work that must pause for a human.
|
|
331
|
+
`PASSPORT_ENDPOINT` is Passport's one URL (`https://<host>/mcp`, where the agent key's own prefix says which workspace) or a workspace's own (`https://<host>/w/<workspace>/mcp`). Set both variables together. Environment auth overrides stored profiles, persists nothing, and cannot be combined with `--profile` or `login`/`logout`. Agent keys skip member approval prompts; use a member profile for work that must pause for a human.
|
|
241
332
|
|
|
242
333
|
## Managed access
|
|
243
334
|
|
|
@@ -290,7 +381,10 @@ With `--json`, stdout is exactly one JSON value; hints and warnings go to stderr
|
|
|
290
381
|
| `profiles` | `{profiles:[{name,active,client?}],active?}` |
|
|
291
382
|
| `use` | `{profile,active:true}` |
|
|
292
383
|
| `logout` | `{profile,removed,revoked}` |
|
|
293
|
-
| `status` | `{workspace,member,endpoint,auth,profile?,client,mcps,next?}` |
|
|
384
|
+
| `status` | `{workspace,member,endpoint,auth,profile?,client,mcps,autopilot?:{presets,floors,floorReason?,cache:{version,fetchedAt,ageMs}},next?}` |
|
|
385
|
+
| `wait` | `{approvalId,status:"approved",scope?,message}`; declined, expired, and still-waiting are errors with `approvalId` |
|
|
386
|
+
| `rules` | `{command,decision,cause?,explanation?,environment?,environmentAssumed?,actionClass?,source}` |
|
|
387
|
+
| `sessions` | `{sessions:[{id,client,folder,status,startedAt,lastActivityAt,counts,environments,waiting}],nextCursor}` |
|
|
294
388
|
| `doctor` | `{version,ok,auth,profile?,profileCount,endpointOrigin?,server?,checks}`, also on failure |
|
|
295
389
|
| `ready` | `{ready,version,ok,auth,profile?,profileCount,endpointOrigin?,server?,checks}` |
|
|
296
390
|
| `search` | Gateway payload with `results` or `catalog`, and `note` |
|
|
@@ -304,7 +398,7 @@ With `--json`, stdout is exactly one JSON value; hints and warnings go to stderr
|
|
|
304
398
|
| `access` | `keygen`: algorithm, paths, public JWK; `actions`: `{actions}`; `run`/`cancel`: `{run}`; `invoke`: governed result; `status`: `{receipt}` |
|
|
305
399
|
| `completion` | `{shell,script}` |
|
|
306
400
|
| `help` | `{command,help}` |
|
|
307
|
-
| `version` | `{version,profileCount,profileSelected,selectionSource,next,
|
|
401
|
+
| `version` | `{version,profileCount,profileSelected,selectionSource,next,endpoint?,profile?}` |
|
|
308
402
|
|
|
309
403
|
Errors: `{"error":"...","cause":"blocked","exitCode":5,"app":"github"}`, optionally with `approvalId`, `hint`, `profiles`, `next` (`argv` plus description), `remediation`, `retry`, `requiredInput`, or `connectUrl`.
|
|
310
404
|
|
|
@@ -314,8 +408,8 @@ Errors: `{"error":"...","cause":"blocked","exitCode":5,"app":"github"}`, optiona
|
|
|
314
408
|
| 1 | Network, timeout, server, or unsupported-content error |
|
|
315
409
|
| 2 | Missing, expired, or revoked authentication |
|
|
316
410
|
| 3 | App needs member sign-in |
|
|
317
|
-
| 4 | Approval pending |
|
|
318
|
-
| 5 | Policy, guardrail, selection, or approval denial |
|
|
411
|
+
| 4 | Approval pending (including `wait` still waiting at its timeout) |
|
|
412
|
+
| 5 | Policy, guardrail, selection, or approval denial (including a declined or expired approval in `wait`) |
|
|
319
413
|
| 6 | Invalid usage or unknown tool/app |
|
|
320
414
|
|
|
321
415
|
## MCP stdio bridge
|
|
@@ -339,4 +433,6 @@ passport-bridge serve --profile cursor@ws_example
|
|
|
339
433
|
|
|
340
434
|
## Maintainers
|
|
341
435
|
|
|
436
|
+
Tests never reach production Passport: `scripts/no-production-guard.mjs` is preloaded by the unit tests and, through `NODE_OPTIONS`, by every process `cli-e2e.ts` starts, and any request to passportmcp.com fails the run. Harnesses use a local server with `--cloud http://127.0.0.1:<port>` (or `PASSPORT_CLOUD`) and `PASSPORT_NO_OPEN=1`.
|
|
437
|
+
|
|
342
438
|
`npm run pack:verified` builds the npm tarball, checks required files, and writes a `.sha256` checksum file (verify with `sha256sum -c passport-bridge-<version>.tgz.sha256`). Releases publish only through the repository's npm trusted-publisher workflow.
|
package/dist/cli.js
CHANGED
|
@@ -27,9 +27,9 @@ function arg(flag, fallback = "") {
|
|
|
27
27
|
const i = process.argv.indexOf(flag);
|
|
28
28
|
return i >= 0 && process.argv[i + 1] ? process.argv[i + 1] : fallback;
|
|
29
29
|
}
|
|
30
|
-
/** `npx passport-bridge@latest scan` and `
|
|
31
|
-
*
|
|
32
|
-
const PASSPORT_ONE_LINERS = new Set(["scan", "init"]);
|
|
30
|
+
/** `npx passport-bridge@latest scan`, `init`, and `setup --org` run the
|
|
31
|
+
* `passport` CLI's own implementation, so both bins behave identically. */
|
|
32
|
+
const PASSPORT_ONE_LINERS = new Set(["scan", "init", "setup"]);
|
|
33
33
|
async function passportOneLiner() {
|
|
34
34
|
const problem = oneLinerNodeProblem();
|
|
35
35
|
if (problem) {
|
|
@@ -77,6 +77,7 @@ Commands:
|
|
|
77
77
|
logout Revoke and remove a saved profile
|
|
78
78
|
scan Find keys your agents can reach. Local, no account
|
|
79
79
|
init Set up Passport for your agents, step by step
|
|
80
|
+
setup setup --org <key>: set up every agent here for your company (MDM)
|
|
80
81
|
|
|
81
82
|
Options:
|
|
82
83
|
--profile <name> Use a named profile (default: default)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* "Answered for you": how many prompts this computer answered so the agent
|
|
3
|
+
* didn't have to ask. The guard counts an allow it gave (Claude Code, Cursor)
|
|
4
|
+
* and a Codex command Passport synced into Codex's own rules, and only when a
|
|
5
|
+
* prompt would really have appeared: plain reads the agents already run
|
|
6
|
+
* without asking (ls, cat, git status) don't count.
|
|
7
|
+
*
|
|
8
|
+
* Counting is append-only, one byte per answer in a file per day, so parallel
|
|
9
|
+
* hooks never lose a count. Batches go to Passport at most every five minutes
|
|
10
|
+
* with an id, so a retried batch lands once. Only counts ever leave the machine.
|
|
11
|
+
*/
|
|
12
|
+
import type { CliFinding } from "./cliHookClassify.js";
|
|
13
|
+
export declare const ANSWERED_REPORT_MS: number;
|
|
14
|
+
/** Whether an allow for these findings answered a prompt the agent would have shown. */
|
|
15
|
+
export declare function answersAPrompt(findings: CliFinding[]): boolean;
|
|
16
|
+
/** The local calendar day, so "today" means the person's today. */
|
|
17
|
+
export declare function localDay(now: number): string;
|
|
18
|
+
/** Count one answered prompt. Never throws. */
|
|
19
|
+
export declare function noteAnswered(profile: string, now?: number): void;
|
|
20
|
+
/** Prompts answered on this computer today. */
|
|
21
|
+
export declare function answeredToday(profile: string, now?: number): number;
|
|
22
|
+
/** The next batch to report, or null. A batch that wasn't confirmed is sent again as is. */
|
|
23
|
+
export declare function claimAnsweredBatch(profile: string, now?: number, force?: boolean): {
|
|
24
|
+
batch: string;
|
|
25
|
+
count: number;
|
|
26
|
+
} | null;
|
|
27
|
+
/** Passport recorded the batch: move the mark forward and forget old days. */
|
|
28
|
+
export declare function settleAnsweredBatch(profile: string, batch: string, now?: number): void;
|
|
29
|
+
/**
|
|
30
|
+
* Count an allow that answered a prompt the agent would have shown: Claude
|
|
31
|
+
* Code and Cursor take the hook's allow; Codex runs a command without asking
|
|
32
|
+
* only when Passport synced it into Codex's own rules. Never throws.
|
|
33
|
+
*/
|
|
34
|
+
export declare function countAnswered(profile: string, how: {
|
|
35
|
+
client: string;
|
|
36
|
+
command: string;
|
|
37
|
+
printed: boolean;
|
|
38
|
+
}, findings: CliFinding[], now?: number): Promise<void>;
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* "Answered for you": how many prompts this computer answered so the agent
|
|
3
|
+
* didn't have to ask. The guard counts an allow it gave (Claude Code, Cursor)
|
|
4
|
+
* and a Codex command Passport synced into Codex's own rules, and only when a
|
|
5
|
+
* prompt would really have appeared: plain reads the agents already run
|
|
6
|
+
* without asking (ls, cat, git status) don't count.
|
|
7
|
+
*
|
|
8
|
+
* Counting is append-only, one byte per answer in a file per day, so parallel
|
|
9
|
+
* hooks never lose a count. Batches go to Passport at most every five minutes
|
|
10
|
+
* with an id, so a retried batch lands once. Only counts ever leave the machine.
|
|
11
|
+
*/
|
|
12
|
+
import { randomBytes } from "node:crypto";
|
|
13
|
+
import { appendFileSync, closeSync, constants, mkdirSync, openSync, readdirSync, readFileSync, rmSync, statSync, utimesSync } from "node:fs";
|
|
14
|
+
import { join } from "node:path";
|
|
15
|
+
import { credentialDir, ensurePrivateDirectory, writePrivateAtomic } from "./credentialStorage.js";
|
|
16
|
+
import { assertProfileName } from "./credentials.js";
|
|
17
|
+
const DIRECTORY = "answered";
|
|
18
|
+
export const ANSWERED_REPORT_MS = 5 * 60 * 1000;
|
|
19
|
+
const KEEP_DAYS = 3;
|
|
20
|
+
/** Reads the agents already run without a prompt: no prompt was answered. */
|
|
21
|
+
const QUIET_READERS = new Set([
|
|
22
|
+
"ls",
|
|
23
|
+
"cat",
|
|
24
|
+
"echo",
|
|
25
|
+
"pwd",
|
|
26
|
+
"head",
|
|
27
|
+
"tail",
|
|
28
|
+
"grep",
|
|
29
|
+
"rg",
|
|
30
|
+
"find",
|
|
31
|
+
"fd",
|
|
32
|
+
"wc",
|
|
33
|
+
"which",
|
|
34
|
+
"diff",
|
|
35
|
+
"stat",
|
|
36
|
+
"du",
|
|
37
|
+
"tree",
|
|
38
|
+
"file",
|
|
39
|
+
"sort",
|
|
40
|
+
"uniq",
|
|
41
|
+
"cut",
|
|
42
|
+
"tr",
|
|
43
|
+
"basename",
|
|
44
|
+
"dirname",
|
|
45
|
+
"realpath",
|
|
46
|
+
"readlink",
|
|
47
|
+
"date",
|
|
48
|
+
"whoami",
|
|
49
|
+
"uname",
|
|
50
|
+
"ps",
|
|
51
|
+
"jq",
|
|
52
|
+
"less",
|
|
53
|
+
"sed",
|
|
54
|
+
"column",
|
|
55
|
+
"nl"
|
|
56
|
+
]);
|
|
57
|
+
/** Whether an allow for these findings answered a prompt the agent would have shown. */
|
|
58
|
+
export function answersAPrompt(findings) {
|
|
59
|
+
return findings.some((finding) => {
|
|
60
|
+
if (!finding.vendor)
|
|
61
|
+
return false;
|
|
62
|
+
if (finding.local?.actionClass !== "read")
|
|
63
|
+
return true;
|
|
64
|
+
if (finding.vendor === "git")
|
|
65
|
+
return false;
|
|
66
|
+
return !QUIET_READERS.has(finding.vendor);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function directory() {
|
|
70
|
+
return join(credentialDir(), DIRECTORY);
|
|
71
|
+
}
|
|
72
|
+
/** The local calendar day, so "today" means the person's today. */
|
|
73
|
+
export function localDay(now) {
|
|
74
|
+
const date = new Date(now);
|
|
75
|
+
const pad = (value) => String(value).padStart(2, "0");
|
|
76
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
|
|
77
|
+
}
|
|
78
|
+
function logPath(profile, day) {
|
|
79
|
+
assertProfileName(profile);
|
|
80
|
+
return join(directory(), `${profile}.${day}.log`);
|
|
81
|
+
}
|
|
82
|
+
function statePath(profile) {
|
|
83
|
+
assertProfileName(profile);
|
|
84
|
+
return join(directory(), `${profile}.json`);
|
|
85
|
+
}
|
|
86
|
+
/** Count one answered prompt. Never throws. */
|
|
87
|
+
export function noteAnswered(profile, now = Date.now()) {
|
|
88
|
+
try {
|
|
89
|
+
ensurePrivateDirectory(true);
|
|
90
|
+
mkdirSync(directory(), { recursive: true, mode: 0o700 });
|
|
91
|
+
appendFileSync(logPath(profile, localDay(now)), "1", { mode: 0o600 });
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
/* A lost count is harmless. */
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function sizeOf(path) {
|
|
98
|
+
try {
|
|
99
|
+
return statSync(path).size;
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
return 0;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/** Prompts answered on this computer today. */
|
|
106
|
+
export function answeredToday(profile, now = Date.now()) {
|
|
107
|
+
try {
|
|
108
|
+
return sizeOf(logPath(profile, localDay(now)));
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
return 0;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function readState(profile) {
|
|
115
|
+
try {
|
|
116
|
+
const parsed = JSON.parse(readFileSync(statePath(profile), "utf8"));
|
|
117
|
+
return parsed && typeof parsed.sent === "object" && parsed.sent ? parsed : { sent: {} };
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
return { sent: {} };
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function writeState(profile, state) {
|
|
124
|
+
writePrivateAtomic(statePath(profile), ".answered", `${JSON.stringify(state)}\n`, "answered counts");
|
|
125
|
+
}
|
|
126
|
+
/** At most one report per interval per profile, claimed before any network. */
|
|
127
|
+
function claimInterval(profile, now) {
|
|
128
|
+
const marker = join(directory(), `.${profile}.report`);
|
|
129
|
+
try {
|
|
130
|
+
const last = statSync(marker).mtimeMs;
|
|
131
|
+
if (now - last < ANSWERED_REPORT_MS && last <= now)
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
if (error.code !== "ENOENT")
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
try {
|
|
139
|
+
const noFollow = typeof constants.O_NOFOLLOW === "number" ? constants.O_NOFOLLOW : 0;
|
|
140
|
+
closeSync(openSync(marker, constants.O_WRONLY | constants.O_CREAT | noFollow, 0o600));
|
|
141
|
+
utimesSync(marker, now / 1000, now / 1000);
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/** The next batch to report, or null. A batch that wasn't confirmed is sent again as is. */
|
|
149
|
+
export function claimAnsweredBatch(profile, now = Date.now(), force = false) {
|
|
150
|
+
try {
|
|
151
|
+
if (!force && !claimInterval(profile, now))
|
|
152
|
+
return null;
|
|
153
|
+
const state = readState(profile);
|
|
154
|
+
if (state.pending)
|
|
155
|
+
return { batch: state.pending.batch, count: state.pending.count };
|
|
156
|
+
const days = readdirSync(directory())
|
|
157
|
+
.map((name) => new RegExp(`^${profile.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\.(\\d{4}-\\d{2}-\\d{2})\\.log$`).exec(name)?.[1])
|
|
158
|
+
.filter((day) => Boolean(day))
|
|
159
|
+
.sort();
|
|
160
|
+
for (const day of days) {
|
|
161
|
+
const count = sizeOf(logPath(profile, day)) - (state.sent[day] ?? 0);
|
|
162
|
+
if (count <= 0)
|
|
163
|
+
continue;
|
|
164
|
+
const pending = { batch: `ans_${randomBytes(12).toString("hex")}`, day, count: Math.min(count, 100_000) };
|
|
165
|
+
writeState(profile, { ...state, pending });
|
|
166
|
+
return { batch: pending.batch, count: pending.count };
|
|
167
|
+
}
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/** Passport recorded the batch: move the mark forward and forget old days. */
|
|
175
|
+
export function settleAnsweredBatch(profile, batch, now = Date.now()) {
|
|
176
|
+
try {
|
|
177
|
+
const state = readState(profile);
|
|
178
|
+
if (state.pending?.batch !== batch)
|
|
179
|
+
return;
|
|
180
|
+
const { day, count } = state.pending;
|
|
181
|
+
const sent = { ...state.sent, [day]: (state.sent[day] ?? 0) + count };
|
|
182
|
+
const today = localDay(now);
|
|
183
|
+
const oldest = localDay(now - KEEP_DAYS * 24 * 60 * 60 * 1000);
|
|
184
|
+
for (const kept of Object.keys(sent)) {
|
|
185
|
+
if (kept < oldest && kept !== today) {
|
|
186
|
+
delete sent[kept];
|
|
187
|
+
rmSync(logPath(profile, kept), { force: true });
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
writeState(profile, { sent });
|
|
191
|
+
}
|
|
192
|
+
catch {
|
|
193
|
+
/* Sent again next time, under the same batch id. */
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Count an allow that answered a prompt the agent would have shown: Claude
|
|
198
|
+
* Code and Cursor take the hook's allow; Codex runs a command without asking
|
|
199
|
+
* only when Passport synced it into Codex's own rules. Never throws.
|
|
200
|
+
*/
|
|
201
|
+
export async function countAnswered(profile, how, findings, now = Date.now()) {
|
|
202
|
+
try {
|
|
203
|
+
if (!answersAPrompt(findings))
|
|
204
|
+
return;
|
|
205
|
+
if (how.client === "codex") {
|
|
206
|
+
const { syncedForCodex } = await import("./nativeSync.js");
|
|
207
|
+
if (!syncedForCodex(how.command))
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
else if (!how.printed)
|
|
211
|
+
return;
|
|
212
|
+
noteAnswered(profile, now);
|
|
213
|
+
}
|
|
214
|
+
catch {
|
|
215
|
+
/* Counting never gets in the agent's way. */
|
|
216
|
+
}
|
|
217
|
+
}
|
package/dist/cliArgs.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const COMMANDS: readonly ["init", "login", "logout", "profiles", "use", "status", "doctor", "ready", "search", "describe", "run", "connect", "resources", "prompts", "discover", "scan", "hook", "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", "wait", "rules", "sessions", "sync", "exec", "keys", "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
|
@@ -16,6 +16,12 @@ export const COMMANDS = [
|
|
|
16
16
|
"discover",
|
|
17
17
|
"scan",
|
|
18
18
|
"hook",
|
|
19
|
+
"wait",
|
|
20
|
+
"rules",
|
|
21
|
+
"sessions",
|
|
22
|
+
"sync",
|
|
23
|
+
"exec",
|
|
24
|
+
"keys",
|
|
19
25
|
"setup",
|
|
20
26
|
"session",
|
|
21
27
|
"access",
|
|
@@ -30,13 +36,15 @@ const FLAGS = {
|
|
|
30
36
|
quiet: { kind: "boolean" },
|
|
31
37
|
caller: { kind: "value" },
|
|
32
38
|
help: { kind: "boolean" },
|
|
33
|
-
cloud: { kind: "value", commands: ["login", "init"] },
|
|
39
|
+
cloud: { kind: "value", commands: ["login", "init", "setup"] },
|
|
34
40
|
workspace: { kind: "value", commands: ["login", "access"] },
|
|
35
|
-
client: { kind: "value", commands: ["login", "setup", "hook"] },
|
|
41
|
+
client: { kind: "value", commands: ["login", "setup", "hook", "exec"] },
|
|
36
42
|
apply: { kind: "boolean", commands: ["setup", "hook"] },
|
|
37
43
|
guard: { kind: "boolean", commands: ["hook"] },
|
|
38
44
|
"no-open": { kind: "boolean", commands: ["login", "init"] },
|
|
39
|
-
yes: { kind: "boolean", commands: ["init"] },
|
|
45
|
+
yes: { kind: "boolean", commands: ["init", "setup", "keys"] },
|
|
46
|
+
org: { kind: "value", commands: ["setup"] },
|
|
47
|
+
clients: { kind: "value", commands: ["setup"] },
|
|
40
48
|
"skip-apps": { kind: "boolean", commands: ["init"] },
|
|
41
49
|
"skip-agents": { kind: "boolean", commands: ["init"] },
|
|
42
50
|
"skip-guard": { kind: "boolean", commands: ["init"] },
|
|
@@ -44,11 +52,12 @@ const FLAGS = {
|
|
|
44
52
|
args: { kind: "value", commands: ["run"] },
|
|
45
53
|
set: { kind: "repeat", commands: ["run", "prompts"] },
|
|
46
54
|
"set-json": { kind: "repeat", commands: ["run"] },
|
|
47
|
-
wait: { kind: "value", commands: ["run", "connect"] },
|
|
55
|
+
wait: { kind: "value", commands: ["run", "connect", "exec"] },
|
|
56
|
+
session: { kind: "value", commands: ["exec"] },
|
|
48
57
|
alias: { kind: "value", commands: ["connect"] },
|
|
49
58
|
open: { kind: "boolean", commands: ["connect"] },
|
|
50
59
|
out: { kind: "value", commands: ["resources", "prompts"] },
|
|
51
|
-
verbose: { kind: "boolean", commands: ["scan", "init"] },
|
|
60
|
+
verbose: { kind: "boolean", commands: ["scan", "init", "exec"] },
|
|
52
61
|
path: { kind: "value", commands: ["scan"] },
|
|
53
62
|
check: { kind: "boolean", commands: ["scan"] },
|
|
54
63
|
input: { kind: "value", commands: ["access"] },
|
|
@@ -56,7 +65,10 @@ const FLAGS = {
|
|
|
56
65
|
"private-key-file": { kind: "value", commands: ["access"] },
|
|
57
66
|
"public-jwk-file": { kind: "value", commands: ["access"] },
|
|
58
67
|
"delegation-id": { kind: "value", commands: ["access"] },
|
|
59
|
-
"client-id": { kind: "value", commands: ["access"] }
|
|
68
|
+
"client-id": { kind: "value", commands: ["access"] },
|
|
69
|
+
environment: { kind: "value", commands: ["rules"] },
|
|
70
|
+
status: { kind: "value", commands: ["sessions"] },
|
|
71
|
+
remove: { kind: "boolean", commands: ["sync"] }
|
|
60
72
|
};
|
|
61
73
|
export class ArgError extends Error {
|
|
62
74
|
}
|
|
@@ -126,6 +138,10 @@ export function parseArgs(argv) {
|
|
|
126
138
|
}
|
|
127
139
|
else {
|
|
128
140
|
positionals.push(raw);
|
|
141
|
+
// `passport exec railway up --service api`: everything after the CLI's
|
|
142
|
+
// name belongs to that CLI, flags included.
|
|
143
|
+
if (command === "exec")
|
|
144
|
+
positionalOnly = true;
|
|
129
145
|
}
|
|
130
146
|
}
|
|
131
147
|
command ??= "help";
|
|
@@ -160,6 +176,11 @@ function validateShape(command, positionals) {
|
|
|
160
176
|
discover: 0,
|
|
161
177
|
scan: 0,
|
|
162
178
|
hook: 1,
|
|
179
|
+
wait: 1,
|
|
180
|
+
rules: 2,
|
|
181
|
+
sessions: 0,
|
|
182
|
+
sync: 0,
|
|
183
|
+
keys: 2,
|
|
163
184
|
setup: 3,
|
|
164
185
|
session: 0,
|
|
165
186
|
access: 2,
|
|
@@ -167,9 +188,24 @@ function validateShape(command, positionals) {
|
|
|
167
188
|
help: 1,
|
|
168
189
|
version: 0
|
|
169
190
|
};
|
|
170
|
-
const minimum = {
|
|
191
|
+
const minimum = {
|
|
192
|
+
describe: 1,
|
|
193
|
+
run: 1,
|
|
194
|
+
use: 1,
|
|
195
|
+
completion: 1,
|
|
196
|
+
wait: 1,
|
|
197
|
+
rules: 1,
|
|
198
|
+
exec: 1
|
|
199
|
+
};
|
|
200
|
+
const needs = {
|
|
201
|
+
run: "a tool name",
|
|
202
|
+
completion: "bash, zsh, or fish",
|
|
203
|
+
wait: "an approval id",
|
|
204
|
+
rules: 'test "<command>"',
|
|
205
|
+
exec: "a command, like passport exec -- railway up"
|
|
206
|
+
};
|
|
171
207
|
if (positionals.length < (minimum[command] ?? 0)) {
|
|
172
|
-
throw new ArgError(`${command} requires ${command
|
|
208
|
+
throw new ArgError(`${command} requires ${needs[command] ?? "a name"}.`);
|
|
173
209
|
}
|
|
174
210
|
const cap = max[command];
|
|
175
211
|
if (cap !== undefined && positionals.length > cap)
|