@agentage/cli 0.51.1 → 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 +26 -15
- 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 +33 -12
- 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 -96
- 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/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 +10 -10
- package/dist/commands/extension/up.js +62 -74
- 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
|
@@ -4,6 +4,8 @@ import {} from 'commander';
|
|
|
4
4
|
import { getConfigDir } from '../../lib/fs/config.js';
|
|
5
5
|
import { acquireFileLock, releaseFileLock } from '../../lib/fs/file-lock.js';
|
|
6
6
|
import { requireNpm10, runNpm } from '../../lib/npm/npm-cli.js';
|
|
7
|
+
import { restartIfRunning } from '../../lib/daemon/daemon-client.js';
|
|
8
|
+
import { addJson, messageOf } from '../../lib/json-output.js';
|
|
7
9
|
import { checkForUpdate, INSTALL_HINT } from '../../lib/update/update-check.js';
|
|
8
10
|
import { VERSION } from '../../utils/version.js';
|
|
9
11
|
const INSTALL_TIMEOUT_MS = 5 * 60_000;
|
|
@@ -25,6 +27,7 @@ const defaultDeps = {
|
|
|
25
27
|
install: () => installLatest(),
|
|
26
28
|
acquireLock: () => acquireFileLock(updateLockTarget(), Date.now(), UPDATE_LOCK),
|
|
27
29
|
releaseLock: () => releaseFileLock(updateLockTarget()),
|
|
30
|
+
restartDaemon: () => restartIfRunning(),
|
|
28
31
|
log: (msg) => console.log(msg),
|
|
29
32
|
};
|
|
30
33
|
const describe = (info) => {
|
|
@@ -44,29 +47,40 @@ const install = async (deps) => {
|
|
|
44
47
|
deps.log('Installing the latest @agentage/cli...');
|
|
45
48
|
await deps.install();
|
|
46
49
|
deps.log(chalk.green('Updated. Run `agentage status` to confirm.'));
|
|
50
|
+
// The running daemon still holds the old code; a failed restart leaves the next command to it.
|
|
51
|
+
await deps
|
|
52
|
+
.restartDaemon()
|
|
53
|
+
.catch((err) => deps.log(`daemon not restarted: ${messageOf(err)}`));
|
|
47
54
|
};
|
|
48
55
|
// --check never installs; otherwise install only when behind, under a single-writer lock.
|
|
49
56
|
export const runUpdate = async (opts, deps = defaultDeps) => {
|
|
50
57
|
const info = await deps.check(VERSION);
|
|
51
58
|
deps.log(describe(info));
|
|
52
|
-
const
|
|
59
|
+
const { status } = info;
|
|
60
|
+
const result = {
|
|
61
|
+
installed: VERSION,
|
|
62
|
+
status: status.kind,
|
|
63
|
+
latest: 'latest' in status ? (status.latest ?? null) : null,
|
|
64
|
+
updated: false,
|
|
65
|
+
};
|
|
66
|
+
const behind = status.kind === 'update-available' || status.kind === 'unsupported';
|
|
53
67
|
if (opts.check || !behind)
|
|
54
|
-
return;
|
|
68
|
+
return result;
|
|
55
69
|
if (!deps.acquireLock()) {
|
|
56
70
|
deps.log(chalk.yellow('Another update is already in progress; skipping.'));
|
|
57
|
-
return;
|
|
71
|
+
return result;
|
|
58
72
|
}
|
|
59
73
|
try {
|
|
60
74
|
await install(deps);
|
|
75
|
+
return { ...result, updated: true };
|
|
61
76
|
}
|
|
62
77
|
finally {
|
|
63
78
|
deps.releaseLock();
|
|
64
79
|
}
|
|
65
80
|
};
|
|
66
81
|
export const registerUpdate = (program, action) => {
|
|
67
|
-
program
|
|
82
|
+
addJson(program
|
|
68
83
|
.command('update')
|
|
69
84
|
.description('Update @agentage/cli to the latest published version')
|
|
70
|
-
.option('--check', 'report whether an update is available, without installing')
|
|
71
|
-
.action(action);
|
|
85
|
+
.option('--check', 'report whether an update is available, without installing')).action(action);
|
|
72
86
|
};
|
|
@@ -2,7 +2,5 @@ type Doc = Record<string, unknown>;
|
|
|
2
2
|
export declare const parseLock: (raw: string | null) => Doc | null;
|
|
3
3
|
export declare const lockEntries: (lock: Doc) => string[];
|
|
4
4
|
export declare const rootDependencies: (lock: Doc) => Record<string, string>;
|
|
5
|
-
export declare const lockedVersion: (lock: Doc | null, name: string) => string | null;
|
|
6
|
-
export declare const lockAgrees: (lock: Doc, dependencies: Record<string, string>) => boolean;
|
|
7
5
|
export declare const integrityDrift: (a: Doc, b: Doc) => string[];
|
|
8
6
|
export {};
|
|
@@ -28,18 +28,6 @@ export const rootDependencies = (lock) => {
|
|
|
28
28
|
const deps = isRecord(root) && isRecord(root['dependencies']) ? root['dependencies'] : {};
|
|
29
29
|
return Object.fromEntries(Object.entries(deps).map(([name, spec]) => [name, text(spec)]));
|
|
30
30
|
};
|
|
31
|
-
// The version the lock installed for a root dependency; null when it has none.
|
|
32
|
-
export const lockedVersion = (lock, name) => {
|
|
33
|
-
const entry = lock === null ? null : packagesOf(lock)[`${NODE_MODULES}${name}`];
|
|
34
|
-
return isRecord(entry) && typeof entry['version'] === 'string' ? entry['version'] : null;
|
|
35
|
-
};
|
|
36
|
-
// npm ci refuses a lock whose root dependencies differ from package.json.
|
|
37
|
-
export const lockAgrees = (lock, dependencies) => {
|
|
38
|
-
const locked = rootDependencies(lock);
|
|
39
|
-
const names = Object.keys(dependencies);
|
|
40
|
-
return (Object.keys(locked).length === names.length &&
|
|
41
|
-
names.every((name) => locked[name] === dependencies[name]));
|
|
42
|
-
};
|
|
43
31
|
const integrities = (lock) => new Map(installed(lock).map(([path, entry]) => [nameAt(path, entry), text(entry['integrity'])]));
|
|
44
32
|
// The same name@version with another integrity: one of the two locks was changed by hand.
|
|
45
33
|
export const integrityDrift = (a, b) => {
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { EXTENSION_API_VERSION } from '../../extension.js';
|
|
2
2
|
import { isRecord } from '../../lib/fs/json-file.js';
|
|
3
3
|
import { kitVersion } from '../kit-version.js';
|
|
4
|
-
import { manifestInfo } from '../loader/manifest.js';
|
|
4
|
+
import { manifestInfo, onPreviousKit } from '../loader/manifest.js';
|
|
5
5
|
import { isRange, newestFirst, satisfies } from '../semver-range.js';
|
|
6
6
|
export const cliGate = () => ({ api: EXTENSION_API_VERSION, kit: kitVersion() });
|
|
7
7
|
export const fitsApi = (engine, api = EXTENSION_API_VERSION) => isRange(engine) && satisfies(api, engine);
|
|
8
|
-
// The gate picks the API by manifest shape.
|
|
9
|
-
export const fits = (p, gate = cliGate()) =>
|
|
8
|
+
// The gate picks the API by manifest shape; a kit-shaped range may also be the previous kit minor.
|
|
9
|
+
export const fits = (p, gate = cliGate()) => p.kit
|
|
10
|
+
? fitsApi(p.engine, gate.kit) || onPreviousKit(p.engine, gate.kit)
|
|
11
|
+
: fitsApi(p.engine, gate.api);
|
|
10
12
|
export const needsText = ({ engine, kit }) => `needs ${kit ? 'kit' : 'extension API'} ${engine}`;
|
|
11
13
|
export const needs = (p) => `${p.version}: ${needsText(p)}`;
|
|
12
14
|
// The resolver's rule: the newest version this CLI can load, instead of whatever `latest` is.
|
|
@@ -9,3 +9,4 @@ export declare const manifestArgs: (command: LookupCommand, spec: string, regist
|
|
|
9
9
|
export declare const npmMajor: (env?: NodeJS.ProcessEnv) => Promise<number>;
|
|
10
10
|
export declare const prepareNpm: (env?: NodeJS.ProcessEnv) => Promise<Npm>;
|
|
11
11
|
export declare const prepareManifest: (env?: NodeJS.ProcessEnv) => Promise<NpmManifest>;
|
|
12
|
+
export declare const lastLines: (output: string, count?: number) => string;
|
|
@@ -74,3 +74,9 @@ export const prepareManifest = async (env = process.env) => {
|
|
|
74
74
|
npmCli,
|
|
75
75
|
});
|
|
76
76
|
};
|
|
77
|
+
// npm's last lines, enough to see why it failed.
|
|
78
|
+
export const lastLines = (output, count = 20) => output
|
|
79
|
+
.split(/\r?\n/)
|
|
80
|
+
.filter((line) => line.trim() !== '')
|
|
81
|
+
.slice(-count)
|
|
82
|
+
.join('\n');
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { readdirSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { isRecord, readJson } from '../../lib/fs/json-file.js';
|
|
4
|
+
import { currentTree } from '../loader/discover.js';
|
|
5
|
+
import { extensionsDir } from '../paths.js';
|
|
6
|
+
import { packageDir, packagesDir } from './package-dir.js';
|
|
7
|
+
const names = (dir) => {
|
|
8
|
+
try {
|
|
9
|
+
return readdirSync(dir);
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
// Every package folder in a node_modules, scoped ones included.
|
|
16
|
+
const packagesIn = (modules) => names(modules).flatMap((name) => name.startsWith('@')
|
|
17
|
+
? names(join(modules, name)).map((n) => join(modules, name, n))
|
|
18
|
+
: [join(modules, name)]);
|
|
19
|
+
const manifestOf = (dir) => readJson(join(dir, 'package.json'), isRecord);
|
|
20
|
+
// The package of id (at version, when given) in the tree cli 0.51 installed, or null.
|
|
21
|
+
const oldPackage = (id, version) => {
|
|
22
|
+
const tree = currentTree(extensionsDir()).dir;
|
|
23
|
+
if (tree === null)
|
|
24
|
+
return null;
|
|
25
|
+
const match = (dir) => {
|
|
26
|
+
const pkg = manifestOf(dir);
|
|
27
|
+
const agentage = isRecord(pkg?.['agentage']) ? pkg['agentage'] : {};
|
|
28
|
+
return agentage['id'] === id && (version === undefined || pkg?.['version'] === version);
|
|
29
|
+
};
|
|
30
|
+
return packagesIn(join(tree, 'node_modules')).find(match) ?? null;
|
|
31
|
+
};
|
|
32
|
+
// Moved entries run from the 0.51 tree as they are: no npm call, so the move works offline.
|
|
33
|
+
export const oldPackageDir = (id, version) => oldPackage(id, version);
|
|
34
|
+
// The npm name id was installed under here (the daemon's trees, then the 0.51 tree), or null.
|
|
35
|
+
export const installedName = (id) => {
|
|
36
|
+
const own = names(join(packagesDir(), 'trees'))
|
|
37
|
+
.filter((tree) => tree.startsWith(`${id}@`))
|
|
38
|
+
.map((tree) => packageDir(id, tree.slice(id.length + 1)))
|
|
39
|
+
.find((dir) => dir !== null);
|
|
40
|
+
const dir = own ?? oldPackage(id);
|
|
41
|
+
const name = dir ? manifestOf(dir)?.['name'] : undefined;
|
|
42
|
+
return typeof name === 'string' ? name : null;
|
|
43
|
+
};
|
|
44
|
+
// A version on disk: the daemon's own tree first, then the 0.51 tree.
|
|
45
|
+
export const installedDir = (id, version) => packageDir(id, version) ?? oldPackageDir(id, version);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Npm } from './npm.js';
|
|
2
|
+
export declare const packagesDir: () => string;
|
|
3
|
+
export interface PackageSpec {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
version: string;
|
|
7
|
+
registries: Record<string, string>;
|
|
8
|
+
}
|
|
9
|
+
export declare const packageDir: (id: string, version: string) => string | null;
|
|
10
|
+
export declare const installPackage: (spec: PackageSpec, npm: Npm) => Promise<string>;
|
|
11
|
+
export declare const prunePackages: (id: string, inUse: string[]) => string[];
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readdirSync, rmSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { isRecord, readJson } from '../../lib/fs/json-file.js';
|
|
4
|
+
import { extensionsDir } from '../paths.js';
|
|
5
|
+
import { lastLines } from './npm.js';
|
|
6
|
+
import { clearStaging, commitTree, discardTree, isComplete, manifestText, npmrcText, stageTree, treePath, withInstallLock, } from './tree.js';
|
|
7
|
+
// One npm tree per extension version: a running child keeps its folder while a new one installs.
|
|
8
|
+
export const packagesDir = () => join(extensionsDir(), 'packages');
|
|
9
|
+
const treeName = (id, version) => `${id}@${version}`;
|
|
10
|
+
// The installed package folder of id@version, or null when that tree was never finished.
|
|
11
|
+
export const packageDir = (id, version) => {
|
|
12
|
+
const root = packagesDir();
|
|
13
|
+
if (!isComplete(root, treeName(id, version)))
|
|
14
|
+
return null;
|
|
15
|
+
const tree = treePath(root, treeName(id, version));
|
|
16
|
+
const deps = readJson(join(tree, 'package.json'), isRecord)?.['dependencies'];
|
|
17
|
+
const name = isRecord(deps) ? Object.keys(deps)[0] : undefined;
|
|
18
|
+
return name === undefined ? null : join(tree, 'node_modules', name);
|
|
19
|
+
};
|
|
20
|
+
const installTree = async (spec, npm) => {
|
|
21
|
+
const root = packagesDir();
|
|
22
|
+
clearStaging(root);
|
|
23
|
+
const manifest = manifestText({ [spec.name]: spec.version });
|
|
24
|
+
const staging = stageTree(root, { manifest, npmrc: npmrcText(spec.registries), lock: null });
|
|
25
|
+
const res = await npm('install', staging);
|
|
26
|
+
if (res.code !== 0) {
|
|
27
|
+
discardTree(staging);
|
|
28
|
+
const why = lastLines(res.stderr.trim() === '' ? res.stdout : res.stderr);
|
|
29
|
+
throw new Error(`npm install ${spec.name}@${spec.version} failed (exit ${res.code})\n${why}`);
|
|
30
|
+
}
|
|
31
|
+
commitTree(root, staging, treeName(spec.id, spec.version));
|
|
32
|
+
};
|
|
33
|
+
// Idempotent: a finished tree is reused, so a boot that calls it again needs no network.
|
|
34
|
+
export const installPackage = async (spec, npm) => {
|
|
35
|
+
mkdirSync(packagesDir(), { recursive: true, mode: 0o700 });
|
|
36
|
+
return withInstallLock(packagesDir(), async () => {
|
|
37
|
+
const have = packageDir(spec.id, spec.version);
|
|
38
|
+
if (have)
|
|
39
|
+
return have;
|
|
40
|
+
await installTree(spec, npm);
|
|
41
|
+
return join(treePath(packagesDir(), treeName(spec.id, spec.version)), 'node_modules', spec.name);
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
// The versions of id that no installation entry uses any more go; only the daemon's own trees,
|
|
45
|
+
// never the 0.51 tree (read-only for this cli). Called after the daemon stopped the old child.
|
|
46
|
+
export const prunePackages = (id, inUse) => {
|
|
47
|
+
const trees = join(packagesDir(), 'trees');
|
|
48
|
+
const names = existsSync(trees) ? readdirSync(trees) : [];
|
|
49
|
+
const unused = names.filter((name) => name.startsWith(`${id}@`) && !inUse.includes(name.slice(id.length + 1)));
|
|
50
|
+
for (const name of unused)
|
|
51
|
+
rmSync(join(trees, name), { recursive: true, force: true });
|
|
52
|
+
return unused;
|
|
53
|
+
};
|
|
@@ -5,8 +5,7 @@ import {} from '../../lib/npm/npm-cli.js';
|
|
|
5
5
|
import { PACKAGE_NAME, specProblem } from '../profile/schema.js';
|
|
6
6
|
import { cliGate, needs, newestCompatible, parsePublished } from './compat.js';
|
|
7
7
|
import { isKitShaped } from '../loader/kit-manifest.js';
|
|
8
|
-
import { lastLines } from './
|
|
9
|
-
import {} from './npm.js';
|
|
8
|
+
import { lastLines } from './npm.js';
|
|
10
9
|
// Every release: a range, not `*`, which npm view reads as the `latest` tag alone.
|
|
11
10
|
const EVERY_RELEASE = '>=0.0.0';
|
|
12
11
|
const LOCAL = /^\.{1,2}(?:[/\\]|$)/;
|
|
@@ -4,10 +4,8 @@ export interface TreeFiles {
|
|
|
4
4
|
npmrc: string;
|
|
5
5
|
lock: string | null;
|
|
6
6
|
}
|
|
7
|
-
export declare const sortedSet: (install: Record<string, string>) => Record<string, string>;
|
|
8
7
|
export declare const manifestText: (install: Record<string, string>) => string;
|
|
9
8
|
export declare const npmrcText: (registries: Record<string, string>) => string;
|
|
10
|
-
export declare const treeName: (entries: string[]) => string;
|
|
11
9
|
export declare const treePath: (extensionsDir: string, name: string) => string;
|
|
12
10
|
export declare const isComplete: (extensionsDir: string, name: string) => boolean;
|
|
13
11
|
export declare const readText: (path: string) => string | null;
|
|
@@ -15,7 +13,4 @@ export declare const clearStaging: (extensionsDir: string) => void;
|
|
|
15
13
|
export declare const stageTree: (extensionsDir: string, files: TreeFiles) => string;
|
|
16
14
|
export declare const discardTree: (dir: string) => void;
|
|
17
15
|
export declare const commitTree: (extensionsDir: string, staging: string, name: string) => void;
|
|
18
|
-
export declare const collectTrees: (extensionsDir: string, keep: string) => void;
|
|
19
|
-
export declare const pointCurrent: (extensionsDir: string, name: string) => void;
|
|
20
|
-
export declare const promoteFiles: (extensionsDir: string, files: Omit<TreeFiles, "npmrc">) => void;
|
|
21
16
|
export declare const withInstallLock: <T>(extensionsDir: string, fn: () => Promise<T>) => Promise<T>;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { createHash } from 'node:crypto';
|
|
2
1
|
import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync, } from 'node:fs';
|
|
3
2
|
import { join } from 'node:path';
|
|
4
3
|
import { refreshFileLock, withFileLock } from '../../lib/fs/file-lock.js';
|
|
5
|
-
import { writeTextAtomic } from '../../lib/fs/json-file.js';
|
|
6
4
|
export const LOCK_FILE = 'package-lock.json';
|
|
7
5
|
const MANIFEST_FILE = 'package.json';
|
|
8
6
|
const TREES = 'trees';
|
|
@@ -14,15 +12,13 @@ const STAGING_PREFIX = '.staging-';
|
|
|
14
12
|
// An install runs for minutes: a long TTL plus a heartbeat keep a live holder from looking dead.
|
|
15
13
|
const INSTALL_LOCK = { ttlMs: 2 * 60_000, hardStaleMs: 60 * 60_000, maxWaitMs: 30 * 60_000 };
|
|
16
14
|
const HEARTBEAT_MS = 20_000;
|
|
17
|
-
|
|
15
|
+
const sortedSet = (install) => Object.fromEntries(Object.entries(install).sort(([a], [b]) => (a < b ? -1 : 1)));
|
|
18
16
|
// Same install set, same bytes: no scripts, nothing machine-specific.
|
|
19
17
|
export const manifestText = (install) => `${JSON.stringify({ name: MANIFEST_NAME, private: true, dependencies: sortedSet(install) }, null, 2)}\n`;
|
|
20
18
|
// npm's own per-scope registry lines; every other package uses the --registry default.
|
|
21
19
|
export const npmrcText = (registries) => Object.entries(sortedSet(registries))
|
|
22
20
|
.map(([scope, url]) => `${scope}:registry=${url}\n`)
|
|
23
21
|
.join('');
|
|
24
|
-
// Content-addressed: the same normalized lock names the same tree on every machine.
|
|
25
|
-
export const treeName = (entries) => createHash('sha256').update(entries.join('\n')).digest('hex').slice(0, 16);
|
|
26
22
|
export const treePath = (extensionsDir, name) => join(extensionsDir, TREES, name);
|
|
27
23
|
export const isComplete = (extensionsDir, name) => existsSync(join(treePath(extensionsDir, name), COMPLETE));
|
|
28
24
|
export const readText = (path) => {
|
|
@@ -62,26 +58,6 @@ export const commitTree = (extensionsDir, staging, name) => {
|
|
|
62
58
|
writeFileSync(join(staging, COMPLETE), '');
|
|
63
59
|
renameSync(staging, target);
|
|
64
60
|
};
|
|
65
|
-
// Only `keep` stays: the lock in the extensions root can rebuild any other tree. Staging dirs are
|
|
66
|
-
// left to clearStaging, so a run never removes another's.
|
|
67
|
-
export const collectTrees = (extensionsDir, keep) => {
|
|
68
|
-
const trees = join(extensionsDir, TREES);
|
|
69
|
-
if (!existsSync(trees))
|
|
70
|
-
return;
|
|
71
|
-
for (const name of readdirSync(trees))
|
|
72
|
-
if (name !== keep && !name.startsWith(STAGING_PREFIX))
|
|
73
|
-
remove(join(trees, name));
|
|
74
|
-
};
|
|
75
|
-
export const pointCurrent = (extensionsDir, name) => writeTextAtomic(join(extensionsDir, 'current'), `${name}\n`);
|
|
76
|
-
// The extensions root always describes the tree `current` names, never a failed attempt.
|
|
77
|
-
export const promoteFiles = (extensionsDir, files) => {
|
|
78
|
-
writeTextAtomic(join(extensionsDir, MANIFEST_FILE), files.manifest);
|
|
79
|
-
const lock = join(extensionsDir, LOCK_FILE);
|
|
80
|
-
if (files.lock === null)
|
|
81
|
-
remove(lock);
|
|
82
|
-
else
|
|
83
|
-
writeTextAtomic(lock, files.lock);
|
|
84
|
-
};
|
|
85
61
|
const heartbeat = async (target, fn) => {
|
|
86
62
|
const beat = setInterval(() => refreshFileLock(target), HEARTBEAT_MS);
|
|
87
63
|
beat.unref();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const kitIdProblem: (id: string) => string | null;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import { isRecord, readJson } from '../lib/fs/json-file.js';
|
|
3
|
+
let cached;
|
|
4
|
+
// The kit's own id rule, read from the JSON schema it exports (data: no kit code is loaded).
|
|
5
|
+
const read = () => {
|
|
6
|
+
const file = '@agentage/extension/schemas/extension-package.schema.json';
|
|
7
|
+
const schema = readJson(createRequire(import.meta.url).resolve(file), isRecord);
|
|
8
|
+
const props = (o) => (isRecord(o) && isRecord(o['properties']) ? o['properties'] : {});
|
|
9
|
+
const id = props(props(schema)['agentage'])['id'];
|
|
10
|
+
if (!isRecord(id) || typeof id['pattern'] !== 'string' || typeof id['maxLength'] !== 'number')
|
|
11
|
+
throw new Error(`${file} has no agentage.id rule`);
|
|
12
|
+
return { pattern: new RegExp(id['pattern']), max: id['maxLength'] };
|
|
13
|
+
};
|
|
14
|
+
// Why the kit refuses the id (the daemon takes no such row), or null.
|
|
15
|
+
export const kitIdProblem = (id) => {
|
|
16
|
+
const rule = (cached ??= read());
|
|
17
|
+
if (id.length > rule.max)
|
|
18
|
+
return `the id ${id} is longer than ${rule.max} characters`;
|
|
19
|
+
return rule.pattern.test(id) ? null : `the id ${id} is a name the platform owns or not lowercase`;
|
|
20
|
+
};
|
|
@@ -18,6 +18,7 @@ export interface DiscoveredExtension {
|
|
|
18
18
|
secrets: string[];
|
|
19
19
|
descriptions: Record<string, string>;
|
|
20
20
|
problem: string | null;
|
|
21
|
+
warning: string | null;
|
|
21
22
|
missing: boolean;
|
|
22
23
|
}
|
|
23
24
|
export interface DiscoverInput {
|
|
@@ -25,7 +26,6 @@ export interface DiscoverInput {
|
|
|
25
26
|
names: string[];
|
|
26
27
|
dev: Record<string, string>;
|
|
27
28
|
config: ConfigMap;
|
|
28
|
-
tree?: string;
|
|
29
29
|
}
|
|
30
30
|
export interface Discovery {
|
|
31
31
|
extensions: DiscoveredExtension[];
|
|
@@ -36,4 +36,10 @@ export interface CurrentTree {
|
|
|
36
36
|
warning: string | null;
|
|
37
37
|
}
|
|
38
38
|
export declare const currentTree: (extensionsDir: string) => CurrentTree;
|
|
39
|
+
export interface Candidate {
|
|
40
|
+
pkg: string;
|
|
41
|
+
source: ExtensionSource;
|
|
42
|
+
dir: string | null;
|
|
43
|
+
}
|
|
44
|
+
export declare const inspect: ({ pkg, source, dir }: Candidate, configs: ConfigMap) => DiscoveredExtension;
|
|
39
45
|
export declare const discover: (input: DiscoverInput) => Discovery;
|
|
@@ -5,7 +5,7 @@ import {} from '../profile/schema.js';
|
|
|
5
5
|
import { checkConfig } from './config.js';
|
|
6
6
|
import { unsafeDevPath } from './dev-path.js';
|
|
7
7
|
import {} from './kit-manifest.js';
|
|
8
|
-
import { manifestInfo, manifestProblem } from './manifest.js';
|
|
8
|
+
import { kitWarning, manifestInfo, manifestProblem, } from './manifest.js';
|
|
9
9
|
const readText = (path) => {
|
|
10
10
|
try {
|
|
11
11
|
return readFileSync(path, 'utf-8');
|
|
@@ -65,9 +65,10 @@ const blank = (pkg, source, dir) => ({
|
|
|
65
65
|
secrets: [],
|
|
66
66
|
descriptions: {},
|
|
67
67
|
problem: null,
|
|
68
|
+
warning: null,
|
|
68
69
|
missing: false,
|
|
69
70
|
});
|
|
70
|
-
const inspect = ({ pkg, source, dir }, configs) => {
|
|
71
|
+
export const inspect = ({ pkg, source, dir }, configs) => {
|
|
71
72
|
const base = blank(pkg, source, dir ?? '');
|
|
72
73
|
if (source === 'dev' && !isAbsolute(base.dir))
|
|
73
74
|
return { ...base, problem: 'dev path not absolute' };
|
|
@@ -82,7 +83,7 @@ const inspect = ({ pkg, source, dir }, configs) => {
|
|
|
82
83
|
const unsafe = source === 'dev' ? unsafeDevPath(dir, process.getuid?.()) : null;
|
|
83
84
|
const problem = unsafe ?? manifestProblem(pkg, info) ?? entryProblem(info, entry) ?? badConfig;
|
|
84
85
|
const read = { kind, version, id, entry, commands, kitCommands, peers, optionalPeers };
|
|
85
|
-
return { ...base, ...read, ...declared, problem };
|
|
86
|
+
return { ...base, ...read, ...declared, problem, warning: kitWarning(info) };
|
|
86
87
|
};
|
|
87
88
|
// Every claimant of a shared id is invalid; a dev copy of the same package never reaches here.
|
|
88
89
|
const markDuplicates = (extensions) => extensions.map((p) => {
|
|
@@ -102,7 +103,7 @@ const extensionPeers = (p, known, nodeModules) => p.peers.filter((peer) => {
|
|
|
102
103
|
return manifest === null || isRecord(manifest['agentage']);
|
|
103
104
|
});
|
|
104
105
|
export const discover = (input) => {
|
|
105
|
-
const tree =
|
|
106
|
+
const tree = currentTree(input.extensionsDir);
|
|
106
107
|
const nodeModules = tree.dir === null ? null : join(tree.dir, 'node_modules');
|
|
107
108
|
const installed = input.names.filter((name) => !(name in input.dev));
|
|
108
109
|
const found = markDuplicates([
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type DiscoveredExtension } from './discover.js';
|
|
2
|
+
export declare const installationPath: () => string;
|
|
3
|
+
export declare const settingsPath: () => string;
|
|
4
|
+
export declare const versionsInUse: (id: string) => string[];
|
|
5
|
+
export declare const installationRows: () => {
|
|
6
|
+
id: string;
|
|
7
|
+
dir: string | null;
|
|
8
|
+
}[];
|
|
9
|
+
export declare const installedExtensions: () => DiscoveredExtension[] | null;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { getConfigDir } from '../../lib/fs/config.js';
|
|
4
|
+
import { isRecord, readJson } from '../../lib/fs/json-file.js';
|
|
5
|
+
import { installedDir } from '../installer/old-tree.js';
|
|
6
|
+
import {} from '../profile/schema.js';
|
|
7
|
+
import { inspect } from './discover.js';
|
|
8
|
+
export const installationPath = () => join(getConfigDir(), 'installation.json');
|
|
9
|
+
export const settingsPath = () => join(getConfigDir(), 'settings.json');
|
|
10
|
+
// The C3 rows as written; an absent or unreadable file has none.
|
|
11
|
+
const rows = () => {
|
|
12
|
+
const doc = readJson(installationPath(), isRecord);
|
|
13
|
+
return Array.isArray(doc?.['extensions']) ? doc['extensions'] : [];
|
|
14
|
+
};
|
|
15
|
+
// The package folder of one C3 row: its source folder, or the tree that holds its version.
|
|
16
|
+
const dirOf = (row) => {
|
|
17
|
+
if (typeof row['source'] === 'string')
|
|
18
|
+
return { dir: row['source'], dev: true };
|
|
19
|
+
const { id, version } = row;
|
|
20
|
+
if (typeof id !== 'string' || typeof version !== 'string')
|
|
21
|
+
return null;
|
|
22
|
+
const dir = installedDir(id, version);
|
|
23
|
+
return dir === null ? null : { dir, dev: false };
|
|
24
|
+
};
|
|
25
|
+
// The daemon's settings by id: what a 1.0-API extension's ctx.config holds.
|
|
26
|
+
const settings = () => {
|
|
27
|
+
const all = readJson(settingsPath(), isRecord) ?? {};
|
|
28
|
+
return Object.fromEntries(Object.entries(all).filter((e) => isRecord(e[1])));
|
|
29
|
+
};
|
|
30
|
+
// The versions of id that installation.json names now.
|
|
31
|
+
export const versionsInUse = (id) => rows().flatMap((row) => isRecord(row) && row['id'] === id && typeof row['version'] === 'string' ? [row['version']] : []);
|
|
32
|
+
// Each row's id and package folder, disabled ones too (null: its version is on no disk here).
|
|
33
|
+
export const installationRows = () => rows().flatMap((row) => isRecord(row) && typeof row['id'] === 'string'
|
|
34
|
+
? [{ id: row['id'], dir: dirOf(row)?.dir ?? null }]
|
|
35
|
+
: []);
|
|
36
|
+
const discovered = (row, configs) => {
|
|
37
|
+
const found = isRecord(row) && row['enabled'] !== false ? dirOf(row) : null;
|
|
38
|
+
if (found === null)
|
|
39
|
+
return [];
|
|
40
|
+
const name = readJson(join(found.dir, 'package.json'), isRecord)?.['name'];
|
|
41
|
+
const pkg = typeof name === 'string' ? name : String(row['id']);
|
|
42
|
+
const ext = inspect({ pkg, source: found.dev ? 'dev' : 'tree', dir: found.dir }, configs);
|
|
43
|
+
return ext.missing || ext.problem ? [] : [ext];
|
|
44
|
+
};
|
|
45
|
+
// What installation.json runs, read from the files (no daemon is asked); null before the move.
|
|
46
|
+
export const installedExtensions = () => {
|
|
47
|
+
if (!existsSync(installationPath()))
|
|
48
|
+
return null;
|
|
49
|
+
const configs = settings();
|
|
50
|
+
return rows().flatMap((row) => discovered(row, configs));
|
|
51
|
+
};
|
|
@@ -17,4 +17,8 @@ export interface ManifestInfo {
|
|
|
17
17
|
shape: string | null;
|
|
18
18
|
}
|
|
19
19
|
export declare const manifestInfo: (pkg: Record<string, unknown>) => ManifestInfo;
|
|
20
|
+
export declare const OLDER_KIT_MINORS: string[];
|
|
21
|
+
export declare const olderKitWarning: (minor: string) => string;
|
|
22
|
+
export declare const onPreviousKit: (engine: string, kit?: string) => boolean;
|
|
23
|
+
export declare const kitWarning: (info: ManifestInfo, kit?: string) => string | null;
|
|
20
24
|
export declare const manifestProblem: (pkg: string, info: ManifestInfo, api?: string, kit?: string) => string | null;
|
|
@@ -83,10 +83,32 @@ const engineProblem = (engine, version, against) => {
|
|
|
83
83
|
return null;
|
|
84
84
|
return `engines.agentage "${engine}" does not match ${against} ${version}`;
|
|
85
85
|
};
|
|
86
|
+
// The older kit minors this kit still hosts: 0.12 is what cli 0.51 installed, 0.13 the one before
|
|
87
|
+
// this kit; their part modules and command contract are those of 0.14 (the update smoke proves it).
|
|
88
|
+
export const OLDER_KIT_MINORS = ['0.12', '0.13'];
|
|
89
|
+
const OLDER = OLDER_KIT_MINORS.map((minor) => ({
|
|
90
|
+
minor,
|
|
91
|
+
versions: Array.from({ length: 100 }, (_, patch) => `${minor}.${patch}`),
|
|
92
|
+
}));
|
|
93
|
+
const olderMinorOf = (engine, kit) => {
|
|
94
|
+
if (!isRange(engine) || satisfies(kit, engine))
|
|
95
|
+
return null;
|
|
96
|
+
return OLDER.find(({ versions }) => versions.some((v) => satisfies(v, engine)))?.minor ?? null;
|
|
97
|
+
};
|
|
98
|
+
export const olderKitWarning = (minor) => `built on kit ${minor}, update the extension`;
|
|
99
|
+
// A range this kit does not satisfy and an older hosted minor does: a warning, never a problem.
|
|
100
|
+
export const onPreviousKit = (engine, kit = kitVersion()) => olderMinorOf(engine, kit) !== null;
|
|
101
|
+
export const kitWarning = (info, kit = kitVersion()) => {
|
|
102
|
+
const minor = info.kind === 'kit' ? olderMinorOf(info.engine, kit) : null;
|
|
103
|
+
return minor ? olderKitWarning(minor) : null;
|
|
104
|
+
};
|
|
105
|
+
const kitRangeProblem = (engine, kit) => {
|
|
106
|
+
if (engine === '')
|
|
107
|
+
return 'engines.agentage is missing';
|
|
108
|
+
return onPreviousKit(engine, kit) ? null : engineProblem(engine, kit, 'kit');
|
|
109
|
+
};
|
|
86
110
|
// A kit-shaped range is over the kit's version; it has no default.
|
|
87
|
-
const kitProblem = (info, kit) => idProblem(info.id) ??
|
|
88
|
-
info.shape ??
|
|
89
|
-
(info.engine === '' ? 'engines.agentage is missing' : engineProblem(info.engine, kit, 'kit'));
|
|
111
|
+
const kitProblem = (info, kit) => idProblem(info.id) ?? info.shape ?? kitRangeProblem(info.engine, kit);
|
|
90
112
|
// Commands are named after the id, so no two extensions, nor the core, can claim one.
|
|
91
113
|
const commandsProblem = (id, commands) => {
|
|
92
114
|
const ownSub = (name) => name.startsWith(`${id}:`) && SUBCOMMAND.test(name.slice(id.length + 1));
|
|
@@ -14,5 +14,6 @@ export interface Scan {
|
|
|
14
14
|
removed: DiscoveredExtension[];
|
|
15
15
|
drift: string[];
|
|
16
16
|
}
|
|
17
|
-
export declare const scan: (machine: MachineFile
|
|
17
|
+
export declare const scan: (machine: MachineFile) => Scan;
|
|
18
18
|
export declare const loadSet: (found: Scan) => DiscoveredExtension[];
|
|
19
|
+
export declare const scanNow: (machine: MachineFile) => Scan;
|
package/dist/core/loader/scan.js
CHANGED
|
@@ -5,6 +5,7 @@ import { readProfile } from '../profile/profile.js';
|
|
|
5
5
|
import {} from '../profile/schema.js';
|
|
6
6
|
import { extensionsDir } from '../paths.js';
|
|
7
7
|
import { discover } from './discover.js';
|
|
8
|
+
import { installedExtensions } from './installed.js';
|
|
8
9
|
import { staticStates } from './states.js';
|
|
9
10
|
// A tree extension whose bytes the two locks disagree on is never trusted, so never imported.
|
|
10
11
|
const withDrift = (found, drift) => ({
|
|
@@ -15,14 +16,13 @@ const withDrift = (found, drift) => ({
|
|
|
15
16
|
return drifted ? { ...p, problem: `integrity drift: ${key}` } : p;
|
|
16
17
|
}),
|
|
17
18
|
});
|
|
18
|
-
// Everything known about this machine's extensions without running any of them
|
|
19
|
-
|
|
20
|
-
export const scan = (machine, tree) => {
|
|
19
|
+
// Everything known about this machine's extensions without running any of them.
|
|
20
|
+
export const scan = (machine) => {
|
|
21
21
|
const parsed = readProfile();
|
|
22
22
|
const eff = effective(parsed?.ok ? parsed.profile : null, machine);
|
|
23
23
|
const dir = extensionsDir();
|
|
24
24
|
const drift = lockDrift(dir).integrity;
|
|
25
|
-
const input = { extensionsDir: dir, dev: eff.dev, config: eff.config
|
|
25
|
+
const input = { extensionsDir: dir, dev: eff.dev, config: eff.config };
|
|
26
26
|
const found = withDrift(discover({ ...input, names: Object.keys(eff.install) }), drift);
|
|
27
27
|
const plan = planChanges(eff, currentDependencies(dir));
|
|
28
28
|
const gone = plan.extensions.filter((e) => e.verb === 'remove' && !(e.name in eff.dev));
|
|
@@ -32,3 +32,16 @@ export const scan = (machine, tree) => {
|
|
|
32
32
|
};
|
|
33
33
|
// What can load: a valid manifest, installed, not off here, and peers that can load too.
|
|
34
34
|
export const loadSet = (found) => found.found.extensions.filter((ext) => found.states.get(ext.pkg)?.state === 'installed');
|
|
35
|
+
// Once installation.json exists it is this machine's list: no profile plan, no drift.
|
|
36
|
+
const scanInstalled = (machine, installed) => {
|
|
37
|
+
const eff = effective(null, machine);
|
|
38
|
+
const found = { extensions: installed, warnings: [] };
|
|
39
|
+
const plan = planChanges(eff, {});
|
|
40
|
+
const states = staticStates(installed, []);
|
|
41
|
+
return { machine, parsed: readProfile(), eff, found, states, plan, removed: [], drift: [] };
|
|
42
|
+
};
|
|
43
|
+
// What status and doctor read: installation.json when it exists, else the old lists.
|
|
44
|
+
export const scanNow = (machine) => {
|
|
45
|
+
const installed = installedExtensions();
|
|
46
|
+
return installed === null ? scan(machine) : scanInstalled(machine, installed);
|
|
47
|
+
};
|
|
@@ -1,9 +1,2 @@
|
|
|
1
1
|
import { type ExtensionSecrets } from '../../extension.js';
|
|
2
|
-
import { type DiscoveredExtension } from './discover.js';
|
|
3
|
-
export interface SecretKey {
|
|
4
|
-
id: string;
|
|
5
|
-
key: string;
|
|
6
|
-
description: string | null;
|
|
7
|
-
}
|
|
8
2
|
export declare const secretsFor: (id: string) => ExtensionSecrets;
|
|
9
|
-
export declare const missingSecrets: (extensions: DiscoveredExtension[]) => SecretKey[];
|
|
@@ -2,7 +2,6 @@ import {} from '../../extension.js';
|
|
|
2
2
|
import { withFileLock } from '../../lib/fs/file-lock.js';
|
|
3
3
|
import { isRecord, readJson, writeJsonAtomic } from '../../lib/fs/json-file.js';
|
|
4
4
|
import { secretsPath } from '../paths.js';
|
|
5
|
-
import {} from './discover.js';
|
|
6
5
|
const isStrings = (value) => isRecord(value) && Object.values(value).every((v) => typeof v === 'string');
|
|
7
6
|
const isSecretsFile = (value) => isRecord(value) && Object.values(value).every(isStrings);
|
|
8
7
|
const readSecrets = () => readJson(secretsPath(), isSecretsFile) ?? {};
|
|
@@ -16,13 +15,3 @@ export const secretsFor = (id) => ({
|
|
|
16
15
|
set: (key, value) => change(id, (own) => ({ ...own, [key]: value })),
|
|
17
16
|
delete: (key) => change(id, (own) => Object.fromEntries(Object.entries(own).filter(([k]) => k !== key))),
|
|
18
17
|
});
|
|
19
|
-
// The keys extensions declare `secret: true` that this machine has no value for yet.
|
|
20
|
-
export const missingSecrets = (extensions) => {
|
|
21
|
-
const stored = readSecrets();
|
|
22
|
-
return extensions.flatMap((ext) => {
|
|
23
|
-
const id = ext.id ?? '';
|
|
24
|
-
return ext.secrets
|
|
25
|
-
.filter((key) => stored[id]?.[key] === undefined)
|
|
26
|
-
.map((key) => ({ id, key, description: ext.descriptions[key] ?? null }));
|
|
27
|
-
});
|
|
28
|
-
};
|
|
@@ -10,6 +10,5 @@ export interface Verbs {
|
|
|
10
10
|
namespaced: Namespaced[];
|
|
11
11
|
}
|
|
12
12
|
export declare const readHeld: () => Map<string, string>;
|
|
13
|
-
export declare const writeHeld: (top: Map<string, string>) => void;
|
|
14
13
|
export declare const claimVerbs: (extensions: DiscoveredExtension[], held: Map<string, string>) => Verbs;
|
|
15
14
|
export declare const commandNames: (ext: DiscoveredExtension, verbs: Verbs) => string[];
|