foldrun 20.2.0 → 20.4.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/bin/foldrun.mjs CHANGED
@@ -300,9 +300,11 @@ Signing in
300
300
  foldrun preferences your own settings on the platform — the theme; set theme system|light|dark (a key acts for whoever minted it)
301
301
  foldrun doctor check the path to the platform: node, CLI, model credential, account, DNS, a timed /api/healthz
302
302
  foldrun accounts every account signed in on this machine, and which one is active
303
+ foldrun accounts prune forget the saved sign-ins that no longer work (--unreachable: also those whose platform did not answer)
303
304
  foldrun use <name> act as one of them from here on
304
305
  foldrun keys ls the account's API keys: created, last used, expires, scope, and which are a machine's CLI sign-in (they renew themselves) — also create <label> [--expires 90d], rotate <id> [--grace 1h], revoke <id>
305
306
  foldrun keys create <label> --a2a --to <ws> --flows a,b a key for an OUTSIDE agent: it opens /a2a for those published flows and no /api route (--max-tasks N open at once, default 10; --expires); shown once
307
+ foldrun keys set <id> --sonnet openai/gpt-6 which model a gateway key runs each Claude Code tier on (--opus, --haiku; - clears one, --clear all)
306
308
  foldrun keys create <label> --gateway --cap <usd> [--daily <usd>] a key for a CODING agent (Claude Code: ANTHROPIC_BASE_URL + this key) — it spends the account's credits on foldrun's models through the gateway, up to its own limits, and opens no /api route; an admin of every workspace; shown once
307
309
  foldrun a2a ls --to <ws> what a workspace serves over A2A: each flow's a2a:, card and endpoint URLs, its A2A keys (admins), recent tasks and the key that asked (--json)
308
310
  foldrun a2a publish <flow> set a2a: publish: true in the flow (--to <ws>: the deployed copy, an admin's) — --name, --description, --example "…" (repeatable), --public-card | --private-card; diff, checked, --dry-run
@@ -455,6 +457,7 @@ Options
455
457
  --gateway keys create: a gateway key for Claude Code — with --cap <usd> (in all) and/or --daily <usd> (per UTC day)
456
458
  --cap <usd>, --daily <usd> keys create --gateway: the key's own spending limits, $0.01–$100000
457
459
  --login keys create --gateway: on the operator's Claude login instead (the operator's own accounts; not metered, no limits)
460
+ --opus, --sonnet, --haiku <model> keys set <id>: which model that Claude Code tier runs on with a gateway key (e.g. openai/gpt-6; - clears it)
458
461
  --key-env <NAME> a2a call, a2a status, a2a cancel, a2a card: the environment variable holding the A2A key (default FOLDRUN_A2A_KEY) — a key is never taken on the command line
459
462
  --card <url> a2a status, a2a cancel: the agent card of the agent that holds the task
460
463
 
@@ -499,7 +502,7 @@ if (!command || command === "--help" || command === "-h") {
499
502
  // `--value` as the account's argument and stored an empty secret; `--force
500
503
  // ./dir` swallowed the directory. A flag followed by another flag is also
501
504
  // boolean, so an unlisted switch at least does not eat its neighbour.
502
- const BOOLEAN_FLAGS = new Set(["read-only", "account", "follow", "force", "oauth2", "wait", "watch", "print", "dry-run", "help", "no-browser", "local", "test", "flat", "yes", "platform", "json", "forever", "all", "check", "new-client", "quiet", "off", "can-ask", "preview", "csv", "failed", "starter", "history", "list", "library", "clear", "security", "changed", "write-baseline", "no-baseline", "rules", "calls", "tree", "tool-error", "stop", "last", "no-pkce", "generate-key", "device", "write", "dpop", "export", "isolated", "no-wait", "dismissed", "unread", "team", "started", "mine", "none", "a2a", "gateway", "login", "public-card", "private-card", "return-immediately", "online", "overwrite", "no-send", "event-wait", "with-client", "use", "clear-name", "clear-description", "clear-examples", "clear-accept-risk", "clear-address", "clear-email", "clear-abn", "no-task", "empty"]);
505
+ const BOOLEAN_FLAGS = new Set(["read-only", "account", "follow", "force", "oauth2", "wait", "watch", "print", "dry-run", "help", "no-browser", "local", "test", "flat", "yes", "platform", "json", "forever", "all", "check", "new-client", "quiet", "off", "can-ask", "preview", "csv", "failed", "starter", "history", "list", "library", "clear", "security", "changed", "write-baseline", "no-baseline", "rules", "calls", "tree", "tool-error", "stop", "last", "no-pkce", "generate-key", "device", "write", "dpop", "export", "isolated", "no-wait", "dismissed", "unread", "team", "started", "mine", "none", "a2a", "gateway", "login", "unreachable", "public-card", "private-card", "return-immediately", "online", "overwrite", "no-send", "event-wait", "with-client", "use", "clear-name", "clear-description", "clear-examples", "clear-accept-risk", "clear-address", "clear-email", "clear-abn", "no-task", "empty"]);
503
506
  // Flags said more than once collect into a list: `--tag a --tag b`.
504
507
  const REPEATABLE = new Set(["tag", "expect", "header", "site", "add", "remove", "rule", "authorize-param", "example", "accept-risk"]);
505
508
  // `--wait` is a switch everywhere but `flow add <flow> wait`, where it takes
package/docs/api.md CHANGED
@@ -366,7 +366,8 @@ Reads return which secrets exist, never their values.
366
366
 
367
367
  | Route | Methods | |
368
368
  |---|---|---|
369
- | `/api/keys` | GET, POST, DELETE | API keys — an admin's (`keys:manage`) to list, mint and revoke; any key may revoke itself (DELETE with its own `id`, audited as self — what `foldrun logout` does). POST `label`, `role` (viewer \| editor \| admin, never above your own, default editor), `workspaces` (names, or `null` for all — never wider than your own scope); `expires` (`30d`, `90d`, `365d`, any number of days up to 3650, or `never` — the default; anything else is a 400, never a key that lives forever); returns `{ ok, key, id, prefix, role, workspaces, expiresAt }`. POST `{ purpose: "a2a", workspace, flows, maxTasks?, label?, expires? }` mints an A2A key instead: for an outside agent, it opens `/a2a/<account>/<workspace>/…` for the named flows (each must say `a2a: { publish: true }` when the key is minted — a flow not published is refused, 400 — and still say it on every call) and every `/api` route refuses it (403); `maxTasks` (1–100, default 10) caps its tasks open at once; it answers `{ ok, key, id, prefix, purpose, workspace, flows, maxTasks, role, workspaces, expiresAt }`, and rotating one keeps the tasks it made, and the key is shown once. POST `{ purpose: "gateway", capUsd?, dailyUsd?, label?, expires? }` mints a gateway key: for a coding agent such as Claude Code (`ANTHROPIC_BASE_URL` + the key, [Claude Code](claude-code.md)), it spends the account's credits on foldrun's Anthropic models through the gateway and every `/api` route refuses it (403); it needs `capUsd` (USD in all) or `dailyUsd` (USD per UTC day), $0.01–$100,000 after rounding to cents, is minted only by an admin of every workspace (a scoped admin is 403) and only on the hosted platform (400 elsewhere), and answers `{ ok, key, id, prefix, purpose, capUsd, dailyUsd, expiresAt, gatewayUrl }`; rotating one keeps its limits. With `credential: "login"` it runs on the operator's own Claude login instead — only on an account the operator allows its model credential (403 otherwise), with no `capUsd`/`dailyUsd` (400), not metered or billed; it answers `credential: "login"` and lists with no spend. GET lists each key with `createdAt`, `createdBy`, `expiresAt`, `lastUsedAt`, `lastIp` and `replacedBy` (the id of the key a rotation replaced it with; `null` until then), a gateway key's `gateway: { capUsd, dailyUsd, spentUsd, todayUsd }` (spent in all and today, UTC, calls in flight at their hold), and at the top `gatewayUrl` (the gateway's address; `null` where the install has none) — the last-use pair written at most once a minute per key, the address cut to its /24 (IPv4) or /48 (IPv6). A key past its `expiresAt` is refused with 401 `API key expired on <date>`; the owner is emailed seven days before. Mint, revoke and rotate are written to the audit log. POST with `workspace` or `access` is refused (400): those minted deploy keys for the platform's own git, which went on 17 Oct 2026 — a deploy key minted before is refused everywhere (403). A key for one workspace is `workspaces: ["<ws>"]`. DELETE `id`. `?tenant=` / body `tenant` is read only on an install with no users yet (first-run bootstrap), and there, when the install has a setup token (`FOLDRUN_SETUP_TOKEN`, written by the self-hosting installer), only with that token in `X-Foldrun-Setup-Token` |
369
+ | `/api/keys` | GET, POST, DELETE | API keys — an admin's (`keys:manage`) to list, mint and revoke; any key may revoke itself (DELETE with its own `id`, audited as self — what `foldrun logout` does). POST `label`, `role` (viewer \| editor \| admin, never above your own, default editor), `workspaces` (names, or `null` for all — never wider than your own scope); `expires` (`30d`, `90d`, `365d`, any number of days up to 3650, or `never` — the default; anything else is a 400, never a key that lives forever); returns `{ ok, key, id, prefix, role, workspaces, expiresAt }`. POST `{ purpose: "a2a", workspace, flows, maxTasks?, label?, expires? }` mints an A2A key instead: for an outside agent, it opens `/a2a/<account>/<workspace>/…` for the named flows (each must say `a2a: { publish: true }` when the key is minted — a flow not published is refused, 400 — and still say it on every call) and every `/api` route refuses it (403); `maxTasks` (1–100, default 10) caps its tasks open at once; it answers `{ ok, key, id, prefix, purpose, workspace, flows, maxTasks, role, workspaces, expiresAt }`, and rotating one keeps the tasks it made, and the key is shown once. POST `{ purpose: "gateway", capUsd?, dailyUsd?, label?, expires? }` mints a gateway key: for a coding agent such as Claude Code (`ANTHROPIC_BASE_URL` + the key, [Claude Code](claude-code.md)), it spends the account's credits on foldrun's Anthropic models through the gateway and every `/api` route refuses it (403); it needs `capUsd` (USD in all) or `dailyUsd` (USD per UTC day), $0.01–$100,000 after rounding to cents, is minted only by an admin of every workspace (a scoped admin is 403) and only on the hosted platform (400 elsewhere), and answers `{ ok, key, id, prefix, purpose, capUsd, dailyUsd, expiresAt, gatewayUrl }`; rotating one keeps its limits. `models` maps Claude Code's tiers to other models (see `PATCH /api/keys/<id>`). With `credential: "login"` it runs on the operator's own Claude login instead — only on an account the operator allows its model credential (403 otherwise), with no `capUsd`/`dailyUsd` (400), not metered or billed; it answers `credential: "login"` and lists with no spend. GET lists each key with `createdAt`, `createdBy`, `expiresAt`, `lastUsedAt`, `lastIp` and `replacedBy` (the id of the key a rotation replaced it with; `null` until then), a gateway key's `gateway: { capUsd, dailyUsd, spentUsd, todayUsd }` (spent in all and today, UTC, calls in flight at their hold), and at the top `gatewayUrl` (the gateway's address; `null` where the install has none) — the last-use pair written at most once a minute per key, the address cut to its /24 (IPv4) or /48 (IPv6). A key past its `expiresAt` is refused with 401 `API key expired on <date>`; the owner is emailed seven days before. Mint, revoke and rotate are written to the audit log. POST with `workspace` or `access` is refused (400): those minted deploy keys for the platform's own git, which went on 17 Oct 2026 — a deploy key minted before is refused everywhere (403). A key for one workspace is `workspaces: ["<ws>"]`. DELETE `id`. `?tenant=` / body `tenant` is read only on an install with no users yet (first-run bootstrap), and there, when the install has a setup token (`FOLDRUN_SETUP_TOKEN`, written by the self-hosting installer), only with that token in `X-Foldrun-Setup-Token` |
370
+ | `/api/keys/<id>` | PATCH | a gateway key's model map: `{ models: { opus?, sonnet?, haiku? } }` — which model each Claude Code tier runs on with that key (`provider/model` such as `openai/gpt-6`, or a known prefix), each on foldrun's price list; a login gateway key maps to Claude models only; `{ models: null }` clears it. Answers `{ ok, id, models }`. `keys:manage` and an admin of every workspace; any other key is 400. The gateway reads the change within its 10 s key cache. Audited as `apikey.models`. The same `models` may be given when minting (`POST /api/keys { purpose: "gateway", models }`) |
370
371
  | `/api/keys/<id>/rotate` | POST | a new key with the old one's label, role, workspaces and deploy scope — and, when it had an end, the same lifetime from today — returned once like a mint (`{ ok, key, id, prefix, role, workspaces, expiresAt, replaced: { id, endsAt } }`). `grace`: `0` (default — the old key is revoked at once), or a duration up to `7d` such as `1h` or `24h`, during which the old key still works and after which it is refused as expired. A key is rotated once: rotating a key already replaced is 409 `this key was already rotated to <prefix>…; rotate that one` — and someone who lost the new key's secret rotates the NEW key, which mints another and ends the lost one (rotating the old one again would leave the lost key working). Two rotations of one key at once mint one key. `keys:manage`; a key outside the caller's scope is 404 — except that a key `foldrun login` minted may rotate **itself**, whatever its role: same label, role, workspaces and 90-day lifetime from today, the old key ending 10 minutes later (`grace` is not read). A retry with the old key inside those 10 minutes — the CLI lost the answer, or could not store it — rotates that replacement instead, when nobody has used it and it is at least 30 seconds old (a younger one is a 409: another command may have just stored it). That is how the CLI renews its sign-in; any other key rotating itself still needs `keys:manage`. Audited as `apikey.rotated` (`self: true` for a self-rotation). A `foldrun login` key stays one only when it renews itself or its own person rotates it, signed in; rotated by any other caller the new key is an ordinary one |
371
372
  | `/api/team` | GET, POST | members with their roles and workspace scope; mint an invite (a session, or the person's own `foldrun login` key, which invites no admin) — `role` (viewer \| editor \| admin, default editor), `workspaces` (names, or omit for all), `email` (only that address can accept it; sent through the account's `RESEND_API_KEY` unless `send: false`). An invite works **once**, for seven days, and a newer invite to the same address revokes the older ones still pending. Returns `id`, `path` (the invite's relative URL, shown only here), `expires`, `sent` and any `sendError` either way; the full link is in the mail. Links made before 29 Oct 2026 (`inv1`–`inv3`) are refused |
372
373
  | `/api/team/invites?all=1` | GET | the account's invites, newest first — pending ones unless `all=1` (then accepted, revoked and expired too): `{ invites: [{ id, email, role, workspaces, invitedBy, createdAt, expiresAt, status }] }`, `email` `null` for a link anyone may use, `workspaces` `null` for all, `status` `pending` \| `accepted` \| `revoked` \| `expired`. Never the link. `team:manage` — an admin key included; a caller scoped to some workspaces sees only the invites inside its scope |
@@ -66,6 +66,60 @@ only on such an account). Such a key:
66
66
  It is for the operator's own use. A subscription's terms are its owner's to
67
67
  keep; foldrun's models (the rest of this page) are what to give anyone else.
68
68
 
69
+ ## Other providers' models
70
+
71
+ The same key reaches DeepSeek's, Kimi's, OpenAI's and Gemini's models: name
72
+ one, and the gateway sends it to that provider on foldrun's models (billed at
73
+ its price, under the same limits).
74
+
75
+ ```sh
76
+ claude --model deepseek/deepseek-v4 # or /model deepseek/deepseek-v4 in a session
77
+ claude --model kimi/kimi-k3
78
+ claude --model openai/gpt-6 # or gpt-6
79
+ claude --model gemini/gemini-3-pro # or gemini-3-pro
80
+ ```
81
+
82
+ - **Choosing a provider.** `provider/model` always works (`anthropic/`,
83
+ `deepseek/`, `kimi/`, `openai/`, `gemini/`). A bare name with a known prefix
84
+ works too: `deepseek-…`, `kimi-…`, `gpt-…`, `gemini-…`, or `claude-…` for
85
+ Anthropic. Anything else goes to Anthropic.
86
+ - **How each is reached.** DeepSeek and Kimi speak Anthropic's format and are
87
+ sent as they are. OpenAI (Responses API) and Gemini (Chat Completions) are
88
+ translated both ways, by the same translator runs use.
89
+ - Tools work on all of them.
90
+ - Gemini's thought signatures are kept between your calls (in the
91
+ platform's cache, per account, for two hours), so a multi-turn tool loop
92
+ works on Gemini too.
93
+ - Translation drops prompt caching, thinking where the provider has none,
94
+ and Anthropic's server tools (web search, web fetch).
95
+ - **What Claude Code sends.** It sends the name you give it unchanged.
96
+ Claude Code's own `/model` list shows Claude models only, so type the name.
97
+ Each provider gets only the request fields its API takes; the rest are
98
+ dropped.
99
+ - **Token counts.** A provider with no token-count route gets an estimate
100
+ (marked `x-foldrun-estimate: 1`).
101
+ - **What Claude Code can't know.** For non-Claude models it shows the wrong
102
+ cost and context size. The charge is foldrun's.
103
+ - **What isn't offered.** A login gateway key stays Claude-only.
104
+
105
+ ## Run Claude Code's own tiers on other models
106
+
107
+ Claude Code's `/model` list shows Claude's tiers alone. A gateway key can map
108
+ each tier to any model foldrun offers, so picking Sonnet in `/model` (or
109
+ `--model sonnet`) runs, say, GPT — with no setting in Claude Code at all:
110
+
111
+ ```sh
112
+ foldrun keys set <id> --sonnet openai/gpt-6 --haiku deepseek/deepseek-v4
113
+ foldrun keys set <id> --haiku - # Haiku back to Claude
114
+ foldrun keys set <id> --clear # every tier as Claude Code names it
115
+ ```
116
+
117
+ On Settings → API keys, a gateway key's **Models** button does the same, and
118
+ the row shows what each tier runs on. A mapped model must be on foldrun's
119
+ price list; a login gateway key maps to Claude models only. The gateway reads a
120
+ change within 10 seconds. API: `PATCH /api/keys/<id> { models }`, or `models`
121
+ when minting.
122
+
69
123
  ## What the gateway serves
70
124
 
71
125
  | Route | |
@@ -109,8 +163,10 @@ the reason:
109
163
  | `401` | no key, an unknown, revoked or expired key |
110
164
  | `403` | not a gateway key; foldrun's models off for the account |
111
165
  | `402` | out of credits; the key's limit or the account's daily limit has no room; a model with no price |
166
+ | `429` | the key's request rate (300 a minute) or its open calls (32 at once) — with `Retry-After`; waiting helps. Every route and every kind of key counts |
112
167
  | `400` | a request field that is not offered (named in the message) |
113
168
 
114
- A spent limit is a `402`, not a `429`: Claude Code retries a `429` for minutes,
169
+ A key that is revoked can still answer for up to 10 seconds: each gateway pod
170
+ caches a key for that long. A spent limit is a `402`, not a `429`: Claude Code retries a `429` for minutes,
115
171
  and no retry makes room under a limit. A `429` from Anthropic itself comes
116
172
  back as it was.
package/docs/cli.md CHANGED
@@ -203,12 +203,13 @@ claude.ai or Claude Code there, nor any MCP configuration on disk.
203
203
  | `foldrun history restore <path> --id <revision>` | the History drawer's **Restore this version**: the file is rewritten with that revision's text as a new revision, `restored <rev> from history`, so the restore is itself undone the same way. Shows the diff against the file now and asks (`--yes`, `--dry-run`); sent with `ifMatch`, so a file that changed since is refused. A version that does not pass today's checks is still restored, and the errors are printed (`--to`) |
204
204
  | `foldrun restore <workspace> --to <revision\|time\|age>` | put a workspace's source back as it was then — `--to` is a revision id (`r-…`, from `foldrun history`), the commit a deploy named, a date/time (the last revision at or before it) or an age (`90m`, `12h`, `3d`, `2w`). Always shows the change first (`--dry-run`: the full diff and nothing else); the restore asks for the workspace's name typed back (`--yes` with no terminal) and sends the removals it showed, so a file added in between refuses it. A new revision, so it prints the `foldrun restore … --to <from>` that undoes it. Runs, `state/`, storage and secrets are not touched. See [Backups and restore](backups-and-restore.md) |
205
205
  | `foldrun backups` | how the account is backed up: the schedule, how many are kept, the last snapshot (verified? copied off the server? encrypted?), the snapshots that hold the account, each marked encrypted or not, each workspace's last change, and earlier restore requests (`--limit`, `--json`). `backups request --what runs\|state\|storage\|everything --at "<when>" [--to <workspace>] [--backup <id>] [--note "…"]` asks the platform team for a restore from a snapshot — recorded and emailed; nothing is restored until they do it. `backups requests` lists every request this account has made, and where each stands (`GET /api/account/backups/requests`, `--json`) |
206
- | `foldrun accounts` | every account signed in on this machine, and which one a bare command acts as. `foldrun profiles` is the same command |
206
+ | `foldrun accounts` | every account signed in on this machine whose sign-in still works, and which one a bare command acts as. Each is asked once (`GET /api/me`, in parallel); one whose key is refused (revoked, expired, an account that is gone) or whose platform does not answer is left out and counted in one line — the active one is always shown, marked when it fails. `--all` lists every one with what it answered; `accounts prune` forgets the refused ones on this machine (asks first; `--yes` on a pipe; `--unreachable` also those that did not answer). `foldrun profiles` is the same command |
207
207
  | `foldrun use <name>` | act as one of them from here on. `foldrun switch <name>` is the same command |
208
208
  | `foldrun keys ls` | the account's API keys, each with its role and scope, when it was created, when it was last used and from where (a /24 or /48), and when it expires; a key `foldrun login` minted is tagged `CLI sign-in · renews itself` (revoke it to sign that machine out) — also `create <label>` (`--expires 30d\|90d\|365d\|never`), `rotate <id>` and `revoke <id>` |
209
209
  | `foldrun keys rotate <id>` | a new key with the old one's label, role, workspaces and deploy scope, printed once; the old key is revoked at once (asks first; `--yes` on a pipe), or keeps working for `--grace 1h` / `24h` while you swap the new one in. A key already rotated is refused (409) and the command names the key that replaced it — rotate that one, also if its secret was lost; `keys ls` shows `rotated → <id>`. The owner is emailed a week before any key expires |
210
210
  | `foldrun keys create <label> --a2a --to <ws> --flows a,b` | a key for an outside agent ([A2A](a2a.md)): it opens `/a2a/<account>/<ws>/…` — the agent card and JSON-RPC endpoint of those flows, each published with `a2a:` (a flow not published when the key is minted is refused: publish first) — and no `/api` route. `--max-tasks <n>` caps the tasks it may have open at once (1–100, default 10); `--expires` as for any key. Printed once; `keys ls` shows it as `A2A · <ws> · <flows>`. `POST /api/keys { purpose: "a2a", workspace, flows, maxTasks }`, an admin's |
211
211
  | `foldrun keys create <label> --gateway --cap <usd>` | a gateway key for a coding agent ([Claude Code](claude-code.md)): `ANTHROPIC_BASE_URL` + this key run Claude Code on the account's credits, through foldrun's gateway, and it opens no `/api` route. `--cap` (USD in all) and/or `--daily` (USD per UTC day) — at least one, $0.01–$100,000; `--expires` as for any key. Printed once with the two `export` lines; `keys ls` shows it as `gateway · Claude Code · $spent of $cap · $today of $daily today`. `POST /api/keys { purpose: "gateway", capUsd, dailyUsd }`, an admin of every workspace |
212
+ | `foldrun keys set <id> --sonnet <model>` | a gateway key's model map: which model each Claude Code tier runs on with that key (`--opus`, `--sonnet`, `--haiku`, each `provider/model` such as `openai/gpt-6`; `-` clears one, `--clear` all). The tiers named change, the rest stay. `keys ls` shows the map. `PATCH /api/keys/<id> { models }`, an admin of every workspace |
212
213
  | `foldrun a2a ls --to <ws>` | what a workspace serves over A2A (`GET /api/workspaces/<ws>/a2a`): every flow that says `a2a:`, published or not, with its public/private card and its card and endpoint URLs; the workspace's A2A keys (an admin's view; `null` otherwise); and the newest tasks — state, flow, run, and `A2A · <key label>`; then, under **Secret and code**, every agent that holds a secret and can run code, accepted or not, with the `--accept-risk` line that accepts it. `--json` prints the answer as it came |
213
214
  | `foldrun a2a publish <flow>` | sets `a2a: { publish: true }` in the flow, keeping the rest of its block: `--name`, `--description`, `--example "…"` (repeatable — the card's examples), `--public-card` (the card is readable without a key; calling never is) or `--private-card`. Checked with core's `a2a:` rules before anything is written; shows the diff, `--dry-run` writes nothing. Without `--to` it edits this folder (`deploy` ships it); `--to <workspace>` sends the flow page's `PATCH …/flows/<flow> { a2a, expect }` — an admin's, the platform refuses an editor — and prints the card URL. A caller also needs an A2A key that names the flow |
214
215
  | `foldrun a2a unpublish <flow>` | `a2a: publish: false` — no outside agent may call it, whatever keys name it; the rest of `a2a:` stays for the next publish. `--to`, `--dry-run` as for `publish` |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foldrun",
3
- "version": "20.2.0",
3
+ "version": "20.4.0",
4
4
  "description": "Agents are just folders. Write them, check them, run them — on your machine.",
5
5
  "license": "FSL-1.1-ALv2",
6
6
  "type": "module",
@@ -11,7 +11,7 @@
11
11
  "node": ">=22"
12
12
  },
13
13
  "dependencies": {
14
- "@foldrun/core": "^18.0.0"
14
+ "@foldrun/core": "^18.0.1"
15
15
  },
16
16
  "files": [
17
17
  "bin",
package/src/commands.mjs CHANGED
@@ -4697,6 +4697,7 @@ async function doctor(flags) {
4697
4697
  * keys create <label> --a2a --to <ws> --flows a,b [--max-tasks N] a key for an outside agent: /a2a only
4698
4698
  * keys create <label> --gateway --cap <usd> [--daily <usd>] a coding agent's key (Claude Code): the gateway only
4699
4699
  * keys create <label> --gateway --login on the operator's Claude login (its own accounts): not metered
4700
+ * keys set <id> --opus|--sonnet|--haiku <provider/model> which model each Claude Code tier runs on (a gateway key; `-` clears one, --clear all)
4700
4701
  * keys rotate <id> [--grace 1h] a new key, same label/role/scope; the old
4701
4702
  * one ends now, or when the grace runs out.
4702
4703
  * A key already rotated is refused (409):
@@ -4795,7 +4796,8 @@ async function keysCmd(positional, flags) {
4795
4796
  console.log(` ${c.dim(`Shown once. The old key ${grace === "0" ? "is revoked" : `keeps working until ${String(ends).slice(0, 16).replace("T", " ")} UTC`}.`)}\n`);
4796
4797
  return 0;
4797
4798
  }
4798
- throw new Error(`keys: unknown verb "${verb}" — ls, create, rotate, revoke`);
4799
+ if (verb === "set") return keysSetModels(url, arg, flags);
4800
+ throw new Error(`keys: unknown verb "${verb}" — ls, create, set, rotate, revoke`);
4799
4801
  }
4800
4802
 
4801
4803
  /**
@@ -4827,15 +4829,55 @@ async function keysCreateA2a(url, label, flags) {
4827
4829
  return 0;
4828
4830
  }
4829
4831
 
4832
+ /**
4833
+ * `foldrun keys set <id> --sonnet openai/gpt-6 [--opus …] [--haiku …]` — a
4834
+ * gateway key's model map: which model each Claude Code tier runs on with
4835
+ * that key. The tiers named change; the rest stay. `-` clears one tier,
4836
+ * `--clear` every one. PATCH /api/keys/<id> { models }.
4837
+ */
4838
+ async function keysSetModels(url, id, flags) {
4839
+ if (!id) throw new Error("which key? foldrun keys set <id> --sonnet openai/gpt-6 — ids are in `foldrun keys ls`");
4840
+ const tiers = ["opus", "sonnet", "haiku"];
4841
+ const named = tiers.filter((t) => flags[t] !== undefined);
4842
+ if (flags.clear !== true && !named.length) throw new Error("which tier? --opus, --sonnet or --haiku <provider/model> (`-` clears one), or --clear for all");
4843
+ for (const t of named) if (typeof flags[t] !== "string" || !flags[t]) throw new Error(`--${t} needs a model, e.g. --${t} openai/gpt-6 (or - to clear it)`);
4844
+ let models = null;
4845
+ if (flags.clear !== true) {
4846
+ const { keys = [] } = await remoteCall(url, flags, "/api/keys");
4847
+ const key = keys.find((k) => k.id === id);
4848
+ if (!key) throw new Error(`no key ${id} — \`foldrun keys ls\` lists them`);
4849
+ if (key.purpose !== "gateway") throw new Error(`${id} is not a gateway key — only a gateway key has a model map`);
4850
+ const next = { ...(key.gateway?.models ?? {}) };
4851
+ for (const t of named) {
4852
+ if (flags[t] === "-") delete next[t];
4853
+ else next[t] = flags[t];
4854
+ }
4855
+ models = Object.keys(next).length ? next : null;
4856
+ }
4857
+ const made = await remoteCall(url, flags, `/api/keys/${encodeURIComponent(id)}`, { method: "PATCH", body: JSON.stringify({ models }) });
4858
+ const line = modelsLine(made.models);
4859
+ console.log(`\n ${c.green("✓")} ${c.bold(id)} ${line ? c.dim(line) : c.dim("runs Claude Code's models as named")}\n`);
4860
+ return 0;
4861
+ }
4862
+
4863
+ /** A gateway key's model map in one line, or null when there is none. */
4864
+ function modelsLine(m) {
4865
+ const label = { opus: "Opus", sonnet: "Sonnet", haiku: "Haiku" };
4866
+ const parts = ["opus", "sonnet", "haiku"].filter((t) => m?.[t]).map((t) => `${label[t]} → ${m[t]}`);
4867
+ return parts.length ? parts.join(" · ") : null;
4868
+ }
4869
+
4830
4870
  /** How `keys ls` describes a gateway key: its limits, and what it has spent. */
4831
4871
  function gatewayLine(g) {
4832
- if (g?.credential === "login") return "gateway · Claude Code · the operator's Claude login · not metered";
4872
+ const map = modelsLine(g?.models);
4873
+ const tail = map ? ` · ${map}` : "";
4874
+ if (g?.credential === "login") return `gateway · Claude Code · the operator's Claude login · not metered${tail}`;
4833
4875
  const usd = (n) => `$${Number(n ?? 0).toFixed(2)}`;
4834
4876
  const parts = ["gateway · Claude Code"];
4835
4877
  if (g?.capUsd != null) parts.push(`${usd(g.spentUsd)} of ${usd(g.capUsd)}`);
4836
4878
  else if (g?.spentUsd != null) parts.push(`${usd(g.spentUsd)} spent`);
4837
4879
  if (g?.dailyUsd != null) parts.push(`${usd(g.todayUsd)} of ${usd(g.dailyUsd)} today`);
4838
- return parts.join(" · ");
4880
+ return parts.join(" · ") + tail;
4839
4881
  }
4840
4882
 
4841
4883
  /** A dollar limit from a flag: above 0, at most 100000 (what the platform takes). */
@@ -4879,7 +4921,11 @@ async function keysCreateGateway(url, label, flags) {
4879
4921
  console.log(` ${c.dim("Shown once. Point Claude Code at it:")}\n`);
4880
4922
  console.log(` export ANTHROPIC_BASE_URL=${base}`);
4881
4923
  console.log(` export ANTHROPIC_API_KEY=<key>\n`);
4882
- console.log(` ${c.dim(`It opens the gateway only. \`foldrun keys ls\` shows what it has spent; \`foldrun keys revoke ${made.id}\` ends it.`)}\n`);
4924
+ // A login key is not metered: there is no spend for `keys ls` to show.
4925
+ const after = made.credential === "login"
4926
+ ? `It opens the gateway only and runs on the operator's Claude login, not metered — it shares that subscription's weekly cap with the desks. \`foldrun keys revoke ${made.id}\` ends it.`
4927
+ : `It opens the gateway only. \`foldrun keys ls\` shows what it has spent; \`foldrun keys revoke ${made.id}\` ends it.`;
4928
+ console.log(` ${c.dim(after)}\n`);
4883
4929
  return 0;
4884
4930
  }
4885
4931
 
@@ -5876,6 +5922,35 @@ async function workspacesCmd(positional, flags, layout) {
5876
5922
  return 0;
5877
5923
  }
5878
5924
 
5925
+ /**
5926
+ * Whether a stored sign-in still works: one GET /api/me with its key, all
5927
+ * at once, a few seconds each. `refused`: the platform answered and said no
5928
+ * (a revoked, expired or unknown key, an account that is gone). `unreachable`:
5929
+ * nothing answered (an install that is down, a laptop offline, a 5xx).
5930
+ * @typedef {{ ok: boolean, why: "refused" | "unreachable" | null, detail: string }} SignInStatus
5931
+ * @returns {Promise<SignInStatus>}
5932
+ */
5933
+ async function signInWorks(p, seconds = 6) {
5934
+ if (!p.token || !p.url) return { ok: false, why: "refused", detail: "no key stored" };
5935
+ /** @type {(why: "refused" | "unreachable", detail: string) => SignInStatus} */
5936
+ const fail = (why, detail) => ({ ok: false, why, detail });
5937
+ try {
5938
+ // Resolved as remoteFetch resolves every call (against the origin), so
5939
+ // the check asks the endpoint real commands use (Codex review).
5940
+ const res = await fetch(new URL("/api/me", p.url), {
5941
+ headers: { authorization: `Bearer ${p.token}`, "user-agent": `foldrun-cli/${CLI_VERSION}` },
5942
+ signal: AbortSignal.timeout(seconds * 1000),
5943
+ });
5944
+ await res.body?.cancel().catch(() => {});
5945
+ if (res.ok) return { ok: true, why: null, detail: "" };
5946
+ if (res.status === 401 || res.status === 403) return fail("refused", `${res.status} — the key no longer works`);
5947
+ return fail("unreachable", `the platform answered ${res.status}`);
5948
+ } catch (err) {
5949
+ const timedOut = err && typeof err === "object" && "name" in err && err.name === "TimeoutError";
5950
+ return fail("unreachable", timedOut ? `no answer in ${seconds}s` : "could not reach it");
5951
+ }
5952
+ }
5953
+
5879
5954
  /**
5880
5955
  * `foldrun accounts` — every account this machine is signed in to, and
5881
5956
  * which one a bare command talks as. `foldrun use <name>` switches.
@@ -5883,21 +5958,64 @@ async function workspacesCmd(positional, flags, layout) {
5883
5958
  * The list is the point: someone looking after four customers on one
5884
5959
  * platform could see only the last one they signed in as, and had to paste
5885
5960
  * --token to reach the others.
5886
- */
5887
- function accountsCmd(positional) {
5961
+ *
5962
+ * Only sign-ins that still work are listed (owner, 10 Nov 2026): each is
5963
+ * asked once (GET /api/me), and one whose key is refused or whose platform
5964
+ * does not answer is left out — counted in one line, so the stale keys in
5965
+ * the file are never silently forgotten. The active one is always shown,
5966
+ * marked when it fails, since every bare command uses it. `--all` lists
5967
+ * every one with what it answered; `prune` removes the refused ones
5968
+ * (`--unreachable` too: those that did not answer).
5969
+ */
5970
+ async function accountsCmd(positional, flags = {}) {
5888
5971
  const profiles = listProfiles();
5889
5972
  if (!profiles.length) {
5890
5973
  console.log(`\n ${c.dim("not signed in anywhere — `foldrun login`")}\n`);
5891
5974
  return 0;
5892
5975
  }
5893
5976
  const verb = positional[0];
5894
- if (verb && verb !== "ls" && verb !== "list") throw new Error(`accounts: unknown verb "${verb}" — it takes none; \`foldrun use <name>\` switches`);
5895
- const width = Math.max(...profiles.map((p) => p.name.length));
5977
+ if (verb && verb !== "ls" && verb !== "list" && verb !== "prune") throw new Error(`accounts: unknown verb "${verb}" — ls (the default) or prune; \`foldrun use <name>\` switches`);
5978
+ const checks = await Promise.all(profiles.map((p) => signInWorks(p)));
5979
+ /** @type {(p: { name: string }) => SignInStatus} */
5980
+ const statusOf = (p) => checks[profiles.findIndex((x) => x.name === p.name)] ?? { ok: false, why: "unreachable", detail: "not asked" };
5981
+
5982
+ if (verb === "prune") {
5983
+ const gone = profiles.filter((p) => {
5984
+ const s = statusOf(p);
5985
+ return !s.ok && (s.why === "refused" || (flags.unreachable === true && s.why === "unreachable"));
5986
+ });
5987
+ if (!gone.length) {
5988
+ console.log(`\n ${c.dim(`nothing to remove — every saved sign-in works${flags.unreachable === true ? " or was not asked to go" : " (or only did not answer: --unreachable removes those)"}`)}\n`);
5989
+ return 0;
5990
+ }
5991
+ const what = `${gone.length} saved sign-in${gone.length === 1 ? "" : "s"} on this machine (${gone.map((p) => p.name).join(", ")}) — their keys stay wherever else they are; only this machine forgets them`;
5992
+ if (!(await sureToDelete(flags, "accounts prune", what))) return 1;
5993
+ for (const p of gone) removeCredential(p.name);
5994
+ console.log(`\n ${c.green("✓")} removed ${gone.map((p) => c.bold(p.name)).join(", ")}\n`);
5995
+ return 0;
5996
+ }
5997
+
5998
+ const all = flags.all === true;
5999
+ const shown = profiles.filter((p) => all || p.current || statusOf(p).ok);
6000
+ const hidden = profiles.filter((p) => !shown.includes(p));
6001
+ const width = Math.max(...shown.map((p) => p.name.length));
5896
6002
  console.log("");
5897
- for (const p of profiles) {
5898
- const mark = p.current ? c.green("●") : " ";
6003
+ for (const p of shown) {
6004
+ const s = statusOf(p);
6005
+ const mark = p.current ? (s.ok ? c.green("●") : c.red("●")) : " ";
5899
6006
  const who = p.email ?? c.dim("api key");
5900
- console.log(` ${mark} ${c.bold(p.name.padEnd(width))} ${p.account} ${c.dim(`${p.role ?? "?"} · ${who} · ${p.url}`)}`);
6007
+ const state = s.ok ? "" : ` ${c.red(s.why === "refused" ? "sign-in no longer works" : "platform not answering")} ${c.dim(`(${s.detail})`)}`;
6008
+ console.log(` ${mark} ${c.bold(p.name.padEnd(width))} ${p.account} ${c.dim(`${p.role ?? "?"} · ${who} · ${p.url}`)}${state}`);
6009
+ }
6010
+ const current = profiles.find((p) => p.current);
6011
+ if (current && !statusOf(current).ok) {
6012
+ console.log(`\n ${c.amber("!")} ${c.dim(`the active one, ${current.name}, does not work: \`foldrun login\` again, or \`foldrun use <name>\` another`)}`);
6013
+ }
6014
+ if (hidden.length) {
6015
+ const refused = hidden.filter((p) => statusOf(p).why === "refused").length;
6016
+ const away = hidden.length - refused;
6017
+ const parts = [refused ? `${refused} no longer work${refused === 1 ? "s" : ""}` : "", away ? `${away} did not answer` : ""].filter(Boolean).join(", ");
6018
+ console.log(`\n ${c.dim(`${hidden.length} more saved sign-in${hidden.length === 1 ? "" : "s"} not shown (${parts}) — \`foldrun accounts --all\` lists them, \`foldrun accounts prune\` removes the ones that no longer work.`)}`);
5901
6019
  }
5902
6020
  console.log(`\n ${c.dim("● is the one a bare command talks as. `foldrun use <name>` switches; --profile <name> is one command.")}\n`);
5903
6021
  return 0;
@@ -14713,7 +14831,7 @@ export async function run(command, positional, flags, workspace, layout) {
14713
14831
  return auditCmd(positional, flags);
14714
14832
  case "accounts":
14715
14833
  case "profiles":
14716
- return accountsCmd(positional);
14834
+ return accountsCmd(positional, flags);
14717
14835
  case "use":
14718
14836
  case "switch":
14719
14837
  return useCmd(positional);