@agentage/cli 0.51.1 → 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.
- package/README.md +26 -15
- package/dist/commands/auth/setup.d.ts +2 -0
- package/dist/commands/auth/setup.js +4 -1
- package/dist/commands/daemon/daemon.d.ts +38 -0
- package/dist/commands/daemon/daemon.js +75 -0
- package/dist/commands/daemon/installer.d.ts +11 -0
- package/dist/commands/daemon/installer.js +87 -0
- package/dist/commands/daemon/move-plan.d.ts +17 -0
- package/dist/commands/daemon/move-plan.js +67 -0
- package/dist/commands/daemon/move-settings.d.ts +5 -0
- package/dist/commands/daemon/move-settings.js +50 -0
- package/dist/commands/daemon/move.d.ts +17 -0
- package/dist/commands/daemon/move.js +106 -0
- package/dist/commands/daemon/run.d.ts +6 -0
- package/dist/commands/daemon/run.js +36 -0
- package/dist/commands/extension/build.d.ts +13 -4
- package/dist/commands/extension/build.js +67 -25
- package/dist/commands/extension/configure.d.ts +26 -0
- package/dist/commands/extension/configure.js +100 -0
- package/dist/commands/extension/create-install.d.ts +26 -0
- package/dist/commands/extension/create-install.js +81 -0
- package/dist/commands/extension/create.d.ts +6 -1
- package/dist/commands/extension/create.js +33 -12
- package/dist/commands/extension/delegate.js +3 -1
- package/dist/commands/extension/doctor.d.ts +1 -1
- package/dist/commands/extension/doctor.js +8 -7
- package/dist/commands/extension/install-once.d.ts +17 -0
- package/dist/commands/extension/install-once.js +57 -0
- package/dist/commands/extension/kit-tool.d.ts +1 -1
- package/dist/commands/extension/lifecycle-commands.d.ts +19 -0
- package/dist/commands/extension/lifecycle-commands.js +80 -0
- package/dist/commands/extension/lifecycle-list.d.ts +26 -0
- package/dist/commands/extension/lifecycle-list.js +92 -0
- package/dist/commands/extension/lifecycle.d.ts +41 -0
- package/dist/commands/extension/lifecycle.js +142 -0
- package/dist/commands/extension/line.d.ts +1 -0
- package/dist/commands/extension/line.js +2 -0
- package/dist/commands/extension/list.d.ts +4 -14
- package/dist/commands/extension/list.js +11 -96
- package/dist/commands/extension/package-build.d.ts +15 -0
- package/dist/commands/extension/package-build.js +51 -0
- package/dist/commands/extension/plan.d.ts +4 -2
- package/dist/commands/extension/plan.js +37 -37
- package/dist/commands/extension/profile-plan.d.ts +16 -0
- package/dist/commands/extension/profile-plan.js +48 -0
- package/dist/commands/extension/release.d.ts +2 -1
- package/dist/commands/extension/release.js +10 -9
- package/dist/commands/extension/row-lines.d.ts +1 -2
- package/dist/commands/extension/row-lines.js +5 -6
- package/dist/commands/extension/rows.js +6 -4
- package/dist/commands/extension/setup-cloud.d.ts +2 -2
- package/dist/commands/extension/setup-cloud.js +6 -5
- package/dist/commands/extension/setup-install.d.ts +8 -0
- package/dist/commands/extension/setup-install.js +56 -0
- package/dist/commands/extension/setup.d.ts +4 -1
- package/dist/commands/extension/setup.js +56 -18
- package/dist/commands/extension/sync.d.ts +6 -11
- package/dist/commands/extension/sync.js +8 -50
- package/dist/commands/extension/up-commands.d.ts +9 -0
- package/dist/commands/extension/up-commands.js +74 -0
- package/dist/commands/extension/up-local.d.ts +21 -0
- package/dist/commands/extension/up-local.js +94 -0
- package/dist/commands/extension/up-run.d.ts +23 -0
- package/dist/commands/extension/up-run.js +75 -0
- package/dist/commands/extension/up.d.ts +10 -10
- package/dist/commands/extension/up.js +62 -74
- package/dist/commands/update/update.d.ts +9 -1
- package/dist/commands/update/update.js +20 -6
- package/dist/core/installer/compare-lock.d.ts +0 -2
- package/dist/core/installer/compare-lock.js +0 -12
- package/dist/core/installer/compat.js +5 -3
- package/dist/core/installer/npm.d.ts +1 -0
- package/dist/core/installer/npm.js +6 -0
- package/dist/core/installer/old-tree.d.ts +3 -0
- package/dist/core/installer/old-tree.js +45 -0
- package/dist/core/installer/package-dir.d.ts +11 -0
- package/dist/core/installer/package-dir.js +53 -0
- package/dist/core/installer/resolve.js +1 -2
- package/dist/core/installer/tree.d.ts +0 -5
- package/dist/core/installer/tree.js +1 -25
- package/dist/core/kit-id.d.ts +1 -0
- package/dist/core/kit-id.js +20 -0
- package/dist/core/loader/discover.d.ts +7 -1
- package/dist/core/loader/discover.js +5 -4
- package/dist/core/loader/installed.d.ts +9 -0
- package/dist/core/loader/installed.js +51 -0
- package/dist/core/loader/manifest.d.ts +4 -0
- package/dist/core/loader/manifest.js +25 -3
- package/dist/core/loader/scan.d.ts +2 -1
- package/dist/core/loader/scan.js +17 -4
- package/dist/core/loader/secrets.d.ts +0 -7
- package/dist/core/loader/secrets.js +0 -11
- package/dist/core/loader/verbs.d.ts +0 -1
- package/dist/core/loader/verbs.js +1 -13
- package/dist/core/profile/machine.d.ts +0 -1
- package/dist/core/profile/machine.js +0 -5
- package/dist/lib/auth/introspect.js +1 -2
- package/dist/lib/auth/sign-in.js +3 -0
- package/dist/lib/child-env.d.ts +1 -0
- package/dist/lib/child-env.js +6 -0
- package/dist/lib/daemon/daemon-answer.d.ts +8 -0
- package/dist/lib/daemon/daemon-answer.js +38 -0
- package/dist/lib/daemon/daemon-client.d.ts +17 -0
- package/dist/lib/daemon/daemon-client.js +112 -0
- package/dist/lib/daemon/daemon-file.d.ts +16 -0
- package/dist/lib/daemon/daemon-file.js +30 -0
- package/dist/lib/daemon/daemon-health.d.ts +16 -0
- package/dist/lib/daemon/daemon-health.js +36 -0
- package/dist/lib/daemon/daemon-probe.d.ts +32 -0
- package/dist/lib/daemon/daemon-probe.js +41 -0
- package/dist/lib/daemon/daemon-stop.d.ts +13 -0
- package/dist/lib/daemon/daemon-stop.js +42 -0
- package/dist/lib/daemon/host-client.d.ts +40 -0
- package/dist/lib/daemon/host-client.js +45 -0
- package/dist/lib/exit-code.d.ts +2 -0
- package/dist/lib/exit-code.js +8 -0
- package/dist/lib/fs/json-file.d.ts +1 -0
- package/dist/lib/fs/json-file.js +1 -1
- package/dist/lib/json-output.d.ts +36 -0
- package/dist/lib/json-output.js +163 -0
- package/dist/lib/net/market-error.d.ts +12 -0
- package/dist/lib/net/market-error.js +28 -0
- package/dist/lib/net/market.d.ts +17 -2
- package/dist/lib/net/market.js +92 -18
- package/dist/lib/wait.d.ts +6 -0
- package/dist/lib/wait.js +17 -0
- package/dist/lib/with-action.d.ts +12 -0
- package/dist/lib/with-action.js +33 -0
- package/dist/program-deps.d.ts +2 -0
- package/dist/program-deps.js +95 -0
- package/dist/program.d.ts +29 -21
- package/dist/program.js +41 -75
- package/package.json +8 -6
- package/CHANGELOG.md +0 -68
- package/dist/commands/extension/install-load.d.ts +0 -7
- package/dist/commands/extension/install-load.js +0 -42
- package/dist/commands/extension/install.d.ts +0 -12
- package/dist/commands/extension/install.js +0 -49
- package/dist/commands/extension/latest.d.ts +0 -2
- package/dist/commands/extension/latest.js +0 -71
- package/dist/commands/extension/remove.d.ts +0 -15
- package/dist/commands/extension/remove.js +0 -86
- package/dist/commands/extension/secrets-prompt.d.ts +0 -6
- package/dist/commands/extension/secrets-prompt.js +0 -47
- package/dist/core/installer/installer.d.ts +0 -28
- package/dist/core/installer/installer.js +0 -87
- package/dist/core/installer/latest.d.ts +0 -27
- package/dist/core/installer/latest.js +0 -90
- package/dist/core/profile/edit.d.ts +0 -4
- package/dist/core/profile/edit.js +0 -27
package/README.md
CHANGED
|
@@ -19,8 +19,8 @@ extension.
|
|
|
19
19
|
## Get started
|
|
20
20
|
|
|
21
21
|
`agentage setup` opens your browser for sign-in. Check the session with `agentage status`.
|
|
22
|
-
Installing and running extensions needs no sign-in.
|
|
23
|
-
machine
|
|
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.
|
|
24
24
|
|
|
25
25
|
### On a server or in CI (no browser)
|
|
26
26
|
|
|
@@ -38,32 +38,34 @@ More: [docs/reference.md](docs/reference.md#token-auth-ci-and-headless).
|
|
|
38
38
|
|
|
39
39
|
| Command | What it does |
|
|
40
40
|
| ----------------------------- | ----------------------------------------------------------------------------- |
|
|
41
|
-
| `agentage setup` | Sign in
|
|
41
|
+
| `agentage setup` | Sign in, install your account's profile, show status, start the daemon |
|
|
42
42
|
| `agentage setup --no-browser` | Print the sign-in URL instead of opening a browser |
|
|
43
43
|
| `agentage setup --reauth` | Force a fresh sign-in |
|
|
44
44
|
| `agentage setup --disconnect` | Sign out and remove local credentials |
|
|
45
45
|
| `agentage status` | Version, update, target, sign-in, endpoint, then machine, profile, extensions |
|
|
46
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 |
|
|
47
48
|
| `agentage extension ...` | Manage extensions, see [Extensions](#extensions) |
|
|
49
|
+
| any command with `--json` | One JSON object on stdout: `{ success, data }` or `{ success, error }` |
|
|
48
50
|
|
|
49
|
-
More: [author commands](docs/extensions.md#author-commands).
|
|
51
|
+
More: [author commands](docs/extensions.md#author-commands) and [the lifecycle](docs/extensions.md#lifecycle).
|
|
50
52
|
|
|
51
53
|
## Extensions
|
|
52
54
|
|
|
53
55
|
- A **profile** lists what your account wants: extensions, version ranges, and which are off
|
|
54
56
|
per machine.
|
|
55
|
-
- `setup` installs the profile
|
|
56
|
-
|
|
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.
|
|
57
61
|
- Nothing installs on a timer: the machine changes only when you run a command.
|
|
58
62
|
|
|
59
63
|
```bash
|
|
60
|
-
agentage extension install probe
|
|
61
|
-
agentage extension
|
|
62
|
-
agentage
|
|
63
|
-
agentage
|
|
64
|
-
agentage extension
|
|
65
|
-
agentage setup --latest # newest versions the ranges allow
|
|
66
|
-
agentage setup --profile profile.json # install a profile file, no sign-in
|
|
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
|
|
67
69
|
```
|
|
68
70
|
|
|
69
71
|
Extensions run in the CLI process with your privileges, so install only ones you trust. npm runs with
|
|
@@ -81,7 +83,7 @@ agentage extension create example api # makes ./extension-example with the api
|
|
|
81
83
|
cd extension-example && npm ci # installs the pinned cli
|
|
82
84
|
git init -q && git add -A && git commit -qm init # up needs one commit
|
|
83
85
|
npx agentage extension up # runs it with Docker
|
|
84
|
-
npx agentage extension token --scope example:read
|
|
86
|
+
npx agentage extension token --scope example:read # prints a dev token with that scope
|
|
85
87
|
npx agentage extension down # removes what up started
|
|
86
88
|
```
|
|
87
89
|
|
|
@@ -100,7 +102,7 @@ Everything lives in the config directory, `~/.agentage` by default:
|
|
|
100
102
|
| `~/.agentage/machine.json` | this machine's id, name, dev extensions and account |
|
|
101
103
|
| `~/.agentage/extensions/` | installed extensions; `current` names the live tree |
|
|
102
104
|
| `~/.agentage/state/` | the last run of each extension |
|
|
103
|
-
| `~/.agentage/commands.json` |
|
|
105
|
+
| `~/.agentage/commands.json` | cli 0.51's command holders; read, never written |
|
|
104
106
|
| `~/.agentage/secrets.json` | extension secrets, owner-only |
|
|
105
107
|
| `~/.agentage/data/<id>/` | what each extension keeps |
|
|
106
108
|
|
|
@@ -142,6 +144,15 @@ npm registry that serves `fixtures/`.
|
|
|
142
144
|
GitHub Actions publishes to npm when a release PR merges to `master` as a `chore(release): X.Y.Z`
|
|
143
145
|
commit that touches `package.json`. It skips a version already on npm.
|
|
144
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
|
+
|
|
145
156
|
## Documentation
|
|
146
157
|
|
|
147
158
|
- [docs/reference.md](docs/reference.md): every flag, exit code and environment variable.
|
|
@@ -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.
|
|
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,50 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { isRecord, readJson } from '../../lib/fs/json-file.js';
|
|
3
|
+
import {} from './move-plan.js';
|
|
4
|
+
const NUMERIC = /^-?\d+(?:\.\d+)?$/;
|
|
5
|
+
// 0.51 kept any JSON value; the daemon wants the manifest's type, so a value is turned into it.
|
|
6
|
+
const coerce = (type, value) => {
|
|
7
|
+
if (type === 'string')
|
|
8
|
+
return typeof value === 'object' ? null : { value: String(value) };
|
|
9
|
+
if (type === 'boolean') {
|
|
10
|
+
if (typeof value === 'boolean')
|
|
11
|
+
return { value };
|
|
12
|
+
return value === 'true' || value === 'false' ? { value: value === 'true' } : null;
|
|
13
|
+
}
|
|
14
|
+
const n = typeof value === 'number' ? value : NUMERIC.test(String(value)) ? Number(value) : NaN;
|
|
15
|
+
if (Number.isNaN(n) || typeof value === 'object')
|
|
16
|
+
return null;
|
|
17
|
+
return type === 'integer' && !Number.isInteger(n) ? null : { value: n };
|
|
18
|
+
};
|
|
19
|
+
const declared = (dir) => {
|
|
20
|
+
const agentage = readJson(join(dir, 'package.json'), isRecord)?.['agentage'];
|
|
21
|
+
const settings = isRecord(agentage) ? agentage['settings'] : undefined;
|
|
22
|
+
return isRecord(settings) ? settings : null;
|
|
23
|
+
};
|
|
24
|
+
const valueOf = (decl, value) => {
|
|
25
|
+
if (!isRecord(decl))
|
|
26
|
+
return null;
|
|
27
|
+
const done = coerce(decl['type'], value);
|
|
28
|
+
const allowed = Array.isArray(decl['enum']) ? decl['enum'] : null;
|
|
29
|
+
return done && allowed && !allowed.includes(done.value) ? null : done;
|
|
30
|
+
};
|
|
31
|
+
// The settings the extension declares, of its types; a key it cannot take is dropped and reported,
|
|
32
|
+
// so the extension still starts. No declared settings (an 0.51 extension): kept as they are.
|
|
33
|
+
export const movedSettings = (id, dir, config) => {
|
|
34
|
+
const decls = declared(dir);
|
|
35
|
+
if (decls === null)
|
|
36
|
+
return { settings: config, dropped: [] };
|
|
37
|
+
const settings = {};
|
|
38
|
+
const dropped = [];
|
|
39
|
+
for (const [key, value] of Object.entries(config)) {
|
|
40
|
+
const done = valueOf(decls[key], value);
|
|
41
|
+
if (done)
|
|
42
|
+
settings[key] = done.value;
|
|
43
|
+
else
|
|
44
|
+
dropped.push({
|
|
45
|
+
entry: `${id} setting ${key}`,
|
|
46
|
+
reason: key in decls ? `${JSON.stringify(value)} does not fit its type` : 'not declared',
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return { settings, dropped };
|
|
50
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type * as KitHost from '@agentage/extension/host';
|
|
2
|
+
import { type Moved, type Skipped } from './move-plan.js';
|
|
3
|
+
export declare const MOVED_MARKER = "installation.moved";
|
|
4
|
+
export declare const MOVE_REPORT = "installation.moved.json";
|
|
5
|
+
export interface MoveReport {
|
|
6
|
+
moved: string[];
|
|
7
|
+
skipped: Skipped[];
|
|
8
|
+
warning: string | null;
|
|
9
|
+
}
|
|
10
|
+
export type KitMove = Pick<typeof KitHost, 'updateInstallation' | 'withFileLock'>;
|
|
11
|
+
export declare const readMoveReport: () => MoveReport | null;
|
|
12
|
+
export interface MoveHooks {
|
|
13
|
+
entry?: (moved: Moved) => void;
|
|
14
|
+
kit?: () => Promise<KitMove>;
|
|
15
|
+
}
|
|
16
|
+
export declare const moveOldLists: (hooks?: MoveHooks) => Promise<void>;
|
|
17
|
+
export declare const moveBeforeStart: (hooks?: MoveHooks) => Promise<void>;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { existsSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { settingsPath } from '../../core/loader/installed.js';
|
|
4
|
+
import { ensureConfigDir, getConfigDir } from '../../lib/fs/config.js';
|
|
5
|
+
import { isRecord, readJson, writeJsonAtomic } from '../../lib/fs/json-file.js';
|
|
6
|
+
import { messageOf } from '../../lib/json-output.js';
|
|
7
|
+
import { movePlan } from './move-plan.js';
|
|
8
|
+
// Written once every old entry is moved or deliberately skipped; the old files stay as they were.
|
|
9
|
+
export const MOVED_MARKER = 'installation.moved';
|
|
10
|
+
// What the last move did: the skipped entries and why, or the warning that stopped it.
|
|
11
|
+
export const MOVE_REPORT = 'installation.moved.json';
|
|
12
|
+
const kitMove = () => import('@agentage/extension/host');
|
|
13
|
+
// An id in installation.json keeps its row: a rerun after a stop adds only what is missing.
|
|
14
|
+
const addRow = (kit, row) => kit.updateInstallation(getConfigDir(), (doc) => doc.extensions.some((r) => r.id === row.id)
|
|
15
|
+
? doc
|
|
16
|
+
: { ...doc, extensions: [...doc.extensions, row] });
|
|
17
|
+
// The daemon's own values win over the profile's: they were set after the move.
|
|
18
|
+
const addSettings = async (kit, id, settings) => {
|
|
19
|
+
if (Object.keys(settings).length === 0)
|
|
20
|
+
return;
|
|
21
|
+
await kit.withFileLock(settingsPath(), () => {
|
|
22
|
+
const all = readJson(settingsPath(), isRecord) ?? {};
|
|
23
|
+
const mine = isRecord(all[id]) ? all[id] : {};
|
|
24
|
+
writeJsonAtomic(settingsPath(), { ...all, [id]: { ...settings, ...mine } }, 0o600);
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
const writeReport = (report) => writeJsonAtomic(join(getConfigDir(), MOVE_REPORT), report, 0o644);
|
|
28
|
+
const isSkipped = (v) => isRecord(v) && typeof v['entry'] === 'string' && typeof v['reason'] === 'string';
|
|
29
|
+
const isMoveReport = (v) => isRecord(v) &&
|
|
30
|
+
Array.isArray(v['moved']) &&
|
|
31
|
+
v['moved'].every((id) => typeof id === 'string') &&
|
|
32
|
+
Array.isArray(v['skipped']) &&
|
|
33
|
+
v['skipped'].every(isSkipped) &&
|
|
34
|
+
(v['warning'] === null || typeof v['warning'] === 'string');
|
|
35
|
+
export const readMoveReport = () => readJson(join(getConfigDir(), MOVE_REPORT), isMoveReport);
|
|
36
|
+
const say = (report) => {
|
|
37
|
+
if (report.moved.length > 0)
|
|
38
|
+
console.error(`moved ${report.moved.length} extensions into installation.json`);
|
|
39
|
+
for (const { entry, reason } of report.skipped)
|
|
40
|
+
console.error(`move skipped ${entry}: ${reason}`);
|
|
41
|
+
};
|
|
42
|
+
// A row the kit's check refuses is skipped with its reason; the other rows still move.
|
|
43
|
+
const addEntry = async (kit, moved, hooks) => {
|
|
44
|
+
try {
|
|
45
|
+
await addRow(kit, moved.row);
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
if (err.code !== 'VALIDATION_ERROR')
|
|
49
|
+
throw err;
|
|
50
|
+
return { entry: moved.row.id, reason: `the daemon refuses the row (${messageOf(err)})` };
|
|
51
|
+
}
|
|
52
|
+
await addSettings(kit, moved.row.id, moved.settings);
|
|
53
|
+
hooks.entry?.(moved);
|
|
54
|
+
return null;
|
|
55
|
+
};
|
|
56
|
+
const addAll = async (kit, report, plan, hooks) => {
|
|
57
|
+
for (const moved of plan) {
|
|
58
|
+
const skipped = await addEntry(kit, moved, hooks);
|
|
59
|
+
if (!skipped)
|
|
60
|
+
continue;
|
|
61
|
+
report.skipped.push(skipped);
|
|
62
|
+
report.moved = report.moved.filter((id) => id !== skipped.entry);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
// D6, before the daemon reads the file. An old list that does not parse moves nothing and writes
|
|
66
|
+
// no marker: the daemon still starts, and the next start tries again.
|
|
67
|
+
export const moveOldLists = async (hooks = {}) => {
|
|
68
|
+
const marker = join(ensureConfigDir(), MOVED_MARKER);
|
|
69
|
+
if (existsSync(marker))
|
|
70
|
+
return;
|
|
71
|
+
const plan = movePlan();
|
|
72
|
+
const report = {
|
|
73
|
+
moved: plan.moved.map((m) => m.row.id),
|
|
74
|
+
skipped: [...plan.skipped],
|
|
75
|
+
warning: plan.warning,
|
|
76
|
+
};
|
|
77
|
+
if (plan.warning) {
|
|
78
|
+
writeReport(report);
|
|
79
|
+
return console.error(`move: ${plan.warning}; nothing moved, fix it and restart the daemon`);
|
|
80
|
+
}
|
|
81
|
+
const kit = await (hooks.kit ?? kitMove)();
|
|
82
|
+
await addAll(kit, report, plan.moved, hooks);
|
|
83
|
+
writeReport(report);
|
|
84
|
+
writeFileSync(marker, `${new Date().toISOString()}\n`);
|
|
85
|
+
say(report);
|
|
86
|
+
};
|
|
87
|
+
// The daemon's `before`: a move that fails (a held lock, a full disk) never stops the start. No
|
|
88
|
+
// marker is written, so the next start tries again; `daemon status` shows the reason. Another live
|
|
89
|
+
// daemon on the folder is no move failure: this start ends, and that daemon's report stays.
|
|
90
|
+
export const moveBeforeStart = async (hooks = {}) => {
|
|
91
|
+
try {
|
|
92
|
+
await moveOldLists(hooks);
|
|
93
|
+
}
|
|
94
|
+
catch (err) {
|
|
95
|
+
if (err.code === 'DAEMON_RUNNING')
|
|
96
|
+
throw err;
|
|
97
|
+
const warning = `the move stopped (${messageOf(err)}); the next daemon start tries again`;
|
|
98
|
+
console.error(`move: ${warning}`);
|
|
99
|
+
try {
|
|
100
|
+
writeReport({ moved: [], skipped: [], warning });
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
// the report is only shown; the daemon still starts
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
};
|