@agentage/cli 0.52.1 → 0.54.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 +9 -11
- package/dist/commands/daemon/daemon.d.ts +5 -3
- package/dist/commands/daemon/daemon.js +45 -10
- package/dist/commands/daemon/installer.d.ts +4 -0
- package/dist/commands/daemon/installer.js +32 -8
- package/dist/commands/daemon/run.d.ts +3 -0
- package/dist/commands/daemon/run.js +11 -1
- package/dist/commands/extension/build.js +5 -3
- package/dist/commands/extension/configure.js +2 -1
- package/dist/commands/extension/create-install.js +3 -2
- package/dist/commands/extension/install-once.d.ts +2 -0
- package/dist/commands/extension/install-once.js +5 -5
- package/dist/commands/extension/install-spec.d.ts +7 -0
- package/dist/commands/extension/install-spec.js +33 -0
- package/dist/commands/extension/lifecycle.d.ts +1 -4
- package/dist/commands/extension/lifecycle.js +8 -32
- package/dist/commands/extension/package-build.d.ts +11 -1
- package/dist/commands/extension/package-build.js +53 -17
- package/dist/commands/extension/release-guard.d.ts +8 -1
- package/dist/commands/extension/release-guard.js +39 -16
- package/dist/commands/extension/release.js +35 -19
- package/dist/commands/extension/setup-install.js +48 -23
- package/dist/commands/extension/setup-marker.d.ts +6 -0
- package/dist/commands/extension/setup-marker.js +23 -0
- package/dist/commands/extension/up-build.d.ts +17 -0
- package/dist/commands/extension/up-build.js +71 -0
- package/dist/commands/extension/up-commands.js +11 -10
- package/dist/commands/extension/up-local.d.ts +15 -12
- package/dist/commands/extension/up-local.js +61 -60
- package/dist/commands/extension/up-reload.d.ts +30 -0
- package/dist/commands/extension/up-reload.js +115 -0
- package/dist/commands/extension/up-run.d.ts +9 -11
- package/dist/commands/extension/up-run.js +132 -50
- package/dist/commands/extension/up-watch.d.ts +23 -0
- package/dist/commands/extension/up-watch.js +81 -0
- package/dist/commands/extension/up.d.ts +5 -3
- package/dist/commands/extension/up.js +48 -25
- package/dist/core/installer/version-spec.d.ts +2 -0
- package/dist/core/installer/version-spec.js +5 -0
- package/dist/core/loader/manifest.d.ts +2 -1
- package/dist/core/loader/manifest.js +13 -8
- package/dist/lib/daemon/daemon-client.js +16 -11
- package/dist/lib/daemon/daemon-file.d.ts +2 -0
- package/dist/lib/daemon/daemon-file.js +4 -0
- package/dist/lib/daemon/daemon-health.d.ts +5 -0
- package/dist/lib/daemon/daemon-health.js +27 -2
- package/dist/lib/daemon/daemon-probe.d.ts +10 -5
- package/dist/lib/daemon/daemon-probe.js +8 -2
- package/dist/lib/daemon/host-client.d.ts +17 -2
- package/dist/lib/daemon/host-client.js +42 -12
- package/dist/lib/fs/file-lock.js +6 -0
- package/dist/lib/json-output.js +7 -5
- package/dist/lib/proc/start-time.d.ts +10 -0
- package/dist/lib/proc/start-time.js +46 -0
- package/dist/program-deps.js +3 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -75,16 +75,14 @@ More: [docs/profiles.md](docs/profiles.md).
|
|
|
75
75
|
|
|
76
76
|
### Write and run your own extension
|
|
77
77
|
|
|
78
|
-
`create` needs git and network. `build` and `
|
|
79
|
-
Docker; `release` needs the `gh` CLI.
|
|
78
|
+
`create` needs git and network. `build --container`, `up --docker` and `release` also need
|
|
79
|
+
Docker and a committed tree; `release` needs the `gh` CLI.
|
|
80
80
|
|
|
81
81
|
```bash
|
|
82
82
|
agentage extension create example api # makes ./extension-example with the api part
|
|
83
83
|
cd extension-example && npm ci # installs the pinned cli
|
|
84
|
-
|
|
85
|
-
npx agentage extension
|
|
86
|
-
npx agentage extension token --scope example:read # prints a dev token with that scope
|
|
87
|
-
npx agentage extension down # removes what up started
|
|
84
|
+
npx agentage extension up # runs it on the daemon, reloads each saved change
|
|
85
|
+
npx agentage extension down # removes the row up added (its data stays)
|
|
88
86
|
```
|
|
89
87
|
|
|
90
88
|
In the extension folder, use `npx agentage`: the project's pinned cli and the global one can differ.
|
|
@@ -147,11 +145,11 @@ commit that touches `package.json`. It skips a version already on npm.
|
|
|
147
145
|
- The publish worked but the tag push failed: push the tag by hand on the release commit
|
|
148
146
|
(`git tag v0.52.0 <release commit> && git push origin v0.52.0`); never publish again.
|
|
149
147
|
- 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
|
|
151
|
-
|
|
152
|
-
- Before the release PR merges, check: the PR checks of the release commit are green, and the
|
|
153
|
-
|
|
154
|
-
(`AGENTAGE_CLI_TARBALL=<tgz>
|
|
148
|
+
its `@smoke` tests before the publish. No workflow of this repo runs its lifecycle, execution
|
|
149
|
+
and reload tests on a candidate; agentage/e2e runs them on its own PRs against the published cli.
|
|
150
|
+
- Before the release PR merges, check: the PR checks of the release commit are green, and the cli
|
|
151
|
+
project of agentage/e2e passes 48 of 48 against the packed tarball of that commit
|
|
152
|
+
(`AGENTAGE_CLI_TARBALL=<tgz> npm run test:cli -- --retries=0`).
|
|
155
153
|
|
|
156
154
|
## Documentation
|
|
157
155
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Command } from 'commander';
|
|
2
|
-
import { type Health } from '../../lib/daemon/daemon-probe.js';
|
|
2
|
+
import { type Health, type Probe } from '../../lib/daemon/daemon-probe.js';
|
|
3
3
|
import { type HealthMarks } from '../../lib/daemon/daemon-health.js';
|
|
4
4
|
import { type StopResult } from '../../lib/daemon/daemon-stop.js';
|
|
5
5
|
import { type MoveReport } from './move.js';
|
|
@@ -20,12 +20,14 @@ export type DaemonStatus = ({
|
|
|
20
20
|
} & Health & HealthMarks)) & {
|
|
21
21
|
move?: MoveReport | null;
|
|
22
22
|
};
|
|
23
|
-
export declare const runDaemonStatus: (look?: (port: number, tries?: number, timeoutMs?: number) => Promise<
|
|
23
|
+
export declare const runDaemonStatus: (look?: (port: number, tries?: number, timeoutMs?: number) => Promise<Probe>) => Promise<DaemonStatus>;
|
|
24
24
|
export declare const runDaemonStop: (stop?: () => Promise<StopResult>) => Promise<{
|
|
25
25
|
stopped: boolean;
|
|
26
26
|
}>;
|
|
27
|
-
export declare const
|
|
27
|
+
export declare const settled: (port: number, look?: (port: number, tries?: number, timeoutMs?: number) => Promise<Probe>, timeoutMs?: number) => Promise<string[]>;
|
|
28
|
+
export declare const runDaemonRestart: (ensure?: () => Promise<number>, settle?: (port: number) => Promise<string[]>) => Promise<{
|
|
28
29
|
port: number;
|
|
30
|
+
settled: boolean;
|
|
29
31
|
}>;
|
|
30
32
|
type Action = (opts: DaemonOptions) => Promise<void>;
|
|
31
33
|
export interface DaemonActions {
|
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
import {} from 'commander';
|
|
2
2
|
import { ensureDaemon } from '../../lib/daemon/daemon-client.js';
|
|
3
3
|
import { isAlive, readDaemonFile } from '../../lib/daemon/daemon-file.js';
|
|
4
|
-
import { probeRetry, proven } from '../../lib/daemon/daemon-probe.js';
|
|
5
|
-
import {
|
|
4
|
+
import { PROGRESS_MS, probeRetry, proven, } from '../../lib/daemon/daemon-probe.js';
|
|
5
|
+
import { waitFor } from '../../lib/wait.js';
|
|
6
|
+
import { degradedReasons, healthLines, withSealError, } from '../../lib/daemon/daemon-health.js';
|
|
6
7
|
import { stopDaemon } from '../../lib/daemon/daemon-stop.js';
|
|
7
8
|
import { addJson } from '../../lib/json-output.js';
|
|
8
9
|
import { readMoveReport } from './move.js';
|
|
9
10
|
import { helpOrUnknown } from '../extension/list.js';
|
|
10
11
|
// Degraded always comes with its reasons, in the lines and in --json.
|
|
11
|
-
const report = (file,
|
|
12
|
+
const report = (file, found) => {
|
|
13
|
+
const live = withSealError(found);
|
|
12
14
|
console.log(`daemon: ${live.status} on 127.0.0.1:${file.port}, pid ${live.pid}, ${live.version}`);
|
|
13
15
|
const reasons = degradedReasons(live);
|
|
14
16
|
for (const line of healthLines(live, reasons))
|
|
15
17
|
console.log(line);
|
|
16
18
|
return { running: true, port: file.port, ...live, ...(reasons.length > 0 && { reasons }) };
|
|
17
19
|
};
|
|
18
|
-
//
|
|
19
|
-
// The D6 move's warning or skipped entries, until the user fixes them.
|
|
20
|
+
// The D6 move's warning or skipped entries; reads only, a stale daemon.json stays.
|
|
20
21
|
const moveLines = () => {
|
|
21
22
|
const move = readMoveReport();
|
|
22
23
|
if (move?.warning)
|
|
@@ -29,16 +30,31 @@ export const runDaemonStatus = async (look = probeRetry) => {
|
|
|
29
30
|
const status = await daemonStatus(look);
|
|
30
31
|
return { ...status, ...moveLines() };
|
|
31
32
|
};
|
|
33
|
+
// The probe is bounded (3 tries, 2 s each); a wait past 3 s says so on stderr.
|
|
34
|
+
const asked = async (file, look) => {
|
|
35
|
+
const slow = setTimeout(() => console.error(`waiting for the daemon (pid ${file.pid}) on 127.0.0.1:${file.port}...`), PROGRESS_MS);
|
|
36
|
+
try {
|
|
37
|
+
return await look(file.port);
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
clearTimeout(slow);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const silentLine = ({ pid, port }) => `daemon: pid ${pid} does not answer on 127.0.0.1:${port} (3 tries, 2 s each); ` +
|
|
44
|
+
'try again, or agentage daemon restart';
|
|
45
|
+
const notRunning = (file, found) => file && found?.kind === 'foreign'
|
|
46
|
+
? `daemon: not running (pid ${file.pid} of daemon.json lives, but 127.0.0.1:${file.port} answers as another program)`
|
|
47
|
+
: 'daemon: not running';
|
|
32
48
|
const daemonStatus = async (look) => {
|
|
33
49
|
const file = readDaemonFile();
|
|
34
|
-
const found = file && isAlive(file.pid) ? await
|
|
50
|
+
const found = file && isAlive(file.pid) ? await asked(file, look) : null;
|
|
35
51
|
if (file && found?.kind === 'silent') {
|
|
36
|
-
console.log(
|
|
52
|
+
console.log(silentLine(file));
|
|
37
53
|
return { running: false, unresponsive: true, pid: file.pid, port: file.port };
|
|
38
54
|
}
|
|
39
55
|
const live = file && found ? proven(file, found) : null;
|
|
40
56
|
if (!file || !live)
|
|
41
|
-
return (console.log(
|
|
57
|
+
return (console.log(notRunning(file, found)), { running: false });
|
|
42
58
|
return report(file, live);
|
|
43
59
|
};
|
|
44
60
|
const STOPPED = (result) => {
|
|
@@ -53,9 +69,28 @@ export const runDaemonStop = async (stop = () => stopDaemon()) => {
|
|
|
53
69
|
console.log(STOPPED(result));
|
|
54
70
|
return { stopped: result !== null && 'stopped' in result };
|
|
55
71
|
};
|
|
56
|
-
|
|
72
|
+
const SETTLE_MS = 60_000;
|
|
73
|
+
// Row 4 of S1.1.2: the ids still `starting` when the wait ran out ([] once none is).
|
|
74
|
+
export const settled = async (port, look = probeRetry, timeoutMs = SETTLE_MS) => {
|
|
75
|
+
let starting = [];
|
|
76
|
+
const none = async () => {
|
|
77
|
+
const found = await look(port);
|
|
78
|
+
if (found.kind !== 'ours')
|
|
79
|
+
return ((starting = []), true);
|
|
80
|
+
starting = found.health.extensions.filter((e) => e.state === 'starting').map((e) => e.id);
|
|
81
|
+
return starting.length === 0;
|
|
82
|
+
};
|
|
83
|
+
const line = 'waiting for the extensions to start...';
|
|
84
|
+
return (await waitFor(none, timeoutMs, { afterMs: PROGRESS_MS, line })) ? [] : starting;
|
|
85
|
+
};
|
|
86
|
+
// A wait that ran out is one warning, never a failure: the daemon runs and they may still start.
|
|
87
|
+
export const runDaemonRestart = async (ensure = () => ensureDaemon(), settle = settled) => {
|
|
57
88
|
await stopDaemon();
|
|
58
|
-
|
|
89
|
+
const port = await ensure();
|
|
90
|
+
const starting = await settle(port);
|
|
91
|
+
if (starting.length > 0)
|
|
92
|
+
console.error(`warning: still starting after ${SETTLE_MS / 1000} s: ${starting.join(', ')}`);
|
|
93
|
+
return { port, settled: starting.length === 0 };
|
|
59
94
|
};
|
|
60
95
|
const HELP = `
|
|
61
96
|
The daemon runs the installed extensions on 127.0.0.1 (port 4243, AGENTAGE_DAEMON_PORT for
|
|
@@ -7,5 +7,9 @@ export interface InstallerDeps {
|
|
|
7
7
|
market: () => Market;
|
|
8
8
|
}
|
|
9
9
|
export declare const installError: (code: string, status: 400 | 404 | 502, message: string) => Error;
|
|
10
|
+
export declare const distTagOf: (input: string) => {
|
|
11
|
+
name: string;
|
|
12
|
+
tag: string;
|
|
13
|
+
} | null;
|
|
10
14
|
export declare const cliInstaller: (deps: InstallerDeps) => Installer;
|
|
11
15
|
export declare const npmNewest: (manifest: () => Promise<NpmManifest>) => (id: string) => Promise<string>;
|
|
@@ -2,7 +2,9 @@ import { join } from 'node:path';
|
|
|
2
2
|
import { installedDir, installedName } from '../../core/installer/old-tree.js';
|
|
3
3
|
import { installPackage, packageDir } from '../../core/installer/package-dir.js';
|
|
4
4
|
import {} from '../../core/installer/npm.js';
|
|
5
|
-
import { registryLookup, resolveName } from '../../core/installer/resolve.js';
|
|
5
|
+
import { candidatesFor, registryLookup, resolveName, } from '../../core/installer/resolve.js';
|
|
6
|
+
import { isRange } from '../../core/semver-range.js';
|
|
7
|
+
import { DIST_TAG, isVersionSpec } from '../../core/installer/version-spec.js';
|
|
6
8
|
import { editableProfile } from '../../core/profile/profile.js';
|
|
7
9
|
import { isRecord, readJson } from '../../lib/fs/json-file.js';
|
|
8
10
|
import { messageOf } from '../../lib/json-output.js';
|
|
@@ -13,8 +15,7 @@ import { siteFqdn } from '../../lib/net/origins.js';
|
|
|
13
15
|
export const installError = (code, status, message) => Object.assign(new Error(message), { code, status });
|
|
14
16
|
// The market's own reason, in the daemon's case (market_failed is MARKET_FAILED).
|
|
15
17
|
const marketDown = (id, why) => installError(why.code.toUpperCase(), 502, `${id}: ${why.message}`);
|
|
16
|
-
//
|
|
17
|
-
// market the name id was installed under, else both names, as cli 0.51.1.
|
|
18
|
+
// A market: the scoped name only (anyone can publish the other); no market: as cli 0.51.1.
|
|
18
19
|
const npmName = (id, down) => noSiteMarket(down) ? (installedName(id) ?? id) : `@agentage/extension-${id}`;
|
|
19
20
|
// The market names the package and its newest version; without it npm alone decides.
|
|
20
21
|
const inputOf = async (id, version, market) => {
|
|
@@ -41,8 +42,31 @@ const resolveError = (err) => {
|
|
|
41
42
|
return installError('INSTALL_FAILED', 502, message);
|
|
42
43
|
return installError('VALIDATION_ERROR', 400, message);
|
|
43
44
|
};
|
|
44
|
-
//
|
|
45
|
+
// `fixture@broken`: a word that is not a range is a dist-tag, resolved by npm as npm does.
|
|
46
|
+
export const distTagOf = (input) => {
|
|
47
|
+
const at = input.lastIndexOf('@');
|
|
48
|
+
const tag = at > 0 ? input.slice(at + 1) : '';
|
|
49
|
+
return DIST_TAG.test(tag) && !isRange(tag) ? { name: input.slice(0, at), tag } : null;
|
|
50
|
+
};
|
|
51
|
+
const tagged = async (input, registry) => {
|
|
52
|
+
const { name, tag } = distTagOf(input) ?? { name: '', tag: '' };
|
|
53
|
+
for (const candidate of candidatesFor(name)) {
|
|
54
|
+
const found = await registry.find(`${candidate}@${tag}`).catch((err) => {
|
|
55
|
+
throw resolveError(err);
|
|
56
|
+
});
|
|
57
|
+
if (found)
|
|
58
|
+
return found;
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
};
|
|
62
|
+
// The one exact version npm has for a range, a version, a dist-tag, or the newest that fits.
|
|
45
63
|
const exact = async (input, registry) => {
|
|
64
|
+
if (distTagOf(input)) {
|
|
65
|
+
const found = await tagged(input, registry);
|
|
66
|
+
if (found)
|
|
67
|
+
return found;
|
|
68
|
+
throw installError('NOT_FOUND', 404, `${input}: npm has no such dist-tag`);
|
|
69
|
+
}
|
|
46
70
|
const target = await resolveName(input, registry).catch((err) => {
|
|
47
71
|
throw resolveError(err);
|
|
48
72
|
});
|
|
@@ -69,9 +93,10 @@ const fetched = async (id, found, deps) => {
|
|
|
69
93
|
throw installError('INSTALL_FAILED', 502, messageOf(err));
|
|
70
94
|
});
|
|
71
95
|
};
|
|
72
|
-
//
|
|
73
|
-
// otherwise the market, then npm into one folder per version (idempotent).
|
|
96
|
+
// A version on disk needs no network; else the market, then npm into one folder per version.
|
|
74
97
|
export const cliInstaller = (deps) => async ({ id, version }) => {
|
|
98
|
+
if (version !== undefined && !isVersionSpec(version))
|
|
99
|
+
throw installError('VALIDATION_ERROR', 400, `${id}@${version}: not a version, range or dist-tag`);
|
|
75
100
|
const have = version ? installedDir(id, version) : null;
|
|
76
101
|
if (version && have)
|
|
77
102
|
return { id, version, dir: have };
|
|
@@ -81,7 +106,6 @@ export const cliInstaller = (deps) => async ({ id, version }) => {
|
|
|
81
106
|
checkId(dir, id);
|
|
82
107
|
return { id, version: found.version, dir };
|
|
83
108
|
};
|
|
84
|
-
//
|
|
85
|
-
// on a site with no market); never another npm name for an installed row.
|
|
109
|
+
// No market: the newest runnable version of the npm name the row was installed under, no other.
|
|
86
110
|
export const npmNewest = (manifest) => async (id) => (await exact(installedName(id) ?? id, registryLookup(manifest, editableProfile().registries)))
|
|
87
111
|
.version;
|
|
@@ -4,6 +4,11 @@ import { getConfigDir } from '../../lib/fs/config.js';
|
|
|
4
4
|
import { CliError } from '../../lib/json-output.js';
|
|
5
5
|
import { VERSION } from '../../utils/version.js';
|
|
6
6
|
import { KIT_EXIT } from '../extension/kit-commands.js';
|
|
7
|
+
// C5: the test clock comes only from this env (the e2e lab); unset or empty is the real clock.
|
|
8
|
+
export const clockRateOf = (env = process.env) => {
|
|
9
|
+
const raw = env['AGENTAGE_DAEMON_CLOCK_RATE'];
|
|
10
|
+
return raw ? { clockRate: Number(raw) } : {};
|
|
11
|
+
};
|
|
7
12
|
const signalled = () => new Promise((resolve) => {
|
|
8
13
|
process.once('SIGTERM', resolve);
|
|
9
14
|
process.once('SIGINT', resolve);
|
|
@@ -29,7 +34,12 @@ export const runDaemon = async (deps) => {
|
|
|
29
34
|
const stopping = signalled();
|
|
30
35
|
await deps.before?.().catch(running);
|
|
31
36
|
const { createDaemon } = await import('@agentage/extension/host');
|
|
32
|
-
const opts = {
|
|
37
|
+
const opts = {
|
|
38
|
+
configDir: getConfigDir(),
|
|
39
|
+
port: daemonPort(),
|
|
40
|
+
version: VERSION,
|
|
41
|
+
...clockRateOf(),
|
|
42
|
+
};
|
|
33
43
|
const daemon = await createDaemon({ ...opts, install: deps.installer(), startedBy: 'cli' }).catch(busy);
|
|
34
44
|
await stopping;
|
|
35
45
|
await daemon.stop();
|
|
@@ -3,7 +3,7 @@ import { promisify } from 'node:util';
|
|
|
3
3
|
import {} from 'commander';
|
|
4
4
|
import { addJson, CliError, omitJson } from '../../lib/json-output.js';
|
|
5
5
|
import { loadKitTool } from './kit-tool.js';
|
|
6
|
-
import { buildPackage } from './package-build.js';
|
|
6
|
+
import { buildPackage, newerKitLine } from './package-build.js';
|
|
7
7
|
// With --json the written paths go to stderr, so stdout stays one JSON document.
|
|
8
8
|
const writeContracts = async (dir, tool, json) => {
|
|
9
9
|
for (const file of await (await tool()).writeContracts(dir))
|
|
@@ -19,8 +19,10 @@ export const runExtensionCheck = async ({ dir = '.', json, write } = {}, tool =
|
|
|
19
19
|
const fail = report.conforms ? undefined : lines.pop();
|
|
20
20
|
for (const line of json ? [JSON.stringify(report, null, 2)] : lines)
|
|
21
21
|
console.log(line);
|
|
22
|
-
if (
|
|
23
|
-
|
|
22
|
+
if (report.conforms)
|
|
23
|
+
return;
|
|
24
|
+
const newer = newerKitLine(dir);
|
|
25
|
+
throw new CliError('not_conforming', [fail ?? 'does not conform', newer].filter(Boolean).join('; '));
|
|
24
26
|
};
|
|
25
27
|
// The build record names HEAD, so the tree it builds must be HEAD.
|
|
26
28
|
export const assertCommitted = async (dir) => {
|
|
@@ -2,7 +2,8 @@ import { join } from 'node:path';
|
|
|
2
2
|
import { installationRows } from '../../core/loader/installed.js';
|
|
3
3
|
import { isRecord, readJson } from '../../lib/fs/json-file.js';
|
|
4
4
|
import { CliError, DaemonError, isJsonRun } from '../../lib/json-output.js';
|
|
5
|
-
import {
|
|
5
|
+
import { specOf } from './install-spec.js';
|
|
6
|
+
import { report } from './lifecycle.js';
|
|
6
7
|
const ENTER = ['\r', '\n', '\u0004'];
|
|
7
8
|
const CTRL_C = '\u0003';
|
|
8
9
|
const BACKSPACE = '\u007f';
|
|
@@ -7,7 +7,7 @@ import { CliError } from '../../lib/json-output.js';
|
|
|
7
7
|
import { loadKitTool } from './kit-tool.js';
|
|
8
8
|
import { confirmed, report, summaryOf, terminalIo } from './lifecycle.js';
|
|
9
9
|
import { ignoreLocal } from './up-local.js';
|
|
10
|
-
import { buildPackage, npmIn } from './package-build.js';
|
|
10
|
+
import { buildPackage, newerKitLine, npmIn } from './package-build.js';
|
|
11
11
|
export const createInstallDeps = {
|
|
12
12
|
npm: npmIn,
|
|
13
13
|
build: (dir) => buildPackage(dir),
|
|
@@ -45,7 +45,8 @@ const conforms = async (dir, deps) => {
|
|
|
45
45
|
return;
|
|
46
46
|
for (const text of (await deps.tool()).checkLines(checked))
|
|
47
47
|
console.error(`check ${text}`);
|
|
48
|
-
|
|
48
|
+
const newer = newerKitLine(dir);
|
|
49
|
+
throw new CliError('not_conforming', newer ?? `${dir} does not conform: agentage extension check`);
|
|
49
50
|
};
|
|
50
51
|
// After the scaffold: npm ci, the package build, then the daemon runs the folder (POST {source});
|
|
51
52
|
// --no-install leaves the scaffold as it is: no npm, no build.
|
|
@@ -14,4 +14,6 @@ export interface Installed {
|
|
|
14
14
|
}
|
|
15
15
|
export declare const addOnce: (host: HostClient, spec: IdBody) => Promise<Installed>;
|
|
16
16
|
export declare const installId: (host: HostClient, spec: IdBody) => Promise<Installed>;
|
|
17
|
+
export declare const real: (path: string) => string;
|
|
18
|
+
export declare const folderRow: (host: HostClient, id: string, dir: string) => Promise<HostRow | undefined>;
|
|
17
19
|
export declare const installFolder: (host: HostClient, source: string) => Promise<Installed>;
|
|
@@ -2,8 +2,7 @@ import { realpathSync } from 'node:fs';
|
|
|
2
2
|
import { existingOf } from '../../lib/daemon/daemon-answer.js';
|
|
3
3
|
import {} from '../../lib/daemon/host-client.js';
|
|
4
4
|
import { CliError, DaemonError } from '../../lib/json-output.js';
|
|
5
|
-
// The add
|
|
6
|
-
// whose details name the installed entry.
|
|
5
|
+
// The add is the check: of two cli runs, the second gets CONFLICT naming the installed entry.
|
|
7
6
|
const added = (host, body) => host.add(body).catch((err) => {
|
|
8
7
|
const existing = err instanceof DaemonError ? existingOf(err) : null;
|
|
9
8
|
if (existing)
|
|
@@ -32,7 +31,7 @@ export const installId = async (host, spec) => {
|
|
|
32
31
|
return { row: await host.change(id, { version: spec.version }), already: false };
|
|
33
32
|
return got;
|
|
34
33
|
};
|
|
35
|
-
const real = (path) => {
|
|
34
|
+
export const real = (path) => {
|
|
36
35
|
try {
|
|
37
36
|
return realpathSync(path);
|
|
38
37
|
}
|
|
@@ -40,8 +39,9 @@ const real = (path) => {
|
|
|
40
39
|
return path;
|
|
41
40
|
}
|
|
42
41
|
};
|
|
43
|
-
//
|
|
44
|
-
|
|
42
|
+
// The daemon's row of id when it runs this folder (by real path), else undefined.
|
|
43
|
+
export const folderRow = async (host, id, dir) => (await host.list()).find((row) => row.id === id && real(row.source) === real(dir));
|
|
44
|
+
// The same folder again (by real path) is installed already; its id from elsewhere is refused.
|
|
45
45
|
export const installFolder = async (host, source) => {
|
|
46
46
|
const got = await added(host, { source });
|
|
47
47
|
if (!isExisting(got))
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { isVersionSpec } from '../../core/installer/version-spec.js';
|
|
2
|
+
import { kitIdProblem } from '../../core/kit-id.js';
|
|
3
|
+
import { CliError } from '../../lib/json-output.js';
|
|
4
|
+
const ID = /^[a-z][a-z0-9-]*$/;
|
|
5
|
+
const PACKAGE_PREFIX = /^(@agentage\/extension-|agentage-extension-)/;
|
|
6
|
+
export const UNSCOPED = 'agentage-extension-';
|
|
7
|
+
// The daemon takes an id, not a package name: with a market it resolves only the scoped name.
|
|
8
|
+
export const unscoped = (name) => new CliError('invalid_argument', `${name}: an unscoped npm name installs only on a site with no market; nothing installed; install its folder instead: agentage extension install ./<folder>`);
|
|
9
|
+
// What 0.51 installed and the daemon does not: say what to type instead.
|
|
10
|
+
const refusedName = (name) => {
|
|
11
|
+
if (/^https?:\/\//i.test(name))
|
|
12
|
+
return `${name}: a tarball URL no longer installs; unpack it, then agentage extension install ./<folder>`;
|
|
13
|
+
if (name.startsWith('@') && !PACKAGE_PREFIX.test(name))
|
|
14
|
+
return `${name}: only @agentage/extension-<id> packages install, by id; for another package, install its folder (./path)`;
|
|
15
|
+
return null;
|
|
16
|
+
};
|
|
17
|
+
// `probe`, `probe@0.6.2`, or a package name of the id.
|
|
18
|
+
export const specOf = (name) => {
|
|
19
|
+
const refused = refusedName(name);
|
|
20
|
+
if (refused)
|
|
21
|
+
throw new CliError('invalid_argument', refused);
|
|
22
|
+
const at = name.indexOf('@', 1);
|
|
23
|
+
const id = (at < 0 ? name : name.slice(0, at)).replace(PACKAGE_PREFIX, '');
|
|
24
|
+
const version = at < 0 ? undefined : name.slice(at + 1);
|
|
25
|
+
if (!ID.test(id) || version === '')
|
|
26
|
+
throw new CliError('invalid_argument', `${name}: not an id, id@version or a folder (./path)`);
|
|
27
|
+
if (version !== undefined && !isVersionSpec(version))
|
|
28
|
+
throw new CliError('invalid_argument', `${name}: after @ only a version, a range or a dist-tag`);
|
|
29
|
+
const owned = kitIdProblem(id);
|
|
30
|
+
if (owned)
|
|
31
|
+
throw new CliError('invalid_argument', `${name}: ${owned}`);
|
|
32
|
+
return { id, ...(version && { version }) };
|
|
33
|
+
};
|
|
@@ -18,15 +18,12 @@ export interface RemoveOptions {
|
|
|
18
18
|
force?: boolean;
|
|
19
19
|
json?: boolean;
|
|
20
20
|
}
|
|
21
|
-
export declare const specOf: (name: string) => {
|
|
22
|
-
id: string;
|
|
23
|
-
version?: string;
|
|
24
|
-
};
|
|
25
21
|
export declare const summaryOf: ({ id, version, state, error }: HostSummary) => HostSummary;
|
|
26
22
|
export declare const report: (done: HostSummary, note?: string) => HostSummary;
|
|
27
23
|
export interface InstallDeps extends LifecycleDeps {
|
|
28
24
|
fromNpm?: (id: string, what: string) => Promise<string | null>;
|
|
29
25
|
hasMarket?: (id: string) => Promise<boolean>;
|
|
26
|
+
sealOff?: () => Promise<string | null>;
|
|
30
27
|
}
|
|
31
28
|
export declare const runInstall: (opts: InstallOptions, deps: InstallDeps) => Promise<HostSummary>;
|
|
32
29
|
export declare const runEnabled: (id: string, enabled: boolean, deps: LifecycleDeps) => Promise<HostSummary>;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { realpathSync } from 'node:fs';
|
|
2
2
|
import { createInterface } from 'node:readline/promises';
|
|
3
3
|
import { isAbsolute, join, resolve } from 'node:path';
|
|
4
|
-
import { kitIdProblem } from '../../core/kit-id.js';
|
|
5
4
|
import { unsafeDevPath } from '../../core/loader/dev-path.js';
|
|
6
5
|
import { prunePackages } from '../../core/installer/package-dir.js';
|
|
7
6
|
import { installationRows, versionsInUse } from '../../core/loader/installed.js';
|
|
@@ -10,35 +9,8 @@ import { isRecord, readJson } from '../../lib/fs/json-file.js';
|
|
|
10
9
|
import {} from '../../lib/daemon/host-client.js';
|
|
11
10
|
import { installFolder, installId } from './install-once.js';
|
|
12
11
|
import { CliError, isJsonRun } from '../../lib/json-output.js';
|
|
13
|
-
|
|
12
|
+
import { specOf, unscoped, UNSCOPED } from './install-spec.js';
|
|
14
13
|
const LOCAL = /^\.{1,2}(?:[/\\]|$)/;
|
|
15
|
-
const PACKAGE_PREFIX = /^(@agentage\/extension-|agentage-extension-)/;
|
|
16
|
-
const UNSCOPED = 'agentage-extension-';
|
|
17
|
-
// The daemon takes an id, not a package name: with a market it resolves only the scoped name.
|
|
18
|
-
const unscoped = (name) => new CliError('invalid_argument', `${name}: an unscoped npm name installs only on a site with no market; nothing installed; install its folder instead: agentage extension install ./<folder>`);
|
|
19
|
-
// What 0.51 installed and the daemon does not: say what to type instead.
|
|
20
|
-
const refusedName = (name) => {
|
|
21
|
-
if (/^https?:\/\//i.test(name))
|
|
22
|
-
return `${name}: a tarball URL no longer installs; unpack it, then agentage extension install ./<folder>`;
|
|
23
|
-
if (name.startsWith('@') && !PACKAGE_PREFIX.test(name))
|
|
24
|
-
return `${name}: only @agentage/extension-<id> packages install, by id; for another package, install its folder (./path)`;
|
|
25
|
-
return null;
|
|
26
|
-
};
|
|
27
|
-
// `probe`, `probe@0.6.2`, or a package name of the id.
|
|
28
|
-
export const specOf = (name) => {
|
|
29
|
-
const refused = refusedName(name);
|
|
30
|
-
if (refused)
|
|
31
|
-
throw new CliError('invalid_argument', refused);
|
|
32
|
-
const at = name.indexOf('@', 1);
|
|
33
|
-
const id = (at < 0 ? name : name.slice(0, at)).replace(PACKAGE_PREFIX, '');
|
|
34
|
-
const version = at < 0 ? undefined : name.slice(at + 1);
|
|
35
|
-
if (!ID.test(id) || version === '')
|
|
36
|
-
throw new CliError('invalid_argument', `${name}: not an id, id@version or a folder (./path)`);
|
|
37
|
-
const owned = kitIdProblem(id);
|
|
38
|
-
if (owned)
|
|
39
|
-
throw new CliError('invalid_argument', `${name}: ${owned}`);
|
|
40
|
-
return { id, ...(version && { version }) };
|
|
41
|
-
};
|
|
42
14
|
// The real path; a folder another user can write runs code as you, so it is refused.
|
|
43
15
|
const folderOf = (input) => {
|
|
44
16
|
let path;
|
|
@@ -66,19 +38,23 @@ export const report = (done, note = '') => {
|
|
|
66
38
|
console.log(`${done.id} ${done.version} ${done.state}${note}`);
|
|
67
39
|
return summaryOf(done);
|
|
68
40
|
};
|
|
41
|
+
// The install string is checked before the daemon starts: a bad one starts nothing.
|
|
69
42
|
export const runInstall = async (opts, deps) => {
|
|
70
|
-
const
|
|
71
|
-
const folder = LOCAL.test(opts.name) || isAbsolute(opts.name);
|
|
43
|
+
const folder = LOCAL.test(opts.name) || isAbsolute(opts.name) ? folderOf(opts.name) : null;
|
|
72
44
|
const spec = folder ? null : specOf(opts.name);
|
|
73
45
|
if (spec && opts.name.startsWith(UNSCOPED) && (await deps.hasMarket?.(spec.id)))
|
|
74
46
|
throw unscoped(opts.name);
|
|
47
|
+
const host = await deps.host();
|
|
75
48
|
const { row: done, already } = spec
|
|
76
49
|
? await installId(host, spec)
|
|
77
|
-
: await installFolder(host,
|
|
50
|
+
: await installFolder(host, folder ?? '');
|
|
78
51
|
const bare = spec && !spec.version && !already;
|
|
79
52
|
const line = bare && (await deps.fromNpm?.(spec.id, `${spec.id} ${done.version} came`));
|
|
80
53
|
if (line)
|
|
81
54
|
console.error(line);
|
|
55
|
+
const seal = await deps.sealOff?.().catch(() => null);
|
|
56
|
+
if (seal)
|
|
57
|
+
console.error(seal);
|
|
82
58
|
if (!opts.off)
|
|
83
59
|
return report(done, already ? ' (already installed)' : '');
|
|
84
60
|
console.error('install --off is now: agentage extension disable <id>');
|
|
@@ -1,7 +1,17 @@
|
|
|
1
|
+
import { type ChildProcess } from 'node:child_process';
|
|
1
2
|
import type { CheckReport } from '@agentage/extension/tool';
|
|
2
3
|
import { type LoadKitTool } from './kit-tool.js';
|
|
4
|
+
export declare const STEP_MS = 600000;
|
|
3
5
|
export type Npm = (dir: string, args: string[]) => Promise<void>;
|
|
4
|
-
export declare const
|
|
6
|
+
export declare const how: (code: number | null, signal: NodeJS.Signals | null) => string;
|
|
7
|
+
export declare const deadline: (child: ChildProcess, timeoutMs: number, graceMs: number) => {
|
|
8
|
+
late: () => boolean;
|
|
9
|
+
stop: () => void;
|
|
10
|
+
};
|
|
11
|
+
export declare const npmIn: (dir: string, args: string[], timeoutMs?: number, graceMs?: number, npmCli?: (opts?: import("../../lib/npm/npm-cli.js").ResolveNpmOptions) => string) => Promise<void>;
|
|
12
|
+
export declare const packageOf: (dir: string) => Record<string, unknown>;
|
|
13
|
+
export declare const buildScriptOf: (dir: string) => string | null;
|
|
14
|
+
export declare const newerKitLine: (dir: string, kit?: string) => string | null;
|
|
5
15
|
export interface PackageBuild {
|
|
6
16
|
dir: string;
|
|
7
17
|
built: boolean;
|
|
@@ -2,17 +2,25 @@ import { spawn } from 'node:child_process';
|
|
|
2
2
|
import { existsSync, readFileSync } from 'node:fs';
|
|
3
3
|
import { join, resolve } from 'node:path';
|
|
4
4
|
import { childEnv } from '../../lib/child-env.js';
|
|
5
|
-
import {
|
|
5
|
+
import { isRecord, readJson } from '../../lib/fs/json-file.js';
|
|
6
|
+
import { CliError, messageOf } from '../../lib/json-output.js';
|
|
7
|
+
import { resolveNpmCli } from '../../lib/npm/npm-cli.js';
|
|
8
|
+
import { compareVersions } from '../../lib/update/update-check.js';
|
|
9
|
+
import { kitVersion } from '../../core/kit-version.js';
|
|
6
10
|
import { loadKitTool } from './kit-tool.js';
|
|
7
|
-
const STEP_MS = 600_000;
|
|
11
|
+
export const STEP_MS = 600_000;
|
|
8
12
|
const GRACE_MS = 5_000;
|
|
9
13
|
const failed = (what, why) => new CliError('build_failed', `${what} ${why}`);
|
|
10
|
-
const how = (code, signal) => code === null ? `exited by signal ${signal ?? 'unknown'}` : `exited ${code}`;
|
|
11
|
-
// npm
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
export const how = (code, signal) => code === null ? `exited by signal ${signal ?? 'unknown'}` : `exited ${code}`;
|
|
15
|
+
// npm runs as `node npm-cli.js`: no npm.cmd shim, which Windows cannot spawn with no shell.
|
|
16
|
+
const spawnNpm = (dir, args, npmCli) => spawn(process.execPath, [npmCli(), ...args], {
|
|
17
|
+
cwd: dir,
|
|
18
|
+
env: childEnv(),
|
|
19
|
+
stdio: ['ignore', 2, 2],
|
|
20
|
+
windowsHide: true,
|
|
21
|
+
});
|
|
22
|
+
// Past its time SIGTERM, then SIGKILL after the grace time.
|
|
23
|
+
export const deadline = (child, timeoutMs, graceMs) => {
|
|
16
24
|
let late = false;
|
|
17
25
|
let kill;
|
|
18
26
|
const timer = setTimeout(() => {
|
|
@@ -20,27 +28,55 @@ export const npmIn = (dir, args, timeoutMs = STEP_MS, graceMs = GRACE_MS) => new
|
|
|
20
28
|
child.kill('SIGTERM');
|
|
21
29
|
kill = setTimeout(() => child.kill('SIGKILL'), graceMs);
|
|
22
30
|
}, timeoutMs);
|
|
23
|
-
|
|
24
|
-
|
|
31
|
+
return { late: () => late, stop: () => (clearTimeout(timer), clearTimeout(kill)) };
|
|
32
|
+
};
|
|
33
|
+
// npm's output to stderr (a --json stdout stays one object); past its time SIGTERM, then SIGKILL.
|
|
34
|
+
export const npmIn = (dir, args, timeoutMs = STEP_MS, graceMs = GRACE_MS, npmCli = resolveNpmCli) => new Promise((done, fail) => {
|
|
35
|
+
const what = `npm ${args.join(' ')} in ${dir}`;
|
|
36
|
+
const notStarted = (err) => fail(failed(what, `did not start: ${messageOf(err)}`));
|
|
37
|
+
let child;
|
|
38
|
+
try {
|
|
39
|
+
child = spawnNpm(dir, args, () => npmCli());
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
return notStarted(err);
|
|
43
|
+
}
|
|
44
|
+
const clock = deadline(child, timeoutMs, graceMs);
|
|
45
|
+
child.once('error', (err) => (clock.stop(), notStarted(err)));
|
|
25
46
|
child.once('exit', (code, signal) => {
|
|
26
|
-
stop();
|
|
47
|
+
clock.stop();
|
|
27
48
|
if (code === 0)
|
|
28
49
|
return done();
|
|
29
50
|
const stopped = `did not finish in ${timeoutMs / 1000} s; stopped (${how(code, signal)})`;
|
|
30
|
-
fail(failed(what, late ? stopped : how(code, signal)));
|
|
51
|
+
fail(failed(what, clock.late() ? stopped : how(code, signal)));
|
|
31
52
|
});
|
|
32
53
|
});
|
|
33
|
-
const
|
|
34
|
-
|
|
54
|
+
export const packageOf = (dir) => {
|
|
55
|
+
const file = join(dir, 'package.json');
|
|
56
|
+
if (!existsSync(file))
|
|
35
57
|
throw new CliError('invalid_argument', `no package.json in ${dir}: run it in an extension package folder`);
|
|
36
|
-
const pkg = JSON.parse(readFileSync(
|
|
37
|
-
return
|
|
58
|
+
const pkg = JSON.parse(readFileSync(file, 'utf8'));
|
|
59
|
+
return isRecord(pkg) ? pkg : {};
|
|
60
|
+
};
|
|
61
|
+
export const buildScriptOf = (dir) => {
|
|
62
|
+
const scripts = packageOf(dir)['scripts'];
|
|
63
|
+
const script = isRecord(scripts) ? scripts['build'] : undefined;
|
|
64
|
+
return typeof script === 'string' ? script : null;
|
|
65
|
+
};
|
|
66
|
+
// A package on a newer kit than this cli bundles fails the check for that cause only: say so.
|
|
67
|
+
export const newerKitLine = (dir, kit = kitVersion()) => {
|
|
68
|
+
const engines = readJson(join(dir, 'package.json'), isRecord)?.['engines'];
|
|
69
|
+
const range = isRecord(engines) ? engines['agentage'] : undefined;
|
|
70
|
+
const lowest = typeof range === 'string' ? /\d+\.\d+\.\d+/.exec(range)?.[0] : undefined;
|
|
71
|
+
if (!lowest || compareVersions(lowest, kit) <= 0)
|
|
72
|
+
return null;
|
|
73
|
+
return `this cli bundles kit ${kit}, the package needs kit ${String(range)}: update the cli (agentage update), then run it again`;
|
|
38
74
|
};
|
|
39
75
|
const defaultDeps = { npm: npmIn, tool: loadKitTool };
|
|
40
76
|
// The author's build script, the kit's contract files, then the kit's check; no Docker.
|
|
41
77
|
export const buildPackage = async (folder = '.', deps = defaultDeps) => {
|
|
42
78
|
const dir = resolve(folder);
|
|
43
|
-
const built =
|
|
79
|
+
const built = buildScriptOf(dir) !== null;
|
|
44
80
|
if (built)
|
|
45
81
|
await deps.npm(dir, ['run', 'build']);
|
|
46
82
|
const kit = await deps.tool();
|