@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.
- package/README.md +95 -127
- 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 +58 -16
- 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 -95
- 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/stack-owner.d.ts +4 -0
- package/dist/commands/extension/stack-owner.js +45 -0
- 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 +12 -11
- package/dist/commands/extension/up.js +65 -71
- 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
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { createServer } from 'node:http';
|
|
2
|
+
import { appendFileSync, existsSync, mkdirSync, readFileSync, rmSync } from 'node:fs';
|
|
3
|
+
import { join, resolve } from 'node:path';
|
|
4
|
+
import { isPid } from '../../lib/daemon/daemon-file.js';
|
|
5
|
+
import { isRecord, readJson, writeTextAtomic } from '../../lib/fs/json-file.js';
|
|
6
|
+
import { CliError, messageOf } from '../../lib/json-output.js';
|
|
7
|
+
import { waitFor } from '../../lib/wait.js';
|
|
8
|
+
// D7: a local up takes the first free port from here; the daemon keeps 4243.
|
|
9
|
+
export const UP_FROM = 4244;
|
|
10
|
+
// The kit's own folder in a working copy (`.agentage/`, ignored by the template).
|
|
11
|
+
const LOCAL = '.agentage';
|
|
12
|
+
export const recordPath = (dir) => join(resolve(dir), LOCAL, 'up.json');
|
|
13
|
+
export const dataDirOf = (dir) => join(resolve(dir), LOCAL, 'data');
|
|
14
|
+
const isUpRecord = (value) => isRecord(value) &&
|
|
15
|
+
isPid(value['pid']) &&
|
|
16
|
+
Number.isInteger(value['port']) &&
|
|
17
|
+
value['port'] >= 1024 &&
|
|
18
|
+
value['port'] <= 65535 &&
|
|
19
|
+
typeof value['id'] === 'string' &&
|
|
20
|
+
typeof value['instance'] === 'string';
|
|
21
|
+
export const readRecord = (dir) => readJson(recordPath(dir), isUpRecord);
|
|
22
|
+
// The run state stays out of git: `.agentage/` goes into the folder's .gitignore when missing.
|
|
23
|
+
export const ignoreLocal = (dir) => {
|
|
24
|
+
if (!existsSync(resolve(dir)))
|
|
25
|
+
return;
|
|
26
|
+
const file = join(resolve(dir), '.gitignore');
|
|
27
|
+
const text = existsSync(file) ? readFileSync(file, 'utf8') : '';
|
|
28
|
+
if (text.split('\n').some((line) => /^\/?\.agentage\/?$/.test(line.trim())))
|
|
29
|
+
return;
|
|
30
|
+
appendFileSync(file, `${text === '' || text.endsWith('\n') ? '' : '\n'}${LOCAL}/\n`);
|
|
31
|
+
console.error(`gitignore added ${LOCAL}/ to ${file}`);
|
|
32
|
+
};
|
|
33
|
+
export const writeRecord = (dir, record) => {
|
|
34
|
+
mkdirSync(join(resolve(dir), LOCAL), { recursive: true });
|
|
35
|
+
ignoreLocal(dir);
|
|
36
|
+
writeTextAtomic(recordPath(dir), `${JSON.stringify(record)}\n`);
|
|
37
|
+
};
|
|
38
|
+
export const removeRecord = (dir) => rmSync(recordPath(dir), { force: true });
|
|
39
|
+
const bind = (handler, port) => new Promise((done, fail) => {
|
|
40
|
+
const server = createServer(handler);
|
|
41
|
+
server.once('error', (err) => err.code === 'EADDRINUSE' ? done(null) : fail(err));
|
|
42
|
+
server.listen(port, '127.0.0.1', () => done(server));
|
|
43
|
+
});
|
|
44
|
+
// D7: the first port from 4244 that binds; a port taken meanwhile is skipped, not fatal.
|
|
45
|
+
export const listenFrom = async (handler, from = UP_FROM) => {
|
|
46
|
+
for (let port = from; port < from + 100; port += 1) {
|
|
47
|
+
const server = await bind(handler, port);
|
|
48
|
+
if (server)
|
|
49
|
+
return server;
|
|
50
|
+
}
|
|
51
|
+
throw new CliError('port_in_use', `no free port from ${from} to ${from + 99}`);
|
|
52
|
+
};
|
|
53
|
+
export const portOf = (server) => server.address().port;
|
|
54
|
+
// The record's extension answers on its port when /health names the same id and instance.
|
|
55
|
+
export const answerOf = async (record, timeoutMs = 2_000) => {
|
|
56
|
+
const res = await fetch(`http://127.0.0.1:${record.port}/health`, {
|
|
57
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
58
|
+
}).catch(() => null);
|
|
59
|
+
if (!res)
|
|
60
|
+
return 'none';
|
|
61
|
+
const body = (await res.json().catch(() => null));
|
|
62
|
+
const same = body?.data?.extension === record.id && body.data.instance === record.instance;
|
|
63
|
+
return same ? 'ours' : 'other';
|
|
64
|
+
};
|
|
65
|
+
// Resolves on the first SIGINT or SIGTERM, then releases both.
|
|
66
|
+
export const untilSignal = () => new Promise((done) => {
|
|
67
|
+
const on = (signal) => {
|
|
68
|
+
process.off('SIGINT', on);
|
|
69
|
+
process.off('SIGTERM', on);
|
|
70
|
+
done(signal);
|
|
71
|
+
};
|
|
72
|
+
process.once('SIGINT', on);
|
|
73
|
+
process.once('SIGTERM', on);
|
|
74
|
+
});
|
|
75
|
+
const gone = (record, timeoutMs) => waitFor(async () => (await answerOf(record, 500)) === 'none', timeoutMs);
|
|
76
|
+
// Signals the recorded pid only when its port answers as that extension; else the record is stale.
|
|
77
|
+
export const stopLocal = async (dir, timeoutMs = 10_000) => {
|
|
78
|
+
const record = readRecord(dir);
|
|
79
|
+
if (!record)
|
|
80
|
+
return 'none';
|
|
81
|
+
if ((await answerOf(record)) !== 'ours')
|
|
82
|
+
return (removeRecord(dir), 'stale');
|
|
83
|
+
try {
|
|
84
|
+
process.kill(record.pid, 'SIGTERM');
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
const why = messageOf(err);
|
|
88
|
+
throw new CliError('stop_failed', `cannot stop extension up (pid ${record.pid}): ${why}`);
|
|
89
|
+
}
|
|
90
|
+
if (!(await gone(record, timeoutMs)))
|
|
91
|
+
throw new CliError('stop_failed', `extension up (pid ${record.pid}) did not stop`);
|
|
92
|
+
removeRecord(dir);
|
|
93
|
+
return 'stopped';
|
|
94
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type * as KitHostModule from '@agentage/extension/host';
|
|
2
|
+
import type { HostedExtension, HostOptions } from '@agentage/extension/host';
|
|
3
|
+
import { type PackageBuild } from './package-build.js';
|
|
4
|
+
export interface KitHost {
|
|
5
|
+
host: (dir: string, opts: HostOptions) => Promise<HostedExtension>;
|
|
6
|
+
}
|
|
7
|
+
type KitModule = Pick<typeof KitHostModule, 'hostExtension'>;
|
|
8
|
+
export declare const loadKitHost: (load?: () => Promise<KitModule>) => Promise<KitHost>;
|
|
9
|
+
export interface LocalUpDeps {
|
|
10
|
+
build: (dir: string) => Promise<PackageBuild>;
|
|
11
|
+
kit: () => Promise<KitHost>;
|
|
12
|
+
stopped: () => Promise<string>;
|
|
13
|
+
}
|
|
14
|
+
export declare const localUpDeps: LocalUpDeps;
|
|
15
|
+
export interface LocalUp {
|
|
16
|
+
id: string;
|
|
17
|
+
version: string;
|
|
18
|
+
url: string;
|
|
19
|
+
port: number;
|
|
20
|
+
stoppedBy: string;
|
|
21
|
+
}
|
|
22
|
+
export declare const runLocalUp: (folder?: string, deps?: LocalUpDeps, json?: boolean) => Promise<LocalUp>;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import {} from 'node:http';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { setExit } from '../../lib/exit-code.js';
|
|
4
|
+
import { CliError } from '../../lib/json-output.js';
|
|
5
|
+
import { loadKitTool } from './kit-tool.js';
|
|
6
|
+
import { buildPackage } from './package-build.js';
|
|
7
|
+
import { answerOf, dataDirOf, listenFrom, portOf, readRecord, removeRecord, untilSignal, writeRecord, } from './up-local.js';
|
|
8
|
+
export const loadKitHost = async (load = () => import('@agentage/extension/host')) => {
|
|
9
|
+
const kit = await load();
|
|
10
|
+
return { host: (dir, opts) => kit.hostExtension(dir, { ...opts, localOnly: true }) };
|
|
11
|
+
};
|
|
12
|
+
export const localUpDeps = {
|
|
13
|
+
build: (dir) => buildPackage(dir),
|
|
14
|
+
kit: () => loadKitHost(),
|
|
15
|
+
stopped: untilSignal,
|
|
16
|
+
};
|
|
17
|
+
const refuseRunning = async (dir) => {
|
|
18
|
+
const record = readRecord(dir);
|
|
19
|
+
if (!record)
|
|
20
|
+
return;
|
|
21
|
+
if ((await answerOf(record)) !== 'ours')
|
|
22
|
+
return removeRecord(dir);
|
|
23
|
+
const at = `http://127.0.0.1:${record.port}`;
|
|
24
|
+
throw new CliError('already_running', `extension up runs for ${dir} on ${at}: extension down`);
|
|
25
|
+
};
|
|
26
|
+
// Problems do not stop a local run; they are printed, as `extension build` would refuse them.
|
|
27
|
+
const warnProblems = async ({ report }) => {
|
|
28
|
+
if (report.conforms)
|
|
29
|
+
return;
|
|
30
|
+
for (const text of (await loadKitTool()).checkLines(report))
|
|
31
|
+
console.error(`check ${text}`);
|
|
32
|
+
};
|
|
33
|
+
const serve = (hosted) => listenFrom(hosted.app);
|
|
34
|
+
const close = async (server, hosted, dir) => {
|
|
35
|
+
server?.closeAllConnections();
|
|
36
|
+
await Promise.all([server && new Promise((done) => server.close(done)), hosted.stop()]);
|
|
37
|
+
removeRecord(dir);
|
|
38
|
+
};
|
|
39
|
+
// Ready: the line, and with --json one JSON line on stdout before the envelope at exit.
|
|
40
|
+
const ready = (hosted, url, port, json) => {
|
|
41
|
+
console.log(`up ${hosted.id} ${hosted.version} on ${url} (Ctrl-C stops it)`);
|
|
42
|
+
const line = { ready: true, id: hosted.id, version: hosted.version, url, port };
|
|
43
|
+
if (json)
|
|
44
|
+
process.stdout.write(`${JSON.stringify(line)}\n`);
|
|
45
|
+
};
|
|
46
|
+
const runHosted = async (dir, hosted, deps, json) => {
|
|
47
|
+
let server = null;
|
|
48
|
+
try {
|
|
49
|
+
server = await serve(hosted);
|
|
50
|
+
const port = portOf(server);
|
|
51
|
+
const { instance } = (await hosted.health()).data;
|
|
52
|
+
writeRecord(dir, { pid: process.pid, port, id: hosted.id, instance });
|
|
53
|
+
const url = `http://127.0.0.1:${port}/api/${hosted.id}/`;
|
|
54
|
+
ready(hosted, url, port, json);
|
|
55
|
+
const stoppedBy = await deps.stopped();
|
|
56
|
+
return { id: hosted.id, version: hosted.version, url, port, stoppedBy };
|
|
57
|
+
}
|
|
58
|
+
finally {
|
|
59
|
+
await close(server, hosted, dir);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
// D7: the working copy in this terminal, on the next free port from 4244, until Ctrl-C (exit 130).
|
|
63
|
+
export const runLocalUp = async (folder = '.', deps = localUpDeps, json = false) => {
|
|
64
|
+
const dir = resolve(folder);
|
|
65
|
+
await refuseRunning(dir);
|
|
66
|
+
await warnProblems(await deps.build(dir));
|
|
67
|
+
delete process.env['AGENTAGE_TOKEN'];
|
|
68
|
+
const kit = await deps.kit();
|
|
69
|
+
const hosted = await kit.host(dir, { dataDir: dataDirOf(dir) });
|
|
70
|
+
const done = await runHosted(dir, hosted, deps, json);
|
|
71
|
+
console.log(`stopped ${done.id} (${done.stoppedBy})`);
|
|
72
|
+
if (done.stoppedBy === 'SIGINT')
|
|
73
|
+
setExit(130);
|
|
74
|
+
return done;
|
|
75
|
+
};
|
|
@@ -1,22 +1,23 @@
|
|
|
1
|
-
import { type Command } from 'commander';
|
|
2
1
|
import { type LoadKitTool } from './kit-tool.js';
|
|
2
|
+
import { type Exec } from './release-guard.js';
|
|
3
3
|
export interface ExtensionUpOptions {
|
|
4
4
|
dir?: string;
|
|
5
|
+
json?: boolean;
|
|
5
6
|
}
|
|
6
7
|
export interface ExtensionDownOptions extends ExtensionUpOptions {
|
|
7
8
|
keepData?: boolean;
|
|
8
9
|
}
|
|
9
|
-
export interface ExtensionTokenOptions {
|
|
10
|
+
export interface ExtensionTokenOptions extends ExtensionUpOptions {
|
|
10
11
|
scope: string;
|
|
11
12
|
issuer?: string;
|
|
12
13
|
}
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export declare const issuerUrl: (value: string) => string;
|
|
17
|
-
export interface KitActions {
|
|
18
|
-
up: (opts: ExtensionUpOptions) => Promise<void>;
|
|
19
|
-
down: (opts: ExtensionDownOptions) => Promise<void>;
|
|
20
|
-
token: (opts: ExtensionTokenOptions) => Promise<void>;
|
|
14
|
+
export interface ExtensionUpFlags extends ExtensionUpOptions {
|
|
15
|
+
docker?: boolean;
|
|
16
|
+
local?: boolean;
|
|
21
17
|
}
|
|
22
|
-
export declare const
|
|
18
|
+
export declare const UP_CHANGED = "extension up now runs with no Docker; the Docker stack is `extension up --docker`";
|
|
19
|
+
type LocalRun = (dir: string | undefined, json: boolean) => Promise<unknown>;
|
|
20
|
+
export declare const runExtensionUp: ({ docker, local: asked, ...opts }?: ExtensionUpFlags, tool?: LoadKitTool, local?: LocalRun, env?: NodeJS.ProcessEnv, tty?: boolean) => Promise<unknown>;
|
|
21
|
+
export declare const runExtensionDown: (opts?: ExtensionDownOptions, tool?: LoadKitTool) => Promise<unknown>;
|
|
22
|
+
export declare const runExtensionToken: ({ dir, json, ...opts }: ExtensionTokenOptions, tool?: LoadKitTool, exec?: Exec) => Promise<unknown>;
|
|
23
|
+
export {};
|
|
@@ -1,80 +1,74 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { join, resolve } from 'node:path';
|
|
3
|
+
import { CliError, omitJson } from '../../lib/json-output.js';
|
|
2
4
|
import { loadKitTool } from './kit-tool.js';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
import { execIn } from './release-guard.js';
|
|
6
|
+
import { assertOwnStack } from './stack-owner.js';
|
|
7
|
+
import { stopLocal } from './up-local.js';
|
|
8
|
+
import { runLocalUp } from './up-run.js';
|
|
9
|
+
// Prints each line as the kit reports it and keeps them for the --json answer.
|
|
10
|
+
const printed = () => {
|
|
11
|
+
const lines = [];
|
|
12
|
+
return { lines, onLine: (line) => void (console.log(line), lines.push(line)) };
|
|
8
13
|
};
|
|
9
|
-
export const
|
|
10
|
-
|
|
11
|
-
|
|
14
|
+
export const UP_CHANGED = 'extension up now runs with no Docker; the Docker stack is `extension up --docker`';
|
|
15
|
+
// CI=false, 0 or empty is not CI.
|
|
16
|
+
const inCi = (env) => !['', 'false', '0', undefined].includes(env['CI']);
|
|
17
|
+
// 0.51's up was Docker: a CI script with neither flag asked for that, so it stops instead.
|
|
18
|
+
const noticeChange = ({ local }, env, tty) => {
|
|
19
|
+
if (local)
|
|
20
|
+
return;
|
|
21
|
+
if (inCi(env) && !tty)
|
|
22
|
+
throw new CliError('invalid_argument', `${UP_CHANGED}; or --local`);
|
|
23
|
+
console.error(UP_CHANGED);
|
|
12
24
|
};
|
|
13
|
-
//
|
|
14
|
-
export const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
let protocol;
|
|
21
|
-
try {
|
|
22
|
-
protocol = new URL(value).protocol;
|
|
23
|
-
}
|
|
24
|
-
catch {
|
|
25
|
-
throw new InvalidArgumentError('not a URL.');
|
|
25
|
+
// No Docker: the working copy in this terminal (D7). --docker: the kit's path, a line per step.
|
|
26
|
+
export const runExtensionUp = async ({ docker, local: asked, ...opts } = {}, tool = loadKitTool, local = (dir, json) => runLocalUp(dir, undefined, json), env = process.env, tty = process.stdin.isTTY === true) => {
|
|
27
|
+
if (docker && asked)
|
|
28
|
+
throw new CliError('invalid_argument', '--docker and --local: pick one');
|
|
29
|
+
if (!docker) {
|
|
30
|
+
noticeChange({ local: asked }, env, tty);
|
|
31
|
+
return local(opts.dir, opts.json === true);
|
|
26
32
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
33
|
+
const { up } = await tool();
|
|
34
|
+
const { lines, onLine } = printed();
|
|
35
|
+
await up({ ...omitJson(opts), onLine });
|
|
36
|
+
return { lines };
|
|
30
37
|
};
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
on a kept store says what was already applied. Prints one line per step as the kit reports it,
|
|
37
|
-
the last one once every part is healthy. Needs docker; every docker call has a timeout. Exits 1
|
|
38
|
-
when a step fails, with the kit's message.`;
|
|
39
|
-
const DOWN_HELP = `
|
|
40
|
-
Removes what agentage extension up started for the package in --dir, and nothing else: its
|
|
41
|
-
containers, network and the store's volume; --keep-data keeps the volume. The line it prints
|
|
42
|
-
names the compose project it removed. Exits 1 when that fails.`;
|
|
43
|
-
const TOKEN_HELP = `
|
|
44
|
-
Prints a token from the dev issuer agentage extension up started, alone on stdout, for calling
|
|
45
|
-
/api/v1/ and /mcp by hand or from tests. Only up trusts it. Exits 1 when the issuer refuses or
|
|
46
|
-
does not answer within 5 s.`;
|
|
47
|
-
const DIR = '--dir <path>';
|
|
48
|
-
const DIR_TEXT = 'the extension package folder (default: the current folder)';
|
|
49
|
-
const addUp = (group, up) => {
|
|
50
|
-
group
|
|
51
|
-
.command('up')
|
|
52
|
-
.description('Run the extension package on this machine: images, store, issuer, gateway')
|
|
53
|
-
.option(DIR, DIR_TEXT)
|
|
54
|
-
.addHelpText('after', UP_HELP)
|
|
55
|
-
.action(up);
|
|
38
|
+
const dockerDown = async (opts, tool) => {
|
|
39
|
+
const { down } = await tool();
|
|
40
|
+
const { lines, onLine } = printed();
|
|
41
|
+
await down({ ...omitJson(opts), onLine });
|
|
42
|
+
return lines;
|
|
56
43
|
};
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
.option(DIR, DIR_TEXT)
|
|
62
|
-
.option('--keep-data', "keep the store's volume")
|
|
63
|
-
.addHelpText('after', DOWN_HELP)
|
|
64
|
-
.action(down);
|
|
44
|
+
const LOCAL_LINES = {
|
|
45
|
+
stopped: 'stopped extension up in this folder',
|
|
46
|
+
stale: 'removed a stale extension up record (its port no longer answers as it)',
|
|
47
|
+
none: '',
|
|
65
48
|
};
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
.
|
|
73
|
-
|
|
49
|
+
// A local up of the folder stops; a Docker stack up --docker started there goes too.
|
|
50
|
+
export const runExtensionDown = async (opts = {}, tool = loadKitTool) => {
|
|
51
|
+
const dir = opts.dir ?? '.';
|
|
52
|
+
const local = await stopLocal(dir);
|
|
53
|
+
const lines = local === 'none' ? [] : [LOCAL_LINES[local]];
|
|
54
|
+
for (const line of lines)
|
|
55
|
+
console.log(line);
|
|
56
|
+
if (existsSync(join(dir, '.agentage', 'compose.json')))
|
|
57
|
+
lines.push(...(await dockerDown(opts, tool)));
|
|
58
|
+
if (lines.length === 0) {
|
|
59
|
+
lines.push(`nothing runs for ${resolve(dir)}`);
|
|
60
|
+
console.log(lines[0]);
|
|
61
|
+
}
|
|
62
|
+
return { local, lines };
|
|
74
63
|
};
|
|
75
|
-
//
|
|
76
|
-
export const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
64
|
+
// The token alone on stdout, so a script can take it as it is.
|
|
65
|
+
export const runExtensionToken = async ({ dir = '.', json, ...opts }, tool = loadKitTool, exec = execIn('.', 10)) => {
|
|
66
|
+
if (!opts.issuer)
|
|
67
|
+
await assertOwnStack(dir, exec, tool);
|
|
68
|
+
const { token } = await tool();
|
|
69
|
+
const value = await token(opts);
|
|
70
|
+
if (json)
|
|
71
|
+
return { token: value };
|
|
72
|
+
console.log(value);
|
|
73
|
+
return undefined;
|
|
80
74
|
};
|
|
@@ -7,10 +7,18 @@ export interface UpdateDeps {
|
|
|
7
7
|
install: () => Promise<void>;
|
|
8
8
|
acquireLock: () => boolean;
|
|
9
9
|
releaseLock: () => void;
|
|
10
|
+
restartDaemon: () => Promise<unknown>;
|
|
10
11
|
log: (msg: string) => void;
|
|
11
12
|
}
|
|
12
13
|
export interface UpdateOptions {
|
|
13
14
|
check?: boolean;
|
|
15
|
+
json?: boolean;
|
|
14
16
|
}
|
|
15
|
-
export
|
|
17
|
+
export interface UpdateResult {
|
|
18
|
+
installed: string;
|
|
19
|
+
status: UpdateInfo['status']['kind'];
|
|
20
|
+
latest: string | null;
|
|
21
|
+
updated: boolean;
|
|
22
|
+
}
|
|
23
|
+
export declare const runUpdate: (opts: UpdateOptions, deps?: UpdateDeps) => Promise<UpdateResult>;
|
|
16
24
|
export declare const registerUpdate: (program: Command, action: (opts: UpdateOptions) => Promise<void>) => void;
|
|
@@ -4,6 +4,8 @@ import {} from 'commander';
|
|
|
4
4
|
import { getConfigDir } from '../../lib/fs/config.js';
|
|
5
5
|
import { acquireFileLock, releaseFileLock } from '../../lib/fs/file-lock.js';
|
|
6
6
|
import { requireNpm10, runNpm } from '../../lib/npm/npm-cli.js';
|
|
7
|
+
import { restartIfRunning } from '../../lib/daemon/daemon-client.js';
|
|
8
|
+
import { addJson, messageOf } from '../../lib/json-output.js';
|
|
7
9
|
import { checkForUpdate, INSTALL_HINT } from '../../lib/update/update-check.js';
|
|
8
10
|
import { VERSION } from '../../utils/version.js';
|
|
9
11
|
const INSTALL_TIMEOUT_MS = 5 * 60_000;
|
|
@@ -25,6 +27,7 @@ const defaultDeps = {
|
|
|
25
27
|
install: () => installLatest(),
|
|
26
28
|
acquireLock: () => acquireFileLock(updateLockTarget(), Date.now(), UPDATE_LOCK),
|
|
27
29
|
releaseLock: () => releaseFileLock(updateLockTarget()),
|
|
30
|
+
restartDaemon: () => restartIfRunning(),
|
|
28
31
|
log: (msg) => console.log(msg),
|
|
29
32
|
};
|
|
30
33
|
const describe = (info) => {
|
|
@@ -44,29 +47,40 @@ const install = async (deps) => {
|
|
|
44
47
|
deps.log('Installing the latest @agentage/cli...');
|
|
45
48
|
await deps.install();
|
|
46
49
|
deps.log(chalk.green('Updated. Run `agentage status` to confirm.'));
|
|
50
|
+
// The running daemon still holds the old code; a failed restart leaves the next command to it.
|
|
51
|
+
await deps
|
|
52
|
+
.restartDaemon()
|
|
53
|
+
.catch((err) => deps.log(`daemon not restarted: ${messageOf(err)}`));
|
|
47
54
|
};
|
|
48
55
|
// --check never installs; otherwise install only when behind, under a single-writer lock.
|
|
49
56
|
export const runUpdate = async (opts, deps = defaultDeps) => {
|
|
50
57
|
const info = await deps.check(VERSION);
|
|
51
58
|
deps.log(describe(info));
|
|
52
|
-
const
|
|
59
|
+
const { status } = info;
|
|
60
|
+
const result = {
|
|
61
|
+
installed: VERSION,
|
|
62
|
+
status: status.kind,
|
|
63
|
+
latest: 'latest' in status ? (status.latest ?? null) : null,
|
|
64
|
+
updated: false,
|
|
65
|
+
};
|
|
66
|
+
const behind = status.kind === 'update-available' || status.kind === 'unsupported';
|
|
53
67
|
if (opts.check || !behind)
|
|
54
|
-
return;
|
|
68
|
+
return result;
|
|
55
69
|
if (!deps.acquireLock()) {
|
|
56
70
|
deps.log(chalk.yellow('Another update is already in progress; skipping.'));
|
|
57
|
-
return;
|
|
71
|
+
return result;
|
|
58
72
|
}
|
|
59
73
|
try {
|
|
60
74
|
await install(deps);
|
|
75
|
+
return { ...result, updated: true };
|
|
61
76
|
}
|
|
62
77
|
finally {
|
|
63
78
|
deps.releaseLock();
|
|
64
79
|
}
|
|
65
80
|
};
|
|
66
81
|
export const registerUpdate = (program, action) => {
|
|
67
|
-
program
|
|
82
|
+
addJson(program
|
|
68
83
|
.command('update')
|
|
69
84
|
.description('Update @agentage/cli to the latest published version')
|
|
70
|
-
.option('--check', 'report whether an update is available, without installing')
|
|
71
|
-
.action(action);
|
|
85
|
+
.option('--check', 'report whether an update is available, without installing')).action(action);
|
|
72
86
|
};
|
|
@@ -2,7 +2,5 @@ type Doc = Record<string, unknown>;
|
|
|
2
2
|
export declare const parseLock: (raw: string | null) => Doc | null;
|
|
3
3
|
export declare const lockEntries: (lock: Doc) => string[];
|
|
4
4
|
export declare const rootDependencies: (lock: Doc) => Record<string, string>;
|
|
5
|
-
export declare const lockedVersion: (lock: Doc | null, name: string) => string | null;
|
|
6
|
-
export declare const lockAgrees: (lock: Doc, dependencies: Record<string, string>) => boolean;
|
|
7
5
|
export declare const integrityDrift: (a: Doc, b: Doc) => string[];
|
|
8
6
|
export {};
|
|
@@ -28,18 +28,6 @@ export const rootDependencies = (lock) => {
|
|
|
28
28
|
const deps = isRecord(root) && isRecord(root['dependencies']) ? root['dependencies'] : {};
|
|
29
29
|
return Object.fromEntries(Object.entries(deps).map(([name, spec]) => [name, text(spec)]));
|
|
30
30
|
};
|
|
31
|
-
// The version the lock installed for a root dependency; null when it has none.
|
|
32
|
-
export const lockedVersion = (lock, name) => {
|
|
33
|
-
const entry = lock === null ? null : packagesOf(lock)[`${NODE_MODULES}${name}`];
|
|
34
|
-
return isRecord(entry) && typeof entry['version'] === 'string' ? entry['version'] : null;
|
|
35
|
-
};
|
|
36
|
-
// npm ci refuses a lock whose root dependencies differ from package.json.
|
|
37
|
-
export const lockAgrees = (lock, dependencies) => {
|
|
38
|
-
const locked = rootDependencies(lock);
|
|
39
|
-
const names = Object.keys(dependencies);
|
|
40
|
-
return (Object.keys(locked).length === names.length &&
|
|
41
|
-
names.every((name) => locked[name] === dependencies[name]));
|
|
42
|
-
};
|
|
43
31
|
const integrities = (lock) => new Map(installed(lock).map(([path, entry]) => [nameAt(path, entry), text(entry['integrity'])]));
|
|
44
32
|
// The same name@version with another integrity: one of the two locks was changed by hand.
|
|
45
33
|
export const integrityDrift = (a, b) => {
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { EXTENSION_API_VERSION } from '../../extension.js';
|
|
2
2
|
import { isRecord } from '../../lib/fs/json-file.js';
|
|
3
3
|
import { kitVersion } from '../kit-version.js';
|
|
4
|
-
import { manifestInfo } from '../loader/manifest.js';
|
|
4
|
+
import { manifestInfo, onPreviousKit } from '../loader/manifest.js';
|
|
5
5
|
import { isRange, newestFirst, satisfies } from '../semver-range.js';
|
|
6
6
|
export const cliGate = () => ({ api: EXTENSION_API_VERSION, kit: kitVersion() });
|
|
7
7
|
export const fitsApi = (engine, api = EXTENSION_API_VERSION) => isRange(engine) && satisfies(api, engine);
|
|
8
|
-
// The gate picks the API by manifest shape.
|
|
9
|
-
export const fits = (p, gate = cliGate()) =>
|
|
8
|
+
// The gate picks the API by manifest shape; a kit-shaped range may also be the previous kit minor.
|
|
9
|
+
export const fits = (p, gate = cliGate()) => p.kit
|
|
10
|
+
? fitsApi(p.engine, gate.kit) || onPreviousKit(p.engine, gate.kit)
|
|
11
|
+
: fitsApi(p.engine, gate.api);
|
|
10
12
|
export const needsText = ({ engine, kit }) => `needs ${kit ? 'kit' : 'extension API'} ${engine}`;
|
|
11
13
|
export const needs = (p) => `${p.version}: ${needsText(p)}`;
|
|
12
14
|
// The resolver's rule: the newest version this CLI can load, instead of whatever `latest` is.
|
|
@@ -9,3 +9,4 @@ export declare const manifestArgs: (command: LookupCommand, spec: string, regist
|
|
|
9
9
|
export declare const npmMajor: (env?: NodeJS.ProcessEnv) => Promise<number>;
|
|
10
10
|
export declare const prepareNpm: (env?: NodeJS.ProcessEnv) => Promise<Npm>;
|
|
11
11
|
export declare const prepareManifest: (env?: NodeJS.ProcessEnv) => Promise<NpmManifest>;
|
|
12
|
+
export declare const lastLines: (output: string, count?: number) => string;
|
|
@@ -74,3 +74,9 @@ export const prepareManifest = async (env = process.env) => {
|
|
|
74
74
|
npmCli,
|
|
75
75
|
});
|
|
76
76
|
};
|
|
77
|
+
// npm's last lines, enough to see why it failed.
|
|
78
|
+
export const lastLines = (output, count = 20) => output
|
|
79
|
+
.split(/\r?\n/)
|
|
80
|
+
.filter((line) => line.trim() !== '')
|
|
81
|
+
.slice(-count)
|
|
82
|
+
.join('\n');
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { readdirSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { isRecord, readJson } from '../../lib/fs/json-file.js';
|
|
4
|
+
import { currentTree } from '../loader/discover.js';
|
|
5
|
+
import { extensionsDir } from '../paths.js';
|
|
6
|
+
import { packageDir, packagesDir } from './package-dir.js';
|
|
7
|
+
const names = (dir) => {
|
|
8
|
+
try {
|
|
9
|
+
return readdirSync(dir);
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
// Every package folder in a node_modules, scoped ones included.
|
|
16
|
+
const packagesIn = (modules) => names(modules).flatMap((name) => name.startsWith('@')
|
|
17
|
+
? names(join(modules, name)).map((n) => join(modules, name, n))
|
|
18
|
+
: [join(modules, name)]);
|
|
19
|
+
const manifestOf = (dir) => readJson(join(dir, 'package.json'), isRecord);
|
|
20
|
+
// The package of id (at version, when given) in the tree cli 0.51 installed, or null.
|
|
21
|
+
const oldPackage = (id, version) => {
|
|
22
|
+
const tree = currentTree(extensionsDir()).dir;
|
|
23
|
+
if (tree === null)
|
|
24
|
+
return null;
|
|
25
|
+
const match = (dir) => {
|
|
26
|
+
const pkg = manifestOf(dir);
|
|
27
|
+
const agentage = isRecord(pkg?.['agentage']) ? pkg['agentage'] : {};
|
|
28
|
+
return agentage['id'] === id && (version === undefined || pkg?.['version'] === version);
|
|
29
|
+
};
|
|
30
|
+
return packagesIn(join(tree, 'node_modules')).find(match) ?? null;
|
|
31
|
+
};
|
|
32
|
+
// Moved entries run from the 0.51 tree as they are: no npm call, so the move works offline.
|
|
33
|
+
export const oldPackageDir = (id, version) => oldPackage(id, version);
|
|
34
|
+
// The npm name id was installed under here (the daemon's trees, then the 0.51 tree), or null.
|
|
35
|
+
export const installedName = (id) => {
|
|
36
|
+
const own = names(join(packagesDir(), 'trees'))
|
|
37
|
+
.filter((tree) => tree.startsWith(`${id}@`))
|
|
38
|
+
.map((tree) => packageDir(id, tree.slice(id.length + 1)))
|
|
39
|
+
.find((dir) => dir !== null);
|
|
40
|
+
const dir = own ?? oldPackage(id);
|
|
41
|
+
const name = dir ? manifestOf(dir)?.['name'] : undefined;
|
|
42
|
+
return typeof name === 'string' ? name : null;
|
|
43
|
+
};
|
|
44
|
+
// A version on disk: the daemon's own tree first, then the 0.51 tree.
|
|
45
|
+
export const installedDir = (id, version) => packageDir(id, version) ?? oldPackageDir(id, version);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Npm } from './npm.js';
|
|
2
|
+
export declare const packagesDir: () => string;
|
|
3
|
+
export interface PackageSpec {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
version: string;
|
|
7
|
+
registries: Record<string, string>;
|
|
8
|
+
}
|
|
9
|
+
export declare const packageDir: (id: string, version: string) => string | null;
|
|
10
|
+
export declare const installPackage: (spec: PackageSpec, npm: Npm) => Promise<string>;
|
|
11
|
+
export declare const prunePackages: (id: string, inUse: string[]) => string[];
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readdirSync, rmSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { isRecord, readJson } from '../../lib/fs/json-file.js';
|
|
4
|
+
import { extensionsDir } from '../paths.js';
|
|
5
|
+
import { lastLines } from './npm.js';
|
|
6
|
+
import { clearStaging, commitTree, discardTree, isComplete, manifestText, npmrcText, stageTree, treePath, withInstallLock, } from './tree.js';
|
|
7
|
+
// One npm tree per extension version: a running child keeps its folder while a new one installs.
|
|
8
|
+
export const packagesDir = () => join(extensionsDir(), 'packages');
|
|
9
|
+
const treeName = (id, version) => `${id}@${version}`;
|
|
10
|
+
// The installed package folder of id@version, or null when that tree was never finished.
|
|
11
|
+
export const packageDir = (id, version) => {
|
|
12
|
+
const root = packagesDir();
|
|
13
|
+
if (!isComplete(root, treeName(id, version)))
|
|
14
|
+
return null;
|
|
15
|
+
const tree = treePath(root, treeName(id, version));
|
|
16
|
+
const deps = readJson(join(tree, 'package.json'), isRecord)?.['dependencies'];
|
|
17
|
+
const name = isRecord(deps) ? Object.keys(deps)[0] : undefined;
|
|
18
|
+
return name === undefined ? null : join(tree, 'node_modules', name);
|
|
19
|
+
};
|
|
20
|
+
const installTree = async (spec, npm) => {
|
|
21
|
+
const root = packagesDir();
|
|
22
|
+
clearStaging(root);
|
|
23
|
+
const manifest = manifestText({ [spec.name]: spec.version });
|
|
24
|
+
const staging = stageTree(root, { manifest, npmrc: npmrcText(spec.registries), lock: null });
|
|
25
|
+
const res = await npm('install', staging);
|
|
26
|
+
if (res.code !== 0) {
|
|
27
|
+
discardTree(staging);
|
|
28
|
+
const why = lastLines(res.stderr.trim() === '' ? res.stdout : res.stderr);
|
|
29
|
+
throw new Error(`npm install ${spec.name}@${spec.version} failed (exit ${res.code})\n${why}`);
|
|
30
|
+
}
|
|
31
|
+
commitTree(root, staging, treeName(spec.id, spec.version));
|
|
32
|
+
};
|
|
33
|
+
// Idempotent: a finished tree is reused, so a boot that calls it again needs no network.
|
|
34
|
+
export const installPackage = async (spec, npm) => {
|
|
35
|
+
mkdirSync(packagesDir(), { recursive: true, mode: 0o700 });
|
|
36
|
+
return withInstallLock(packagesDir(), async () => {
|
|
37
|
+
const have = packageDir(spec.id, spec.version);
|
|
38
|
+
if (have)
|
|
39
|
+
return have;
|
|
40
|
+
await installTree(spec, npm);
|
|
41
|
+
return join(treePath(packagesDir(), treeName(spec.id, spec.version)), 'node_modules', spec.name);
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
// The versions of id that no installation entry uses any more go; only the daemon's own trees,
|
|
45
|
+
// never the 0.51 tree (read-only for this cli). Called after the daemon stopped the old child.
|
|
46
|
+
export const prunePackages = (id, inUse) => {
|
|
47
|
+
const trees = join(packagesDir(), 'trees');
|
|
48
|
+
const names = existsSync(trees) ? readdirSync(trees) : [];
|
|
49
|
+
const unused = names.filter((name) => name.startsWith(`${id}@`) && !inUse.includes(name.slice(id.length + 1)));
|
|
50
|
+
for (const name of unused)
|
|
51
|
+
rmSync(join(trees, name), { recursive: true, force: true });
|
|
52
|
+
return unused;
|
|
53
|
+
};
|