@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
|
@@ -3,6 +3,9 @@ import { existsSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSyn
|
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
import { promisify } from 'node:util';
|
|
5
5
|
import {} from 'commander';
|
|
6
|
+
import { addJson, CliError } from '../../lib/json-output.js';
|
|
7
|
+
import { installCreated, trustFrom } from './create-install.js';
|
|
8
|
+
import { terminalIo } from './lifecycle.js';
|
|
6
9
|
const run = promisify(execFile);
|
|
7
10
|
export const TEMPLATE = 'agentage/extension-template';
|
|
8
11
|
export const PARTS = ['pages', 'ui', 'api', 'mcp', 'worker', 'store', 'cli'];
|
|
@@ -10,6 +13,8 @@ const ROUTED = ['pages', 'ui', 'api', 'mcp'];
|
|
|
10
13
|
// `_` is a separator here, so `template__echo` is the id too.
|
|
11
14
|
const WORD = /(?<![A-Za-z0-9])template(?![A-Za-z0-9])/g;
|
|
12
15
|
const LOCK = 'package-lock.json';
|
|
16
|
+
// owner/repo, optionally #branch: a git ref that cannot pass for a flag or leave the repo.
|
|
17
|
+
const FROM = /^[\w.-]+\/[\w.-]+(?:#\w[\w./-]*)?$/;
|
|
13
18
|
// What else goes with a dropped part: manifest keys the kit refuses without it, the store's SQL, the contract file of api and mcp.
|
|
14
19
|
const PRUNE = {
|
|
15
20
|
cli: { keys: [['agentage', 'commands']] },
|
|
@@ -27,8 +32,8 @@ const refusal = ({ id, parts, from = TEMPLATE }, kept) => {
|
|
|
27
32
|
return `id ${id} is a part name: pick another id`;
|
|
28
33
|
if (!kept.some((part) => ROUTED.includes(part)))
|
|
29
34
|
return `an extension needs at least one of ${ROUTED.join(', ')}`;
|
|
30
|
-
if (
|
|
31
|
-
return `--from ${from}: owner/repo`;
|
|
35
|
+
if (!FROM.test(from) || from.includes('..'))
|
|
36
|
+
return `--from ${from}: owner/repo or owner/repo#branch`;
|
|
32
37
|
return existsSync(`extension-${id}`)
|
|
33
38
|
? `extension-${id} exists: pick another id or remove it`
|
|
34
39
|
: '';
|
|
@@ -76,48 +81,85 @@ const renameLock = (dir, id) => {
|
|
|
76
81
|
Object.assign(at, { name });
|
|
77
82
|
save(join(dir, LOCK), lock);
|
|
78
83
|
};
|
|
84
|
+
// --from owner/repo[#branch], checked by refusal() first.
|
|
85
|
+
const repoRef = (from) => {
|
|
86
|
+
const [repo = from, ref] = from.split('#');
|
|
87
|
+
return { repo, ...(ref && { ref }) };
|
|
88
|
+
};
|
|
79
89
|
// Bounded, a partial folder removed; git's own first line says why (no repo, no network, no access).
|
|
80
90
|
const clone = async (url, from, dir) => {
|
|
91
|
+
const { ref } = repoRef(from);
|
|
92
|
+
const branch = ref ? ['--branch', ref] : [];
|
|
81
93
|
const env = { ...process.env, GIT_TERMINAL_PROMPT: '0' };
|
|
82
|
-
await run('git', ['clone', '-q', '--depth', '1', url, dir], {
|
|
94
|
+
await run('git', ['clone', '-q', '--depth', '1', ...branch, url, dir], {
|
|
95
|
+
env,
|
|
96
|
+
timeout: 120_000,
|
|
97
|
+
}).catch((err) => {
|
|
83
98
|
rmSync(dir, { recursive: true, force: true });
|
|
84
99
|
const why = (err.stderr?.trim() || err.message).split('\n')[0];
|
|
85
100
|
throw new Error(`cannot clone template ${from}: ${why}`);
|
|
86
101
|
});
|
|
87
102
|
rmSync(join(dir, '.git'), { recursive: true, force: true });
|
|
88
103
|
};
|
|
104
|
+
const CI = join('.github', 'workflows', 'ci.yml');
|
|
105
|
+
const FLOOR = /MIN_EXECUTED: '\d+'/;
|
|
106
|
+
const LOWERED = " ci MIN_EXECUTED is 1: after the first green run, set it to the gate's count";
|
|
107
|
+
const BY_HAND = ` ci no MIN_EXECUTED line found in ${CI}: set it by hand to the gate's count`;
|
|
108
|
+
// The template's floor counts the gate's tests for all seven parts; a subset's count is unknown.
|
|
109
|
+
const lowerFloor = (dir, kept) => {
|
|
110
|
+
if (kept.length === PARTS.length)
|
|
111
|
+
return undefined;
|
|
112
|
+
const file = join(dir, CI);
|
|
113
|
+
const text = existsSync(file) ? readFileSync(file, 'utf8') : '';
|
|
114
|
+
if (!FLOOR.test(text))
|
|
115
|
+
return BY_HAND;
|
|
116
|
+
writeFileSync(file, text.replace(FLOOR, "MIN_EXECUTED: '1'"));
|
|
117
|
+
return LOWERED;
|
|
118
|
+
};
|
|
89
119
|
// A half-made folder is removed, so a re-run is not refused as "exists".
|
|
90
120
|
const shape = (dir, from, id, kept) => {
|
|
91
121
|
try {
|
|
92
122
|
drop(dir, kept);
|
|
93
123
|
rewrite(dir, id);
|
|
94
124
|
renameLock(dir, id);
|
|
125
|
+
return lowerFloor(dir, kept);
|
|
95
126
|
}
|
|
96
127
|
catch (err) {
|
|
97
128
|
rmSync(dir, { recursive: true, force: true });
|
|
98
129
|
throw new Error(`template ${from}: ${err.message}`);
|
|
99
130
|
}
|
|
100
131
|
};
|
|
101
|
-
|
|
102
|
-
|
|
132
|
+
const printNext = (dir, from, id, kept) => {
|
|
133
|
+
const kit = String(json(join(dir, 'package.json'))['dependencies']?.['@agentage/extension'] ?? '?');
|
|
134
|
+
const { repo, ref } = repoRef(from);
|
|
135
|
+
const branch = ref ? `branch ${ref}` : 'default branch';
|
|
136
|
+
console.log(` template ${repo} (${branch}, kit ${kit.replace(/^[\^~]/, '')})`);
|
|
137
|
+
console.log(` kept ${kept.join(', ')}`);
|
|
138
|
+
console.log(` id ${id} · host ${id}.next.agentage.io · contract ${id}.mcpc.json`);
|
|
139
|
+
console.log(` next cd ${dir} && agentage extension up`);
|
|
140
|
+
};
|
|
141
|
+
// Clones the template's default branch (or the #branch of --from) into ./extension-<id> as a new working copy, no history;
|
|
142
|
+
// then installs its dependencies, builds it and (unless --no-install) gives it to the daemon.
|
|
143
|
+
export const runExtensionCreate = async (opts, url = (from) => `https://github.com/${from}`, after = installCreated, io = terminalIo()) => {
|
|
103
144
|
const { id, from = TEMPLATE } = opts;
|
|
104
145
|
const kept = opts.parts.length > 0 ? [...new Set(opts.parts)] : PARTS;
|
|
105
146
|
const refused = refusal(opts, kept);
|
|
106
147
|
if (refused)
|
|
107
|
-
throw new
|
|
148
|
+
throw new CliError('invalid_argument', refused);
|
|
149
|
+
await trustFrom(from, opts, opts.json ? { ...io, isTTY: false } : io);
|
|
108
150
|
const dir = `extension-${id}`;
|
|
109
|
-
await clone(url(from), from, dir);
|
|
110
|
-
shape(dir, from, id, kept);
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
console.log(` next cd ${dir} && npm ci && npm run build && agentage extension check`);
|
|
151
|
+
await clone(url(repoRef(from).repo), from, dir);
|
|
152
|
+
const ci = shape(dir, from, id, kept);
|
|
153
|
+
printNext(dir, from, id, kept);
|
|
154
|
+
if (ci)
|
|
155
|
+
console.log(ci);
|
|
156
|
+
return { id, dir, from, kept, ...(await after(dir, opts.install !== false)) };
|
|
116
157
|
};
|
|
117
|
-
export const addCreate = (group, create) => group
|
|
158
|
+
export const addCreate = (group, create) => addJson(group
|
|
118
159
|
.command('create')
|
|
119
160
|
.description('Create ./extension-<id> from the extension template with the parts named')
|
|
120
161
|
.argument('<id>', 'the extension id, also its host and contract name')
|
|
121
162
|
.argument('[parts...]', `parts to keep (default: all seven): ${PARTS.join(', ')}`)
|
|
122
|
-
.option('--from <owner/repo>', `the template repo (default: ${TEMPLATE})`)
|
|
123
|
-
.
|
|
163
|
+
.option('--from <owner/repo[#branch]>', `the template repo (default: ${TEMPLATE})`)
|
|
164
|
+
.option('--no-install', 'build the folder, but do not give it to the daemon')
|
|
165
|
+
.option('--yes', 'run code from another --from repo or branch without asking')).action((id, parts, o) => create({ id, parts, ...o }));
|
|
@@ -2,6 +2,7 @@ import {} from 'commander';
|
|
|
2
2
|
import {} from '../../core/loader/discover.js';
|
|
3
3
|
import { loadExtensions } from '../../core/loader/load.js';
|
|
4
4
|
import { loadOrder } from '../../core/loader/order.js';
|
|
5
|
+
import { installedExtensions } from '../../core/loader/installed.js';
|
|
5
6
|
import { loadSet, scan } from '../../core/loader/scan.js';
|
|
6
7
|
import { claimVerbs, commandNames, readHeld } from '../../core/loader/verbs.js';
|
|
7
8
|
import { NO_MACHINE, readMachine } from '../../core/profile/machine.js';
|
|
@@ -37,7 +38,8 @@ const registerApi = (program, ext, run) => {
|
|
|
37
38
|
// Manifests only, never code: each stub hands the command line, --help included, to the extension.
|
|
38
39
|
export const registerDelegates = (program, argv, wrap, tool = loadKitTool) => {
|
|
39
40
|
const core = program.commands.map((command) => command.name());
|
|
40
|
-
|
|
41
|
+
// The daemon's installation once it exists; before the one-time move, the old lists.
|
|
42
|
+
const extensions = installedExtensions() ?? loadSet(scan(readMachine() ?? NO_MACHINE));
|
|
41
43
|
const verbs = claimVerbs(extensions, readHeld());
|
|
42
44
|
for (const ext of extensions) {
|
|
43
45
|
if (ext.kind === 'kit')
|
|
@@ -5,7 +5,7 @@ export interface ExtensionDoctorOptions {
|
|
|
5
5
|
json?: boolean;
|
|
6
6
|
}
|
|
7
7
|
type BeforeLoad = (extensions: DiscoveredExtension[]) => Promise<void>;
|
|
8
|
-
export declare const loadAndGather: (beforeLoad?: BeforeLoad,
|
|
8
|
+
export declare const loadAndGather: (beforeLoad?: BeforeLoad, tool?: LoadKitTool) => Promise<ExtensionsGather>;
|
|
9
9
|
export declare const failedError: (rows: ExtensionRow[]) => Error | null;
|
|
10
10
|
export declare const runExtensionDoctor: (opts?: ExtensionDoctorOptions, tool?: LoadKitTool) => Promise<void>;
|
|
11
11
|
export {};
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
import { CliError } from '../../lib/json-output.js';
|
|
1
2
|
import { driftLines } from '../../core/installer/plan.js';
|
|
2
3
|
import {} from '../../core/loader/discover.js';
|
|
3
4
|
import { loadExtensions } from '../../core/loader/load.js';
|
|
4
|
-
import { loadSet,
|
|
5
|
+
import { loadSet, scanNow } from '../../core/loader/scan.js';
|
|
5
6
|
import { loadMachine } from '../../core/profile/machine.js';
|
|
6
7
|
import { kitCheck } from './kit-tool.js';
|
|
7
8
|
import { printReport } from './list.js';
|
|
8
9
|
import { gatherFrom, invalidProfileError, } from './rows.js';
|
|
9
|
-
// Loads what can load once
|
|
10
|
-
export const loadAndGather = async (beforeLoad = async () => undefined,
|
|
11
|
-
const found =
|
|
10
|
+
// Loads what can load once, for the report only; the kit checks kit-shaped ones.
|
|
11
|
+
export const loadAndGather = async (beforeLoad = async () => undefined, tool) => {
|
|
12
|
+
const found = scanNow(await loadMachine());
|
|
12
13
|
const extensions = loadSet(found);
|
|
13
14
|
await beforeLoad(extensions);
|
|
14
15
|
const session = await loadExtensions(extensions, undefined, kitCheck(tool));
|
|
@@ -20,13 +21,13 @@ export const failedError = (rows) => {
|
|
|
20
21
|
if (failed.length === 0)
|
|
21
22
|
return null;
|
|
22
23
|
const count = `${failed.length} extension${failed.length === 1 ? '' : 's'}`;
|
|
23
|
-
return new
|
|
24
|
+
return new CliError('extension_failed', `${count} failed to load: ${failed.join(', ')}`);
|
|
24
25
|
};
|
|
25
26
|
// Integrity drift: the extensions it names were not loaded, and setup refuses to build on it.
|
|
26
|
-
const driftError = (drift) => drift.length === 0 ? null : new
|
|
27
|
+
const driftError = (drift) => drift.length === 0 ? null : new CliError('integrity_drift', driftLines(drift).join('\n'));
|
|
27
28
|
// The rows always print; an invalid profile.json, integrity drift or a failed load fails the step.
|
|
28
29
|
export const runExtensionDoctor = async (opts = {}, tool) => {
|
|
29
|
-
const gathered = await loadAndGather(undefined,
|
|
30
|
+
const gathered = await loadAndGather(undefined, tool);
|
|
30
31
|
printReport(gathered, opts.json);
|
|
31
32
|
const { profile, extensions } = gathered.status;
|
|
32
33
|
const failure = invalidProfileError(profile) ?? driftError(gathered.drift) ?? failedError(extensions);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type HostClient, type HostRow, type HostSummary } from '../../lib/daemon/host-client.js';
|
|
2
|
+
export interface IdBody {
|
|
3
|
+
id: string;
|
|
4
|
+
version?: string;
|
|
5
|
+
enabled?: false;
|
|
6
|
+
}
|
|
7
|
+
export type AddBody = IdBody | {
|
|
8
|
+
source: string;
|
|
9
|
+
enabled?: false;
|
|
10
|
+
};
|
|
11
|
+
export interface Installed {
|
|
12
|
+
row: HostSummary | HostRow;
|
|
13
|
+
already: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare const addOnce: (host: HostClient, spec: IdBody) => Promise<Installed>;
|
|
16
|
+
export declare const installId: (host: HostClient, spec: IdBody) => Promise<Installed>;
|
|
17
|
+
export declare const installFolder: (host: HostClient, source: string) => Promise<Installed>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { realpathSync } from 'node:fs';
|
|
2
|
+
import { existingOf } from '../../lib/daemon/daemon-answer.js';
|
|
3
|
+
import {} from '../../lib/daemon/host-client.js';
|
|
4
|
+
import { CliError, DaemonError } from '../../lib/json-output.js';
|
|
5
|
+
// The add itself is the check, so two cli runs cannot both add one id: the second gets CONFLICT,
|
|
6
|
+
// whose details name the installed entry.
|
|
7
|
+
const added = (host, body) => host.add(body).catch((err) => {
|
|
8
|
+
const existing = err instanceof DaemonError ? existingOf(err) : null;
|
|
9
|
+
if (existing)
|
|
10
|
+
return existing;
|
|
11
|
+
throw err;
|
|
12
|
+
});
|
|
13
|
+
const isExisting = (got) => !('state' in got);
|
|
14
|
+
const elsewhere = (what, id) => new CliError('already_installed', `${what}; agentage extension remove ${id} first`);
|
|
15
|
+
// The row of an id: added now, or the one the daemon has (removed in between: added again).
|
|
16
|
+
export const addOnce = async (host, spec) => {
|
|
17
|
+
const got = await added(host, spec);
|
|
18
|
+
if (!isExisting(got))
|
|
19
|
+
return { row: got, already: false };
|
|
20
|
+
const row = (await host.list()).find((r) => r.id === spec.id);
|
|
21
|
+
return row ? { row, already: true } : { row: await host.add(spec), already: false };
|
|
22
|
+
};
|
|
23
|
+
// An id installed already: another version is a change of version (go back, data kept).
|
|
24
|
+
export const installId = async (host, spec) => {
|
|
25
|
+
const got = await addOnce(host, spec);
|
|
26
|
+
if (!got.already)
|
|
27
|
+
return got;
|
|
28
|
+
const { id, source } = got.row;
|
|
29
|
+
if (source !== 'market')
|
|
30
|
+
throw elsewhere(`${id} runs from the folder ${source}`, id);
|
|
31
|
+
if (spec.version && spec.version !== got.row.version)
|
|
32
|
+
return { row: await host.change(id, { version: spec.version }), already: false };
|
|
33
|
+
return got;
|
|
34
|
+
};
|
|
35
|
+
const real = (path) => {
|
|
36
|
+
try {
|
|
37
|
+
return realpathSync(path);
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return path;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
// A folder: the same folder again (by real path) is installed already; its id from elsewhere is
|
|
44
|
+
// refused.
|
|
45
|
+
export const installFolder = async (host, source) => {
|
|
46
|
+
const got = await added(host, { source });
|
|
47
|
+
if (!isExisting(got))
|
|
48
|
+
return { row: got, already: false };
|
|
49
|
+
const { id } = got;
|
|
50
|
+
const where = got.source ? `the folder ${got.source}` : 'the market';
|
|
51
|
+
if (!got.source || real(got.source) !== real(source))
|
|
52
|
+
throw elsewhere(`${id} is installed from ${where}`, id);
|
|
53
|
+
const row = (await host.list()).find((r) => r.id === id);
|
|
54
|
+
if (row)
|
|
55
|
+
return { row, already: true };
|
|
56
|
+
return { row: await host.add({ source }), already: false };
|
|
57
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type * as Kit from '@agentage/extension/tool';
|
|
2
2
|
import { type KitCheck } from '../../core/loader/load.js';
|
|
3
|
-
export type KitTool = Pick<typeof Kit, 'check' | 'checkLines' | 'build' | 'buildLines' | 'runCommand' | 'checkCli' | 'up' | 'down' | 'token' | 'readManifest'>;
|
|
3
|
+
export type KitTool = Pick<typeof Kit, 'check' | 'checkLines' | 'build' | 'buildLines' | 'runCommand' | 'checkCli' | 'up' | 'down' | 'token' | 'readManifest' | 'writeContracts'>;
|
|
4
4
|
export type LoadKitTool = () => Promise<KitTool>;
|
|
5
5
|
export declare const loadKitTool: LoadKitTool;
|
|
6
6
|
export declare const kitCheck: (tool?: LoadKitTool) => KitCheck;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type Command } from 'commander';
|
|
2
|
+
import { type ConfigureOptions } from './configure.js';
|
|
3
|
+
import { type InstallOptions, type RemoveOptions } from './lifecycle.js';
|
|
4
|
+
import { type ListOptions, type ExtensionUpdateOptions } from './lifecycle-list.js';
|
|
5
|
+
type Action<T> = (opts: T) => Promise<void>;
|
|
6
|
+
export interface LifecycleActions {
|
|
7
|
+
install: Action<InstallOptions>;
|
|
8
|
+
list: Action<ListOptions>;
|
|
9
|
+
update: Action<ExtensionUpdateOptions>;
|
|
10
|
+
enabled: Action<{
|
|
11
|
+
id: string;
|
|
12
|
+
enabled: boolean;
|
|
13
|
+
json?: boolean;
|
|
14
|
+
}>;
|
|
15
|
+
configure: Action<ConfigureOptions>;
|
|
16
|
+
remove: Action<RemoveOptions>;
|
|
17
|
+
}
|
|
18
|
+
export declare const addLifecycle: (group: Command, actions: LifecycleActions) => void;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import {} from 'commander';
|
|
2
|
+
import { addJson } from '../../lib/json-output.js';
|
|
3
|
+
import {} from './configure.js';
|
|
4
|
+
import {} from './lifecycle.js';
|
|
5
|
+
import {} from './lifecycle-list.js';
|
|
6
|
+
const INSTALL_HELP = `
|
|
7
|
+
Every lifecycle command is a client of the daemon (agentage daemon status) and starts it when
|
|
8
|
+
none runs. <id> asks the market for its newest version; <id>@<version> installs that version,
|
|
9
|
+
and over an installed one changes to it, data kept (go back). A local path (./path, ../path,
|
|
10
|
+
/path) runs that folder itself, no copy; a folder another user can write is refused. The
|
|
11
|
+
extension then runs: its api at 127.0.0.1:4243/api/<id>/ and its commands in agentage --help.`;
|
|
12
|
+
const LIST_HELP = `
|
|
13
|
+
One row per installed extension: id, version, source (market or folder) and state (starting,
|
|
14
|
+
running, failed with the reason, disabled). --json gives the daemon's rows. --available reads
|
|
15
|
+
the market instead: each listed id with its newest version.`;
|
|
16
|
+
const REMOVE_HELP = `
|
|
17
|
+
Stops the extension and forgets its settings and secrets; its data folder (data/<id>/ in the
|
|
18
|
+
config folder) stays. --purge also deletes it, after asking; without a terminal it needs --yes.`;
|
|
19
|
+
const CONFIGURE_HELP = `
|
|
20
|
+
The daemon starts the extension again with the new values, then moves its route: the daemon does
|
|
21
|
+
not restart and no request is lost. --secret stores the values as secrets (never printed); a
|
|
22
|
+
single <key> with no =value reads the value from stdin, or asks for it on a terminal.`;
|
|
23
|
+
const addInstall = (group, { install, list }) => {
|
|
24
|
+
addJson(group
|
|
25
|
+
.command('install')
|
|
26
|
+
.description('Install an extension in the daemon and run it')
|
|
27
|
+
.argument('<name>', '<id>, <id>@<version> or a local folder')
|
|
28
|
+
.option('--off', 'old name of: install, then extension disable'))
|
|
29
|
+
.addHelpText('after', INSTALL_HELP)
|
|
30
|
+
.action((name, opts) => install({ name, ...opts }));
|
|
31
|
+
addJson(group
|
|
32
|
+
.command('list')
|
|
33
|
+
.description('Show each installed extension: id, version, source, state')
|
|
34
|
+
.option('--available', 'what the market offers, with the newest versions'))
|
|
35
|
+
.addHelpText('after', LIST_HELP)
|
|
36
|
+
.action(list);
|
|
37
|
+
};
|
|
38
|
+
const addChanges = (group, { update, enabled }) => {
|
|
39
|
+
addJson(group
|
|
40
|
+
.command('update')
|
|
41
|
+
.description('Move each market extension, or one, to its newest version')
|
|
42
|
+
.argument('[id]', 'only this extension')
|
|
43
|
+
.option('--check', 'only report what would change')).action((id, opts) => update({ ...opts, id }));
|
|
44
|
+
for (const [name, on] of [
|
|
45
|
+
['disable', false],
|
|
46
|
+
['enable', true],
|
|
47
|
+
])
|
|
48
|
+
addJson(group
|
|
49
|
+
.command(name)
|
|
50
|
+
.description(on ? 'Run a disabled extension again' : 'Stop an extension, keep its data')
|
|
51
|
+
.argument('<id>', 'the extension id')).action((id, opts) => enabled({ ...opts, id, enabled: on }));
|
|
52
|
+
};
|
|
53
|
+
const addConfigure = (group, configure) => {
|
|
54
|
+
addJson(group
|
|
55
|
+
.command('configure')
|
|
56
|
+
.description('Set settings (or --secret secrets) of an extension, no restart')
|
|
57
|
+
.argument('<id>', 'the extension id')
|
|
58
|
+
.argument('<pairs...>', '<key>=<value>, one or more')
|
|
59
|
+
.option('--secret', 'store them as secrets'))
|
|
60
|
+
.addHelpText('after', CONFIGURE_HELP)
|
|
61
|
+
.action((id, pairs, opts) => configure({ ...opts, id, pairs }));
|
|
62
|
+
};
|
|
63
|
+
const addRemove = (group, remove) => {
|
|
64
|
+
addJson(group
|
|
65
|
+
.command('remove')
|
|
66
|
+
.description('Stop and remove an extension; its data stays unless --purge')
|
|
67
|
+
.argument('<id>', 'the extension id')
|
|
68
|
+
.option('--purge', "also delete the extension's data, data/<id>/")
|
|
69
|
+
.option('--yes', 'do not ask before --purge deletes (needed without a terminal)')
|
|
70
|
+
.option('--force', 'remove it although another installed extension depends on it'))
|
|
71
|
+
.addHelpText('after', REMOVE_HELP)
|
|
72
|
+
.action((name, opts) => remove({ name, ...opts }));
|
|
73
|
+
};
|
|
74
|
+
// C1: install, list, update, disable, enable, configure, remove.
|
|
75
|
+
export const addLifecycle = (group, actions) => {
|
|
76
|
+
addInstall(group, actions);
|
|
77
|
+
addChanges(group, actions);
|
|
78
|
+
addConfigure(group, actions.configure);
|
|
79
|
+
addRemove(group, actions.remove);
|
|
80
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type HostRow } from '../../lib/daemon/host-client.js';
|
|
2
|
+
import { WithMeta } from '../../lib/json-output.js';
|
|
3
|
+
import { type Listing, type Market } from '../../lib/net/market.js';
|
|
4
|
+
import { type LifecycleDeps } from './lifecycle.js';
|
|
5
|
+
export interface ListOptions {
|
|
6
|
+
available?: boolean;
|
|
7
|
+
json?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface ExtensionUpdateOptions {
|
|
10
|
+
id?: string;
|
|
11
|
+
check?: boolean;
|
|
12
|
+
json?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface ListDeps extends LifecycleDeps {
|
|
15
|
+
available: () => Promise<Listing>;
|
|
16
|
+
market: () => Market;
|
|
17
|
+
npmNewest: (id: string) => Promise<string>;
|
|
18
|
+
}
|
|
19
|
+
export declare const table: (rows: string[][]) => string[];
|
|
20
|
+
export declare const runList: (opts: ListOptions, deps: ListDeps) => Promise<WithMeta | HostRow[]>;
|
|
21
|
+
export declare const runUpdate: (opts: ExtensionUpdateOptions, deps: ListDeps) => Promise<{
|
|
22
|
+
updated: boolean;
|
|
23
|
+
id: string;
|
|
24
|
+
from: string;
|
|
25
|
+
to: string;
|
|
26
|
+
}[]>;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import {} from '../../lib/daemon/host-client.js';
|
|
2
|
+
import { CliError, messageOf, WithMeta } from '../../lib/json-output.js';
|
|
3
|
+
import {} from '../../lib/net/market.js';
|
|
4
|
+
import { fromNpmLine, noSiteMarket } from '../../lib/net/market-error.js';
|
|
5
|
+
import { siteFqdn } from '../../lib/net/origins.js';
|
|
6
|
+
import { pruneUnused } from './lifecycle.js';
|
|
7
|
+
// The daemon's rows as they are; a folder entry says `folder` and keeps its path.
|
|
8
|
+
const shown = (row) => row.source === 'market' ? row : { ...row, source: 'folder', path: row.source };
|
|
9
|
+
export const table = (rows) => {
|
|
10
|
+
const widths = rows[0]?.map((_, i) => Math.max(...rows.map((r) => (r[i] ?? '').length))) ?? [];
|
|
11
|
+
return rows.map((r) => r
|
|
12
|
+
.map((cell, i) => cell.padEnd(widths[i] ?? 0))
|
|
13
|
+
.join(' ')
|
|
14
|
+
.trimEnd());
|
|
15
|
+
};
|
|
16
|
+
const printRows = (rows) => {
|
|
17
|
+
const cells = rows.map((r) => [r.id, r.version, r.source, r.state, r.error ?? '']);
|
|
18
|
+
const lines = table([['ID', 'VERSION', 'SOURCE', 'STATE', ''], ...cells]);
|
|
19
|
+
for (const line of rows.length > 0 ? lines : ['no extensions'])
|
|
20
|
+
console.log(line);
|
|
21
|
+
};
|
|
22
|
+
// A row the market cannot answer for is left out and named on stderr; the others are listed.
|
|
23
|
+
const available = async (deps) => {
|
|
24
|
+
const { offered, skipped } = await deps.available();
|
|
25
|
+
const lines = table([['ID', 'VERSION'], ...offered.map((o) => [o.id, o.version])]);
|
|
26
|
+
for (const line of offered.length > 0 ? lines : ['the market lists nothing'])
|
|
27
|
+
console.log(line);
|
|
28
|
+
if (skipped.length > 0)
|
|
29
|
+
console.error(`skipped ${skipped.map((s) => `${s.id} (${s.reason})`).join(', ')}`);
|
|
30
|
+
return new WithMeta(offered, { skipped });
|
|
31
|
+
};
|
|
32
|
+
export const runList = async (opts, deps) => {
|
|
33
|
+
if (opts.available)
|
|
34
|
+
return available(deps);
|
|
35
|
+
const rows = (await (await deps.host()).list()).map(shown);
|
|
36
|
+
printRows(rows);
|
|
37
|
+
return rows;
|
|
38
|
+
};
|
|
39
|
+
// The market's newest. A market that answers without the id keeps the installed version (one
|
|
40
|
+
// line); only a site with no market asks npm, by the name the row was installed under.
|
|
41
|
+
const newestOf = async (row, market, deps) => {
|
|
42
|
+
const to = (await market.latest(row.id))?.version;
|
|
43
|
+
const down = market.down();
|
|
44
|
+
if (to || (down && !noSiteMarket(down)))
|
|
45
|
+
return to ?? null;
|
|
46
|
+
if (down)
|
|
47
|
+
return deps.npmNewest(row.id);
|
|
48
|
+
console.error(`${row.id}: not in the market any more; ${row.version} stays`);
|
|
49
|
+
return null;
|
|
50
|
+
};
|
|
51
|
+
// An id npm cannot resolve is named and skipped: the other ids still update.
|
|
52
|
+
const movesOf = async (rows, deps) => {
|
|
53
|
+
const market = deps.market();
|
|
54
|
+
const moves = [];
|
|
55
|
+
const failed = [];
|
|
56
|
+
for (const row of rows) {
|
|
57
|
+
const to = await newestOf(row, market, deps).catch((err) => {
|
|
58
|
+
failed.push(`${row.id}: ${messageOf(err)}`);
|
|
59
|
+
return null;
|
|
60
|
+
});
|
|
61
|
+
if (to && to !== row.version)
|
|
62
|
+
moves.push({ id: row.id, from: row.version, to });
|
|
63
|
+
}
|
|
64
|
+
const down = market.down();
|
|
65
|
+
if (down && !noSiteMarket(down))
|
|
66
|
+
throw down;
|
|
67
|
+
if (down && rows.length > 0)
|
|
68
|
+
console.error(fromNpmLine(siteFqdn(), 'newest versions'));
|
|
69
|
+
return { moves, failed };
|
|
70
|
+
};
|
|
71
|
+
const marketRows = async (opts, rows) => {
|
|
72
|
+
const chosen = rows.filter((r) => r.source === 'market' && (!opts.id || r.id === opts.id));
|
|
73
|
+
if (opts.id && chosen.length === 0)
|
|
74
|
+
throw new CliError('not_installed', `${opts.id} is not installed from the market`);
|
|
75
|
+
return chosen;
|
|
76
|
+
};
|
|
77
|
+
// The market's newest version for each extension it installed (or one); --check changes nothing.
|
|
78
|
+
// On a site with no market, an id npm cannot resolve fails the run at the end (exit 1).
|
|
79
|
+
export const runUpdate = async (opts, deps) => {
|
|
80
|
+
const host = await deps.host();
|
|
81
|
+
const { moves, failed } = await movesOf(await marketRows(opts, await host.list()), deps);
|
|
82
|
+
for (const { id, from, to } of moves) {
|
|
83
|
+
if (!opts.check)
|
|
84
|
+
await host.change(id, { version: to }).then(() => pruneUnused(id));
|
|
85
|
+
console.log(`${id} ${from} to ${to}${opts.check ? ' (available)' : ''}`);
|
|
86
|
+
}
|
|
87
|
+
if (moves.length === 0 && failed.length === 0)
|
|
88
|
+
console.log('every extension is at its newest version');
|
|
89
|
+
if (failed.length > 0)
|
|
90
|
+
throw new CliError('extension_failed', `no newest version found:\n ${failed.join('\n ')}`);
|
|
91
|
+
return moves.map((move) => ({ ...move, updated: !opts.check }));
|
|
92
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type HostClient, type HostSummary } from '../../lib/daemon/host-client.js';
|
|
2
|
+
export interface LifecycleDeps {
|
|
3
|
+
host: () => Promise<HostClient>;
|
|
4
|
+
}
|
|
5
|
+
export interface ConfirmIo {
|
|
6
|
+
isTTY: boolean;
|
|
7
|
+
prompt: (question: string) => Promise<string>;
|
|
8
|
+
}
|
|
9
|
+
export interface InstallOptions {
|
|
10
|
+
name: string;
|
|
11
|
+
off?: boolean;
|
|
12
|
+
json?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface RemoveOptions {
|
|
15
|
+
name: string;
|
|
16
|
+
purge?: boolean;
|
|
17
|
+
yes?: boolean;
|
|
18
|
+
force?: boolean;
|
|
19
|
+
json?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export declare const specOf: (name: string) => {
|
|
22
|
+
id: string;
|
|
23
|
+
version?: string;
|
|
24
|
+
};
|
|
25
|
+
export declare const summaryOf: ({ id, version, state, error }: HostSummary) => HostSummary;
|
|
26
|
+
export declare const report: (done: HostSummary, note?: string) => HostSummary;
|
|
27
|
+
export interface InstallDeps extends LifecycleDeps {
|
|
28
|
+
fromNpm?: (id: string, what: string) => Promise<string | null>;
|
|
29
|
+
hasMarket?: (id: string) => Promise<boolean>;
|
|
30
|
+
}
|
|
31
|
+
export declare const runInstall: (opts: InstallOptions, deps: InstallDeps) => Promise<HostSummary>;
|
|
32
|
+
export declare const runEnabled: (id: string, enabled: boolean, deps: LifecycleDeps) => Promise<HostSummary>;
|
|
33
|
+
export declare const terminalIo: () => ConfirmIo;
|
|
34
|
+
export declare const confirmed: (io: ConfirmIo, question: string) => Promise<boolean>;
|
|
35
|
+
export declare const pruneUnused: (id: string) => string[];
|
|
36
|
+
export declare const runRemove: (opts: RemoveOptions, deps: LifecycleDeps & {
|
|
37
|
+
io: ConfirmIo;
|
|
38
|
+
}) => Promise<{
|
|
39
|
+
id: string;
|
|
40
|
+
purged: boolean;
|
|
41
|
+
}>;
|