@aragon-agent/cli 0.6.70 → 0.6.72
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/CHANGELOG.md +20 -0
- package/README.md +33 -14
- package/dist/account/config.d.ts +61 -0
- package/dist/account/config.js +83 -0
- package/dist/account/device-client.d.ts +113 -0
- package/dist/account/device-client.js +425 -0
- package/dist/account/format.d.ts +51 -0
- package/dist/account/format.js +102 -0
- package/dist/account/login-flow.d.ts +68 -0
- package/dist/account/login-flow.js +305 -0
- package/dist/account/session.d.ts +62 -0
- package/dist/account/session.js +63 -0
- package/dist/account/store.d.ts +86 -0
- package/dist/account/store.js +231 -0
- package/dist/agent/controller.d.ts +25 -1
- package/dist/agent/controller.js +78 -3
- package/dist/agent/project-guidance-prompt.js +97 -97
- package/dist/app/App.d.ts +12 -3
- package/dist/app/App.js +216 -3
- package/dist/cli.js +2 -2
- package/dist/commands/account-command.d.ts +86 -0
- package/dist/commands/account-command.js +165 -0
- package/dist/commands/builtins.js +15 -0
- package/dist/commands/catalog.js +17 -1
- package/dist/config/app-paths.d.ts +15 -0
- package/dist/config/app-paths.js +17 -0
- package/dist/config/cli-commands.d.ts +1 -1
- package/dist/config/cli-commands.js +4 -0
- package/dist/config/env.js +6 -0
- package/dist/config/load.js +36 -1
- package/dist/governance/engine/lifecycle.js +1 -1
- package/dist/governance/prompts/orchestrator-block.js +3 -3
- package/dist/host/controller-factory.d.ts +15 -0
- package/dist/host/controller-factory.js +10 -2
- package/dist/host/memory.d.ts +5 -1
- package/dist/host/memory.js +13 -0
- package/dist/memory/block.d.ts +38 -4
- package/dist/memory/block.js +52 -5
- package/dist/memory/command.js +56 -2
- package/dist/memory/journal.d.ts +58 -0
- package/dist/memory/journal.js +202 -0
- package/dist/memory/ledger.d.ts +54 -0
- package/dist/memory/ledger.js +105 -0
- package/dist/memory/paths.d.ts +10 -0
- package/dist/memory/paths.js +31 -0
- package/dist/memory/service.d.ts +54 -1
- package/dist/memory/service.js +156 -1
- package/dist/memory/store.d.ts +21 -3
- package/dist/memory/store.js +66 -6
- package/dist/memory/tools-batch.d.ts +27 -0
- package/dist/memory/tools-batch.js +462 -0
- package/dist/memory/tools-shared.d.ts +176 -0
- package/dist/memory/tools-shared.js +305 -0
- package/dist/memory/tools.d.ts +19 -28
- package/dist/memory/tools.js +148 -228
- package/dist/memory/undo.d.ts +53 -0
- package/dist/memory/undo.js +173 -0
- package/dist/redteam/prompt-template.js +16 -16
- package/dist/tools/index.d.ts +2 -2
- package/dist/tools/index.js +16 -1
- package/package.json +3 -3
- package/runtime/insecure-tls-warning.cjs +62 -62
- package/runtime/insecure-tls-warning.d.cts +5 -5
- package/skills/project-indexer/templates/artifact-hygiene-template.md +14 -14
package/CHANGELOG.md
CHANGED
|
@@ -135,6 +135,26 @@ were written.
|
|
|
135
135
|
|
|
136
136
|
### Added
|
|
137
137
|
|
|
138
|
+
- **Agent memory writes are autonomous by default: one approval for a bulk change, a journal and undo for
|
|
139
|
+
everything else.** `memory.agentWrites` now defaults to `auto`, so a small change is applied on the
|
|
140
|
+
model's own hand instead of waiting behind a preview card. Three things make that safe rather than
|
|
141
|
+
silent. Every write appends a line to a journal in the memory directory, so `/memory undo [n|batch]`
|
|
142
|
+
restores the previous version of each note and `/memory activity [n]` (the manager's `t` page) can say
|
|
143
|
+
what changed; and each write leaves one receipt line in the transcript. The policy still asks whenever
|
|
144
|
+
the change is not small: one request touching at least `memory.bulkThreshold` notes, a note **you**
|
|
145
|
+
wrote yourself, a turn that has used `memory.autoWritesPerTurn`, a rolling 24 hours that has used
|
|
146
|
+
`memory.autoWritesPerDay`, or one note rewritten again and again. The card's second line is always
|
|
147
|
+
`Why:`, and approving one batch does not raise the 24-hour ceiling. New keys:
|
|
148
|
+
`memory.autoWritesPerTurn` (3, 1-20), `memory.autoWritesPerDay` (20, 1-200, rebuilt from the journal so a
|
|
149
|
+
restart does not reset it), `memory.bulkThreshold` (5, 2-20) and `memory.protectUserNotes` (true). New
|
|
150
|
+
tool `memory_batch` changes up to 20 notes under **one** approval: every op is validated first and
|
|
151
|
+
nothing is written unless the whole plan is valid; it is blocked in plan mode and for a governed
|
|
152
|
+
orchestrator, and it joins `HOST_TOOL_NAMES` / `MEMORY_TOOL_NAMES`. An unrecognised `agentWrites` value
|
|
153
|
+
still falls back to `ask` - a typo is never the way you end up with the looser policy. **Migration:** an
|
|
154
|
+
existing configuration is migrated once, on the next launch - `agentWrites: ask` becomes `auto` with an
|
|
155
|
+
`autonomyMigrated` marker, and `off` is never widened. `aragon exec --input-format bridge` registers the
|
|
156
|
+
write tools; `-p` and bridgeless `exec` do not, and a write that needs a human and finds none returns
|
|
157
|
+
`approval_unavailable` without touching a file.
|
|
138
158
|
- **A governed run now has a ROUND BUDGET, and it can be auto.** A round is one failure-driven
|
|
139
159
|
repeat dispatch - a `fix` stage, or a `dev` stage that reworks a work package - so a clean pass
|
|
140
160
|
through dev / review / test / settle / integrate costs nothing. `governance.rounds` is either a
|
package/README.md
CHANGED
|
@@ -968,7 +968,7 @@ ignores them rather than rejecting the library):
|
|
|
968
968
|
| `/bg [list\|logs <id> [n]\|stop <id\|all>\|status]` | Background jobs (services and tasks): what is running, its log tail, and how to stop it. `list` is the default |
|
|
969
969
|
| `/update [status\|now\|skip\|off]` | Auto-update: what is running, what is available, where it came from, when it looks again. `now` forces a check past the throttle; `skip` declines the offered version until a newer one appears |
|
|
970
970
|
| `/prompts [manage\|list\|show <n\|title>\|add [title :: body]\|edit <n\|title>\|rm <n\|title> [--yes]\|move <n\|title> <to>\|favorite <n\|title>\|sort name\|recent\|favorite]` | Quick prompt library: `/prompts` opens the picker (Enter fills the draft, `Ctrl+Enter` fills and sends), `add`/`edit` open the editor. `<n\|title>` accepts a 1-based index, an exact title, or a unique title prefix; a repeated title is refused **with its candidates** rather than guessed |
|
|
971
|
-
| `/memory [list [words]\|show <ref>\|save [--global] <text>\|add [text]\|rm <ref>\|restore [ref]\|mount\|unmount\|reset <ref>\|auto on\|off\|reset\|agent ask\|auto\|reset\|path\|help]` (alias `/mem`) | Memory: `/memory` opens the manager. `<ref>` is a number from `list`, an id, an exact title or a unique id prefix; an ambiguous one is refused **with its candidates**. `list` never prints a note body. `rm` moves to a 30-day trash and `restore` undoes it |
|
|
971
|
+
| `/memory [list [words]\|show <ref>\|save [--global] <text>\|add [text]\|rm <ref>\|restore [ref]\|mount\|unmount\|reset <ref>\|auto on\|off\|reset\|agent ask\|auto\|reset\|undo [n\|batch]\|activity [n]\|path\|help]` (alias `/mem`) | Memory: `/memory` opens the manager. `<ref>` is a number from `list`, an id, an exact title or a unique id prefix; an ambiguous one is refused **with its candidates**. `list` never prints a note body. `rm` moves to a 30-day trash and `restore` undoes it. `undo [n\|batch]` takes back a whole batch the agent wrote, and `activity [n]` lists what changed recently (the same list as the manager's `t` page) |
|
|
972
972
|
| `/kit [list\|use <name\|current>]` | Agent kits: what is in effect and where it came from, the whole library with each preset's three connections, or apply one for **this session**. `/kit use current` releases it. Never writes the config file |
|
|
973
973
|
| `/theme <auto\|warm\|cool\|light>` | Switch the color theme live (persisted) |
|
|
974
974
|
| `/expand [n]` | Expand / collapse the n-th-from-last (default last) tool card |
|
|
@@ -996,7 +996,7 @@ completes, `Up` / `Down` moves the selection, `Esc` closes it.
|
|
|
996
996
|
| `Shift+Tab` | Cycle the posture `BUILD` -> `PLAN` -> `GOVERN` -> `PLAN+GOVERN` -> `BUILD` (two states when governance is unavailable or `governance.shiftTab` is off). Equivalent: `/plan`, `/gov`. On Windows this needs a console flag Node < 22.17 does not set; aragon sets it at startup — see [Requirements](#requirements) |
|
|
997
997
|
| `Ctrl+N` | The same toggle, over a channel no Windows console can swallow. Use it if `Shift+Tab` does nothing. Written `Ctrl+N` everywhere, never `^N` - `^N` is the header's line-offset chip |
|
|
998
998
|
| `Ctrl+P` | **Quick prompt library**: the manager - create, edit, delete, favourite and reorder your own prompts. See [Quick prompt library](#quick-prompt-library) |
|
|
999
|
-
| `Ctrl+M` / `Alt+M` | **Memory manager**: save, edit, search and mount the notes AragonAgent remembers across sessions. `Ctrl+M` is the same byte as `Enter` on a terminal without keyboard enhancement (Windows Terminal, kitty, iTerm2 and WezTerm have it), where it still submits the draft exactly as before - use `Alt+M` or `/memory` there. See [Memory](#memory) |
|
|
999
|
+
| `Ctrl+M` / `Alt+M` | **Memory manager**: save, edit, search and mount the notes AragonAgent remembers across sessions. `Ctrl+M` is the same byte as `Enter` on a terminal without keyboard enhancement (Windows Terminal, kitty, iTerm2 and WezTerm have it), where it still submits the draft exactly as before - use `Alt+M` or `/memory` there. `t` in the manager opens the activity page (what changed recently, one line each) and `u` on a row undoes that batch after a `y` - the same `/memory activity` / `/memory undo`. See [Memory](#memory) |
|
|
1000
1000
|
| `Ctrl+B` | **Agents board**: the details of a running dispatch. Left column lists every child (not just the five the roster fits), the right-hand sections show the selected child's state, turns, tools, tokens, files, mail, supervisor actions, retries, compaction, its current activity, its final answer or error, and the last 24 events. `Up` / `Down` change the child, `PgUp` / `PgDn` and the wheel page, `Esc` closes. The board survives the end of the dispatch - it freezes the last live snapshot and marks it `dispatch ended` - and opens after the fact from the session's own team card, where everything except the live-only sections (current activity, mail count, timeline) is still readable. Pressing `Ctrl+B` again, or `/agents`, opens and closes it |
|
|
1001
1001
|
| `Ctrl+I` | **Build the project index** (bundled `project-indexer` skill). Asks for confirmation, then writes `.claude-index/` and matching `CLAUDE.md` / `AGENTS.md`, including rules for results in `runs/` and temporary-file checks. On terminals without keyboard enhancement `Ctrl+I` is the Tab byte and completes input instead |
|
|
1002
1002
|
| `Ctrl+K` | **Agent kits**: pick a model preset — main / subagent / fast profile in one choice — for **this session only**. Nothing is written to the config file. `Current setup` (the first row) releases the preset and returns to the file's bindings. See [Agent kits](#agent-kits) |
|
|
@@ -1160,13 +1160,15 @@ survive across sessions, that you can search, edit by hand and choose to put in
|
|
|
1160
1160
|
- **`Ctrl+M`** (or `Alt+M`, or `/memory`) opens the manager. `Space` mounts a note into this session -
|
|
1161
1161
|
its **full text** goes into the agent's context - or takes it out again; `n` writes a new one, `Enter`
|
|
1162
1162
|
opens it, `e` edits, `d` deletes (to a 30-day trash), `p` pins, `x` disables, `a` flips auto-load for
|
|
1163
|
-
this session,
|
|
1163
|
+
this session, `t` opens the activity page (what changed recently; `u` there undoes a batch), `/` filters,
|
|
1164
|
+
`Tab` switches between all / global / project. The header shows how many
|
|
1164
1165
|
notes are in context and roughly how many tokens they cost. In the editor, `Ctrl+S` saves; `Tab` to the
|
|
1165
1166
|
`Save` row then `Enter` does exactly the same thing. A second `Esc` is needed to discard an edited
|
|
1166
1167
|
draft, and a half-typed note survives the agent asking you an unrelated question.
|
|
1167
|
-
- **
|
|
1168
|
-
|
|
1169
|
-
compacting, `/clear` and switching
|
|
1168
|
+
- **Your notes are saved only when you say so; the agent's writes are journalled and undoable.** A file
|
|
1169
|
+
appears when you press Save or type `/memory save`, or when the agent saves a small change under the
|
|
1170
|
+
default `memory.agentWrites: auto`. Opening the manager, chatting, compacting, `/clear` and switching
|
|
1171
|
+
models write nothing.
|
|
1170
1172
|
- **Two scopes.** *Global* notes follow you everywhere; *project* notes belong to the repository you are
|
|
1171
1173
|
in (keyed by its path and kept in your home directory - never inside the repository, so cloning a repo
|
|
1172
1174
|
cannot pre-load notes into your agent). Separate git worktrees are separate projects: put a note in
|
|
@@ -1177,11 +1179,19 @@ survive across sessions, that you can search, edit by hand and choose to put in
|
|
|
1177
1179
|
`memory_search` and `memory_read`, which return at most ten short rows or 6,000 characters per call.
|
|
1178
1180
|
A mounted note is always loaded in full; if the budget cannot hold it the manager says so rather than
|
|
1179
1181
|
cutting silently. A model window under 16k tokens turns auto-load off (you can still mount).
|
|
1180
|
-
- **The agent can use memory
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1182
|
+
- **The agent can use memory; it asks only when a change is large or personal.** `memory_search` /
|
|
1183
|
+
`memory_read` read; `memory_write` changes ONE note and `memory_batch` changes up to 20 in one request.
|
|
1184
|
+
Under the default `auto` a small change is applied on the model's own hand and leaves a one-line receipt;
|
|
1185
|
+
every write is journalled, so `/memory undo` takes it back. It still asks - one card, whose second line
|
|
1186
|
+
says why - when a request touches at least `memory.bulkThreshold` notes, when it would change a note you
|
|
1187
|
+
wrote yourself, when the turn or the rolling 24 hours is out of budget, when one note is being rewritten
|
|
1188
|
+
again and again, or when the mode is `ask`. `off` removes the tools. Approving one batch does not raise
|
|
1189
|
+
the 24-hour ceiling. Plan mode blocks both write tools; `Ctrl+M` still works there. The agent cannot save
|
|
1190
|
+
anything that looks like a credential, and notes are presented to it as **data, not instructions**.
|
|
1191
|
+
- **Seeing and undoing what it did.** `/memory activity [n]` lists the recent changes, one line each;
|
|
1192
|
+
`/memory undo [n|batch]` takes back a whole batch (no argument = the newest). In the manager, `t` opens
|
|
1193
|
+
the activity page and `u` undoes the selected batch after a `y`. The status bar's `w6/20` chip is writes
|
|
1194
|
+
used against the rolling 24-hour ceiling, and it disappears entirely rather than showing a bare count.
|
|
1185
1195
|
- **Plain files.** One Markdown file per note under `~/.aragon-agent/memory/` (`global/`, and
|
|
1186
1196
|
`projects/<name>-<hash>/`), `0600` on POSIX, with a small frontmatter. Edit them in any editor; a file
|
|
1187
1197
|
with no frontmatter is still read. Opening the manager never rewrites your files. Overwrites keep the
|
|
@@ -1200,13 +1210,22 @@ survive across sessions, that you can search, edit by hand and choose to put in
|
|
|
1200
1210
|
| --- | --- | --- |
|
|
1201
1211
|
| `memory.enabled` | `true` | `false` removes the tools, the prompt block and the keys. `/memory` stays registered and reports that memory is off. Turning it **on** needs a restart (the tools are registered at launch) |
|
|
1202
1212
|
| `memory.autoload` | `true` | Whether new sessions load the catalog and pinned notes. `/memory auto` and `a` change it for one session |
|
|
1203
|
-
| `memory.agentWrites` | `
|
|
1213
|
+
| `memory.agentWrites` | `auto` | `ask` / `auto` / `off`. The default applies a small change without asking and leaves a receipt; anything else (`banana`, `true`, `1`) becomes `ask` - a typo must never be the way you end up with the looser policy |
|
|
1214
|
+
| `memory.autoWritesPerTurn` | `3` | Automatic writes in one turn before the next one needs your approval (1-20) |
|
|
1215
|
+
| `memory.autoWritesPerDay` | `20` | Automatic writes in a rolling 24 hours (1-200). Rebuilt from the journal, so a restart does not reset it, and approving one batch does not raise it |
|
|
1216
|
+
| `memory.bulkThreshold` | `5` | One request touching this many notes is a bulk change and gets one approval card (2-20) |
|
|
1217
|
+
| `memory.protectUserNotes` | `true` | Changing or deleting a note you wrote yourself needs one approval |
|
|
1204
1218
|
| `memory.indexMaxChars` | `3200` | Catalog budget (800-8000). Non-ASCII characters count three times: Chinese is not cheaper than English |
|
|
1205
1219
|
| `memory.bodyBudgetChars` | `6000` | Auto-loaded text budget (0-16000); `0` loads no text automatically |
|
|
1206
1220
|
| `memory.perBodyMaxChars` | `2000` | Longest note auto-load takes whole (200-8000); the rest is read on demand |
|
|
1207
1221
|
|
|
1208
|
-
`ARAGON_MEMORY=0` (or `--no-memory`) is the kill switch; it can only turn memory **off**.
|
|
1209
|
-
`aragon exec`
|
|
1222
|
+
`ARAGON_MEMORY=0` (or `--no-memory`) is the kill switch; it can only turn memory **off**. `aragon -p` and
|
|
1223
|
+
`aragon exec` **without a bridge** never load memory and never register the tools. `aragon exec
|
|
1224
|
+
--input-format bridge` **does** register them - it deliberately does not set `neverPrompts` - which is
|
|
1225
|
+
exactly why a write that needs a human and finds none returns `approval_unavailable` and writes nothing:
|
|
1226
|
+
that branch is the only place "there is nobody to ask" is kept distinct from "assume yes". Subagents never
|
|
1227
|
+
get the tools either. An existing configuration is migrated once, on the next launch: `ask` becomes `auto`,
|
|
1228
|
+
and `off` is never widened.
|
|
1210
1229
|
|
|
1211
1230
|
## Gene Bank
|
|
1212
1231
|
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every URL and protocol constant the CLI's account layer needs, in one place.
|
|
3
|
+
*
|
|
4
|
+
* WHY A MODULE AND NOT LITERALS AT THE CALL SITES: the base URL is user-selectable
|
|
5
|
+
* (`ARAGON_WEB_URL`), and the device-flow constants are a contract with `apps/web`
|
|
6
|
+
* (C1 / C2). Two copies of `/api/device/token` is exactly the shape that lets a
|
|
7
|
+
* rename land in one of them and not the other, and the failure is a login that
|
|
8
|
+
* polls a 404 forever.
|
|
9
|
+
*
|
|
10
|
+
* THE BASE URL IS NEVER DERIVED FROM THE RESPONSE: the server tells us where to
|
|
11
|
+
* send the user (`verification_uri_complete`), but `baseUrl` stays what the user
|
|
12
|
+
* chose, and it is what gets written into `account.json` (C3), so `aragon whoami`
|
|
13
|
+
* can say which site issued the credential.
|
|
14
|
+
*
|
|
15
|
+
* ASCII ONLY - `src/account/**` renders text a user reads.
|
|
16
|
+
*/
|
|
17
|
+
/** Where the device flow talks when nobody says otherwise (spec section 1). */
|
|
18
|
+
export declare const DEFAULT_WEB_BASE_URL = "https://aragonagent.com";
|
|
19
|
+
/** RFC 8628 section 3.1: the client identifier the web side has allow-listed (C1). */
|
|
20
|
+
export declare const DEVICE_CLIENT_ID = "aragon-cli";
|
|
21
|
+
/** The only scope a device grant may request (C1). */
|
|
22
|
+
export declare const DEVICE_SCOPE = "account:read";
|
|
23
|
+
/** RFC 8628 section 3.4 grant type, verbatim: the server compares it byte for byte. */
|
|
24
|
+
export declare const DEVICE_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:device_code";
|
|
25
|
+
export declare const DEVICE_CODE_PATH = "/api/device/code";
|
|
26
|
+
export declare const DEVICE_TOKEN_PATH = "/api/device/token";
|
|
27
|
+
export declare const ACCOUNT_ME_PATH = "/api/v1/me";
|
|
28
|
+
/**
|
|
29
|
+
* Polling bounds.
|
|
30
|
+
*
|
|
31
|
+
* `MAX_POLL_INTERVAL_SECONDS` is the SAME 60 the web side caps its own interval
|
|
32
|
+
* at (`DEVICE_INTERVAL_MAX_SECONDS`), and it is not negotiable from this side: a
|
|
33
|
+
* client that waits less than the server asked gets `slow_down` forever, and a
|
|
34
|
+
* client that waits more than 60 s keeps a terminal idle for no reason.
|
|
35
|
+
*/
|
|
36
|
+
export declare const MIN_POLL_INTERVAL_SECONDS = 1;
|
|
37
|
+
export declare const MAX_POLL_INTERVAL_SECONDS = 60;
|
|
38
|
+
export declare const SLOW_DOWN_STEP_SECONDS = 5;
|
|
39
|
+
export declare const DEFAULT_POLL_INTERVAL_SECONDS = 5;
|
|
40
|
+
/**
|
|
41
|
+
* `https://host[:port][/path]` without a trailing slash, or `null` when `raw` is
|
|
42
|
+
* not an absolute http(s) URL.
|
|
43
|
+
*
|
|
44
|
+
* A TRAILING SLASH IS THE BUG THIS EXISTS FOR: `${base}/api/device/code` with a
|
|
45
|
+
* base of `https://x/` is `https://x//api/device/code`, which some servers 404
|
|
46
|
+
* and others rewrite, and neither failure says why. Query and fragment are
|
|
47
|
+
* dropped rather than rejected - they cannot be part of a base URL and a user
|
|
48
|
+
* who pasted one meant the origin.
|
|
49
|
+
*/
|
|
50
|
+
export declare function normaliseBaseUrl(raw: string | null | undefined): string | null;
|
|
51
|
+
/**
|
|
52
|
+
* `ARAGON_WEB_URL` -> the default. Never throws, never returns `''`.
|
|
53
|
+
*
|
|
54
|
+
* AN ILLEGAL VALUE FALLS BACK RATHER THAN FAILING: the alternative is a login
|
|
55
|
+
* command that refuses to start because of a typo in a shell profile, and the
|
|
56
|
+
* user has no way to tell that from "sign-in is down". The fallback is the
|
|
57
|
+
* public site, which is what an unset variable means anyway.
|
|
58
|
+
*/
|
|
59
|
+
export declare function resolveWebBaseUrl(env?: NodeJS.ProcessEnv): string;
|
|
60
|
+
/** `https://host/api/device/code`; `baseUrl` is expected to be normalised. */
|
|
61
|
+
export declare function apiUrl(baseUrl: string, path: string): string;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every URL and protocol constant the CLI's account layer needs, in one place.
|
|
3
|
+
*
|
|
4
|
+
* WHY A MODULE AND NOT LITERALS AT THE CALL SITES: the base URL is user-selectable
|
|
5
|
+
* (`ARAGON_WEB_URL`), and the device-flow constants are a contract with `apps/web`
|
|
6
|
+
* (C1 / C2). Two copies of `/api/device/token` is exactly the shape that lets a
|
|
7
|
+
* rename land in one of them and not the other, and the failure is a login that
|
|
8
|
+
* polls a 404 forever.
|
|
9
|
+
*
|
|
10
|
+
* THE BASE URL IS NEVER DERIVED FROM THE RESPONSE: the server tells us where to
|
|
11
|
+
* send the user (`verification_uri_complete`), but `baseUrl` stays what the user
|
|
12
|
+
* chose, and it is what gets written into `account.json` (C3), so `aragon whoami`
|
|
13
|
+
* can say which site issued the credential.
|
|
14
|
+
*
|
|
15
|
+
* ASCII ONLY - `src/account/**` renders text a user reads.
|
|
16
|
+
*/
|
|
17
|
+
import process from 'node:process';
|
|
18
|
+
/** Where the device flow talks when nobody says otherwise (spec section 1). */
|
|
19
|
+
export const DEFAULT_WEB_BASE_URL = 'https://aragonagent.com';
|
|
20
|
+
/** RFC 8628 section 3.1: the client identifier the web side has allow-listed (C1). */
|
|
21
|
+
export const DEVICE_CLIENT_ID = 'aragon-cli';
|
|
22
|
+
/** The only scope a device grant may request (C1). */
|
|
23
|
+
export const DEVICE_SCOPE = 'account:read';
|
|
24
|
+
/** RFC 8628 section 3.4 grant type, verbatim: the server compares it byte for byte. */
|
|
25
|
+
export const DEVICE_GRANT_TYPE = 'urn:ietf:params:oauth:grant-type:device_code';
|
|
26
|
+
export const DEVICE_CODE_PATH = '/api/device/code';
|
|
27
|
+
export const DEVICE_TOKEN_PATH = '/api/device/token';
|
|
28
|
+
export const ACCOUNT_ME_PATH = '/api/v1/me';
|
|
29
|
+
/**
|
|
30
|
+
* Polling bounds.
|
|
31
|
+
*
|
|
32
|
+
* `MAX_POLL_INTERVAL_SECONDS` is the SAME 60 the web side caps its own interval
|
|
33
|
+
* at (`DEVICE_INTERVAL_MAX_SECONDS`), and it is not negotiable from this side: a
|
|
34
|
+
* client that waits less than the server asked gets `slow_down` forever, and a
|
|
35
|
+
* client that waits more than 60 s keeps a terminal idle for no reason.
|
|
36
|
+
*/
|
|
37
|
+
export const MIN_POLL_INTERVAL_SECONDS = 1;
|
|
38
|
+
export const MAX_POLL_INTERVAL_SECONDS = 60;
|
|
39
|
+
export const SLOW_DOWN_STEP_SECONDS = 5;
|
|
40
|
+
export const DEFAULT_POLL_INTERVAL_SECONDS = 5;
|
|
41
|
+
/**
|
|
42
|
+
* `https://host[:port][/path]` without a trailing slash, or `null` when `raw` is
|
|
43
|
+
* not an absolute http(s) URL.
|
|
44
|
+
*
|
|
45
|
+
* A TRAILING SLASH IS THE BUG THIS EXISTS FOR: `${base}/api/device/code` with a
|
|
46
|
+
* base of `https://x/` is `https://x//api/device/code`, which some servers 404
|
|
47
|
+
* and others rewrite, and neither failure says why. Query and fragment are
|
|
48
|
+
* dropped rather than rejected - they cannot be part of a base URL and a user
|
|
49
|
+
* who pasted one meant the origin.
|
|
50
|
+
*/
|
|
51
|
+
export function normaliseBaseUrl(raw) {
|
|
52
|
+
const text = raw?.trim();
|
|
53
|
+
if (!text)
|
|
54
|
+
return null;
|
|
55
|
+
let url;
|
|
56
|
+
try {
|
|
57
|
+
url = new URL(text);
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
if (url.protocol !== 'https:' && url.protocol !== 'http:')
|
|
63
|
+
return null;
|
|
64
|
+
if (url.hostname.length === 0)
|
|
65
|
+
return null;
|
|
66
|
+
const path = url.pathname.replace(/\/+$/, '');
|
|
67
|
+
return `${url.protocol}//${url.host}${path}`;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* `ARAGON_WEB_URL` -> the default. Never throws, never returns `''`.
|
|
71
|
+
*
|
|
72
|
+
* AN ILLEGAL VALUE FALLS BACK RATHER THAN FAILING: the alternative is a login
|
|
73
|
+
* command that refuses to start because of a typo in a shell profile, and the
|
|
74
|
+
* user has no way to tell that from "sign-in is down". The fallback is the
|
|
75
|
+
* public site, which is what an unset variable means anyway.
|
|
76
|
+
*/
|
|
77
|
+
export function resolveWebBaseUrl(env = process.env) {
|
|
78
|
+
return normaliseBaseUrl(env.ARAGON_WEB_URL) ?? DEFAULT_WEB_BASE_URL;
|
|
79
|
+
}
|
|
80
|
+
/** `https://host/api/device/code`; `baseUrl` is expected to be normalised. */
|
|
81
|
+
export function apiUrl(baseUrl, path) {
|
|
82
|
+
return `${baseUrl.replace(/\/+$/, '')}${path}`;
|
|
83
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The RFC 8628 device-flow client (C1), with no UI and no ambient clock.
|
|
3
|
+
*
|
|
4
|
+
* TWO CALLS AND A STATE MACHINE:
|
|
5
|
+
*
|
|
6
|
+
* start() -> POST {baseUrl}/api/device/code {client_id, scope}
|
|
7
|
+
* poll() -> POST {baseUrl}/api/device/token {grant_type, device_code, client_id}
|
|
8
|
+
*
|
|
9
|
+
* EVERYTHING IS INJECTED - `fetch`, the clock and `sleep`. That is not test
|
|
10
|
+
* decoration: the polling loop's whole contract is about TIME (the server's
|
|
11
|
+
* interval, the `slow_down` growth, the 60 s cap, the `expires_in` ceiling), and
|
|
12
|
+
* a test that waits those seconds is a test nobody runs. With `now` and `sleep`
|
|
13
|
+
* as dependencies the intervals are data a fake clock can measure, and the
|
|
14
|
+
* shipped defaults are the only place a real timer exists.
|
|
15
|
+
*
|
|
16
|
+
* WHAT THIS MODULE REFUSES TO DO, each for a reason:
|
|
17
|
+
*
|
|
18
|
+
* - Never treat a non-200 as success, and never read the site's
|
|
19
|
+
* `{"error":{"code":...}}` envelope (C1). The device endpoints answer in the
|
|
20
|
+
* OAuth shape `{"error":"authorization_pending"}`; an object where a string
|
|
21
|
+
* belongs means this is not the endpoint we think it is, which is an error,
|
|
22
|
+
* not a token.
|
|
23
|
+
* - Never log or embed the `device_code` or the `access_token`. The token is
|
|
24
|
+
* returned to the caller and registered with the redactor there; the device
|
|
25
|
+
* code is a 34.6-bit credential that would let anyone redeem the grant.
|
|
26
|
+
* - Never poll past `expires_in`. The loop stops before a wait that would end
|
|
27
|
+
* after the deadline, so a terminal cannot sit there one interval too long
|
|
28
|
+
* holding a grant the server has already deleted.
|
|
29
|
+
* - Never spin: `authorization_pending` waits the server's interval, 429 waits
|
|
30
|
+
* the server's `retry-after`, and a transport failure backs off exponentially
|
|
31
|
+
* from the interval, capped at the same 60 s the server caps its own interval
|
|
32
|
+
* at. `maxNetworkRetries` bounds the backoff.
|
|
33
|
+
*/
|
|
34
|
+
/** A whole request may not hang longer than this. */
|
|
35
|
+
export declare const DEFAULT_REQUEST_TIMEOUT_MS = 10000;
|
|
36
|
+
/** Consecutive transport failures before `poll()` gives up. */
|
|
37
|
+
export declare const DEFAULT_MAX_NETWORK_RETRIES = 5;
|
|
38
|
+
/** A 429 without a usable `retry-after` header waits this long. */
|
|
39
|
+
export declare const DEFAULT_RETRY_AFTER_SECONDS = 5;
|
|
40
|
+
export interface DeviceCodeInfo {
|
|
41
|
+
readonly deviceCode: string;
|
|
42
|
+
readonly userCode: string;
|
|
43
|
+
readonly verificationUri: string;
|
|
44
|
+
readonly verificationUriComplete: string;
|
|
45
|
+
readonly expiresInSec: number;
|
|
46
|
+
readonly intervalSec: number;
|
|
47
|
+
}
|
|
48
|
+
export interface DeviceTokenInfo {
|
|
49
|
+
readonly accessToken: string;
|
|
50
|
+
readonly tokenType: string;
|
|
51
|
+
readonly expiresInSec: number;
|
|
52
|
+
readonly scope: string;
|
|
53
|
+
readonly tokenPrefix: string;
|
|
54
|
+
}
|
|
55
|
+
export type DeviceCodeResult = {
|
|
56
|
+
readonly kind: 'code';
|
|
57
|
+
readonly code: DeviceCodeInfo;
|
|
58
|
+
} | {
|
|
59
|
+
readonly kind: 'invalid';
|
|
60
|
+
readonly message: string;
|
|
61
|
+
} | {
|
|
62
|
+
readonly kind: 'network';
|
|
63
|
+
readonly message: string;
|
|
64
|
+
} | {
|
|
65
|
+
readonly kind: 'cancelled';
|
|
66
|
+
};
|
|
67
|
+
export type DevicePollResult = {
|
|
68
|
+
readonly kind: 'token';
|
|
69
|
+
readonly token: DeviceTokenInfo;
|
|
70
|
+
} | {
|
|
71
|
+
readonly kind: 'denied';
|
|
72
|
+
} | {
|
|
73
|
+
readonly kind: 'expired';
|
|
74
|
+
} | {
|
|
75
|
+
readonly kind: 'invalid';
|
|
76
|
+
readonly message: string;
|
|
77
|
+
} | {
|
|
78
|
+
readonly kind: 'network';
|
|
79
|
+
readonly message: string;
|
|
80
|
+
} | {
|
|
81
|
+
readonly kind: 'cancelled';
|
|
82
|
+
};
|
|
83
|
+
export interface PollInput {
|
|
84
|
+
readonly code: DeviceCodeInfo;
|
|
85
|
+
readonly signal?: AbortSignal;
|
|
86
|
+
readonly onProgress?: (progress: {
|
|
87
|
+
readonly elapsedSec: number;
|
|
88
|
+
}) => void;
|
|
89
|
+
}
|
|
90
|
+
export interface DeviceClientDeps {
|
|
91
|
+
readonly baseUrl: string;
|
|
92
|
+
readonly fetchImpl?: typeof fetch;
|
|
93
|
+
readonly now?: () => number;
|
|
94
|
+
/** Resolves after `ms`, or as soon as `signal` aborts. Injected in tests. */
|
|
95
|
+
readonly sleep?: (ms: number, signal?: AbortSignal) => Promise<void>;
|
|
96
|
+
readonly maxNetworkRetries?: number;
|
|
97
|
+
readonly requestTimeoutMs?: number;
|
|
98
|
+
}
|
|
99
|
+
export interface DeviceClient {
|
|
100
|
+
start(options?: {
|
|
101
|
+
readonly signal?: AbortSignal;
|
|
102
|
+
}): Promise<DeviceCodeResult>;
|
|
103
|
+
poll(input: PollInput): Promise<DevicePollResult>;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Build a client bound to one origin.
|
|
107
|
+
*
|
|
108
|
+
* A FACTORY RATHER THAN MODULE STATE: the base URL is per-login (the user may
|
|
109
|
+
* point `ARAGON_WEB_URL` at staging), and a module-level singleton would leak
|
|
110
|
+
* one login's origin into the next. The object is cheap; callers create one per
|
|
111
|
+
* `startLogin`.
|
|
112
|
+
*/
|
|
113
|
+
export declare function createDeviceClient(deps: DeviceClientDeps): DeviceClient;
|