passport-bridge 0.16.0 → 0.16.1
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 -13
- package/dist/bridgeExchange.d.ts +11 -1
- package/dist/bridgeExchange.js +12 -1
- package/dist/cliArgs.js +1 -0
- package/dist/cliAutopilot.d.ts +2 -0
- package/dist/cliAutopilot.js +4 -0
- package/dist/cliClient.js +2 -1
- package/dist/cliExec.js +2 -1
- package/dist/cliInit.d.ts +12 -1
- package/dist/cliInit.js +43 -10
- package/dist/cliKeys.js +8 -3
- package/dist/cliLoosening.d.ts +34 -0
- package/dist/cliLoosening.js +107 -0
- package/dist/cliOutput.d.ts +10 -1
- package/dist/cliOutput.js +60 -3
- package/dist/cliSupport.d.ts +9 -0
- package/dist/cliSupport.js +25 -0
- package/dist/completion.js +1 -1
- package/dist/initKeysStep.js +17 -2
- package/dist/initUi.d.ts +43 -2
- package/dist/initUi.js +174 -32
- package/dist/passport.js +4 -7
- package/dist/pluginPin.d.ts +1 -1
- package/dist/pluginPin.js +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -48,7 +48,7 @@ passport run github_search_issues '{"query":"SSO"}'
|
|
|
48
48
|
|
|
49
49
|
| Command | Purpose |
|
|
50
50
|
| --- | --- |
|
|
51
|
-
| `init [--yes] [--no-open] [--cloud <origin>] [--skip-apps\|--skip-agents\|--skip-guard] [--verbose] [--json]` | Set up Passport for this computer's agents in one pass. Every step asks first, can be skipped, and is safe to run again. |
|
|
51
|
+
| `init [--yes] [--move-keys] [--no-open] [--cloud <origin>] [--skip-apps\|--skip-agents\|--skip-guard] [--verbose] [--json]` | Set up Passport for this computer's agents in one pass. Every step asks first, can be skipped, and is safe to run again. |
|
|
52
52
|
| `login` | Browser sign-in or sign-up (or device sign-in with `--workspace`); saves a rotating CLI credential and makes the profile active. |
|
|
53
53
|
| `logout` | Revoke the credential and always remove the local profile (warns if revocation fails). |
|
|
54
54
|
| `profiles` / `use <name>` | List stored profiles / select the active one. Offline. |
|
|
@@ -124,19 +124,21 @@ Reads agent MCP configs (Claude Desktop, Claude Code, Cursor, VS Code, Codex), C
|
|
|
124
124
|
|
|
125
125
|
```sh
|
|
126
126
|
npx passport-bridge@latest init # or: passport init
|
|
127
|
-
npx passport-bridge@latest init --yes # accept every default; needed without a terminal
|
|
127
|
+
npx passport-bridge@latest init --yes # accept every default; needed without a terminal. Keys stay put
|
|
128
|
+
npx passport-bridge@latest init --yes --move-keys # also move CLI keys into Passport and sign those CLIs out
|
|
128
129
|
npx passport-bridge@latest init --yes --json # one summary object with each step's status
|
|
129
130
|
```
|
|
130
131
|
|
|
131
|
-
|
|
132
|
+
Eight steps, each reusing the command that owns it:
|
|
132
133
|
|
|
133
134
|
1. **Scan**: the same local scan as `passport scan`, as one summary line (`--verbose` prints the table).
|
|
134
135
|
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`.
|
|
135
136
|
3. **Apps**: Railway, Vercel, Supabase, Cloudflare, GitHub, and Stripe, when the scan found a key or its CLI is on PATH. Missing apps are added through the same catalog rules as the web (an app your workspace reviews first says `! Stripe needs approval from your admin.`), then one sign-in page covers the rest. In a terminal init waits until they connect (Enter stops waiting); without one it prints the page and `Next: passport connect --wait 300` and moves on.
|
|
136
|
-
4. **
|
|
137
|
-
5. **
|
|
138
|
-
6. **
|
|
139
|
-
7. **
|
|
137
|
+
4. **Keys**: for each CLI sign-in on this computer, the same question as `passport keys move`: `Store your Railway account token in Passport and sign the Railway CLI out on this computer? [y/n]`. It has no default: Enter asks again (`Type y or n.`). `--yes` never moves a key: the step prints `Keys stayed on this computer. Run passport keys move to move them.` Add `--move-keys` to move every key it finds unasked; the closing summary then says which (`Moved your Railway key into Passport and signed that CLI out on this computer.`). Quiet when there's nothing to move.
|
|
138
|
+
5. **Environments**: the environments Passport has placed for your apps, each with its kind: `Found 3 environments: production (Railway), preview (Vercel), qa (Railway)`. Anything Passport can't place counts as Production; change it any time in Rules. With no app connected yet it says `Environments appear once an app is connected.`
|
|
139
|
+
6. **Agents**: Passport's one MCP URL with this workspace as its hint (`https://passportmcp.com/mcp?ws=<workspace>`), with each agent's own browser sign-in; a server that doesn't serve `/mcp` yet (read from its OAuth protected-resource metadata) gets the workspace's own URL (`https://<host>/w/<workspace>/mcp`). An existing entry at either URL for this workspace counts as set up, so no token lands in a config file. Claude Code and Codex through their own CLIs (`claude mcp add --transport http --scope user`, `codex mcp add --url`), Cursor through `~/.cursor/mcp.json`, VS Code through `code --add-mcp` or its user `mcp.json`. Claude Desktop connects through Settings → Connectors, so init prints that step.
|
|
140
|
+
7. **Guard**: asks `Apply your Autopilot rules before each shell command in <agents>? [Y/n]`, then runs `passport hook install --guard` for Claude Code, Codex, and Cursor (Codex: blocks only), pointing at a stable copy of the CLI in `$PASSPORT_HOME/cli/<version>/` (never npm's cache), or at a global `passport-bridge` of the same version or newer. Once the new copy is in place, older copies are deleted unless a hook still runs them.
|
|
141
|
+
8. **Autopilot**: how much agents can do on their own, per environment:
|
|
140
142
|
|
|
141
143
|
```
|
|
142
144
|
Autopilot How much can agents do on their own?
|
|
@@ -160,7 +162,7 @@ What changes on disk, and how to undo it:
|
|
|
160
162
|
| VS Code user `mcp.json` | `servers.passport` | `MCP: List Servers`, then remove it |
|
|
161
163
|
| `~/.claude/settings.json`, `~/.codex/hooks.json`, `~/.cursor/hooks.json` | Passport's audit and guard hooks | `passport hook uninstall --client <agent> --apply` |
|
|
162
164
|
|
|
163
|
-
Before editing a file it didn't create, init says which file and keeps one copy of the original as `<file>.passport-backup`. It changes only Passport's own entries, writes atomically, refuses a malformed file with one line, and leaves an existing Passport entry alone unless it points at npm's cache or a file that's gone. Ctrl-C at any point stops cleanly; run init again to pick up where it left off. Without a terminal, `init` needs `--yes` (exit 6 otherwise), and `--json` needs `--yes`. It never edits your shell profile: it prints the one `PATH` line to add if you want `passport` everywhere.
|
|
165
|
+
Before editing a file it didn't create, init says which file and keeps one copy of the original as `<file>.passport-backup`. It changes only Passport's own entries, writes atomically, refuses a malformed file with one line, and leaves an existing Passport entry alone unless it points at npm's cache or a file that's gone. Ctrl-C at any point stops cleanly; run init again to pick up where it left off. A question only takes keys typed after it appears, so an Enter pressed during a pause never answers it. Any wait longer than a moment shows what it's for in the step's row (`Sign in Checking your sign-in…`); off a terminal nothing extra prints. If Passport can't be reached, init says `Couldn't reach Passport at <origin>. Check your connection, then run passport init again.` and exits 1. Without a terminal, `init` needs `--yes` (exit 6 otherwise), and `--json` needs `--yes`. It never edits your shell profile: it prints the one `PATH` line to add if you want `passport` everywhere.
|
|
164
166
|
|
|
165
167
|
### Company rollout
|
|
166
168
|
|
|
@@ -258,19 +260,19 @@ passport env # or: passport env set railway qa staging
|
|
|
258
260
|
- `wait` long-polls `GET /api/my/approvals/<id>/wait`. Approved: `Approved by Ramish. Run the command again.` (exit 0). Declined: the note for the agent, `Declined by Ramish: <note>` (exit 5, cause `approval_denied`). Expired: `Expired. The agent can ask again.` (exit 5, cause `approval_expired`). Still waiting at `--timeout` (default 100 seconds, under an agent's 2-minute command limit): exit 4 with the same command as `next`.
|
|
259
261
|
- `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.
|
|
260
262
|
- `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.
|
|
261
|
-
- `status` adds `Answered for you: N prompts today` (allows the hook gave in Claude Code and Cursor, and Codex commands Passport synced, counted only when the agent would have prompted) and which agents' allowlists are synced. Counts are appended locally (`$PASSPORT_HOME/answered/`) and sent in batches at most every five minutes as `answered: {batch, count}` on `POST /api/my/cli-activity`.
|
|
263
|
+
- `status` adds `Answered for you: N prompts today` (allows the hook gave in Claude Code and Cursor, and Codex commands Passport synced, counted only when the agent would have prompted) and which agents' allowlists are synced. 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`.
|
|
262
264
|
- `rules test`, `sessions`, and `sync` need a member profile. `wait` also works for a cloud agent's key, on the approval its own `passport exec` opened.
|
|
263
265
|
|
|
264
266
|
### Keys and passport exec
|
|
265
267
|
|
|
266
268
|
```sh
|
|
267
|
-
passport keys move # confirm each key, store it in Passport, sign that CLI out here
|
|
269
|
+
passport keys move # confirm each key [y/n], store it in Passport, sign that CLI out here
|
|
268
270
|
passport keys # what Passport holds, and what's still on this computer
|
|
269
271
|
passport keys add railway # store a key you paste (stdin, never echoed)
|
|
270
272
|
passport exec -- railway up -e staging
|
|
271
273
|
```
|
|
272
274
|
|
|
273
|
-
- `keys move` finds CLI sign-ins (Railway, GitHub CLI, Vercel, Wrangler API tokens, Supabase, Stripe test keys, the AWS `default` profile) and tokens in Claude Code's settings `env`. For each it asks, stores the key in Passport (`POST /api/my/keys`), then signs that CLI out with its own command (`railway logout`, `gh auth logout`, `vercel logout`, `wrangler logout`, `supabase logout`, `stripe logout`) or removes only that entry. A sign-out that fails leaves the key in Passport and says what's left on disk. `.env` files are never touched: "Used by your app, so Passport leaves it." Browser-session sign-ins (Railway, Vercel, Wrangler OAuth) can't move; the line says how to make a token instead. From the CLI, a different key than the one already in Passport is refused; rotate it in Apps. The scan report sent afterwards carries provider counts only.
|
|
275
|
+
- `keys move` finds CLI sign-ins (Railway, GitHub CLI, Vercel, Wrangler API tokens, Supabase, Stripe test keys, the AWS `default` profile) and tokens in Claude Code's settings `env`. For each it asks `[y/n]` with no default (an empty answer asks again; `--yes` moves them all), stores the key in Passport (`POST /api/my/keys`), then signs that CLI out with its own command (`railway logout`, `gh auth logout`, `vercel logout`, `wrangler logout`, `supabase logout`, `stripe logout`) or removes only that entry. A sign-out that fails leaves the key in Passport and says what's left on disk. `.env` files are never touched: "Used by your app, so Passport leaves it." Browser-session sign-ins (Railway, Vercel, Wrangler OAuth) can't move; the line says how to make a token instead. From the CLI, a different key than the one already in Passport is refused; rotate it in Apps. The scan report sent afterwards carries provider counts only.
|
|
274
276
|
- `exec -- <cli> …` runs railway, gh, vercel, wrangler, supabase, stripe, aws, neonctl, or flyctl from PATH. It classifies the command here, asks `POST /api/my/exec/authorize`, and on allow sets only that vendor's variables (`GH_TOKEN`, `RAILWAY_API_TOKEN`, `VERCEL_TOKEN`, `CLOUDFLARE_API_TOKEN`, `SUPABASE_ACCESS_TOKEN`, `STRIPE_API_KEY`, `AWS_*`, `NEON_API_KEY`, `FLY_API_TOKEN`) in the child's environment, removing Passport's own and any stray vendor tokens. Output and exit code pass through. Afterwards it reports the exit code and duration (`POST /api/my/exec/result`, best effort, two seconds at most) so the session row reads Ran or Failed. It refuses paths, shells, `env`, and subcommands that would print the key, sign in again, mint longer-lived tokens, or run another program with the key (`railway run`, `gh auth`, gh extensions, `aws configure`, `vercel dev`, `fly tokens`).
|
|
275
277
|
- Asks wait for your approval in Passport (web or push) when you're at the keyboard or with `--wait <sec>`; otherwise exit 4 with the approval id: run `passport wait <id>`, then the command again. An approval is used once. Blocked or declined: exit 5. No key, or it stopped working: exit 3 ("Your Railway key in Passport stopped working. Update it in Apps."). Offline: exit 1, nothing runs, and exec never uses a key on this computer instead.
|
|
276
278
|
- In Claude Code, the guard rewrites a plain vendor command whose key is in Passport to `passport exec` (PreToolUse `updatedInput` with allow; a block stays a deny). When the rules ask, or someone is at the keyboard, the rewrite adds `--wait 120`, so the agent holds while the person approves: "Approve it on your phone or in Passport." Codex and Cursor get no rewrite: use `passport exec` there.
|
|
@@ -396,7 +398,7 @@ With `--json`, stdout is exactly one JSON value; hints and warnings go to stderr
|
|
|
396
398
|
| `profiles` | `{profiles:[{name,active,client?}],active?}` |
|
|
397
399
|
| `use` | `{profile,active:true}` |
|
|
398
400
|
| `logout` | `{profile,removed,revoked}` |
|
|
399
|
-
| `status` | `{workspace,member,endpoint,auth,profile?,client,mcps,autopilot?:{presets,floors,floorReason?,cache:{version,fetchedAt,ageMs}},next?}` |
|
|
401
|
+
| `status` | `{workspace,member,endpoint,auth,profile?,client,mcps,autopilot?:{presets,floors,floorReason?,exceptions?,cache:{version,fetchedAt,ageMs}},next?}` |
|
|
400
402
|
| `wait` | `{approvalId,status:"approved",scope?,message}`; declined, expired, and still-waiting are errors with `approvalId` |
|
|
401
403
|
| `rules` | `{command,decision,cause?,explanation?,environment?,environmentAssumed?,actionClass?,source}` |
|
|
402
404
|
| `sessions` | `{sessions:[{id,client,folder,status,startedAt,lastActivityAt,counts,environments,waiting}],nextCursor}` |
|
|
@@ -421,7 +423,7 @@ Errors: `{"error":"...","cause":"blocked","exitCode":5,"app":"github"}`, optiona
|
|
|
421
423
|
| Exit | Meaning |
|
|
422
424
|
| ---: | --- |
|
|
423
425
|
| 0 | Success |
|
|
424
|
-
| 1 | Network, timeout, server, or unsupported-content error |
|
|
426
|
+
| 1 | Network, timeout, server, or unsupported-content error. When Passport can't be reached: `Passport couldn't be reached at <host>. Check your connection and try again.` |
|
|
425
427
|
| 2 | Missing, expired, or revoked authentication |
|
|
426
428
|
| 3 | App needs member sign-in |
|
|
427
429
|
| 4 | Approval pending (including `wait` still waiting at its timeout) |
|
package/dist/bridgeExchange.d.ts
CHANGED
|
@@ -21,14 +21,23 @@ export type ExchangeRetryPolicy = {
|
|
|
21
21
|
budgetMs: number;
|
|
22
22
|
};
|
|
23
23
|
export declare const DEFAULT_EXCHANGE_RETRY: ExchangeRetryPolicy;
|
|
24
|
+
/** A one-shot CLI command: a couple of quick retries, then one clear line.
|
|
25
|
+
* The next command still lands inside the server's grace window. */
|
|
26
|
+
export declare const CLI_EXCHANGE_RETRY: ExchangeRetryPolicy;
|
|
27
|
+
/** A token exchange is one small request. A CLI attempt that hasn't answered
|
|
28
|
+
* by now is retried instead of holding the command for the full deadline. */
|
|
29
|
+
export declare const CLI_EXCHANGE_ATTEMPT_MS = 10000;
|
|
24
30
|
export type TokenManagerOptions = {
|
|
25
31
|
/** Defaults to DEFAULT_EXCHANGE_RETRY for rotating managers and no retry
|
|
26
32
|
* for non-rotating ones, whose failures are never ambiguous. */
|
|
27
33
|
retry?: ExchangeRetryPolicy;
|
|
28
34
|
/** Keep the process alive while waiting to retry. A serving bridge sets
|
|
29
35
|
* this so a startup retry is never cut short; one-shot CLI commands leave
|
|
30
|
-
* it off so a pending retry cannot hold a finished command open
|
|
36
|
+
* it off so a pending retry cannot hold a finished command open (the CLI
|
|
37
|
+
* keeps itself alive until its command settles). */
|
|
31
38
|
keepAliveDuringRetry?: boolean;
|
|
39
|
+
/** Don't log retries to stderr. The CLI prints one line when it gives up. */
|
|
40
|
+
quietRetries?: boolean;
|
|
32
41
|
};
|
|
33
42
|
/**
|
|
34
43
|
* Holds the long-lived refresh token and mints short-lived access tokens
|
|
@@ -57,6 +66,7 @@ export declare class TokenManager {
|
|
|
57
66
|
private tenantFlipLogged;
|
|
58
67
|
private readonly retry;
|
|
59
68
|
private readonly keepAliveDuringRetry;
|
|
69
|
+
private readonly quietRetries;
|
|
60
70
|
/**
|
|
61
71
|
* @param onRotate durably persist a rotated refresh token before its access
|
|
62
72
|
* token is usable. Rejection leaves the child pending for local retry.
|
package/dist/bridgeExchange.js
CHANGED
|
@@ -36,6 +36,15 @@ export const DEFAULT_EXCHANGE_RETRY = Object.freeze({
|
|
|
36
36
|
delaysMs: Object.freeze([1_000, 2_000, 4_000, 8_000, 16_000, 32_000, 60_000]),
|
|
37
37
|
budgetMs: 4 * 60_000
|
|
38
38
|
});
|
|
39
|
+
/** A one-shot CLI command: a couple of quick retries, then one clear line.
|
|
40
|
+
* The next command still lands inside the server's grace window. */
|
|
41
|
+
export const CLI_EXCHANGE_RETRY = Object.freeze({
|
|
42
|
+
delaysMs: Object.freeze([1_000, 2_000]),
|
|
43
|
+
budgetMs: 5_000
|
|
44
|
+
});
|
|
45
|
+
/** A token exchange is one small request. A CLI attempt that hasn't answered
|
|
46
|
+
* by now is retried instead of holding the command for the full deadline. */
|
|
47
|
+
export const CLI_EXCHANGE_ATTEMPT_MS = 10_000;
|
|
39
48
|
const NO_EXCHANGE_RETRY = Object.freeze({ delaysMs: Object.freeze([]), budgetMs: 0 });
|
|
40
49
|
/** An exchange failure that may have been committed server-side, or is
|
|
41
50
|
* simply transient. Carries the original error so callers see the same
|
|
@@ -120,6 +129,7 @@ export class TokenManager {
|
|
|
120
129
|
tenantFlipLogged = false;
|
|
121
130
|
retry;
|
|
122
131
|
keepAliveDuringRetry;
|
|
132
|
+
quietRetries;
|
|
123
133
|
/**
|
|
124
134
|
* @param onRotate durably persist a rotated refresh token before its access
|
|
125
135
|
* token is usable. Rejection leaves the child pending for local retry.
|
|
@@ -143,6 +153,7 @@ export class TokenManager {
|
|
|
143
153
|
this.homeWorkspace = workspaceOfToken(refreshToken);
|
|
144
154
|
this.retry = options.retry ?? (onRotate ? DEFAULT_EXCHANGE_RETRY : NO_EXCHANGE_RETRY);
|
|
145
155
|
this.keepAliveDuringRetry = options.keepAliveDuringRetry === true;
|
|
156
|
+
this.quietRetries = options.quietRetries === true;
|
|
146
157
|
}
|
|
147
158
|
/** The refresh token this process last presented or adopted. In-process
|
|
148
159
|
* only: never log it. Recovery correlates with it and self-heal compares
|
|
@@ -313,7 +324,7 @@ export class TokenManager {
|
|
|
313
324
|
if (delay === undefined || this.requestSignal?.aborted || Date.now() - started + delay > this.retry.budgetMs) {
|
|
314
325
|
throw error.original;
|
|
315
326
|
}
|
|
316
|
-
if (retries === 0)
|
|
327
|
+
if (retries === 0 && !this.quietRetries)
|
|
317
328
|
log("token exchange did not complete; retrying within the rotation grace window");
|
|
318
329
|
retries++;
|
|
319
330
|
await sleepFor(delay, this.requestSignal, this.keepAliveDuringRetry);
|
package/dist/cliArgs.js
CHANGED
|
@@ -50,6 +50,7 @@ const FLAGS = {
|
|
|
50
50
|
"skip-apps": { kind: "boolean", commands: ["init"] },
|
|
51
51
|
"skip-agents": { kind: "boolean", commands: ["init"] },
|
|
52
52
|
"skip-guard": { kind: "boolean", commands: ["init"] },
|
|
53
|
+
"move-keys": { kind: "boolean", commands: ["init"] },
|
|
53
54
|
app: { kind: "value", commands: ["search"] },
|
|
54
55
|
args: { kind: "value", commands: ["run"] },
|
|
55
56
|
set: { kind: "repeat", commands: ["run", "prompts"] },
|
package/dist/cliAutopilot.d.ts
CHANGED
|
@@ -57,6 +57,8 @@ export type AutopilotStatus = {
|
|
|
57
57
|
presets: (Record<EnvKind, Preset> & Partial<Record<PresetRow, Preset>>) | null;
|
|
58
58
|
floors: Partial<Record<PresetRow, Preset | null>> | null;
|
|
59
59
|
floorReason?: string;
|
|
60
|
+
/** One line per exception that lets something run your presets would ask about. */
|
|
61
|
+
exceptions?: string[];
|
|
60
62
|
cache: {
|
|
61
63
|
version: 1 | 2 | null;
|
|
62
64
|
fetchedAt: number | null;
|
package/dist/cliAutopilot.js
CHANGED
|
@@ -20,6 +20,7 @@ import { NODE_LINK_FS } from "./envLinkFs.js";
|
|
|
20
20
|
import { resolveTarget } from "./envResolve.js";
|
|
21
21
|
// `passport env` lives in cliEnv.ts; the dispatcher reaches it through here.
|
|
22
22
|
export { env } from "./cliEnv.js";
|
|
23
|
+
import { looseningLines } from "./cliLoosening.js";
|
|
23
24
|
import { readCliPolicy } from "./cliPolicy.js";
|
|
24
25
|
import { callerFrom, failure, readBoundedJson, resolveCliAuth, safeApiError, sanitize, sleep, timeoutMs } from "./cliSupport.js";
|
|
25
26
|
/** Long enough to be useful, short enough for an agent's default 2-minute
|
|
@@ -474,12 +475,14 @@ export async function autopilotStatus(fetchApi, profile, signal, now = Date.now(
|
|
|
474
475
|
floors[row] = isPresetName(floor) ? floor : null;
|
|
475
476
|
}
|
|
476
477
|
const reason = text(body.floors?.reason, 120);
|
|
478
|
+
const exceptions = looseningLines(body);
|
|
477
479
|
const answered = await answeredStatus(fetchApi, profile, signal, now);
|
|
478
480
|
const allowlists = await allowlistStatus();
|
|
479
481
|
return {
|
|
480
482
|
presets: presetMap(body.presets),
|
|
481
483
|
floors,
|
|
482
484
|
...(reason ? { floorReason: reason } : {}),
|
|
485
|
+
...(exceptions.length ? { exceptions } : {}),
|
|
483
486
|
cache,
|
|
484
487
|
...(answered ? { answered } : {}),
|
|
485
488
|
...(allowlists ? { allowlists } : {})
|
|
@@ -498,6 +501,7 @@ export function autopilotLines(status) {
|
|
|
498
501
|
const floors = PRESET_ROWS.filter((row) => status.floors?.[row]).map((row) => `${rowLabel(row)} at least ${PRESET_LABEL[status.floors[row]]}`);
|
|
499
502
|
if (floors.length)
|
|
500
503
|
lines.push(`Team floors: ${floors.join(" · ")}${status.floorReason ? ` (${sanitize(status.floorReason)})` : ""}`);
|
|
504
|
+
lines.push(...(status.exceptions ?? []));
|
|
501
505
|
}
|
|
502
506
|
const { cache } = status;
|
|
503
507
|
lines.push(cache.fetchedAt === null
|
package/dist/cliClient.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
2
|
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
3
3
|
import { TokenManager } from "./bridge.js";
|
|
4
|
+
import { CLI_EXCHANGE_ATTEMPT_MS, CLI_EXCHANGE_RETRY } from "./bridgeExchange.js";
|
|
4
5
|
import { persistCurrentProfileRotation, recoverProfileRotation, withProfileLock } from "./credentials.js";
|
|
5
6
|
import { VERSION } from "./version.js";
|
|
6
7
|
import { SERVER_TOO_OLD } from "./cliProtocol.js";
|
|
@@ -53,7 +54,7 @@ function authedFetchFor(options) {
|
|
|
53
54
|
const manager = new TokenManager(endpoint, options.auth.refreshToken, (next, previous) => persistCurrentProfileRotation(profile, previous, next, endpoint), {
|
|
54
55
|
reload: () => recoverProfileRotation(profile)?.refreshToken,
|
|
55
56
|
lock: (fn) => withProfileLock(profile, fn)
|
|
56
|
-
}, options.timeoutMs, options.signal);
|
|
57
|
+
}, Math.min(options.timeoutMs, CLI_EXCHANGE_ATTEMPT_MS), options.signal, fetch, { retry: CLI_EXCHANGE_RETRY, quietRetries: true });
|
|
57
58
|
return decorateFetch(manager.authedFetch, {
|
|
58
59
|
"x-passport-surface": "cli",
|
|
59
60
|
...(options.caller ? { "x-passport-caller": options.caller } : {})
|
package/dist/cliExec.js
CHANGED
|
@@ -22,6 +22,7 @@ import { readFileSync } from "node:fs";
|
|
|
22
22
|
import { basename, dirname, join, resolve } from "node:path";
|
|
23
23
|
import { bool, value } from "./cliArgs.js";
|
|
24
24
|
import { memberApi } from "./cliClient.js";
|
|
25
|
+
import { passportUnreachable } from "./cliOutput.js";
|
|
25
26
|
import { classifyCommand } from "./cliHookClassify.js";
|
|
26
27
|
import { reportedEnvironment } from "./cliHookEnvironment.js";
|
|
27
28
|
import { localMachine } from "./cliHookLocal.js";
|
|
@@ -190,7 +191,7 @@ async function post(client, body, runtime, ms, binary) {
|
|
|
190
191
|
if (runtime.signal.aborted)
|
|
191
192
|
throw error;
|
|
192
193
|
const message = error instanceof Error ? error.message : "";
|
|
193
|
-
if (/token exchange failed|invalid_or_revoked|unauthori[sz]ed/i.test(message)) {
|
|
194
|
+
if (!passportUnreachable(error) && /token exchange failed|invalid_or_revoked|unauthori[sz]ed/i.test(message)) {
|
|
194
195
|
return failure("Passport refused this sign-in. Nothing ran.", 2, "auth", { hint: "Run: passport login" });
|
|
195
196
|
}
|
|
196
197
|
return offline(binary);
|
package/dist/cliInit.d.ts
CHANGED
|
@@ -10,6 +10,17 @@ import { APP_LABELS, INIT_APPS, PASSPORT_CLOUD, type Gateway, type AutopilotView
|
|
|
10
10
|
import { InitScreen, type InitTerminal } from "./initUi.js";
|
|
11
11
|
import { type ScanResult } from "./scan.js";
|
|
12
12
|
export { APP_LABELS, INIT_APPS, PASSPORT_CLOUD, type InitApp, type InitDependencies, type StepStatus };
|
|
13
|
+
/** What each step shows while it waits on Passport, a CLI, or a file. */
|
|
14
|
+
declare const STEP_ACTIVITY: {
|
|
15
|
+
readonly scan: "Looking for keys your agents can reach…";
|
|
16
|
+
readonly signIn: "Checking your sign-in…";
|
|
17
|
+
readonly apps: "Checking your apps…";
|
|
18
|
+
readonly keys: "Looking for CLI sign-ins on this computer…";
|
|
19
|
+
readonly environments: "Finding your environments…";
|
|
20
|
+
readonly agents: "Checking your agents…";
|
|
21
|
+
readonly guard: "Checking the guard…";
|
|
22
|
+
readonly autopilot: "Reading your Autopilot settings…";
|
|
23
|
+
};
|
|
13
24
|
export declare class Init implements InitSession {
|
|
14
25
|
readonly args: ParsedArgs;
|
|
15
26
|
readonly runtime: Runtime;
|
|
@@ -48,7 +59,7 @@ export declare class Init implements InitSession {
|
|
|
48
59
|
run(): Promise<CommandResult>;
|
|
49
60
|
contactOrigin(): string;
|
|
50
61
|
step: string;
|
|
51
|
-
soft(step:
|
|
62
|
+
soft(step: keyof typeof STEP_ACTIVITY, label: string, run: () => Promise<void>): Promise<void>;
|
|
52
63
|
finish(): CommandResult;
|
|
53
64
|
scanStep(): void;
|
|
54
65
|
appsOnPath(seed: InitApp[]): InitApp[];
|
package/dist/cliInit.js
CHANGED
|
@@ -13,10 +13,11 @@ import { homedir } from "node:os";
|
|
|
13
13
|
import { bool, value } from "./cliArgs.js";
|
|
14
14
|
import { managePayload } from "./cliConnect.js";
|
|
15
15
|
import { login } from "./cliLogin.js";
|
|
16
|
-
import { asFailure } from "./cliOutput.js";
|
|
16
|
+
import { asFailure, passportUnreachable } from "./cliOutput.js";
|
|
17
17
|
import { renderScan } from "./cliScan.js";
|
|
18
18
|
import { cloudOrigin, endpoint, failure, selfCommand } from "./cliSupport.js";
|
|
19
19
|
import { isCliProfile, readActiveProfile, readCreds, setActiveProfile } from "./credentials.js";
|
|
20
|
+
import { EXEC_VENDOR_NAMES } from "./execVendors.js";
|
|
20
21
|
import { AGENT_NAMES } from "./initAgents.js";
|
|
21
22
|
import { appsStep } from "./initAppsStep.js";
|
|
22
23
|
import { findOnPath, pathLine } from "./initInstall.js";
|
|
@@ -31,6 +32,17 @@ export { APP_LABELS, INIT_APPS, PASSPORT_CLOUD };
|
|
|
31
32
|
function initArgs(values, booleans = []) {
|
|
32
33
|
return { command: "login", positionals: [], values, repeats: {}, booleans: new Set(booleans) };
|
|
33
34
|
}
|
|
35
|
+
/** What each step shows while it waits on Passport, a CLI, or a file. */
|
|
36
|
+
const STEP_ACTIVITY = {
|
|
37
|
+
scan: "Looking for keys your agents can reach…",
|
|
38
|
+
signIn: "Checking your sign-in…",
|
|
39
|
+
apps: "Checking your apps…",
|
|
40
|
+
keys: "Looking for CLI sign-ins on this computer…",
|
|
41
|
+
environments: "Finding your environments…",
|
|
42
|
+
agents: "Checking your agents…",
|
|
43
|
+
guard: "Checking the guard…",
|
|
44
|
+
autopilot: "Reading your Autopilot settings…"
|
|
45
|
+
};
|
|
34
46
|
export class Init {
|
|
35
47
|
args;
|
|
36
48
|
runtime;
|
|
@@ -102,6 +114,8 @@ export class Init {
|
|
|
102
114
|
this.scanStep();
|
|
103
115
|
this.screen.endStep();
|
|
104
116
|
this.step = "signIn";
|
|
117
|
+
// Every wait from here on says what it's waiting for (STEP_ACTIVITY).
|
|
118
|
+
this.screen.working(STEP_ACTIVITY.signIn, "Sign in");
|
|
105
119
|
if (!(await this.signInStep()))
|
|
106
120
|
return this.finish();
|
|
107
121
|
this.screen.endStep();
|
|
@@ -112,9 +126,11 @@ export class Init {
|
|
|
112
126
|
await this.soft("agents", "Agents", () => agentsStep(this));
|
|
113
127
|
await this.soft("guard", "Guard", () => guardStep(this));
|
|
114
128
|
await this.soft("autopilot", "Autopilot", () => autopilotStep(this));
|
|
129
|
+
this.screen.idle();
|
|
115
130
|
this.outro();
|
|
116
131
|
}
|
|
117
132
|
catch (error) {
|
|
133
|
+
this.screen.idle();
|
|
118
134
|
if (error instanceof InitPaused || this.signal.aborted) {
|
|
119
135
|
this.summary.paused = true;
|
|
120
136
|
this.summary.ok = false;
|
|
@@ -122,13 +138,12 @@ export class Init {
|
|
|
122
138
|
this.screen.outro([`Setup paused. Run ${this.self} init again to pick up where you left off.`]);
|
|
123
139
|
}
|
|
124
140
|
else {
|
|
125
|
-
const failed = asFailure(error);
|
|
126
|
-
const unreachable = failed.cause === "
|
|
127
|
-
/fetch failed|ECONN|ENOTFOUND|EAI_AGAIN|socket|network/i.test(failed.message);
|
|
141
|
+
const failed = asFailure(error, this.contactOrigin());
|
|
142
|
+
const unreachable = passportUnreachable(error) || failed.cause === "timeout";
|
|
128
143
|
const message = unreachable
|
|
129
144
|
? `Couldn't reach Passport at ${this.contactOrigin()}. Check your connection, then run ${this.self} init again.`
|
|
130
145
|
: failed.message;
|
|
131
|
-
this.screen.result("warn", message);
|
|
146
|
+
this.screen.result("warn", message, this.step === "signIn" ? "Sign in" : undefined);
|
|
132
147
|
if (failed.details.hint && !unreachable)
|
|
133
148
|
this.screen.line(failed.details.hint);
|
|
134
149
|
this.summary.ok = false;
|
|
@@ -139,6 +154,7 @@ export class Init {
|
|
|
139
154
|
}
|
|
140
155
|
}
|
|
141
156
|
finally {
|
|
157
|
+
this.screen.idle();
|
|
142
158
|
await this.gateway?.close().catch(() => undefined);
|
|
143
159
|
}
|
|
144
160
|
return this.finish();
|
|
@@ -152,6 +168,7 @@ export class Init {
|
|
|
152
168
|
step = "scan";
|
|
153
169
|
async soft(step, label, run) {
|
|
154
170
|
this.step = step;
|
|
171
|
+
this.screen.working(STEP_ACTIVITY[step], label);
|
|
155
172
|
try {
|
|
156
173
|
await run();
|
|
157
174
|
}
|
|
@@ -159,7 +176,7 @@ export class Init {
|
|
|
159
176
|
if (error instanceof InitPaused || this.signal.aborted)
|
|
160
177
|
throw error;
|
|
161
178
|
const failed = asFailure(error);
|
|
162
|
-
const unreachable =
|
|
179
|
+
const unreachable = passportUnreachable(error) || failed.cause === "timeout";
|
|
163
180
|
const message = unreachable
|
|
164
181
|
? `Couldn't reach Passport. Run ${this.self} init again to finish this step.`
|
|
165
182
|
: failed.message;
|
|
@@ -177,6 +194,8 @@ export class Init {
|
|
|
177
194
|
scanStep() {
|
|
178
195
|
const scan = this.deps.scan ?? runScan;
|
|
179
196
|
const cwd = this.deps.cwd ?? process.cwd();
|
|
197
|
+
// The scan holds the event loop, so its line shows before it starts.
|
|
198
|
+
this.screen.working(STEP_ACTIVITY.scan, "Scan", true);
|
|
180
199
|
try {
|
|
181
200
|
this.scan = scan({ env: this.env, cwd, root: cwd, platform: this.platform });
|
|
182
201
|
}
|
|
@@ -258,11 +277,13 @@ export class Init {
|
|
|
258
277
|
}
|
|
259
278
|
if (prompt.opened) {
|
|
260
279
|
this.screen.line(`Opening your browser. Confirm code ${code}.`, "Sign in");
|
|
261
|
-
return;
|
|
262
280
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
281
|
+
else {
|
|
282
|
+
// A link on its own line stays whole and clickable at any width.
|
|
283
|
+
this.screen.line(`Open this link and confirm code ${code}:`, "Sign in");
|
|
284
|
+
this.screen.line(prompt.verifyUrl);
|
|
285
|
+
}
|
|
286
|
+
this.screen.working("Waiting for you to finish signing in…");
|
|
266
287
|
};
|
|
267
288
|
async runLogin(values, browserOnly) {
|
|
268
289
|
const cloud = this.requestedCloud();
|
|
@@ -436,6 +457,10 @@ export class Init {
|
|
|
436
457
|
lines.push(`${lead} Run ${this.self} init again after you install an agent or add an app.`);
|
|
437
458
|
if (this.autopilotSummary)
|
|
438
459
|
lines.push(this.autopilotSummary);
|
|
460
|
+
// Said in the summary too, since --yes --move-keys moves keys without asking.
|
|
461
|
+
const moved = movedKeysLine(this.summary);
|
|
462
|
+
if (moved)
|
|
463
|
+
lines.push(moved);
|
|
439
464
|
const keys = this.scan?.report.findings.length ?? 0;
|
|
440
465
|
if (keys && (apps.length || signingIn.length)) {
|
|
441
466
|
lines.push("Your old keys still work. Rotate them once your agents don't need them.");
|
|
@@ -463,6 +488,14 @@ export class Init {
|
|
|
463
488
|
this.screen.outro(lines);
|
|
464
489
|
}
|
|
465
490
|
}
|
|
491
|
+
/** "Moved your Railway key into Passport and signed that CLI out on this computer." */
|
|
492
|
+
function movedKeysLine(summary) {
|
|
493
|
+
const moved = (summary.steps.keys?.moved ?? []).map((vendor) => EXEC_VENDOR_NAMES[vendor]);
|
|
494
|
+
if (!moved.length)
|
|
495
|
+
return undefined;
|
|
496
|
+
const one = moved.length === 1;
|
|
497
|
+
return `Moved your ${listOf(moved)} ${one ? "key" : "keys"} into Passport and signed ${one ? "that CLI" : "those CLIs"} out on this computer.`;
|
|
498
|
+
}
|
|
466
499
|
/** `passport init`. */
|
|
467
500
|
export async function init(args, runtime, deps = {}) {
|
|
468
501
|
const problem = oneLinerNodeProblem(deps.nodeVersion);
|
package/dist/cliKeys.js
CHANGED
|
@@ -19,7 +19,7 @@ import { EXEC_TOKEN_PAGES, EXEC_VENDOR_NAMES, execVendorOf } from "./execVendors
|
|
|
19
19
|
import { writeExecVendors } from "./execMarker.js";
|
|
20
20
|
import { findLocalKeys, removeLocalCopy } from "./keysLocal.js";
|
|
21
21
|
import { runScan } from "./scan.js";
|
|
22
|
-
import { listOf, processTerminal } from "./initUi.js";
|
|
22
|
+
import { discardTypeAhead, listOf, processTerminal } from "./initUi.js";
|
|
23
23
|
export const KEYS_PATH = "/api/my/keys";
|
|
24
24
|
const MOVABLE_PROVIDERS = new Set(["Railway", "GitHub", "Vercel", "Cloudflare", "Supabase", "Stripe", "AWS"]);
|
|
25
25
|
const ENV_FILE_LOCATION = /(?:^|\/)\.env[^/ ]*(?: \(|$)/;
|
|
@@ -299,10 +299,12 @@ async function move(args, runtime, deps) {
|
|
|
299
299
|
}
|
|
300
300
|
const summary = await moveKeys({
|
|
301
301
|
api,
|
|
302
|
+
// Signing a CLI out can't be taken back from here: no default, so a
|
|
303
|
+
// stray Enter asks again instead of moving the key.
|
|
302
304
|
confirm: async (question) => {
|
|
303
305
|
for (;;) {
|
|
304
|
-
const answer = (await terminal.question(`${question} [
|
|
305
|
-
if (answer === "
|
|
306
|
+
const answer = (await terminal.question(`${question} [y/n] `, runtime.signal)).trim().toLowerCase();
|
|
307
|
+
if (answer === "y" || answer === "yes")
|
|
306
308
|
return true;
|
|
307
309
|
if (answer === "n" || answer === "no")
|
|
308
310
|
return false;
|
|
@@ -347,6 +349,9 @@ async function readSecret(runtime, prompt) {
|
|
|
347
349
|
}
|
|
348
350
|
return Buffer.concat(chunks).toString("utf8").trim();
|
|
349
351
|
}
|
|
352
|
+
// Keys typed before the prompt aren't part of the key.
|
|
353
|
+
if (await discardTypeAhead(stdin))
|
|
354
|
+
throw new Error("Cancelled.");
|
|
350
355
|
runtime.stderr.write(prompt);
|
|
351
356
|
stdin.setRawMode(true);
|
|
352
357
|
let value = "";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `passport status`: the exceptions that let something run your presets would
|
|
3
|
+
* ask about, in the web's words. The server says which rows each exception
|
|
4
|
+
* loosens (`loosens` on /api/my/autopilot rules); this only words it.
|
|
5
|
+
*
|
|
6
|
+
* Checked copies of shared/autopilotLoosening.ts (the CLI can't import
|
|
7
|
+
* shared/); cliLoosening.test.ts fails if they drift.
|
|
8
|
+
*/
|
|
9
|
+
import { type ActionClass, type PresetRow } from "./cliAutopilotPolicy.js";
|
|
10
|
+
export type LooseningMatch = {
|
|
11
|
+
appKey?: string;
|
|
12
|
+
tool?: string;
|
|
13
|
+
cli?: {
|
|
14
|
+
vendor: string;
|
|
15
|
+
verb: string;
|
|
16
|
+
};
|
|
17
|
+
class?: ActionClass;
|
|
18
|
+
};
|
|
19
|
+
/** What a loosening exception lets run, and its verb: "Deletes" run,
|
|
20
|
+
* "railway redeploy" runs. */
|
|
21
|
+
export declare function looseningSubject(match: LooseningMatch, appName?: (key: string) => string): {
|
|
22
|
+
subject: string;
|
|
23
|
+
verb: "run" | "runs";
|
|
24
|
+
};
|
|
25
|
+
/** "Deletes run in Production and Staging without asking, even without a backup." */
|
|
26
|
+
export declare function looseningLine(match: LooseningMatch, rows: readonly PresetRow[], appName?: (key: string) => string): string;
|
|
27
|
+
/**
|
|
28
|
+
* One line per exception that loosens your presets, from /api/my/autopilot:
|
|
29
|
+
* `! 1 exception: deletes run in Production without asking, even without a backup.`
|
|
30
|
+
*/
|
|
31
|
+
export declare function looseningLines(body: {
|
|
32
|
+
rules?: unknown;
|
|
33
|
+
environmentApps?: unknown;
|
|
34
|
+
}): string[];
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `passport status`: the exceptions that let something run your presets would
|
|
3
|
+
* ask about, in the web's words. The server says which rows each exception
|
|
4
|
+
* loosens (`loosens` on /api/my/autopilot rules); this only words it.
|
|
5
|
+
*
|
|
6
|
+
* Checked copies of shared/autopilotLoosening.ts (the CLI can't import
|
|
7
|
+
* shared/); cliLoosening.test.ts fails if they drift.
|
|
8
|
+
*/
|
|
9
|
+
import { ACTION_CLASSES, PRESET_ROWS } from "./cliAutopilotPolicy.js";
|
|
10
|
+
import { sanitize } from "./cliSupport.js";
|
|
11
|
+
const CLASS_PLURAL = {
|
|
12
|
+
read: "reads",
|
|
13
|
+
change: "changes",
|
|
14
|
+
delete: "deletes",
|
|
15
|
+
irreversible: "irreversible actions"
|
|
16
|
+
};
|
|
17
|
+
const ROW_PLACE = {
|
|
18
|
+
production: "Production",
|
|
19
|
+
staging: "Staging",
|
|
20
|
+
development: "Development",
|
|
21
|
+
other: "other apps"
|
|
22
|
+
};
|
|
23
|
+
function listWords(words) {
|
|
24
|
+
if (words.length <= 2)
|
|
25
|
+
return words.join(" and ");
|
|
26
|
+
return `${words.slice(0, -1).join(", ")}, and ${words[words.length - 1]}`;
|
|
27
|
+
}
|
|
28
|
+
/** What a loosening exception lets run, and its verb: "Deletes" run,
|
|
29
|
+
* "railway redeploy" runs. */
|
|
30
|
+
export function looseningSubject(match, appName = (key) => key) {
|
|
31
|
+
if (match.cli)
|
|
32
|
+
return { subject: `${match.cli.vendor} ${match.cli.verb}`, verb: "runs" };
|
|
33
|
+
if (match.tool)
|
|
34
|
+
return { subject: match.tool.replace(/_/g, " "), verb: "runs" };
|
|
35
|
+
const app = match.appKey ? appName(match.appKey) : undefined;
|
|
36
|
+
const plural = match.class ? CLASS_PLURAL[match.class] : "actions";
|
|
37
|
+
if (app)
|
|
38
|
+
return { subject: `${app} ${plural}`, verb: "run" };
|
|
39
|
+
return { subject: plural.charAt(0).toUpperCase() + plural.slice(1), verb: "run" };
|
|
40
|
+
}
|
|
41
|
+
/** "Deletes run in Production and Staging without asking, even without a backup." */
|
|
42
|
+
export function looseningLine(match, rows, appName) {
|
|
43
|
+
const { subject, verb } = looseningSubject(match, appName);
|
|
44
|
+
const where = listWords(PRESET_ROWS.filter((row) => rows.includes(row)).map((row) => ROW_PLACE[row]));
|
|
45
|
+
const backup = match.class === "delete" ? ", even without a backup" : "";
|
|
46
|
+
return `${subject} ${verb} in ${where} without asking${backup}.`;
|
|
47
|
+
}
|
|
48
|
+
function short(value, max) {
|
|
49
|
+
if (typeof value !== "string")
|
|
50
|
+
return undefined;
|
|
51
|
+
const clean = sanitize(value).trim();
|
|
52
|
+
return clean && clean.length <= max ? clean : undefined;
|
|
53
|
+
}
|
|
54
|
+
/** A rule's match as the server sent it, or undefined when it's malformed. */
|
|
55
|
+
function matchOf(raw) {
|
|
56
|
+
if (!raw || typeof raw !== "object")
|
|
57
|
+
return undefined;
|
|
58
|
+
const source = raw;
|
|
59
|
+
const match = {};
|
|
60
|
+
const appKey = short(source.appKey, 80);
|
|
61
|
+
const tool = short(source.tool, 120);
|
|
62
|
+
if (appKey)
|
|
63
|
+
match.appKey = appKey;
|
|
64
|
+
if (tool)
|
|
65
|
+
match.tool = tool;
|
|
66
|
+
if (source.cli && typeof source.cli === "object") {
|
|
67
|
+
const cli = source.cli;
|
|
68
|
+
const vendor = short(cli.vendor, 40);
|
|
69
|
+
const verb = short(cli.verb, 80);
|
|
70
|
+
if (vendor && verb)
|
|
71
|
+
match.cli = { vendor, verb };
|
|
72
|
+
}
|
|
73
|
+
if (ACTION_CLASSES.includes(source.class))
|
|
74
|
+
match.class = source.class;
|
|
75
|
+
return match;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* One line per exception that loosens your presets, from /api/my/autopilot:
|
|
79
|
+
* `! 1 exception: deletes run in Production without asking, even without a backup.`
|
|
80
|
+
*/
|
|
81
|
+
export function looseningLines(body) {
|
|
82
|
+
const names = new Map();
|
|
83
|
+
if (Array.isArray(body.environmentApps)) {
|
|
84
|
+
for (const app of body.environmentApps) {
|
|
85
|
+
const key = short(app?.key, 80);
|
|
86
|
+
const name = short(app?.name, 80);
|
|
87
|
+
if (key && name)
|
|
88
|
+
names.set(key, name);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const appName = (key) => names.get(key) ?? key;
|
|
92
|
+
const lines = [];
|
|
93
|
+
for (const rule of Array.isArray(body.rules) ? body.rules : []) {
|
|
94
|
+
const rows = Array.isArray(rule?.loosens)
|
|
95
|
+
? rule.loosens.filter((row) => PRESET_ROWS.includes(row))
|
|
96
|
+
: [];
|
|
97
|
+
const match = matchOf(rule?.match);
|
|
98
|
+
if (!rows.length || !match)
|
|
99
|
+
continue;
|
|
100
|
+
lines.push(looseningLine(match, rows, appName));
|
|
101
|
+
}
|
|
102
|
+
// After a colon a class reads lowercase, the way the web's row note says it.
|
|
103
|
+
const lowered = (line) => /^(Changes|Deletes|Irreversible|Actions)\b/.test(line) ? line.charAt(0).toLowerCase() + line.slice(1) : line;
|
|
104
|
+
if (lines.length === 1)
|
|
105
|
+
return [`! 1 exception: ${lowered(lines[0])}`];
|
|
106
|
+
return lines.map((line) => `! Exception: ${lowered(line)}`);
|
|
107
|
+
}
|
package/dist/cliOutput.d.ts
CHANGED
|
@@ -2,6 +2,15 @@ import { type ParsedArgs } from "./cliArgs.js";
|
|
|
2
2
|
import { CliFailure, type CommandResult, type Runtime } from "./cliSupport.js";
|
|
3
3
|
export declare function helpResult(args: ParsedArgs): CommandResult;
|
|
4
4
|
export declare function emitResult(result: CommandResult, args: ParsedArgs, runtime: Runtime): void;
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Passport didn't answer: no connection, a dropped one, or Passport said it
|
|
7
|
+
* was unavailable (a 5xx or 429) while trading the sign-in for a token.
|
|
8
|
+
* Never true for an answer Passport gave on purpose, like a refused sign-in.
|
|
9
|
+
*/
|
|
10
|
+
export declare function passportUnreachable(error: unknown): boolean;
|
|
11
|
+
/** The one line a command prints when Passport can't be reached. */
|
|
12
|
+
export declare function unreachableMessage(origin?: string): string;
|
|
13
|
+
/** `origin` names the Passport the command tried, when it's known. */
|
|
14
|
+
export declare function asFailure(error: unknown, origin?: string): CliFailure;
|
|
6
15
|
export declare function emitFailure(error: CliFailure, json: boolean, quiet: boolean, runtime: Runtime): void;
|
|
7
16
|
export declare function failurePayload(error: CliFailure): Record<string, unknown>;
|