@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,50 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { isRecord, readJson } from '../../lib/fs/json-file.js';
|
|
3
|
+
import {} from './move-plan.js';
|
|
4
|
+
const NUMERIC = /^-?\d+(?:\.\d+)?$/;
|
|
5
|
+
// 0.51 kept any JSON value; the daemon wants the manifest's type, so a value is turned into it.
|
|
6
|
+
const coerce = (type, value) => {
|
|
7
|
+
if (type === 'string')
|
|
8
|
+
return typeof value === 'object' ? null : { value: String(value) };
|
|
9
|
+
if (type === 'boolean') {
|
|
10
|
+
if (typeof value === 'boolean')
|
|
11
|
+
return { value };
|
|
12
|
+
return value === 'true' || value === 'false' ? { value: value === 'true' } : null;
|
|
13
|
+
}
|
|
14
|
+
const n = typeof value === 'number' ? value : NUMERIC.test(String(value)) ? Number(value) : NaN;
|
|
15
|
+
if (Number.isNaN(n) || typeof value === 'object')
|
|
16
|
+
return null;
|
|
17
|
+
return type === 'integer' && !Number.isInteger(n) ? null : { value: n };
|
|
18
|
+
};
|
|
19
|
+
const declared = (dir) => {
|
|
20
|
+
const agentage = readJson(join(dir, 'package.json'), isRecord)?.['agentage'];
|
|
21
|
+
const settings = isRecord(agentage) ? agentage['settings'] : undefined;
|
|
22
|
+
return isRecord(settings) ? settings : null;
|
|
23
|
+
};
|
|
24
|
+
const valueOf = (decl, value) => {
|
|
25
|
+
if (!isRecord(decl))
|
|
26
|
+
return null;
|
|
27
|
+
const done = coerce(decl['type'], value);
|
|
28
|
+
const allowed = Array.isArray(decl['enum']) ? decl['enum'] : null;
|
|
29
|
+
return done && allowed && !allowed.includes(done.value) ? null : done;
|
|
30
|
+
};
|
|
31
|
+
// The settings the extension declares, of its types; a key it cannot take is dropped and reported,
|
|
32
|
+
// so the extension still starts. No declared settings (an 0.51 extension): kept as they are.
|
|
33
|
+
export const movedSettings = (id, dir, config) => {
|
|
34
|
+
const decls = declared(dir);
|
|
35
|
+
if (decls === null)
|
|
36
|
+
return { settings: config, dropped: [] };
|
|
37
|
+
const settings = {};
|
|
38
|
+
const dropped = [];
|
|
39
|
+
for (const [key, value] of Object.entries(config)) {
|
|
40
|
+
const done = valueOf(decls[key], value);
|
|
41
|
+
if (done)
|
|
42
|
+
settings[key] = done.value;
|
|
43
|
+
else
|
|
44
|
+
dropped.push({
|
|
45
|
+
entry: `${id} setting ${key}`,
|
|
46
|
+
reason: key in decls ? `${JSON.stringify(value)} does not fit its type` : 'not declared',
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return { settings, dropped };
|
|
50
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type * as KitHost from '@agentage/extension/host';
|
|
2
|
+
import { type Moved, type Skipped } from './move-plan.js';
|
|
3
|
+
export declare const MOVED_MARKER = "installation.moved";
|
|
4
|
+
export declare const MOVE_REPORT = "installation.moved.json";
|
|
5
|
+
export interface MoveReport {
|
|
6
|
+
moved: string[];
|
|
7
|
+
skipped: Skipped[];
|
|
8
|
+
warning: string | null;
|
|
9
|
+
}
|
|
10
|
+
export type KitMove = Pick<typeof KitHost, 'updateInstallation' | 'withFileLock'>;
|
|
11
|
+
export declare const readMoveReport: () => MoveReport | null;
|
|
12
|
+
export interface MoveHooks {
|
|
13
|
+
entry?: (moved: Moved) => void;
|
|
14
|
+
kit?: () => Promise<KitMove>;
|
|
15
|
+
}
|
|
16
|
+
export declare const moveOldLists: (hooks?: MoveHooks) => Promise<void>;
|
|
17
|
+
export declare const moveBeforeStart: (hooks?: MoveHooks) => Promise<void>;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { existsSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { settingsPath } from '../../core/loader/installed.js';
|
|
4
|
+
import { ensureConfigDir, getConfigDir } from '../../lib/fs/config.js';
|
|
5
|
+
import { isRecord, readJson, writeJsonAtomic } from '../../lib/fs/json-file.js';
|
|
6
|
+
import { messageOf } from '../../lib/json-output.js';
|
|
7
|
+
import { movePlan } from './move-plan.js';
|
|
8
|
+
// Written once every old entry is moved or deliberately skipped; the old files stay as they were.
|
|
9
|
+
export const MOVED_MARKER = 'installation.moved';
|
|
10
|
+
// What the last move did: the skipped entries and why, or the warning that stopped it.
|
|
11
|
+
export const MOVE_REPORT = 'installation.moved.json';
|
|
12
|
+
const kitMove = () => import('@agentage/extension/host');
|
|
13
|
+
// An id in installation.json keeps its row: a rerun after a stop adds only what is missing.
|
|
14
|
+
const addRow = (kit, row) => kit.updateInstallation(getConfigDir(), (doc) => doc.extensions.some((r) => r.id === row.id)
|
|
15
|
+
? doc
|
|
16
|
+
: { ...doc, extensions: [...doc.extensions, row] });
|
|
17
|
+
// The daemon's own values win over the profile's: they were set after the move.
|
|
18
|
+
const addSettings = async (kit, id, settings) => {
|
|
19
|
+
if (Object.keys(settings).length === 0)
|
|
20
|
+
return;
|
|
21
|
+
await kit.withFileLock(settingsPath(), () => {
|
|
22
|
+
const all = readJson(settingsPath(), isRecord) ?? {};
|
|
23
|
+
const mine = isRecord(all[id]) ? all[id] : {};
|
|
24
|
+
writeJsonAtomic(settingsPath(), { ...all, [id]: { ...settings, ...mine } }, 0o600);
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
const writeReport = (report) => writeJsonAtomic(join(getConfigDir(), MOVE_REPORT), report, 0o644);
|
|
28
|
+
const isSkipped = (v) => isRecord(v) && typeof v['entry'] === 'string' && typeof v['reason'] === 'string';
|
|
29
|
+
const isMoveReport = (v) => isRecord(v) &&
|
|
30
|
+
Array.isArray(v['moved']) &&
|
|
31
|
+
v['moved'].every((id) => typeof id === 'string') &&
|
|
32
|
+
Array.isArray(v['skipped']) &&
|
|
33
|
+
v['skipped'].every(isSkipped) &&
|
|
34
|
+
(v['warning'] === null || typeof v['warning'] === 'string');
|
|
35
|
+
export const readMoveReport = () => readJson(join(getConfigDir(), MOVE_REPORT), isMoveReport);
|
|
36
|
+
const say = (report) => {
|
|
37
|
+
if (report.moved.length > 0)
|
|
38
|
+
console.error(`moved ${report.moved.length} extensions into installation.json`);
|
|
39
|
+
for (const { entry, reason } of report.skipped)
|
|
40
|
+
console.error(`move skipped ${entry}: ${reason}`);
|
|
41
|
+
};
|
|
42
|
+
// A row the kit's check refuses is skipped with its reason; the other rows still move.
|
|
43
|
+
const addEntry = async (kit, moved, hooks) => {
|
|
44
|
+
try {
|
|
45
|
+
await addRow(kit, moved.row);
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
if (err.code !== 'VALIDATION_ERROR')
|
|
49
|
+
throw err;
|
|
50
|
+
return { entry: moved.row.id, reason: `the daemon refuses the row (${messageOf(err)})` };
|
|
51
|
+
}
|
|
52
|
+
await addSettings(kit, moved.row.id, moved.settings);
|
|
53
|
+
hooks.entry?.(moved);
|
|
54
|
+
return null;
|
|
55
|
+
};
|
|
56
|
+
const addAll = async (kit, report, plan, hooks) => {
|
|
57
|
+
for (const moved of plan) {
|
|
58
|
+
const skipped = await addEntry(kit, moved, hooks);
|
|
59
|
+
if (!skipped)
|
|
60
|
+
continue;
|
|
61
|
+
report.skipped.push(skipped);
|
|
62
|
+
report.moved = report.moved.filter((id) => id !== skipped.entry);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
// D6, before the daemon reads the file. An old list that does not parse moves nothing and writes
|
|
66
|
+
// no marker: the daemon still starts, and the next start tries again.
|
|
67
|
+
export const moveOldLists = async (hooks = {}) => {
|
|
68
|
+
const marker = join(ensureConfigDir(), MOVED_MARKER);
|
|
69
|
+
if (existsSync(marker))
|
|
70
|
+
return;
|
|
71
|
+
const plan = movePlan();
|
|
72
|
+
const report = {
|
|
73
|
+
moved: plan.moved.map((m) => m.row.id),
|
|
74
|
+
skipped: [...plan.skipped],
|
|
75
|
+
warning: plan.warning,
|
|
76
|
+
};
|
|
77
|
+
if (plan.warning) {
|
|
78
|
+
writeReport(report);
|
|
79
|
+
return console.error(`move: ${plan.warning}; nothing moved, fix it and restart the daemon`);
|
|
80
|
+
}
|
|
81
|
+
const kit = await (hooks.kit ?? kitMove)();
|
|
82
|
+
await addAll(kit, report, plan.moved, hooks);
|
|
83
|
+
writeReport(report);
|
|
84
|
+
writeFileSync(marker, `${new Date().toISOString()}\n`);
|
|
85
|
+
say(report);
|
|
86
|
+
};
|
|
87
|
+
// The daemon's `before`: a move that fails (a held lock, a full disk) never stops the start. No
|
|
88
|
+
// marker is written, so the next start tries again; `daemon status` shows the reason. Another live
|
|
89
|
+
// daemon on the folder is no move failure: this start ends, and that daemon's report stays.
|
|
90
|
+
export const moveBeforeStart = async (hooks = {}) => {
|
|
91
|
+
try {
|
|
92
|
+
await moveOldLists(hooks);
|
|
93
|
+
}
|
|
94
|
+
catch (err) {
|
|
95
|
+
if (err.code === 'DAEMON_RUNNING')
|
|
96
|
+
throw err;
|
|
97
|
+
const warning = `the move stopped (${messageOf(err)}); the next daemon start tries again`;
|
|
98
|
+
console.error(`move: ${warning}`);
|
|
99
|
+
try {
|
|
100
|
+
writeReport({ moved: [], skipped: [], warning });
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
// the report is only shown; the daemon still starts
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { CommanderError } from 'commander';
|
|
2
|
+
import { daemonPort, EADDRINUSE_EXIT } from '../../lib/daemon/daemon-file.js';
|
|
3
|
+
import { getConfigDir } from '../../lib/fs/config.js';
|
|
4
|
+
import { CliError } from '../../lib/json-output.js';
|
|
5
|
+
import { VERSION } from '../../utils/version.js';
|
|
6
|
+
import { KIT_EXIT } from '../extension/kit-commands.js';
|
|
7
|
+
const signalled = () => new Promise((resolve) => {
|
|
8
|
+
process.once('SIGTERM', resolve);
|
|
9
|
+
process.once('SIGINT', resolve);
|
|
10
|
+
});
|
|
11
|
+
// The kit's refusal of a second daemon on one config folder (from the move or from createDaemon).
|
|
12
|
+
const running = (err) => {
|
|
13
|
+
const { code, details } = err;
|
|
14
|
+
if (code !== 'DAEMON_RUNNING')
|
|
15
|
+
throw err;
|
|
16
|
+
const at = `pid ${details?.pid ?? '?'} on 127.0.0.1:${details?.port ?? '?'}`;
|
|
17
|
+
throw new CliError('already_running', `a daemon (${at}) runs on ${getConfigDir()} already`);
|
|
18
|
+
};
|
|
19
|
+
// A busy port exits EADDRINUSE_EXIT, so the cli that spawned this process stops waiting.
|
|
20
|
+
const busy = (err) => {
|
|
21
|
+
if (err.code !== 'EADDRINUSE')
|
|
22
|
+
return running(err);
|
|
23
|
+
console.error(`port ${daemonPort()} is in use`);
|
|
24
|
+
throw new CommanderError(EADDRINUSE_EXIT, KIT_EXIT, 'port in use');
|
|
25
|
+
};
|
|
26
|
+
// The daemon process (hidden `daemon run`): the kit's daemon until SIGTERM, then every child stops.
|
|
27
|
+
export const runDaemon = async (deps) => {
|
|
28
|
+
// Attached first: a stop during the move or the boot is kept and served once the boot ends.
|
|
29
|
+
const stopping = signalled();
|
|
30
|
+
await deps.before?.().catch(running);
|
|
31
|
+
const { createDaemon } = await import('@agentage/extension/host');
|
|
32
|
+
const opts = { configDir: getConfigDir(), port: daemonPort(), version: VERSION };
|
|
33
|
+
const daemon = await createDaemon({ ...opts, install: deps.installer(), startedBy: 'cli' }).catch(busy);
|
|
34
|
+
await stopping;
|
|
35
|
+
await daemon.stop();
|
|
36
|
+
};
|
|
@@ -1,17 +1,26 @@
|
|
|
1
1
|
import { type Command } from 'commander';
|
|
2
2
|
import type { BuildOptions } from '@agentage/extension/tool';
|
|
3
3
|
import { type LoadKitTool } from './kit-tool.js';
|
|
4
|
-
|
|
4
|
+
import { type PackageBuild } from './package-build.js';
|
|
5
|
+
export type ExtensionBuildOptions = Pick<BuildOptions, 'push' | 'dir' | 'registry' | 'container'> & {
|
|
6
|
+
docker?: boolean;
|
|
7
|
+
json?: boolean;
|
|
8
|
+
};
|
|
5
9
|
export type ExtensionCheckOptions = {
|
|
6
10
|
dir?: string;
|
|
7
11
|
json?: boolean;
|
|
8
12
|
write?: boolean;
|
|
9
13
|
};
|
|
10
|
-
export
|
|
11
|
-
export declare const runExtensionCheck: ({ dir, json, write }?: ExtensionCheckOptions, tool?: LoadKitTool, writer?: LoadWriter) => Promise<void>;
|
|
14
|
+
export declare const runExtensionCheck: ({ dir, json, write }?: ExtensionCheckOptions, tool?: LoadKitTool) => Promise<void>;
|
|
12
15
|
export type Committed = (dir: string) => Promise<void>;
|
|
13
16
|
export declare const assertCommitted: Committed;
|
|
14
|
-
export declare const
|
|
17
|
+
export declare const runImageBuild: (opts?: ExtensionBuildOptions, tool?: LoadKitTool, committed?: Committed) => Promise<unknown>;
|
|
18
|
+
export interface BuildFlagDeps {
|
|
19
|
+
tool: LoadKitTool;
|
|
20
|
+
committed: Committed;
|
|
21
|
+
pkg: (dir?: string) => Promise<PackageBuild>;
|
|
22
|
+
}
|
|
23
|
+
export declare const runExtensionBuild: (opts?: ExtensionBuildOptions, deps?: BuildFlagDeps) => Promise<unknown>;
|
|
15
24
|
export interface BuildActions {
|
|
16
25
|
check: (opts: ExtensionCheckOptions) => Promise<void>;
|
|
17
26
|
build: (opts: ExtensionBuildOptions) => Promise<void>;
|
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
import { execFile } from 'node:child_process';
|
|
2
2
|
import { promisify } from 'node:util';
|
|
3
3
|
import {} from 'commander';
|
|
4
|
+
import { addJson, CliError, omitJson } from '../../lib/json-output.js';
|
|
4
5
|
import { loadKitTool } from './kit-tool.js';
|
|
5
|
-
|
|
6
|
-
const loadWriter = () => import('@agentage/extension/tool');
|
|
6
|
+
import { buildPackage } from './package-build.js';
|
|
7
7
|
// With --json the written paths go to stderr, so stdout stays one JSON document.
|
|
8
|
-
const writeContracts = async (dir,
|
|
9
|
-
const
|
|
10
|
-
if (typeof write !== 'function')
|
|
11
|
-
throw new Error('check --write needs @agentage/extension >= 0.5.1');
|
|
12
|
-
for (const file of await write(dir))
|
|
8
|
+
const writeContracts = async (dir, tool, json) => {
|
|
9
|
+
for (const file of await (await tool()).writeContracts(dir))
|
|
13
10
|
(json ? console.error : console.log)(`wrote ${file}`);
|
|
14
11
|
};
|
|
15
12
|
// The kit's lines, or its report as JSON, on stdout; a package that does not conform exits 1.
|
|
16
|
-
export const runExtensionCheck = async ({ dir = '.', json, write } = {}, tool = loadKitTool
|
|
13
|
+
export const runExtensionCheck = async ({ dir = '.', json, write } = {}, tool = loadKitTool) => {
|
|
17
14
|
if (write)
|
|
18
|
-
await writeContracts(dir,
|
|
15
|
+
await writeContracts(dir, tool, json);
|
|
19
16
|
const { check, checkLines } = await tool();
|
|
20
17
|
const report = await check(dir);
|
|
21
18
|
const lines = checkLines(report);
|
|
@@ -23,31 +20,74 @@ export const runExtensionCheck = async ({ dir = '.', json, write } = {}, tool =
|
|
|
23
20
|
for (const line of json ? [JSON.stringify(report, null, 2)] : lines)
|
|
24
21
|
console.log(line);
|
|
25
22
|
if (!report.conforms)
|
|
26
|
-
throw new
|
|
23
|
+
throw new CliError('not_conforming', fail ?? 'does not conform');
|
|
27
24
|
};
|
|
28
25
|
// The build record names HEAD, so the tree it builds must be HEAD.
|
|
29
26
|
export const assertCommitted = async (dir) => {
|
|
30
|
-
const status = promisify(execFile)('git', ['status', '--porcelain'], {
|
|
27
|
+
const status = promisify(execFile)('git', ['status', '--porcelain'], {
|
|
28
|
+
cwd: dir,
|
|
29
|
+
timeout: 30_000,
|
|
30
|
+
});
|
|
31
31
|
const { stdout } = await status.catch(() => {
|
|
32
32
|
throw new Error(`${dir} is not a git checkout: commit first`);
|
|
33
33
|
});
|
|
34
34
|
if (stdout.trim())
|
|
35
|
-
throw new
|
|
35
|
+
throw new CliError('uncommitted_changes', `${dir} has uncommitted changes: commit first`);
|
|
36
36
|
};
|
|
37
|
-
//
|
|
38
|
-
export const
|
|
37
|
+
// The images of the kit recipe, from a committed tree: --push (the release path) or --container.
|
|
38
|
+
export const runImageBuild = async (opts = {}, tool = loadKitTool, committed = assertCommitted) => {
|
|
39
39
|
await committed(opts.dir ?? '.');
|
|
40
40
|
const { build, buildLines } = await tool();
|
|
41
|
-
|
|
41
|
+
const kit = omitJson(opts);
|
|
42
|
+
delete kit.docker;
|
|
43
|
+
const result = await build(kit);
|
|
44
|
+
for (const line of buildLines(result))
|
|
42
45
|
console.log(line);
|
|
46
|
+
return result;
|
|
47
|
+
};
|
|
48
|
+
const defaultFlagDeps = {
|
|
49
|
+
tool: loadKitTool,
|
|
50
|
+
committed: assertCommitted,
|
|
51
|
+
pkg: (dir) => buildPackage(dir),
|
|
52
|
+
};
|
|
53
|
+
const refusedFlags = (opts) => {
|
|
54
|
+
if (opts.container && opts.docker)
|
|
55
|
+
return '--container and --docker: pick one';
|
|
56
|
+
if (opts.registry && !opts.push && !opts.container && !opts.docker)
|
|
57
|
+
return '--registry names where images go: use it with --docker, --container or --push';
|
|
58
|
+
return '';
|
|
59
|
+
};
|
|
60
|
+
// The package with no Docker: the build script, the contracts, then check; it must conform.
|
|
61
|
+
const packageOnly = async (dir, deps) => {
|
|
62
|
+
const { report, ...done } = await deps.pkg(dir);
|
|
63
|
+
const lines = (await deps.tool()).checkLines(report);
|
|
64
|
+
const fail = report.conforms ? undefined : lines.pop();
|
|
65
|
+
for (const line of lines)
|
|
66
|
+
console.log(line);
|
|
67
|
+
if (!report.conforms)
|
|
68
|
+
throw new CliError('not_conforming', fail ?? 'does not conform');
|
|
69
|
+
return { ...done, conforms: true };
|
|
70
|
+
};
|
|
71
|
+
// No flag: the package. --docker: the part images; --container: one image; --push: pushed, with the record.
|
|
72
|
+
export const runExtensionBuild = async (opts = {}, deps = defaultFlagDeps) => {
|
|
73
|
+
const refused = refusedFlags(opts);
|
|
74
|
+
if (refused)
|
|
75
|
+
throw new CliError('invalid_argument', refused);
|
|
76
|
+
if (!opts.push && !opts.container && !opts.docker)
|
|
77
|
+
return packageOnly(opts.dir, deps);
|
|
78
|
+
return runImageBuild(opts, deps.tool, deps.committed);
|
|
43
79
|
};
|
|
44
80
|
const BUILD_HELP = `
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
81
|
+
With no flag, builds the package in --dir (default: the current folder) with no Docker: its own
|
|
82
|
+
build script, then the contract files the kit writes (such as {id}.mcpc.json), then extension
|
|
83
|
+
check. Any folder state works, committed or not. Exits 1 when a step fails or the package does
|
|
84
|
+
not conform.
|
|
85
|
+
|
|
86
|
+
--container builds one image of the extension, ghcr.io/agentage/<id>:<version>, with the kit's
|
|
87
|
+
recipe (node:26-alpine, the kit host as its command). --docker builds one
|
|
88
|
+
image per server part on this machine. --push builds those, pushes them (run docker login first)
|
|
89
|
+
and writes dist/agentage-extension.json, the build record with every image by digest; with
|
|
90
|
+
--container it pushes the one image. Each needs docker and a committed tree.`;
|
|
51
91
|
export const addBuild = (group, { check, build }) => {
|
|
52
92
|
group
|
|
53
93
|
.command('check')
|
|
@@ -56,12 +96,14 @@ export const addBuild = (group, { check, build }) => {
|
|
|
56
96
|
.option('--json', 'machine-readable report')
|
|
57
97
|
.option('--write', 'write the committed contracts (such as {id}.mcpc.json) first, then check')
|
|
58
98
|
.action((dir, opts) => check({ dir, ...opts }));
|
|
59
|
-
group
|
|
99
|
+
addJson(group
|
|
60
100
|
.command('build')
|
|
61
|
-
.description('Build the
|
|
62
|
-
.option('--
|
|
101
|
+
.description('Build the extension package; --container = one image, all parts')
|
|
102
|
+
.option('--docker', 'one image per server part on this machine (needs docker)')
|
|
103
|
+
.option('--container', 'one image of the extension (needs docker)')
|
|
104
|
+
.option('--push', 'build and push the images, write the build record with their digests')
|
|
63
105
|
.option('--dir <path>', 'the extension package folder (default: the current folder)')
|
|
64
|
-
.option('--registry <host/owner>', 'image registry and owner (default: ghcr.io/agentage)')
|
|
106
|
+
.option('--registry <host/owner>', 'image registry and owner (default: ghcr.io/agentage)'))
|
|
65
107
|
.addHelpText('after', BUILD_HELP)
|
|
66
108
|
.action(build);
|
|
67
109
|
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type ConfirmIo, type LifecycleDeps } from './lifecycle.js';
|
|
2
|
+
export interface ConfigureOptions {
|
|
3
|
+
id: string;
|
|
4
|
+
pairs: string[];
|
|
5
|
+
secret?: boolean;
|
|
6
|
+
json?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface SecretInput extends ConfirmIo {
|
|
9
|
+
readStdin: () => Promise<string>;
|
|
10
|
+
}
|
|
11
|
+
type Tty = Pick<NodeJS.ReadStream, 'on' | 'off' | 'setRawMode' | 'resume' | 'pause'>;
|
|
12
|
+
export declare const readHidden: (question: string, { stdin, stderr }?: {
|
|
13
|
+
stdin: Tty;
|
|
14
|
+
stderr: Pick<NodeJS.WriteStream, "write">;
|
|
15
|
+
}) => Promise<string>;
|
|
16
|
+
export declare const stdinInput: (prompt: SecretInput["prompt"]) => SecretInput;
|
|
17
|
+
export declare const runConfigure: (opts: ConfigureOptions, deps: LifecycleDeps & {
|
|
18
|
+
input: SecretInput;
|
|
19
|
+
}) => Promise<{
|
|
20
|
+
keys: string[];
|
|
21
|
+
id: string;
|
|
22
|
+
version: string;
|
|
23
|
+
state: string;
|
|
24
|
+
error?: string;
|
|
25
|
+
}>;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { installationRows } from '../../core/loader/installed.js';
|
|
3
|
+
import { isRecord, readJson } from '../../lib/fs/json-file.js';
|
|
4
|
+
import { CliError, DaemonError, isJsonRun } from '../../lib/json-output.js';
|
|
5
|
+
import { report, specOf } from './lifecycle.js';
|
|
6
|
+
const ENTER = ['\r', '\n', '\u0004'];
|
|
7
|
+
const CTRL_C = '\u0003';
|
|
8
|
+
const BACKSPACE = '\u007f';
|
|
9
|
+
// One keypress: the answer so far, or null once Enter ends it.
|
|
10
|
+
const typed = (answer, char) => {
|
|
11
|
+
if (ENTER.includes(char))
|
|
12
|
+
return null;
|
|
13
|
+
return char === BACKSPACE ? answer.slice(0, -1) : answer + char;
|
|
14
|
+
};
|
|
15
|
+
export const readHidden = (question, { stdin, stderr } = process) => new Promise((resolve) => {
|
|
16
|
+
let answer = '';
|
|
17
|
+
const onData = (chunk) => {
|
|
18
|
+
for (const char of chunk.toString('utf-8')) {
|
|
19
|
+
const next = char === CTRL_C ? null : typed(answer, char);
|
|
20
|
+
if (next === null)
|
|
21
|
+
return finish(char === CTRL_C);
|
|
22
|
+
answer = next;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const finish = (interrupted) => {
|
|
26
|
+
stdin.off('data', onData).setRawMode(false).pause();
|
|
27
|
+
stderr.write('\n');
|
|
28
|
+
resolve(answer);
|
|
29
|
+
if (interrupted)
|
|
30
|
+
process.kill(process.pid, 'SIGINT');
|
|
31
|
+
};
|
|
32
|
+
stderr.write(question);
|
|
33
|
+
stdin.setRawMode(true).resume().on('data', onData);
|
|
34
|
+
});
|
|
35
|
+
const readAll = async () => {
|
|
36
|
+
let text = '';
|
|
37
|
+
for await (const chunk of process.stdin)
|
|
38
|
+
text += String(chunk);
|
|
39
|
+
return text;
|
|
40
|
+
};
|
|
41
|
+
export const stdinInput = (prompt) => ({
|
|
42
|
+
isTTY: process.stdin.isTTY === true,
|
|
43
|
+
readStdin: readAll,
|
|
44
|
+
prompt,
|
|
45
|
+
});
|
|
46
|
+
const secretValue = async (key, input) => {
|
|
47
|
+
if (!input.isTTY)
|
|
48
|
+
return (await input.readStdin()).replace(/\r?\n$/, '');
|
|
49
|
+
if (isJsonRun())
|
|
50
|
+
throw new CliError('confirmation_required', `${key}: with --json, give the value on stdin`);
|
|
51
|
+
return input.prompt(`${key}: `);
|
|
52
|
+
};
|
|
53
|
+
// `key=value` pairs; with --secret a single bare key reads its value instead.
|
|
54
|
+
const valuesOf = async (opts, input) => {
|
|
55
|
+
const values = {};
|
|
56
|
+
for (const pair of opts.pairs) {
|
|
57
|
+
const at = pair.indexOf('=');
|
|
58
|
+
if (at > 0)
|
|
59
|
+
values[pair.slice(0, at)] = pair.slice(at + 1);
|
|
60
|
+
else if (at < 0 && opts.secret && opts.pairs.length === 1)
|
|
61
|
+
values[pair] = await secretValue(pair, input);
|
|
62
|
+
else
|
|
63
|
+
throw new CliError('invalid_argument', `${pair}: expected <key>=<value>`);
|
|
64
|
+
}
|
|
65
|
+
return values;
|
|
66
|
+
};
|
|
67
|
+
// The keys the installed package declares (null: its folder is not on this disk).
|
|
68
|
+
const declaredOf = (id) => {
|
|
69
|
+
const dir = installationRows().find((row) => row.id === id)?.dir;
|
|
70
|
+
if (!dir)
|
|
71
|
+
return null;
|
|
72
|
+
const agentage = readJson(join(dir, 'package.json'), isRecord)?.['agentage'];
|
|
73
|
+
const settings = isRecord(agentage) ? agentage['settings'] : undefined;
|
|
74
|
+
return Object.keys(isRecord(settings) ? settings : {});
|
|
75
|
+
};
|
|
76
|
+
// The daemon names the key it refused; the answer adds the keys the extension does declare.
|
|
77
|
+
const withDeclared = (id, err) => {
|
|
78
|
+
if (!(err instanceof DaemonError) || !/not declared/.test(err.message))
|
|
79
|
+
return err;
|
|
80
|
+
const keys = declaredOf(id);
|
|
81
|
+
const tail = keys === null
|
|
82
|
+
? 'see agentage.settings in its package.json'
|
|
83
|
+
: keys.length > 0
|
|
84
|
+
? `${id} declares: ${keys.join(', ')}`
|
|
85
|
+
: `${id} declares no settings`;
|
|
86
|
+
return new DaemonError(err.code, `${err.message}; ${tail}`);
|
|
87
|
+
};
|
|
88
|
+
// The daemon starts a new child with the values, then moves the route: no request is lost.
|
|
89
|
+
export const runConfigure = async (opts, deps) => {
|
|
90
|
+
const { id } = specOf(opts.id);
|
|
91
|
+
const values = await valuesOf(opts, deps.input);
|
|
92
|
+
const patch = opts.secret ? { secrets: values } : { settings: values };
|
|
93
|
+
const changed = (await deps.host()).change(id, patch).catch((err) => {
|
|
94
|
+
throw withDeclared(id, err);
|
|
95
|
+
});
|
|
96
|
+
const done = report(await changed);
|
|
97
|
+
const keys = Object.keys(values);
|
|
98
|
+
console.log(`${opts.secret ? 'secrets' : 'settings'} set: ${keys.join(', ')}`);
|
|
99
|
+
return { ...done, keys };
|
|
100
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type HostClient } from '../../lib/daemon/host-client.js';
|
|
2
|
+
import { type LoadKitTool } from './kit-tool.js';
|
|
3
|
+
import { type ConfirmIo } from './lifecycle.js';
|
|
4
|
+
import { type Npm, type PackageBuild } from './package-build.js';
|
|
5
|
+
export interface CreateInstallDeps {
|
|
6
|
+
npm: Npm;
|
|
7
|
+
build: (dir: string) => Promise<PackageBuild>;
|
|
8
|
+
daemon: () => Promise<{
|
|
9
|
+
port: number;
|
|
10
|
+
host: HostClient;
|
|
11
|
+
}>;
|
|
12
|
+
fetch: typeof fetch;
|
|
13
|
+
tool: LoadKitTool;
|
|
14
|
+
}
|
|
15
|
+
export declare const createInstallDeps: CreateInstallDeps;
|
|
16
|
+
export declare const publicPaths: (dir: string) => string[];
|
|
17
|
+
export declare const installCreated: (folder: string, install: boolean, deps?: CreateInstallDeps) => Promise<{
|
|
18
|
+
installed: null;
|
|
19
|
+
url: null;
|
|
20
|
+
} | {
|
|
21
|
+
installed: import("../../lib/daemon/host-client.js").HostSummary;
|
|
22
|
+
url: string | null;
|
|
23
|
+
}>;
|
|
24
|
+
export declare const trustFrom: (from: string, opts: {
|
|
25
|
+
yes?: boolean;
|
|
26
|
+
}, io?: ConfirmIo) => Promise<void>;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { join, resolve } from 'node:path';
|
|
3
|
+
import { ensureDaemon } from '../../lib/daemon/daemon-client.js';
|
|
4
|
+
import { daemonOff } from '../../lib/daemon/daemon-file.js';
|
|
5
|
+
import { hostClient } from '../../lib/daemon/host-client.js';
|
|
6
|
+
import { CliError } from '../../lib/json-output.js';
|
|
7
|
+
import { loadKitTool } from './kit-tool.js';
|
|
8
|
+
import { confirmed, report, summaryOf, terminalIo } from './lifecycle.js';
|
|
9
|
+
import { ignoreLocal } from './up-local.js';
|
|
10
|
+
import { buildPackage, npmIn } from './package-build.js';
|
|
11
|
+
export const createInstallDeps = {
|
|
12
|
+
npm: npmIn,
|
|
13
|
+
build: (dir) => buildPackage(dir),
|
|
14
|
+
daemon: async () => {
|
|
15
|
+
const port = await ensureDaemon();
|
|
16
|
+
return { port, host: hostClient(port) };
|
|
17
|
+
},
|
|
18
|
+
fetch: (...args) => fetch(...args),
|
|
19
|
+
tool: loadKitTool,
|
|
20
|
+
};
|
|
21
|
+
// The public GET routes the package's openapi.json names that need no parameter (such as ping).
|
|
22
|
+
export const publicPaths = (dir) => {
|
|
23
|
+
const file = join(dir, 'openapi.json');
|
|
24
|
+
if (!existsSync(file))
|
|
25
|
+
return [];
|
|
26
|
+
const doc = JSON.parse(readFileSync(file, 'utf8'));
|
|
27
|
+
return Object.entries(doc.paths ?? {})
|
|
28
|
+
.filter(([, { get }]) => get && !get.security?.length && !get.parameters?.some((p) => p.required))
|
|
29
|
+
.map(([path]) => path);
|
|
30
|
+
};
|
|
31
|
+
// The first of those that answers 2xx through the daemon.
|
|
32
|
+
const answering = async (deps, port, dir) => {
|
|
33
|
+
for (const path of publicPaths(dir)) {
|
|
34
|
+
const url = `http://127.0.0.1:${port}${path}`;
|
|
35
|
+
const res = await deps.fetch(url, { signal: AbortSignal.timeout(5_000) }).catch(() => null);
|
|
36
|
+
if (res?.ok)
|
|
37
|
+
return url;
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
};
|
|
41
|
+
// The check's problem lines go to stderr, then the command fails naming the folder.
|
|
42
|
+
const conforms = async (dir, deps) => {
|
|
43
|
+
const { report: checked } = await deps.build(dir);
|
|
44
|
+
if (checked.conforms)
|
|
45
|
+
return;
|
|
46
|
+
for (const text of (await deps.tool()).checkLines(checked))
|
|
47
|
+
console.error(`check ${text}`);
|
|
48
|
+
throw new CliError('not_conforming', `${dir} does not conform: agentage extension check`);
|
|
49
|
+
};
|
|
50
|
+
// After the scaffold: npm ci, the package build, then the daemon runs the folder (POST {source});
|
|
51
|
+
// --no-install leaves the scaffold as it is: no npm, no build.
|
|
52
|
+
export const installCreated = async (folder, install, deps = createInstallDeps) => {
|
|
53
|
+
if (!install)
|
|
54
|
+
return { installed: null, url: null };
|
|
55
|
+
const dir = resolve(folder);
|
|
56
|
+
await deps.npm(dir, ['ci', '--ignore-scripts', '--no-audit', '--no-fund']);
|
|
57
|
+
await conforms(dir, deps);
|
|
58
|
+
ignoreLocal(dir);
|
|
59
|
+
if (daemonOff()) {
|
|
60
|
+
console.log(' install the daemon is off (AGENTAGE_NO_DAEMON=1): not installed');
|
|
61
|
+
return { installed: null, url: null };
|
|
62
|
+
}
|
|
63
|
+
const { port, host } = await deps.daemon();
|
|
64
|
+
const installed = summaryOf(report(await host.add({ source: dir })));
|
|
65
|
+
const url = await answering(deps, port, dir);
|
|
66
|
+
console.log(url ? ` url ${url}` : ' url none answers yet: agentage extension list');
|
|
67
|
+
return { installed, url };
|
|
68
|
+
};
|
|
69
|
+
const OWN_TEMPLATE = 'agentage/extension-template';
|
|
70
|
+
// Another repo, or a branch of ours, is code nobody reviewed for you: its build script runs here.
|
|
71
|
+
export const trustFrom = async (from, opts, io = terminalIo()) => {
|
|
72
|
+
if (from === OWN_TEMPLATE)
|
|
73
|
+
return;
|
|
74
|
+
console.error(`template ${from}: code from that repo will be built and run on this machine`);
|
|
75
|
+
if (opts.yes)
|
|
76
|
+
return;
|
|
77
|
+
if (!io.isTTY)
|
|
78
|
+
throw new CliError('invalid_argument', `--from ${from} with no terminal: pass --yes to run it`);
|
|
79
|
+
if (!(await confirmed(io, 'run it? (y/N) ')))
|
|
80
|
+
throw new CliError('cancelled', `--from ${from}: not confirmed, nothing created`);
|
|
81
|
+
};
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { type Command } from 'commander';
|
|
2
|
+
import { installCreated } from './create-install.js';
|
|
3
|
+
import { type ConfirmIo } from './lifecycle.js';
|
|
2
4
|
export declare const TEMPLATE = "agentage/extension-template";
|
|
3
5
|
export declare const PARTS: string[];
|
|
4
6
|
export interface ExtensionCreateOptions {
|
|
5
7
|
id: string;
|
|
6
8
|
parts: string[];
|
|
7
9
|
from?: string;
|
|
10
|
+
install?: boolean;
|
|
11
|
+
yes?: boolean;
|
|
12
|
+
json?: boolean;
|
|
8
13
|
}
|
|
9
|
-
export declare const runExtensionCreate: (opts: ExtensionCreateOptions, url?: (from: string) => string) => Promise<
|
|
14
|
+
export declare const runExtensionCreate: (opts: ExtensionCreateOptions, url?: (from: string) => string, after?: typeof installCreated, io?: ConfirmIo) => Promise<unknown>;
|
|
10
15
|
export declare const addCreate: (group: Command, create: (o: ExtensionCreateOptions) => Promise<void>) => Command;
|