passport-bridge 0.33.0 → 0.35.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.
Files changed (101) hide show
  1. package/README.md +27 -3
  2. package/dist/cliArgs.d.ts +1 -1
  3. package/dist/cliArgs.js +5 -1
  4. package/dist/cliAutopilot.js +2 -1
  5. package/dist/cliAutopilotPolicy.d.ts +18 -2
  6. package/dist/cliAutopilotPolicy.js +32 -9
  7. package/dist/cliExec.d.ts +3 -2
  8. package/dist/cliExec.js +52 -32
  9. package/dist/cliGitCredential.d.ts +38 -0
  10. package/dist/cliGitCredential.js +456 -0
  11. package/dist/cliHook.js +10 -13
  12. package/dist/cliHookAfter.d.ts +2 -0
  13. package/dist/cliHookAfter.js +8 -1
  14. package/dist/cliHookDecide.d.ts +7 -23
  15. package/dist/cliHookDecide.js +117 -87
  16. package/dist/cliHookDeliver.js +5 -2
  17. package/dist/cliHookEarly.d.ts +10 -0
  18. package/dist/cliHookEarly.js +8 -0
  19. package/dist/cliHookRewrite.d.ts +31 -5
  20. package/dist/cliHookRewrite.js +51 -9
  21. package/dist/cliHookServerDecision.d.ts +30 -0
  22. package/dist/cliHookServerDecision.js +85 -0
  23. package/dist/cliInit.js +4 -0
  24. package/dist/cliKeys.js +17 -12
  25. package/dist/cliKeysShim.js +2 -1
  26. package/dist/cliMain.js +5 -1
  27. package/dist/cliOutput.js +6 -0
  28. package/dist/cliPolicyV2.js +32 -2
  29. package/dist/cliStatus.js +6 -1
  30. package/dist/cliStatusGuard.js +4 -1
  31. package/dist/cliWorkWords.js +1 -1
  32. package/dist/commandRepair.d.ts +13 -0
  33. package/dist/commandRepair.js +73 -0
  34. package/dist/completion.js +2 -0
  35. package/dist/controlPlane.generated.d.ts +434 -0
  36. package/dist/controlPlane.generated.js +134 -0
  37. package/dist/controlPlaneExec.d.ts +68 -0
  38. package/dist/controlPlaneExec.js +135 -0
  39. package/dist/controlPlaneGithub.generated.d.ts +45 -0
  40. package/dist/controlPlaneGithub.generated.js +94 -0
  41. package/dist/controlPlaneGithubApi.generated.d.ts +15 -0
  42. package/dist/controlPlaneGithubApi.generated.js +117 -0
  43. package/dist/controlPlaneGithubCatalog.generated.d.ts +127 -0
  44. package/dist/controlPlaneGithubCatalog.generated.js +253 -0
  45. package/dist/controlPlaneGithubCli.generated.d.ts +94 -0
  46. package/dist/controlPlaneGithubCli.generated.js +287 -0
  47. package/dist/controlPlaneGithubWebhook.generated.d.ts +30 -0
  48. package/dist/controlPlaneGithubWebhook.generated.js +105 -0
  49. package/dist/controlPlaneGuard.d.ts +147 -0
  50. package/dist/controlPlaneGuard.js +277 -0
  51. package/dist/controlPlaneLate.d.ts +30 -0
  52. package/dist/controlPlaneLate.js +72 -0
  53. package/dist/controlPlaneLateHold.d.ts +20 -0
  54. package/dist/controlPlaneLateHold.js +101 -0
  55. package/dist/controlPlaneRailway.generated.d.ts +30 -0
  56. package/dist/controlPlaneRailway.generated.js +217 -0
  57. package/dist/controlPlaneRailwayCli.generated.d.ts +11 -0
  58. package/dist/controlPlaneRailwayCli.generated.js +436 -0
  59. package/dist/controlPlaneRailwayGuard.d.ts +172 -0
  60. package/dist/controlPlaneRailwayGuard.js +527 -0
  61. package/dist/controlPlaneRailwayModel.generated.d.ts +189 -0
  62. package/dist/controlPlaneRailwayModel.generated.js +355 -0
  63. package/dist/controlPlaneRailwayReach.d.ts +43 -0
  64. package/dist/controlPlaneRailwayReach.js +163 -0
  65. package/dist/credentialStorage.d.ts +3 -0
  66. package/dist/credentialStorage.js +13 -2
  67. package/dist/credentials.js +60 -6
  68. package/dist/designTokens.generated.d.ts +16 -0
  69. package/dist/designTokens.generated.js +11 -0
  70. package/dist/envLinksHosting.d.ts +16 -1
  71. package/dist/envLinksHosting.js +60 -21
  72. package/dist/execGit.d.ts +16 -0
  73. package/dist/execGit.js +31 -0
  74. package/dist/execShims.d.ts +16 -3
  75. package/dist/execShims.js +96 -9
  76. package/dist/gitCredentialSetup.d.ts +94 -0
  77. package/dist/gitCredentialSetup.js +357 -0
  78. package/dist/gitInvocation.d.ts +41 -0
  79. package/dist/gitInvocation.js +207 -0
  80. package/dist/gitPush.d.ts +27 -0
  81. package/dist/gitPush.js +172 -0
  82. package/dist/gitPushDecisions.d.ts +6 -0
  83. package/dist/gitPushDecisions.js +69 -0
  84. package/dist/gitReadOnly.d.ts +10 -0
  85. package/dist/gitReadOnly.js +57 -0
  86. package/dist/initAutopilotStep.d.ts +2 -1
  87. package/dist/initAutopilotStep.js +19 -7
  88. package/dist/initInstall.js +19 -13
  89. package/dist/initKeysStep.d.ts +6 -0
  90. package/dist/initKeysStep.js +43 -3
  91. package/dist/initPlan.js +7 -0
  92. package/dist/launcherHealth.d.ts +11 -0
  93. package/dist/launcherHealth.js +49 -0
  94. package/dist/pluginPin.d.ts +1 -1
  95. package/dist/pluginPin.js +1 -1
  96. package/dist/railwayDecisions.d.ts +12 -0
  97. package/dist/railwayDecisions.js +112 -0
  98. package/dist/version.d.ts +1 -1
  99. package/dist/version.js +1 -1
  100. package/npm-shrinkwrap.json +2 -2
  101. package/package.json +1 -1
package/README.md CHANGED
@@ -173,7 +173,7 @@ Eight steps, each reusing the command that owns it:
173
173
  Development Ask if irreversible
174
174
  ```
175
175
 
176
- 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 writes" 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 writes, 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.
176
+ 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 writes" 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 writes, deletes outside Development, and irreversible actions`. **Full autopilot** (every row runs, irreversible actions included) is turned on only in Rules on the web: init never offers it, skips rows already on it, and says `Full autopilot: nothing asks.` when every row is. A server without Autopilot gets no rules step (`Autopilot needs a newer Passport server.`); init never writes the retired safety profile.
177
177
 
178
178
  What changes on disk, and how to undo it:
179
179
 
@@ -252,7 +252,7 @@ Two hooks per agent. `passport hook` runs after each shell command and records t
252
252
 
253
253
  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.`
254
254
 
255
- **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:
255
+ **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 outside a Full autopilot row (cli-policy v2 `fullAutopilot`; there irreversible runs, and an ask a rule makes stays in the agent's prompt): it is approved only in Passport, 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:
256
256
 
257
257
  | Signal | Means |
258
258
  | ------------------------------------------------------------------------------------------------- | --------------------------------------- |
@@ -287,7 +287,7 @@ An ask becomes one Activity row. In Claude Code, with the audit hook registered,
287
287
 
288
288
  **App access.** The person's pass for the app a `passport exec` CLI acts on (Railway for `railway`, GitHub for `gh`, and so on) comes with cli-policy v2 as `access`, one record per CLI whose app limits the person (an older server's `appAccess` map is read the same way). The guard applies it before any rule, and no rule or exception lifts it. No access blocks every command of that CLI with `You don't have access to Railway in Passport. Ask an admin: passport request railway --reason "<why>"` and, on the next line, a link to the app's Access tab; read-only blocks everything but reads and names `passport request railway --full --reason "<why>"`. `passport exec` says the same (exit 5, cause `no_access`, with `Access: <link>`). A CLI whose app isn't in the workspace keeps working from its key.
289
289
 
290
- `src/cliPolicy.ts` caches the member's CLI policy (`GET /api/my/cli-policy`) at `$PASSPORT_HOME/cli-policy/<profile>.json` (mode 600). Servers with Autopilot send version 2 (`src/cliPolicyV2.ts`: presets, floors, CLI rules, irreversible and delete verbs, environment flags, placed environments); older servers send version 1, and then the guard keeps its earlier shape: ask or deny before destructive verbs, never allow, no server call, and reports without the Autopilot fields. `passport login` and `passport status` refresh it and `passport logout` removes it. A 404 or error keeps the previous copy; with no copy the guard asks before every destructive verb. `PASSPORT_HOOK_DISABLED=1` turns both hooks off.
290
+ `src/cliPolicy.ts` caches the member's CLI policy (`GET /api/my/cli-policy`) at `$PASSPORT_HOME/cli-policy/<profile>.json` (mode 600). Servers with Autopilot send version 2 (`src/cliPolicyV2.ts`: presets, floors, CLI rules, irreversible and delete verbs, environment flags, placed environments; Full autopilot rows come as `handsoff` plus `fullAutopilot`, so CLI 0.33 and older ask before irreversible there, and a malformed list counts as none); older servers send version 1, and then the guard keeps its earlier shape: ask or deny before destructive verbs, never allow, no server call, and reports without the Autopilot fields. `passport login` and `passport status` refresh it and `passport logout` removes it. A 404 or error keeps the previous copy; with no copy the guard asks before every destructive verb. `PASSPORT_HOOK_DISABLED=1` turns both hooks off.
291
291
 
292
292
  Token numbers (`src/cliUsage.ts`, 0.24.0+): Claude Code's SessionStart and SessionEnd hooks note the session's `transcript_path` under `$PASSPORT_HOME/usage/<profile>/`; the detached `passport hook flush` reads what each transcript (and its subagents' files) added since the last byte offset, bounded per run, and sends per-session, per-model token counts and model ids as `usage` batches. No message content is kept or sent. Only when cli-policy v2 carries `usage: true` (the workspace keeps them); `PASSPORT_TOKEN_USAGE=off` turns it off on one computer.
293
293
 
@@ -355,6 +355,30 @@ passport keys shim # the CLIs that run through Passport when you type
355
355
  - Cloud agents (Agents → Cloud agents) run exec and MCP with their agent token in `PASSPORT_AGENT_KEY` and `PASSPORT_ENDPOINT`: the owner's rules decide, the owner's keys are used, and approvals go to the owner.
356
356
  - 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.
357
357
 
358
+ ### git through Passport
359
+
360
+ ```sh
361
+ passport git-credential setup # git sends github.com to Passport (backed up first)
362
+ passport git-credential setup --remove # back to your own GitHub sign-in
363
+ ```
364
+
365
+ When your workspace's GitHub App covers a repository, `gh` and `git` use tokens Passport issues from it, so GitHub reports their pushes, PRs and merges as the App (`<app>[bot]`; commit authors stay you) and the control plane counts them through Passport. `passport exec -- gh …` (the guard's rewrite in Claude Code, and the `gh` shim) already gets one; `passport keys` lists `gh` as going through Passport and says when git doesn't yet.
366
+
367
+ `setup` adds Passport as git's credential helper for `https://github.com/` in your global git config (`GIT_CONFIG_GLOBAL` is honored), after an empty `helper =` so no helper set before it (osxkeychain, `gh auth git-credential`) answers for github.com. Those earlier helpers (from your system and global config only, never a repository's own) are remembered (names only, in `$PASSPORT_HOME/git-credential.json`) and still answer for repositories the App doesn't cover; running setup again keeps them. Pushes from SSH remotes go over HTTPS (`url.https://github.com/<owner>/.pushInsteadOf`) only for the accounts the App covers, and only when one of those helpers can answer over HTTPS; fetches stay on SSH. The file is copied once to `<file>.passport-backup`. `--remove` puts Passport's section back exactly as it was and removes only what setup added. If `gh auth setup-git` runs afterwards, git asks gh first again; `passport keys` says so, and setup again fixes it. Setup says done only once git's helper answers as this Passport (it runs the helper with `probe`); otherwise git goes back to how it was. If the helper or the launcher it runs falls behind (a global npm update leaves an old copy behind it), `passport init` and `passport status` point it at this Passport again. `passport init` offers it in the Keys step when the App covers you (asked step by step, done with `--move-keys`, otherwise the next command). Not on Windows: setup refuses there, since its reset would stop Git Credential Manager answering for github.com.
368
+
369
+ Then for each fetch or push git runs `passport git-credential get`:
370
+
371
+ - It reads which git command asked from its parent processes, on this computer (`/proc`, or two `ps` calls that read only its ancestors' command lines, 1500ms in all); a git alias is resolved, and anything else that isn't a fetch, pull, clone or push (a shell alias, `git lfs`) reads as unknown. Only the classification (resource and action) is sent, never the command line.
372
+ - A fetch gets a 1-hour read-only token.
373
+ - A push is resolved as git will (the remote, and for a bare `git push` the branch `push.default` and its upstream pick), and every ref it moves is decided (`POST /api/cp/decide`). In Claude Code the guard has already decided them and leaves the decisions for the helper, so a push is decided once. Passport issues the push token (Contents write, and Workflows write when allowed) only against those decisions, each spent once, within a minute. Blocked on any ref: git stops with the block message (`quit=1`).
374
+ - A push it can't name ref by ref (`--all`, `--mirror` or a mirror remote, `--prune`, a tag delete, a ref outside branches and tags, `push.default=matching`, a detached HEAD) is decided as a force-push and a branch delete on the repository.
375
+ - A command it can't name (the parent processes couldn't be read in time, no `ps`, a GUI running git its own way) gets a read-only token, never your own sign-in: a fetch works, and GitHub refuses a push (403). Passport records it in Activity ("Read-only token for a git command Passport couldn't name"), git's output says so in one line, and in Claude Code the after-hook tells the agent when GitHub refused a push for it. Run the push again, or as `passport exec -- git push …`, which names the command for the helper (`PASSPORT_GIT_COMMAND`) so it is decided and pushed as usual.
376
+ - Fail open, like the guard: when Passport doesn't answer within 5 seconds in all (1 second at most per decision), refuses (read-only access, an App without Contents write, an agent key), or the helper can't tell what a push changes, git uses your own sign-in, through the helpers you had before. That push counts as outside Passport, and a push says so in one line on stderr.
377
+ - A repository the App doesn't cover goes to your earlier helpers too.
378
+ - `store` and `erase` never keep a Passport token. No token is written to disk.
379
+
380
+ POSIX only; on Windows git keeps your own sign-in and the guard decides pushes as before.
381
+
358
382
  ### Kubernetes sign-in
359
383
 
360
384
  ```sh
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", "request", "resources", "prompts", "discover", "scan", "hook", "wait", "rules", "actions", "tasks", "changes", "env", "where", "sync", "exec", "kube-credential", "undo", "keys", "setup", "session", "access", "update", "completion", "help", "version"];
1
+ export declare const COMMANDS: readonly ["init", "login", "logout", "profiles", "use", "status", "doctor", "ready", "search", "describe", "run", "connect", "request", "resources", "prompts", "discover", "scan", "hook", "wait", "rules", "actions", "tasks", "changes", "env", "where", "sync", "exec", "kube-credential", "git-credential", "undo", "keys", "setup", "session", "access", "update", "completion", "help", "version"];
2
2
  export type Command = (typeof COMMANDS)[number];
3
3
  /** Old names that still run for one release, left out of help, completion,
4
4
  * and suggestions. `discover` is part of `scan` now. */
package/dist/cliArgs.js CHANGED
@@ -28,6 +28,7 @@ export const COMMANDS = [
28
28
  "sync",
29
29
  "exec",
30
30
  "kube-credential",
31
+ "git-credential",
31
32
  "undo",
32
33
  "keys",
33
34
  "setup",
@@ -69,6 +70,8 @@ const FLAGS = {
69
70
  "move-keys": { kind: "boolean", commands: ["init"] },
70
71
  "dry-run": { kind: "boolean", commands: ["init"] },
71
72
  "ask-again": { kind: "boolean", commands: ["exec"] },
73
+ // The guard's own rewrite (Claude Code): the railway decision exec spends instead of deciding again.
74
+ decision: { kind: "value", commands: ["exec"] },
72
75
  app: { kind: "value", commands: ["search", "changes", "tasks"] },
73
76
  args: { kind: "value", commands: ["run", "actions"] },
74
77
  id: { kind: "value", commands: ["actions"] },
@@ -107,7 +110,7 @@ const FLAGS = {
107
110
  until: { kind: "value", commands: ["tasks", "changes"] },
108
111
  env: { kind: "value", commands: ["tasks", "changes"] },
109
112
  history: { kind: "boolean", commands: ["tasks", "changes"] },
110
- remove: { kind: "boolean", commands: ["sync", "keys"] },
113
+ remove: { kind: "boolean", commands: ["sync", "keys", "git-credential"] },
111
114
  last: { kind: "boolean", commands: ["undo"] },
112
115
  local: { kind: "boolean", commands: ["undo", "scan", "actions"] },
113
116
  // The detached check the CLI and hooks start; not for people to type.
@@ -292,6 +295,7 @@ function validateShape(command, positionals) {
292
295
  sync: 0,
293
296
  undo: 1,
294
297
  "kube-credential": 1,
298
+ "git-credential": 1,
295
299
  keys: 3,
296
300
  setup: 3,
297
301
  session: 0,
@@ -278,8 +278,9 @@ export async function rules(args, runtime, deps = {}) {
278
278
  human: ruleTestLines(termOf(runtime.stdout, runtime.env), label, result, source).join("\n")
279
279
  };
280
280
  }
281
+ /** "full" is Full autopilot, which `passport status` names as such. */
281
282
  function isPresetName(value) {
282
- return value === "careful" || value === "balanced" || value === "handsoff";
283
+ return value === "careful" || value === "balanced" || value === "handsoff" || value === "full";
283
284
  }
284
285
  function presetMap(raw) {
285
286
  if (!raw || typeof raw !== "object")
@@ -10,14 +10,20 @@
10
10
  * 3. The most specific exception (action > app > class), strictest across
11
11
  * scopes, never looser than the team floor.
12
12
  * 4. The environment preset, bounded by the floor, applied to the class.
13
- * 5. Irreversible actions ask unless step 3 allowed them.
13
+ * 5. Irreversible actions ask unless step 3 allowed them or the row is on
14
+ * Full autopilot (cli-policy v2 `fullAutopilot`).
14
15
  *
15
16
  * Every decision carries its cause, and every cause reads as one line.
16
17
  */
17
18
  import { type CliAllowance } from "./cliAllowances.js";
18
19
  import { type EnvKind } from "./cliHookEnvironment.js";
19
- export declare const PRESETS: readonly ["careful", "balanced", "handsoff"];
20
+ /** Strictest first. "full" (Full autopilot) never comes as a preset on the
21
+ * wire: the server sends "handsoff" plus `fullAutopilot`, which bridges up to
22
+ * 0.33 ignore. */
23
+ export declare const PRESETS: readonly ["careful", "balanced", "handsoff", "full"];
20
24
  export type Preset = (typeof PRESETS)[number];
25
+ /** The presets a CLI credential may pick: Full autopilot is turned on only in Passport. */
26
+ export declare const CLI_PRESETS: readonly ["careful", "balanced", "handsoff"];
21
27
  export declare const ACTION_CLASSES: readonly ["read", "change", "delete", "irreversible"];
22
28
  export type ActionClass = (typeof ACTION_CLASSES)[number];
23
29
  export type Decision = "allow" | "ask" | "block";
@@ -136,6 +142,8 @@ export type AutopilotPolicy = {
136
142
  floors: Record<EnvKind, Preset | null> & {
137
143
  other?: Preset | null;
138
144
  };
145
+ /** Rows on Full autopilot (cli-policy v2 `fullAutopilot`): irreversible runs there too. */
146
+ fullAutopilot?: ActionEnv[];
139
147
  rules: CliRule[];
140
148
  /** Verbs that are irreversible wherever they run. */
141
149
  irreversible: Record<string, string[]>;
@@ -224,6 +232,10 @@ export type AutopilotPolicy = {
224
232
  allowances?: CliAllowance[];
225
233
  /** One deploy at a time (cli-policy v2 `leases`): take a lease first. */
226
234
  leases?: boolean;
235
+ /** The control plane: GitHub is connected (cli-policy v2 `controlPlane.github`). */
236
+ controlPlaneGithub?: boolean;
237
+ /** The control plane: Railway is connected (cli-policy v2 `controlPlane.railway`). */
238
+ controlPlaneRailway?: boolean;
227
239
  /** Known project scripts (Batch A item 5), vendor `project`: they set class
228
240
  * and environment only, never an allow. */
229
241
  project?: {
@@ -280,6 +292,10 @@ export type ActionFacts = {
280
292
  };
281
293
  /** The reason a repo rule's block gives: "this repo's AGENTS.md: Never run `railway up`." */
282
294
  export declare const REPO_RULE_LEAD = "this repo's ";
295
+ /** Checked copy of shared/autopilotContract.ts `fullAutopilotCause`. */
296
+ export declare function fullAutopilotCause(env: ActionEnv): string;
297
+ /** Whether the server put this row on Full autopilot (cli-policy v2 `fullAutopilot`). */
298
+ export declare function fullAutopilotRow(policy: Pick<AutopilotPolicy, "fullAutopilot">, env: ActionEnv | undefined): boolean;
283
299
  export type LocalDecision = {
284
300
  decision: Decision;
285
301
  cause: Cause;
@@ -10,14 +10,20 @@
10
10
  * 3. The most specific exception (action > app > class), strictest across
11
11
  * scopes, never looser than the team floor.
12
12
  * 4. The environment preset, bounded by the floor, applied to the class.
13
- * 5. Irreversible actions ask unless step 3 allowed them.
13
+ * 5. Irreversible actions ask unless step 3 allowed them or the row is on
14
+ * Full autopilot (cli-policy v2 `fullAutopilot`).
14
15
  *
15
16
  * Every decision carries its cause, and every cause reads as one line.
16
17
  */
17
18
  import { allowanceCauseLabel, matchAllowance } from "./cliAllowances.js";
18
19
  import { ENV_LABEL } from "./cliHookEnvironment.js";
19
20
  import { vendorKeys } from "./cliHookVendors.js";
20
- export const PRESETS = ["careful", "balanced", "handsoff"];
21
+ /** Strictest first. "full" (Full autopilot) never comes as a preset on the
22
+ * wire: the server sends "handsoff" plus `fullAutopilot`, which bridges up to
23
+ * 0.33 ignore. */
24
+ export const PRESETS = ["careful", "balanced", "handsoff", "full"];
25
+ /** The presets a CLI credential may pick: Full autopilot is turned on only in Passport. */
26
+ export const CLI_PRESETS = ["careful", "balanced", "handsoff"];
21
27
  export const ACTION_CLASSES = ["read", "change", "delete", "irreversible"];
22
28
  /**
23
29
  * Checked copies of the class words in shared/autopilotContract.ts
@@ -123,13 +129,15 @@ export function rowLabel(row) {
123
129
  export const PRESET_STANCE_LABEL = {
124
130
  careful: "Ask before writes",
125
131
  balanced: "Ask before deletes",
126
- handsoff: "Ask if irreversible"
132
+ handsoff: "Ask if irreversible",
133
+ full: "Full autopilot"
127
134
  };
128
- /** What each preset does, per class. Irreversible always asks. */
135
+ /** What each preset does, per class. Irreversible asks except under Full autopilot. */
129
136
  const PRESET_TABLE = {
130
137
  careful: { read: "allow", change: "ask", delete: "ask", irreversible: "ask" },
131
138
  balanced: { read: "allow", change: "allow", delete: "ask", irreversible: "ask" },
132
- handsoff: { read: "allow", change: "allow", delete: "allow", irreversible: "ask" }
139
+ handsoff: { read: "allow", change: "allow", delete: "allow", irreversible: "ask" },
140
+ full: { read: "allow", change: "allow", delete: "allow", irreversible: "allow" }
133
141
  };
134
142
  export const DEFAULT_PRESETS = {
135
143
  production: "careful",
@@ -141,7 +149,7 @@ export const DEFAULT_PRESETS = {
141
149
  export function envLabel(env) {
142
150
  return env === OTHER_APPS ? "Other apps" : ENV_LABEL[env];
143
151
  }
144
- const STRICTNESS = { careful: 2, balanced: 1, handsoff: 0 };
152
+ const STRICTNESS = { careful: 3, balanced: 2, handsoff: 1, full: 0 };
145
153
  const DECISION_RANK = { allow: 0, ask: 1, block: 2 };
146
154
  export function stricterPreset(a, b) {
147
155
  return b && STRICTNESS[b] > STRICTNESS[a] ? b : a;
@@ -263,9 +271,19 @@ function ruleLabel(rule) {
263
271
  return `A rule says ${verb} ${matchText(rule)}${where}`;
264
272
  return `${owner}, ${verb} ${matchText(rule)}${where}`;
265
273
  }
266
- function presetLabel(env, _preset, actionClass, decision) {
274
+ /** Checked copy of shared/autopilotContract.ts `fullAutopilotCause`. */
275
+ export function fullAutopilotCause(env) {
276
+ return `Full autopilot is on for ${envLabel(env)}`;
277
+ }
278
+ /** Whether the server put this row on Full autopilot (cli-policy v2 `fullAutopilot`). */
279
+ export function fullAutopilotRow(policy, env) {
280
+ return env !== undefined && Boolean(policy.fullAutopilot?.includes(env));
281
+ }
282
+ function presetLabel(env, preset, actionClass, decision) {
267
283
  if (actionClass === "read")
268
284
  return "Reads always run";
285
+ if (preset === "full")
286
+ return fullAutopilotCause(env);
269
287
  if (actionClass === "irreversible")
270
288
  return "Irreversible actions always ask";
271
289
  // Plain words, no preset name: "Production writes ask first", "Staging writes run on their own".
@@ -326,6 +344,9 @@ function backupGate(policy, facts, decided) {
326
344
  return decided;
327
345
  if (decided.cause.kind !== "preset" && decided.cause.kind !== "default")
328
346
  return decided;
347
+ // Under Full autopilot nothing asks, backup or not.
348
+ if (fullAutopilotRow(policy, facts.environment))
349
+ return decided;
329
350
  if (facts.backup)
330
351
  return decided;
331
352
  if (facts.environment !== "production" && rows[facts.environment] === true)
@@ -372,8 +393,10 @@ function decideByRules(policy, facts) {
372
393
  }
373
394
  return { decision: rule.decision, cause: { kind: "rule", id: rule.id, label: ruleLabel(rule) } };
374
395
  }
375
- // 4 + 5. The environment preset, raised to the floor; irreversible always asks.
376
- const own = policy.presets[facts.environment] ?? DEFAULT_PRESETS[facts.environment];
396
+ // 4 + 5. The environment preset, raised to the floor; irreversible asks except under Full autopilot.
397
+ const own = fullAutopilotRow(policy, facts.environment)
398
+ ? "full"
399
+ : (policy.presets[facts.environment] ?? DEFAULT_PRESETS[facts.environment]);
377
400
  const ownDecision = presetDecision(own, facts.actionClass);
378
401
  if (floor && floorDecision && stricter(ownDecision, floorDecision) !== ownDecision) {
379
402
  return { decision: floorDecision, cause: { kind: "floor", label: floorLabel(facts.environment, floor) } };
package/dist/cliExec.d.ts CHANGED
@@ -51,8 +51,9 @@ export declare function execFinding(vendor: ExecVendor, binary: string, args: re
51
51
  } & Record<string, string>;
52
52
  /** gh acts on `--repo owner/name`, or the folder's GitHub origin. */
53
53
  export declare function githubRepo(args: readonly string[], cwd: string): string | undefined;
54
- /** Only the vendor's own variables, as plain single-line strings. */
55
- export declare function checkedCredential(vendor: ExecVendor, raw: unknown): Record<string, string>;
54
+ /** Only the vendor's own variables, as plain single-line strings. None for a Railway read Passport sends with the
55
+ * person's own sign-in (`ownSignIn`: Passport mints only for actions). */
56
+ export declare function checkedCredential(vendor: ExecVendor, raw: unknown, ownSignIn?: unknown): Record<string, string>;
56
57
  /** The child's environment: this shell's, minus every other credential the
57
58
  * vendor CLI could pick up and Passport's own, plus the issued one. */
58
59
  export declare function childEnvironment(base: NodeJS.ProcessEnv, credential: Record<string, string>): NodeJS.ProcessEnv;
package/dist/cliExec.js CHANGED
@@ -24,6 +24,7 @@ import { basename, dirname, join, resolve } from "node:path";
24
24
  import { bool, value } from "./cliArgs.js";
25
25
  import { memberApi } from "./cliClient.js";
26
26
  import { passportUnreachable } from "./cliOutput.js";
27
+ import { execControlPlaneRefusal, execRailwayScope, execRelease } from "./controlPlaneExec.js";
27
28
  import { classifyCommand, UNRECOGNIZED_VERB } from "./cliHookClassify.js";
28
29
  import { reportedEnvironment } from "./cliHookEnvironment.js";
29
30
  import { localMachine } from "./cliHookLocal.js";
@@ -134,8 +135,11 @@ export function githubRepo(args, cwd) {
134
135
  }
135
136
  return undefined;
136
137
  }
137
- /** Only the vendor's own variables, as plain single-line strings. */
138
- export function checkedCredential(vendor, raw) {
138
+ /** Only the vendor's own variables, as plain single-line strings. None for a Railway read Passport sends with the
139
+ * person's own sign-in (`ownSignIn`: Passport mints only for actions). */
140
+ export function checkedCredential(vendor, raw, ownSignIn) {
141
+ if (vendor === "railway" && ownSignIn === true)
142
+ return {};
139
143
  const allowed = new Set(EXEC_ENV_NAMES[vendor]);
140
144
  const env = raw && typeof raw === "object" && !Array.isArray(raw) ? raw : null;
141
145
  if (!env || !Object.keys(env).length) {
@@ -417,6 +421,9 @@ async function decide(ask, client, prepared, args, runtime, deps, auth) {
417
421
  return ask();
418
422
  }
419
423
  export async function exec(args, runtime, deps = {}) {
424
+ // git holds no key: its helper decides once exec names the command (execGit.ts).
425
+ if (args.positionals[0] === "git")
426
+ return (await import("./execGit.js")).execGit(args, runtime, deps);
420
427
  // Refusals come first: nothing is read or sent for a command exec won't run.
421
428
  const target = execTarget(args.positionals);
422
429
  if ("refused" in target)
@@ -425,6 +432,7 @@ export async function exec(args, runtime, deps = {}) {
425
432
  const auth = resolveCliAuth(args, runtime.env);
426
433
  const prepared = prepare(args, runtime, deps, auth);
427
434
  await withExecPlan(prepared, auth, () => execWhere(prepared.cwd, runtime.env));
435
+ await execRailwayScope(prepared, auth, runtime.env, deps.home, value(args, "decision"));
428
436
  const { vendor, binary } = prepared;
429
437
  const client = deps.api ??
430
438
  memberApi({ auth, caller: callerFrom(args, runtime.env), timeoutMs: timeoutMs(args), signal: runtime.signal });
@@ -475,44 +483,56 @@ export async function exec(args, runtime, deps = {}) {
475
483
  }
476
484
  if (decided.decision !== "allow")
477
485
  return pendingFailure(decided, "Passport didn't allow this command yet.");
478
- const credential = checkedCredential(vendor, decided.credential?.env);
479
- remember(true);
480
- // A dev loop runs only with a key that expires within minutes.
481
- const devLoop = devLoopRefusal(vendor, args.positionals.slice(1), decided.credential?.issuance);
482
- if (devLoop)
483
- return failure(devLoop, 6, "exec_refused");
484
- if (bool(args, "verbose") && typeof decided.credential?.label === "string") {
485
- // "Your stored Railway key" reads "Passport: used your stored Railway key."
486
- const label = decided.credential.label.slice(0, 120);
487
- runtime.stderr.write(`Passport: used ${label.charAt(0).toLowerCase()}${label.slice(1)}.\n`);
488
- }
486
+ // A Railway token Passport minted is revoked however the command ends: it exits, is refused, or never starts.
487
+ const issued = execRelease(client.fetchApi, vendor, decided);
489
488
  let code;
490
489
  const startedAt = (deps.now ?? Date.now)();
491
- const needles = maskingWanted(args, runtime.env, runtime.stdout) ? secretNeedles(credential) : [];
492
490
  // Links (bridge 0.32.0): a bounded copy of what it prints, only when that isn't a terminal.
493
491
  const wanted = linksWanted(auth.kind === "profile" ? readCliPolicy(auth.profile) : null);
494
492
  const capture = execCapture(wanted, runtime.stdout);
495
- const piped = outputTarget(runtime, needles, capture);
496
- const handed = await handOver(prepared, credential, decided.credential?.expiresAt, runtime, deps);
497
- const options = {
498
- stdio: piped ? ["inherit", "pipe", "pipe"] : "inherit",
499
- env: childEnvironment(runtime.env, handed.env),
500
- shell: false,
501
- cwd: prepared.cwd
502
- };
503
- // One deploy at a time: renew the lease Passport took while it runs, release it after.
504
- const lease = (await import("./execLease.js")).keepLease(client.fetchApi, decided.leaseId);
505
493
  try {
506
- code = deps.spawn
507
- ? await deps.spawn(prepared.executable, prepared.rest, options)
508
- : await spawnVendor(prepared.executable, prepared.rest, options, piped);
509
- }
510
- catch {
511
- return failure(`${binary} couldn't start.`, 1, "not_installed");
494
+ const credential = checkedCredential(vendor, decided.credential?.env, decided.credential?.ownSignIn);
495
+ remember(true);
496
+ // The control plane (GitHub connected) decides a gh command with its token's id.
497
+ await execControlPlaneRefusal(client.fetchApi, prepared, decided, timeoutMs(args), {
498
+ ...(runtime.signal ? { signal: runtime.signal } : {}),
499
+ asks: auth.kind === "profile"
500
+ });
501
+ // A dev loop runs only with a key that expires within minutes.
502
+ const devLoop = devLoopRefusal(vendor, args.positionals.slice(1), decided.credential?.issuance);
503
+ if (devLoop)
504
+ return failure(devLoop, 6, "exec_refused");
505
+ if (bool(args, "verbose") && typeof decided.credential?.label === "string") {
506
+ // "Your stored Railway key" reads "Passport: used your stored Railway key."
507
+ const label = decided.credential.label.slice(0, 120);
508
+ runtime.stderr.write(`Passport: used ${label.charAt(0).toLowerCase()}${label.slice(1)}.\n`);
509
+ }
510
+ const needles = maskingWanted(args, runtime.env, runtime.stdout) ? secretNeedles(credential) : [];
511
+ const piped = outputTarget(runtime, needles, capture);
512
+ const handed = await handOver(prepared, credential, decided.credential?.expiresAt, runtime, deps);
513
+ const options = {
514
+ stdio: piped ? ["inherit", "pipe", "pipe"] : "inherit",
515
+ env: { ...childEnvironment(runtime.env, handed.env), ...issued.env },
516
+ shell: false,
517
+ cwd: prepared.cwd
518
+ };
519
+ // One deploy at a time: renew the lease Passport took while it runs, release it after.
520
+ const lease = (await import("./execLease.js")).keepLease(client.fetchApi, decided.leaseId);
521
+ try {
522
+ code = deps.spawn
523
+ ? await deps.spawn(prepared.executable, prepared.rest, options)
524
+ : await spawnVendor(prepared.executable, prepared.rest, options, piped);
525
+ }
526
+ catch {
527
+ return failure(`${binary} couldn't start.`, 1, "not_installed");
528
+ }
529
+ finally {
530
+ await lease.stop();
531
+ await handed.stop();
532
+ }
512
533
  }
513
534
  finally {
514
- await lease.stop();
515
- await handed.stop();
535
+ await issued.release();
516
536
  }
517
537
  if (typeof decided.actionId === "string") {
518
538
  const durationMs = Math.max(0, Math.round((deps.now ?? Date.now)() - startedAt));
@@ -0,0 +1,38 @@
1
+ import { type ParsedArgs } from "./cliArgs.js";
2
+ import { type CommandResult, type Runtime } from "./cliSupport.js";
3
+ import { type ReadProcess } from "./gitInvocation.js";
4
+ import { type RunGit } from "./gitCredentialSetup.js";
5
+ export declare const GIT_CREDENTIAL_PATH = "/api/my/github/git-credential";
6
+ export declare const TOKEN_USERNAME = "x-access-token";
7
+ /** git waits on us for every fetch and push: past this in all, the push uses this computer's own sign-in. */
8
+ export declare const MINT_TIMEOUT_MS = 5000;
9
+ /** Each decision gets at most this long, within what's left of the whole. */
10
+ export declare const DECIDE_TIMEOUT_MS = 1000;
11
+ type ApiCall = (path: string, init: RequestInit) => Promise<Response>;
12
+ export type GitCredentialDependencies = {
13
+ api?: ApiCall;
14
+ /** Which git command asked (tests); the default walks this process's parents. */
15
+ clock?: () => number;
16
+ asking?: () => string[] | null;
17
+ readProcess?: ReadProcess;
18
+ /** Run a fallback helper with the request on stdin (tests). */
19
+ fallback?: (helper: string, operation: string, input: string, env: Runtime["env"]) => Promise<string>;
20
+ run?: RunGit;
21
+ command?: readonly string[];
22
+ /** What a helper line answers (tests); the default runs it as git would. */
23
+ probe?: (line: string, env: Runtime["env"]) => string | null;
24
+ mintTimeoutMs?: number;
25
+ decideTimeoutMs?: number;
26
+ cwd?: string;
27
+ platform?: NodeJS.Platform;
28
+ };
29
+ export type CredentialRequest = Map<string, string>;
30
+ export declare function parseCredentialRequest(text: string): CredentialRequest;
31
+ /** owner/name for https://github.com/<owner>/<name>(.git), else null. */
32
+ export declare function githubRepoOf(request: CredentialRequest): string | null;
33
+ /** How git runs a helper string (gitcredentials(7)): `!cmd` through the shell, an absolute path as is, else `git credential-<name>`. */
34
+ export declare function fallbackCommand(helper: string, operation: string): string;
35
+ /** The accounts the App covers, from the keys view; none when Passport can't be asked. */
36
+ export declare function coveredOwners(api: ApiCall | undefined, signal: AbortSignal): Promise<string[]>;
37
+ export declare function gitCredential(args: ParsedArgs, runtime: Runtime, deps?: GitCredentialDependencies): Promise<CommandResult>;
38
+ export {};