passport-bridge 0.14.0 → 0.16.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.
- package/README.md +40 -3
- package/dist/cliAnswered.d.ts +38 -0
- package/dist/cliAnswered.js +217 -0
- package/dist/cliArgs.d.ts +1 -1
- package/dist/cliArgs.js +33 -7
- package/dist/cliAutopilot.d.ts +23 -1
- package/dist/cliAutopilot.js +179 -51
- package/dist/cliAutopilotPolicy.d.ts +50 -6
- package/dist/cliAutopilotPolicy.js +53 -4
- package/dist/cliEnv.d.ts +40 -0
- package/dist/cliEnv.js +157 -0
- package/dist/cliExec.d.ts +83 -0
- package/dist/cliExec.js +453 -0
- package/dist/cliHook.d.ts +19 -24
- package/dist/cliHook.js +95 -70
- package/dist/cliHookClassify.d.ts +30 -0
- package/dist/cliHookClassify.js +32 -2
- package/dist/cliHookDecide.d.ts +6 -3
- package/dist/cliHookDecide.js +26 -9
- package/dist/cliHookEnvironment.d.ts +9 -3
- package/dist/cliHookEnvironment.js +69 -15
- package/dist/cliHookGuard.d.ts +32 -6
- package/dist/cliHookGuard.js +155 -26
- package/dist/cliHookInput.d.ts +27 -0
- package/dist/cliHookInput.js +47 -0
- package/dist/cliHookInstall.js +16 -0
- package/dist/cliHookLocal.d.ts +79 -0
- package/dist/cliHookLocal.js +473 -0
- package/dist/cliHookParse.d.ts +33 -0
- package/dist/cliHookParse.js +144 -30
- package/dist/cliHookRewrite.d.ts +45 -0
- package/dist/cliHookRewrite.js +135 -0
- package/dist/cliHookVendors.js +8 -2
- package/dist/cliHookVendorsMore.d.ts +21 -0
- package/dist/cliHookVendorsMore.js +196 -0
- package/dist/cliInit.js +2 -1
- package/dist/cliKeys.d.ts +67 -0
- package/dist/cliKeys.js +426 -0
- package/dist/cliLogin.js +1 -1
- package/dist/cliOutput.js +10 -0
- package/dist/cliPolicy.d.ts +2 -0
- package/dist/cliPolicyRefresh.d.ts +7 -0
- package/dist/cliPolicyRefresh.js +20 -0
- package/dist/cliPolicyV2.js +126 -16
- package/dist/cliSetupOrg.js +12 -0
- package/dist/cliSync.d.ts +14 -0
- package/dist/cliSync.js +63 -0
- package/dist/cliUndo.d.ts +49 -0
- package/dist/cliUndo.js +312 -0
- package/dist/completion.js +12 -1
- package/dist/envDatabase.d.ts +28 -0
- package/dist/envDatabase.js +166 -0
- package/dist/envLinkFs.d.ts +57 -0
- package/dist/envLinkFs.js +140 -0
- package/dist/envLinksCloud.d.ts +31 -0
- package/dist/envLinksCloud.js +233 -0
- package/dist/envLinksHosting.d.ts +33 -0
- package/dist/envLinksHosting.js +463 -0
- package/dist/envResolve.d.ts +48 -0
- package/dist/envResolve.js +221 -0
- package/dist/envTarget.d.ts +61 -0
- package/dist/envTarget.js +50 -0
- package/dist/execBackupTarget.d.ts +25 -0
- package/dist/execBackupTarget.js +201 -0
- package/dist/execMarker.d.ts +7 -0
- package/dist/execMarker.js +66 -0
- package/dist/execVendors.d.ts +34 -0
- package/dist/execVendors.js +221 -0
- package/dist/initAutopilotStep.js +72 -5
- package/dist/initKeysStep.d.ts +2 -0
- package/dist/initKeysStep.js +67 -0
- package/dist/initLocalSteps.js +1 -1
- package/dist/initState.d.ts +3 -0
- package/dist/keysLocal.d.ts +56 -0
- package/dist/keysLocal.js +494 -0
- package/dist/localCommands.d.ts +39 -0
- package/dist/localCommands.js +534 -0
- package/dist/localFiles.d.ts +22 -0
- package/dist/localFiles.js +272 -0
- package/dist/localGit.d.ts +24 -0
- package/dist/localGit.js +270 -0
- package/dist/localNetwork.d.ts +16 -0
- package/dist/localNetwork.js +185 -0
- package/dist/localShared.d.ts +99 -0
- package/dist/localShared.js +173 -0
- package/dist/localTools.d.ts +52 -0
- package/dist/localTools.js +643 -0
- package/dist/nativeSync.d.ts +89 -0
- package/dist/nativeSync.js +376 -0
- package/dist/passport.js +25 -12
- package/dist/pluginPin.d.ts +1 -1
- package/dist/pluginPin.js +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -67,6 +67,7 @@ passport run github_search_issues '{"query":"SSO"}'
|
|
|
67
67
|
| `wait <approval-id> [--timeout <s>]` | Wait for a person to decide an approval request (default 100 seconds). |
|
|
68
68
|
| `rules test "<command>" [--environment <kind>]` | What Autopilot decides for a command, why, and which environment it acts on. |
|
|
69
69
|
| `sessions [--status running\|idle\|ended]` | Your agents' recent sessions with what Passport decided. |
|
|
70
|
+
| `undo <action-id>\|--last [--option <id>] [--yes]` | Undo an action Passport took a backup before, within 7 days. See [Undo](#undo). |
|
|
70
71
|
| `setup --org <pek_key> [--yes] [--clients <list>]` | Set up every agent on this computer for your company without asking anything (MDM and scripts). See [Company rollout](#company-rollout). |
|
|
71
72
|
| `setup` | Install and maintain assigned team workflows as managed skills. |
|
|
72
73
|
| `session` | Run NDJSON commands over one authenticated MCP session. |
|
|
@@ -205,10 +206,12 @@ passport hook uninstall --client claude-code --guard --apply # guard only
|
|
|
205
206
|
|
|
206
207
|
Two hooks per agent. `passport hook` runs after each shell command and records the vendor, a coarse verb, a risk class, and (with Autopilot) the environment name the flags gave and the guard's decision in Activity; the server works out the class and cause. `passport hook guard` runs before it and decides from the member's Autopilot rules (`src/cliHookGuard.ts`):
|
|
207
208
|
|
|
208
|
-
- **Allow** (Claude Code `permissionDecision: "allow"`, Cursor `permission: "allow"`) only when every
|
|
209
|
+
- **Allow** (Claude Code `permissionDecision: "allow"`, Cursor `permission: "allow"`) only when every part of the line is understood and allowed: vendor commands in `src/cliHookVendors.ts` read with confidence, and everyday commands (below). Substitutions, heredocs, variables in a path, unknown wrappers or environment prefixes, scripts, aliases, `make`, and programs Passport doesn't know mean no decision, so the agent's own permission rules apply. Codex can't receive allow; its own approvals apply (see `passport sync`).
|
|
209
210
|
- **Ask** or **deny** when any recognized command needs it. The strictest part of a compound command wins and names itself. `--help` and `--dry-run` never ask.
|
|
210
211
|
- Each reason names its cause in one line: `Passport: railway redeploy changes Production. Approve to run it.`, or `Blocked by Passport: Team rule, no deletes in Production. Ask an admin to run it, or request an exception in Passport.`
|
|
211
212
|
|
|
213
|
+
**Everyday commands** (`src/cliHookLocal.ts`, tables in `src/localCommands.ts`, `localTools.ts`, `localFiles.ts`, `localGit.ts`, `localNetwork.ts`). Local commands are placed by what they touch on this computer. The project folder (the git root, else the agent's folder; never `/` or the home folder) is Development: reads such as `ls`, `rg`, `git status`, test runners, linters, builds, and type checks are Reads; `git commit`, formatters with `--write`, package scripts, and `mv`/`cp` are Changes; `rm`, `git clean -fd`, and `git reset --hard` are Deletes. Package installs (`npm install`, `pip install`, `brew install`) are Changes in Other apps. `git push` to the default branch (origin's HEAD, else `main`/`master`) is a Change in Production, to any other branch a Change in Development; deleting a remote branch (`--delete`, `:branch`) is a Delete in Other apps because teammates share it. Temporary folders (`/tmp`, `$TMPDIR`) count as Development; deleting one whole is Irreversible. Outside the project: deleting the home folder, `/`, system paths, or the whole project is Irreversible; other writes are Changes and deletes are Deletes in Other apps; writes to keys, shell startup files, or an agent's own settings are Deletes, and reads of them are no decision. `curl`/`wget` GETs are Reads and anything that sends data is a Change, in Other apps (Development for localhost). docker `ps`/`logs` read, `run`/`build`/`compose up` change, `rm`/`prune` delete. `sudo` never runs silently. Symlinks are resolved before deciding, `cd` is followed through `&&`, `;`, and subshells, and redirects are writes where they land. The server keeps a generated copy of the tables (`node scripts/generate-local-commands.mjs`) for `rules test` on the web. Allowed project work and reads are counted on the machine ("Answered for you") rather than recorded one by one; installs, pushes, and anything that asks or blocks are recorded like vendor commands, with the environment kind and never a path.
|
|
214
|
+
|
|
212
215
|
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.`
|
|
213
216
|
|
|
214
217
|
**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:
|
|
@@ -242,14 +245,47 @@ The Passport plugin (`rsyed94/passport-plugins`) runs the same two hooks from th
|
|
|
242
245
|
|
|
243
246
|
```sh
|
|
244
247
|
passport rules test "railway redeploy -e staging"
|
|
248
|
+
passport rules test "rm -rf ~/"
|
|
245
249
|
passport wait apr_123
|
|
246
250
|
passport sessions
|
|
251
|
+
passport sync # or: passport sync --remove
|
|
252
|
+
passport env # or: passport env set railway qa staging
|
|
247
253
|
```
|
|
248
254
|
|
|
249
|
-
- `
|
|
255
|
+
- `env` lists where commands in this folder land, read the way each vendor's own CLI reads it (`src/envResolve.ts`; order: flag, the folder's link, the vendor's default, the workspace's saved mapping, the whole-word naming rule, else Production). Link readers: `src/envLinksHosting.ts` (Railway `~/.railway/config.json`, Vercel `.vercel/project.json` / `repo.json`, Supabase `supabase/.temp/project-ref`, Wrangler config, Netlify `.netlify/state.json`, Firebase `.firebaserc` + configstore, Convex `CONVEX_DEPLOYMENT`, Neon `.neon`), `src/envLinksCloud.ts` (Fly, Heroku git remotes, kubeconfig, AWS profile, gcloud configuration, Terraform workspace, Stripe key mode), and `src/envDatabase.ts` (database URLs: only `DATABASE_URL`, `DIRECT_URL`, `POSTGRES_URL*`, `DATABASE_URL_UNPOOLED`, reduced to a host-derived key; the URL, user, and password never leave the function). Files are read fresh for every command, size-capped, and a link file symlinked out of the project is ignored (`src/envLinkFs.ts`). A name in a link file never loosens anything: an unplaced id is Production, and for a placed id its mapping decides while a different name is treated as a rename (sent as the new label, which the server stores). Findings to a server that sends `resources` in cli-policy v2 carry `{kind, source, resourceKey?, label?, platform?, flag?, via}`. `env set` calls `PUT /api/my/environments/:platform/:key`; members may only say Production.
|
|
256
|
+
|
|
257
|
+
- `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.
|
|
250
258
|
- `wait` long-polls `GET /api/my/approvals/<id>/wait`. Approved: `Approved by Ramish. Run the command again.` (exit 0). Declined: the note for the agent, `Declined by Ramish: <note>` (exit 5, cause `approval_denied`). Expired: `Expired. The agent can ask again.` (exit 5, cause `approval_expired`). Still waiting at `--timeout` (default 100 seconds, under an agent's 2-minute command limit): exit 4 with the same command as `next`.
|
|
251
259
|
- `sessions` lists recent sessions (`GET /api/my/agent-sessions`): status, agent, folder, start, `42 ran · 2 asked · 1 blocked`, environments touched, and `Waiting for you` when approvals are pending.
|
|
252
|
-
-
|
|
260
|
+
- `sync` writes the allows Passport is sure of into each agent's own permission settings, so those prompts disappear offline and in Codex (`src/nativeSync.ts`). Only reads, test runners, builds and type checks, linters that only check, `git status`, `git add`, and `git commit`, checked against the person's rules. Formatters, fixing linters, `mv`/`cp`, and package scripts stay with the hook, which sees what they touch; deletes, installs, pushes, and Production never sync. Claude Code: `Bash(npm test *)` in `permissions.allow` of `~/.claude/settings.json`. Codex: `prefix_rule(pattern = ["npm", "test"], decision = "allow")` in `~/.codex/rules/passport.rules`, a file Passport owns. Cursor CLI: `Shell(npm:test*)` in `permissions.allow` of `~/.cursor/cli-config.json`. Cursor: `npm test` in `terminalAllowlist` of `~/.cursor/permissions.json`, only when that list already exists there (defining it replaces Cursor's in-app list). Entries Passport added are listed in `$PASSPORT_HOME/native-sync.json`; an entry you had before is never claimed or removed, and a file Passport can't parse exactly (JSONC) is left alone. Sync runs on `init`, `setup --org`, every rules refresh, and `passport sync`; `hook uninstall`, `sync --remove`, and signing out of the last profile take the entries out.
|
|
261
|
+
- `status` adds `Answered for you: N prompts today` (allows the hook gave in Claude Code and Cursor, and Codex commands Passport synced, counted only when the agent would have prompted) and which agents' allowlists are synced. Counts are appended locally (`$PASSPORT_HOME/answered/`) and sent in batches at most every five minutes as `answered: {batch, count}` on `POST /api/my/cli-activity`.
|
|
262
|
+
- `rules test`, `sessions`, and `sync` need a member profile. `wait` also works for a cloud agent's key, on the approval its own `passport exec` opened.
|
|
263
|
+
|
|
264
|
+
### Keys and passport exec
|
|
265
|
+
|
|
266
|
+
```sh
|
|
267
|
+
passport keys move # confirm each key, store it in Passport, sign that CLI out here
|
|
268
|
+
passport keys # what Passport holds, and what's still on this computer
|
|
269
|
+
passport keys add railway # store a key you paste (stdin, never echoed)
|
|
270
|
+
passport exec -- railway up -e staging
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
- `keys move` finds CLI sign-ins (Railway, GitHub CLI, Vercel, Wrangler API tokens, Supabase, Stripe test keys, the AWS `default` profile) and tokens in Claude Code's settings `env`. For each it asks, stores the key in Passport (`POST /api/my/keys`), then signs that CLI out with its own command (`railway logout`, `gh auth logout`, `vercel logout`, `wrangler logout`, `supabase logout`, `stripe logout`) or removes only that entry. A sign-out that fails leaves the key in Passport and says what's left on disk. `.env` files are never touched: "Used by your app, so Passport leaves it." Browser-session sign-ins (Railway, Vercel, Wrangler OAuth) can't move; the line says how to make a token instead. From the CLI, a different key than the one already in Passport is refused; rotate it in Apps. The scan report sent afterwards carries provider counts only.
|
|
274
|
+
- `exec -- <cli> …` runs railway, gh, vercel, wrangler, supabase, stripe, aws, neonctl, or flyctl from PATH. It classifies the command here, asks `POST /api/my/exec/authorize`, and on allow sets only that vendor's variables (`GH_TOKEN`, `RAILWAY_API_TOKEN`, `VERCEL_TOKEN`, `CLOUDFLARE_API_TOKEN`, `SUPABASE_ACCESS_TOKEN`, `STRIPE_API_KEY`, `AWS_*`, `NEON_API_KEY`, `FLY_API_TOKEN`) in the child's environment, removing Passport's own and any stray vendor tokens. Output and exit code pass through. Afterwards it reports the exit code and duration (`POST /api/my/exec/result`, best effort, two seconds at most) so the session row reads Ran or Failed. It refuses paths, shells, `env`, and subcommands that would print the key, sign in again, mint longer-lived tokens, or run another program with the key (`railway run`, `gh auth`, gh extensions, `aws configure`, `vercel dev`, `fly tokens`).
|
|
275
|
+
- Asks wait for your approval in Passport (web or push) when you're at the keyboard or with `--wait <sec>`; otherwise exit 4 with the approval id: run `passport wait <id>`, then the command again. An approval is used once. Blocked or declined: exit 5. No key, or it stopped working: exit 3 ("Your Railway key in Passport stopped working. Update it in Apps."). Offline: exit 1, nothing runs, and exec never uses a key on this computer instead.
|
|
276
|
+
- In Claude Code, the guard rewrites a plain vendor command whose key is in Passport to `passport exec` (PreToolUse `updatedInput` with allow; a block stays a deny). When the rules ask, or someone is at the keyboard, the rewrite adds `--wait 120`, so the agent holds while the person approves: "Approve it on your phone or in Passport." Codex and Cursor get no rewrite: use `passport exec` there.
|
|
277
|
+
- Cloud agents (Agents → Cloud agents) run exec and MCP with `PASSPORT_AGENT_KEY` and `PASSPORT_ENDPOINT`: the owner's rules decide, the owner's keys are used, and approvals go to the owner.
|
|
278
|
+
- Backups: for `gh issue close`, `gh pr close`, `gh api -X DELETE` of a branch, `vercel env rm`, `vercel rollback`, and `vercel promote`, exec also sends the ids Passport needs to take a backup first (repo and number or branch; the linked Vercel project and variable name from `.vercel/project.json`), never a value. After the run it prints `Backup taken. Undo within 7 days: passport undo <action-id>`, or `No backup: <reason>` for a delete it couldn't back up.
|
|
279
|
+
|
|
280
|
+
### Undo
|
|
281
|
+
|
|
282
|
+
```sh
|
|
283
|
+
passport undo act_123
|
|
284
|
+
passport undo --last --yes
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
- Shows what comes back and what won't, how old the backup is, and how long undo stays available, then asks `Undo it? [y/N]` (and which option, when there are several). Without a terminal it prints the preview and `passport undo <id> --yes`; `--option <id>` picks an option.
|
|
288
|
+
- Passport decides an undo from the CLI like a change in that environment. Asks first: exit 4 with the approval id; run `passport wait <id>`, then the undo again. Blocked or declined: exit 5. Done: exit 0, with each step (`✓`/`✗`). Partly done or failed: exit 1. Expired, already undone, or otherwise unavailable: exit 5 with the reason. No backup: exit 6. Needs a member profile.
|
|
253
289
|
|
|
254
290
|
### Persistent sessions
|
|
255
291
|
|
|
@@ -364,6 +400,7 @@ With `--json`, stdout is exactly one JSON value; hints and warnings go to stderr
|
|
|
364
400
|
| `wait` | `{approvalId,status:"approved",scope?,message}`; declined, expired, and still-waiting are errors with `approvalId` |
|
|
365
401
|
| `rules` | `{command,decision,cause?,explanation?,environment?,environmentAssumed?,actionClass?,source}` |
|
|
366
402
|
| `sessions` | `{sessions:[{id,client,folder,status,startedAt,lastActivityAt,counts,environments,waiting}],nextCursor}` |
|
|
403
|
+
| `undo` | `{actionId,status,message,steps:[{label,ok,detail?}],option,undoActionId?}`; without `--yes` off a terminal, `{actionId,status:"preview",preview,next}`; pending, blocked, and declined are errors |
|
|
367
404
|
| `doctor` | `{version,ok,auth,profile?,profileCount,endpointOrigin?,server?,checks}`, also on failure |
|
|
368
405
|
| `ready` | `{ready,version,ok,auth,profile?,profileCount,endpointOrigin?,server?,checks}` |
|
|
369
406
|
| `search` | Gateway payload with `results` or `catalog`, and `note` |
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* "Answered for you": how many prompts this computer answered so the agent
|
|
3
|
+
* didn't have to ask. The guard counts an allow it gave (Claude Code, Cursor)
|
|
4
|
+
* and a Codex command Passport synced into Codex's own rules, and only when a
|
|
5
|
+
* prompt would really have appeared: plain reads the agents already run
|
|
6
|
+
* without asking (ls, cat, git status) don't count.
|
|
7
|
+
*
|
|
8
|
+
* Counting is append-only, one byte per answer in a file per day, so parallel
|
|
9
|
+
* hooks never lose a count. Batches go to Passport at most every five minutes
|
|
10
|
+
* with an id, so a retried batch lands once. Only counts ever leave the machine.
|
|
11
|
+
*/
|
|
12
|
+
import type { CliFinding } from "./cliHookClassify.js";
|
|
13
|
+
export declare const ANSWERED_REPORT_MS: number;
|
|
14
|
+
/** Whether an allow for these findings answered a prompt the agent would have shown. */
|
|
15
|
+
export declare function answersAPrompt(findings: CliFinding[]): boolean;
|
|
16
|
+
/** The local calendar day, so "today" means the person's today. */
|
|
17
|
+
export declare function localDay(now: number): string;
|
|
18
|
+
/** Count one answered prompt. Never throws. */
|
|
19
|
+
export declare function noteAnswered(profile: string, now?: number): void;
|
|
20
|
+
/** Prompts answered on this computer today. */
|
|
21
|
+
export declare function answeredToday(profile: string, now?: number): number;
|
|
22
|
+
/** The next batch to report, or null. A batch that wasn't confirmed is sent again as is. */
|
|
23
|
+
export declare function claimAnsweredBatch(profile: string, now?: number, force?: boolean): {
|
|
24
|
+
batch: string;
|
|
25
|
+
count: number;
|
|
26
|
+
} | null;
|
|
27
|
+
/** Passport recorded the batch: move the mark forward and forget old days. */
|
|
28
|
+
export declare function settleAnsweredBatch(profile: string, batch: string, now?: number): void;
|
|
29
|
+
/**
|
|
30
|
+
* Count an allow that answered a prompt the agent would have shown: Claude
|
|
31
|
+
* Code and Cursor take the hook's allow; Codex runs a command without asking
|
|
32
|
+
* only when Passport synced it into Codex's own rules. Never throws.
|
|
33
|
+
*/
|
|
34
|
+
export declare function countAnswered(profile: string, how: {
|
|
35
|
+
client: string;
|
|
36
|
+
command: string;
|
|
37
|
+
printed: boolean;
|
|
38
|
+
}, findings: CliFinding[], now?: number): Promise<void>;
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* "Answered for you": how many prompts this computer answered so the agent
|
|
3
|
+
* didn't have to ask. The guard counts an allow it gave (Claude Code, Cursor)
|
|
4
|
+
* and a Codex command Passport synced into Codex's own rules, and only when a
|
|
5
|
+
* prompt would really have appeared: plain reads the agents already run
|
|
6
|
+
* without asking (ls, cat, git status) don't count.
|
|
7
|
+
*
|
|
8
|
+
* Counting is append-only, one byte per answer in a file per day, so parallel
|
|
9
|
+
* hooks never lose a count. Batches go to Passport at most every five minutes
|
|
10
|
+
* with an id, so a retried batch lands once. Only counts ever leave the machine.
|
|
11
|
+
*/
|
|
12
|
+
import { randomBytes } from "node:crypto";
|
|
13
|
+
import { appendFileSync, closeSync, constants, mkdirSync, openSync, readdirSync, readFileSync, rmSync, statSync, utimesSync } from "node:fs";
|
|
14
|
+
import { join } from "node:path";
|
|
15
|
+
import { credentialDir, ensurePrivateDirectory, writePrivateAtomic } from "./credentialStorage.js";
|
|
16
|
+
import { assertProfileName } from "./credentials.js";
|
|
17
|
+
const DIRECTORY = "answered";
|
|
18
|
+
export const ANSWERED_REPORT_MS = 5 * 60 * 1000;
|
|
19
|
+
const KEEP_DAYS = 3;
|
|
20
|
+
/** Reads the agents already run without a prompt: no prompt was answered. */
|
|
21
|
+
const QUIET_READERS = new Set([
|
|
22
|
+
"ls",
|
|
23
|
+
"cat",
|
|
24
|
+
"echo",
|
|
25
|
+
"pwd",
|
|
26
|
+
"head",
|
|
27
|
+
"tail",
|
|
28
|
+
"grep",
|
|
29
|
+
"rg",
|
|
30
|
+
"find",
|
|
31
|
+
"fd",
|
|
32
|
+
"wc",
|
|
33
|
+
"which",
|
|
34
|
+
"diff",
|
|
35
|
+
"stat",
|
|
36
|
+
"du",
|
|
37
|
+
"tree",
|
|
38
|
+
"file",
|
|
39
|
+
"sort",
|
|
40
|
+
"uniq",
|
|
41
|
+
"cut",
|
|
42
|
+
"tr",
|
|
43
|
+
"basename",
|
|
44
|
+
"dirname",
|
|
45
|
+
"realpath",
|
|
46
|
+
"readlink",
|
|
47
|
+
"date",
|
|
48
|
+
"whoami",
|
|
49
|
+
"uname",
|
|
50
|
+
"ps",
|
|
51
|
+
"jq",
|
|
52
|
+
"less",
|
|
53
|
+
"sed",
|
|
54
|
+
"column",
|
|
55
|
+
"nl"
|
|
56
|
+
]);
|
|
57
|
+
/** Whether an allow for these findings answered a prompt the agent would have shown. */
|
|
58
|
+
export function answersAPrompt(findings) {
|
|
59
|
+
return findings.some((finding) => {
|
|
60
|
+
if (!finding.vendor)
|
|
61
|
+
return false;
|
|
62
|
+
if (finding.local?.actionClass !== "read")
|
|
63
|
+
return true;
|
|
64
|
+
if (finding.vendor === "git")
|
|
65
|
+
return false;
|
|
66
|
+
return !QUIET_READERS.has(finding.vendor);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function directory() {
|
|
70
|
+
return join(credentialDir(), DIRECTORY);
|
|
71
|
+
}
|
|
72
|
+
/** The local calendar day, so "today" means the person's today. */
|
|
73
|
+
export function localDay(now) {
|
|
74
|
+
const date = new Date(now);
|
|
75
|
+
const pad = (value) => String(value).padStart(2, "0");
|
|
76
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
|
|
77
|
+
}
|
|
78
|
+
function logPath(profile, day) {
|
|
79
|
+
assertProfileName(profile);
|
|
80
|
+
return join(directory(), `${profile}.${day}.log`);
|
|
81
|
+
}
|
|
82
|
+
function statePath(profile) {
|
|
83
|
+
assertProfileName(profile);
|
|
84
|
+
return join(directory(), `${profile}.json`);
|
|
85
|
+
}
|
|
86
|
+
/** Count one answered prompt. Never throws. */
|
|
87
|
+
export function noteAnswered(profile, now = Date.now()) {
|
|
88
|
+
try {
|
|
89
|
+
ensurePrivateDirectory(true);
|
|
90
|
+
mkdirSync(directory(), { recursive: true, mode: 0o700 });
|
|
91
|
+
appendFileSync(logPath(profile, localDay(now)), "1", { mode: 0o600 });
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
/* A lost count is harmless. */
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function sizeOf(path) {
|
|
98
|
+
try {
|
|
99
|
+
return statSync(path).size;
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
return 0;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/** Prompts answered on this computer today. */
|
|
106
|
+
export function answeredToday(profile, now = Date.now()) {
|
|
107
|
+
try {
|
|
108
|
+
return sizeOf(logPath(profile, localDay(now)));
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
return 0;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function readState(profile) {
|
|
115
|
+
try {
|
|
116
|
+
const parsed = JSON.parse(readFileSync(statePath(profile), "utf8"));
|
|
117
|
+
return parsed && typeof parsed.sent === "object" && parsed.sent ? parsed : { sent: {} };
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
return { sent: {} };
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function writeState(profile, state) {
|
|
124
|
+
writePrivateAtomic(statePath(profile), ".answered", `${JSON.stringify(state)}\n`, "answered counts");
|
|
125
|
+
}
|
|
126
|
+
/** At most one report per interval per profile, claimed before any network. */
|
|
127
|
+
function claimInterval(profile, now) {
|
|
128
|
+
const marker = join(directory(), `.${profile}.report`);
|
|
129
|
+
try {
|
|
130
|
+
const last = statSync(marker).mtimeMs;
|
|
131
|
+
if (now - last < ANSWERED_REPORT_MS && last <= now)
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
if (error.code !== "ENOENT")
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
try {
|
|
139
|
+
const noFollow = typeof constants.O_NOFOLLOW === "number" ? constants.O_NOFOLLOW : 0;
|
|
140
|
+
closeSync(openSync(marker, constants.O_WRONLY | constants.O_CREAT | noFollow, 0o600));
|
|
141
|
+
utimesSync(marker, now / 1000, now / 1000);
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/** The next batch to report, or null. A batch that wasn't confirmed is sent again as is. */
|
|
149
|
+
export function claimAnsweredBatch(profile, now = Date.now(), force = false) {
|
|
150
|
+
try {
|
|
151
|
+
if (!force && !claimInterval(profile, now))
|
|
152
|
+
return null;
|
|
153
|
+
const state = readState(profile);
|
|
154
|
+
if (state.pending)
|
|
155
|
+
return { batch: state.pending.batch, count: state.pending.count };
|
|
156
|
+
const days = readdirSync(directory())
|
|
157
|
+
.map((name) => new RegExp(`^${profile.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\.(\\d{4}-\\d{2}-\\d{2})\\.log$`).exec(name)?.[1])
|
|
158
|
+
.filter((day) => Boolean(day))
|
|
159
|
+
.sort();
|
|
160
|
+
for (const day of days) {
|
|
161
|
+
const count = sizeOf(logPath(profile, day)) - (state.sent[day] ?? 0);
|
|
162
|
+
if (count <= 0)
|
|
163
|
+
continue;
|
|
164
|
+
const pending = { batch: `ans_${randomBytes(12).toString("hex")}`, day, count: Math.min(count, 100_000) };
|
|
165
|
+
writeState(profile, { ...state, pending });
|
|
166
|
+
return { batch: pending.batch, count: pending.count };
|
|
167
|
+
}
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/** Passport recorded the batch: move the mark forward and forget old days. */
|
|
175
|
+
export function settleAnsweredBatch(profile, batch, now = Date.now()) {
|
|
176
|
+
try {
|
|
177
|
+
const state = readState(profile);
|
|
178
|
+
if (state.pending?.batch !== batch)
|
|
179
|
+
return;
|
|
180
|
+
const { day, count } = state.pending;
|
|
181
|
+
const sent = { ...state.sent, [day]: (state.sent[day] ?? 0) + count };
|
|
182
|
+
const today = localDay(now);
|
|
183
|
+
const oldest = localDay(now - KEEP_DAYS * 24 * 60 * 60 * 1000);
|
|
184
|
+
for (const kept of Object.keys(sent)) {
|
|
185
|
+
if (kept < oldest && kept !== today) {
|
|
186
|
+
delete sent[kept];
|
|
187
|
+
rmSync(logPath(profile, kept), { force: true });
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
writeState(profile, { sent });
|
|
191
|
+
}
|
|
192
|
+
catch {
|
|
193
|
+
/* Sent again next time, under the same batch id. */
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Count an allow that answered a prompt the agent would have shown: Claude
|
|
198
|
+
* Code and Cursor take the hook's allow; Codex runs a command without asking
|
|
199
|
+
* only when Passport synced it into Codex's own rules. Never throws.
|
|
200
|
+
*/
|
|
201
|
+
export async function countAnswered(profile, how, findings, now = Date.now()) {
|
|
202
|
+
try {
|
|
203
|
+
if (!answersAPrompt(findings))
|
|
204
|
+
return;
|
|
205
|
+
if (how.client === "codex") {
|
|
206
|
+
const { syncedForCodex } = await import("./nativeSync.js");
|
|
207
|
+
if (!syncedForCodex(how.command))
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
else if (!how.printed)
|
|
211
|
+
return;
|
|
212
|
+
noteAnswered(profile, now);
|
|
213
|
+
}
|
|
214
|
+
catch {
|
|
215
|
+
/* Counting never gets in the agent's way. */
|
|
216
|
+
}
|
|
217
|
+
}
|
package/dist/cliArgs.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const COMMANDS: readonly ["init", "login", "logout", "profiles", "use", "status", "doctor", "ready", "search", "describe", "run", "connect", "resources", "prompts", "discover", "scan", "hook", "wait", "rules", "sessions", "setup", "session", "access", "completion", "help", "version"];
|
|
1
|
+
export declare const COMMANDS: readonly ["init", "login", "logout", "profiles", "use", "status", "doctor", "ready", "search", "describe", "run", "connect", "resources", "prompts", "discover", "scan", "hook", "wait", "rules", "sessions", "env", "sync", "exec", "undo", "keys", "setup", "session", "access", "completion", "help", "version"];
|
|
2
2
|
export type Command = (typeof COMMANDS)[number];
|
|
3
3
|
export declare class ArgError extends Error {
|
|
4
4
|
}
|
package/dist/cliArgs.js
CHANGED
|
@@ -19,6 +19,11 @@ export const COMMANDS = [
|
|
|
19
19
|
"wait",
|
|
20
20
|
"rules",
|
|
21
21
|
"sessions",
|
|
22
|
+
"env",
|
|
23
|
+
"sync",
|
|
24
|
+
"exec",
|
|
25
|
+
"undo",
|
|
26
|
+
"keys",
|
|
22
27
|
"setup",
|
|
23
28
|
"session",
|
|
24
29
|
"access",
|
|
@@ -35,11 +40,11 @@ const FLAGS = {
|
|
|
35
40
|
help: { kind: "boolean" },
|
|
36
41
|
cloud: { kind: "value", commands: ["login", "init", "setup"] },
|
|
37
42
|
workspace: { kind: "value", commands: ["login", "access"] },
|
|
38
|
-
client: { kind: "value", commands: ["login", "setup", "hook"] },
|
|
43
|
+
client: { kind: "value", commands: ["login", "setup", "hook", "exec"] },
|
|
39
44
|
apply: { kind: "boolean", commands: ["setup", "hook"] },
|
|
40
45
|
guard: { kind: "boolean", commands: ["hook"] },
|
|
41
46
|
"no-open": { kind: "boolean", commands: ["login", "init"] },
|
|
42
|
-
yes: { kind: "boolean", commands: ["init", "setup"] },
|
|
47
|
+
yes: { kind: "boolean", commands: ["init", "setup", "keys", "undo"] },
|
|
43
48
|
org: { kind: "value", commands: ["setup"] },
|
|
44
49
|
clients: { kind: "value", commands: ["setup"] },
|
|
45
50
|
"skip-apps": { kind: "boolean", commands: ["init"] },
|
|
@@ -49,11 +54,12 @@ const FLAGS = {
|
|
|
49
54
|
args: { kind: "value", commands: ["run"] },
|
|
50
55
|
set: { kind: "repeat", commands: ["run", "prompts"] },
|
|
51
56
|
"set-json": { kind: "repeat", commands: ["run"] },
|
|
52
|
-
wait: { kind: "value", commands: ["run", "connect"] },
|
|
57
|
+
wait: { kind: "value", commands: ["run", "connect", "exec"] },
|
|
58
|
+
session: { kind: "value", commands: ["exec"] },
|
|
53
59
|
alias: { kind: "value", commands: ["connect"] },
|
|
54
60
|
open: { kind: "boolean", commands: ["connect"] },
|
|
55
61
|
out: { kind: "value", commands: ["resources", "prompts"] },
|
|
56
|
-
verbose: { kind: "boolean", commands: ["scan", "init"] },
|
|
62
|
+
verbose: { kind: "boolean", commands: ["scan", "init", "exec"] },
|
|
57
63
|
path: { kind: "value", commands: ["scan"] },
|
|
58
64
|
check: { kind: "boolean", commands: ["scan"] },
|
|
59
65
|
input: { kind: "value", commands: ["access"] },
|
|
@@ -63,7 +69,10 @@ const FLAGS = {
|
|
|
63
69
|
"delegation-id": { kind: "value", commands: ["access"] },
|
|
64
70
|
"client-id": { kind: "value", commands: ["access"] },
|
|
65
71
|
environment: { kind: "value", commands: ["rules"] },
|
|
66
|
-
status: { kind: "value", commands: ["sessions"] }
|
|
72
|
+
status: { kind: "value", commands: ["sessions"] },
|
|
73
|
+
remove: { kind: "boolean", commands: ["sync"] },
|
|
74
|
+
last: { kind: "boolean", commands: ["undo"] },
|
|
75
|
+
option: { kind: "value", commands: ["undo"] }
|
|
67
76
|
};
|
|
68
77
|
export class ArgError extends Error {
|
|
69
78
|
}
|
|
@@ -133,6 +142,10 @@ export function parseArgs(argv) {
|
|
|
133
142
|
}
|
|
134
143
|
else {
|
|
135
144
|
positionals.push(raw);
|
|
145
|
+
// `passport exec railway up --service api`: everything after the CLI's
|
|
146
|
+
// name belongs to that CLI, flags included.
|
|
147
|
+
if (command === "exec")
|
|
148
|
+
positionalOnly = true;
|
|
136
149
|
}
|
|
137
150
|
}
|
|
138
151
|
command ??= "help";
|
|
@@ -170,6 +183,10 @@ function validateShape(command, positionals) {
|
|
|
170
183
|
wait: 1,
|
|
171
184
|
rules: 2,
|
|
172
185
|
sessions: 0,
|
|
186
|
+
env: 4,
|
|
187
|
+
sync: 0,
|
|
188
|
+
undo: 1,
|
|
189
|
+
keys: 2,
|
|
173
190
|
setup: 3,
|
|
174
191
|
session: 0,
|
|
175
192
|
access: 2,
|
|
@@ -177,12 +194,21 @@ function validateShape(command, positionals) {
|
|
|
177
194
|
help: 1,
|
|
178
195
|
version: 0
|
|
179
196
|
};
|
|
180
|
-
const minimum = {
|
|
197
|
+
const minimum = {
|
|
198
|
+
describe: 1,
|
|
199
|
+
run: 1,
|
|
200
|
+
use: 1,
|
|
201
|
+
completion: 1,
|
|
202
|
+
wait: 1,
|
|
203
|
+
rules: 1,
|
|
204
|
+
exec: 1
|
|
205
|
+
};
|
|
181
206
|
const needs = {
|
|
182
207
|
run: "a tool name",
|
|
183
208
|
completion: "bash, zsh, or fish",
|
|
184
209
|
wait: "an approval id",
|
|
185
|
-
rules: 'test "<command>"'
|
|
210
|
+
rules: 'test "<command>"',
|
|
211
|
+
exec: "a command, like passport exec -- railway up"
|
|
186
212
|
};
|
|
187
213
|
if (positionals.length < (minimum[command] ?? 0)) {
|
|
188
214
|
throw new ArgError(`${command} requires ${needs[command] ?? "a name"}.`);
|
package/dist/cliAutopilot.d.ts
CHANGED
|
@@ -13,7 +13,10 @@
|
|
|
13
13
|
import { type ParsedArgs } from "./cliArgs.js";
|
|
14
14
|
import { type Preset, type PresetRow } from "./cliAutopilotPolicy.js";
|
|
15
15
|
import { type MemberApi } from "./cliClient.js";
|
|
16
|
+
import { type LocalMachine } from "./cliHookLocal.js";
|
|
16
17
|
import { type EnvKind } from "./cliHookEnvironment.js";
|
|
18
|
+
import { type LinkFs } from "./envLinkFs.js";
|
|
19
|
+
export { env } from "./cliEnv.js";
|
|
17
20
|
import { type CommandResult, type Runtime } from "./cliSupport.js";
|
|
18
21
|
/** Long enough to be useful, short enough for an agent's default 2-minute
|
|
19
22
|
* command timeout. */
|
|
@@ -21,7 +24,13 @@ export declare const WAIT_DEFAULT_SECONDS = 100;
|
|
|
21
24
|
export type AutopilotDependencies = {
|
|
22
25
|
api?: MemberApi;
|
|
23
26
|
now?: () => number;
|
|
27
|
+
/** The machine `rules test` reads paths on; tests pass a pretend one. */
|
|
28
|
+
machine?: LocalMachine;
|
|
29
|
+
/** Where folder links are read from; tests pass a pretend one. */
|
|
30
|
+
linkFs?: LinkFs;
|
|
24
31
|
};
|
|
32
|
+
export declare function api(args: ParsedArgs, runtime: Runtime, deps: AutopilotDependencies, waitMs?: number, agentKeyOk?: boolean): MemberApi;
|
|
33
|
+
export declare function json<T>(response: Response, fallback: string): Promise<T>;
|
|
25
34
|
export declare function wait(args: ParsedArgs, runtime: Runtime, deps?: AutopilotDependencies): Promise<CommandResult>;
|
|
26
35
|
export declare function rules(args: ParsedArgs, runtime: Runtime, deps?: AutopilotDependencies): Promise<CommandResult>;
|
|
27
36
|
type SessionRow = {
|
|
@@ -53,8 +62,21 @@ export type AutopilotStatus = {
|
|
|
53
62
|
fetchedAt: number | null;
|
|
54
63
|
ageMs: number | null;
|
|
55
64
|
};
|
|
65
|
+
/** "Answered for you" today: across your computers when Passport keeps the
|
|
66
|
+
* count, else this computer's own. */
|
|
67
|
+
answered?: {
|
|
68
|
+
today: number;
|
|
69
|
+
source: "workspace" | "this-computer";
|
|
70
|
+
};
|
|
71
|
+
/** Agents whose own allowlist Passport keeps in sync, with how many entries. */
|
|
72
|
+
allowlists?: Array<{
|
|
73
|
+
agent: string;
|
|
74
|
+
name: string;
|
|
75
|
+
entries: number;
|
|
76
|
+
}>;
|
|
56
77
|
};
|
|
78
|
+
/** Local midnight, so "today" is the person's today wherever the server is. */
|
|
79
|
+
export declare function localMidnight(now: number): number;
|
|
57
80
|
/** Read presets and floors for `passport status`. Never throws. */
|
|
58
81
|
export declare function autopilotStatus(fetchApi: (path: string, init: RequestInit) => Promise<Response>, profile: string | undefined, signal: AbortSignal, now?: number): Promise<AutopilotStatus>;
|
|
59
82
|
export declare function autopilotLines(status: AutopilotStatus): string[];
|
|
60
|
-
export {};
|