passport-bridge 0.16.13 → 0.16.14
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 +15 -15
- package/dist/bridgeExchange.d.ts +7 -1
- package/dist/bridgeExchange.js +11 -2
- package/dist/cli.js +3 -1
- package/dist/cliActions.js +37 -18
- package/dist/cliArgs.js +14 -9
- package/dist/cliAutopilot.js +35 -14
- package/dist/cliAutopilotPolicy.d.ts +10 -0
- package/dist/cliAutopilotPolicy.js +28 -0
- package/dist/cliConnect.js +7 -6
- package/dist/cliDeadline.js +2 -1
- package/dist/cliEnv.js +5 -4
- package/dist/cliExec.js +13 -5
- package/dist/cliGuardState.d.ts +2 -0
- package/dist/cliGuardState.js +5 -1
- package/dist/cliHelp.d.ts +5 -4
- package/dist/cliHelp.js +2 -27
- package/dist/cliHook.js +6 -2
- package/dist/cliHookGuard.js +2 -2
- package/dist/cliHookInstall.d.ts +3 -0
- package/dist/cliHookInstall.js +17 -7
- package/dist/cliHookStatus.d.ts +2 -1
- package/dist/cliHookStatus.js +26 -17
- package/dist/cliInit.js +5 -3
- package/dist/cliKeys.d.ts +3 -0
- package/dist/cliKeys.js +59 -77
- package/dist/cliKeysShim.js +7 -5
- package/dist/cliLogin.js +44 -24
- package/dist/cliLogout.js +23 -7
- package/dist/cliMain.js +48 -20
- package/dist/cliOffline.d.ts +2 -2
- package/dist/cliOffline.js +31 -8
- package/dist/cliOutput.js +72 -42
- package/dist/cliReady.d.ts +2 -1
- package/dist/cliReady.js +9 -6
- package/dist/cliResult.js +1 -1
- package/dist/cliScan.js +10 -28
- package/dist/cliSessions.d.ts +3 -2
- package/dist/cliSessions.js +19 -17
- package/dist/cliSetup.js +6 -4
- package/dist/cliSetupLock.js +1 -0
- package/dist/cliSetupOrg.js +7 -5
- package/dist/cliStatus.d.ts +2 -4
- package/dist/cliStatus.js +55 -60
- package/dist/cliSuggest.d.ts +3 -2
- package/dist/cliSuggest.js +19 -6
- package/dist/cliSupport.d.ts +1 -1
- package/dist/cliSupport.js +3 -7
- package/dist/cliSync.js +2 -0
- package/dist/cliUndo.d.ts +3 -1
- package/dist/cliUndo.js +14 -11
- package/dist/cliWait.d.ts +3 -2
- package/dist/cliWait.js +10 -18
- package/dist/doctor.d.ts +4 -1
- package/dist/doctor.js +43 -24
- package/dist/execNoKey.d.ts +1 -1
- package/dist/execNoKey.js +3 -2
- package/dist/execShims.js +2 -2
- package/dist/hookFastPath.js +1 -0
- package/dist/initAutopilotStep.js +5 -4
- package/dist/initInstall.js +4 -3
- package/dist/initKeysStep.js +1 -1
- package/dist/initLocalSteps.js +4 -2
- package/dist/initOutro.d.ts +1 -3
- package/dist/initOutro.js +7 -15
- package/dist/initPlan.js +6 -6
- package/dist/initUi.d.ts +2 -4
- package/dist/initUi.js +8 -17
- package/dist/keysLocal.js +3 -3
- package/dist/keysSecret.d.ts +6 -0
- package/dist/keysSecret.js +43 -0
- package/dist/launcherFastPath.js +1 -0
- package/dist/loginFlow.d.ts +1 -1
- package/dist/loginFlow.js +4 -4
- package/dist/pathLines.d.ts +1 -0
- package/dist/pathLines.js +23 -0
- package/dist/pluginPin.d.ts +1 -1
- package/dist/pluginPin.js +1 -1
- package/dist/plural.d.ts +10 -0
- package/dist/plural.js +14 -0
- package/dist/term.d.ts +49 -5
- package/dist/term.js +200 -26
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/waitingLine.js +2 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,7 +37,7 @@ passport run github_search_issues '{"query":"SSO"}'
|
|
|
37
37
|
|
|
38
38
|
- First time? Bare `passport login` opens `/cli` in your browser. Sign in with Google, GitHub, or an emailed code, then connect a workspace you belong to or create one. No workspace id needed.
|
|
39
39
|
- One screen every time: `Code: HJKT-WQRM`, the pre-filled `Link:`, and `Check the code matches the one in your browser before you approve.` Nothing connects until you click Connect. It ends `Signed in as Erin Park to Acme.`; `--verbose` adds the profile name and where it's saved.
|
|
40
|
-
- Already signed in? On a terminal, `passport login` asks `Already signed in as Erin Park to Acme. Switch? [y/N]`. Enter keeps you signed in; `--switch` skips the question and lets the browser pick again. A sign-in that stopped working just signs in again
|
|
40
|
+
- Already signed in? On a terminal, `passport login` asks `Already signed in as Erin Park to Acme. Switch? [y/N]`. Enter keeps you signed in; `--switch` skips the question and lets the browser pick again. A sign-in that stopped working just signs in again; when Passport can't confirm the current one, login says `Couldn't confirm your current sign-in, so signing in again.`
|
|
41
41
|
- Re-signing in? Bare `passport login` reuses the workspace of the active profile, the sole CLI profile, or the one workspace all saved profiles share. With several workspaces saved it lists them and asks for `--workspace`.
|
|
42
42
|
- `--workspace ws_example` takes the same browser sign-in straight to that workspace, and only that workspace is accepted. Self-hosted: add `--cloud https://passport.example.com` (origin only). A server without browser sign-in falls back to its device flow when the workspace is known, else asks for `--workspace`.
|
|
43
43
|
- Without a terminal (an agent's shell, CI) or with `--json`, login is two steps, like `stripe login --non-interactive`: it prints `{status:"pending", verification_url, code, next_step, login_id}` and exits; once the code is approved in the browser, run `next_step` (`passport login --complete <login_id>`) to save the profile. The poll secret stays in an owner-only file under `~/.passport/login-pending/`.
|
|
@@ -54,8 +54,8 @@ passport run github_search_issues '{"query":"SSO"}'
|
|
|
54
54
|
| `login` | Browser sign-in or sign-up (or device sign-in with `--workspace`); saves a rotating CLI credential and makes the profile active. |
|
|
55
55
|
| `logout` | Revoke the credential and always remove the local profile (warns if revocation fails). |
|
|
56
56
|
| `profiles` / `use <name>` | List stored profiles / select the active one. Offline. |
|
|
57
|
-
| `status` |
|
|
58
|
-
| `doctor` | Check Node,
|
|
57
|
+
| `status` | Your setup on one screen: you, this computer, each agent's guard and its fix; Autopilot; apps; keys in Passport; this folder's environments; the CLI version. |
|
|
58
|
+
| `doctor` | Check Node, how your sign-in is stored, the server, your sign-in, and that this CLI and the server match. Exit 1 on a failed check, 2 when not signed in. |
|
|
59
59
|
| `ready` | Readiness preflight for automation; gate on its `ready` field and exit code. |
|
|
60
60
|
| `search [query] [--app <key>]` | Search permitted tools. Empty query lists the full catalog. |
|
|
61
61
|
| `describe <tool>` | One exact definition with its full parameter schema. |
|
|
@@ -132,26 +132,26 @@ npx passport-bridge@latest init --yes --move-keys # also move CLI keys into Pas
|
|
|
132
132
|
npx passport-bridge@latest init --yes --json # one summary object with each step's status and the plan
|
|
133
133
|
```
|
|
134
134
|
|
|
135
|
-
Plan, then apply. Init scans and signs in, then reads every step below without changing anything and shows one plan: **
|
|
135
|
+
Plan, then apply. Init scans and signs in, then reads every step below without changing anything and shows one plan: **Plan** (what the recommended setup changes), **Edits** (every file it edits, each backed up first), **Done** (already set up), **Kept** (not changed, with how to change it later), and **You do**, then the Autopilot presets and **Where** (environments). Labels sit in one column, at least two spaces from their text. One question follows: `Use the recommended setup? (n to choose step by step) [Y/n]`. Enter applies the plan; `n` walks each step with its own question. When nothing is missing it says `Nothing to change.` and asks nothing. It ends with a ✓ list of what's true now and what's left for you, and one next command (the `PATH` line, `passport connect --wait 300`, a first thing to ask your agent, or `passport status`).
|
|
136
136
|
|
|
137
137
|
Eight steps, each reusing the command that owns it:
|
|
138
138
|
|
|
139
139
|
1. **Scan**: the same local scan as `passport scan`, as one summary line (`--verbose` prints the table).
|
|
140
140
|
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`.
|
|
141
141
|
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); with `--yes` or without a terminal it prints the page, adds `passport connect --wait 300` to `next`, and moves on.
|
|
142
|
-
4. **Keys**: the recommended setup keeps them; the plan says `Your
|
|
143
|
-
5. **
|
|
144
|
-
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: on a terminal init copies the URL and says `Claude Desktop: Settings → Connectors → Add custom connector
|
|
142
|
+
4. **Keys**: the recommended setup keeps them; the plan says `Your GitHub and Railway keys stay on this computer. Move them any time.` with `Run: passport keys move` under it. Step by step asks the same question as `passport keys move` for each: `Move your Railway account token into Passport and sign the Railway CLI out on this computer? [y/N]` (a long question wraps; `[y/N]` stays on its last line). Enter keeps the key here; an answer that isn't y or n asks again (`Type y or n.`). Add `--move-keys` to move every key it finds without asking; the closing list then says which (`Moved your Railway key into Passport and signed that CLI out here`) and, once per moved key, where to rotate the old one (`Rotate the old Railway key, since copies may exist elsewhere: https://railway.com/account/tokens`). When Passport already holds a different key for that CLI, an interactive run asks `Passport already holds a different Railway key. Replace it with this computer's? Every agent that uses it switches to this one.` then `Type railway to confirm, or press Enter to cancel:`: only the name replaces it and signs the CLI out, keeping links; anything else prints `Kept the key in Passport. This computer's Railway CLI stays signed in.` `--yes` never replaces a key. Quiet when there's nothing to move.
|
|
143
|
+
5. **Where** (environments): the environments Passport has placed for your apps, grouped by kind (`Production production (Railway), production (Vercel)`), one row per resource. Anything Passport can't place counts as Production and is listed once: `Treated as Production until placed: blue (Railway). Change it in Rules.` A resource named for its kind (`production` in Production) is never called assumed. This folder's links follow (`This folder: Railway production (linked), counted as Production`). With no app connected yet it says they appear once one is.
|
|
144
|
+
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: on a terminal init copies the URL and says `Claude Desktop: paste the copied URL in Settings → Connectors → Add custom connector`; without one it names the URL.
|
|
145
145
|
7. **Guard**: (step by step asks `Check each shell command in <agents> before it runs? [Y/n]`) runs `passport hook install --guard` for Claude Code, Codex, and Cursor (in Codex, a command your rules ask about is blocked with how to approve it, since Codex can't show Passport's questions), 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.
|
|
146
146
|
8. **Autopilot**: how much agents can do on their own, per environment:
|
|
147
147
|
|
|
148
148
|
```
|
|
149
|
-
Autopilot
|
|
150
|
-
|
|
151
|
-
|
|
149
|
+
Autopilot Production Careful reads run, changes ask
|
|
150
|
+
Staging Balanced reads and changes run, deletes ask
|
|
151
|
+
Development Hands-off everything except irreversible runs
|
|
152
152
|
```
|
|
153
153
|
|
|
154
|
-
The plan shows them once. Step by step asks one compact question per environment where a choice is left (`Staging: 1 Careful 2 Balanced 3 Hands-off [2]`, Enter keeps it); the recommended setup and `--yes` keep 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 lists them under
|
|
154
|
+
The plan shows them once. Step by step asks one compact question per environment where a choice is left (`Staging: 1 Careful 2 Balanced 3 Hands-off [2]`, Enter keeps it); the recommended setup and `--yes` keep 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 lists them under Done without asking. The closing list says what will ask: `Autopilot on: asks only for Production changes, deletes outside Development, and irreversible actions`. A server without Autopilot gets the earlier Safety step instead.
|
|
155
155
|
|
|
156
156
|
What changes on disk, and how to undo it:
|
|
157
157
|
|
|
@@ -220,7 +220,7 @@ Two hooks per agent. `passport hook` runs after each shell command and records t
|
|
|
220
220
|
|
|
221
221
|
- **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`).
|
|
222
222
|
- **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.
|
|
223
|
-
- Each reason names its cause in one line: `Passport: railway redeploy changes Production. Approve to run it.`, or `Blocked by
|
|
223
|
+
- Each reason names its cause in one line: `Passport: railway redeploy changes Production. Approve to run it.`, or `Blocked by a team rule: no deletes in Production. Ask an admin to run it, or request an exception in Passport.` (a cause that isn't a rule reads `Blocked by Passport: <cause>`).
|
|
224
224
|
|
|
225
225
|
**Speed.** Hooks must never slow agents down. The launcher `$PASSPORT_HOME/cli/bin/passport` (written by `src/initInstall.ts`) answers plain reads and local dev commands in POSIX sh without starting Node (`src/launcherFastPath.ts`): `ls`, `cat`, `rg`, `git status`, `cargo check`, and the rest of a fixed list, joined only by single pipes, with relative paths that stay in the folder and pass through no symlink or hidden file. It answers only while `cli-policy/fastpath.ok` is armed: a full guard run arms it for five minutes when the cached rules give those commands exactly the launcher's answer (`src/hookFastPath.ts`), and a policy or profile change removes it. Each answer appends one line (agent, session id, program names, never an argument) to `cli-policy/fastpath.spool`, which the next full run counts. Anything else, or any doubt, starts Node with the same input, through `dist/hookMain.js`, which loads only the guard. `src/launcherFastPath.test.ts` holds the launcher to the full guard's exact answer across both corpora and generated variants. `PASSPORT_HOOK_FAST=0` turns it off. The after-hook and the guard's own report never wait on the network: they queue to `$PASSPORT_HOME/hook-outbox/` and a detached `passport hook flush` sends them within the budget (`src/hookOutbox.ts`). Each guard run records its timings (numbers only, `src/cliSpeed.ts`), sent every five minutes with the answered counts. `npm run bench:guard` times it all on the compiled CLI.
|
|
226
226
|
|
|
@@ -253,7 +253,7 @@ An ask becomes one Activity row. In Claude Code, with the audit hook registered,
|
|
|
253
253
|
- 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 (an ask fails the hook open, and its allow rewrites commands), so an ask is a deny there that says why (`Codex can't ask from a hook, so Passport blocked it. Approve it in Passport or run it yourself.`), recorded as a block. With a member profile and Autopilot, it goes to Passport like an unattended ask: an approval request, then the waiting line. Trust the hooks in Codex's `/hooks`.
|
|
254
254
|
- 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.
|
|
255
255
|
|
|
256
|
-
**Guard health** (`src/cliGuardHealth.ts`, states and fixes in `src/cliGuardState.ts`, a checked copy of `shared/guardContract.ts`). `passport hook status` and `passport status` show each agent's guard in the web's words, **On**, **Off**, **Outdated**, **Not trusted**, or **Locked**, and each problem's fix: `passport hook install --
|
|
256
|
+
**Guard health** (`src/cliGuardHealth.ts`, states and fixes in `src/cliGuardState.ts`, a checked copy of `shared/guardContract.ts`). `passport hook status` and `passport status` show each agent's guard in the web's words, **On**, **Off**, **Outdated**, **Not trusted**, or **Locked**, and each problem's fix (on a terminal the command goes on its own `Run:` line): `passport hook install --agent <agent> --guard --apply`, `npx passport-bridge@latest init`, or `Open Codex → /hooks and trust Passport's hooks.` At most once a day (`$PASSPORT_HOME/guard/.<profile>.heartbeat`) the CLI sends `POST /api/my/guard-health` with `{cliVersion, launcherTarget?, clients: [{client, present, mode, guard, plugin, codexTrust?, locked?, disabledEnv?}]}`: flags only, never a command, path, or value. It goes from a guard run with at least 300 ms of its budget left (a hook's first one waits a day), from `passport exec`, and from `passport status`. Codex trust (`src/cliCodexTrust.ts`) compares `trusted_hash` in `~/.codex/config.toml` `[hooks.state."<hooks.json>:pre_tool_use:<group>:<handler>"]` with Codex's own hash of Passport's guard entry: SHA-256 of the sorted-key JSON of `{event_name, matcher?, hooks: [{type, command, timeout (600 when unset), async, statusMessage?, additionalContextLimit? (when not 2500)}]}`, as in openai/codex `hook_hash`/`version_for_toml`, checked against codex-cli 0.146.0's `hooks/list`. Missing is **Not trusted**, a different hash is **Not trusted** (modified), `enabled = false` is **Off**. **Locked** means managed settings hold Passport's guard: `/Library/Application Support/ClaudeCode/managed-settings.json` (and `managed-settings.d/`), `/etc/claude-code/…`, `/etc/codex/requirements.toml`, `/Library/Application Support/Cursor/hooks.json`, or `/etc/cursor/hooks.json` (`PASSPORT_MANAGED_ROOT` points tests elsewhere).
|
|
257
257
|
|
|
258
258
|
**Coverage** (`src/cliSeen.ts`). The guard counts every command it saw, per agent per day, one character per command in `$PASSPORT_HOME/seen/<profile>.<agent>.<day>.log` (an app's action, not checked, or neither), and Cursor's imported copy of Claude Code's hook doesn't count twice. Counts go in their own batches, at most every five minutes, as `seen: {batch, day, count, governed, opaque}` on `POST /api/my/cli-activity`, never inside a report that can expire. `passport status` prints `Checked: 94% of commands Passport saw this week`.
|
|
259
259
|
|
|
@@ -281,7 +281,7 @@ passport actions sync # propose this repository's .passport/actions.toml
|
|
|
281
281
|
- `env` lists where commands in this folder land, read the way each vendor's own CLI reads it (`src/envResolve.ts`; order: flag, the folder's link, the vendor's default, the workspace's saved mapping, the whole-word naming rule, else Production). Link readers: `src/envLinksHosting.ts` (Railway `~/.railway/config.json`, Vercel `.vercel/project.json` / `repo.json`, Supabase `supabase/.temp/project-ref`, Wrangler config, Netlify `.netlify/state.json`, Firebase `.firebaserc` + configstore, Convex `CONVEX_DEPLOYMENT`, Neon `.neon`), `src/envLinksCloud.ts` (Fly, Heroku git remotes, kubeconfig, AWS profile, gcloud configuration, Terraform workspace, Stripe key mode), and `src/envDatabase.ts` (database URLs: only `DATABASE_URL`, `DIRECT_URL`, `POSTGRES_URL*`, `DATABASE_URL_UNPOOLED`, reduced to a host-derived key; the URL, user, and password never leave the function). Files are read fresh for every command, size-capped, and a link file symlinked out of the project is ignored (`src/envLinkFs.ts`). For a placed id its mapping decides, and a different name in the link file is treated as a rename (sent as the new label, which the server stores). A name in a link file never loosens anything: an unplaced id is named only by a label the server confirmed through the connected app (`resources[].confirmed`), which the naming rule then reads (`source: "name"`, shown as `Staging (from its name)`); without one, or when it says nothing, it is assumed Production. The table keeps its columns when every row fits the terminal and stacks each row otherwise. Findings to a server that sends `resources` in cli-policy v2 carry `{kind, source, resourceKey?, label?, platform?, flag?, via}`. `env set` calls `PUT /api/my/environments/:platform/:key`; members may only say Production.
|
|
282
282
|
|
|
283
283
|
- `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.
|
|
284
|
-
- `wait` long-polls `GET /api/my/approvals/<id>/wait`, after a short first look that names who decides.
|
|
284
|
+
- `wait` long-polls `GET /api/my/approvals/<id>/wait`, after a short first look that names who decides. Once Passport says the request is still pending (never for one that doesn't exist or is already decided), on a terminal it prints the approval link and one live line (`Waiting for Erin · 1:32 left`); piped, `Waiting for a decision on <id> (up to 100 seconds).` and `Open in Passport: <url>`. Ctrl-C exits 4 with `The request is still open. Keep waiting any time.` and `Run: passport wait <id>`. 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`.
|
|
285
285
|
- `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.
|
|
286
286
|
- `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.
|
|
287
287
|
- `status` is one screen, like `gh auth status`, with a label per row (`You` with the name you signed in as, `Computer`, `Guard`, `Autopilot`, `Apps`, `Keys`, `Shims`, `This folder`, `Allowlists`, `CLI`); under 60 columns each label gets its own row, and piped it never wraps. `Guard` lists each agent's guard (`✓ Claude Code On`, `! Codex Not trusted`) with its fix on the line under it, the coverage line, and sends the daily guard report when due. It also adds today's speed line, `Passport added 0.3 s and asked you twice today. 412 actions ran on their own.` (across your computers when the server keeps speed numbers, else `(this computer)`), and `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. Under the presets, one line per exception that lets something run your presets would ask about, in the web's words: `! 1 exception: deletes run in Production without asking, even without a backup.` 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`.
|
|
@@ -306,7 +306,7 @@ passport keys shim # the CLIs that run through Passport when you type
|
|
|
306
306
|
- After a move, `keys move` remembers where each removed key was in `$PASSPORT_HOME/keys-moved.json` (vendor, `~/…` location, file, field names, size, modified time; never a value or hash). With the daily guard report, files that changed are read again; a key that's back is reported as `reappeared: [vendor]` on `POST /api/my/keys/report`, so the key reads "Back on <computer>" in Apps with the fix `passport keys move`. Kept keys are never listed. The report's computer is the CLI's own sign-in (its Device); the name it sends stays for older servers.
|
|
307
307
|
- `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]` (Enter keeps it; `--yes` moves them all; `keys move <cli>` only that CLI's), 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. A different key than the one already in Passport is replaced only when the person types the CLI's name at a terminal (`Type railway to confirm, or press Enter to cancel:`); no flag does it, so an agent's script can never swap a key. The CLI then names the key it replaces (`replace: <keyId>` on `POST /api/my/keys`). The server alerts the owner and admins with an Undo, records it in the audit trail, and keeps the old value encrypted for seven days (`POST /api/my/keys/:id/restore` from the browser, or the alert). Without a person at a terminal (`--yes`, no terminal), both keys stay, and the line says `Replacing a key in Passport needs you at a terminal. Run passport keys move railway yourself.` The scan report sent afterwards carries provider counts only.
|
|
308
308
|
- `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`).
|
|
309
|
-
- 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. While it waits, the approval link prints at once and, on a terminal, one live line counts down (`Waiting for Erin · 1:32 left`); piped, it prints the waiting line and `Open in Passport: <url>`. Ctrl-C exits 4: `The request is still open.
|
|
309
|
+
- 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. While it waits, the approval link prints at once and, on a terminal, one live line counts down (`Waiting for Erin · 1:32 left`); piped, it prints the waiting line and `Open in Passport: <url>`. Ctrl-C exits 4: `The request is still open. Keep waiting, then run the command again.` and `Run: passport wait <id>`. An approval is used once. Blocked or declined: exit 5. A decline answers the same command for ten minutes, said with who and when: `Declined 2 minutes ago by Erin: Not during the freeze.` and `Run with --ask-again to request again.`; `--ask-again` opens a new request. No key, or it stopped working: exit 3 (`No Railway key in Passport yet. Add a Railway key in Passport → Apps.`, or `Your Railway key in Passport stopped working. Update it in Apps.`). When this computer still has the Railway CLI's own sign-in, the no-key line is `No Railway key in Passport yet, but this computer has one.` with `Run: passport keys move railway` instead (read here; Passport never sees this computer's files). Offline: exit 1, nothing runs, and exec never uses a key on this computer instead. A team that requires the guard refuses exec for an agent whose computer hasn't reported its guard On in 48 hours: exit 5 with `Blocked by Passport: guard required…` and the fix.
|
|
310
310
|
- 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.
|
|
311
311
|
- 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.
|
|
312
312
|
- Backups: for `gh issue close`, `gh pr close`, `gh api -X DELETE` of a branch, `vercel env rm`, `vercel rollback`, and `vercel promote`, exec also sends the ids Passport needs to take a backup first (repo and number or branch; the linked Vercel project and variable name from `.vercel/project.json`), never a value. After the run it prints `Backup taken. Undo within 7 days: passport undo <action-id>`, or `No backup: <reason>` for a delete it couldn't back up.
|
package/dist/bridgeExchange.d.ts
CHANGED
|
@@ -9,7 +9,13 @@ export declare const TENANT_FLIP_MESSAGE = "This computer's Passport sign-in now
|
|
|
9
9
|
* (superseded by a newer rotation that this process cannot see on disk). */
|
|
10
10
|
export declare class BridgeCredentialError extends Error {
|
|
11
11
|
readonly status: 401 | 409;
|
|
12
|
-
|
|
12
|
+
readonly phase: "exchange" | "request";
|
|
13
|
+
/**
|
|
14
|
+
* `request`: the sign-in still works (a fresh token was issued) but
|
|
15
|
+
* Passport refused this one request with it. `exchange`: the sign-in
|
|
16
|
+
* itself was refused, so it expired or was revoked.
|
|
17
|
+
*/
|
|
18
|
+
constructor(status: 401 | 409, phase?: "exchange" | "request");
|
|
13
19
|
}
|
|
14
20
|
export declare function isBridgeCredentialError(error: unknown): error is BridgeCredentialError;
|
|
15
21
|
/** How long a rotating exchange keeps retrying an ambiguous failure (a
|
package/dist/bridgeExchange.js
CHANGED
|
@@ -23,9 +23,16 @@ const ROTATION_PERSISTENCE_MESSAGE = "Passport rotated the credential, but durab
|
|
|
23
23
|
* (superseded by a newer rotation that this process cannot see on disk). */
|
|
24
24
|
export class BridgeCredentialError extends Error {
|
|
25
25
|
status;
|
|
26
|
-
|
|
26
|
+
phase;
|
|
27
|
+
/**
|
|
28
|
+
* `request`: the sign-in still works (a fresh token was issued) but
|
|
29
|
+
* Passport refused this one request with it. `exchange`: the sign-in
|
|
30
|
+
* itself was refused, so it expired or was revoked.
|
|
31
|
+
*/
|
|
32
|
+
constructor(status, phase = "exchange") {
|
|
27
33
|
super(`token exchange failed (${status}); reconnect this agent from the Passport web app (or run \`passport-bridge login\`)`);
|
|
28
34
|
this.status = status;
|
|
35
|
+
this.phase = phase;
|
|
29
36
|
this.name = "BridgeCredentialError";
|
|
30
37
|
}
|
|
31
38
|
}
|
|
@@ -485,7 +492,9 @@ export class TokenManager {
|
|
|
485
492
|
res = await this.fetcher(input, apply(await this.accessToken(true)));
|
|
486
493
|
if (res.status === 401) {
|
|
487
494
|
await res.body?.cancel().catch(() => undefined);
|
|
488
|
-
|
|
495
|
+
// A fresh token was just issued, so the sign-in works: Passport
|
|
496
|
+
// refused this request, not the sign-in.
|
|
497
|
+
throw new BridgeCredentialError(401, "request");
|
|
489
498
|
}
|
|
490
499
|
}
|
|
491
500
|
return res;
|
package/dist/cli.js
CHANGED
|
@@ -70,6 +70,7 @@ async function main() {
|
|
|
70
70
|
process.exit(1);
|
|
71
71
|
}
|
|
72
72
|
function help() {
|
|
73
|
+
// copy-style-allow double-space: help columns line up
|
|
73
74
|
process.stdout.write(`Passport bridge ${VERSION}
|
|
74
75
|
|
|
75
76
|
Usage: passport-bridge [command] [options]
|
|
@@ -354,7 +355,8 @@ async function login() {
|
|
|
354
355
|
});
|
|
355
356
|
out("");
|
|
356
357
|
out(` ✓ Signed in. Saved profile "${profile}" to ${credsPath()}`);
|
|
357
|
-
out(
|
|
358
|
+
out(" Now point your agent at it:");
|
|
359
|
+
out(` passport-bridge serve --profile ${profile}`);
|
|
358
360
|
out("");
|
|
359
361
|
}
|
|
360
362
|
async function status() {
|
package/dist/cliActions.js
CHANGED
|
@@ -24,12 +24,16 @@ import { localMachine, NODE_FS } from "./cliHookLocal.js";
|
|
|
24
24
|
import { lookupOpaqueId, normalizeRemote, originUrl, remoteFingerprint, sha256 } from "./cliScriptRead.js";
|
|
25
25
|
import { linesDigestInput, makeLines, packageLines, parseRepoActions } from "./cliScriptText.js";
|
|
26
26
|
import { unknownSubcommand } from "./cliSuggest.js";
|
|
27
|
-
import {
|
|
27
|
+
import { joinParts, termOf } from "./term.js";
|
|
28
28
|
import { callerFrom, failure, resolveCliAuth, safeApiError, timeoutMs } from "./cliSupport.js";
|
|
29
29
|
const ENVIRONMENTS = new Set(["production", "staging", "development"]);
|
|
30
30
|
const CLASSES = new Set(["read", "change", "delete", "irreversible"]);
|
|
31
31
|
const RUNNERS = new Set(["make", "npm", "pnpm", "yarn"]);
|
|
32
32
|
const ENV_WORD = { production: "Production", staging: "Staging", development: "Development" };
|
|
33
|
+
/** An action class in sentence case, as `rules test` and the web say it: "Change". */
|
|
34
|
+
function classWord(actionClass) {
|
|
35
|
+
return actionClass ? `${actionClass.charAt(0).toUpperCase()}${actionClass.slice(1)}` : "";
|
|
36
|
+
}
|
|
33
37
|
function api(args, runtime, deps) {
|
|
34
38
|
if (deps.api)
|
|
35
39
|
return deps.api;
|
|
@@ -118,7 +122,7 @@ async function post(client, body, args, runtime) {
|
|
|
118
122
|
function line(action, fallback) {
|
|
119
123
|
const label = action.label ?? fallback;
|
|
120
124
|
const where = action.environment ? (ENV_WORD[action.environment] ?? action.environment) : "";
|
|
121
|
-
const what = action.actionClass
|
|
125
|
+
const what = classWord(action.actionClass);
|
|
122
126
|
return action.status === "proposed"
|
|
123
127
|
? `${label}: proposed (${what} in ${where}). An admin approves it in Passport Rules › Environments.`
|
|
124
128
|
: `${label}: ${what} in ${where}. Passport checks it from now on.`;
|
|
@@ -126,11 +130,25 @@ function line(action, fallback) {
|
|
|
126
130
|
function classified(args) {
|
|
127
131
|
const environment = value(args, "environment")?.toLowerCase() ?? "";
|
|
128
132
|
const actionClass = value(args, "class")?.toLowerCase() ?? "";
|
|
129
|
-
|
|
130
|
-
|
|
133
|
+
// Say everything that's missing or wrong at once, naming a bad value.
|
|
134
|
+
const shown = (raw) => raw.replace(/[^\w-]/g, "").slice(0, 30);
|
|
135
|
+
const problems = [];
|
|
136
|
+
const missing = [];
|
|
137
|
+
if (!environment)
|
|
138
|
+
missing.push("--environment production|staging|development");
|
|
139
|
+
else if (!ENVIRONMENTS.has(environment))
|
|
140
|
+
problems.push(`--environment takes production, staging, or development, not ${shown(environment)}.`);
|
|
141
|
+
if (!actionClass)
|
|
142
|
+
missing.push("--class read|change|delete|irreversible");
|
|
143
|
+
else if (!CLASSES.has(actionClass))
|
|
144
|
+
problems.push(`--class takes read, change, delete, or irreversible, not ${shown(actionClass)}.`);
|
|
145
|
+
// What's missing, one option a line: each is long, and never splits.
|
|
146
|
+
if (missing.length) {
|
|
147
|
+
const what = [!environment ? "where it acts" : "", !actionClass ? "what it does" : ""].filter(Boolean);
|
|
148
|
+
problems.push([`Add ${what.join(" and ")}:`, ...missing.map((flag) => ` ${flag}`)].join("\n"));
|
|
131
149
|
}
|
|
132
|
-
if (
|
|
133
|
-
return failure(
|
|
150
|
+
if (problems.length)
|
|
151
|
+
return failure(problems.join("\n"), 6, "usage");
|
|
134
152
|
return { environment, class: actionClass };
|
|
135
153
|
}
|
|
136
154
|
async function add(args, runtime, deps) {
|
|
@@ -198,23 +216,24 @@ async function list(args, runtime, deps) {
|
|
|
198
216
|
return failure(await safeApiError(response, "Passport couldn't list them."), 1, "server");
|
|
199
217
|
const body = (await readBoundedJson(response).catch(() => ({})));
|
|
200
218
|
const actions = body.projectActions ?? [];
|
|
201
|
-
//
|
|
202
|
-
//
|
|
203
|
-
|
|
219
|
+
// Every script laid out the same way, however many there are: its name,
|
|
220
|
+
// then where it acts, its class, its repository, and notes, broken only
|
|
221
|
+
// between those parts.
|
|
222
|
+
const width = termOf((runtime.stdout ?? {}), runtime.env).width;
|
|
223
|
+
const lines = actions.flatMap((action) => [
|
|
204
224
|
action.label ?? "script",
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
225
|
+
...joinParts([
|
|
226
|
+
action.environment ? (ENV_WORD[action.environment] ?? action.environment) : "",
|
|
227
|
+
classWord(action.actionClass),
|
|
228
|
+
action.repoName ?? "Any repository",
|
|
209
229
|
...(action.setByName ? [`Set by ${action.setByName}`] : []),
|
|
210
230
|
...(action.status === "proposed" ? ["Proposed"] : []),
|
|
211
231
|
...(action.changedAt ? ["Changed since set"] : [])
|
|
212
|
-
]
|
|
232
|
+
], width, " ")
|
|
213
233
|
]);
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
: "No project scripts yet. Add one: passport actions add <script> --environment <kind> --class <class>";
|
|
234
|
+
const human = lines.length
|
|
235
|
+
? lines.join("\n")
|
|
236
|
+
: "No project scripts yet. Tell Passport what one does.\nRun: passport actions add <script> --environment <kind> --class <class>";
|
|
218
237
|
return { json: { actions }, human };
|
|
219
238
|
}
|
|
220
239
|
export async function actions(args, runtime, deps = {}) {
|
package/dist/cliArgs.js
CHANGED
|
@@ -68,7 +68,7 @@ const FLAGS = {
|
|
|
68
68
|
alias: { kind: "value", commands: ["connect"] },
|
|
69
69
|
open: { kind: "boolean", commands: ["connect"] },
|
|
70
70
|
out: { kind: "value", commands: ["resources", "prompts"] },
|
|
71
|
-
verbose: { kind: "boolean", commands: ["scan", "init", "exec", "login"] },
|
|
71
|
+
verbose: { kind: "boolean", commands: ["scan", "init", "exec", "login", "hook"] },
|
|
72
72
|
"no-masking": { kind: "boolean", commands: ["exec"] },
|
|
73
73
|
mask: { kind: "boolean", commands: ["exec"] },
|
|
74
74
|
"no-shim": { kind: "boolean", commands: ["keys"] },
|
|
@@ -110,7 +110,7 @@ function optionsFor(command) {
|
|
|
110
110
|
function unknownCommand(raw, help = false) {
|
|
111
111
|
const guess = closest(raw, COMMANDS);
|
|
112
112
|
const argv = guess ? ["passport", ...(help ? ["help"] : []), guess] : undefined;
|
|
113
|
-
return new ArgError(`Unknown command "${raw}". ${argv ? `Did you mean: ${argv.join(" ")}` : "
|
|
113
|
+
return new ArgError(`Unknown command "${raw}". ${argv ? `Did you mean: ${argv.join(" ")}` : "See every command with passport help."}`, argv);
|
|
114
114
|
}
|
|
115
115
|
function unknownOption(raw, command) {
|
|
116
116
|
const given = raw.startsWith("--") ? flagParts(raw).name : raw.replace(/^-+/, "");
|
|
@@ -119,7 +119,7 @@ function unknownOption(raw, command) {
|
|
|
119
119
|
return new ArgError(`Unknown option "${raw}". Did you mean: --${guess}`, command ? ["passport", command, `--${guess}`] : undefined);
|
|
120
120
|
}
|
|
121
121
|
const where = command && command !== "help" ? `passport help ${command}` : "passport help";
|
|
122
|
-
return new ArgError(`Unknown option "${raw}".
|
|
122
|
+
return new ArgError(`Unknown option "${raw}". See the options with ${where}.`);
|
|
123
123
|
}
|
|
124
124
|
function knownCommand(value) {
|
|
125
125
|
return COMMANDS.includes(value);
|
|
@@ -221,6 +221,9 @@ function settle(args) {
|
|
|
221
221
|
}
|
|
222
222
|
if (command === "help" && positionals[0] !== undefined && !knownCommand(positionals[0]))
|
|
223
223
|
throw unknownCommand(positionals[0], true);
|
|
224
|
+
// `help keys add` shows the page for keys, which covers its subcommands.
|
|
225
|
+
if (command === "help")
|
|
226
|
+
positionals.splice(1);
|
|
224
227
|
validateShape(command, positionals);
|
|
225
228
|
validateNumbers(values);
|
|
226
229
|
return { command, positionals, values, repeats, booleans };
|
|
@@ -266,14 +269,16 @@ function validateShape(command, positionals) {
|
|
|
266
269
|
exec: 1
|
|
267
270
|
};
|
|
268
271
|
const needs = {
|
|
269
|
-
run: "a tool name",
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
272
|
+
run: "run needs a tool name.",
|
|
273
|
+
describe: "describe needs a tool name.",
|
|
274
|
+
use: "use needs a profile name. See them with passport profiles.",
|
|
275
|
+
completion: "completion needs bash, zsh, or fish.",
|
|
276
|
+
wait: "wait needs an approval id.",
|
|
277
|
+
rules: 'Use: passport rules test "<command>"',
|
|
278
|
+
exec: "exec needs a command to run.\nUse: passport exec -- railway up"
|
|
274
279
|
};
|
|
275
280
|
if (positionals.length < (minimum[command] ?? 0)) {
|
|
276
|
-
throw new ArgError(`${command}
|
|
281
|
+
throw new ArgError(needs[command] ?? `${command} needs a name.`);
|
|
277
282
|
}
|
|
278
283
|
const cap = max[command];
|
|
279
284
|
if (cap !== undefined && positionals.length > cap)
|
package/dist/cliAutopilot.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import { guardStatus } from "./cliStatusGuard.js";
|
|
12
12
|
import { value } from "./cliArgs.js";
|
|
13
|
-
import { OTHER_APPS, PRESET_ROWS, rowLabel } from "./cliAutopilotPolicy.js";
|
|
13
|
+
import { OTHER_APPS, causeSentence, PRESET_ROWS, rowLabel } from "./cliAutopilotPolicy.js";
|
|
14
14
|
import { classifyLine, localMachine } from "./cliHookLocal.js";
|
|
15
15
|
import { ENV_KINDS, isEnvKind } from "./cliHookEnvironment.js";
|
|
16
16
|
import { decideGuard, guardLabel } from "./cliHookGuard.js";
|
|
@@ -22,11 +22,14 @@ export { actions } from "./cliActions.js";
|
|
|
22
22
|
import { looseningLines } from "./cliLoosening.js";
|
|
23
23
|
import { readCliPolicy } from "./cliPolicy.js";
|
|
24
24
|
import { failure, readBoundedJson, resolveCliAuth, timeoutMs } from "./cliSupport.js";
|
|
25
|
+
import { unknownSubcommand } from "./cliSuggest.js";
|
|
26
|
+
import { mark, termOf } from "./term.js";
|
|
25
27
|
export { api, json } from "./cliMemberCall.js";
|
|
26
28
|
export { wait } from "./cliWait.js";
|
|
27
29
|
import { api, text } from "./cliMemberCall.js";
|
|
28
30
|
// ---- passport rules test ----------------------------------------------------
|
|
29
31
|
const DECISION_WORDS = { allow: "Runs", ask: "Asks first", block: "Blocked" };
|
|
32
|
+
const DECISION_MARKS = { allow: "done", ask: "warn", block: "fail" };
|
|
30
33
|
const CLASS_WORDS = {
|
|
31
34
|
read: "Read",
|
|
32
35
|
change: "Change",
|
|
@@ -42,24 +45,29 @@ function ageText(ms) {
|
|
|
42
45
|
const hours = Math.round(minutes / 60);
|
|
43
46
|
return hours < 48 ? `${hours} h ago` : `${Math.round(hours / 24)} days ago`;
|
|
44
47
|
}
|
|
45
|
-
|
|
48
|
+
/** Each line of `text` under the command, or nothing. */
|
|
49
|
+
function indented(text) {
|
|
50
|
+
return text ? text.split("\n").map((line) => ` ${line}`) : [];
|
|
51
|
+
}
|
|
52
|
+
function ruleTestLines(term, label, result, source) {
|
|
46
53
|
if (result.decision === "none") {
|
|
47
54
|
return [
|
|
48
55
|
label,
|
|
49
56
|
" No decision: Passport doesn't decide this command, so your agent's own prompt applies.",
|
|
50
|
-
...(source
|
|
57
|
+
...indented(source)
|
|
51
58
|
];
|
|
52
59
|
}
|
|
53
|
-
const explanation = text(result.explanation) ??
|
|
60
|
+
const explanation = text(result.explanation) ??
|
|
61
|
+
`${result.cause ? causeSentence(result.decision, result.cause.label) : DECISION_WORDS[result.decision]}.`;
|
|
54
62
|
const environment = result.environment
|
|
55
63
|
? `${rowLabel(result.environment)}${result.environmentAssumed ? " (assumed)" : ""}`
|
|
56
64
|
: undefined;
|
|
57
65
|
return [
|
|
58
66
|
label,
|
|
59
|
-
` ${explanation}`,
|
|
67
|
+
` ${mark(term, DECISION_MARKS[result.decision])} ${explanation}`,
|
|
60
68
|
...(environment ? [` Environment: ${environment}`] : []),
|
|
61
69
|
...(result.actionClass ? [` Class: ${CLASS_WORDS[result.actionClass]}`] : []),
|
|
62
|
-
|
|
70
|
+
...indented(source)
|
|
63
71
|
];
|
|
64
72
|
}
|
|
65
73
|
/** Place every finding in the environment the person picked. */
|
|
@@ -121,16 +129,25 @@ async function askServer(body, args, runtime, deps) {
|
|
|
121
129
|
return null;
|
|
122
130
|
}
|
|
123
131
|
}
|
|
124
|
-
|
|
132
|
+
/** `rules test "<command>" [--environment <kind>]`, or a usage failure that
|
|
133
|
+
* suggests `test` for a typo. */
|
|
134
|
+
function ruleTestArgs(args) {
|
|
125
135
|
const [action, command] = args.positionals;
|
|
126
|
-
if (action !== "test"
|
|
136
|
+
if (action !== undefined && action !== "test") {
|
|
137
|
+
const unknown = unknownSubcommand("rules", action, ["test"]);
|
|
138
|
+
return failure(unknown.message, 6, "usage", unknown.next ? { next: unknown.next } : {});
|
|
139
|
+
}
|
|
140
|
+
if (!command?.trim()) {
|
|
127
141
|
return failure('Use: passport rules test "<command>" [--environment production|staging|development]', 6, "usage");
|
|
128
142
|
}
|
|
129
|
-
const
|
|
130
|
-
if (
|
|
143
|
+
const environment = value(args, "environment");
|
|
144
|
+
if (environment !== undefined && !isEnvKind(environment)) {
|
|
131
145
|
return failure("--environment must be production, staging, or development.", 6, "usage");
|
|
132
146
|
}
|
|
133
|
-
|
|
147
|
+
return { command, environment: environment };
|
|
148
|
+
}
|
|
149
|
+
export async function rules(args, runtime, deps = {}) {
|
|
150
|
+
const { command, environment } = ruleTestArgs(args);
|
|
134
151
|
// Paths are read where you run this, like the hook reads the agent's folder.
|
|
135
152
|
const machine = deps.machine ?? localMachine(process.cwd(), runtime.env);
|
|
136
153
|
const line = classifyLine(command, machine);
|
|
@@ -151,7 +168,9 @@ export async function rules(args, runtime, deps = {}) {
|
|
|
151
168
|
const result = { decision: "none" };
|
|
152
169
|
return {
|
|
153
170
|
json: { command: null, ...result },
|
|
154
|
-
human: ruleTestLines("This command", result, "")
|
|
171
|
+
human: ruleTestLines(termOf(runtime.stdout, runtime.env), "This command", result, "")
|
|
172
|
+
.filter(Boolean)
|
|
173
|
+
.join("\n")
|
|
155
174
|
};
|
|
156
175
|
}
|
|
157
176
|
const profile = (() => {
|
|
@@ -185,11 +204,13 @@ export async function rules(args, runtime, deps = {}) {
|
|
|
185
204
|
result = local ?? { decision: "none" };
|
|
186
205
|
source = cached
|
|
187
206
|
? `Decided on this computer from rules synced ${ageText(Math.max(0, Date.now() - cached.fetchedAt))}.`
|
|
188
|
-
:
|
|
207
|
+
: profile
|
|
208
|
+
? "Decided on this computer from built-in rules, until yours sync.\nRun: passport status"
|
|
209
|
+
: "Decided on this computer from built-in rules. Sign in to use yours.\nRun: passport login";
|
|
189
210
|
}
|
|
190
211
|
return {
|
|
191
212
|
json: { command: label, ...result, source: source.startsWith("Decided by") ? "server" : "local" },
|
|
192
|
-
human: ruleTestLines(label, result, source).join("\n")
|
|
213
|
+
human: ruleTestLines(termOf(runtime.stdout, runtime.env), label, result, source).join("\n")
|
|
193
214
|
};
|
|
194
215
|
}
|
|
195
216
|
function isPresetName(value) {
|
|
@@ -23,6 +23,16 @@ export type Cause = {
|
|
|
23
23
|
id?: string;
|
|
24
24
|
label: string;
|
|
25
25
|
};
|
|
26
|
+
/**
|
|
27
|
+
* Checked copies of `ruleParts` and `causeSentence` in shared/collabContract.ts
|
|
28
|
+
* (the CLI can't import shared/; cliAutopilot.test.ts compares them):
|
|
29
|
+
* "Blocked by a workspace rule: no railway volume delete in Production".
|
|
30
|
+
*/
|
|
31
|
+
export declare function ruleParts(label: string): {
|
|
32
|
+
owner: string;
|
|
33
|
+
says: string;
|
|
34
|
+
} | null;
|
|
35
|
+
export declare function causeSentence(decision: Decision, label: string): string;
|
|
26
36
|
/** A CLI-relevant rule, flattened by the server (`CliPolicyRule`). */
|
|
27
37
|
export type CliRule = {
|
|
28
38
|
id: string;
|
|
@@ -14,6 +14,34 @@
|
|
|
14
14
|
import { ENV_LABEL } from "./cliHookEnvironment.js";
|
|
15
15
|
export const PRESETS = ["careful", "balanced", "handsoff"];
|
|
16
16
|
export const ACTION_CLASSES = ["read", "change", "delete", "irreversible"];
|
|
17
|
+
/**
|
|
18
|
+
* Checked copies of `ruleParts` and `causeSentence` in shared/collabContract.ts
|
|
19
|
+
* (the CLI can't import shared/; cliAutopilot.test.ts compares them):
|
|
20
|
+
* "Blocked by a workspace rule: no railway volume delete in Production".
|
|
21
|
+
*/
|
|
22
|
+
export function ruleParts(label) {
|
|
23
|
+
const said = /^A rule says (.+)$/.exec(label);
|
|
24
|
+
if (said)
|
|
25
|
+
return { owner: "a rule", says: said[1] };
|
|
26
|
+
const match = /^(Your rule|Workspace rule|Team rule|(.{1,60}) team rule), (.+)$/.exec(label);
|
|
27
|
+
if (!match)
|
|
28
|
+
return null;
|
|
29
|
+
const owner = match[1] === "Your rule"
|
|
30
|
+
? "your rule"
|
|
31
|
+
: match[1] === "Workspace rule"
|
|
32
|
+
? "a workspace rule"
|
|
33
|
+
: match[1] === "Team rule"
|
|
34
|
+
? "a team rule"
|
|
35
|
+
: `the ${match[2]} team rule`;
|
|
36
|
+
return { owner, says: match[3] };
|
|
37
|
+
}
|
|
38
|
+
export function causeSentence(decision, label) {
|
|
39
|
+
const rule = ruleParts(label);
|
|
40
|
+
if (decision === "block")
|
|
41
|
+
return rule ? `Blocked by ${rule.owner}: ${rule.says}` : `Blocked by Passport: ${label}`;
|
|
42
|
+
const lead = decision === "ask" ? "Asks first" : "Runs";
|
|
43
|
+
return rule ? `${lead} under ${rule.owner}: ${rule.says}` : `${lead}: ${label}`;
|
|
44
|
+
}
|
|
17
45
|
/** The second-person rule's cause lines, as the server words them. */
|
|
18
46
|
export const SECOND_PERSON_LABEL = {
|
|
19
47
|
change: "Production changes need someone else to approve",
|
package/dist/cliConnect.js
CHANGED
|
@@ -2,6 +2,7 @@ import { bool, value } from "./cliArgs.js";
|
|
|
2
2
|
import { SERVER_TOO_OLD } from "./cliProtocol.js";
|
|
3
3
|
import { firstText, payloadOf, requireSuccess } from "./cliResult.js";
|
|
4
4
|
import { failure, openUrl, sleep } from "./cliSupport.js";
|
|
5
|
+
import { countOf } from "./plural.js";
|
|
5
6
|
export function managePayload(result) {
|
|
6
7
|
requireSuccess(result);
|
|
7
8
|
const payload = payloadOf(result, "connection");
|
|
@@ -62,7 +63,7 @@ export async function connect(args, runtime, withGateway) {
|
|
|
62
63
|
return failure("--open requires a single connect URL. Name one app, or use the aggregate connect flow.", 6, "usage");
|
|
63
64
|
if (urls[0]) {
|
|
64
65
|
if (!bool(args, "quiet"))
|
|
65
|
-
runtime.stderr.write("Opening the
|
|
66
|
+
runtime.stderr.write("Opening the sign-in page in your browser…\n");
|
|
66
67
|
if (!openUrl(urls[0]))
|
|
67
68
|
runtime.stderr.write(`Could not open a browser automatically. Open: ${urls[0]}\n`);
|
|
68
69
|
}
|
|
@@ -87,7 +88,7 @@ export async function connect(args, runtime, withGateway) {
|
|
|
87
88
|
if (!bool(args, "json") && (!bool(args, "quiet") || !bool(args, "open")))
|
|
88
89
|
runtime.stdout.write(`${human.join("\n")}\n`);
|
|
89
90
|
if (!bool(args, "quiet")) {
|
|
90
|
-
runtime.stderr.write(`Waiting up to ${waitSeconds}
|
|
91
|
+
runtime.stderr.write(`Waiting up to ${countOf(waitSeconds, "second")} for ${targets.length === 1 ? targets[0] : "the connections"}…\n`);
|
|
91
92
|
}
|
|
92
93
|
const waitResult = await waitForConnections(gateway, targets, waitSeconds, runtime.signal);
|
|
93
94
|
if (!waitResult.connected) {
|
|
@@ -102,7 +103,7 @@ function findConnection(rows, requested) {
|
|
|
102
103
|
const needle = requested.trim().toLowerCase();
|
|
103
104
|
const row = rows.find((entry) => String(entry.app ?? "").toLowerCase() === needle || String(entry.name ?? "").toLowerCase() === needle);
|
|
104
105
|
if (!row)
|
|
105
|
-
return failure(`Unknown app "${requested}".
|
|
106
|
+
return failure(`Unknown app "${requested}". See the apps you can connect with passport status.`, 6, "unknown_app", {
|
|
106
107
|
app: requested,
|
|
107
108
|
hint: "Run: passport status",
|
|
108
109
|
next: [{ argv: ["passport", "status"], description: "List visible app connections." }]
|
|
@@ -118,19 +119,19 @@ function connectionUrls(managed, rows, explicitlyNamed) {
|
|
|
118
119
|
function connectionLines(managed, rows, explicitlyNamed) {
|
|
119
120
|
const urls = connectionUrls(managed, rows, explicitlyNamed);
|
|
120
121
|
if (!explicitlyNamed && urls.length === 1 && rows.filter((row) => row.status === "needs_your_signin").length >= 2) {
|
|
121
|
-
return [
|
|
122
|
+
return ["Sign in to your apps on one page:", ` ${urls[0]}`];
|
|
122
123
|
}
|
|
123
124
|
const lines = [];
|
|
124
125
|
for (const row of rows) {
|
|
125
126
|
const name = String(row.name ?? row.app ?? "app");
|
|
126
127
|
if (row.status === "needs_your_signin" && typeof row.connectUrl === "string")
|
|
127
|
-
lines.push(`${name}: ${row.connectUrl}`);
|
|
128
|
+
lines.push(`${name}: sign in here`, ` ${row.connectUrl}`);
|
|
128
129
|
else if (row.status === "connected" || row.status === "org_managed")
|
|
129
130
|
lines.push(`${name}: already connected`);
|
|
130
131
|
else if (typeof row.action === "string")
|
|
131
132
|
lines.push(`${name}: ${row.action}`);
|
|
132
133
|
else
|
|
133
|
-
lines.push(`${name}: ${String(row.status ?? "unknown")}`);
|
|
134
|
+
lines.push(`${name}: ${String(row.status ?? "unknown").replace(/_/g, " ")}`);
|
|
134
135
|
}
|
|
135
136
|
if (!lines.length || (!explicitlyNamed && !rows.some((row) => row.status === "needs_your_signin")))
|
|
136
137
|
lines.push(managed.note || "Nothing needs connecting.");
|
package/dist/cliDeadline.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { countOf } from "./plural.js";
|
|
1
2
|
const systemClock = {
|
|
2
3
|
set: (callback, ms) => setTimeout(callback, ms),
|
|
3
4
|
clear: (timer) => clearTimeout(timer)
|
|
@@ -12,7 +13,7 @@ export async function withCliDeadline(promise, ms, onTimeout, clock = systemCloc
|
|
|
12
13
|
const expired = new Promise((_, reject) => {
|
|
13
14
|
timer = clock.set(() => {
|
|
14
15
|
onTimeout();
|
|
15
|
-
const error = new Error(`Request timed out after ${Math.ceil(ms / 1000)}
|
|
16
|
+
const error = new Error(`Request timed out after ${countOf(Math.ceil(ms / 1000), "second")}.`);
|
|
16
17
|
error.name = "TimeoutError";
|
|
17
18
|
reject(error);
|
|
18
19
|
}, ms);
|