@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
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { secretsFor } from '../../core/loader/secrets.js';
|
|
2
|
-
const ENTER = ['\r', '\n', '\u0004'];
|
|
3
|
-
const CTRL_C = '\u0003';
|
|
4
|
-
const BACKSPACE = '\u007f';
|
|
5
|
-
// One keypress: the answer so far, or null once Enter ends it.
|
|
6
|
-
const typed = (answer, char) => {
|
|
7
|
-
if (ENTER.includes(char))
|
|
8
|
-
return null;
|
|
9
|
-
return char === BACKSPACE ? answer.slice(0, -1) : answer + char;
|
|
10
|
-
};
|
|
11
|
-
// Raw mode keeps the answer off the screen; Ctrl+C still interrupts once the terminal is restored.
|
|
12
|
-
const readHidden = (question) => new Promise((resolve) => {
|
|
13
|
-
const { stdin, stderr } = process;
|
|
14
|
-
let answer = '';
|
|
15
|
-
const onData = (chunk) => {
|
|
16
|
-
for (const char of chunk.toString('utf-8')) {
|
|
17
|
-
const next = char === CTRL_C ? null : typed(answer, char);
|
|
18
|
-
if (next === null)
|
|
19
|
-
return finish(char === CTRL_C);
|
|
20
|
-
answer = next;
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
const finish = (interrupted) => {
|
|
24
|
-
stdin.off('data', onData).setRawMode(false).pause();
|
|
25
|
-
stderr.write('\n');
|
|
26
|
-
resolve(answer);
|
|
27
|
-
if (interrupted)
|
|
28
|
-
process.kill(process.pid, 'SIGINT');
|
|
29
|
-
};
|
|
30
|
-
stderr.write(question);
|
|
31
|
-
stdin.setRawMode(true).resume().on('data', onData);
|
|
32
|
-
});
|
|
33
|
-
const terminal = () => ({ isTTY: process.stdin.isTTY === true, prompt: readHidden });
|
|
34
|
-
const nameOf = ({ id, key }) => `${id}.${key}`;
|
|
35
|
-
// Before loading: a terminal is asked for each missing secret, anything else gets the list.
|
|
36
|
-
export const askSecrets = async (missing, io = terminal()) => {
|
|
37
|
-
if (missing.length === 0)
|
|
38
|
-
return;
|
|
39
|
-
if (!io.isTTY)
|
|
40
|
-
return void console.log(`secrets to set: ${missing.map(nameOf).join(', ')}`);
|
|
41
|
-
for (const secret of missing) {
|
|
42
|
-
const described = secret.description === null ? '' : ` (${secret.description})`;
|
|
43
|
-
const value = await io.prompt(`${nameOf(secret)}${described}: `);
|
|
44
|
-
if (value !== '')
|
|
45
|
-
await secretsFor(secret.id).set(secret.key, value);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { type Profile } from '../profile/schema.js';
|
|
2
|
-
import { type Npm, type NpmCommand } from './npm.js';
|
|
3
|
-
import { type TreeFiles } from './tree.js';
|
|
4
|
-
export type InstallSet = Pick<Profile, 'extensions' | 'registries'> & {
|
|
5
|
-
lock?: Record<string, unknown> | null;
|
|
6
|
-
};
|
|
7
|
-
export interface InstallPlan extends TreeFiles {
|
|
8
|
-
extensionsDir: string;
|
|
9
|
-
install: Record<string, string>;
|
|
10
|
-
registries: Record<string, string>;
|
|
11
|
-
npm: NpmCommand | null;
|
|
12
|
-
tree: string | null;
|
|
13
|
-
reuse: boolean;
|
|
14
|
-
}
|
|
15
|
-
export interface InstallResult {
|
|
16
|
-
tree: string;
|
|
17
|
-
npm: NpmCommand | null;
|
|
18
|
-
reused: boolean;
|
|
19
|
-
count: number;
|
|
20
|
-
}
|
|
21
|
-
export declare const planInstall: (set: InstallSet) => InstallPlan;
|
|
22
|
-
export declare const lastLines: (output: string, count?: number) => string;
|
|
23
|
-
export declare const runNpmInto: (staging: string, command: NpmCommand, npm: Npm, packages?: string[]) => Promise<{
|
|
24
|
-
tree: string;
|
|
25
|
-
lock: string;
|
|
26
|
-
}>;
|
|
27
|
-
export declare const refuseDrift: (dir: string) => void;
|
|
28
|
-
export declare const install: (set: InstallSet, prepare?: () => Promise<Npm>) => Promise<InstallResult>;
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { join } from 'node:path';
|
|
2
|
-
import {} from '../../lib/npm/npm-cli.js';
|
|
3
|
-
import { extensionsDir } from '../paths.js';
|
|
4
|
-
import {} from '../profile/schema.js';
|
|
5
|
-
import { lockAgrees, lockEntries, parseLock } from './compare-lock.js';
|
|
6
|
-
import { prepareNpm } from './npm.js';
|
|
7
|
-
import { driftLines, lockDrift } from './plan.js';
|
|
8
|
-
import { clearStaging, collectTrees, commitTree, discardTree, isComplete, LOCK_FILE, manifestText, npmrcText, pointCurrent, promoteFiles, readText, sortedSet, stageTree, treeName, withInstallLock, } from './tree.js';
|
|
9
|
-
// The current lock rides into the staged tree, so npm keeps every pin it can.
|
|
10
|
-
const lockPlan = (dir, install, raw) => {
|
|
11
|
-
if (Object.keys(install).length === 0) {
|
|
12
|
-
const tree = treeName([]);
|
|
13
|
-
return { lock: null, npm: null, tree, reuse: isComplete(dir, tree) };
|
|
14
|
-
}
|
|
15
|
-
const lock = parseLock(raw);
|
|
16
|
-
if (lock === null)
|
|
17
|
-
return { lock: null, npm: 'install', tree: null, reuse: false };
|
|
18
|
-
if (!lockAgrees(lock, install))
|
|
19
|
-
return { lock: raw, npm: 'install', tree: null, reuse: false };
|
|
20
|
-
const tree = treeName(lockEntries(lock));
|
|
21
|
-
const reuse = isComplete(dir, tree);
|
|
22
|
-
return { lock: raw, npm: reuse ? null : 'ci', tree, reuse };
|
|
23
|
-
};
|
|
24
|
-
// Reads only: `setup --dry-run` prints this and stops.
|
|
25
|
-
export const planInstall = (set) => {
|
|
26
|
-
const dir = extensionsDir();
|
|
27
|
-
const install = sortedSet(set.extensions);
|
|
28
|
-
const registries = sortedSet(set.registries);
|
|
29
|
-
const files = { manifest: manifestText(install), npmrc: npmrcText(registries) };
|
|
30
|
-
const raw = set.lock ? `${JSON.stringify(set.lock, null, 2)}\n` : readText(join(dir, LOCK_FILE));
|
|
31
|
-
const lock = lockPlan(dir, install, raw);
|
|
32
|
-
return { extensionsDir: dir, install, registries, ...files, ...lock };
|
|
33
|
-
};
|
|
34
|
-
// npm's last lines, enough to see why it failed.
|
|
35
|
-
export const lastLines = (output, count = 20) => output
|
|
36
|
-
.split(/\r?\n/)
|
|
37
|
-
.filter((line) => line.trim() !== '')
|
|
38
|
-
.slice(-count)
|
|
39
|
-
.join('\n');
|
|
40
|
-
const npmFailure = (command, res) => new Error(`npm ${command} failed (exit ${res.code}); extensions/current is unchanged\n` +
|
|
41
|
-
lastLines(`${res.stdout}\n${res.stderr}`));
|
|
42
|
-
// The staged tree's name and lock text, once npm succeeded in it; `packages` limits an update.
|
|
43
|
-
export const runNpmInto = async (staging, command, npm, packages = []) => {
|
|
44
|
-
const res = await npm(command, staging, packages);
|
|
45
|
-
if (res.code !== 0)
|
|
46
|
-
throw npmFailure(command, res);
|
|
47
|
-
const lock = readText(join(staging, LOCK_FILE));
|
|
48
|
-
const parsed = parseLock(lock);
|
|
49
|
-
if (lock === null || parsed === null)
|
|
50
|
-
throw new Error(`npm ${command} wrote no usable ${LOCK_FILE}`);
|
|
51
|
-
return { tree: treeName(lockEntries(parsed)), lock };
|
|
52
|
-
};
|
|
53
|
-
const build = async (plan, prepare) => {
|
|
54
|
-
const npm = plan.npm === null ? null : await prepare();
|
|
55
|
-
const staging = stageTree(plan.extensionsDir, plan);
|
|
56
|
-
try {
|
|
57
|
-
const built = npm === null || plan.npm === null
|
|
58
|
-
? { tree: treeName([]), lock: null }
|
|
59
|
-
: await runNpmInto(staging, plan.npm, npm);
|
|
60
|
-
commitTree(plan.extensionsDir, staging, built.tree);
|
|
61
|
-
return built;
|
|
62
|
-
}
|
|
63
|
-
catch (err) {
|
|
64
|
-
discardTree(staging);
|
|
65
|
-
throw err;
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
// A lock that disagrees with its own tree on a package's bytes is never built on.
|
|
69
|
-
export const refuseDrift = (dir) => {
|
|
70
|
-
const { integrity } = lockDrift(dir);
|
|
71
|
-
if (integrity.length > 0)
|
|
72
|
-
throw new Error(driftLines(integrity).join('\n'));
|
|
73
|
-
};
|
|
74
|
-
const execute = async (plan, prepare) => {
|
|
75
|
-
refuseDrift(plan.extensionsDir);
|
|
76
|
-
clearStaging(plan.extensionsDir);
|
|
77
|
-
const built = plan.reuse && plan.tree !== null
|
|
78
|
-
? { tree: plan.tree, lock: plan.lock }
|
|
79
|
-
: await build(plan, prepare);
|
|
80
|
-
pointCurrent(plan.extensionsDir, built.tree);
|
|
81
|
-
promoteFiles(plan.extensionsDir, { manifest: plan.manifest, lock: built.lock });
|
|
82
|
-
collectTrees(plan.extensionsDir, built.tree);
|
|
83
|
-
const count = Object.keys(plan.install).length;
|
|
84
|
-
return { tree: built.tree, npm: plan.npm, reused: plan.reuse, count };
|
|
85
|
-
};
|
|
86
|
-
// Plans again under the lock: a run that waited sees the tree the first one built.
|
|
87
|
-
export const install = async (set, prepare = prepareNpm) => withInstallLock(extensionsDir(), () => execute(planInstall(set), prepare));
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { type InstallSet } from './installer.js';
|
|
2
|
-
import { type Npm } from './npm.js';
|
|
3
|
-
export interface VersionChange {
|
|
4
|
-
name: string;
|
|
5
|
-
from: string | null;
|
|
6
|
-
to: string | null;
|
|
7
|
-
}
|
|
8
|
-
export interface Held {
|
|
9
|
-
name: string;
|
|
10
|
-
version: string;
|
|
11
|
-
newer: string;
|
|
12
|
-
engine: string;
|
|
13
|
-
kit: boolean;
|
|
14
|
-
}
|
|
15
|
-
export interface LatestResult {
|
|
16
|
-
changes: VersionChange[];
|
|
17
|
-
held: Held[];
|
|
18
|
-
unchanged: number;
|
|
19
|
-
tree: string | null;
|
|
20
|
-
current: boolean;
|
|
21
|
-
}
|
|
22
|
-
export type Staged = Omit<LatestResult, 'tree' | 'current'> & {
|
|
23
|
-
tree: string;
|
|
24
|
-
dir: string;
|
|
25
|
-
};
|
|
26
|
-
export type Check = (staged: Staged) => Promise<boolean>;
|
|
27
|
-
export declare const updateLatest: (set: InstallSet, prepare: () => Promise<Npm>, check: Check) => Promise<LatestResult>;
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { join } from 'node:path';
|
|
2
|
-
import { isRecord, readJson } from '../../lib/fs/json-file.js';
|
|
3
|
-
import { manifestInfo } from '../loader/manifest.js';
|
|
4
|
-
import { extensionsDir } from '../paths.js';
|
|
5
|
-
import { fits } from './compat.js';
|
|
6
|
-
import { lockEntries, lockedVersion, parseLock, rootDependencies } from './compare-lock.js';
|
|
7
|
-
import { planInstall, refuseDrift, runNpmInto, } from './installer.js';
|
|
8
|
-
import {} from './npm.js';
|
|
9
|
-
import { clearStaging, collectTrees, commitTree, discardTree, pointCurrent, promoteFiles, readText, stageTree, treePath, withInstallLock, } from './tree.js';
|
|
10
|
-
const diff = (names, before, after) => names
|
|
11
|
-
.map((name) => ({ name, from: lockedVersion(before, name), to: lockedVersion(after, name) }))
|
|
12
|
-
.filter((change) => change.from !== change.to);
|
|
13
|
-
// Every extension the profile names or the old lock installed, sorted.
|
|
14
|
-
const namesOf = (plan, before) => {
|
|
15
|
-
const installed = before === null ? [] : Object.keys(rootDependencies(before));
|
|
16
|
-
return [...new Set([...Object.keys(plan.install), ...installed])].sort();
|
|
17
|
-
};
|
|
18
|
-
const update = async (plan, npm, packages = []) => {
|
|
19
|
-
const staging = stageTree(plan.extensionsDir, plan);
|
|
20
|
-
try {
|
|
21
|
-
const { tree, lock } = await runNpmInto(staging, 'update', npm, packages);
|
|
22
|
-
return { staging, tree, lock: parseLock(lock), raw: lock };
|
|
23
|
-
}
|
|
24
|
-
catch (err) {
|
|
25
|
-
discardTree(staging);
|
|
26
|
-
throw err;
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
const engineIn = (staging, name) => {
|
|
30
|
-
const info = manifestInfo(readJson(join(staging, 'node_modules', name, 'package.json'), isRecord) ?? {});
|
|
31
|
-
return { engine: info.engine, kit: info.kind === 'kit' };
|
|
32
|
-
};
|
|
33
|
-
// An extension whose new version needs another extension API stays where it was.
|
|
34
|
-
const heldIn = (built, changes) => changes.flatMap(({ name, from, to }) => {
|
|
35
|
-
if (from === null || to === null)
|
|
36
|
-
return [];
|
|
37
|
-
const range = engineIn(built.staging, name);
|
|
38
|
-
return fits(range) ? [] : [{ name, version: from, newer: to, ...range }];
|
|
39
|
-
});
|
|
40
|
-
const unchanged = (plan, changes) => Object.keys(plan.install).filter((name) => !changes.some((c) => c.name === name)).length;
|
|
41
|
-
// One update; when it moved an extension past the extension API, again without moving that one.
|
|
42
|
-
const settle = async (plan, npm, names, before) => {
|
|
43
|
-
const first = await update(plan, npm);
|
|
44
|
-
const changes = diff(names, before, first.lock);
|
|
45
|
-
const held = heldIn(first, changes);
|
|
46
|
-
if (held.length === 0)
|
|
47
|
-
return { built: first, held };
|
|
48
|
-
discardTree(first.staging);
|
|
49
|
-
const moving = changes.map((c) => c.name).filter((name) => !held.some((h) => h.name === name));
|
|
50
|
-
return { built: moving.length === 0 ? null : await update(plan, npm, moving), held };
|
|
51
|
-
};
|
|
52
|
-
const sameEntries = (a, b) => (a ? lockEntries(a).join('\n') : '') === (b ? lockEntries(b).join('\n') : '');
|
|
53
|
-
// A tree that failed its check goes, unless extensions/current already names it.
|
|
54
|
-
const dropUnlessCurrent = (dir, tree) => {
|
|
55
|
-
if (readText(join(dir, 'current'))?.trim() !== tree)
|
|
56
|
-
discardTree(treePath(dir, tree));
|
|
57
|
-
};
|
|
58
|
-
// The new tree becomes current only once it passed the check; then it is the only tree left.
|
|
59
|
-
const commit = async (plan, built, staged, check) => {
|
|
60
|
-
commitTree(plan.extensionsDir, built.staging, built.tree);
|
|
61
|
-
if (!(await check(staged))) {
|
|
62
|
-
dropUnlessCurrent(plan.extensionsDir, built.tree);
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
pointCurrent(plan.extensionsDir, built.tree);
|
|
66
|
-
promoteFiles(plan.extensionsDir, { manifest: plan.manifest, lock: built.raw });
|
|
67
|
-
collectTrees(plan.extensionsDir, built.tree);
|
|
68
|
-
return true;
|
|
69
|
-
};
|
|
70
|
-
const run = async (plan, prepare, check) => {
|
|
71
|
-
refuseDrift(plan.extensionsDir);
|
|
72
|
-
clearStaging(plan.extensionsDir);
|
|
73
|
-
const before = parseLock(plan.lock);
|
|
74
|
-
const names = namesOf(plan, before);
|
|
75
|
-
const none = { changes: [], held: [], unchanged: 0, tree: null, current: false };
|
|
76
|
-
if (names.length === 0)
|
|
77
|
-
return none;
|
|
78
|
-
const { built, held } = await settle(plan, await prepare(), names, before);
|
|
79
|
-
const changes = built === null ? [] : diff(names, before, built.lock);
|
|
80
|
-
const result = { ...none, changes, held, unchanged: unchanged(plan, changes) };
|
|
81
|
-
if (built === null || sameEntries(before, built.lock)) {
|
|
82
|
-
if (built !== null)
|
|
83
|
-
discardTree(built.staging);
|
|
84
|
-
return result;
|
|
85
|
-
}
|
|
86
|
-
const staged = { ...result, tree: built.tree, dir: treePath(plan.extensionsDir, built.tree) };
|
|
87
|
-
return { ...result, tree: built.tree, current: await commit(plan, built, staged, check) };
|
|
88
|
-
};
|
|
89
|
-
// `setup --latest`: npm update from the current lock, under the install lock for the whole run.
|
|
90
|
-
export const updateLatest = (set, prepare, check) => withInstallLock(extensionsDir(), () => run(planInstall(set), prepare, check));
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { type Profile } from './schema.js';
|
|
2
|
-
export declare const addExtension: (profile: Profile, name: string, spec: string, machineId: string, off: boolean) => Profile;
|
|
3
|
-
export declare const dropExtension: (profile: Profile, name: string, machineId: string) => Profile;
|
|
4
|
-
export declare const changeProfile: (change: (profile: Profile) => Profile) => Promise<Profile>;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { loadMachine, setProfileSource } from './machine.js';
|
|
2
|
-
import { editableProfile, mutateProfile } from './profile.js';
|
|
3
|
-
import {} from './schema.js';
|
|
4
|
-
const NO_ENTRY = { off: [], config: {}, extra: {} };
|
|
5
|
-
// This machine's off list with `name` in or out; an entry is only created to turn one off.
|
|
6
|
-
const withOff = (profile, machineId, name, off) => {
|
|
7
|
-
const self = profile.machines[machineId];
|
|
8
|
-
if (!self && !off)
|
|
9
|
-
return profile;
|
|
10
|
-
const rest = (self?.off ?? []).filter((pkg) => pkg !== name);
|
|
11
|
-
const entry = { ...NO_ENTRY, ...self, off: off ? [...rest, name] : rest };
|
|
12
|
-
return { ...profile, machines: { ...profile.machines, [machineId]: entry } };
|
|
13
|
-
};
|
|
14
|
-
// Installing a name again replaces its spec; without --off it loads on this machine again.
|
|
15
|
-
export const addExtension = (profile, name, spec, machineId, off) => withOff({ ...profile, extensions: { ...profile.extensions, [name]: spec } }, machineId, name, off);
|
|
16
|
-
// Other machines' off lists are theirs to keep.
|
|
17
|
-
export const dropExtension = (profile, name, machineId) => {
|
|
18
|
-
const extensions = Object.fromEntries(Object.entries(profile.extensions).filter(([pkg]) => pkg !== name));
|
|
19
|
-
return withOff({ ...profile, extensions }, machineId, name, false);
|
|
20
|
-
};
|
|
21
|
-
// A file source stays `file`; any other profile changed here is now this machine's own copy.
|
|
22
|
-
export const changeProfile = async (change) => {
|
|
23
|
-
const next = await mutateProfile(() => change(editableProfile()));
|
|
24
|
-
if ((await loadMachine()).profileSource !== 'file')
|
|
25
|
-
await setProfileSource('default');
|
|
26
|
-
return next;
|
|
27
|
-
};
|