foldrun 20.1.0 → 20.3.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 +3 -1
- package/docs/api.md +1 -1
- package/docs/claude-code.md +26 -3
- package/docs/cli.md +2 -2
- package/package.json +1 -1
- package/src/commands.mjs +90 -12
package/bin/foldrun.mjs
CHANGED
|
@@ -300,6 +300,7 @@ 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
|
|
@@ -454,6 +455,7 @@ Options
|
|
|
454
455
|
--a2a keys create: an A2A key for an outside agent — with --to <workspace> and --flows a,b; --max-tasks <n> caps its open tasks (1–100, default 10)
|
|
455
456
|
--gateway keys create: a gateway key for Claude Code — with --cap <usd> (in all) and/or --daily <usd> (per UTC day)
|
|
456
457
|
--cap <usd>, --daily <usd> keys create --gateway: the key's own spending limits, $0.01–$100000
|
|
458
|
+
--login keys create --gateway: on the operator's Claude login instead (the operator's own accounts; not metered, no limits)
|
|
457
459
|
--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
|
|
458
460
|
--card <url> a2a status, a2a cancel: the agent card of the agent that holds the task
|
|
459
461
|
|
|
@@ -498,7 +500,7 @@ if (!command || command === "--help" || command === "-h") {
|
|
|
498
500
|
// `--value` as the account's argument and stored an empty secret; `--force
|
|
499
501
|
// ./dir` swallowed the directory. A flag followed by another flag is also
|
|
500
502
|
// boolean, so an unlisted switch at least does not eat its neighbour.
|
|
501
|
-
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", "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
|
+
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"]);
|
|
502
504
|
// Flags said more than once collect into a list: `--tag a --tag b`.
|
|
503
505
|
const REPEATABLE = new Set(["tag", "expect", "header", "site", "add", "remove", "rule", "authorize-param", "example", "accept-risk"]);
|
|
504
506
|
// `--wait` is a switch everywhere but `flow add <flow> wait`, where it takes
|
package/docs/api.md
CHANGED
|
@@ -366,7 +366,7 @@ 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. 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. 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
370
|
| `/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
371
|
| `/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
372
|
| `/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 |
|
package/docs/claude-code.md
CHANGED
|
@@ -28,9 +28,8 @@ foldrun keys create laptop --gateway --cap 20 --daily 5
|
|
|
28
28
|
- **A limit of its own is required:** `--cap` (USD, in all) or `--daily`
|
|
29
29
|
(USD, per UTC day), or both — from $0.01 to $100,000.
|
|
30
30
|
Limits are in dollars charged — what the account pays at foldrun's price
|
|
31
|
-
list — and so is the spend `keys ls` shows.
|
|
32
|
-
|
|
33
|
-
new one.
|
|
31
|
+
list — and so is the spend `keys ls` shows. Each call is kept at the
|
|
32
|
+
margin it was charged at, so a margin changed later re-prices nothing.
|
|
34
33
|
- **Who may mint one:** an admin of every workspace. The key spends the
|
|
35
34
|
whole account's balance, so a workspace-scoped admin cannot.
|
|
36
35
|
- **What it opens:** the gateway only. Every `/api` route refuses it (403),
|
|
@@ -43,6 +42,30 @@ foldrun keys create laptop --gateway --cap 20 --daily 5
|
|
|
43
42
|
The API is `POST /api/keys { purpose: "gateway", capUsd?, dailyUsd?, label?, expires? }`
|
|
44
43
|
([API](api.md)).
|
|
45
44
|
|
|
45
|
+
## On the operator's Claude login
|
|
46
|
+
|
|
47
|
+
An account the operator allows its own model credential — the one its desks
|
|
48
|
+
run on — may mint a gateway key on the operator's Claude login instead:
|
|
49
|
+
|
|
50
|
+
```sh
|
|
51
|
+
foldrun keys create mine --gateway --login
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
or **Runs on → The operator's Claude login** on Settings → API keys (shown
|
|
55
|
+
only on such an account). Such a key:
|
|
56
|
+
|
|
57
|
+
- sends the operator's Claude login to Anthropic, read fresh on every call,
|
|
58
|
+
so the platform's token refresh reaches it with no restart;
|
|
59
|
+
- is **not metered or billed** and takes no `--cap` or `--daily` — the
|
|
60
|
+
login is a flat-rate subscription, so there is no dollar figure to hold;
|
|
61
|
+
- shares that subscription's weekly cap with the account's desks: a long
|
|
62
|
+
coding session can leave the desks out of their window until it resets;
|
|
63
|
+
- opens nothing once the account is no longer allowed the credential: the
|
|
64
|
+
gateway asks on every call.
|
|
65
|
+
|
|
66
|
+
It is for the operator's own use. A subscription's terms are its owner's to
|
|
67
|
+
keep; foldrun's models (the rest of this page) are what to give anyone else.
|
|
68
|
+
|
|
46
69
|
## What the gateway serves
|
|
47
70
|
|
|
48
71
|
| Route | |
|
package/docs/cli.md
CHANGED
|
@@ -203,7 +203,7 @@ 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 |
|
|
@@ -314,7 +314,7 @@ claude.ai or Claude Code there, nor any MCP configuration on disk.
|
|
|
314
314
|
| `--expires <span>` | `keys create`: when it stops working — `30d`, `90d` (the default, as in the dashboard; before CLI 15.0.0 the default was never), `365d` or `never`; `--forever` is `never` |
|
|
315
315
|
| `--grace <span>` | `keys rotate`: keep the old key working for `1h` or `24h` (default `0`: revoked now) |
|
|
316
316
|
| `--a2a` | `keys create`: an A2A key for an outside agent, with `--to <workspace>`, `--flows a,b` and optionally `--max-tasks <n>` |
|
|
317
|
-
| `--gateway` | `keys create`: a gateway key for Claude Code, with `--cap <usd>` and/or `--daily <usd>` |
|
|
317
|
+
| `--gateway` | `keys create`: a gateway key for Claude Code, with `--cap <usd>` and/or `--daily <usd>` — or `--login` (the operator's Claude login, on the operator's own accounts; not metered, no limits) |
|
|
318
318
|
| `--key-env <NAME>` | `a2a call`, `a2a status`, `a2a cancel`, `a2a card`: the environment variable that holds the A2A key (default `FOLDRUN_A2A_KEY`) |
|
|
319
319
|
| `--card <url>` | `a2a status`, `a2a cancel`: the agent card of the agent that holds the task |
|
|
320
320
|
| `--force` | `deploy`: deploy while runs are in flight. `pull`, `storage get`: overwrite local files |
|
package/package.json
CHANGED
package/src/commands.mjs
CHANGED
|
@@ -4696,6 +4696,7 @@ async function doctor(flags) {
|
|
|
4696
4696
|
* keys create <label> --expires 90d it stops working in 90 days (30d, 365d, never)
|
|
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
|
+
* keys create <label> --gateway --login on the operator's Claude login (its own accounts): not metered
|
|
4699
4700
|
* keys rotate <id> [--grace 1h] a new key, same label/role/scope; the old
|
|
4700
4701
|
* one ends now, or when the grace runs out.
|
|
4701
4702
|
* A key already rotated is refused (409):
|
|
@@ -4828,6 +4829,7 @@ async function keysCreateA2a(url, label, flags) {
|
|
|
4828
4829
|
|
|
4829
4830
|
/** How `keys ls` describes a gateway key: its limits, and what it has spent. */
|
|
4830
4831
|
function gatewayLine(g) {
|
|
4832
|
+
if (g?.credential === "login") return "gateway · Claude Code · the operator's Claude login · not metered";
|
|
4831
4833
|
const usd = (n) => `$${Number(n ?? 0).toFixed(2)}`;
|
|
4832
4834
|
const parts = ["gateway · Claude Code"];
|
|
4833
4835
|
if (g?.capUsd != null) parts.push(`${usd(g.spentUsd)} of ${usd(g.capUsd)}`);
|
|
@@ -4855,10 +4857,14 @@ async function keysCreateGateway(url, label, flags) {
|
|
|
4855
4857
|
if (flags.role !== undefined || flags.workspaces !== undefined || flags.to !== undefined || flags.flows !== undefined) {
|
|
4856
4858
|
throw new Error("a gateway key takes --cap and --daily, not --role, --workspaces, --to or --flows — it opens the gateway only, never the API");
|
|
4857
4859
|
}
|
|
4858
|
-
|
|
4859
|
-
|
|
4860
|
-
if (
|
|
4860
|
+
// --login: the operator's own Claude login, for an account the operator
|
|
4861
|
+
// allows it (its desks' accounts) — not metered, so it takes no limit.
|
|
4862
|
+
if (flags.login === true && (flags.cap !== undefined || flags.daily !== undefined)) throw new Error("--login takes no --cap or --daily — the operator's Claude login is not metered, so a dollar limit could not hold it");
|
|
4863
|
+
const capUsd = flags.login === true ? undefined : usdFlag(flags.cap, "--cap");
|
|
4864
|
+
const dailyUsd = flags.login === true ? undefined : usdFlag(flags.daily, "--daily");
|
|
4865
|
+
if (flags.login !== true && capUsd === undefined && dailyUsd === undefined) throw new Error("a gateway key needs a limit of its own: --cap <usd> in all, or --daily <usd> per UTC day (or both) — or --login, on an account the operator's Claude login is for");
|
|
4861
4866
|
const body = { label, purpose: "gateway" };
|
|
4867
|
+
if (flags.login === true) body.credential = "login";
|
|
4862
4868
|
if (capUsd !== undefined) body.capUsd = capUsd;
|
|
4863
4869
|
if (dailyUsd !== undefined) body.dailyUsd = dailyUsd;
|
|
4864
4870
|
if (flags.forever === true && flags.expires !== undefined) throw new Error("--forever or --expires <span>, not both");
|
|
@@ -4866,7 +4872,7 @@ async function keysCreateGateway(url, label, flags) {
|
|
|
4866
4872
|
if (flags.expires !== undefined && typeof flags.expires !== "string") throw new Error("--expires needs a span: 30d, 90d, 365d or never");
|
|
4867
4873
|
body.expires = flags.forever === true ? "never" : typeof flags.expires === "string" ? flags.expires : "90d";
|
|
4868
4874
|
const made = await remoteCall(url, flags, "/api/keys", { method: "POST", body: JSON.stringify(body) });
|
|
4869
|
-
console.log(`\n ${c.green("✓")} ${c.bold(label)} ${c.dim(made.id)} ${c.dim(gatewayLine({ capUsd: made.capUsd ?? null, dailyUsd: made.dailyUsd ?? null, spentUsd: 0, todayUsd: 0 }))}${made.expiresAt ? c.dim(` expires ${made.expiresAt.slice(0, 10)}`) : ""}\n`);
|
|
4875
|
+
console.log(`\n ${c.green("✓")} ${c.bold(label)} ${c.dim(made.id)} ${c.dim(gatewayLine({ capUsd: made.capUsd ?? null, dailyUsd: made.dailyUsd ?? null, spentUsd: 0, todayUsd: 0, credential: made.credential }))}${made.expiresAt ? c.dim(` expires ${made.expiresAt.slice(0, 10)}`) : ""}\n`);
|
|
4870
4876
|
if (made.key == null) return lostSecret(made.id);
|
|
4871
4877
|
console.log(` ${made.key}\n`);
|
|
4872
4878
|
const base = made.gatewayUrl ?? "<the gateway URL — not set on this platform yet>";
|
|
@@ -5870,6 +5876,35 @@ async function workspacesCmd(positional, flags, layout) {
|
|
|
5870
5876
|
return 0;
|
|
5871
5877
|
}
|
|
5872
5878
|
|
|
5879
|
+
/**
|
|
5880
|
+
* Whether a stored sign-in still works: one GET /api/me with its key, all
|
|
5881
|
+
* at once, a few seconds each. `refused`: the platform answered and said no
|
|
5882
|
+
* (a revoked, expired or unknown key, an account that is gone). `unreachable`:
|
|
5883
|
+
* nothing answered (an install that is down, a laptop offline, a 5xx).
|
|
5884
|
+
* @typedef {{ ok: boolean, why: "refused" | "unreachable" | null, detail: string }} SignInStatus
|
|
5885
|
+
* @returns {Promise<SignInStatus>}
|
|
5886
|
+
*/
|
|
5887
|
+
async function signInWorks(p, seconds = 6) {
|
|
5888
|
+
if (!p.token || !p.url) return { ok: false, why: "refused", detail: "no key stored" };
|
|
5889
|
+
/** @type {(why: "refused" | "unreachable", detail: string) => SignInStatus} */
|
|
5890
|
+
const fail = (why, detail) => ({ ok: false, why, detail });
|
|
5891
|
+
try {
|
|
5892
|
+
// Resolved as remoteFetch resolves every call (against the origin), so
|
|
5893
|
+
// the check asks the endpoint real commands use (Codex review).
|
|
5894
|
+
const res = await fetch(new URL("/api/me", p.url), {
|
|
5895
|
+
headers: { authorization: `Bearer ${p.token}`, "user-agent": `foldrun-cli/${CLI_VERSION}` },
|
|
5896
|
+
signal: AbortSignal.timeout(seconds * 1000),
|
|
5897
|
+
});
|
|
5898
|
+
await res.body?.cancel().catch(() => {});
|
|
5899
|
+
if (res.ok) return { ok: true, why: null, detail: "" };
|
|
5900
|
+
if (res.status === 401 || res.status === 403) return fail("refused", `${res.status} — the key no longer works`);
|
|
5901
|
+
return fail("unreachable", `the platform answered ${res.status}`);
|
|
5902
|
+
} catch (err) {
|
|
5903
|
+
const timedOut = err && typeof err === "object" && "name" in err && err.name === "TimeoutError";
|
|
5904
|
+
return fail("unreachable", timedOut ? `no answer in ${seconds}s` : "could not reach it");
|
|
5905
|
+
}
|
|
5906
|
+
}
|
|
5907
|
+
|
|
5873
5908
|
/**
|
|
5874
5909
|
* `foldrun accounts` — every account this machine is signed in to, and
|
|
5875
5910
|
* which one a bare command talks as. `foldrun use <name>` switches.
|
|
@@ -5877,21 +5912,64 @@ async function workspacesCmd(positional, flags, layout) {
|
|
|
5877
5912
|
* The list is the point: someone looking after four customers on one
|
|
5878
5913
|
* platform could see only the last one they signed in as, and had to paste
|
|
5879
5914
|
* --token to reach the others.
|
|
5880
|
-
|
|
5881
|
-
|
|
5915
|
+
*
|
|
5916
|
+
* Only sign-ins that still work are listed (owner, 10 Nov 2026): each is
|
|
5917
|
+
* asked once (GET /api/me), and one whose key is refused or whose platform
|
|
5918
|
+
* does not answer is left out — counted in one line, so the stale keys in
|
|
5919
|
+
* the file are never silently forgotten. The active one is always shown,
|
|
5920
|
+
* marked when it fails, since every bare command uses it. `--all` lists
|
|
5921
|
+
* every one with what it answered; `prune` removes the refused ones
|
|
5922
|
+
* (`--unreachable` too: those that did not answer).
|
|
5923
|
+
*/
|
|
5924
|
+
async function accountsCmd(positional, flags = {}) {
|
|
5882
5925
|
const profiles = listProfiles();
|
|
5883
5926
|
if (!profiles.length) {
|
|
5884
5927
|
console.log(`\n ${c.dim("not signed in anywhere — `foldrun login`")}\n`);
|
|
5885
5928
|
return 0;
|
|
5886
5929
|
}
|
|
5887
5930
|
const verb = positional[0];
|
|
5888
|
-
if (verb && verb !== "ls" && verb !== "list") throw new Error(`accounts: unknown verb "${verb}" —
|
|
5889
|
-
const
|
|
5931
|
+
if (verb && verb !== "ls" && verb !== "list" && verb !== "prune") throw new Error(`accounts: unknown verb "${verb}" — ls (the default) or prune; \`foldrun use <name>\` switches`);
|
|
5932
|
+
const checks = await Promise.all(profiles.map((p) => signInWorks(p)));
|
|
5933
|
+
/** @type {(p: { name: string }) => SignInStatus} */
|
|
5934
|
+
const statusOf = (p) => checks[profiles.findIndex((x) => x.name === p.name)] ?? { ok: false, why: "unreachable", detail: "not asked" };
|
|
5935
|
+
|
|
5936
|
+
if (verb === "prune") {
|
|
5937
|
+
const gone = profiles.filter((p) => {
|
|
5938
|
+
const s = statusOf(p);
|
|
5939
|
+
return !s.ok && (s.why === "refused" || (flags.unreachable === true && s.why === "unreachable"));
|
|
5940
|
+
});
|
|
5941
|
+
if (!gone.length) {
|
|
5942
|
+
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`);
|
|
5943
|
+
return 0;
|
|
5944
|
+
}
|
|
5945
|
+
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`;
|
|
5946
|
+
if (!(await sureToDelete(flags, "accounts prune", what))) return 1;
|
|
5947
|
+
for (const p of gone) removeCredential(p.name);
|
|
5948
|
+
console.log(`\n ${c.green("✓")} removed ${gone.map((p) => c.bold(p.name)).join(", ")}\n`);
|
|
5949
|
+
return 0;
|
|
5950
|
+
}
|
|
5951
|
+
|
|
5952
|
+
const all = flags.all === true;
|
|
5953
|
+
const shown = profiles.filter((p) => all || p.current || statusOf(p).ok);
|
|
5954
|
+
const hidden = profiles.filter((p) => !shown.includes(p));
|
|
5955
|
+
const width = Math.max(...shown.map((p) => p.name.length));
|
|
5890
5956
|
console.log("");
|
|
5891
|
-
for (const p of
|
|
5892
|
-
const
|
|
5957
|
+
for (const p of shown) {
|
|
5958
|
+
const s = statusOf(p);
|
|
5959
|
+
const mark = p.current ? (s.ok ? c.green("●") : c.red("●")) : " ";
|
|
5893
5960
|
const who = p.email ?? c.dim("api key");
|
|
5894
|
-
|
|
5961
|
+
const state = s.ok ? "" : ` ${c.red(s.why === "refused" ? "sign-in no longer works" : "platform not answering")} ${c.dim(`(${s.detail})`)}`;
|
|
5962
|
+
console.log(` ${mark} ${c.bold(p.name.padEnd(width))} ${p.account} ${c.dim(`${p.role ?? "?"} · ${who} · ${p.url}`)}${state}`);
|
|
5963
|
+
}
|
|
5964
|
+
const current = profiles.find((p) => p.current);
|
|
5965
|
+
if (current && !statusOf(current).ok) {
|
|
5966
|
+
console.log(`\n ${c.amber("!")} ${c.dim(`the active one, ${current.name}, does not work: \`foldrun login\` again, or \`foldrun use <name>\` another`)}`);
|
|
5967
|
+
}
|
|
5968
|
+
if (hidden.length) {
|
|
5969
|
+
const refused = hidden.filter((p) => statusOf(p).why === "refused").length;
|
|
5970
|
+
const away = hidden.length - refused;
|
|
5971
|
+
const parts = [refused ? `${refused} no longer work${refused === 1 ? "s" : ""}` : "", away ? `${away} did not answer` : ""].filter(Boolean).join(", ");
|
|
5972
|
+
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.`)}`);
|
|
5895
5973
|
}
|
|
5896
5974
|
console.log(`\n ${c.dim("● is the one a bare command talks as. `foldrun use <name>` switches; --profile <name> is one command.")}\n`);
|
|
5897
5975
|
return 0;
|
|
@@ -14707,7 +14785,7 @@ export async function run(command, positional, flags, workspace, layout) {
|
|
|
14707
14785
|
return auditCmd(positional, flags);
|
|
14708
14786
|
case "accounts":
|
|
14709
14787
|
case "profiles":
|
|
14710
|
-
return accountsCmd(positional);
|
|
14788
|
+
return accountsCmd(positional, flags);
|
|
14711
14789
|
case "use":
|
|
14712
14790
|
case "switch":
|
|
14713
14791
|
return useCmd(positional);
|