passport-bridge 0.16.10 → 0.16.13
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 +16 -7
- package/dist/cli.js +6 -2
- package/dist/cliActions.js +20 -14
- package/dist/cliArgs.d.ts +3 -0
- package/dist/cliArgs.js +50 -6
- package/dist/cliAsk.d.ts +28 -0
- package/dist/cliAsk.js +49 -0
- package/dist/cliAutopilotPolicy.d.ts +15 -0
- package/dist/cliExec.d.ts +4 -0
- package/dist/cliExec.js +8 -1
- package/dist/cliGuardState.d.ts +20 -3
- package/dist/cliGuardState.js +24 -12
- package/dist/cliHook.js +4 -2
- package/dist/cliHookDecide.d.ts +16 -4
- package/dist/cliHookDecide.js +58 -14
- package/dist/cliHookDeliver.d.ts +17 -1
- package/dist/cliHookDeliver.js +70 -19
- package/dist/cliHookGuard.d.ts +9 -0
- package/dist/cliHookGuard.js +16 -2
- package/dist/cliHookInstall.d.ts +2 -0
- package/dist/cliHookInstall.js +2 -1
- package/dist/cliHookStatus.js +2 -4
- package/dist/cliKeys.d.ts +10 -3
- package/dist/cliKeys.js +60 -45
- package/dist/cliLogin.js +5 -2
- package/dist/cliMain.d.ts +7 -0
- package/dist/cliMain.js +502 -0
- package/dist/cliOutput.d.ts +3 -0
- package/dist/cliOutput.js +115 -8
- package/dist/cliPolicyV2.js +53 -2
- package/dist/cliSuggest.d.ts +19 -0
- package/dist/cliSuggest.js +57 -0
- package/dist/cliUndo.js +3 -8
- package/dist/compileCache.d.ts +8 -0
- package/dist/compileCache.js +60 -0
- package/dist/execNoKey.d.ts +9 -0
- package/dist/execNoKey.js +25 -0
- package/dist/hookMain.js +7 -11
- package/dist/hookOutbox.d.ts +15 -2
- package/dist/hookOutbox.js +143 -3
- package/dist/initKeysStep.d.ts +1 -1
- package/dist/initKeysStep.js +8 -7
- package/dist/initOutro.js +2 -1
- package/dist/initUi.d.ts +7 -2
- package/dist/initUi.js +22 -9
- package/dist/passport.d.ts +1 -7
- package/dist/passport.js +15 -499
- package/dist/pluginPin.d.ts +1 -1
- package/dist/pluginPin.js +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/webLinks.d.ts +2 -0
- package/dist/webLinks.js +7 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -139,10 +139,10 @@ Eight steps, each reusing the command that owns it:
|
|
|
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 Railway and GitHub keys stay on this computer. Move them any time: passport keys move`. Step by step asks the same question as `passport keys move` for each: `Store your Railway account token in Passport and sign the Railway CLI out on this computer? [y/
|
|
142
|
+
4. **Keys**: the recommended setup keeps them; the plan says `Your Railway and GitHub keys stay on this computer. Move them any time: passport keys move`. Step by step asks the same question as `passport keys move` for each: `Store your Railway account token in Passport and sign the Railway CLI out on this computer? [y/N]`. 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
143
|
5. **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 · Production`). With no app connected yet it says they appear once one is.
|
|
144
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 → paste the URL (copied)`; without one it names the URL.
|
|
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 (Codex
|
|
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
|
```
|
|
@@ -257,7 +257,9 @@ An ask becomes one Activity row. In Claude Code, with the audit hook registered,
|
|
|
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
|
|
|
260
|
-
**When Passport can't be reached.** When the guard needs Passport (an unattended ask, Codex, or a Production action someone else approves) and it doesn't answer within the budget, the environment's `offline` setting from cli-policy v2 decides: ask, block, or allow (
|
|
260
|
+
**When Passport can't be reached.** A local run, block, or attended ask stands as decided. When the guard needs Passport (an unattended ask, Codex, or a Production action someone else approves) and it doesn't answer within the budget, the environment's `offline` setting from cli-policy v2 decides: ask, block, or allow (ask everywhere by default). An ask nobody can answer (unattended, or Codex) blocks, a second-person action is always blocked, and allow never covers an irreversible action or an ask from a team floor, team or workspace rule, approver rule, or approved exception. A policy synced more than 7 days ago uses the default. The reason ends with one line saying why, such as `Nobody is here to approve it and Passport couldn't be reached, so it's blocked.`
|
|
261
|
+
|
|
262
|
+
**App access.** The person's pass for the app a `passport exec` CLI acts on (Railway for `railway`, GitHub for `gh`, and so on) comes with cli-policy v2 as `appAccess`. No access blocks every command of that CLI with `You don't have access to Railway in Passport. Ask an admin.` and a link to the app's Access tab; read-only blocks everything but reads. `passport exec` says the same (exit 5, cause `no_access`, with `Access: <link>`). A CLI whose app isn't in the workspace keeps working from its key.
|
|
261
263
|
|
|
262
264
|
`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.
|
|
263
265
|
|
|
@@ -289,7 +291,8 @@ passport actions sync # propose this repository's .passport/actions.toml
|
|
|
289
291
|
### Keys and passport exec
|
|
290
292
|
|
|
291
293
|
```sh
|
|
292
|
-
passport keys move # confirm each key [y/
|
|
294
|
+
passport keys move # confirm each key [y/N], store it in Passport, sign that CLI out here
|
|
295
|
+
passport keys move railway # only the Railway key
|
|
293
296
|
passport keys # what Passport holds, and what's still on this computer
|
|
294
297
|
passport keys add railway # store a key you paste (stdin, never echoed)
|
|
295
298
|
passport exec -- railway up -e staging
|
|
@@ -301,9 +304,9 @@ passport keys shim # the CLIs that run through Passport when you type
|
|
|
301
304
|
- Releases: Passport's own release computer keeps its Railway sign-in, so releases never depend on Passport. In a repository with `scripts/lib/local-release-controller.mjs`, `keys move` and `init` ask `This computer deploys Passport with the Railway CLI. Moving the key will stop releases. Keep it here? [Y/n]` (Enter, `--yes`, and no terminal keep it). Release attestation checks the exact Railway CLI binary on PATH with a throwaway HOME, so a shim in front of it fails closed. See `docs/DEPLOY.md`.
|
|
302
305
|
|
|
303
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.
|
|
304
|
-
- `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/
|
|
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.
|
|
305
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`).
|
|
306
|
-
- 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. Run passport wait <id> to keep waiting, then run the command again.` 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 (
|
|
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. Run passport wait <id> to keep waiting, then run the command again.` 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. 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.
|
|
307
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.
|
|
308
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.
|
|
309
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.
|
|
@@ -421,6 +424,10 @@ const actions = await client.actions(); // or client.actions(delegationId)
|
|
|
421
424
|
|
|
422
425
|
With `--json`, stdout is exactly one JSON value; hints and warnings go to stderr. JSON shapes only gain fields.
|
|
423
426
|
|
|
427
|
+
A mistyped command, option, subcommand, or `help <command>` exits 6 with the closest match, stated rather than asked (`Unknown command "stauts". Did you mean: passport status`, `Unknown option "--jsn". Did you mean: --json`); with `--json` the match is in `next`. With nothing close it says where to look (`Run passport help to see every command.`). `help <unknown>` never prints the general help. Help pages lead with examples, and `passport help` ends with the exit codes below.
|
|
428
|
+
|
|
429
|
+
Questions follow one convention (`src/cliAsk.ts`), only on a terminal: `[Y/n]` for a safe step (Enter is yes); `[y/N]` for a destructive one, such as signing a CLI out, switching who you're signed in as, or an undo (Enter is no); and for a severe one you type its name (`Type railway to confirm, or press Enter to cancel:`). `--yes` never answers a severe question. A severe step a script may take gets `--confirm=<name>`; replacing a key Passport holds, today's only severe step, deliberately has no flag, so it only ever happens on a person's answer at a terminal.
|
|
430
|
+
|
|
424
431
|
On a terminal, human output comes from one renderer (`src/term.ts`): it wraps to the window's width (at least 40 columns, at most 100) without breaking a URL or a `passport` command, hangs wrapped lines under their label or mark, stacks a table one row at a time when its columns don't fit, and clips a live line (a countdown, a "Checking…" row) to one row so it's always replaced cleanly. Marks always sit next to words (`✓ On`, `! Not trusted`, `– skipped`), with `+`, `!`, `-` where the terminal can't show them. Piped output never wraps, has no color, and draws no live lines. `NO_COLOR` and `TERM=dumb` turn color off.
|
|
425
432
|
|
|
426
433
|
| Command | JSON value |
|
|
@@ -459,7 +466,7 @@ Errors: `{"error":"...","cause":"blocked","exitCode":5,"app":"github"}`, optiona
|
|
|
459
466
|
| 3 | App needs member sign-in |
|
|
460
467
|
| 4 | Approval pending (including `wait` still waiting at its timeout) |
|
|
461
468
|
| 5 | Policy, guardrail, selection, or approval denial (including a declined or expired approval in `wait`) |
|
|
462
|
-
| 6 |
|
|
469
|
+
| 6 | Usage mistake: an unknown command, option, tool, or app (with the closest match when there is one) |
|
|
463
470
|
|
|
464
471
|
## MCP stdio bridge
|
|
465
472
|
|
|
@@ -482,6 +489,8 @@ passport-bridge serve --profile cursor@ws_example
|
|
|
482
489
|
|
|
483
490
|
## Maintainers
|
|
484
491
|
|
|
492
|
+
Startup: `dist/passport.js` (the npm bin, the launcher `$PASSPORT_HOME/cli/bin/passport`, and `passport.cmd` on Windows) and the hooks' `dist/hookMain.js` are tiny entries that turn on Node's compile cache (`module.enableCompileCache`, `src/compileCache.ts`) before loading the CLI (`src/cliMain.ts`), so the second and later runs skip compiling it. The cache is `$PASSPORT_HOME/cli/compile-cache` (`~/.passport/cli/compile-cache`), created 0700 and used only while it's owned by this user and nobody else can write it: never the repository or the system's temp folder. `NODE_COMPILE_CACHE` and `NODE_DISABLE_COMPILE_CACHE` keep Node's meaning. `npm run bench:guard` times the guard and `version`, `--help`, and `status` (piped, Passport refusing connections) through the launcher; `PASSPORT_BENCH_NO_CACHE=1` times the same build without the cache. The hook path never loads the renderer or prompt code (`src/termImports.test.ts`).
|
|
493
|
+
|
|
485
494
|
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`.
|
|
486
495
|
|
|
487
496
|
`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
|
@@ -38,7 +38,7 @@ async function passportOneLiner() {
|
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
40
40
|
ensureOneLinerRuntime();
|
|
41
|
-
const { main: passport } = await import("./
|
|
41
|
+
const { main: passport } = await import("./cliMain.js");
|
|
42
42
|
process.exitCode = await passport(process.argv.slice(2), process.env, {
|
|
43
43
|
stdin: process.stdin,
|
|
44
44
|
stdout: process.stdout,
|
|
@@ -62,7 +62,11 @@ async function main() {
|
|
|
62
62
|
return logout();
|
|
63
63
|
if (command === "status")
|
|
64
64
|
return status();
|
|
65
|
-
|
|
65
|
+
const { closest } = await import("./cliSuggest.js");
|
|
66
|
+
const guess = closest(command, ["serve", "login", "logout", "status", "help", "version", ...PASSPORT_ONE_LINERS]);
|
|
67
|
+
process.stderr.write(guess
|
|
68
|
+
? `Unknown command "${command}". Did you mean: passport-bridge ${guess}\n`
|
|
69
|
+
: `Unknown command "${command}". Run passport-bridge --help to see every command.\n`);
|
|
66
70
|
process.exit(1);
|
|
67
71
|
}
|
|
68
72
|
function help() {
|
package/dist/cliActions.js
CHANGED
|
@@ -23,6 +23,8 @@ import { memberApi } from "./cliClient.js";
|
|
|
23
23
|
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
|
+
import { unknownSubcommand } from "./cliSuggest.js";
|
|
27
|
+
import { table, termOf } from "./term.js";
|
|
26
28
|
import { callerFrom, failure, resolveCliAuth, safeApiError, timeoutMs } from "./cliSupport.js";
|
|
27
29
|
const ENVIRONMENTS = new Set(["production", "staging", "development"]);
|
|
28
30
|
const CLASSES = new Set(["read", "change", "delete", "irreversible"]);
|
|
@@ -196,19 +198,22 @@ async function list(args, runtime, deps) {
|
|
|
196
198
|
return failure(await safeApiError(response, "Passport couldn't list them."), 1, "server");
|
|
197
199
|
const body = (await readBoundedJson(response).catch(() => ({})));
|
|
198
200
|
const actions = body.projectActions ?? [];
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
]
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
201
|
+
// One aligned row per script (script, environment, class, repository,
|
|
202
|
+
// notes); on a narrow terminal each row stacks.
|
|
203
|
+
const rows = actions.map((action) => [
|
|
204
|
+
action.label ?? "script",
|
|
205
|
+
action.environment ? (ENV_WORD[action.environment] ?? action.environment) : "",
|
|
206
|
+
action.actionClass ?? "",
|
|
207
|
+
action.repoName ?? "Any repository",
|
|
208
|
+
[
|
|
209
|
+
...(action.setByName ? [`Set by ${action.setByName}`] : []),
|
|
210
|
+
...(action.status === "proposed" ? ["Proposed"] : []),
|
|
211
|
+
...(action.changedAt ? ["Changed since set"] : [])
|
|
212
|
+
].join(" · ")
|
|
213
|
+
]);
|
|
214
|
+
const width = termOf((runtime.stdout ?? {}), runtime.env).width;
|
|
215
|
+
const human = rows.length
|
|
216
|
+
? table(rows, width).join("\n")
|
|
212
217
|
: "No project scripts yet. Add one: passport actions add <script> --environment <kind> --class <class>";
|
|
213
218
|
return { json: { actions }, human };
|
|
214
219
|
}
|
|
@@ -220,5 +225,6 @@ export async function actions(args, runtime, deps = {}) {
|
|
|
220
225
|
return add(args, runtime, deps);
|
|
221
226
|
if (action === "sync")
|
|
222
227
|
return sync(args, runtime, deps);
|
|
223
|
-
|
|
228
|
+
const unknown = unknownSubcommand("actions", action, ["list", "add", "sync"]);
|
|
229
|
+
return failure(unknown.message, 6, "usage", unknown.next ? { next: unknown.next } : {});
|
|
224
230
|
}
|
package/dist/cliArgs.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
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", "actions", "sessions", "env", "sync", "exec", "undo", "keys", "setup", "session", "access", "completion", "help", "version"];
|
|
2
2
|
export type Command = (typeof COMMANDS)[number];
|
|
3
|
+
/** A usage mistake. `suggestion` is the command the person most likely meant. */
|
|
3
4
|
export declare class ArgError extends Error {
|
|
5
|
+
readonly suggestion?: string[] | undefined;
|
|
6
|
+
constructor(message: string, suggestion?: string[] | undefined);
|
|
4
7
|
}
|
|
5
8
|
export type ParsedArgs = {
|
|
6
9
|
command: Command;
|
package/dist/cliArgs.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { closest } from "./cliSuggest.js";
|
|
1
2
|
export const COMMANDS = [
|
|
2
3
|
"init",
|
|
3
4
|
"login",
|
|
@@ -91,7 +92,34 @@ const FLAGS = {
|
|
|
91
92
|
const FLAG_ALIASES = { agent: "client", agents: "clients" };
|
|
92
93
|
const shownFlag = (name) => Object.keys(FLAG_ALIASES).find((alias) => FLAG_ALIASES[alias] === name) ?? name;
|
|
93
94
|
const passedTwice = (name) => shownFlag(name) === name ? `--${name} may only be passed once.` : `Pass --${shownFlag(name)} or --${name} once.`;
|
|
95
|
+
/** A usage mistake. `suggestion` is the command the person most likely meant. */
|
|
94
96
|
export class ArgError extends Error {
|
|
97
|
+
suggestion;
|
|
98
|
+
constructor(message, suggestion) {
|
|
99
|
+
super(message);
|
|
100
|
+
this.suggestion = suggestion;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/** Every option name a command takes, as typed (`--agent`, not `--client`). */
|
|
104
|
+
function optionsFor(command) {
|
|
105
|
+
const names = Object.keys(FLAGS)
|
|
106
|
+
.filter((name) => !command || !FLAGS[name].commands || FLAGS[name].commands.includes(command))
|
|
107
|
+
.map(shownFlag);
|
|
108
|
+
return [...new Set(names)];
|
|
109
|
+
}
|
|
110
|
+
function unknownCommand(raw, help = false) {
|
|
111
|
+
const guess = closest(raw, COMMANDS);
|
|
112
|
+
const argv = guess ? ["passport", ...(help ? ["help"] : []), guess] : undefined;
|
|
113
|
+
return new ArgError(`Unknown command "${raw}". ${argv ? `Did you mean: ${argv.join(" ")}` : "Run passport help to see every command."}`, argv);
|
|
114
|
+
}
|
|
115
|
+
function unknownOption(raw, command) {
|
|
116
|
+
const given = raw.startsWith("--") ? flagParts(raw).name : raw.replace(/^-+/, "");
|
|
117
|
+
const guess = closest(given, optionsFor(command));
|
|
118
|
+
if (guess) {
|
|
119
|
+
return new ArgError(`Unknown option "${raw}". Did you mean: --${guess}`, command ? ["passport", command, `--${guess}`] : undefined);
|
|
120
|
+
}
|
|
121
|
+
const where = command && command !== "help" ? `passport help ${command}` : "passport help";
|
|
122
|
+
return new ArgError(`Unknown option "${raw}". Run ${where} to see the options.`);
|
|
95
123
|
}
|
|
96
124
|
function knownCommand(value) {
|
|
97
125
|
return COMMANDS.includes(value);
|
|
@@ -109,6 +137,9 @@ export function parseArgs(argv) {
|
|
|
109
137
|
const repeats = {};
|
|
110
138
|
const booleans = new Set();
|
|
111
139
|
let positionalOnly = false;
|
|
140
|
+
// An unknown option is reported once the command is known, so the
|
|
141
|
+
// suggestion comes from that command's own options.
|
|
142
|
+
let unknown;
|
|
112
143
|
for (let i = 0; i < argv.length; i++) {
|
|
113
144
|
let raw = argv[i];
|
|
114
145
|
if (!positionalOnly && raw === "--") {
|
|
@@ -128,8 +159,10 @@ export function parseArgs(argv) {
|
|
|
128
159
|
const { name: given, inline } = flagParts(raw);
|
|
129
160
|
const name = FLAG_ALIASES[given] ?? given;
|
|
130
161
|
const spec = FLAGS[name];
|
|
131
|
-
if (!spec)
|
|
132
|
-
|
|
162
|
+
if (!spec) {
|
|
163
|
+
unknown ??= raw;
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
133
166
|
if (spec.kind === "boolean") {
|
|
134
167
|
if (inline !== undefined)
|
|
135
168
|
throw new ArgError(`--${name} does not take a value.`);
|
|
@@ -151,11 +184,13 @@ export function parseArgs(argv) {
|
|
|
151
184
|
}
|
|
152
185
|
continue;
|
|
153
186
|
}
|
|
154
|
-
if (!positionalOnly && raw.startsWith("-") && raw !== "-")
|
|
155
|
-
|
|
187
|
+
if (!positionalOnly && raw.startsWith("-") && raw !== "-") {
|
|
188
|
+
unknown ??= raw;
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
156
191
|
if (!command) {
|
|
157
192
|
if (!knownCommand(raw))
|
|
158
|
-
throw
|
|
193
|
+
throw unknownCommand(raw);
|
|
159
194
|
command = raw;
|
|
160
195
|
}
|
|
161
196
|
else {
|
|
@@ -166,7 +201,14 @@ export function parseArgs(argv) {
|
|
|
166
201
|
positionalOnly = true;
|
|
167
202
|
}
|
|
168
203
|
}
|
|
169
|
-
|
|
204
|
+
if (unknown !== undefined)
|
|
205
|
+
throw unknownOption(unknown, command);
|
|
206
|
+
return settle({ command: command ?? "help", positionals, values, repeats, booleans });
|
|
207
|
+
}
|
|
208
|
+
/** `--help` becomes `help <command>`; then every option must fit the command. */
|
|
209
|
+
function settle(args) {
|
|
210
|
+
let { command } = args;
|
|
211
|
+
const { positionals, values, repeats, booleans } = args;
|
|
170
212
|
if (booleans.has("help") && command !== "help") {
|
|
171
213
|
positionals.splice(0, positionals.length, command);
|
|
172
214
|
command = "help";
|
|
@@ -177,6 +219,8 @@ export function parseArgs(argv) {
|
|
|
177
219
|
if (allowed && !allowed.includes(command))
|
|
178
220
|
throw new ArgError(`--${shownFlag(name)} is not valid with ${command}.`);
|
|
179
221
|
}
|
|
222
|
+
if (command === "help" && positionals[0] !== undefined && !knownCommand(positionals[0]))
|
|
223
|
+
throw unknownCommand(positionals[0], true);
|
|
180
224
|
validateShape(command, positionals);
|
|
181
225
|
validateNumbers(values);
|
|
182
226
|
return { command, positionals, values, repeats, booleans };
|
package/dist/cliAsk.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one question convention for every prompt the CLI shows (init, keys,
|
|
3
|
+
* undo, login):
|
|
4
|
+
*
|
|
5
|
+
* [Y/n] a safe step. Enter says yes.
|
|
6
|
+
* [y/N] a destructive step: it signs a CLI out, removes something
|
|
7
|
+
* from this computer, switches who you're signed in as, or
|
|
8
|
+
* undoes an action. Enter says no.
|
|
9
|
+
* type the name a severe step: it replaces a key every agent uses. Only the
|
|
10
|
+
* exact name says yes; Enter or anything else says no. A
|
|
11
|
+
* severe step a script may take gets --confirm=<name>; replacing
|
|
12
|
+
* a key Passport holds deliberately has none, so an agent's
|
|
13
|
+
* script can never swap one.
|
|
14
|
+
*
|
|
15
|
+
* A prompt only ever appears on a terminal. --yes answers safe and destructive
|
|
16
|
+
* questions, never a severe one.
|
|
17
|
+
*/
|
|
18
|
+
export type Stakes = "safe" | "destructive";
|
|
19
|
+
export declare function choices(stakes: Stakes): "[Y/n]" | "[y/N]";
|
|
20
|
+
/** true or false, or undefined when the answer is neither. */
|
|
21
|
+
export declare function answerOf(answer: string, stakes: Stakes): boolean | undefined;
|
|
22
|
+
export declare const ASK_AGAIN = "Type y or n.";
|
|
23
|
+
/** Asks until the answer is yes, no, or Enter (the default). */
|
|
24
|
+
export declare function askYesNo(ask: (prompt: string) => Promise<string>, say: (text: string) => void, question: string, stakes: Stakes): Promise<boolean>;
|
|
25
|
+
/** The second line of a severe question. */
|
|
26
|
+
export declare function typeNamePrompt(name: string): string;
|
|
27
|
+
/** Only the exact name confirms. */
|
|
28
|
+
export declare function nameConfirmed(answer: string, name: string): boolean;
|
package/dist/cliAsk.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one question convention for every prompt the CLI shows (init, keys,
|
|
3
|
+
* undo, login):
|
|
4
|
+
*
|
|
5
|
+
* [Y/n] a safe step. Enter says yes.
|
|
6
|
+
* [y/N] a destructive step: it signs a CLI out, removes something
|
|
7
|
+
* from this computer, switches who you're signed in as, or
|
|
8
|
+
* undoes an action. Enter says no.
|
|
9
|
+
* type the name a severe step: it replaces a key every agent uses. Only the
|
|
10
|
+
* exact name says yes; Enter or anything else says no. A
|
|
11
|
+
* severe step a script may take gets --confirm=<name>; replacing
|
|
12
|
+
* a key Passport holds deliberately has none, so an agent's
|
|
13
|
+
* script can never swap one.
|
|
14
|
+
*
|
|
15
|
+
* A prompt only ever appears on a terminal. --yes answers safe and destructive
|
|
16
|
+
* questions, never a severe one.
|
|
17
|
+
*/
|
|
18
|
+
export function choices(stakes) {
|
|
19
|
+
return stakes === "safe" ? "[Y/n]" : "[y/N]";
|
|
20
|
+
}
|
|
21
|
+
/** true or false, or undefined when the answer is neither. */
|
|
22
|
+
export function answerOf(answer, stakes) {
|
|
23
|
+
const typed = answer.trim().toLowerCase();
|
|
24
|
+
if (typed === "y" || typed === "yes")
|
|
25
|
+
return true;
|
|
26
|
+
if (typed === "n" || typed === "no")
|
|
27
|
+
return false;
|
|
28
|
+
if (typed === "")
|
|
29
|
+
return stakes === "safe";
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
export const ASK_AGAIN = "Type y or n.";
|
|
33
|
+
/** Asks until the answer is yes, no, or Enter (the default). */
|
|
34
|
+
export async function askYesNo(ask, say, question, stakes) {
|
|
35
|
+
for (;;) {
|
|
36
|
+
const answer = answerOf(await ask(`${question} ${choices(stakes)} `), stakes);
|
|
37
|
+
if (answer !== undefined)
|
|
38
|
+
return answer;
|
|
39
|
+
say(ASK_AGAIN);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** The second line of a severe question. */
|
|
43
|
+
export function typeNamePrompt(name) {
|
|
44
|
+
return `Type ${name} to confirm, or press Enter to cancel:`;
|
|
45
|
+
}
|
|
46
|
+
/** Only the exact name confirms. */
|
|
47
|
+
export function nameConfirmed(answer, name) {
|
|
48
|
+
return answer.trim() === name;
|
|
49
|
+
}
|
|
@@ -41,6 +41,9 @@ export type CliRule = {
|
|
|
41
41
|
label?: string;
|
|
42
42
|
/** Actions an approved exception lifts this rule for (this person only). */
|
|
43
43
|
except?: RuleException[];
|
|
44
|
+
/** This rule is an approved exception: the person's own, but an admin
|
|
45
|
+
* approved it, so an offline Run never loosens it. */
|
|
46
|
+
exception?: true;
|
|
44
47
|
};
|
|
45
48
|
export type RuleException = {
|
|
46
49
|
vendor?: string;
|
|
@@ -49,6 +52,14 @@ export type RuleException = {
|
|
|
49
52
|
actionClass?: ActionClass;
|
|
50
53
|
environment: ActionEnv | "any";
|
|
51
54
|
};
|
|
55
|
+
/** One vendor's app access: the server's cause and message, and the Access link. */
|
|
56
|
+
export type AppAccessEntry = {
|
|
57
|
+
pass: "full" | "readonly" | "none";
|
|
58
|
+
app: string;
|
|
59
|
+
cause: string;
|
|
60
|
+
message: string;
|
|
61
|
+
link?: string;
|
|
62
|
+
};
|
|
52
63
|
/** The second-person rule's cause lines, as the server words them. */
|
|
53
64
|
export declare const SECOND_PERSON_LABEL: {
|
|
54
65
|
readonly change: "Production changes need someone else to approve";
|
|
@@ -98,6 +109,10 @@ export type AutopilotPolicy = {
|
|
|
98
109
|
/** What the guard does per environment when Passport can't be reached
|
|
99
110
|
* (Batch A). Absent from older servers: built-in defaults apply. */
|
|
100
111
|
offline?: Record<ActionEnv, "ask" | "block" | "allow">;
|
|
112
|
+
/** The person's pass for the app each vendor CLI acts on (cli-policy v2
|
|
113
|
+
* `appAccess`), by vendor: No access blocks every command, Read-only runs
|
|
114
|
+
* only reads. A vendor without an entry has no app in the workspace. */
|
|
115
|
+
appAccess?: Record<string, AppAccessEntry>;
|
|
101
116
|
/** Resources the workspace placed, by id (Phase 4.5). Present only when the
|
|
102
117
|
* server reads where a finding lands, so findings may carry it. */
|
|
103
118
|
resources?: Array<{
|
package/dist/cliExec.d.ts
CHANGED
|
@@ -37,6 +37,8 @@ export type ExecDependencies = {
|
|
|
37
37
|
cwd?: string;
|
|
38
38
|
interactive?: boolean;
|
|
39
39
|
now?: () => number;
|
|
40
|
+
/** Where to look for this computer's own CLI sign-ins (tests). */
|
|
41
|
+
home?: string;
|
|
40
42
|
};
|
|
41
43
|
type Authorized = {
|
|
42
44
|
decision?: unknown;
|
|
@@ -54,6 +56,8 @@ type Authorized = {
|
|
|
54
56
|
/** Phase 4: a backup was taken right before, or couldn't be (with the reason). */
|
|
55
57
|
backup?: unknown;
|
|
56
58
|
backupNote?: unknown;
|
|
59
|
+
/** A block's fix, as a web hash (`#apps/railway/access`). */
|
|
60
|
+
link?: unknown;
|
|
57
61
|
/** A recent decline answered this command: who, the note, and when. */
|
|
58
62
|
declined?: {
|
|
59
63
|
by?: unknown;
|
package/dist/cliExec.js
CHANGED
|
@@ -37,7 +37,7 @@ import { EXEC_ENV_NAMES, EXEC_PASSPORT_ENV, EXEC_SHADOWED_ENV, EXEC_VENDOR_NAMES
|
|
|
37
37
|
import { execTarget } from "./execTarget.js";
|
|
38
38
|
import { maskChildOutput, secretNeedles } from "./execMask.js";
|
|
39
39
|
import { findVendorBinary, removeShims } from "./execShims.js";
|
|
40
|
-
import { approvalLink } from "./webLinks.js";
|
|
40
|
+
import { approvalLink, hashLink } from "./webLinks.js";
|
|
41
41
|
import { workspaceOfToken } from "./tokenWorkspace.js";
|
|
42
42
|
import { declinedLine, waitingParts } from "./waitingLine.js";
|
|
43
43
|
export const EXEC_AUTHORIZE_PATH = "/api/my/exec/authorize";
|
|
@@ -466,6 +466,9 @@ export async function exec(args, runtime, deps = {}) {
|
|
|
466
466
|
if (removed.length && !bool(args, "quiet")) {
|
|
467
467
|
runtime.stderr.write(`Removed Passport's ${removed.join(" and ")} shim, so ${binary} runs on its own again.\n`);
|
|
468
468
|
}
|
|
469
|
+
if (auth.kind === "profile") {
|
|
470
|
+
throw (await import("./execNoKey.js")).keyHereFailure(error, vendor, runtime, deps.home);
|
|
471
|
+
}
|
|
469
472
|
}
|
|
470
473
|
throw error;
|
|
471
474
|
}
|
|
@@ -485,6 +488,10 @@ export async function exec(args, runtime, deps = {}) {
|
|
|
485
488
|
hint: ASK_AGAIN_HINT
|
|
486
489
|
});
|
|
487
490
|
}
|
|
491
|
+
// Blocked by the app's access: say where an admin changes it.
|
|
492
|
+
const link = hashLink(auth.endpoint, decided.link);
|
|
493
|
+
if (link)
|
|
494
|
+
return failure(message, 5, "no_access", { hint: `Access: ${link}` });
|
|
488
495
|
return failure(message, 5, "blocked");
|
|
489
496
|
}
|
|
490
497
|
if (decided.decision !== "allow")
|
package/dist/cliGuardState.d.ts
CHANGED
|
@@ -49,12 +49,29 @@ export declare function guardStateFix(state: GuardState | null, client: GuardCli
|
|
|
49
49
|
export declare function fixLine(fix: ProblemFix): string;
|
|
50
50
|
export type OfflineDecision = "ask" | "block" | "allow";
|
|
51
51
|
export type OfflineRow = "production" | "staging" | "development" | "other";
|
|
52
|
-
|
|
52
|
+
/** Every environment asks unless the person chose otherwise (`OFFLINE_DEFAULT`
|
|
53
|
+
* in shared/guardContract.ts); used only without a fresh policy. */
|
|
54
|
+
export declare const OFFLINE_DEFAULT: OfflineDecision;
|
|
53
55
|
export declare const OFFLINE_CACHE_MAX_MS: number;
|
|
54
|
-
export declare const
|
|
56
|
+
export declare const OFFLINE_NOTES: {
|
|
57
|
+
readonly decided: "Passport couldn't be reached, so this computer decided.";
|
|
58
|
+
readonly setting: "Passport couldn't be reached, and your setting for that blocks it.";
|
|
59
|
+
readonly allowed: "Passport couldn't be reached, and your setting for that runs it.";
|
|
60
|
+
readonly unattended: "Nobody is here to approve it and Passport couldn't be reached, so it's blocked.";
|
|
61
|
+
readonly codex: "Codex can't ask and Passport couldn't be reached, so it's blocked.";
|
|
62
|
+
readonly secondPerson: "Someone else approves this and Passport couldn't be reached, so it's blocked.";
|
|
63
|
+
};
|
|
64
|
+
export type OfflineNote = keyof typeof OFFLINE_NOTES;
|
|
65
|
+
/** A local Ask that needed Passport, when Passport didn't answer in time (see
|
|
66
|
+
* shared/guardContract.ts `offlineDecision`). */
|
|
55
67
|
export declare function offlineDecision(input: {
|
|
56
68
|
setting: OfflineDecision;
|
|
57
69
|
actionClass?: string;
|
|
58
70
|
client: string;
|
|
59
71
|
secondPerson: boolean;
|
|
60
|
-
|
|
72
|
+
attended: boolean;
|
|
73
|
+
required: boolean;
|
|
74
|
+
}): {
|
|
75
|
+
decision: "allow" | "ask" | "block";
|
|
76
|
+
note: OfflineNote;
|
|
77
|
+
};
|
package/dist/cliGuardState.js
CHANGED
|
@@ -101,21 +101,33 @@ export function guardStateFix(state, client) {
|
|
|
101
101
|
export function fixLine(fix) {
|
|
102
102
|
return fix.command ? `${fix.text} Run: ${fix.command}` : fix.text;
|
|
103
103
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
development: "allow",
|
|
108
|
-
other: "allow"
|
|
109
|
-
};
|
|
104
|
+
/** Every environment asks unless the person chose otherwise (`OFFLINE_DEFAULT`
|
|
105
|
+
* in shared/guardContract.ts); used only without a fresh policy. */
|
|
106
|
+
export const OFFLINE_DEFAULT = "ask";
|
|
110
107
|
export const OFFLINE_CACHE_MAX_MS = 7 * 24 * 60 * 60_000;
|
|
111
|
-
export const
|
|
108
|
+
export const OFFLINE_NOTES = {
|
|
109
|
+
decided: "Passport couldn't be reached, so this computer decided.",
|
|
110
|
+
setting: "Passport couldn't be reached, and your setting for that blocks it.",
|
|
111
|
+
allowed: "Passport couldn't be reached, and your setting for that runs it.",
|
|
112
|
+
unattended: "Nobody is here to approve it and Passport couldn't be reached, so it's blocked.",
|
|
113
|
+
codex: "Codex can't ask and Passport couldn't be reached, so it's blocked.",
|
|
114
|
+
secondPerson: "Someone else approves this and Passport couldn't be reached, so it's blocked."
|
|
115
|
+
};
|
|
116
|
+
/** A local Ask that needed Passport, when Passport didn't answer in time (see
|
|
117
|
+
* shared/guardContract.ts `offlineDecision`). */
|
|
112
118
|
export function offlineDecision(input) {
|
|
113
119
|
if (input.secondPerson)
|
|
114
|
-
return "block";
|
|
120
|
+
return { decision: "block", note: "secondPerson" };
|
|
115
121
|
let decision = input.setting;
|
|
116
|
-
if (decision === "allow" && input.actionClass === "irreversible")
|
|
122
|
+
if (decision === "allow" && (input.actionClass === "irreversible" || input.required))
|
|
117
123
|
decision = "ask";
|
|
118
|
-
if (decision === "
|
|
119
|
-
decision
|
|
120
|
-
|
|
124
|
+
if (decision === "allow")
|
|
125
|
+
return { decision, note: "allowed" };
|
|
126
|
+
if (decision === "block")
|
|
127
|
+
return { decision, note: "setting" };
|
|
128
|
+
if (input.client === "codex")
|
|
129
|
+
return { decision: "block", note: "codex" };
|
|
130
|
+
if (!input.attended)
|
|
131
|
+
return { decision: "block", note: "unattended" };
|
|
132
|
+
return { decision, note: "decided" };
|
|
121
133
|
}
|
package/dist/cliHook.js
CHANGED
|
@@ -353,7 +353,9 @@ function outputClient(event, runtime) {
|
|
|
353
353
|
async function guardReport(base, plan, context) {
|
|
354
354
|
if (plan.server && base)
|
|
355
355
|
return serverDecidedReport(base, plan.server, context.now);
|
|
356
|
-
|
|
356
|
+
// Offline, this computer's answer replaces the local Ask on the record.
|
|
357
|
+
const decided = base && plan.offline && plan.verdict ? { ...base, decision: plan.verdict } : base;
|
|
358
|
+
const report = decided && context.v2 && decided.decision === "allow" ? null : codexAskBlocked(decided);
|
|
357
359
|
if (!report)
|
|
358
360
|
return null;
|
|
359
361
|
// Claude Code reuses its tool-use id after a command: an ask waits for the audit hook, then is one row.
|
|
@@ -390,7 +392,7 @@ function answeredWith(decision, plan) {
|
|
|
390
392
|
if (plan.server) {
|
|
391
393
|
return plan.server.decision === "block" ? "deny" : plan.server.decision === "none" ? "none" : plan.server.decision;
|
|
392
394
|
}
|
|
393
|
-
return decision?.verdict ?? "none";
|
|
395
|
+
return plan.verdict ?? decision?.verdict ?? "none";
|
|
394
396
|
}
|
|
395
397
|
/**
|
|
396
398
|
* After the answer is out, on this computer only: the speed numbers, an
|
package/dist/cliHookDecide.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ import { type EnvKind } from "./cliHookEnvironment.js";
|
|
|
20
20
|
import { type GuardClient, type GuardDecision } from "./cliHookGuard.js";
|
|
21
21
|
import type { HookMode } from "./cliHookMode.js";
|
|
22
22
|
import type { CachedCliPolicy } from "./cliPolicy.js";
|
|
23
|
+
import { type OfflineNote } from "./cliGuardState.js";
|
|
23
24
|
export declare const CLI_DECIDE_PATH = "/api/my/cli/decide";
|
|
24
25
|
export type CliDecideRequest = {
|
|
25
26
|
runtime: string;
|
|
@@ -61,20 +62,31 @@ export type GuardPlan = {
|
|
|
61
62
|
output: Record<string, unknown> | null;
|
|
62
63
|
server: ServerDecision | null;
|
|
63
64
|
offline: boolean;
|
|
65
|
+
/** Offline: what this computer decided in place of the local Ask. */
|
|
66
|
+
verdict?: GuardDecision["verdict"];
|
|
64
67
|
};
|
|
65
68
|
/** Codex can't ask from a hook, so an ask it read is recorded as the block it was. */
|
|
66
69
|
export declare function codexAskBlocked<T extends {
|
|
67
70
|
runtime: string;
|
|
68
71
|
decision?: string;
|
|
69
72
|
}>(report: T | null): T | null;
|
|
73
|
+
export type OfflineVerdict = {
|
|
74
|
+
verdict: GuardDecision["verdict"];
|
|
75
|
+
note: OfflineNote;
|
|
76
|
+
};
|
|
70
77
|
/**
|
|
71
78
|
* When Passport can't be reached (Batch A): the person's setting for the
|
|
72
79
|
* action's environment, from a policy synced in the last 7 days, else the
|
|
73
|
-
* built-in
|
|
74
|
-
*
|
|
75
|
-
*
|
|
80
|
+
* built-in default (Ask everywhere). It only ever sees a local Ask that needed
|
|
81
|
+
* Passport; anything else stands as decided. Someone else's approval is never
|
|
82
|
+
* possible offline; Run never covers an irreversible action or anything the
|
|
83
|
+
* team requires; and an Ask nobody can answer (unattended, or Codex) blocks.
|
|
76
84
|
*/
|
|
77
|
-
export declare function offlineVerdict(decision: GuardDecision, policy: CachedCliPolicy | null,
|
|
85
|
+
export declare function offlineVerdict(decision: GuardDecision, policy: CachedCliPolicy | null, context: {
|
|
86
|
+
client: GuardClient;
|
|
87
|
+
secondPerson: boolean;
|
|
88
|
+
attended: boolean;
|
|
89
|
+
}, now: number): OfflineVerdict;
|
|
78
90
|
/**
|
|
79
91
|
* Attended, or no v2 policy: the local decision, printed at once. Unattended
|
|
80
92
|
* ask: the server decides within the budget, and an approval request replaces
|