@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
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
2
|
import { pendingChanges } from '../../core/installer/plan.js';
|
|
3
|
+
import { line } from './line.js';
|
|
3
4
|
import {} from './rows.js';
|
|
4
5
|
const COLOR = {
|
|
5
6
|
installed: chalk.green,
|
|
@@ -11,7 +12,6 @@ const COLOR = {
|
|
|
11
12
|
missing: chalk.yellow,
|
|
12
13
|
};
|
|
13
14
|
const STATE_WIDTH = Math.max(...Object.keys(COLOR).map((state) => state.length));
|
|
14
|
-
const line = (label, value) => `${label.padEnd(10)} ${value}`;
|
|
15
15
|
const cloudText = ({ version, etag }) => chalk.yellow(`; account: version ${version}, etag ${etag} - run agentage setup`);
|
|
16
16
|
const profileText = (profile) => {
|
|
17
17
|
if (profile.state === 'missing')
|
|
@@ -46,22 +46,21 @@ const wantedText = (row) => {
|
|
|
46
46
|
return 'dev';
|
|
47
47
|
return row.wanted === null ? 'not in profile' : `wants ${row.wanted}`;
|
|
48
48
|
};
|
|
49
|
-
const rowLine = (row, widths
|
|
49
|
+
const rowLine = (row, widths) => {
|
|
50
50
|
const id = (row.id ?? '?').padEnd(widths.id);
|
|
51
51
|
const state = COLOR[row.state](row.state.padEnd(STATE_WIDTH));
|
|
52
52
|
const drift = widths.drift === 0 ? '' : `${driftOf(row).padEnd(widths.drift)} `;
|
|
53
53
|
const pkg = `${row.package} ${row.installed ?? '-'} (${wantedText(row)})`;
|
|
54
|
-
const newest = latest ? ` latest ${latest.get(row.id ?? '') ?? '-'}` : '';
|
|
55
54
|
const commands = row.commands.length > 0 ? ` commands: ${row.commands.join(', ')}` : '';
|
|
56
55
|
// A failed load quotes the extension's own message; the core's reasons print as they are.
|
|
57
56
|
const reason = row.state === 'failed' ? `"${row.error}"` : row.error;
|
|
58
57
|
const error = row.error === null ? '' : chalk.dim(` ${reason}`);
|
|
59
|
-
return `${id} ${state} ${drift}${pkg}${
|
|
58
|
+
return `${id} ${state} ${drift}${pkg}${commands}${lastRunText(row.lastRun)}${error}`;
|
|
60
59
|
};
|
|
61
|
-
export const rowLines = (rows
|
|
60
|
+
export const rowLines = (rows) => {
|
|
62
61
|
const id = Math.max(0, ...rows.map((row) => (row.id ?? '?').length));
|
|
63
62
|
const drift = Math.max(0, ...rows.map((row) => driftOf(row).length));
|
|
64
|
-
return rows.map((row) => rowLine(row, { id, drift }
|
|
63
|
+
return rows.map((row) => rowLine(row, { id, drift }));
|
|
65
64
|
};
|
|
66
65
|
export const printWarnings = (warnings) => {
|
|
67
66
|
for (const warning of warnings)
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { CliError } from '../../lib/json-output.js';
|
|
1
2
|
import {} from '../../core/installer/plan.js';
|
|
2
3
|
import {} from '../../core/loader/discover.js';
|
|
3
4
|
import {} from '../../core/loader/load.js';
|
|
4
|
-
import { loadSet,
|
|
5
|
+
import { loadSet, scanNow } from '../../core/loader/scan.js';
|
|
5
6
|
import { readRunState } from '../../core/loader/state.js';
|
|
6
7
|
import {} from '../../core/loader/states.js';
|
|
7
8
|
import { claimVerbs, commandNames, readHeld } from '../../core/loader/verbs.js';
|
|
@@ -56,12 +57,13 @@ export const gatherFrom = (found, runs = new Map()) => {
|
|
|
56
57
|
plan: found.plan.summary,
|
|
57
58
|
extensions,
|
|
58
59
|
};
|
|
59
|
-
const
|
|
60
|
+
const old = found.found.extensions.flatMap((p) => (p.warning ? [`${p.id}: ${p.warning}`] : []));
|
|
61
|
+
const warnings = [...(parsed?.ok ? parsed.warnings : []), ...found.found.warnings, ...old];
|
|
60
62
|
return { status, warnings, drift: found.drift, verbs: seen.verbs };
|
|
61
63
|
};
|
|
62
64
|
// Reads manifests, profile and state files; writes only a missing machine.json.
|
|
63
|
-
export const gatherExtensions = async () => gatherFrom(
|
|
65
|
+
export const gatherExtensions = async () => gatherFrom(scanNow(await loadMachine()));
|
|
64
66
|
// The report still prints first; an invalid profile.json then fails the step.
|
|
65
67
|
export const invalidProfileError = (profile) => profile.state === 'invalid'
|
|
66
|
-
? new
|
|
68
|
+
? new CliError('profile_invalid', `profile.json is invalid:\n${profile.errors.map((e) => ` ${e}`).join('\n')}`)
|
|
67
69
|
: null;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type EditDeps } from './sync.js';
|
|
1
|
+
import { type EditDeps, type ProfileDeps } from './sync.js';
|
|
2
2
|
export interface AccountSetupDeps extends EditDeps {
|
|
3
3
|
signOut: () => Promise<void>;
|
|
4
4
|
}
|
|
5
|
-
export declare const accountSetup: (deps:
|
|
5
|
+
export declare const accountSetup: (deps: ProfileDeps) => Promise<void>;
|
|
6
6
|
export declare const disconnect: (deps: AccountSetupDeps) => Promise<void>;
|
|
@@ -5,7 +5,7 @@ import { defaultProfile, mutateProfile, readProfile } from '../../core/profile/p
|
|
|
5
5
|
import { pushWithReplay } from '../../core/profile/push.js';
|
|
6
6
|
import { disconnectMachine, registerMachine } from '../../core/profile/register.js';
|
|
7
7
|
import {} from '../../core/profile/schema.js';
|
|
8
|
-
import {
|
|
8
|
+
import { line } from './line.js';
|
|
9
9
|
import { applying, checkAccount } from './sync.js';
|
|
10
10
|
const FILE_NOTE = 'from a file (setup --profile), not synced with your account';
|
|
11
11
|
// profile.json: null when absent; an invalid one stops setup naming each problem.
|
|
@@ -26,12 +26,13 @@ const fromLocalCopy = async (reason, deps) => {
|
|
|
26
26
|
if (local === null)
|
|
27
27
|
return console.error(chalk.dim(`${unavailable} and no local profile.json, nothing installed (${reason})`));
|
|
28
28
|
console.error(chalk.dim(`${unavailable}, using local profile.json (${reason})`));
|
|
29
|
-
await
|
|
29
|
+
await deps.installProfile(local);
|
|
30
30
|
};
|
|
31
31
|
const installPulled = async (doc, deps) => {
|
|
32
32
|
await mutateProfile(() => doc.profile);
|
|
33
33
|
console.log(line('profile', `pulled from your account (etag ${doc.etag})`));
|
|
34
|
-
await
|
|
34
|
+
await setCloud(doc.etag);
|
|
35
|
+
await deps.installProfile(doc.profile);
|
|
35
36
|
};
|
|
36
37
|
// A create the account did not take fails nothing: the next setup creates it.
|
|
37
38
|
const notCreated = (err) => {
|
|
@@ -55,7 +56,7 @@ const createIn = async (account, deps) => {
|
|
|
55
56
|
const profileFrom = async (account, machine, deps) => {
|
|
56
57
|
if (machine.profileSource === 'file') {
|
|
57
58
|
console.log(line('profile', FILE_NOTE));
|
|
58
|
-
return
|
|
59
|
+
return deps.installProfile(localCopy() ?? defaultProfile());
|
|
59
60
|
}
|
|
60
61
|
const pulled = await pullProfile(account.fetch, mirroredEtag(machine));
|
|
61
62
|
if (pulled.kind === 'found')
|
|
@@ -63,7 +64,7 @@ const profileFrom = async (account, machine, deps) => {
|
|
|
63
64
|
if (pulled.kind === 'none')
|
|
64
65
|
return createIn(account, deps);
|
|
65
66
|
if (pulled.kind === 'current')
|
|
66
|
-
return
|
|
67
|
+
return deps.installProfile(localCopy() ?? defaultProfile());
|
|
67
68
|
return fromLocalCopy(pulled.reason, deps);
|
|
68
69
|
};
|
|
69
70
|
// The first signed-in setup records the account; another account is refused until --disconnect.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Profile } from '../../core/profile/schema.js';
|
|
2
|
+
import { type HostClient } from '../../lib/daemon/host-client.js';
|
|
3
|
+
export interface ProfileInstallDeps {
|
|
4
|
+
host: () => Promise<HostClient>;
|
|
5
|
+
daemonOff: boolean;
|
|
6
|
+
from: 'account' | 'file';
|
|
7
|
+
}
|
|
8
|
+
export declare const installThroughDaemon: (profile: Profile, deps: ProfileInstallDeps) => Promise<void>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { writeFileSync } from 'node:fs';
|
|
2
|
+
import {} from '../../core/profile/schema.js';
|
|
3
|
+
import {} from '../../lib/daemon/host-client.js';
|
|
4
|
+
import { CliError, messageOf } from '../../lib/json-output.js';
|
|
5
|
+
import { line } from './line.js';
|
|
6
|
+
import { addOnce } from './install-once.js';
|
|
7
|
+
import { accountProfileInstalled, NOT_EXTENSION, profileEntries, profileMarkerPath, } from './profile-plan.js';
|
|
8
|
+
const EXACT = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;
|
|
9
|
+
const KEPT = 'your account profile was installed here already; setup installs nothing (agentage extension install)';
|
|
10
|
+
// An exact version is sent as it is; a range installs the market's newest version.
|
|
11
|
+
const bodyOf = (id, range) => EXACT.test(range) ? { id, version: range } : { id };
|
|
12
|
+
// One entry through POST /host/extensions; an off entry is added disabled (it never starts).
|
|
13
|
+
const installOne = async (host, entry) => {
|
|
14
|
+
const off = entry.off ? { enabled: false } : {};
|
|
15
|
+
const { row, already } = await addOnce(host, { ...bodyOf(entry.id, entry.range), ...off });
|
|
16
|
+
return already ? { ...row, already } : row;
|
|
17
|
+
};
|
|
18
|
+
// A package that is not an extension is said and skipped: the daemon cannot install it, ever.
|
|
19
|
+
// A problem is the line under "not installed": the entry failed to install or to start.
|
|
20
|
+
const tryOne = async (host, entry) => {
|
|
21
|
+
if (entry.id === null)
|
|
22
|
+
return void console.log(`${entry.name}: ${NOT_EXTENSION}`);
|
|
23
|
+
const id = entry.id;
|
|
24
|
+
const row = await installOne(host, { ...entry, id }).catch((err) => ({
|
|
25
|
+
id,
|
|
26
|
+
error: messageOf(err),
|
|
27
|
+
}));
|
|
28
|
+
if ('error' in row && !('state' in row))
|
|
29
|
+
return `${id}: ${row.error}`;
|
|
30
|
+
if ('already' in row)
|
|
31
|
+
return void console.log(`${id} already installed`);
|
|
32
|
+
console.log(`${row.id} ${row.version} ${row.state}`);
|
|
33
|
+
return row.state === 'failed' ? `${id}: ${row.error ?? 'failed'}` : undefined;
|
|
34
|
+
};
|
|
35
|
+
// The profile's extensions go through the daemon, which runs them; the cli loads nothing itself.
|
|
36
|
+
// An entry already in the installation is left as it is.
|
|
37
|
+
export const installThroughDaemon = async (profile, deps) => {
|
|
38
|
+
const account = deps.from === 'account';
|
|
39
|
+
if (account && accountProfileInstalled())
|
|
40
|
+
return console.log(line('extensions', KEPT));
|
|
41
|
+
const entries = profileEntries(profile);
|
|
42
|
+
if (entries.length > 0 && deps.daemonOff)
|
|
43
|
+
return console.log(line('extensions', 'the daemon is off, nothing installed'));
|
|
44
|
+
const host = entries.length > 0 ? await deps.host() : null;
|
|
45
|
+
const problems = [];
|
|
46
|
+
for (const entry of host ? entries : []) {
|
|
47
|
+
const problem = await tryOne(host, entry);
|
|
48
|
+
if (problem)
|
|
49
|
+
problems.push(problem);
|
|
50
|
+
}
|
|
51
|
+
// An empty profile tried nothing: a later setup still installs one with entries.
|
|
52
|
+
if (account && host)
|
|
53
|
+
writeFileSync(profileMarkerPath(), `${new Date().toISOString()}\n`, { mode: 0o600 });
|
|
54
|
+
if (problems.length > 0)
|
|
55
|
+
throw new CliError('extension_failed', ['not installed:', ...problems.map((p) => ` ${p}`)].join('\n'));
|
|
56
|
+
};
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { type SetupDeps, type SetupOptions } from '../auth/setup.js';
|
|
2
|
+
import { type HostClient } from '../../lib/daemon/host-client.js';
|
|
2
3
|
import { type EditDeps } from './sync.js';
|
|
3
4
|
export interface ExtensionSetupDeps extends SetupDeps, EditDeps {
|
|
5
|
+
host: () => Promise<HostClient>;
|
|
6
|
+
updateExtensions: () => Promise<unknown>;
|
|
4
7
|
}
|
|
5
|
-
export declare const runExtensionSetup: (opts: SetupOptions, deps: ExtensionSetupDeps) => Promise<
|
|
8
|
+
export declare const runExtensionSetup: (opts: SetupOptions, deps: ExtensionSetupDeps) => Promise<unknown>;
|
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { rawPatToken } from '../../lib/auth/credentials.js';
|
|
2
3
|
import { loadMachine, setProfileSource } from '../../core/profile/machine.js';
|
|
3
4
|
import { keepMachine } from '../../core/profile/merge.js';
|
|
4
5
|
import { defaultProfile, mutateProfile, parseProfileText, readProfile, } from '../../core/profile/profile.js';
|
|
5
6
|
import {} from '../../core/profile/schema.js';
|
|
6
7
|
import {} from '../auth/setup.js';
|
|
7
|
-
import { installAndLoad } from './install-load.js';
|
|
8
|
-
import { runSetupLatest } from './latest.js';
|
|
9
8
|
import { printDryRun, runSetupCheck } from './plan.js';
|
|
10
9
|
import { printWarnings } from './row-lines.js';
|
|
11
10
|
import { accountSetup, disconnect } from './setup-cloud.js';
|
|
11
|
+
import { installThroughDaemon } from './setup-install.js';
|
|
12
|
+
import {} from '../../lib/daemon/host-client.js';
|
|
13
|
+
import { daemonOff } from '../../lib/daemon/daemon-file.js';
|
|
12
14
|
import {} from './sync.js';
|
|
15
|
+
import { CliError } from '../../lib/json-output.js';
|
|
13
16
|
const sourceOf = (label, parsed) => {
|
|
14
17
|
if (!parsed.ok)
|
|
15
|
-
throw new
|
|
16
|
-
return { profile: parsed.profile, warnings: parsed.warnings };
|
|
18
|
+
throw new CliError('profile_invalid', `${label} is invalid: ${parsed.errors.join('; ')}`);
|
|
19
|
+
return { profile: parsed.profile, warnings: parsed.warnings, from: label };
|
|
17
20
|
};
|
|
18
21
|
const fileSource = (file) => {
|
|
19
22
|
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(file))
|
|
@@ -32,37 +35,72 @@ const localSource = () => {
|
|
|
32
35
|
const parsed = readProfile();
|
|
33
36
|
if (parsed !== null)
|
|
34
37
|
return sourceOf('profile.json', parsed);
|
|
35
|
-
return { profile: defaultProfile(), warnings: [] };
|
|
38
|
+
return { profile: defaultProfile(), warnings: [], from: 'the built-in default profile' };
|
|
36
39
|
};
|
|
37
40
|
// --check and --dry-run read only and never sign in.
|
|
38
|
-
const readOnly = (source, opts) => {
|
|
41
|
+
const readOnly = (source, opts, file) => {
|
|
39
42
|
printWarnings(source.warnings);
|
|
43
|
+
const plan = { ...opts, file, from: source.from };
|
|
40
44
|
if (opts.check)
|
|
41
|
-
runSetupCheck(source.profile,
|
|
45
|
+
runSetupCheck(source.profile, plan);
|
|
42
46
|
else
|
|
43
|
-
printDryRun(source.profile,
|
|
47
|
+
printDryRun(source.profile, plan);
|
|
44
48
|
};
|
|
45
|
-
|
|
46
|
-
|
|
49
|
+
const noDaemon = (opts) => opts.daemon === false || daemonOff();
|
|
50
|
+
// `--profile` never signs in nor calls the account; it installs through the daemon as plain setup.
|
|
51
|
+
const fromFile = async (source, opts, deps) => {
|
|
47
52
|
const machine = await loadMachine();
|
|
48
53
|
await mutateProfile((current) => keepMachine(source.profile, current, machine.id));
|
|
49
54
|
await setProfileSource('file');
|
|
50
|
-
await
|
|
55
|
+
await installThroughDaemon(source.profile, {
|
|
56
|
+
host: deps.host,
|
|
57
|
+
daemonOff: noDaemon(opts),
|
|
58
|
+
from: 'file',
|
|
59
|
+
});
|
|
51
60
|
};
|
|
52
|
-
|
|
61
|
+
// The daemon needs no account; --no-daemon or AGENTAGE_NO_DAEMON=1 leave it off.
|
|
62
|
+
const startDaemon = async (opts, deps) => {
|
|
63
|
+
if (noDaemon(opts))
|
|
64
|
+
return;
|
|
65
|
+
console.log(`daemon running on 127.0.0.1:${await deps.startDaemon()}`);
|
|
66
|
+
};
|
|
67
|
+
// Plain setup installs the profile only through the daemon (one install path).
|
|
68
|
+
const profileDeps = (opts, deps) => ({
|
|
69
|
+
...deps,
|
|
70
|
+
installProfile: (profile) => installThroughDaemon(profile, {
|
|
71
|
+
host: deps.host,
|
|
72
|
+
daemonOff: noDaemon(opts),
|
|
73
|
+
from: 'account',
|
|
74
|
+
}),
|
|
75
|
+
});
|
|
76
|
+
// A token is the headless credential: no browser and no callback, so --reauth has nothing to do.
|
|
77
|
+
const signIn = async (opts, deps) => {
|
|
78
|
+
if (!rawPatToken())
|
|
79
|
+
return void (await deps.ensureSignedIn({ reauth: opts.reauth, browser: opts.browser }));
|
|
80
|
+
if (opts.reauth)
|
|
81
|
+
console.error('--reauth does nothing: AGENTAGE_TOKEN is set and is the credential');
|
|
82
|
+
};
|
|
83
|
+
const setupFlow = async (opts, deps) => {
|
|
53
84
|
if (opts.disconnect)
|
|
54
85
|
return disconnect(deps);
|
|
55
86
|
const file = opts.profile === undefined ? null : fileSource(opts.profile);
|
|
56
87
|
if (opts.check || opts.dryRun)
|
|
57
|
-
return readOnly(file ?? localSource(), opts);
|
|
88
|
+
return readOnly(file ?? localSource(), opts, file !== null);
|
|
58
89
|
if (file)
|
|
59
|
-
return fromFile(file, deps);
|
|
60
|
-
if (opts.latest)
|
|
61
|
-
|
|
62
|
-
|
|
90
|
+
return fromFile(file, opts, deps);
|
|
91
|
+
if (opts.latest) {
|
|
92
|
+
console.error('setup --latest is now: agentage extension update');
|
|
93
|
+
return void (await deps.updateExtensions());
|
|
94
|
+
}
|
|
63
95
|
const token = process.env['AGENTAGE_TOKEN'];
|
|
64
|
-
|
|
96
|
+
await signIn(opts, deps);
|
|
97
|
+
const failure = await accountSetup(profileDeps(opts, deps)).then(() => null, (error) => error);
|
|
65
98
|
await deps.printStatus({ token });
|
|
99
|
+
await startDaemon(opts, deps);
|
|
66
100
|
if (failure)
|
|
67
101
|
throw failure;
|
|
68
102
|
};
|
|
103
|
+
export const runExtensionSetup = async (opts, deps) => {
|
|
104
|
+
await setupFlow(opts, deps);
|
|
105
|
+
return undefined;
|
|
106
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type LoadKitTool } from './kit-tool.js';
|
|
2
|
+
import { type Exec } from './release-guard.js';
|
|
3
|
+
export declare const ownProject: (id: string, dir: string) => Promise<string>;
|
|
4
|
+
export declare const assertOwnStack: (dir: string, exec: Exec, tool: LoadKitTool) => Promise<void>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { readFile, realpath } from 'node:fs/promises';
|
|
3
|
+
import { join, resolve } from 'node:path';
|
|
4
|
+
import {} from './kit-tool.js';
|
|
5
|
+
import {} from './release-guard.js';
|
|
6
|
+
const FORMAT = '{{.Label "com.docker.compose.project"}}\t{{.Ports}}';
|
|
7
|
+
const HERE = 'run agentage extension up here';
|
|
8
|
+
// The kit's projectName over its workingCopy (not exported from /tool): one project per real path.
|
|
9
|
+
export const ownProject = async (id, dir) => {
|
|
10
|
+
const absolute = resolve(dir);
|
|
11
|
+
const real = await realpath(absolute).catch(() => absolute);
|
|
12
|
+
return `agentage-${id}-${createHash('sha256').update(real).digest('hex').slice(0, 8)}`;
|
|
13
|
+
};
|
|
14
|
+
const rendered = async (dir) => readFile(join(dir, '.agentage', 'compose.json'), 'utf8')
|
|
15
|
+
.then((text) => JSON.parse(text).name)
|
|
16
|
+
.catch(() => undefined);
|
|
17
|
+
// As the kit's down decides: this path's project, or the legacy one only when compose.json names it.
|
|
18
|
+
const accepts = async (dir, id, holder) => {
|
|
19
|
+
if (holder === (await ownProject(id, dir)))
|
|
20
|
+
return true;
|
|
21
|
+
return holder === `agentage-${id}` && (await rendered(dir)) === holder;
|
|
22
|
+
};
|
|
23
|
+
// The live signal: the row of the container that publishes the dev issuer's port, if any.
|
|
24
|
+
const issuerRow = async (exec) => {
|
|
25
|
+
const ran = await exec('docker', ['ps', '--format', FORMAT]);
|
|
26
|
+
if (!ran.ok)
|
|
27
|
+
throw new Error(`cannot ask docker which stack is up: ${ran.err}`);
|
|
28
|
+
return ran.out.split('\n').find((line) => line.includes(':4281->'));
|
|
29
|
+
};
|
|
30
|
+
const named = (project) => {
|
|
31
|
+
const id = /^agentage-([a-z][a-z0-9-]*)-[0-9a-f]{8}$/.exec(project)?.[1];
|
|
32
|
+
return id ? `extension ${id} (${project})` : `compose project ${project}`;
|
|
33
|
+
};
|
|
34
|
+
// A dev token only from the stack `up` started in this folder, never from another one.
|
|
35
|
+
export const assertOwnStack = async (dir, exec, tool) => {
|
|
36
|
+
const row = await issuerRow(exec);
|
|
37
|
+
if (row === undefined)
|
|
38
|
+
throw new Error(`no stack is up on localhost:4281: ${HERE}`);
|
|
39
|
+
const holder = row.split('\t')[0] ?? '';
|
|
40
|
+
if (!holder)
|
|
41
|
+
throw new Error(`localhost:4281 is held by a container that is not from compose: stop it, then ${HERE}`);
|
|
42
|
+
const { id } = (await (await tool()).readManifest(dir)).agentage;
|
|
43
|
+
if (!(await accepts(dir, id, holder)))
|
|
44
|
+
throw new Error(`the stack up is ${named(holder)}, not this folder: ${HERE}`);
|
|
45
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Npm } from '../../core/installer/npm.js';
|
|
2
|
-
import { type Account
|
|
2
|
+
import { type Account } from '../../core/profile/cloud.js';
|
|
3
3
|
import { type MachineFile } from '../../core/profile/machine.js';
|
|
4
|
-
import { type Apply
|
|
4
|
+
import { type Apply } from '../../core/profile/push.js';
|
|
5
5
|
import { type Profile } from '../../core/profile/schema.js';
|
|
6
6
|
import { type AccountOf } from './account.js';
|
|
7
7
|
export interface EditDeps {
|
|
@@ -9,14 +9,9 @@ export interface EditDeps {
|
|
|
9
9
|
npmMajor: () => Promise<number>;
|
|
10
10
|
account: AccountOf;
|
|
11
11
|
}
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
fetch: CloudFetch;
|
|
15
|
-
base: CloudProfile;
|
|
12
|
+
export interface ProfileDeps extends EditDeps {
|
|
13
|
+
installProfile: (profile: Profile) => Promise<void>;
|
|
16
14
|
}
|
|
15
|
+
export type Change = (profile: Profile) => Profile;
|
|
17
16
|
export declare const checkAccount: (account: Account, machine: MachineFile) => Promise<string | null>;
|
|
18
|
-
export declare const
|
|
19
|
-
export declare const localLock: (deps: EditDeps) => Promise<LockPair>;
|
|
20
|
-
export declare const applying: (change: Change, deps: EditDeps, note?: string | null) => Apply;
|
|
21
|
-
export declare const pushApplied: (synced: Synced, apply: Apply, opts?: ReplayOptions) => Promise<Pushed>;
|
|
22
|
-
export declare const finishEdit: (synced: Synced | null, change: Change, deps: EditDeps, note?: string | null) => Promise<void>;
|
|
17
|
+
export declare const applying: (change: Change, deps: ProfileDeps, note?: string | null) => Apply;
|
|
@@ -3,15 +3,13 @@ import { parseLock } from '../../core/installer/compare-lock.js';
|
|
|
3
3
|
import {} from '../../core/installer/npm.js';
|
|
4
4
|
import { LOCK_FILE, readText } from '../../core/installer/tree.js';
|
|
5
5
|
import { extensionsDir } from '../../core/paths.js';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import { pushBody, pushWithReplay, } from '../../core/profile/push.js';
|
|
6
|
+
import {} from '../../core/profile/cloud.js';
|
|
7
|
+
import { accountMismatch } from '../../core/profile/machine.js';
|
|
8
|
+
import { mutateProfile } from '../../core/profile/profile.js';
|
|
9
|
+
import { pushBody } from '../../core/profile/push.js';
|
|
11
10
|
import {} from '../../core/profile/schema.js';
|
|
12
11
|
import {} from './account.js';
|
|
13
|
-
import {
|
|
14
|
-
const NOT_SIGNED_IN = 'not signed in - run: agentage setup (this machine syncs its profile with your account)';
|
|
12
|
+
import { line } from './line.js';
|
|
15
13
|
const REPLAY = 'changed in your account meanwhile, replaying this change on it';
|
|
16
14
|
// The signed-in account's id, refused when this machine is connected to another account.
|
|
17
15
|
export const checkAccount = async (account, machine) => {
|
|
@@ -21,27 +19,12 @@ export const checkAccount = async (account, machine) => {
|
|
|
21
19
|
throw mismatch;
|
|
22
20
|
return userId;
|
|
23
21
|
};
|
|
24
|
-
// Pulled whole, before anything changes, so the edit applies to the account's newest document.
|
|
25
|
-
export const pullForEdit = async (deps) => {
|
|
26
|
-
const machine = await loadMachine();
|
|
27
|
-
if (machine.profileSource !== 'cloud')
|
|
28
|
-
return null;
|
|
29
|
-
const account = await deps.account();
|
|
30
|
-
if (account === null)
|
|
31
|
-
throw new Error(NOT_SIGNED_IN);
|
|
32
|
-
await checkAccount(account, machine);
|
|
33
|
-
const pulled = await pullProfile(account.fetch, null);
|
|
34
|
-
if (pulled.kind === 'unavailable')
|
|
35
|
-
throw new Error(`cloud profile unavailable (${pulled.reason}); nothing changed`);
|
|
36
|
-
const base = pulled.kind === 'found' ? pulled.doc : localProfile(editableProfile());
|
|
37
|
-
return { fetch: account.fetch, base };
|
|
38
|
-
};
|
|
39
22
|
// extensions/package-lock.json and the npm major that wrote it, pushed with the profile.
|
|
40
|
-
|
|
23
|
+
const localLock = async (deps) => {
|
|
41
24
|
const lock = parseLock(readText(join(extensionsDir(), LOCK_FILE)));
|
|
42
25
|
return { lock, npmMajor: lock === null ? null : await deps.npmMajor() };
|
|
43
26
|
};
|
|
44
|
-
// Nothing is pushed unless the
|
|
27
|
+
// Nothing is pushed unless the install worked: installProfile throws otherwise.
|
|
45
28
|
export const applying = (change, deps, note = null) => {
|
|
46
29
|
let calls = 0;
|
|
47
30
|
return async (base) => {
|
|
@@ -50,32 +33,7 @@ export const applying = (change, deps, note = null) => {
|
|
|
50
33
|
const text = calls++ === 0 ? note : line('profile', REPLAY);
|
|
51
34
|
if (text !== null)
|
|
52
35
|
console.log(text);
|
|
53
|
-
await
|
|
36
|
+
await deps.installProfile(next);
|
|
54
37
|
return pushBody(next, base, await localLock(deps));
|
|
55
38
|
};
|
|
56
39
|
};
|
|
57
|
-
const onThisMachine = async (change, deps, note) => {
|
|
58
|
-
await changeProfile(change);
|
|
59
|
-
if (note !== null)
|
|
60
|
-
console.log(note);
|
|
61
|
-
await installAndLoad(editableProfile(), deps.npm);
|
|
62
|
-
};
|
|
63
|
-
const installedHere = (err) => {
|
|
64
|
-
if (!(err instanceof NotPushedError))
|
|
65
|
-
throw err;
|
|
66
|
-
throw new Error(`${err.message}; installed here only, run the command again to push it`);
|
|
67
|
-
};
|
|
68
|
-
// `apply` installs and loads before it returns the body: a failed load pushes nothing.
|
|
69
|
-
export const pushApplied = async (synced, apply, opts = {}) => {
|
|
70
|
-
const done = await pushWithReplay(synced.fetch, synced.base, apply, opts).catch(installedHere);
|
|
71
|
-
await setCloud(done.etag);
|
|
72
|
-
return done;
|
|
73
|
-
};
|
|
74
|
-
// install, remove and --off end here; the account gets the change only after the tree loaded.
|
|
75
|
-
export const finishEdit = async (synced, change, deps, note = null) => {
|
|
76
|
-
if (synced === null)
|
|
77
|
-
return onThisMachine(change, deps, note);
|
|
78
|
-
const done = await pushApplied(synced, applying(change, deps, note));
|
|
79
|
-
const where = done.pushed ? 'pushed to' : 'already in';
|
|
80
|
-
console.log(line('profile', `${where} your account (etag ${done.etag})`));
|
|
81
|
-
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Command } from 'commander';
|
|
2
|
+
import { type ExtensionDownOptions, type ExtensionTokenOptions, type ExtensionUpFlags } from './up.js';
|
|
3
|
+
export declare const issuerUrl: (value: string) => string;
|
|
4
|
+
export interface KitActions {
|
|
5
|
+
up: (opts: ExtensionUpFlags) => Promise<void>;
|
|
6
|
+
down: (opts: ExtensionDownOptions) => Promise<void>;
|
|
7
|
+
token: (opts: ExtensionTokenOptions) => Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export declare const addKitTools: (group: Command, actions: KitActions) => void;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { InvalidArgumentError } from 'commander';
|
|
2
|
+
import { addJson } from '../../lib/json-output.js';
|
|
3
|
+
import {} from './up.js';
|
|
4
|
+
// A usage error (exit 2) before the kit is asked: the issuer is an http: or https: URL.
|
|
5
|
+
export const issuerUrl = (value) => {
|
|
6
|
+
let protocol;
|
|
7
|
+
try {
|
|
8
|
+
protocol = new URL(value).protocol;
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
throw new InvalidArgumentError('not a URL.');
|
|
12
|
+
}
|
|
13
|
+
if (protocol === 'http:' || protocol === 'https:')
|
|
14
|
+
return value;
|
|
15
|
+
throw new InvalidArgumentError('not an http: or https: URL.');
|
|
16
|
+
};
|
|
17
|
+
const UP_HELP = `
|
|
18
|
+
With no Docker (the default): builds the package in --dir (default: the current folder) as
|
|
19
|
+
extension build does, prints what check refuses without stopping, and runs it in this terminal
|
|
20
|
+
with the kit host on the first free port from 4244 (127.0.0.1). It prints the URL and runs until
|
|
21
|
+
Ctrl-C. It does not use the daemon and does not change installation.json; its store is in
|
|
22
|
+
.agentage/data of the folder.
|
|
23
|
+
|
|
24
|
+
--docker runs the package the way a deployment runs it: the part images built with the release
|
|
25
|
+
recipe, the store with its migrations and seeds, a dev token issuer and a local gateway. Each
|
|
26
|
+
working copy is its own compose project; up refuses while another one holds localhost:4280 or
|
|
27
|
+
4281 and names it. Prints one line per step as the kit reports it. Exits 1 when a step fails.`;
|
|
28
|
+
const DOWN_HELP = `
|
|
29
|
+
Stops what agentage extension up started for the package in --dir, and nothing else: the local
|
|
30
|
+
run of this folder (only when its port still answers as it), and the Docker stack up --docker
|
|
31
|
+
started there (its containers, network and the store's volume; --keep-data keeps the volume).
|
|
32
|
+
It says so when nothing runs. Exits 1 when that fails.`;
|
|
33
|
+
const TOKEN_HELP = `
|
|
34
|
+
Prints a token from the dev issuer agentage extension up started for the package in --dir,
|
|
35
|
+
alone on stdout, for calling /api/v1/ and /mcp by hand or from tests. Only up trusts it. Exits 1
|
|
36
|
+
when the stack on localhost:4281 is not this package's (it names the one that is), or when the
|
|
37
|
+
issuer refuses or does not answer within 5 s. --issuer asks that issuer and skips the check.`;
|
|
38
|
+
const DIR = '--dir <path>';
|
|
39
|
+
const DIR_TEXT = 'the extension package folder (default: the current folder)';
|
|
40
|
+
const addUp = (group, up) => {
|
|
41
|
+
addJson(group
|
|
42
|
+
.command('up')
|
|
43
|
+
.description('Run the working copy in this terminal until Ctrl-C; --docker = on Docker')
|
|
44
|
+
.option(DIR, DIR_TEXT)
|
|
45
|
+
.option('--docker', 'the images, store, issuer and gateway on Docker')
|
|
46
|
+
.option('--local', 'the run with no Docker, asked for on purpose (no notice; for CI)'))
|
|
47
|
+
.addHelpText('after', UP_HELP)
|
|
48
|
+
.action(up);
|
|
49
|
+
};
|
|
50
|
+
const addDown = (group, down) => {
|
|
51
|
+
addJson(group
|
|
52
|
+
.command('down')
|
|
53
|
+
.description('Stop what extension up started here; --keep-data keeps the Docker store')
|
|
54
|
+
.option(DIR, DIR_TEXT)
|
|
55
|
+
.option('--keep-data', "keep the store's volume"))
|
|
56
|
+
.addHelpText('after', DOWN_HELP)
|
|
57
|
+
.action(down);
|
|
58
|
+
};
|
|
59
|
+
const addToken = (group, token) => {
|
|
60
|
+
addJson(group
|
|
61
|
+
.command('token')
|
|
62
|
+
.description('Print a token from the dev issuer extension up started')
|
|
63
|
+
.requiredOption('--scope <scope>', 'the scope the token carries, e.g. probe:write')
|
|
64
|
+
.option(DIR, DIR_TEXT)
|
|
65
|
+
.option('--issuer <url>', 'the dev issuer (default: http://localhost:4281)', issuerUrl))
|
|
66
|
+
.addHelpText('after', TOKEN_HELP)
|
|
67
|
+
.action(token);
|
|
68
|
+
};
|
|
69
|
+
// up, down and token: thin commands over the kit's tool library, for extension authors.
|
|
70
|
+
export const addKitTools = (group, actions) => {
|
|
71
|
+
addUp(group, actions.up);
|
|
72
|
+
addDown(group, actions.down);
|
|
73
|
+
addToken(group, actions.token);
|
|
74
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type RequestListener, type Server } from 'node:http';
|
|
2
|
+
export declare const UP_FROM = 4244;
|
|
3
|
+
export interface UpRecord {
|
|
4
|
+
pid: number;
|
|
5
|
+
port: number;
|
|
6
|
+
id: string;
|
|
7
|
+
instance: string;
|
|
8
|
+
}
|
|
9
|
+
export declare const recordPath: (dir: string) => string;
|
|
10
|
+
export declare const dataDirOf: (dir: string) => string;
|
|
11
|
+
export declare const readRecord: (dir: string) => UpRecord | null;
|
|
12
|
+
export declare const ignoreLocal: (dir: string) => void;
|
|
13
|
+
export declare const writeRecord: (dir: string, record: UpRecord) => void;
|
|
14
|
+
export declare const removeRecord: (dir: string) => void;
|
|
15
|
+
export declare const listenFrom: (handler: RequestListener, from?: number) => Promise<Server>;
|
|
16
|
+
export declare const portOf: (server: Server) => number;
|
|
17
|
+
export type Answer = 'ours' | 'other' | 'none';
|
|
18
|
+
export declare const answerOf: (record: UpRecord, timeoutMs?: number) => Promise<Answer>;
|
|
19
|
+
export declare const untilSignal: () => Promise<string>;
|
|
20
|
+
export type LocalDown = 'stopped' | 'stale' | 'none';
|
|
21
|
+
export declare const stopLocal: (dir: string, timeoutMs?: number) => Promise<LocalDown>;
|