passport-bridge 0.26.0 → 0.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +4 -4
  2. package/dist/blindKind.d.ts +15 -0
  3. package/dist/blindKind.js +5 -0
  4. package/dist/cliChanges.d.ts +12 -4
  5. package/dist/cliChanges.js +26 -15
  6. package/dist/cliGuardState.js +2 -2
  7. package/dist/cliHook.js +2 -2
  8. package/dist/cliHookBlind.d.ts +15 -0
  9. package/dist/cliHookBlind.js +65 -0
  10. package/dist/cliHookDecide.d.ts +8 -1
  11. package/dist/cliHookDecide.js +52 -4
  12. package/dist/cliHookLocal.d.ts +7 -16
  13. package/dist/cliHookLocal.js +75 -97
  14. package/dist/cliHookLocalCode.js +7 -1
  15. package/dist/cliHookLocalFs.d.ts +15 -0
  16. package/dist/cliHookLocalFs.js +77 -0
  17. package/dist/cliHookScripts.d.ts +2 -1
  18. package/dist/cliHookSessionEnd.d.ts +48 -0
  19. package/dist/cliHookSessionEnd.js +162 -0
  20. package/dist/cliOutput.js +2 -2
  21. package/dist/cliProjectSummary.d.ts +1 -1
  22. package/dist/cliProjectSummary.js +19 -8
  23. package/dist/cliScriptRead.d.ts +5 -4
  24. package/dist/cliScriptRead.js +3 -2
  25. package/dist/cliSeen.d.ts +24 -15
  26. package/dist/cliSeen.js +34 -16
  27. package/dist/cliSessions.js +20 -6
  28. package/dist/cliSessionsJson.d.ts +48 -0
  29. package/dist/cliSessionsJson.js +40 -10
  30. package/dist/cliSessionsRender.d.ts +4 -0
  31. package/dist/cliSessionsRender.js +42 -8
  32. package/dist/inlineCode.d.ts +35 -0
  33. package/dist/inlineCode.js +201 -0
  34. package/dist/inlineScan.d.ts +23 -0
  35. package/dist/inlineScan.js +389 -0
  36. package/dist/localCommands.d.ts +10 -3
  37. package/dist/localCommands.js +59 -37
  38. package/dist/localFiles.d.ts +38 -2
  39. package/dist/localFiles.js +453 -33
  40. package/dist/localGit.js +53 -17
  41. package/dist/localShared.d.ts +3 -0
  42. package/dist/pluginPin.d.ts +1 -1
  43. package/dist/pluginPin.js +1 -1
  44. package/dist/version.d.ts +1 -1
  45. package/dist/version.js +1 -1
  46. package/npm-shrinkwrap.json +2 -2
  47. package/package.json +1 -1
package/README.md CHANGED
@@ -246,7 +246,7 @@ Two hooks per agent. `passport hook` runs after each shell command and records t
246
246
 
247
247
  The environment comes from each vendor's own flags (`src/cliHookEnvironment.ts`): Railway `-e/--environment`, Wrangler and Sentry `-e/--env`, Vercel `--prod`/`--target` (a deploy without either is a preview), Supabase `--local`/`--linked`/`--project-ref` (`db reset` is local unless `--linked`), Stripe `--live` (test mode otherwise), `git push <remote> <branch>`, `psql` hosts (`localhost` is Development), fly and Heroku `-a/--app`, kubectl `--context`/`-n`, helm `--kube-context`/`-n`, AWS `--profile`, gcloud `--project`, plus any flags the server adds. Names follow Passport's rules (`prod|production|live|main` → Production, `stag|qa|uat|preview` → Staging, `dev|local|test|sandbox|feature|branch` → Development), and the workspace's own placement of a name wins. Anything else, or no flag at all (a linked project the hook can't see), counts as Production, and the reason says `Environment unknown, treated as Production.`
248
248
 
249
- **Attended or unattended** (`src/cliHookMode.ts`). With a person at the keyboard, an ask is the agent's own prompt with Passport's reason. With nobody there, the guard asks Passport instead (`POST /api/my/cli/decide`, inside the hook's budget): the server knows grants already given this session, every rule, and the workspace's environments. An allow from it runs the command (for example, a retry after approval); an ask becomes an approval request on the web and the person's phone, and the agent reads ``Waiting for approval from Ramish. Run `passport wait <id>` to wait, or continue with other work.`` If Passport can't answer in time, the local decision stands and the reason adds `Passport couldn't be reached, so this computer decided.` Signals, strongest first:
249
+ **Attended or unattended** (`src/cliHookMode.ts`). With a person at the keyboard, an ask is the agent's own prompt with Passport's reason, except an irreversible command: it is approved only in Passport, with a passkey check, so the guard files the request and holds as below, and blocks with `Passport can't be reached. Irreversible commands need approval in Passport.` if Passport doesn't answer. With nobody there, the guard asks Passport instead (`POST /api/my/cli/decide`, inside the hook's budget): the server knows grants already given this session, every rule, and the workspace's environments. An allow from it runs the command (for example, a retry after approval); an ask becomes an approval request on the web and the person's phone, and the agent reads ``Waiting for approval from Ramish. Run `passport wait <id>` to wait, or continue with other work.`` If Passport can't answer in time, the local decision stands and the reason adds `Passport couldn't be reached, so this computer decided.` Signals, strongest first:
250
250
 
251
251
  | Signal | Means |
252
252
  | ------------------------------------------------------------------------------------------------- | --------------------------------------- |
@@ -261,7 +261,7 @@ Codex has no field for `codex exec`; its prompt-free modes count as unattended,
261
261
 
262
262
  The approval request carries a command summary with secrets removed on this computer (`src/cliHookRedact.ts`, using `passport scan`'s key formats plus secret-named flags, variables, JSON fields, URL credentials, and long opaque values; heredoc bodies are dropped). It is the only part of a command line that ever leaves the machine, and only approvers see it.
263
263
 
264
- The guard decides from local data inside `HOOK_BUDGET_MS` (1.5 s) and prints first; only an unattended ask waits for the server, within the same budget. After answering it never waits on the network: its report, the batches, and, at most every ten minutes, a refresh of a policy cache older than an hour go through the detached `passport hook flush`. Any failure is silent and fails open. Neither hook sends the raw command line, output, folder path, or environment. Both hooks exchange the profile's refresh credential without rotating it and keep the short-lived access token in `$PASSPORT_HOME/.<profile>.access.json` (`src/accessTokenCache.ts`, mode 600, atomic replace), so most runs send one request instead of an exchange and then the request. A cached token is used only with more than a minute left; a 401 on it drops it, exchanges once, and retries once.
264
+ The guard decides from local data inside `HOOK_BUDGET_MS` (1.5 s) and prints first; only an unattended ask (or an irreversible one) waits for the server, within the same budget. The one exception is End session (`src/cliHookSessionEnd.ts`): before a command it would let run on its own (an allow, or nothing to decide), a signed-in guard asks `GET /api/my/cli/session` (agent and session id only) whether a person ended that session, at most every 15 s per session and for at most 300 ms; an ended session is cached and refused with the server's line from then on, and no answer means the command proceeds. It is a guardrail, not a security boundary: the launcher's fast-path reads and a guard running with `PASSPORT_AGENT_KEY` don't check. After answering it never waits on the network: its report, the batches, and, at most every ten minutes, a refresh of a policy cache older than an hour go through the detached `passport hook flush`. Any failure is silent and fails open. Neither hook sends the raw command line, output, folder path, or environment. Both hooks exchange the profile's refresh credential without rotating it and keep the short-lived access token in `$PASSPORT_HOME/.<profile>.access.json` (`src/accessTokenCache.ts`, mode 600, atomic replace), so most runs send one request instead of an exchange and then the request. A cached token is used only with more than a minute left; a 401 on it drops it, exchanges once, and retries once.
265
265
 
266
266
  An ask becomes one Activity row. In Claude Code, with the audit hook registered, the guard parks its report in `$PASSPORT_HOME/hook-pending/` (`src/cliHookPending.ts`, mode 600, claimed by atomic rename). The audit hook for the same tool-use id sends the run with `decision: "ask", ran: true` ("asked first, then ran"). An ask nobody claims within 30 minutes (no agent fires a hook for a declined prompt) is sent by the next hook run as `ran: false` ("asked first, not run"). An allow the server gave is parked the same way, so the run's row says `Approved earlier this session`. Cursor has no tool-use id to match, so its asks are sent at once as their own "asked first" row. Denies are always sent at once; asks and blocks the server decided are recorded by the server.
267
267
 
@@ -307,8 +307,8 @@ passport actions sync # propose this repository's .passport/actions.toml
307
307
 
308
308
  - `rules test` classifies the command here and sends only its app and verb (and the environment kind) to `POST /api/my/rules/test`, never the command line. An everyday command goes as a finding (`{finding: {vendor, verb, risk, environment}}`), because only this computer can place its paths. It prints the decision, its cause, the environment, and the class. Without a server answer it decides from this computer's copy and says how old it is. `--environment` picks one when the flags don't say.
309
309
  - `wait` long-polls `GET /api/my/approvals/<id>/wait` (30 s per request), after a short first look that names who decides, until a person decides or the request expires; `--timeout <s>` caps it. Agents run it as a background command and are woken when it exits. Once Passport says the request is still pending (never for one that doesn't exist or is already decided), on a terminal it prints the approval link and one live line (`Waiting for Erin · 1:32 left`); piped, `Waiting for a decision on <id> (until it expires at 14:05).` and `Open in Passport: <url>`. Ctrl-C exits 4 with `The request is still open. Keep waiting any time.` and `Run: passport wait <id>`. Approved: `Approved by Ramish (once). Run the command again.`, or `… for this session. Matching commands in this session run without asking.` (exit 0). Declined: the person's note, cleaned and labelled, `Declined by Ramish. Their note: "Use staging first"` (exit 5, cause `approval_denied`). Expired: `Expired at 14:05 with no decision. Run the command again to ask again.` (exit 5, cause `approval_expired`). Still waiting at `--timeout`: exit 4 with the same command as `next`.
310
- - `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 in the last 7 days, 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=`). `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
- - `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` (the default), `7d`, `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.
310
+ - `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
+ - `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
312
  - `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
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 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`.
314
314
  - `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.
@@ -0,0 +1,15 @@
1
+ /**
2
+ * What a blind part of a command was, for coverage (`cliSeen.ts`): interpreter
3
+ * code on the line or in a heredoc, a file run by path or given to an
4
+ * interpreter (scripts, task targets, package scripts Passport couldn't
5
+ * read), or a program Passport doesn't know. Shared by the classifier,
6
+ * script reading, and the coverage log; imports nothing.
7
+ */
8
+ export type BlindKind = "inline" | "script" | "program";
9
+ /** The blind part of a classified line: its program's name, never a path, and its kind. */
10
+ export type Blind = {
11
+ program: string;
12
+ kind: BlindKind;
13
+ };
14
+ /** A blind part written as `program\tkind` (the coverage log, the script cache); no tab: a program. */
15
+ export declare function blindOfText(text: string): Blind;
@@ -0,0 +1,5 @@
1
+ /** A blind part written as `program\tkind` (the coverage log, the script cache); no tab: a program. */
2
+ export function blindOfText(text) {
3
+ const [program = "", kind] = text.split("\t");
4
+ return { program, kind: kind === "inline" || kind === "script" ? kind : "program" };
5
+ }
@@ -1,10 +1,11 @@
1
1
  /**
2
2
  * `passport changes`: what changed in Production, the list Sessions ›
3
- * Production changes shows. Every change, delete, and irreversible action
4
- * that ran on confirmed Production in the window, grouped by app, newest
5
- * first, with the agent, the person, the work item, the result, and undo.
3
+ * Production changes shows. Every Production change in the window (a change
4
+ * that ran and succeeded on Production or on a target nobody placed, by the
5
+ * server's one classifier), grouped by app, newest first, with the agent, the
6
+ * person, the work item, the result, and undo.
6
7
  *
7
- * passport changes the last 24 hours
8
+ * passport changes the last 7 days
8
9
  * passport changes --env production --since 1h
9
10
  *
10
11
  * Filters run on the server (`GET /api/my/production-changes`). `--json`
@@ -13,6 +14,7 @@
13
14
  import { type ParsedArgs } from "./cliArgs.js";
14
15
  import { type AutopilotDependencies } from "./cliMemberCall.js";
15
16
  import { type CommandResult, type Runtime } from "./cliSupport.js";
17
+ import { type WindowJson } from "./cliSessionsJson.js";
16
18
  import { type Term } from "./term.js";
17
19
  export type UndoJson = {
18
20
  state: string;
@@ -33,6 +35,8 @@ export type ChangeJson = {
33
35
  actionClass: "change" | "delete" | "irreversible";
34
36
  result: "ok" | "error";
35
37
  approved: boolean;
38
+ /** Its target nobody placed: counted as Production until someone does. */
39
+ unplaced: boolean;
36
40
  sessionId: string | null;
37
41
  project: string | null;
38
42
  branch: string | null;
@@ -51,7 +55,11 @@ export type ChangesJson = {
51
55
  untilTs: number | null;
52
56
  total: number;
53
57
  unplaced: number;
58
+ /** False from a server that counted unplaced changes apart from `total`. */
59
+ unplacedIncluded: boolean;
54
60
  complete: boolean;
61
+ /** The span `total` covers; null from older servers. */
62
+ window: WindowJson | null;
55
63
  apps: Array<{
56
64
  vendor: string;
57
65
  appName: string;
@@ -1,10 +1,11 @@
1
1
  /**
2
2
  * `passport changes`: what changed in Production, the list Sessions ›
3
- * Production changes shows. Every change, delete, and irreversible action
4
- * that ran on confirmed Production in the window, grouped by app, newest
5
- * first, with the agent, the person, the work item, the result, and undo.
3
+ * Production changes shows. Every Production change in the window (a change
4
+ * that ran and succeeded on Production or on a target nobody placed, by the
5
+ * server's one classifier), grouped by app, newest first, with the agent, the
6
+ * person, the work item, the result, and undo.
6
7
  *
7
- * passport changes the last 24 hours
8
+ * passport changes the last 7 days
8
9
  * passport changes --env production --since 1h
9
10
  *
10
11
  * Filters run on the server (`GET /api/my/production-changes`). `--json`
@@ -13,13 +14,13 @@
13
14
  import { value } from "./cliArgs.js";
14
15
  import { api, json } from "./cliMemberCall.js";
15
16
  import { failure, timeoutMs } from "./cliSupport.js";
16
- import { appName, clientName, count, list, oneOf, record, text, time } from "./cliSessionsJson.js";
17
+ import { appName, clientName, count, list, oneOf, record, text, time, windowOf } from "./cliSessionsJson.js";
17
18
  import { countOf } from "./plural.js";
18
19
  import { joinParts, mark, visibleLength, wrap, termOf } from "./term.js";
19
20
  import { hashLink } from "./webLinks.js";
20
21
  const DATE = /^\d{4}-\d{2}-\d{2}$/;
21
22
  const RANGES = ["1h", "6h", "24h", "7d", "30d", "today"];
22
- const DEFAULT_SINCE = "24h";
23
+ const DEFAULT_SINCE = "7d";
23
24
  const WINDOW_WORDS = {
24
25
  "1h": "last hour",
25
26
  "6h": "last 6 hours",
@@ -138,6 +139,7 @@ function changeOf(raw) {
138
139
  actionClass: oneOf(entry.actionClass, ["change", "delete", "irreversible"]) ?? "change",
139
140
  result: entry.result === "error" ? "error" : "ok",
140
141
  approved: entry.approved === true,
142
+ unplaced: entry.unplaced === true,
141
143
  sessionId: text(entry.sessionId, 128) ?? null,
142
144
  project: text(work.project, 200) ?? null,
143
145
  branch: text(work.branch, 200) ?? null,
@@ -180,7 +182,9 @@ export function changesOf(raw) {
180
182
  untilTs: time(page.untilTs),
181
183
  total: Math.max(count(page.total), changes.length),
182
184
  unplaced: count(page.unplaced),
185
+ unplacedIncluded: page.unplacedIncluded === true,
183
186
  complete: page.complete !== false,
187
+ window: windowOf(page.window),
184
188
  apps
185
189
  };
186
190
  }
@@ -228,6 +232,8 @@ export function changeParts(change, projects = false) {
228
232
  parts.push(change.branch);
229
233
  if (change.result === "error")
230
234
  parts.push("Failed");
235
+ if (change.unplaced)
236
+ parts.push("Unplaced");
231
237
  if (change.approved)
232
238
  parts.push("Approved");
233
239
  const undo = undoPart(change.undo);
@@ -268,18 +274,22 @@ export function foldChanges(changes) {
268
274
  }
269
275
  return runs;
270
276
  }
271
- function windowWord(since, sinceTs, now) {
272
- return WINDOW_WORDS[since] ?? (sinceTs ? `since ${changeTime(sinceTs, now)}` : `since ${since}`);
277
+ /** The server's label for the window it counted; an older server's, worded here. */
278
+ function windowWord(page, since, now) {
279
+ if (page.window)
280
+ return page.window.label;
281
+ return WINDOW_WORDS[since] ?? (page.sinceTs ? `since ${changeTime(page.sinceTs, now)}` : `since ${since}`);
273
282
  }
274
283
  export function renderChanges(page, term, now, since, links) {
275
284
  const arrow = term.unicode ? "→" : "->";
276
- const lines = joinParts([
277
- "Production changes",
278
- windowWord(since, page.sinceTs, now),
279
- `${countOf(page.total, "change")} on confirmed Production`
280
- ], term.width);
285
+ // Since the count shape, unplaced changes are among the total and listed;
286
+ // an older server listed confirmed Production only.
287
+ const where = page.unplacedIncluded ? "on Production" : "on confirmed Production";
288
+ const lines = joinParts(["Production changes", windowWord(page, since, now), `${countOf(page.total, "change")} ${where}`], term.width);
281
289
  if (!page.apps.length)
282
- lines.push("", ...wrap("Nothing your agents ran changed a target you placed in Production in this window.", term.width));
290
+ lines.push("", ...wrap(page.unplacedIncluded
291
+ ? "Nothing your agents ran changed Production in this window."
292
+ : "Nothing your agents ran changed a target you placed in Production in this window.", term.width));
283
293
  const projects = new Set(page.apps.flatMap((app) => app.changes.map((change) => change.project)).filter(Boolean)).size > 1;
284
294
  const times = term.unicode ? "×" : "x";
285
295
  for (const app of page.apps) {
@@ -301,7 +311,8 @@ export function renderChanges(page, term, now, since, links) {
301
311
  lines.push(`See all: ${links.more}`);
302
312
  }
303
313
  if (page.unplaced) {
304
- lines.push("", ...wrap(`${countOf(page.unplaced, "unplaced action")}, counted as Production until you place them.`, term.width));
314
+ const among = page.unplacedIncluded ? " among them" : "";
315
+ lines.push("", ...wrap(`${countOf(page.unplaced, "unplaced action")}${among}, counted as Production until you place them.`, term.width));
305
316
  if (links.environments)
306
317
  lines.push(`Set environments: ${links.environments}`);
307
318
  }
@@ -87,8 +87,8 @@ export function problemFix(kind, client) {
87
87
  return {
88
88
  text: "Move it back into Passport.",
89
89
  command: "passport keys move",
90
- link: "#apps",
91
- docs: `${DOCS_BASE}/member/cli-hook#keys-back-on-a-computer`
90
+ link: "#settings/keys",
91
+ docs: `${DOCS_BASE}/member/cli-hook#keys-in-passport`
92
92
  };
93
93
  }
94
94
  }
package/dist/cliHook.js CHANGED
@@ -505,9 +505,9 @@ async function runGuard(args, runtime, deps) {
505
505
  const plan = await planGuard(decision, policy, {
506
506
  client,
507
507
  mode,
508
- canAsk: Boolean(profile) && canReport && !event.cursorImported,
508
+ canAsk: canReport && !event.cursorImported,
509
509
  openApi: () => profileApi(profile, budget, deps.fetch ?? fetch).catch(() => null),
510
- report: base,
510
+ report: base ?? context(input, runtime.env, declared),
511
511
  local,
512
512
  command: event.command,
513
513
  budget,
@@ -0,0 +1,15 @@
1
+ /**
2
+ * What a blind part of a command was, for coverage: the program that ran it
3
+ * (a plain name, never a path) and its kind, so Rules › Project scripts can
4
+ * tell inline code from a project script from a program Passport doesn't know.
5
+ */
6
+ import type { BlindKind } from "./blindKind.js";
7
+ import type { ShellWord } from "./localCommands.js";
8
+ /** The program a part ran, by name. A file run by path (`./x.sh`, `~/bin/tool`,
9
+ * `$HOME/bin/tool`, `node_modules/.bin/tsc`) is "script". */
10
+ export declare function programOf(argv: string[]): string;
11
+ /** A program run from the home folder by `$HOME/…`: read like `~/…`, so its place is known. */
12
+ export declare function homeProgram<W extends ShellWord>(words: W[]): W[];
13
+ /** Script: a file run by path or given to an interpreter, a task target, a package
14
+ * script Passport couldn't read. Program: anything else it doesn't know. */
15
+ export declare function blindKind(program: string, argv: string[]): BlindKind;
@@ -0,0 +1,65 @@
1
+ /**
2
+ * What a blind part of a command was, for coverage: the program that ran it
3
+ * (a plain name, never a path) and its kind, so Rules › Project scripts can
4
+ * tell inline code from a project script from a program Passport doesn't know.
5
+ */
6
+ import { normalizeArgv } from "./cliHookParse.js";
7
+ const HOME_PATH = /^(?:\$HOME|\$\{HOME\})(?=\/|$)/;
8
+ const ASSIGNMENT = /^[A-Za-z_][A-Za-z0-9_]*=/;
9
+ /** The program a part ran, by name. A file run by path (`./x.sh`, `~/bin/tool`,
10
+ * `$HOME/bin/tool`, `node_modules/.bin/tsc`) is "script". */
11
+ export function programOf(argv) {
12
+ const normalized = normalizeArgv(argv);
13
+ if (normalized.via.includes("absolute-path"))
14
+ return "script";
15
+ const first = argv[argv.length - normalized.argv.length] ?? "";
16
+ return HOME_PATH.test(first) || first.startsWith("~") ? "script" : (normalized.argv[0] ?? "");
17
+ }
18
+ /** A program run from the home folder by `$HOME/…`: read like `~/…`, so its place is known. */
19
+ export function homeProgram(words) {
20
+ const index = words.findIndex((word) => !ASSIGNMENT.test(word.text));
21
+ const head = words[index];
22
+ if (!head?.expands || !HOME_PATH.test(head.text))
23
+ return words;
24
+ const rest = head.text.replace(HOME_PATH, "");
25
+ if (/[$`*?[]/.test(rest))
26
+ return words;
27
+ const copy = [...words];
28
+ copy[index] = { text: `~${rest}`, tilde: true };
29
+ return copy;
30
+ }
31
+ const RUNNERS = new Set([
32
+ "node",
33
+ "nodejs",
34
+ "tsx",
35
+ "ts-node",
36
+ "bun",
37
+ "deno",
38
+ "python",
39
+ "python2",
40
+ "python3",
41
+ "ruby",
42
+ "perl",
43
+ "bash",
44
+ "sh",
45
+ "zsh",
46
+ "dash",
47
+ "ksh",
48
+ "fish",
49
+ "php",
50
+ "osascript"
51
+ ]);
52
+ const TASK_RUNNERS = new Set(["make", "just", "task", "source", "."]);
53
+ const PACKAGE_MANAGERS = new Set(["npm", "pnpm", "yarn", "bun"]);
54
+ /** Script: a file run by path or given to an interpreter, a task target, a package
55
+ * script Passport couldn't read. Program: anything else it doesn't know. */
56
+ export function blindKind(program, argv) {
57
+ if (program === "script" || TASK_RUNNERS.has(program))
58
+ return "script";
59
+ const rest = normalizeArgv(argv).argv.slice(1);
60
+ if (RUNNERS.has(program) && rest.some((word) => !word.startsWith("-")))
61
+ return "script";
62
+ if (PACKAGE_MANAGERS.has(program) && /^(run|run-script)$/.test(rest.find((word) => !word.startsWith("-")) ?? ""))
63
+ return "script";
64
+ return "program";
65
+ }
@@ -99,13 +99,20 @@ export declare function offlineVerdict(decision: GuardDecision, policy: CachedCl
99
99
  secondPerson: boolean;
100
100
  attended: boolean;
101
101
  }, now: number): OfflineVerdict;
102
+ /** What an attended irreversible ask says when Passport can't be reached. */
103
+ export declare const IRREVERSIBLE_UNREACHABLE = "Passport can't be reached. Irreversible commands need approval in Passport.";
104
+ /** What an irreversible ask tells the agent while it waits in Passport. */
105
+ export declare const IRREVERSIBLE_IN_PASSPORT = "Approve this in Passport. Irreversible actions need a passkey check.";
102
106
  /**
103
107
  * Attended, or no v2 policy: the local decision, printed at once. Unattended
104
108
  * ask: the server decides within the budget, and an approval request replaces
105
109
  * the prompt nobody would answer; a server that can't answer in time leaves
106
110
  * the local decision with one line saying so.
107
111
  */
108
- export declare function planGuard(decision: GuardDecision | null, policy: CachedCliPolicy | null, context: {
112
+ export declare function planGuard(...args: Parameters<typeof decidePlan>): Promise<GuardPlan & {
113
+ api?: ApiCall;
114
+ }>;
115
+ declare function decidePlan(decision: GuardDecision | null, policy: CachedCliPolicy | null, context: {
109
116
  client: GuardClient;
110
117
  mode: HookMode;
111
118
  /** Signed in with a member profile that may report. */
@@ -23,6 +23,7 @@ import { OFFLINE_CACHE_MAX_MS, OFFLINE_DEFAULT, OFFLINE_NOTES, offlineDecision }
23
23
  import { commandKey } from "./cliHookKey.js";
24
24
  import { unknownVerb, UNRECOGNIZED_VERB } from "./cliHookClassify.js";
25
25
  import { redactCommand } from "./cliHookRedact.js";
26
+ import { endedSessionLine, rememberEnded } from "./cliHookSessionEnd.js";
26
27
  export const CLI_DECIDE_PATH = "/api/my/cli/decide";
27
28
  const MAX_RESPONSE_BYTES = 16 * 1024;
28
29
  const MAX_FINDINGS = 8;
@@ -128,7 +129,11 @@ export async function decideOnServer(api, request, signal) {
128
129
  await response.body?.cancel().catch(() => undefined);
129
130
  return null;
130
131
  }
131
- return parseServerDecision(await readBoundedJson(response, MAX_RESPONSE_BYTES));
132
+ const decided = parseServerDecision(await readBoundedJson(response, MAX_RESPONSE_BYTES));
133
+ // Passport refused because a person ended this session: remember it here.
134
+ if (decided?.decision === "block")
135
+ rememberEnded(request, decided.message);
136
+ return decided;
132
137
  }
133
138
  catch {
134
139
  return null;
@@ -223,13 +228,48 @@ function serverOutput(client, decision, server) {
223
228
  : {};
224
229
  return guardOutput(client, decided, options);
225
230
  }
231
+ /** What an attended irreversible ask says when Passport can't be reached. */
232
+ export const IRREVERSIBLE_UNREACHABLE = "Passport can't be reached. Irreversible commands need approval in Passport.";
233
+ /** What an irreversible ask tells the agent while it waits in Passport. */
234
+ export const IRREVERSIBLE_IN_PASSPORT = "Approve this in Passport. Irreversible actions need a passkey check.";
235
+ /** Whether any command in the line that asked is irreversible. */
236
+ function irreversibleAsk(decision) {
237
+ return (decision.actionClass === "irreversible" ||
238
+ (decision.decided ?? []).some((entry) => entry.decision === "ask" && entry.actionClass === "irreversible"));
239
+ }
240
+ function attendedIrreversible(decision, mode) {
241
+ return mode !== "unattended" && irreversibleAsk(decision);
242
+ }
243
+ /** An attended ask the agent's own prompt answers (Codex can't ask from a hook). */
244
+ function staysLocal(context, toPassport) {
245
+ return context.mode !== "unattended" && !toPassport && context.client !== "codex";
246
+ }
247
+ function unreachableIrreversible(client, decision, api) {
248
+ const output = guardOutput(client, { ...decision, verdict: "deny" }, { waiting: IRREVERSIBLE_UNREACHABLE });
249
+ return { output, server: null, offline: true, verdict: "deny", ...(api ? { api } : {}) };
250
+ }
251
+ /** A person ended this session in Passport: nothing more runs in it, even a
252
+ * command this computer would let run (`cliHookSessionEnd.ts`). */
253
+ async function endedPlan(decision, context) {
254
+ // Only what would run without anyone deciding: an ask is a person's call.
255
+ if (!context.canAsk || (decision && decision.verdict !== "allow"))
256
+ return null;
257
+ const ended = await endedSessionLine(context.report, context.openApi, context);
258
+ if (!ended)
259
+ return null;
260
+ const refused = decision ?? { verdict: "deny", label: "command", findings: [], destructive: false };
261
+ return { output: guardOutput(context.client, refused, { waiting: ended }), server: null, offline: false };
262
+ }
226
263
  /**
227
264
  * Attended, or no v2 policy: the local decision, printed at once. Unattended
228
265
  * ask: the server decides within the budget, and an approval request replaces
229
266
  * the prompt nobody would answer; a server that can't answer in time leaves
230
267
  * the local decision with one line saying so.
231
268
  */
232
- export async function planGuard(decision, policy, context) {
269
+ export async function planGuard(...args) {
270
+ return (await endedPlan(args[0], args[2])) ?? decidePlan(...args);
271
+ }
272
+ async function decidePlan(decision, policy, context) {
233
273
  const local = { output: decision ? guardOutput(context.client, decision) : null, server: null, offline: false };
234
274
  // A Production action someone else must approve goes to Passport even when
235
275
  // someone is at the keyboard: the agent's own prompt would let them approve it.
@@ -240,9 +280,12 @@ export async function planGuard(decision, policy, context) {
240
280
  Boolean(policy.autopilot.secondPerson?.classes.includes(decision.actionClass)));
241
281
  if (!decision || decision.verdict !== "ask" || policy?.version !== 2)
242
282
  return local;
283
+ // An irreversible action is approved only in Passport, with a passkey check:
284
+ // the one attended ask that waits on the network (docs/DECISIONS.md).
285
+ const irreversible = attendedIrreversible(decision, context.mode);
243
286
  // Codex can't ask from a hook: like an unattended run, the ask goes to
244
287
  // Passport as an approval request instead of a prompt nobody would see.
245
- if (context.mode !== "unattended" && !secondPerson && context.client !== "codex")
288
+ if (staysLocal(context, secondPerson || irreversible))
246
289
  return local;
247
290
  if (!context.canAsk)
248
291
  return local;
@@ -262,6 +305,9 @@ export async function planGuard(decision, policy, context) {
262
305
  const server = api && left > 50
263
306
  ? await decideOnServer(api, request, AbortSignal.any([context.budget, AbortSignal.timeout(left)]))
264
307
  : null;
308
+ // Never the agent's own Approve prompt, even with Passport out of reach.
309
+ if (!server && irreversible)
310
+ return unreachableIrreversible(context.client, decision, api);
265
311
  if (!server) {
266
312
  // Passport didn't answer in time: the environment's offline setting decides.
267
313
  const offline = offlineVerdict(decision, policy, { client: context.client, secondPerson, attended: context.mode === "attended" }, context.now());
@@ -288,7 +334,9 @@ async function heldPlan(decision, server, request, api, context) {
288
334
  return { output: serverOutput(context.client, decision, server), server, offline: false, api };
289
335
  const hold = await import("./cliHookHold.js");
290
336
  const pending = (who, expiresAt, approvalId) => guardOutput(context.client, { ...decision, verdict: "deny" }, {
291
- waiting: hold.pendingMessage(approvalId ?? waiting.approvalId, who ?? waiting.waitingFor, expiresAt ?? waiting.expiresAt, context.now())
337
+ // An irreversible action says first that it's approved in Passport.
338
+ waiting: (irreversibleAsk(decision) ? `${IRREVERSIBLE_IN_PASSPORT} ` : "") +
339
+ hold.pendingMessage(approvalId ?? waiting.approvalId, who ?? waiting.waitingFor, expiresAt ?? waiting.expiresAt, context.now())
292
340
  });
293
341
  // Only Claude Code holds: Codex can't run an approved command from a hook,
294
342
  // and Cursor's behaviour past a hook's timeout isn't documented.
@@ -15,21 +15,12 @@
15
15
  * applies. Asks and blocks still come from whatever parts were understood.
16
16
  */
17
17
  import { type CliFinding } from "./cliHookClassify.js";
18
- import { type FileStat, type ScriptFile, type ScriptReader } from "./cliScriptRead.js";
18
+ import type { Blind } from "./blindKind.js";
19
+ import type { ScriptReader } from "./cliScriptRead.js";
20
+ import { type LocalFs } from "./cliHookLocalFs.js";
19
21
  import type { DecidedFinding } from "./cliHookGuard.js";
20
22
  import { type LocalAction, type Place, type ShellWord } from "./localCommands.js";
21
- /** What the hook can read from the machine. Injected so tests never touch it. */
22
- export type LocalFs = {
23
- /** The canonical path, or null when it doesn't exist. */
24
- realpath(path: string): string | null;
25
- /** A small text file, or null. */
26
- readText(path: string): string | null;
27
- isDirectory(path: string): boolean;
28
- isFile(path: string): boolean;
29
- /** A script up to 256 KB with its time and size (script reading), or null. */
30
- readScript?(path: string): ScriptFile | null;
31
- statFile?(path: string): FileStat | null;
32
- };
23
+ export { NODE_FS, type LocalFs } from "./cliHookLocalFs.js";
33
24
  export type LocalMachine = {
34
25
  /** The folder the agent's command starts in, canonical; null when unknown. */
35
26
  cwd: string | null;
@@ -47,7 +38,6 @@ export type LocalMachine = {
47
38
  /** Read the project's own scripts (`cliScriptRead.ts`). Absent: scripts stay unread. */
48
39
  scripts?: ScriptReader;
49
40
  };
50
- export declare const NODE_FS: LocalFs;
51
41
  /** Canonical form of a path that may not exist yet: resolve the deepest
52
42
  * existing ancestor (following symlinks) and keep the rest as written. */
53
43
  export declare function canonical(path: string, fs: LocalFs): string;
@@ -79,8 +69,9 @@ export type LineResult = {
79
69
  /** Every part understood: the only lines Passport may allow. */
80
70
  complete: boolean;
81
71
  /** A part Passport couldn't tell anything about (an unknown program, a
82
- * one-liner): the program that ran it, for coverage's Blind count. */
83
- blind?: string;
72
+ * one-liner it couldn't read): the program that ran it and its kind, for
73
+ * coverage's Blind count. */
74
+ blind?: Blind;
84
75
  };
85
76
  /** A local action as a finding the guard and reports understand. */
86
77
  export declare function localFinding(action: LocalAction): CliFinding;