@agentage/cli 0.51.0 → 0.52.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.
Files changed (152) hide show
  1. package/README.md +95 -127
  2. package/dist/commands/auth/setup.d.ts +2 -0
  3. package/dist/commands/auth/setup.js +4 -1
  4. package/dist/commands/daemon/daemon.d.ts +38 -0
  5. package/dist/commands/daemon/daemon.js +75 -0
  6. package/dist/commands/daemon/installer.d.ts +11 -0
  7. package/dist/commands/daemon/installer.js +87 -0
  8. package/dist/commands/daemon/move-plan.d.ts +17 -0
  9. package/dist/commands/daemon/move-plan.js +67 -0
  10. package/dist/commands/daemon/move-settings.d.ts +5 -0
  11. package/dist/commands/daemon/move-settings.js +50 -0
  12. package/dist/commands/daemon/move.d.ts +17 -0
  13. package/dist/commands/daemon/move.js +106 -0
  14. package/dist/commands/daemon/run.d.ts +6 -0
  15. package/dist/commands/daemon/run.js +36 -0
  16. package/dist/commands/extension/build.d.ts +13 -4
  17. package/dist/commands/extension/build.js +67 -25
  18. package/dist/commands/extension/configure.d.ts +26 -0
  19. package/dist/commands/extension/configure.js +100 -0
  20. package/dist/commands/extension/create-install.d.ts +26 -0
  21. package/dist/commands/extension/create-install.js +81 -0
  22. package/dist/commands/extension/create.d.ts +6 -1
  23. package/dist/commands/extension/create.js +58 -16
  24. package/dist/commands/extension/delegate.js +3 -1
  25. package/dist/commands/extension/doctor.d.ts +1 -1
  26. package/dist/commands/extension/doctor.js +8 -7
  27. package/dist/commands/extension/install-once.d.ts +17 -0
  28. package/dist/commands/extension/install-once.js +57 -0
  29. package/dist/commands/extension/kit-tool.d.ts +1 -1
  30. package/dist/commands/extension/lifecycle-commands.d.ts +19 -0
  31. package/dist/commands/extension/lifecycle-commands.js +80 -0
  32. package/dist/commands/extension/lifecycle-list.d.ts +26 -0
  33. package/dist/commands/extension/lifecycle-list.js +92 -0
  34. package/dist/commands/extension/lifecycle.d.ts +41 -0
  35. package/dist/commands/extension/lifecycle.js +142 -0
  36. package/dist/commands/extension/line.d.ts +1 -0
  37. package/dist/commands/extension/line.js +2 -0
  38. package/dist/commands/extension/list.d.ts +4 -14
  39. package/dist/commands/extension/list.js +11 -95
  40. package/dist/commands/extension/package-build.d.ts +15 -0
  41. package/dist/commands/extension/package-build.js +51 -0
  42. package/dist/commands/extension/plan.d.ts +4 -2
  43. package/dist/commands/extension/plan.js +37 -37
  44. package/dist/commands/extension/profile-plan.d.ts +16 -0
  45. package/dist/commands/extension/profile-plan.js +48 -0
  46. package/dist/commands/extension/release.d.ts +2 -1
  47. package/dist/commands/extension/release.js +10 -9
  48. package/dist/commands/extension/row-lines.d.ts +1 -2
  49. package/dist/commands/extension/row-lines.js +5 -6
  50. package/dist/commands/extension/rows.js +6 -4
  51. package/dist/commands/extension/setup-cloud.d.ts +2 -2
  52. package/dist/commands/extension/setup-cloud.js +6 -5
  53. package/dist/commands/extension/setup-install.d.ts +8 -0
  54. package/dist/commands/extension/setup-install.js +56 -0
  55. package/dist/commands/extension/setup.d.ts +4 -1
  56. package/dist/commands/extension/setup.js +56 -18
  57. package/dist/commands/extension/stack-owner.d.ts +4 -0
  58. package/dist/commands/extension/stack-owner.js +45 -0
  59. package/dist/commands/extension/sync.d.ts +6 -11
  60. package/dist/commands/extension/sync.js +8 -50
  61. package/dist/commands/extension/up-commands.d.ts +9 -0
  62. package/dist/commands/extension/up-commands.js +74 -0
  63. package/dist/commands/extension/up-local.d.ts +21 -0
  64. package/dist/commands/extension/up-local.js +94 -0
  65. package/dist/commands/extension/up-run.d.ts +23 -0
  66. package/dist/commands/extension/up-run.js +75 -0
  67. package/dist/commands/extension/up.d.ts +12 -11
  68. package/dist/commands/extension/up.js +65 -71
  69. package/dist/commands/update/update.d.ts +9 -1
  70. package/dist/commands/update/update.js +20 -6
  71. package/dist/core/installer/compare-lock.d.ts +0 -2
  72. package/dist/core/installer/compare-lock.js +0 -12
  73. package/dist/core/installer/compat.js +5 -3
  74. package/dist/core/installer/npm.d.ts +1 -0
  75. package/dist/core/installer/npm.js +6 -0
  76. package/dist/core/installer/old-tree.d.ts +3 -0
  77. package/dist/core/installer/old-tree.js +45 -0
  78. package/dist/core/installer/package-dir.d.ts +11 -0
  79. package/dist/core/installer/package-dir.js +53 -0
  80. package/dist/core/installer/resolve.js +1 -2
  81. package/dist/core/installer/tree.d.ts +0 -5
  82. package/dist/core/installer/tree.js +1 -25
  83. package/dist/core/kit-id.d.ts +1 -0
  84. package/dist/core/kit-id.js +20 -0
  85. package/dist/core/loader/discover.d.ts +7 -1
  86. package/dist/core/loader/discover.js +5 -4
  87. package/dist/core/loader/installed.d.ts +9 -0
  88. package/dist/core/loader/installed.js +51 -0
  89. package/dist/core/loader/manifest.d.ts +4 -0
  90. package/dist/core/loader/manifest.js +25 -3
  91. package/dist/core/loader/scan.d.ts +2 -1
  92. package/dist/core/loader/scan.js +17 -4
  93. package/dist/core/loader/secrets.d.ts +0 -7
  94. package/dist/core/loader/secrets.js +0 -11
  95. package/dist/core/loader/verbs.d.ts +0 -1
  96. package/dist/core/loader/verbs.js +1 -13
  97. package/dist/core/profile/machine.d.ts +0 -1
  98. package/dist/core/profile/machine.js +0 -5
  99. package/dist/lib/auth/introspect.js +1 -2
  100. package/dist/lib/auth/sign-in.js +3 -0
  101. package/dist/lib/child-env.d.ts +1 -0
  102. package/dist/lib/child-env.js +6 -0
  103. package/dist/lib/daemon/daemon-answer.d.ts +8 -0
  104. package/dist/lib/daemon/daemon-answer.js +38 -0
  105. package/dist/lib/daemon/daemon-client.d.ts +17 -0
  106. package/dist/lib/daemon/daemon-client.js +112 -0
  107. package/dist/lib/daemon/daemon-file.d.ts +16 -0
  108. package/dist/lib/daemon/daemon-file.js +30 -0
  109. package/dist/lib/daemon/daemon-health.d.ts +16 -0
  110. package/dist/lib/daemon/daemon-health.js +36 -0
  111. package/dist/lib/daemon/daemon-probe.d.ts +32 -0
  112. package/dist/lib/daemon/daemon-probe.js +41 -0
  113. package/dist/lib/daemon/daemon-stop.d.ts +13 -0
  114. package/dist/lib/daemon/daemon-stop.js +42 -0
  115. package/dist/lib/daemon/host-client.d.ts +40 -0
  116. package/dist/lib/daemon/host-client.js +45 -0
  117. package/dist/lib/exit-code.d.ts +2 -0
  118. package/dist/lib/exit-code.js +8 -0
  119. package/dist/lib/fs/json-file.d.ts +1 -0
  120. package/dist/lib/fs/json-file.js +1 -1
  121. package/dist/lib/json-output.d.ts +36 -0
  122. package/dist/lib/json-output.js +163 -0
  123. package/dist/lib/net/market-error.d.ts +12 -0
  124. package/dist/lib/net/market-error.js +28 -0
  125. package/dist/lib/net/market.d.ts +17 -2
  126. package/dist/lib/net/market.js +92 -18
  127. package/dist/lib/wait.d.ts +6 -0
  128. package/dist/lib/wait.js +17 -0
  129. package/dist/lib/with-action.d.ts +12 -0
  130. package/dist/lib/with-action.js +33 -0
  131. package/dist/program-deps.d.ts +2 -0
  132. package/dist/program-deps.js +95 -0
  133. package/dist/program.d.ts +29 -21
  134. package/dist/program.js +41 -75
  135. package/package.json +8 -6
  136. package/CHANGELOG.md +0 -68
  137. package/dist/commands/extension/install-load.d.ts +0 -7
  138. package/dist/commands/extension/install-load.js +0 -42
  139. package/dist/commands/extension/install.d.ts +0 -12
  140. package/dist/commands/extension/install.js +0 -49
  141. package/dist/commands/extension/latest.d.ts +0 -2
  142. package/dist/commands/extension/latest.js +0 -71
  143. package/dist/commands/extension/remove.d.ts +0 -15
  144. package/dist/commands/extension/remove.js +0 -86
  145. package/dist/commands/extension/secrets-prompt.d.ts +0 -6
  146. package/dist/commands/extension/secrets-prompt.js +0 -47
  147. package/dist/core/installer/installer.d.ts +0 -28
  148. package/dist/core/installer/installer.js +0 -87
  149. package/dist/core/installer/latest.d.ts +0 -27
  150. package/dist/core/installer/latest.js +0 -90
  151. package/dist/core/profile/edit.d.ts +0 -4
  152. package/dist/core/profile/edit.js +0 -27
package/README.md CHANGED
@@ -2,165 +2,121 @@
2
2
 
3
3
  ![Connect this machine to agentage from the terminal](https://github.com/agentage/cli/raw/master/docs/banner.svg)
4
4
 
5
- Connect this machine to your [agentage](https://agentage.io) account from the terminal, and
6
- install the extensions your account's profile names. One command signs you in through your
7
- browser; the same profile then gives you the same extensions on every machine you set up.
5
+ The agentage CLI connects each machine you use to your agentage account, a shared place for your
6
+ AI tools. Use it from a terminal, a server or CI. It also installs extensions: npm packages that
7
+ add commands to `agentage`. You need Node.js 22 or newer.
8
8
 
9
- ## What is this?
9
+ ```bash
10
+ npm install -g @agentage/cli && agentage setup
11
+ ```
10
12
 
11
- agentage gives your AI tools a shared, account-backed home. Every machine you use is connected
12
- to that account once, by this package. It keeps your sign-in on the machine (OAuth 2.1 with
13
- PKCE, nothing typed into the terminal), tells you whether the machine is connected, and keeps
14
- itself up to date.
13
+ ## What is this?
15
14
 
16
- The CLI itself stays **small**: sign-in, status, update, and an extension manager. Everything
17
- else, memory included, arrives as an extension the CLI installs for you.
15
+ The CLI stays **small**: sign-in, status, update and an extension manager. Sign-in uses OAuth 2.1
16
+ with PKCE: you type nothing into the terminal. Everything else, memory included, arrives as an
17
+ extension.
18
18
 
19
19
  ## Get started
20
20
 
21
- Needs Node.js 22 or newer.
22
-
23
- ```bash
24
- npm install -g @agentage/cli
25
- agentage setup
26
- ```
27
-
28
- `setup` opens your browser, you sign in, and the session is stored in `~/.agentage`. Then:
29
-
30
- ```bash
31
- agentage status
32
- ```
21
+ `agentage setup` opens your browser for sign-in. Check the session with `agentage status`.
22
+ Installing and running extensions needs no sign-in. On a new machine, a signed-in `setup` installs
23
+ the extensions of your account's profile once; after that each machine keeps its own list.
33
24
 
34
25
  ### On a server or in CI (no browser)
35
26
 
27
+ `agentage setup --no-browser` prints the sign-in URL. Open it in a browser on this same machine,
28
+ because sign-in returns to `localhost`. On a server, use a personal access token from the
29
+ dashboard (**Settings -> API tokens**):
30
+
36
31
  ```bash
37
- agentage setup --no-browser # prints the sign-in URL to open elsewhere
38
- AGENTAGE_TOKEN=aga_... agentage status # or use a personal access token
32
+ AGENTAGE_TOKEN=aga_... agentage status
39
33
  ```
40
34
 
41
- ### Then
42
-
43
- - `agentage status --json` in scripts to check the machine is connected.
44
- - `agentage update` whenever a newer version is published; `status` tells you when.
35
+ More: [docs/reference.md](docs/reference.md#token-auth-ci-and-headless).
45
36
 
46
37
  ## Commands
47
38
 
48
39
  | Command | What it does |
49
40
  | ----------------------------- | ----------------------------------------------------------------------------- |
50
- | `agentage setup` | Sign in through your browser, install your account's profile, show status |
41
+ | `agentage setup` | Sign in, install your account's profile, show status, start the daemon |
51
42
  | `agentage setup --no-browser` | Print the sign-in URL instead of opening a browser |
52
43
  | `agentage setup --reauth` | Force a fresh sign-in |
53
44
  | `agentage setup --disconnect` | Sign out and remove local credentials |
54
45
  | `agentage status` | Version, update, target, sign-in, endpoint, then machine, profile, extensions |
55
46
  | `agentage update` | Install the latest published version (`--check` only reports) |
47
+ | `agentage daemon status` | The local daemon on 127.0.0.1:4243 (`stop`, `restart`); `setup` starts it |
48
+ | `agentage extension ...` | Manage extensions, see [Extensions](#extensions) |
49
+ | any command with `--json` | One JSON object on stdout: `{ success, data }` or `{ success, error }` |
56
50
 
57
- For extensions (see below):
58
-
59
- | Command | What it does |
60
- | -------------------------------------------- | ---------------------------------------------------------------- |
61
- | `agentage setup --profile <file>` | Install and load the extensions a profile file names, no sign-in |
62
- | `agentage setup --profile <file> --dry-run` | Show what would be installed, write nothing |
63
- | `agentage setup --latest` | Update each extension to the newest version its range allows |
64
- | `agentage extension install <name> [--off]` | Add an extension to the profile, install and load it |
65
- | `agentage extension remove <name> [--purge]` | Take it out of the profile and reinstall the rest |
66
- | `agentage extension list` | One row per extension: state, version, commands, last run |
67
- | `agentage extension doctor` | Load every extension once and refresh the states |
68
- | `agentage extension create <id> [part...]` | New `./extension-<id>` from the template, only the parts named |
69
- | `agentage extension check [dir] [--write]` | Check that an extension package conforms (the six kit rules) |
70
- | `agentage extension build [--push]` | Build the part images of a committed tree; push with digests |
71
- | `agentage extension release` | Release from a tag in CI: guard, images, record, npm package |
72
- | `agentage extension up` / `down` | Run an extension package on this machine with Docker, then stop |
73
- | `agentage extension token --scope <scope>` | Print a token from the dev issuer `extension up` started |
74
- | `agentage <command>` | Run a command an installed extension contributes |
75
- | `agentage <id> <command>` | The same for an extension built on the kit; always works |
76
-
77
- Flags, exit codes and token auth are in [`docs/reference.md`](docs/reference.md).
51
+ More: [author commands](docs/extensions.md#author-commands) and [the lifecycle](docs/extensions.md#lifecycle).
78
52
 
79
53
  ## Extensions
80
54
 
81
- An extension is an npm package that adds to the CLI: commands today, more later. Extensions are
82
- on by default. A machine whose profile names no extensions has none, and `setup`, `status` and
83
- `update` work as described above, with three more `status` lines: `machine`, `profile` and
84
- `extensions`.
55
+ - A **profile** lists what your account wants: extensions, version ranges, and which are off
56
+ per machine.
57
+ - On a new machine, `setup` installs the profile's extensions through the daemon, once. No
58
+ command pushes your changes back to the account: each machine keeps its own list.
59
+ - `extension install`, `list`, `update`, `disable`, `enable`, `configure` and `remove` manage
60
+ one extension in the local daemon (`127.0.0.1:4243`), which runs each as its own process.
61
+ - Nothing installs on a timer: the machine changes only when you run a command.
62
+
63
+ ```bash
64
+ agentage extension install probe # the market's newest version, then it runs
65
+ agentage extension configure probe echo.prefix=hey # settings, no daemon restart
66
+ agentage extension list # id, version, source, state
67
+ agentage probe ping # run a command by its extension id
68
+ agentage extension remove probe # take it out again; --purge also deletes its data
69
+ ```
70
+
71
+ Extensions run in the CLI process with your privileges, so install only ones you trust. npm runs with
72
+ `--ignore-scripts`. The account token leaves the environment before extension code loads.
73
+
74
+ More: [docs/profiles.md](docs/profiles.md).
85
75
 
86
- The model is simple. A **profile** says what this account wants: which extensions, at which
87
- version ranges, and which ones are switched off on which machine. The CLI brings the machine
88
- to that state: `setup` installs what the profile names, loads each extension once and prints
89
- whether it loaded (`ok`) or why not. `extension install` and `extension remove` edit the
90
- profile and then do the same. Nothing installs itself on a timer; the state only changes when
91
- you run a command.
76
+ ### Write and run your own extension
92
77
 
93
- Once you are signed in, `setup` reads the profile your account holds, when it has one, so every
94
- machine you set up gets the same extensions, and `extension install` and `extension remove` save
95
- the change there. When your account has no profile to give, `setup` says so on one line and
96
- carries on. Each machine you run `setup` on appears in your account as one of its machines.
78
+ `create` needs git and network. `build` and `up` also need
79
+ Docker; `release` needs the `gh` CLI.
97
80
 
98
81
  ```bash
99
- agentage setup --profile ./profile.json # install and load the extensions a profile names
100
- agentage setup --profile ./profile.json --dry-run # show the plan, write nothing
101
- agentage setup --check # exit 1 when this machine differs from its profile
102
- agentage setup --latest # newest versions the ranges allow, diff printed
103
- agentage extension install @agentage/example # add one extension, install and load it
104
- agentage extension install ./my-extension # a local folder, for development
105
- agentage extension install . # link the working copy you are in
106
- agentage extension remove @agentage/example # take it out again
107
- agentage extension list # state per extension, with what setup would change
108
- agentage hello # a command the hello extension contributes
109
- agentage ping # a command of an extension built on the kit
110
- agentage probe ping # the same, by its extension id
82
+ agentage extension create example api # makes ./extension-example with the api part
83
+ cd extension-example && npm ci # installs the pinned cli
84
+ git init -q && git add -A && git commit -qm init # up needs one commit
85
+ npx agentage extension up # runs it with Docker
86
+ npx agentage extension token --scope example:read # prints a dev token with that scope
87
+ npx agentage extension down # removes what up started
111
88
  ```
112
89
 
113
- An extension built on the extension kit lists its commands in its manifest; each runs as
114
- `agentage <command>` and always as `agentage <id> <command>`. When the name is a core command,
115
- an extension id or a command an earlier install took, only `agentage <id> <command>` runs it, and
116
- the install says so.
117
-
118
- The plan is what `setup` would change, one line per extension (`+ add`, `~ update`, `- remove`,
119
- `o off`) and a summary such as `plan: 1 to add, 0 to update, 0 to remove, 0 off, 2 unchanged`.
120
- `setup --dry-run` prints it, `setup --check` exits 1 when anything would change, `extension list`
121
- shows it per extension and `status` sums it up, for example `extensions 2 (1 to add)`.
122
-
123
- `setup --latest` moves each extension to the newest version its range allows and prints one line
124
- per change, such as `~ update @agentage/example 1.0.0 -> 1.0.1`. The new versions take over only
125
- after every extension loaded from them cleanly; until then the installed ones stay. A version
126
- that needs a newer extension API than this CLI has is skipped, here and by `extension install`.
127
-
128
- A profile is a JSON file that maps package names to version ranges. `registries` is optional
129
- and routes a scope to another npm-compatible registry; everything else comes from npm's public
130
- registry.
131
-
132
- ```json
133
- {
134
- "version": 1,
135
- "extensions": { "@agentage/example": "^1.0.0" },
136
- "registries": { "@acme": "https://npm.acme.example" }
137
- }
138
- ```
90
+ In the extension folder, use `npx agentage`: the project's pinned cli and the global one can differ.
91
+
92
+ More: [docs/extensions.md](docs/extensions.md#run-it-locally).
93
+
94
+ ## Where things live
139
95
 
140
- Extensions run in the CLI process with your privileges, so install only extensions you trust.
141
- npm runs with `--ignore-scripts`, and the account token is removed from the environment before
142
- any extension code loads. Everything lives in the config directory:
96
+ Everything lives in the config directory, `~/.agentage` by default:
143
97
 
144
- | Path | What |
145
- | --------------------------- | -------------------------------------------------------------- |
146
- | `~/.agentage/profile.json` | the profile: what this account wants |
147
- | `~/.agentage/machine.json` | this machine's id, name, development extensions and account |
148
- | `~/.agentage/extensions/` | installed extensions; `extensions/current` names the live tree |
149
- | `~/.agentage/state/` | the last run of each extension |
150
- | `~/.agentage/commands.json` | which extension holds each top-level command |
151
- | `~/.agentage/data/<id>/` | what each extension keeps |
98
+ | Path | What |
99
+ | --------------------------- | --------------------------------------------------- |
100
+ | `~/.agentage/auth.json` | your sign-in, owner-only |
101
+ | `~/.agentage/profile.json` | the profile: what this account wants |
102
+ | `~/.agentage/machine.json` | this machine's id, name, dev extensions and account |
103
+ | `~/.agentage/extensions/` | installed extensions; `current` names the live tree |
104
+ | `~/.agentage/state/` | the last run of each extension |
105
+ | `~/.agentage/commands.json` | cli 0.51's command holders; read, never written |
106
+ | `~/.agentage/secrets.json` | extension secrets, owner-only |
107
+ | `~/.agentage/data/<id>/` | what each extension keeps |
152
108
 
153
- Every state an extension can be in, and every flag, is in [`docs/reference.md`](docs/reference.md).
154
- To write an extension, start with [`docs/extensions.md`](docs/extensions.md).
109
+ `status` writes `machine.json` even before you sign in.
110
+
111
+ To uninstall, run `agentage setup --disconnect`, then `npm uninstall -g @agentage/cli`, then
112
+ delete `~/.agentage`.
155
113
 
156
114
  ## How it works
157
115
 
158
- This is the **terminal client for an agentage account**. `setup` registers a one-off OAuth
159
- client, opens the authorization page in your browser and waits on a localhost callback; the
160
- tokens land in `~/.agentage/auth.json` with owner-only permissions and are refreshed
161
- automatically. `status` validates the session against the account's introspection endpoint
162
- and reports version, update, target host and connectivity. Nothing runs in the background, and
163
- nothing is installed beyond this package unless your profile names extensions.
116
+ - `setup` registers a one-off OAuth client and waits for the browser on a localhost callback.
117
+ - Tokens land in `~/.agentage/auth.json` (owner-only) and refresh automatically.
118
+ - `status` checks the session against the account's introspection endpoint.
119
+ - Nothing runs in the background.
164
120
 
165
121
  ## Configuration
166
122
 
@@ -180,16 +136,28 @@ npm run verify
180
136
  npm run build && npm run test:e2e -- --grep @offline
181
137
  ```
182
138
 
183
- The e2e specs under `e2e/core/` read as scenarios: each title names the command and what must
184
- hold. They run against a loopback registry that serves the extensions under `fixtures/`.
139
+ Each e2e title under `e2e/core/` names a command and what must hold. The tests use a loopback
140
+ npm registry that serves `fixtures/`.
185
141
 
186
142
  ## Release
187
143
 
188
- Releases publish to npm via GitHub Actions when a `chore(release): X.Y.Z` commit that touches
189
- `package.json` lands on `master` (the squash-merge subject of a release PR). The workflow skips
190
- any version already on npm.
144
+ GitHub Actions publishes to npm when a release PR merges to `master` as a `chore(release): X.Y.Z`
145
+ commit that touches `package.json`. It skips a version already on npm.
146
+
147
+ - The publish worked but the tag push failed: push the tag by hand on the release commit
148
+ (`git tag v0.52.0 <release commit> && git push origin v0.52.0`); never publish again.
149
+ - The agentage/e2e cli tier (`e2e.yml` on a PR) is not a required check; `release.yml` runs only
150
+ its `@smoke` tests before the publish. No workflow runs its lifecycle tests
151
+ (`AGENTAGE_CLI_LIFECYCLE=1`).
152
+ - Before the release PR merges, check: the PR checks of the release commit are green, and the
153
+ lifecycle tests of agentage/e2e pass 17 of 17 against the packed tarball of that commit
154
+ (`AGENTAGE_CLI_TARBALL=<tgz> AGENTAGE_CLI_LIFECYCLE=1 npm run e2e -- cli p0 local`).
155
+
156
+ ## Documentation
191
157
 
192
- An extension release (`agentage extension release`) skips npm for a package with `"private": true`: it pushes the images, attaches the record and prints `PASS npm: private package, not published`.
158
+ - [docs/reference.md](docs/reference.md): every flag, exit code and environment variable.
159
+ - [docs/profiles.md](docs/profiles.md): profiles, extension states, the plan and updates.
160
+ - [docs/extensions.md](docs/extensions.md): write, check and run your own extension.
193
161
 
194
162
  ## License
195
163
 
@@ -6,6 +6,7 @@ export interface SetupOptions extends SignInOptions {
6
6
  dryRun?: boolean;
7
7
  check?: boolean;
8
8
  latest?: boolean;
9
+ daemon?: boolean;
9
10
  json?: boolean;
10
11
  }
11
12
  export interface SetupDeps {
@@ -14,5 +15,6 @@ export interface SetupDeps {
14
15
  printStatus: (opts?: {
15
16
  token?: string;
16
17
  }) => Promise<void>;
18
+ startDaemon: () => Promise<number>;
17
19
  }
18
20
  export declare const registerSetup: (program: Command, action: (opts: SetupOptions) => Promise<void>) => void;
@@ -10,7 +10,9 @@ Neither signs in. Plain setup signs in, then pulls the profile from your account
10
10
  from this machine's profile.json, or the default, when the account has none), registers this
11
11
  machine in the account and installs; it never pushes a change. When the account cannot be
12
12
  reached it installs from the local profile.json, or, with none, installs nothing and says so on
13
- one line. A profile from --profile stays local: setup neither pulls nor pushes it. Each package
13
+ one line. With AGENTAGE_TOKEN set, setup signs in with that token and opens no browser. Then
14
+ setup starts the daemon on 127.0.0.1:4243, which needs no account (--no-daemon or
15
+ AGENTAGE_NO_DAEMON=1: not started). A profile from --profile stays local: setup neither pulls nor pushes it. Each package
14
16
  comes from the registry the profile's registries map names for its scope (default
15
17
  https://registry.npmjs.org) into AGENTAGE_EXTENSIONS_DIR (default ~/.agentage/extensions). After
16
18
  installing, setup lists the secrets extensions declare and this machine has not set (asking for
@@ -38,6 +40,7 @@ export const registerSetup = (program, action) => {
38
40
  .option('--disconnect', 'sign out and remove local credentials')
39
41
  .option('--reauth', 'force a fresh sign-in')
40
42
  .option('--no-browser', 'print the sign-in URL instead of opening a browser')
43
+ .option('--no-daemon', 'do not start the daemon')
41
44
  .option('--profile <file>', 'install the extensions a profile file names; never signs in')
42
45
  .option('--dry-run', 'print what setup would change and write nothing')
43
46
  .option('--check', 'exit 1 when setup would change anything; write nothing')
@@ -0,0 +1,38 @@
1
+ import { type Command } from 'commander';
2
+ import { type Health } from '../../lib/daemon/daemon-probe.js';
3
+ import { type HealthMarks } from '../../lib/daemon/daemon-health.js';
4
+ import { type StopResult } from '../../lib/daemon/daemon-stop.js';
5
+ import { type MoveReport } from './move.js';
6
+ export interface DaemonOptions {
7
+ json?: boolean;
8
+ }
9
+ export type DaemonStatus = ({
10
+ running: false;
11
+ } | {
12
+ running: false;
13
+ unresponsive: true;
14
+ pid: number;
15
+ port: number;
16
+ } | ({
17
+ running: true;
18
+ port: number;
19
+ reasons?: string[];
20
+ } & Health & HealthMarks)) & {
21
+ move?: MoveReport | null;
22
+ };
23
+ export declare const runDaemonStatus: (look?: (port: number, tries?: number, timeoutMs?: number) => Promise<import("../../lib/daemon/daemon-probe.js").Probe>) => Promise<DaemonStatus>;
24
+ export declare const runDaemonStop: (stop?: () => Promise<StopResult>) => Promise<{
25
+ stopped: boolean;
26
+ }>;
27
+ export declare const runDaemonRestart: (ensure?: () => Promise<number>) => Promise<{
28
+ port: number;
29
+ }>;
30
+ type Action = (opts: DaemonOptions) => Promise<void>;
31
+ export interface DaemonActions {
32
+ status: Action;
33
+ stop: Action;
34
+ restart: Action;
35
+ run: Action;
36
+ }
37
+ export declare const registerDaemon: (program: Command, actions: DaemonActions) => void;
38
+ export {};
@@ -0,0 +1,75 @@
1
+ import {} from 'commander';
2
+ import { ensureDaemon } from '../../lib/daemon/daemon-client.js';
3
+ import { isAlive, readDaemonFile } from '../../lib/daemon/daemon-file.js';
4
+ import { probeRetry, proven } from '../../lib/daemon/daemon-probe.js';
5
+ import { degradedReasons, healthLines } from '../../lib/daemon/daemon-health.js';
6
+ import { stopDaemon } from '../../lib/daemon/daemon-stop.js';
7
+ import { addJson } from '../../lib/json-output.js';
8
+ import { readMoveReport } from './move.js';
9
+ import { helpOrUnknown } from '../extension/list.js';
10
+ // Degraded always comes with its reasons, in the lines and in --json.
11
+ const report = (file, live) => {
12
+ console.log(`daemon: ${live.status} on 127.0.0.1:${file.port}, pid ${live.pid}, ${live.version}`);
13
+ const reasons = degradedReasons(live);
14
+ for (const line of healthLines(live, reasons))
15
+ console.log(line);
16
+ return { running: true, port: file.port, ...live, ...(reasons.length > 0 && { reasons }) };
17
+ };
18
+ // Reads only: a stale daemon.json is left for the next start or stop to remove.
19
+ // The D6 move's warning or skipped entries, until the user fixes them.
20
+ const moveLines = () => {
21
+ const move = readMoveReport();
22
+ if (move?.warning)
23
+ console.log(`move: ${move.warning}`);
24
+ for (const { entry, reason } of move?.skipped ?? [])
25
+ console.log(`move skipped ${entry}: ${reason}`);
26
+ return { move };
27
+ };
28
+ export const runDaemonStatus = async (look = probeRetry) => {
29
+ const status = await daemonStatus(look);
30
+ return { ...status, ...moveLines() };
31
+ };
32
+ const daemonStatus = async (look) => {
33
+ const file = readDaemonFile();
34
+ const found = file && isAlive(file.pid) ? await look(file.port) : null;
35
+ if (file && found?.kind === 'silent') {
36
+ console.log(`daemon: pid ${file.pid} does not answer on 127.0.0.1:${file.port}`);
37
+ return { running: false, unresponsive: true, pid: file.pid, port: file.port };
38
+ }
39
+ const live = file && found ? proven(file, found) : null;
40
+ if (!file || !live)
41
+ return (console.log('daemon: not running'), { running: false });
42
+ return report(file, live);
43
+ };
44
+ const STOPPED = (result) => {
45
+ if (result === null)
46
+ return 'daemon: not running';
47
+ if ('stale' in result)
48
+ return `daemon: not running (daemon.json was stale; pid ${result.stale} not signalled)`;
49
+ return `daemon: stopped (pid ${result.stopped})`;
50
+ };
51
+ export const runDaemonStop = async (stop = () => stopDaemon()) => {
52
+ const result = await stop();
53
+ console.log(STOPPED(result));
54
+ return { stopped: result !== null && 'stopped' in result };
55
+ };
56
+ export const runDaemonRestart = async (ensure = () => ensureDaemon()) => {
57
+ await stopDaemon();
58
+ return { port: await ensure() };
59
+ };
60
+ const HELP = `
61
+ The daemon runs the installed extensions on 127.0.0.1 (port 4243, AGENTAGE_DAEMON_PORT for
62
+ another), one child process each, and serves /api/{id}/* and /host/extensions. setup starts it,
63
+ and so does each command that needs it. daemon.json in the config folder names its pid and port.`;
64
+ export const registerDaemon = (program, actions) => {
65
+ const group = program
66
+ .command('daemon')
67
+ .description('Show, stop or restart the local daemon that runs extensions')
68
+ .allowExcessArguments()
69
+ .addHelpText('after', HELP)
70
+ .action(helpOrUnknown);
71
+ addJson(group.command('status').description('Show the daemon and its extensions')).action(actions.status);
72
+ addJson(group.command('stop').description('Stop the daemon and every extension')).action(actions.stop);
73
+ addJson(group.command('restart').description('Stop the daemon, then start it')).action(actions.restart);
74
+ group.command('run', { hidden: true }).description('Run the daemon here').action(actions.run);
75
+ };
@@ -0,0 +1,11 @@
1
+ import type { Installer } from '@agentage/extension/host';
2
+ import { type Npm, type NpmManifest } from '../../core/installer/npm.js';
3
+ import { type Market } from '../../lib/net/market.js';
4
+ export interface InstallerDeps {
5
+ npm: () => Promise<Npm>;
6
+ manifest: () => Promise<NpmManifest>;
7
+ market: () => Market;
8
+ }
9
+ export declare const installError: (code: string, status: 400 | 404 | 502, message: string) => Error;
10
+ export declare const cliInstaller: (deps: InstallerDeps) => Installer;
11
+ export declare const npmNewest: (manifest: () => Promise<NpmManifest>) => (id: string) => Promise<string>;
@@ -0,0 +1,87 @@
1
+ import { join } from 'node:path';
2
+ import { installedDir, installedName } from '../../core/installer/old-tree.js';
3
+ import { installPackage, packageDir } from '../../core/installer/package-dir.js';
4
+ import {} from '../../core/installer/npm.js';
5
+ import { registryLookup, resolveName } from '../../core/installer/resolve.js';
6
+ import { editableProfile } from '../../core/profile/profile.js';
7
+ import { isRecord, readJson } from '../../lib/fs/json-file.js';
8
+ import { messageOf } from '../../lib/json-output.js';
9
+ import {} from '../../lib/net/market.js';
10
+ import { npmFallbackLine, noSiteMarket } from '../../lib/net/market-error.js';
11
+ import { siteFqdn } from '../../lib/net/origins.js';
12
+ // The kit sends an error with a string code to the client as that envelope (404, 502, else 400).
13
+ export const installError = (code, status, message) => Object.assign(new Error(message), { code, status });
14
+ // The market's own reason, in the daemon's case (market_failed is MARKET_FAILED).
15
+ const marketDown = (id, why) => installError(why.code.toUpperCase(), 502, `${id}: ${why.message}`);
16
+ // With a market only the scoped name (anyone can publish the unscoped one); on a site with no
17
+ // market the name id was installed under, else both names, as cli 0.51.1.
18
+ const npmName = (id, down) => noSiteMarket(down) ? (installedName(id) ?? id) : `@agentage/extension-${id}`;
19
+ // The market names the package and its newest version; without it npm alone decides.
20
+ const inputOf = async (id, version, market) => {
21
+ const latest = await market.latest(id);
22
+ if (latest?.package === null)
23
+ throw installError('PRIVATE_ENTRY', 400, `${id}: private entry, no npm package to install`);
24
+ if (latest)
25
+ return `${latest.package}@${version ?? latest.version}`;
26
+ const down = market.down();
27
+ if (!version && down && !noSiteMarket(down))
28
+ throw marketDown(id, down);
29
+ const line = version ? null : npmFallbackLine(siteFqdn(), id, `${id} resolves`, down);
30
+ if (line)
31
+ console.error(line);
32
+ const name = npmName(id, down);
33
+ return version ? `${name}@${version}` : name;
34
+ };
35
+ // npm's reasons as codes: absent is NOT_FOUND, a registry that fails is INSTALL_FAILED.
36
+ const resolveError = (err) => {
37
+ const message = messageOf(err);
38
+ if (/not found|no published version|No matching version|ETARGET/.test(message))
39
+ return installError('NOT_FOUND', 404, message);
40
+ if (message.startsWith('npm '))
41
+ return installError('INSTALL_FAILED', 502, message);
42
+ return installError('VALIDATION_ERROR', 400, message);
43
+ };
44
+ // The one exact version npm has for the input: a range, a version, or the newest that fits.
45
+ const exact = async (input, registry) => {
46
+ const target = await resolveName(input, registry).catch((err) => {
47
+ throw resolveError(err);
48
+ });
49
+ if (target.kind !== 'package')
50
+ throw installError('VALIDATION_ERROR', 400, `${input}: not an id`);
51
+ const found = await registry.find(`${target.name}@${target.spec}`).catch((err) => {
52
+ throw resolveError(err);
53
+ });
54
+ if (!found)
55
+ throw installError('NOT_FOUND', 404, `${input}: npm has no such version`);
56
+ return found;
57
+ };
58
+ // The package must be the extension it was asked for.
59
+ const checkId = (dir, id) => {
60
+ const agentage = readJson(join(dir, 'package.json'), isRecord)?.['agentage'];
61
+ const got = isRecord(agentage) ? agentage['id'] : undefined;
62
+ if (got !== id)
63
+ throw installError('VALIDATION_ERROR', 400, `${dir}: agentage.id is ${String(got)}`);
64
+ };
65
+ const fetched = async (id, found, deps) => {
66
+ const { registries } = editableProfile();
67
+ const spec = { id, name: found.name, version: found.version, registries };
68
+ return installPackage(spec, await deps.npm()).catch((err) => {
69
+ throw installError('INSTALL_FAILED', 502, messageOf(err));
70
+ });
71
+ };
72
+ // The daemon's installer: a version on disk (its own tree or the 0.51 one) needs no network;
73
+ // otherwise the market, then npm into one folder per version (idempotent).
74
+ export const cliInstaller = (deps) => async ({ id, version }) => {
75
+ const have = version ? installedDir(id, version) : null;
76
+ if (version && have)
77
+ return { id, version, dir: have };
78
+ const registry = registryLookup(deps.manifest, editableProfile().registries);
79
+ const found = await exact(await inputOf(id, version, deps.market()), registry);
80
+ const dir = packageDir(id, found.version) ?? (await fetched(id, found, deps));
81
+ checkId(dir, id);
82
+ return { id, version: found.version, dir };
83
+ };
84
+ // The newest version npm has that this cli can run, of the name id was installed under (update
85
+ // on a site with no market); never another npm name for an installed row.
86
+ export const npmNewest = (manifest) => async (id) => (await exact(installedName(id) ?? id, registryLookup(manifest, editableProfile().registries)))
87
+ .version;
@@ -0,0 +1,17 @@
1
+ export type Row = Record<string, unknown> & {
2
+ id: string;
3
+ };
4
+ export interface Moved {
5
+ row: Row;
6
+ settings: Record<string, unknown>;
7
+ }
8
+ export interface Skipped {
9
+ entry: string;
10
+ reason: string;
11
+ }
12
+ export interface MovePlan {
13
+ moved: Moved[];
14
+ skipped: Skipped[];
15
+ warning: string | null;
16
+ }
17
+ export declare const movePlan: () => MovePlan;
@@ -0,0 +1,67 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { basename } from 'node:path';
3
+ import { installationPath, settingsPath } from '../../core/loader/installed.js';
4
+ import { isRecord, readJson } from '../../lib/fs/json-file.js';
5
+ import {} from '../../core/loader/discover.js';
6
+ import { scan } from '../../core/loader/scan.js';
7
+ import { NO_MACHINE, readMachine } from '../../core/profile/machine.js';
8
+ import { machinePath } from '../../core/paths.js';
9
+ import { readProfile } from '../../core/profile/profile.js';
10
+ import { kitIdProblem } from '../../core/kit-id.js';
11
+ import { movedSettings } from './move-settings.js';
12
+ const PACKAGE_ID = /^(?:@agentage\/extension-|agentage-extension-)([a-z][a-z0-9-]*)$/;
13
+ // A file that is there but does not parse would be written over as empty: its rows would be lost.
14
+ const unparsed = (path) => existsSync(path) && readJson(path, isRecord) === null;
15
+ const invalidList = () => {
16
+ const parsed = readProfile();
17
+ if (parsed !== null && !parsed.ok)
18
+ return `profile.json is invalid (${parsed.errors.join('; ')})`;
19
+ if (existsSync(machinePath()) && readMachine() === null)
20
+ return 'machine.json is invalid';
21
+ const bad = [installationPath(), settingsPath()].find(unparsed);
22
+ return bad ? `${basename(bad)} does not parse` : null;
23
+ };
24
+ // Why an entry stays behind: never run a folder 0.51 refused, or a package that is not there. A
25
+ // package built on kit 0.12 has a warning, not a problem: it moves.
26
+ const reasonOf = (ext, id) => {
27
+ if (ext.missing)
28
+ return ext.source === 'dev' ? 'folder missing' : 'not installed in the 0.51 tree';
29
+ if (!id)
30
+ return 'no agentage.id';
31
+ if (ext.problem)
32
+ return ext.problem;
33
+ const refused = kitIdProblem(id);
34
+ if (refused)
35
+ return `${refused}: the daemon takes no such row`;
36
+ return ext.source === 'tree' && !ext.version ? 'no exact version' : null;
37
+ };
38
+ const entryOf = (ext, off) => {
39
+ const id = ext.id ?? PACKAGE_ID.exec(ext.pkg)?.[1];
40
+ const reason = reasonOf(ext, id);
41
+ if (reason !== null || !id)
42
+ return { entry: ext.source === 'dev' ? ext.dir : ext.pkg, reason: reason ?? '' };
43
+ const where = ext.source === 'dev' ? { source: ext.dir } : { version: ext.version };
44
+ return { row: { id, ...where, ...(off && { enabled: false }) }, settings: {} };
45
+ };
46
+ // profile.json extensions{}, off and config, machine.json dev{}: what cli 0.51 ran here.
47
+ export const movePlan = () => {
48
+ const warning = invalidList();
49
+ if (warning)
50
+ return { moved: [], skipped: [], warning };
51
+ const found = scan(readMachine() ?? NO_MACHINE);
52
+ const { off, config } = found.eff;
53
+ const plan = { moved: [], skipped: [], warning: null };
54
+ for (const ext of found.found.extensions) {
55
+ const entry = entryOf(ext, off.includes(ext.pkg));
56
+ if ('reason' in entry)
57
+ plan.skipped.push(entry);
58
+ else {
59
+ const { settings, dropped } = movedSettings(entry.row.id, ext.dir, {
60
+ ...config[entry.row.id],
61
+ });
62
+ plan.moved.push({ ...entry, settings });
63
+ plan.skipped.push(...dropped);
64
+ }
65
+ }
66
+ return plan;
67
+ };
@@ -0,0 +1,5 @@
1
+ import { type Skipped } from './move-plan.js';
2
+ export declare const movedSettings: (id: string, dir: string, config: Record<string, unknown>) => {
3
+ settings: Record<string, unknown>;
4
+ dropped: Skipped[];
5
+ };