passport-bridge 0.30.1 → 0.31.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 +10 -7
- package/dist/cliAllowances.d.ts +47 -0
- package/dist/cliAllowances.js +89 -0
- package/dist/cliArgs.js +2 -1
- package/dist/cliAutopilot.d.ts +4 -0
- package/dist/cliAutopilot.js +6 -2
- package/dist/cliAutopilotPolicy.d.ts +38 -0
- package/dist/cliAutopilotPolicy.js +29 -10
- package/dist/cliChanges.d.ts +7 -0
- package/dist/cliChanges.js +37 -3
- package/dist/cliExec.d.ts +2 -27
- package/dist/cliExec.js +7 -16
- package/dist/cliGuardState.d.ts +2 -0
- package/dist/cliGuardState.js +5 -3
- package/dist/cliHook.d.ts +1 -5
- package/dist/cliHook.js +51 -48
- package/dist/cliHookAfter.d.ts +74 -0
- package/dist/cliHookAfter.js +155 -0
- package/dist/cliHookAllowance.d.ts +22 -0
- package/dist/cliHookAllowance.js +34 -0
- package/dist/cliHookClassify.d.ts +4 -0
- package/dist/cliHookClassify.js +41 -39
- package/dist/cliHookCreates.d.ts +41 -0
- package/dist/cliHookCreates.js +195 -0
- package/dist/cliHookDecide.d.ts +3 -0
- package/dist/cliHookDecide.js +30 -1
- package/dist/cliHookDeliver.d.ts +33 -0
- package/dist/cliHookDeliver.js +23 -0
- package/dist/cliHookEnvironment.js +22 -9
- package/dist/cliHookGuard.d.ts +13 -0
- package/dist/cliHookGuard.js +20 -15
- package/dist/cliHookInput.d.ts +7 -0
- package/dist/cliHookLease.d.ts +78 -0
- package/dist/cliHookLease.js +216 -0
- package/dist/cliHookLifecycle.d.ts +5 -2
- package/dist/cliHookLifecycle.js +18 -5
- package/dist/cliHookLocal.d.ts +14 -1
- package/dist/cliHookLocal.js +38 -4
- package/dist/cliHookNotice.d.ts +11 -3
- package/dist/cliHookNotice.js +53 -9
- package/dist/cliHookOutcome.d.ts +16 -0
- package/dist/cliHookOutcome.js +53 -0
- package/dist/cliHookParse.d.ts +6 -0
- package/dist/cliHookParse.js +10 -2
- package/dist/cliHookProject.d.ts +2 -0
- package/dist/cliHookProject.js +11 -0
- package/dist/cliHookPushed.d.ts +18 -0
- package/dist/cliHookPushed.js +32 -0
- package/dist/cliHookRewrite.d.ts +22 -0
- package/dist/cliHookRewrite.js +183 -10
- package/dist/cliHookScripts.js +2 -0
- package/dist/cliHookSessionEnd.d.ts +14 -0
- package/dist/cliHookSessionEnd.js +45 -1
- package/dist/cliHookSessionState.d.ts +45 -0
- package/dist/cliHookSessionState.js +130 -0
- package/dist/cliHookSpawn.d.ts +23 -0
- package/dist/cliHookSpawn.js +219 -0
- package/dist/cliHookStuck.d.ts +42 -0
- package/dist/cliHookStuck.js +69 -0
- package/dist/cliHookUncheckedName.d.ts +7 -0
- package/dist/cliHookUncheckedName.js +57 -0
- package/dist/cliHookVendors.d.ts +4 -0
- package/dist/cliHookVendors.js +40 -17
- package/dist/cliHookVendorsMore.js +3 -1
- package/dist/cliLoosening.d.ts +17 -3
- package/dist/cliLoosening.js +72 -10
- package/dist/cliOutput.js +4 -3
- package/dist/cliPolicy.js +3 -1
- package/dist/cliPolicyV2.js +49 -4
- package/dist/cliRequest.d.ts +3 -0
- package/dist/cliRequest.js +5 -0
- package/dist/cliRequestTask.d.ts +22 -0
- package/dist/cliRequestTask.js +87 -0
- package/dist/cliStatus.d.ts +3 -1
- package/dist/cliStatus.js +25 -8
- package/dist/execBackupLine.d.ts +7 -0
- package/dist/execBackupLine.js +16 -0
- package/dist/execLease.d.ts +5 -0
- package/dist/execLease.js +38 -0
- package/dist/hookFastPath.js +7 -0
- package/dist/hookPromptFast.d.ts +2 -1
- package/dist/hookPromptFast.js +11 -8
- package/dist/initAutopilotStep.d.ts +1 -18
- package/dist/initAutopilotStep.js +16 -27
- package/dist/initUi.d.ts +6 -2
- package/dist/initUi.js +12 -3
- package/dist/leaseCommands.d.ts +42 -0
- package/dist/leaseCommands.js +118 -0
- package/dist/localGit.d.ts +7 -0
- package/dist/localGit.js +44 -16
- package/dist/pluginPin.d.ts +1 -1
- package/dist/pluginPin.js +1 -1
- package/dist/repoRules.d.ts +45 -0
- package/dist/repoRules.js +179 -0
- package/dist/sessionBrief.d.ts +27 -0
- package/dist/sessionBrief.js +89 -0
- package/dist/signInFailure.d.ts +28 -0
- package/dist/signInFailure.js +65 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/watchNotice.d.ts +66 -0
- package/dist/watchNotice.js +233 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -115,6 +115,9 @@ passport request linear --reason "Triage this week's bugs"
|
|
|
115
115
|
- `request` files the same request an agent's `passport_request_access` files (`POST /api/my/app-requests`), into the queue admins already answer. It prints `Asked: Full access to GitHub. An admin at Acme decides.` and `Run your command again once it's approved.`; asking again for the same thing says `Already asked`. Where the workspace lets you add the app yourself, or you already have it, it says so and files nothing. `--json` prints `{filed:true,requestId,status,what,created,app}` or `{filed:false,message,app}`.
|
|
116
116
|
- The reason (10 to 280 characters) goes to the admin. Agent tokens can't ask: their owner does. Ten requests an hour per person, shared with agents.
|
|
117
117
|
- A Read-only or No access block names it: `You have read-only access to GitHub in Passport, so only reads run. Ask an admin for full access: passport request github --full --reason "<why>"`, then the app's Access link on the next line.
|
|
118
|
+
- `passport request --task "railway changes in staging, supabase deletes in dev" [--reason "<why>"] [--session <id>]` asks the person, from inside an agent, for what the task needs (`POST /api/my/allowances`). It is one ask with **Approve all** and **Decline**; approved, those actions run without asking until the task ends. Each item is `<app> <changes|deletes> [in <environment>]`; never irreversible actions or Production deletes. The task is `--session`, else the agent's one running task on this computer. `--json` prints `{approvalId,created,allow,link}`.
|
|
119
|
+
|
|
120
|
+
**Task allowances and leases.** cli-policy v2 `allowances` lists the person's allowances in running hook sessions (the agent's own session id, the app's CLIs, class, environment); the guard applies a match after block rules and, before running a command one let through, checks `GET /api/my/cli/session` (300 ms, fail-open) that it wasn't revoked. With `leases: true`, a deploy or migration in Staging or Production takes a lease first (`POST /api/my/leases`, 400 ms, fail-open), holds Claude Code while another session has it, and releases it from the audit hook; `passport exec` renews a long command's lease every 5 minutes.
|
|
118
121
|
|
|
119
122
|
### Resources and prompts
|
|
120
123
|
|
|
@@ -162,12 +165,12 @@ Eight steps, each reusing the command that owns it:
|
|
|
162
165
|
8. **Autopilot**: how much agents can do on their own, per environment:
|
|
163
166
|
|
|
164
167
|
```
|
|
165
|
-
Autopilot Production
|
|
166
|
-
Staging
|
|
167
|
-
Development
|
|
168
|
+
Autopilot Production Ask before changes
|
|
169
|
+
Staging Ask before deletes
|
|
170
|
+
Development Ask only for irreversible
|
|
168
171
|
```
|
|
169
172
|
|
|
170
|
-
The plan shows them once. Step by step asks one
|
|
173
|
+
The plan shows them once. Step by step lists the three choices once, in the words Rules uses, then asks one short question per environment where a choice is left (`Staging (1 to 3) [2]`, Enter keeps it); the recommended setup and `--yes` keep the defaults. A team floor stricter than a default is shown with why (`Your team requires at least "Ask before changes" in Staging.`), and choices below it aren't offered. A CLI credential can only make presets stricter; a looser pick says so in one line and keeps the current ones. A re-run lists them under Done without asking. The closing list says what will ask: `Autopilot on: asks only for Production changes, deletes outside Development, and irreversible actions`. A server without Autopilot gets no rules step (`Autopilot needs a newer Passport server.`); init never writes the retired safety profile.
|
|
171
174
|
|
|
172
175
|
What changes on disk, and how to undo it:
|
|
173
176
|
|
|
@@ -275,7 +278,7 @@ An ask becomes one Activity row. In Claude Code, with the audit hook registered,
|
|
|
275
278
|
|
|
276
279
|
**Guard health** (`src/cliGuardHealth.ts`, states and fixes in `src/cliGuardState.ts`, a checked copy of `shared/guardContract.ts`). `passport hook status` and `passport status` show each agent's guard in the web's words, **On**, **Off**, **Outdated**, **Not trusted**, or **Locked**, and each problem's fix (on a terminal the command goes on its own `Run:` line): `passport hook install --agent <agent> --guard --apply`, `npx passport-bridge@latest init`, or `Open Codex → /hooks and trust Passport's hooks.` At most once a day (`$PASSPORT_HOME/guard/.<profile>.heartbeat`) the CLI sends `POST /api/my/guard-health` with `{cliVersion, launcherTarget?, clients: [{client, present, mode, guard, plugin, codexTrust?, locked?, disabledEnv?}]}`: flags only, never a command, path, or value. It goes from a guard run with at least 300 ms of its budget left (a hook's first one waits a day), from `passport exec`, and from `passport status`. Codex trust (`src/cliCodexTrust.ts`) compares `trusted_hash` in `~/.codex/config.toml` `[hooks.state."<hooks.json>:pre_tool_use:<group>:<handler>"]` with Codex's own hash of Passport's guard entry: SHA-256 of the sorted-key JSON of `{event_name, matcher?, hooks: [{type, command, timeout (600 when unset), async, statusMessage?, additionalContextLimit? (when not 2500)}]}`, as in openai/codex `hook_hash`/`version_for_toml`, checked against codex-cli 0.146.0's `hooks/list`. Missing is **Not trusted**, a different hash is **Not trusted** (modified), `enabled = false` is **Off**. **Locked** means managed settings hold Passport's guard: `/Library/Application Support/ClaudeCode/managed-settings.json` (and `managed-settings.d/`), `/etc/claude-code/…`, `/etc/codex/requirements.toml`, `/Library/Application Support/Cursor/hooks.json`, or `/etc/cursor/hooks.json` (`PASSPORT_MANAGED_ROOT` points tests elsewhere).
|
|
277
280
|
|
|
278
|
-
**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 `
|
|
281
|
+
**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 `Rules could decide 82% of commands Passport saw this week · 1,204 not checked` and a link to those commands on Work (from a server before the buckets: `Checked 94% of commands Passport saw this week`).
|
|
279
282
|
|
|
280
283
|
**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.`
|
|
281
284
|
|
|
@@ -310,7 +313,7 @@ passport actions sync # propose this repository's .passport/actions.toml
|
|
|
310
313
|
- `sessions` lists work items the way the Sessions page does (`GET /api/my/work-items`): a pull request or branch with every session on it rolled up, grouped by project (or, for app connections, by the apps they used). Each item has its agents, then one shape line: actions, active time, failed, confirmed Production changes, unplaced changes, asks with how they ended, blocked, data checks, undone, and the share Passport couldn't check. Notable items come first; the rest fold into `14 routine work items · 3,200 reads · nothing needed you`. `--all` lists every item, `--running` only those with a running session, and `--production-changes` prints the ledger (`GET /api/my/production-ledger`, 7 days unless `--since`): changes to confirmed Production by app and target, then the unplaced count with a link to set environments. `--project`, `--pr`, `--since` (`today`, `24h`, `7d`, `30d`, `90d`, or a date read in local time), and `--status running|ended` go to the server, which applies them to every session in the window, never to a loaded page. The CLI follows up to five pages and then links the rest. `--project <name>` on its own (no lens, `--pr`, or `--status`) opens with the web project page's summary (`GET /api/my/projects/<name>`): sessions and how many run, Environments (the repository's placement, then each platform its changes reached and how many were unplaced), the rules for the apps and scripts it uses, and its Production changes, all over the same window as `--since` (any time without it), then the work list; `--json` adds it as `project` (`{project,link,sinceTs,environments:[{appKey,appName,role,label,kind,source,reached,unplaced}],rules:[{id,kind,label,decision}],moreRules,production:{total,unplaced,apps},totals}`), and a server without the page prints the list alone. A work item with several sessions links to its own page (`#projects/<name>/work?branch=`). Every count the server sends carries its window (`window: {since, until, label}`); the CLI prints the label after the count (`16 work items · … · Last 7 days`) and keeps its own words for an older server. `sessions <id>` reads one session (`GET /api/my/agent-sessions/<id>`): its title, place, agent, and active time; the web page's summary strip (actions, shipped, Production, failed, asked, not checked, undo, data checks); and its 15 latest actions with what each acted on, where it landed, and how it ended. On a terminal parts wrap only between `·` and the timeline stacks when it doesn't fit; piped output never wraps and has no color.
|
|
311
314
|
- `changes` lists every change, delete, and irreversible action that ran on confirmed Production in the window (`GET /api/my/production-changes`), the list Sessions › Production changes shows: grouped by app, newest first, each with its time and command (and what it acted on), then the agent, the person, the pull request (else branch), Failed or Approved, and Undo available, Undone by, or Undo expired. Consecutive alike changes (same command, target, agent, person, repository, and branch) fold into one line, `git push → main ×28` with their span of times, unless one failed, was approved, or has an undo state; `--json` keeps every change. With changes from more than one repository, each line names its repository. Blocked and declined actions never reached Production and aren't listed; unplaced changes are one count with a link to set environments. `--since` takes `1h`, `6h`, `24h`, `7d` (the default), `30d`, `today`, or a date read in local time; `--until` a date; `--project`, `--pr`, `--app`, and `--agent` narrow on the server. `--env` accepts only `production` for now. When the window holds more than one read returns, it says so and links the web page. The deploy and error lanes are web-only.
|
|
312
315
|
- `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`, `init --org`, every rules refresh, and `passport sync`; `hook uninstall`, `sync --remove`, and signing out of the last profile take the entries out.
|
|
313
|
-
- `status` is one screen, like `gh auth status`, with a label per row (`You` with the name you signed in as, `Computer`, `Guard`, `Autopilot`, `Apps`, `Keys`, `Shims`, `This folder`, `Allowlists`, `CLI`); under 60 columns each label gets its own row, and piped it never wraps. `Guard` lists each agent's guard (`✓ Claude Code On`, `! Codex Not trusted`) with its fix on the line under it, the coverage line, and sends the daily guard report when due. It also adds today's speed line, `Passport adds ~20 ms per action and asked you twice today. 412 actions ran on their own.` (across your computers when the server keeps speed numbers, else `(this computer)`), and `Answered for you: N prompts today` (allows the hook gave in Claude Code and Cursor, and Codex commands Passport synced, counted only when the agent would have prompted) and which agents' allowlists are synced. Under
|
|
316
|
+
- `status` is one screen, like `gh auth status`, with a label per row (`You` with the name you signed in as, `Computer`, `Guard`, `Autopilot`, `Apps`, `Keys`, `Shims`, `This folder`, `Allowlists`, `CLI`); under 60 columns each label gets its own row, and piped it never wraps. `Guard` lists each agent's guard (`✓ Claude Code On`, `! Codex Not trusted`) with its fix on the line under it, the coverage line, and sends the daily guard report when due. It also adds today's speed line, `Passport adds ~20 ms per action and asked you twice today. 412 actions ran on their own.` (across your computers when the server keeps speed numbers, else `(this computer)`), and `Answered for you: N prompts today` (allows the hook gave in Claude Code and Cursor, and Codex commands Passport synced, counted only when the agent would have prompted) and which agents' allowlists are synced. The presets read as Rules names them (`Production Ask before changes`). Under them, your specific rules, counted and named as Rules lists them (`2 specific rules:` then `Run git push --delete · Production`), then one line per exception among them that lets something run your presets would ask about: `! 1 exception: git push --delete runs in Production without asking.` 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`.
|
|
314
317
|
- `actions` tells Passport what a project script does (`src/cliActions.ts`): `actions add <script> [args…] --environment <kind> --class <class>` sends the path in the repository (or `make`, `npm`, `pnpm`, `yarn` with the target), an argument glob, the repository's remote fingerprint and name, and the SHA-256 of what it runs, never its contents, to `POST /api/my/project-actions`. `--id <op_…>` resolves a Session row's **Tell Passport what this does** from this computer's scan cache. `actions sync` proposes each entry of `.passport/actions.toml`. A change, delete, or irreversible in Production applies at once; anything looser waits for an admin. The guard then decides a matching run as vendor `project` with that class and environment; it never makes a line allowed on its own, and a changed script stops matching (`projectChanged`) until it's set again. `.passport/actions.toml` entries apply locally only when they ask or block.
|
|
315
318
|
- `rules test`, `sessions`, `actions`, and `sync` need a member profile. `wait` also works for a cloud agent's agent token, on the approval its own `passport exec` opened.
|
|
316
319
|
|
|
@@ -483,7 +486,7 @@ On a terminal, human output comes from one renderer (`src/term.ts`): it wraps to
|
|
|
483
486
|
| `profiles` | `{profiles:[{name,active,client?}],active?}` |
|
|
484
487
|
| `use` | `{profile,active:true}` |
|
|
485
488
|
| `logout` | `{profile,removed,revoked,shimsRemoved?}` |
|
|
486
|
-
| `status` | `{workspace,member,endpoint,auth,profile?,client,mcps,autopilot?:{presets,floors,floorReason?,exceptions?,cache:{version,fetchedAt,ageMs}},next?,computer,keys?,keysOnThisComputer?,folder,cli:{version},signedInAs?,shims?:[{vendor,command,state}]}`
|
|
489
|
+
| `status` | `{workspace,member,endpoint,auth,profile?,client,mcps,autopilot?:{presets,floors,floorReason?,rules?,exceptions?,cache:{version,fetchedAt,ageMs}},next?,computer,keys?,keysOnThisComputer?,folder,cli:{version},signedInAs?,shims?:[{vendor,command,state}]}` |
|
|
487
490
|
| `wait` | `{approvalId,status:"approved",scope?,message}`; declined, expired, and still-waiting are errors with `approvalId` |
|
|
488
491
|
| `rules` | `{command,decision,cause?,explanation?,environment?,environmentAssumed?,actionClass?,source}` |
|
|
489
492
|
| `sessions` | `{view,groups:[{key,kind,label,apps,running,production,unplaced,items:[{key,title,project,branch,pull,agents,sessions,sessionIds,startedAt,lastActivityAt,activeMs,running,waiting,shape,reasons,severity,link}],routine:{count,sessions,actions,reads,items}\|null}],totals,complete,nextCursor}` (`--project <name>` alone adds `project`); `--production-changes`: `{view,sinceTs,untilTs,total,unplaced,apps:[{appKey,appName,count,lastTs,targets:[{target,tool,actionClass,count,failed,firstTs,lastTs}]}]}`; `<id>`: `{view,session,outcome,approvals,timeline,nextCursor}` |
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Task allowances on this computer (cli-policy v2 `allowances`): a person
|
|
3
|
+
* answered an ask with For this task, so this agent session runs every action
|
|
4
|
+
* of one class on one app in one environment ("Railway changes in Staging")
|
|
5
|
+
* without asking again, until the task ends. The server sends only the
|
|
6
|
+
* person's running sessions, each named by the agent's own session id.
|
|
7
|
+
*
|
|
8
|
+
* The guard applies a matching allowance exactly where the server's engine
|
|
9
|
+
* does: after block rules, before exceptions and presets. Never for an
|
|
10
|
+
* irreversible action or a Production delete. A revoke reaches the guard on
|
|
11
|
+
* the next command: before it runs a command an allowance let through, the
|
|
12
|
+
* guard asks Passport which allowances the session still holds
|
|
13
|
+
* (`cliHookSessionEnd.ts`).
|
|
14
|
+
*/
|
|
15
|
+
/** The policy's action classes and environments (cliAutopilotPolicy.ts). */
|
|
16
|
+
type ActionClass = "read" | "change" | "delete" | "irreversible";
|
|
17
|
+
type ActionEnv = "production" | "staging" | "development" | "other";
|
|
18
|
+
export type CliAllowance = {
|
|
19
|
+
id: string;
|
|
20
|
+
/** The agent's own session id, as its hook reports it. */
|
|
21
|
+
session: string;
|
|
22
|
+
runtime: string;
|
|
23
|
+
/** The platform ("railway"), and the CLIs that act on it. */
|
|
24
|
+
app: string;
|
|
25
|
+
vendors: string[];
|
|
26
|
+
actionClass: "change" | "delete";
|
|
27
|
+
environment: ActionEnv;
|
|
28
|
+
/** "Railway changes in Staging" */
|
|
29
|
+
label: string;
|
|
30
|
+
expiresAt: number;
|
|
31
|
+
};
|
|
32
|
+
/** Each well-formed allowance; a malformed one is dropped (it only means an ask). */
|
|
33
|
+
export declare function parseAllowances(value: unknown): CliAllowance[] | undefined;
|
|
34
|
+
export type AllowanceFacts = {
|
|
35
|
+
vendor: string;
|
|
36
|
+
actionClass: ActionClass;
|
|
37
|
+
environment: ActionEnv;
|
|
38
|
+
session?: {
|
|
39
|
+
runtime: string;
|
|
40
|
+
id: string;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
/** The allowance that covers this action in this session, if any. */
|
|
44
|
+
export declare function matchAllowance(allowances: readonly CliAllowance[] | undefined, facts: AllowanceFacts, now?: number): CliAllowance | undefined;
|
|
45
|
+
/** The cause an allowance gives: "Allowed for this task: Railway changes in Staging". */
|
|
46
|
+
export declare function allowanceCauseLabel(allowance: Pick<CliAllowance, "label">): string;
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Task allowances on this computer (cli-policy v2 `allowances`): a person
|
|
3
|
+
* answered an ask with For this task, so this agent session runs every action
|
|
4
|
+
* of one class on one app in one environment ("Railway changes in Staging")
|
|
5
|
+
* without asking again, until the task ends. The server sends only the
|
|
6
|
+
* person's running sessions, each named by the agent's own session id.
|
|
7
|
+
*
|
|
8
|
+
* The guard applies a matching allowance exactly where the server's engine
|
|
9
|
+
* does: after block rules, before exceptions and presets. Never for an
|
|
10
|
+
* irreversible action or a Production delete. A revoke reaches the guard on
|
|
11
|
+
* the next command: before it runs a command an allowance let through, the
|
|
12
|
+
* guard asks Passport which allowances the session still holds
|
|
13
|
+
* (`cliHookSessionEnd.ts`).
|
|
14
|
+
*/
|
|
15
|
+
const MAX_ALLOWANCES = 100;
|
|
16
|
+
const ID = /^[A-Za-z0-9_-]{1,64}$/;
|
|
17
|
+
const SESSION = /^[A-Za-z0-9._:-]{1,128}$/;
|
|
18
|
+
const KEY = /^[a-z0-9][a-z0-9._-]{0,63}$/;
|
|
19
|
+
const ENVS = new Set(["production", "staging", "development", "other"]);
|
|
20
|
+
const LABEL = /^[^\u0000-\u001f\u007f]{1,120}$/;
|
|
21
|
+
function entry(raw) {
|
|
22
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
|
23
|
+
return null;
|
|
24
|
+
const body = raw;
|
|
25
|
+
const vendors = Array.isArray(body.vendors)
|
|
26
|
+
? body.vendors.filter((vendor) => typeof vendor === "string" && KEY.test(vendor)).slice(0, 8)
|
|
27
|
+
: [];
|
|
28
|
+
if (typeof body.id !== "string" ||
|
|
29
|
+
!ID.test(body.id) ||
|
|
30
|
+
typeof body.session !== "string" ||
|
|
31
|
+
!SESSION.test(body.session) ||
|
|
32
|
+
typeof body.runtime !== "string" ||
|
|
33
|
+
!KEY.test(body.runtime) ||
|
|
34
|
+
typeof body.app !== "string" ||
|
|
35
|
+
!KEY.test(body.app) ||
|
|
36
|
+
(body.actionClass !== "change" && body.actionClass !== "delete") ||
|
|
37
|
+
typeof body.environment !== "string" ||
|
|
38
|
+
!ENVS.has(body.environment) ||
|
|
39
|
+
typeof body.label !== "string" ||
|
|
40
|
+
!LABEL.test(body.label) ||
|
|
41
|
+
typeof body.expiresAt !== "number" ||
|
|
42
|
+
!Number.isSafeInteger(body.expiresAt)) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
// A Production delete is never allowed for a task, whatever a server says.
|
|
46
|
+
if (body.actionClass === "delete" && body.environment === "production")
|
|
47
|
+
return null;
|
|
48
|
+
return {
|
|
49
|
+
id: body.id,
|
|
50
|
+
session: body.session,
|
|
51
|
+
runtime: body.runtime,
|
|
52
|
+
app: body.app,
|
|
53
|
+
vendors: vendors.length ? vendors : [body.app],
|
|
54
|
+
actionClass: body.actionClass,
|
|
55
|
+
environment: body.environment,
|
|
56
|
+
label: body.label,
|
|
57
|
+
expiresAt: body.expiresAt
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/** Each well-formed allowance; a malformed one is dropped (it only means an ask). */
|
|
61
|
+
export function parseAllowances(value) {
|
|
62
|
+
if (!Array.isArray(value))
|
|
63
|
+
return undefined;
|
|
64
|
+
const list = value
|
|
65
|
+
.slice(0, MAX_ALLOWANCES)
|
|
66
|
+
.map(entry)
|
|
67
|
+
.filter((item) => item !== null);
|
|
68
|
+
return list.length ? list : undefined;
|
|
69
|
+
}
|
|
70
|
+
/** The allowance that covers this action in this session, if any. */
|
|
71
|
+
export function matchAllowance(allowances, facts, now = Date.now()) {
|
|
72
|
+
const session = facts.session;
|
|
73
|
+
if (!allowances?.length || !session)
|
|
74
|
+
return undefined;
|
|
75
|
+
if (facts.actionClass !== "change" && facts.actionClass !== "delete")
|
|
76
|
+
return undefined;
|
|
77
|
+
if (facts.actionClass === "delete" && facts.environment === "production")
|
|
78
|
+
return undefined;
|
|
79
|
+
return allowances.find((allowance) => allowance.session === session.id &&
|
|
80
|
+
allowance.runtime === session.runtime &&
|
|
81
|
+
allowance.vendors.includes(facts.vendor) &&
|
|
82
|
+
allowance.actionClass === facts.actionClass &&
|
|
83
|
+
allowance.environment === facts.environment &&
|
|
84
|
+
allowance.expiresAt > now);
|
|
85
|
+
}
|
|
86
|
+
/** The cause an allowance gives: "Allowed for this task: Railway changes in Staging". */
|
|
87
|
+
export function allowanceCauseLabel(allowance) {
|
|
88
|
+
return `Allowed for this task: ${allowance.label}`;
|
|
89
|
+
}
|
package/dist/cliArgs.js
CHANGED
|
@@ -74,7 +74,7 @@ const FLAGS = {
|
|
|
74
74
|
set: { kind: "repeat", commands: ["run", "prompts"] },
|
|
75
75
|
"set-json": { kind: "repeat", commands: ["run"] },
|
|
76
76
|
wait: { kind: "value", commands: ["run", "connect", "exec"] },
|
|
77
|
-
session: { kind: "value", commands: ["exec"] },
|
|
77
|
+
session: { kind: "value", commands: ["exec", "request"] },
|
|
78
78
|
alias: { kind: "value", commands: ["connect"] },
|
|
79
79
|
open: { kind: "boolean", commands: ["connect"] },
|
|
80
80
|
out: { kind: "value", commands: ["resources", "prompts"] },
|
|
@@ -109,6 +109,7 @@ const FLAGS = {
|
|
|
109
109
|
background: { kind: "boolean", commands: ["update"] },
|
|
110
110
|
option: { kind: "value", commands: ["undo"] },
|
|
111
111
|
reason: { kind: "value", commands: ["request"] },
|
|
112
|
+
task: { kind: "value", commands: ["request"] },
|
|
112
113
|
full: { kind: "boolean", commands: ["request"] }
|
|
113
114
|
};
|
|
114
115
|
/** `--agent` is the documented name; `--client` keeps working everywhere. */
|
package/dist/cliAutopilot.d.ts
CHANGED
|
@@ -24,6 +24,8 @@ export type AutopilotStatus = {
|
|
|
24
24
|
presets: (Record<EnvKind, Preset> & Partial<Record<PresetRow, Preset>>) | null;
|
|
25
25
|
floors: Partial<Record<PresetRow, Preset | null>> | null;
|
|
26
26
|
floorReason?: string;
|
|
27
|
+
/** Your specific rules, one line each, as the web's Rules list names them. */
|
|
28
|
+
rules?: string[];
|
|
27
29
|
/** One line per exception that lets something run your presets would ask about. */
|
|
28
30
|
exceptions?: string[];
|
|
29
31
|
cache: {
|
|
@@ -51,6 +53,8 @@ export type AutopilotStatus = {
|
|
|
51
53
|
}>;
|
|
52
54
|
/** Batch A: each agent's guard here, coverage this week, and fixes. */
|
|
53
55
|
guard?: GuardStatus;
|
|
56
|
+
/** Task allowances in your running tasks (cli-policy v2 `allowances`). */
|
|
57
|
+
allowed?: number;
|
|
54
58
|
};
|
|
55
59
|
export { localMidnight } from "./cliSpeed.js";
|
|
56
60
|
/** Read presets and floors for `passport status`. Never throws. */
|
package/dist/cliAutopilot.js
CHANGED
|
@@ -20,7 +20,7 @@ import { resolveTarget } from "./envResolve.js";
|
|
|
20
20
|
// `passport env` lives in cliEnv.ts; the dispatcher reaches it through here.
|
|
21
21
|
export { env } from "./cliEnv.js";
|
|
22
22
|
export { actions } from "./cliActions.js";
|
|
23
|
-
import { looseningLines } from "./cliLoosening.js";
|
|
23
|
+
import { looseningLines, specificRuleLines } from "./cliLoosening.js";
|
|
24
24
|
import { readCliPolicy } from "./cliPolicy.js";
|
|
25
25
|
import { failure, readBoundedJson, resolveCliAuth, timeoutMs } from "./cliSupport.js";
|
|
26
26
|
import { unknownSubcommand } from "./cliSuggest.js";
|
|
@@ -285,20 +285,24 @@ export async function autopilotStatus(fetchApi, profile, signal, now = Date.now(
|
|
|
285
285
|
floors[row] = isPresetName(floor) ? floor : null;
|
|
286
286
|
}
|
|
287
287
|
const reason = text(body.floors?.reason, 120);
|
|
288
|
+
const rules = specificRuleLines(body);
|
|
288
289
|
const exceptions = looseningLines(body);
|
|
289
290
|
const { answered, speed } = await (await import("./cliSpeed.js")).todayStatus(fetchApi, profile, signal, now);
|
|
290
291
|
const allowlists = await allowlistStatus();
|
|
291
292
|
const guard = await guardStatus(fetchApi, profile, signal, now);
|
|
293
|
+
const allowed = cached?.version === 2 ? (cached.autopilot.allowances ?? []).filter((a) => a.expiresAt > now).length : 0;
|
|
292
294
|
return {
|
|
293
295
|
presets: presetMap(body.presets),
|
|
294
296
|
floors,
|
|
295
297
|
...(reason ? { floorReason: reason } : {}),
|
|
298
|
+
...(rules.length ? { rules } : {}),
|
|
296
299
|
...(exceptions.length ? { exceptions } : {}),
|
|
297
300
|
cache,
|
|
298
301
|
...(answered ? { answered } : {}),
|
|
299
302
|
...(speed ? { speed } : {}),
|
|
300
303
|
...(guard ? { guard } : {}),
|
|
301
|
-
...(allowlists ? { allowlists } : {})
|
|
304
|
+
...(allowlists ? { allowlists } : {}),
|
|
305
|
+
...(allowed ? { allowed } : {})
|
|
302
306
|
};
|
|
303
307
|
}
|
|
304
308
|
catch {
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
*
|
|
15
15
|
* Every decision carries its cause, and every cause reads as one line.
|
|
16
16
|
*/
|
|
17
|
+
import { type CliAllowance } from "./cliAllowances.js";
|
|
17
18
|
import { type EnvKind } from "./cliHookEnvironment.js";
|
|
18
19
|
export declare const PRESETS: readonly ["careful", "balanced", "handsoff"];
|
|
19
20
|
export type Preset = (typeof PRESETS)[number];
|
|
@@ -69,6 +70,11 @@ export type CliRule = {
|
|
|
69
70
|
/** This rule is an approved exception: the person's own, but an admin
|
|
70
71
|
* approved it, so an offline Run never loosens it. */
|
|
71
72
|
exception?: true;
|
|
73
|
+
/** A repo rule: only in this repository (lower case). */
|
|
74
|
+
repo?: string;
|
|
75
|
+
/** The repository file and line it came from, for the block's reason. */
|
|
76
|
+
repoFile?: string;
|
|
77
|
+
repoLine?: string;
|
|
72
78
|
};
|
|
73
79
|
export type RuleException = {
|
|
74
80
|
vendor?: string;
|
|
@@ -147,9 +153,20 @@ export type AutopilotPolicy = {
|
|
|
147
153
|
/** The workspace keeps the agent's own step descriptions (cli-policy v2
|
|
148
154
|
* `descriptions`, "Show what agents say they're doing"). Off when absent. */
|
|
149
155
|
reportsSteps?: boolean;
|
|
156
|
+
/** Vendors whose working production key the workspace holds: a command
|
|
157
|
+
* that lands in placed Production runs through `passport exec`. */
|
|
158
|
+
productionKeys?: string[];
|
|
150
159
|
/** The server answers an attended ask with its reason line and short link
|
|
151
160
|
* (cli-policy v2 `asks`), so the guard asks it before the agent's prompt. */
|
|
152
161
|
askLines?: boolean;
|
|
162
|
+
/** The server keeps what the after-hook learns (cli-policy v2 `afterFacts`):
|
|
163
|
+
* a sign-in that failed, what a command created or removed, a retry streak. */
|
|
164
|
+
reportsAfterFacts?: boolean;
|
|
165
|
+
/** "Stop retry loops" is on for this person (cli-policy v2 `retryLoops`):
|
|
166
|
+
* the guard asks before a command that failed 5 times in a row runs again. */
|
|
167
|
+
retryLoops?: boolean;
|
|
168
|
+
/** Vendors whose working key Passport holds for this person (cli-policy v2 `heldKeys`). */
|
|
169
|
+
heldKeys?: string[];
|
|
153
170
|
/** Production classes someone else must approve: never run here, and never
|
|
154
171
|
* approved in the agent's own prompt. "Maya or Sam" names who approves. */
|
|
155
172
|
secondPerson?: {
|
|
@@ -182,6 +199,11 @@ export type AutopilotPolicy = {
|
|
|
182
199
|
* only when the server asks before a Hands-off shell delete nothing can
|
|
183
200
|
* back up (`backupGate`); an older server sends nothing and nothing changes. */
|
|
184
201
|
withoutBackup?: Partial<Record<"staging" | "development" | "other", true>>;
|
|
202
|
+
/** Task allowances in this person's running sessions (cli-policy v2
|
|
203
|
+
* `allowances`, `cliAllowances.ts`). */
|
|
204
|
+
allowances?: CliAllowance[];
|
|
205
|
+
/** One deploy at a time (cli-policy v2 `leases`): take a lease first. */
|
|
206
|
+
leases?: boolean;
|
|
185
207
|
/** Known project scripts (Batch A item 5), vendor `project`: they set class
|
|
186
208
|
* and environment only, never an allow. */
|
|
187
209
|
project?: {
|
|
@@ -206,6 +228,13 @@ export type PresetRow = EnvKind | typeof OTHER_APPS;
|
|
|
206
228
|
export declare const PRESET_ROWS: PresetRow[];
|
|
207
229
|
export declare function rowLabel(row: string): string;
|
|
208
230
|
export declare const PRESET_LABEL: Record<Preset, string>;
|
|
231
|
+
/**
|
|
232
|
+
* Each preset named by what it does, as Rules on the web shows it: the words
|
|
233
|
+
* `passport status` and `passport init` use. A checked copy of
|
|
234
|
+
* shared/presetStance.ts `PRESET_STANCE_LABEL` (cliLoosening.test.ts
|
|
235
|
+
* compares them). `PRESET_LABEL` stays for causes, which the server words.
|
|
236
|
+
*/
|
|
237
|
+
export declare const PRESET_STANCE_LABEL: Record<Preset, string>;
|
|
209
238
|
export declare const DEFAULT_PRESETS: Record<ActionEnv, Preset>;
|
|
210
239
|
/** "Production", "Other apps". */
|
|
211
240
|
export declare function envLabel(env: ActionEnv): string;
|
|
@@ -220,7 +249,16 @@ export type ActionFacts = {
|
|
|
220
249
|
environment: ActionEnv;
|
|
221
250
|
/** This computer takes a backup first (`localBackups.ts`). */
|
|
222
251
|
backup?: boolean;
|
|
252
|
+
/** The repository the command runs in (its name), for repo rules. */
|
|
253
|
+
repo?: string;
|
|
254
|
+
/** The agent session it runs in, for its task allowances. */
|
|
255
|
+
session?: {
|
|
256
|
+
runtime: string;
|
|
257
|
+
id: string;
|
|
258
|
+
};
|
|
223
259
|
};
|
|
260
|
+
/** The reason a repo rule's block gives: "this repo's AGENTS.md: Never run `railway up`." */
|
|
261
|
+
export declare const REPO_RULE_LEAD = "this repo's ";
|
|
224
262
|
export type LocalDecision = {
|
|
225
263
|
decision: Decision;
|
|
226
264
|
cause: Cause;
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
*
|
|
15
15
|
* Every decision carries its cause, and every cause reads as one line.
|
|
16
16
|
*/
|
|
17
|
+
import { allowanceCauseLabel, matchAllowance } from "./cliAllowances.js";
|
|
17
18
|
import { ENV_LABEL } from "./cliHookEnvironment.js";
|
|
18
19
|
import { vendorKeys } from "./cliHookVendors.js";
|
|
19
20
|
export const PRESETS = ["careful", "balanced", "handsoff"];
|
|
@@ -107,6 +108,17 @@ export const PRESET_LABEL = {
|
|
|
107
108
|
balanced: "Balanced",
|
|
108
109
|
handsoff: "Hands-off"
|
|
109
110
|
};
|
|
111
|
+
/**
|
|
112
|
+
* Each preset named by what it does, as Rules on the web shows it: the words
|
|
113
|
+
* `passport status` and `passport init` use. A checked copy of
|
|
114
|
+
* shared/presetStance.ts `PRESET_STANCE_LABEL` (cliLoosening.test.ts
|
|
115
|
+
* compares them). `PRESET_LABEL` stays for causes, which the server words.
|
|
116
|
+
*/
|
|
117
|
+
export const PRESET_STANCE_LABEL = {
|
|
118
|
+
careful: "Ask before changes",
|
|
119
|
+
balanced: "Ask before deletes",
|
|
120
|
+
handsoff: "Ask only for irreversible"
|
|
121
|
+
};
|
|
110
122
|
/** What each preset does, per class. Irreversible always asks. */
|
|
111
123
|
const PRESET_TABLE = {
|
|
112
124
|
careful: { read: "allow", change: "ask", delete: "ask", irreversible: "ask" },
|
|
@@ -164,6 +176,9 @@ function appMatches(key, facts) {
|
|
|
164
176
|
function ruleMatches(rule, facts) {
|
|
165
177
|
if (rule.environment !== "any" && rule.environment !== facts.environment)
|
|
166
178
|
return false;
|
|
179
|
+
// A repo rule speaks only for commands run in its repository.
|
|
180
|
+
if (rule.repo !== undefined && rule.repo !== facts.repo?.toLowerCase())
|
|
181
|
+
return false;
|
|
167
182
|
const level = ruleLevel(rule);
|
|
168
183
|
if (level === 0)
|
|
169
184
|
return false;
|
|
@@ -207,8 +222,12 @@ function matchText(rule) {
|
|
|
207
222
|
return `${rule.appKey} actions`;
|
|
208
223
|
return rule.actionClass ? CLASS_PLURAL[rule.actionClass] : "actions";
|
|
209
224
|
}
|
|
225
|
+
/** The reason a repo rule's block gives: "this repo's AGENTS.md: Never run `railway up`." */
|
|
226
|
+
export const REPO_RULE_LEAD = "this repo's ";
|
|
210
227
|
/** "Team rule, no deletes in Production"; the server's own label when it sent one. */
|
|
211
228
|
function ruleLabel(rule) {
|
|
229
|
+
if (rule.repo && rule.repoFile && rule.repoLine)
|
|
230
|
+
return `${REPO_RULE_LEAD}${rule.repoFile}: ${rule.repoLine}`;
|
|
212
231
|
if (rule.label)
|
|
213
232
|
return rule.label;
|
|
214
233
|
const owner = rule.owner
|
|
@@ -231,20 +250,16 @@ function ruleLabel(rule) {
|
|
|
231
250
|
return `A rule says ${verb} ${matchText(rule)}${where}`;
|
|
232
251
|
return `${owner}, ${verb} ${matchText(rule)}${where}`;
|
|
233
252
|
}
|
|
234
|
-
function presetLabel(env,
|
|
253
|
+
function presetLabel(env, _preset, actionClass, decision) {
|
|
235
254
|
if (actionClass === "read")
|
|
236
255
|
return "Reads always run";
|
|
237
256
|
if (actionClass === "irreversible")
|
|
238
257
|
return "Irreversible actions always ask";
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
}
|
|
245
|
-
if (decision === "allow")
|
|
246
|
-
return `${ENV_LABEL[env]} is ${PRESET_LABEL[preset]}`;
|
|
247
|
-
return `${ENV_LABEL[env]} ${CLASS_PLURAL[actionClass]} ask first (${PRESET_LABEL[preset]})`;
|
|
258
|
+
// Plain words, no preset name: "Production changes ask first", "Staging changes run on their own".
|
|
259
|
+
const verb = decision === "allow" ? "run on their own" : "ask first";
|
|
260
|
+
if (env === OTHER_APPS)
|
|
261
|
+
return `Other apps: ${CLASS_PLURAL[actionClass]} ${verb}`;
|
|
262
|
+
return `${ENV_LABEL[env]} ${CLASS_PLURAL[actionClass]} ${verb}`;
|
|
248
263
|
}
|
|
249
264
|
function floorLabel(env, preset) {
|
|
250
265
|
const where = env === OTHER_APPS ? "for other apps" : `in ${ENV_LABEL[env]}`;
|
|
@@ -329,6 +344,10 @@ function decideByRules(policy, facts) {
|
|
|
329
344
|
const rule = mostSpecific(blocks)[0];
|
|
330
345
|
return { decision: "block", cause: { kind: "block", id: rule.id, label: ruleLabel(rule) } };
|
|
331
346
|
}
|
|
347
|
+
// 2. Allowed for this task (the server engine's grant step).
|
|
348
|
+
const allowance = matchAllowance(policy.allowances, facts);
|
|
349
|
+
if (allowance)
|
|
350
|
+
return { decision: "allow", cause: { kind: "grant", id: allowance.id, label: allowanceCauseLabel(allowance) } };
|
|
332
351
|
const floor = policy.floors[facts.environment] ?? null;
|
|
333
352
|
const floorDecision = floor ? presetDecision(floor, facts.actionClass) : undefined;
|
|
334
353
|
// 3. The most specific exception, strictest across scopes, bounded by the floor.
|
package/dist/cliChanges.d.ts
CHANGED
|
@@ -46,6 +46,13 @@ export type ChangeJson = {
|
|
|
46
46
|
url: string | null;
|
|
47
47
|
} | null;
|
|
48
48
|
undo: UndoJson | null;
|
|
49
|
+
/** A deploy-like change: what Passport saw in the 15 minutes after it. */
|
|
50
|
+
watch: WatchJson | null;
|
|
51
|
+
};
|
|
52
|
+
export type WatchJson = {
|
|
53
|
+
state: "watching" | "healthy" | "errors" | "unchecked";
|
|
54
|
+
errors: number;
|
|
55
|
+
deployFailed: boolean;
|
|
49
56
|
};
|
|
50
57
|
/** `passport changes --json`. */
|
|
51
58
|
export type ChangesJson = {
|
package/dist/cliChanges.js
CHANGED
|
@@ -146,9 +146,31 @@ function changeOf(raw) {
|
|
|
146
146
|
pull: pullNumber && pullTitle
|
|
147
147
|
? { number: pullNumber, title: pullTitle, url: pullUrl && /^https:\/\//.test(pullUrl) ? pullUrl : null }
|
|
148
148
|
: null,
|
|
149
|
-
undo: undoOf(entry.undo)
|
|
149
|
+
undo: undoOf(entry.undo),
|
|
150
|
+
watch: watchOf(entry.watch)
|
|
150
151
|
};
|
|
151
152
|
}
|
|
153
|
+
function watchOf(raw) {
|
|
154
|
+
const watch = record(raw);
|
|
155
|
+
const state = oneOf(watch.state, ["watching", "healthy", "errors", "unchecked"]);
|
|
156
|
+
if (!state)
|
|
157
|
+
return null;
|
|
158
|
+
const errors = typeof watch.errors === "number" && Number.isSafeInteger(watch.errors) ? Math.max(0, watch.errors) : 0;
|
|
159
|
+
return { state, errors, deployFailed: watch.deployFailed === true };
|
|
160
|
+
}
|
|
161
|
+
/** What the watch after a deploy saw, in the row's words. */
|
|
162
|
+
function watchPart(watch) {
|
|
163
|
+
if (!watch)
|
|
164
|
+
return null;
|
|
165
|
+
if (watch.state === "watching")
|
|
166
|
+
return "Watching for errors";
|
|
167
|
+
if (watch.state === "healthy")
|
|
168
|
+
return "No new errors in 15 min";
|
|
169
|
+
if (watch.state === "unchecked")
|
|
170
|
+
return "Couldn't check for errors";
|
|
171
|
+
const errors = watch.errors ? `${countOf(watch.errors, "new error")} since` : "";
|
|
172
|
+
return errors && watch.deployFailed ? `${errors}, deploy failed` : errors || "Deploy failed";
|
|
173
|
+
}
|
|
152
174
|
/** The server's app name, unless it's only the bare program ("git" reads "Git"). */
|
|
153
175
|
function nameOf(name, vendor) {
|
|
154
176
|
return name && name !== vendor ? name : appName(vendor);
|
|
@@ -239,11 +261,17 @@ export function changeParts(change, projects = false) {
|
|
|
239
261
|
const undo = undoPart(change.undo);
|
|
240
262
|
if (undo)
|
|
241
263
|
parts.push(undo);
|
|
264
|
+
const watch = watchPart(change.watch);
|
|
265
|
+
if (watch)
|
|
266
|
+
parts.push(watch);
|
|
242
267
|
return parts;
|
|
243
268
|
}
|
|
244
269
|
/** A change keeps its own line when it failed, was approved, or has an undo state worth seeing. */
|
|
245
270
|
function standsAlone(change) {
|
|
246
|
-
return change.result === "error" ||
|
|
271
|
+
return (change.result === "error" ||
|
|
272
|
+
change.approved ||
|
|
273
|
+
Boolean(change.undo && change.undo.state !== "expired") ||
|
|
274
|
+
change.watch !== null);
|
|
247
275
|
}
|
|
248
276
|
function runKey(change) {
|
|
249
277
|
return JSON.stringify([change.command, change.target, change.agent, change.person, change.project, change.branch]);
|
|
@@ -300,7 +328,13 @@ export function renderChanges(page, term, now, since, links) {
|
|
|
300
328
|
const title = change.target ? `${change.command} ${arrow} ${change.target}` : change.command;
|
|
301
329
|
const when = run.length > 1 ? `${changeTime(oldest.ts, now)}-${changeTime(change.ts, now)}` : changeTime(change.ts, now);
|
|
302
330
|
const count = run.length > 1 ? ` ${times}${run.length.toLocaleString("en-US")}` : "";
|
|
303
|
-
|
|
331
|
+
// A watched deploy: ✓ when Passport saw no new errors, ✗ when it did.
|
|
332
|
+
const kind = change.result === "error" || change.watch?.state === "errors"
|
|
333
|
+
? "fail"
|
|
334
|
+
: change.watch?.state === "healthy"
|
|
335
|
+
? "done"
|
|
336
|
+
: "warn";
|
|
337
|
+
const head = `${mark(term, kind)} ${when} ${title}${count}`;
|
|
304
338
|
lines.push(...(visibleLength(head) <= term.width ? [head] : wrap(head, term.width, "", " ")));
|
|
305
339
|
lines.push(...joinParts(changeParts(change, projects), term.width, " "));
|
|
306
340
|
}
|
package/dist/cliExec.d.ts
CHANGED
|
@@ -40,31 +40,6 @@ export type ExecDependencies = {
|
|
|
40
40
|
/** Where to look for this computer's own CLI sign-ins (tests). */
|
|
41
41
|
home?: string;
|
|
42
42
|
};
|
|
43
|
-
type Authorized = {
|
|
44
|
-
decision?: unknown;
|
|
45
|
-
actionId?: unknown;
|
|
46
|
-
explanation?: unknown;
|
|
47
|
-
message?: unknown;
|
|
48
|
-
approvalId?: unknown;
|
|
49
|
-
actionClass?: unknown;
|
|
50
|
-
credential?: {
|
|
51
|
-
env?: unknown;
|
|
52
|
-
issuance?: unknown;
|
|
53
|
-
label?: unknown;
|
|
54
|
-
expiresAt?: unknown;
|
|
55
|
-
};
|
|
56
|
-
/** Phase 4: a backup was taken right before, or couldn't be (with the reason). */
|
|
57
|
-
backup?: unknown;
|
|
58
|
-
backupNote?: unknown;
|
|
59
|
-
/** A block's fix, as a web hash (`#apps/railway/access`). */
|
|
60
|
-
link?: unknown;
|
|
61
|
-
/** A recent decline answered this command: who, the note, and when. */
|
|
62
|
-
declined?: {
|
|
63
|
-
by?: unknown;
|
|
64
|
-
note?: unknown;
|
|
65
|
-
at?: unknown;
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
43
|
export { execTarget };
|
|
69
44
|
/** The classified finding the server decides on: vendor, verb, risk, environment. */
|
|
70
45
|
export declare function execFinding(vendor: ExecVendor, binary: string, args: readonly string[], policy: ReturnType<typeof readCliPolicy>, where?: WhereContext): {
|
|
@@ -104,5 +79,5 @@ export declare function stillOpen(approvalId: string): never;
|
|
|
104
79
|
/** "Passport: railway redeploy changes Production. Waiting up to 120 seconds for Ramish. Approve it on your phone or in Passport." */
|
|
105
80
|
export declare function waitingLine(message: string, seconds: number): string;
|
|
106
81
|
export declare function exec(args: ParsedArgs, runtime: Runtime, deps?: ExecDependencies): Promise<CommandResult>;
|
|
107
|
-
|
|
108
|
-
export
|
|
82
|
+
import { backupLine } from "./execBackupLine.js";
|
|
83
|
+
export { backupLine };
|
package/dist/cliExec.js
CHANGED
|
@@ -522,6 +522,8 @@ export async function exec(args, runtime, deps = {}) {
|
|
|
522
522
|
shell: false,
|
|
523
523
|
cwd: prepared.cwd
|
|
524
524
|
};
|
|
525
|
+
// One deploy at a time: renew the lease Passport took while it runs, release it after.
|
|
526
|
+
const lease = (await import("./execLease.js")).keepLease(client.fetchApi, decided.leaseId);
|
|
525
527
|
try {
|
|
526
528
|
code = deps.spawn
|
|
527
529
|
? await deps.spawn(prepared.executable, prepared.rest, options)
|
|
@@ -536,6 +538,9 @@ export async function exec(args, runtime, deps = {}) {
|
|
|
536
538
|
catch {
|
|
537
539
|
return failure(`${binary} couldn't start.`, 1, "not_installed");
|
|
538
540
|
}
|
|
541
|
+
finally {
|
|
542
|
+
await lease.stop();
|
|
543
|
+
}
|
|
539
544
|
if (typeof decided.actionId === "string") {
|
|
540
545
|
await reportResult(client, decided.actionId, code, (deps.now ?? Date.now)() - startedAt, runtime);
|
|
541
546
|
}
|
|
@@ -544,22 +549,8 @@ export async function exec(args, runtime, deps = {}) {
|
|
|
544
549
|
runtime.stderr.write(`${line}\n`);
|
|
545
550
|
return { json: { exitCode: code }, silent: true, exitCode: code };
|
|
546
551
|
}
|
|
547
|
-
|
|
548
|
-
export
|
|
549
|
-
const actionId = typeof decided.actionId === "string" && /^[A-Za-z0-9_-]{1,80}$/.test(decided.actionId);
|
|
550
|
-
if (decided.backup === "taken" && exitCode === 0 && actionId) {
|
|
551
|
-
return `Backup taken. Undo within 7 days: passport undo ${decided.actionId}`;
|
|
552
|
-
}
|
|
553
|
-
if (decided.backup === "none" && decided.actionClass === "delete" && typeof decided.backupNote === "string") {
|
|
554
|
-
const note = decided.backupNote
|
|
555
|
-
.replace(/[\u0000-\u001f\u007f-\u009f]/g, "")
|
|
556
|
-
.trim()
|
|
557
|
-
.slice(0, 200);
|
|
558
|
-
if (note)
|
|
559
|
-
return `No backup: ${note}`;
|
|
560
|
-
}
|
|
561
|
-
return undefined;
|
|
562
|
-
}
|
|
552
|
+
import { backupLine } from "./execBackupLine.js";
|
|
553
|
+
export { backupLine };
|
|
563
554
|
/** How the command ended, so its session row reads Ran or Failed. Best
|
|
564
555
|
* effort: two seconds at most, silent on failure, never the exit code. */
|
|
565
556
|
async function reportResult(client, actionId, exitCode, durationMs, runtime) {
|