@agentage/cli 0.78.2 → 0.80.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 +2 -0
- package/dist/commands/config/config-get.d.ts +11 -0
- package/dist/commands/config/config-get.js +17 -0
- package/dist/commands/config/config-keys.d.ts +13 -0
- package/dist/commands/config/config-keys.js +18 -0
- package/dist/commands/config/config-list.d.ts +8 -0
- package/dist/commands/config/config-list.js +45 -0
- package/dist/commands/config/config-set.d.ts +12 -0
- package/dist/commands/config/config-set.js +71 -0
- package/dist/commands/config/config.d.ts +13 -0
- package/dist/commands/config/config.js +46 -0
- package/dist/commands/daemon/installer.d.ts +2 -0
- package/dist/commands/daemon/installer.js +12 -0
- package/dist/commands/daemon/repo-installer.d.ts +13 -0
- package/dist/commands/daemon/repo-installer.js +93 -0
- package/dist/commands/daemon/repo-pins.d.ts +6 -0
- package/dist/commands/daemon/repo-pins.js +22 -0
- package/dist/commands/extension/available.d.ts +20 -0
- package/dist/commands/extension/available.js +44 -0
- package/dist/commands/extension/configure.d.ts +1 -0
- package/dist/commands/extension/configure.js +1 -1
- package/dist/commands/extension/install-once.js +2 -1
- package/dist/commands/extension/install-repo.d.ts +7 -0
- package/dist/commands/extension/install-repo.js +30 -0
- package/dist/commands/extension/install-spec.js +12 -4
- package/dist/commands/extension/kit-commands.js +12 -3
- package/dist/commands/extension/kit-tool.d.ts +1 -1
- package/dist/commands/extension/kit-values.d.ts +7 -0
- package/dist/commands/extension/kit-values.js +60 -0
- package/dist/commands/extension/lifecycle-list.d.ts +3 -1
- package/dist/commands/extension/lifecycle-list.js +37 -11
- package/dist/commands/extension/lifecycle-repo.d.ts +16 -0
- package/dist/commands/extension/lifecycle-repo.js +66 -0
- package/dist/commands/extension/lifecycle.d.ts +2 -0
- package/dist/commands/extension/lifecycle.js +2 -1
- package/dist/commands/extension/list.d.ts +4 -0
- package/dist/commands/extension/list.js +5 -1
- package/dist/commands/extension/market-commands.d.ts +10 -0
- package/dist/commands/extension/market-commands.js +24 -0
- package/dist/commands/extension/market.d.ts +39 -0
- package/dist/commands/extension/market.js +89 -0
- package/dist/commands/extension/table.d.ts +1 -0
- package/dist/commands/extension/table.js +8 -0
- package/dist/commands/extension/types.d.ts +14 -0
- package/dist/commands/extension/types.js +51 -0
- package/dist/core/installer/npm.d.ts +1 -0
- package/dist/core/installer/npm.js +1 -1
- package/dist/core/installer/resolve.js +3 -1
- package/dist/core/installer/tree.d.ts +1 -0
- package/dist/core/installer/tree.js +5 -4
- package/dist/core/loader/installed.d.ts +5 -0
- package/dist/core/loader/installed.js +6 -0
- package/dist/core/loader/manifest.js +12 -2
- package/dist/lib/daemon/host-client.d.ts +3 -0
- package/dist/lib/daemon/host-client.js +3 -0
- package/dist/lib/daemon/values.types.d.ts +30 -0
- package/dist/lib/daemon/values.types.js +1 -0
- package/dist/lib/json-codes.d.ts +2 -0
- package/dist/lib/json-codes.js +41 -0
- package/dist/lib/json-output.d.ts +4 -3
- package/dist/lib/json-output.js +8 -39
- package/dist/lib/market/repo-build.d.ts +7 -0
- package/dist/lib/market/repo-build.js +67 -0
- package/dist/lib/market/repo-cache.d.ts +25 -0
- package/dist/lib/market/repo-cache.js +96 -0
- package/dist/lib/market/repo-entries.d.ts +14 -0
- package/dist/lib/market/repo-entries.js +46 -0
- package/dist/lib/market/repo-git.d.ts +13 -0
- package/dist/lib/market/repo-git.js +76 -0
- package/dist/lib/market/repo-links.d.ts +4 -0
- package/dist/lib/market/repo-links.js +35 -0
- package/dist/lib/market/repo-manifest.d.ts +14 -0
- package/dist/lib/market/repo-manifest.js +73 -0
- package/dist/lib/market/repo-markets-file.d.ts +12 -0
- package/dist/lib/market/repo-markets-file.js +39 -0
- package/dist/lib/market/repo-resolve.d.ts +15 -0
- package/dist/lib/market/repo-resolve.js +55 -0
- package/dist/lib/market/repo-text.d.ts +2 -0
- package/dist/lib/market/repo-text.js +7 -0
- package/dist/lib/market/repo-version.d.ts +13 -0
- package/dist/lib/market/repo-version.js +35 -0
- package/dist/lib/npm/npm-cli.d.ts +1 -0
- package/dist/lib/npm/npm-cli.js +1 -1
- package/dist/program-deps.js +36 -1
- package/dist/program.d.ts +13 -0
- package/dist/program.js +18 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -23,6 +23,7 @@ Each command has `--help`. The full reference is [docs/reference.md](docs/refere
|
|
|
23
23
|
| `agentage status` | Show the cli, account, endpoint, machine, profile and extension status |
|
|
24
24
|
| `agentage update` | Update `@agentage/cli` to the latest published version |
|
|
25
25
|
| `agentage daemon` | Start, show, stop or restart the local daemon that runs extensions |
|
|
26
|
+
| `agentage config` | List, get, set or unset the settings and secrets of extensions |
|
|
26
27
|
| `extension install <name>` | Install an extension (`<id>`, `<id>@<version>` or a folder) and run it |
|
|
27
28
|
| `extension list` | Show each installed extension: id, version, source, state |
|
|
28
29
|
| `extension update [id]` | Move each market extension, or one, to its newest version |
|
|
@@ -33,6 +34,7 @@ Each command has `--help`. The full reference is [docs/reference.md](docs/refere
|
|
|
33
34
|
| `extension doctor` | Load every extension once and refresh its state: ok or failed |
|
|
34
35
|
| `extension create <id>` | Create `./extension-<id>` from the extension template |
|
|
35
36
|
| `extension check [dir]` | Check that an extension package conforms, as every build does first |
|
|
37
|
+
| `extension types` | Write `src/agentage-env.d.ts`, the typed keys; `--check` only compares |
|
|
36
38
|
| `extension build` | Build the extension package; `--container` builds one image of all parts |
|
|
37
39
|
| `extension release` | Release an extension in CI; `--changed` releases each changed extension |
|
|
38
40
|
| `extension up` | Run the working copy on the daemon and reload each change |
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ConfigDeps } from './config-keys.js';
|
|
2
|
+
export interface ConfigGetOptions {
|
|
3
|
+
key: string;
|
|
4
|
+
json?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare const runConfigGet: (opts: ConfigGetOptions, deps: ConfigDeps) => Promise<{
|
|
7
|
+
key: string;
|
|
8
|
+
type: string;
|
|
9
|
+
value: unknown;
|
|
10
|
+
source: "default" | "set";
|
|
11
|
+
}>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { CliError, isJsonRun } from '../../lib/json-output.js';
|
|
2
|
+
import { LIST_HINT, ownerOf, secretRefused } from './config-keys.js';
|
|
3
|
+
import { shown } from './config-list.js';
|
|
4
|
+
// One value; a secret is refused by name and never printed.
|
|
5
|
+
export const runConfigGet = async (opts, deps) => {
|
|
6
|
+
const owner = ownerOf(opts.key);
|
|
7
|
+
const rows = await (await deps.host()).values(owner);
|
|
8
|
+
const all = rows.flatMap((row) => row.settings);
|
|
9
|
+
if (rows.some((row) => row.secrets.some((s) => s.key === opts.key)))
|
|
10
|
+
throw secretRefused(opts.key, 'config get never prints one; config list shows if it is set');
|
|
11
|
+
const found = all.find((s) => s.key === opts.key);
|
|
12
|
+
if (!found)
|
|
13
|
+
throw new CliError('invalid_argument', `${opts.key}: ${owner} declares no such key; ${LIST_HINT}`);
|
|
14
|
+
if (!isJsonRun())
|
|
15
|
+
console.log(shown(found.value));
|
|
16
|
+
return { key: found.key, type: found.type, value: found.value, source: found.source };
|
|
17
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type HostClient } from '../../lib/daemon/host-client.js';
|
|
2
|
+
import { type ValueRow } from '../../lib/daemon/values.types.js';
|
|
3
|
+
import { CliError } from '../../lib/json-output.js';
|
|
4
|
+
import { type SecretInput } from '../extension/configure.js';
|
|
5
|
+
export interface ConfigDeps {
|
|
6
|
+
host: () => Promise<HostClient>;
|
|
7
|
+
input: SecretInput;
|
|
8
|
+
}
|
|
9
|
+
export type KeyKind = 'setting' | 'secret';
|
|
10
|
+
export declare const ownerOf: (qualified: string) => string;
|
|
11
|
+
export declare const kindsOf: (rows: ValueRow[]) => Map<string, KeyKind>;
|
|
12
|
+
export declare const LIST_HINT = "agentage config list shows the keys";
|
|
13
|
+
export declare const secretRefused: (key: string, why: string) => CliError;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {} from '../../lib/daemon/host-client.js';
|
|
2
|
+
import {} from '../../lib/daemon/values.types.js';
|
|
3
|
+
import { CliError } from '../../lib/json-output.js';
|
|
4
|
+
import {} from '../extension/configure.js';
|
|
5
|
+
// An extension id has no dot, so the first dot ends the owner (D125.2).
|
|
6
|
+
export const ownerOf = (qualified) => {
|
|
7
|
+
const dot = qualified.indexOf('.');
|
|
8
|
+
if (dot <= 0 || dot === qualified.length - 1)
|
|
9
|
+
throw new CliError('invalid_argument', `${qualified}: expected <owner>.<key>, the owner an extension id or shared`);
|
|
10
|
+
return qualified.slice(0, dot);
|
|
11
|
+
};
|
|
12
|
+
// Every key the daemon knows, by qualified key: only the list tells a secret from a setting.
|
|
13
|
+
export const kindsOf = (rows) => new Map([
|
|
14
|
+
...rows.flatMap((row) => row.settings.map((s) => [s.key, 'setting'])),
|
|
15
|
+
...rows.flatMap((row) => row.secrets.map((s) => [s.key, 'secret'])),
|
|
16
|
+
]);
|
|
17
|
+
export const LIST_HINT = 'agentage config list shows the keys';
|
|
18
|
+
export const secretRefused = (key, why) => new CliError('secret_refused', `${key} is a secret: ${why}`);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type ValueRow } from '../../lib/daemon/values.types.js';
|
|
2
|
+
import { type ConfigDeps } from './config-keys.js';
|
|
3
|
+
export interface ConfigListOptions {
|
|
4
|
+
owner?: string;
|
|
5
|
+
json?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare const shown: (value: unknown) => string;
|
|
8
|
+
export declare const runConfigList: (opts: ConfigListOptions, deps: ConfigDeps) => Promise<ValueRow[]>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {} from '../../lib/daemon/values.types.js';
|
|
2
|
+
import { isJsonRun } from '../../lib/json-output.js';
|
|
3
|
+
import {} from './config-keys.js';
|
|
4
|
+
// Text as typed; anything else as JSON.
|
|
5
|
+
export const shown = (value) => value === undefined ? '(none)' : typeof value === 'string' ? value : JSON.stringify(value);
|
|
6
|
+
// One last cell: the share mode, and for a shared.<key> who declares it.
|
|
7
|
+
const note = (row) => [row.share && `share ${row.share}`, row.declaredBy && `declared by ${row.declaredBy.join(', ')}`]
|
|
8
|
+
.filter(Boolean)
|
|
9
|
+
.join('; ');
|
|
10
|
+
const settingCells = (s) => [
|
|
11
|
+
s.key,
|
|
12
|
+
s.type,
|
|
13
|
+
shown(s.value),
|
|
14
|
+
s.source,
|
|
15
|
+
note(s),
|
|
16
|
+
];
|
|
17
|
+
// A secret is its name and whether it is set, never a value.
|
|
18
|
+
const secretCells = (s) => [
|
|
19
|
+
s.key,
|
|
20
|
+
'secret',
|
|
21
|
+
s.set ? '***' : '(not set)',
|
|
22
|
+
s.set ? 'set' : '',
|
|
23
|
+
note(s),
|
|
24
|
+
];
|
|
25
|
+
const lines = (rows) => {
|
|
26
|
+
const widths = rows[0]?.map((_, i) => Math.max(...rows.map((r) => (r[i] ?? '').length))) ?? [];
|
|
27
|
+
return rows.map((r) => r
|
|
28
|
+
.map((cell, i) => cell.padEnd(widths[i] ?? 0))
|
|
29
|
+
.join(' ')
|
|
30
|
+
.trimEnd());
|
|
31
|
+
};
|
|
32
|
+
const conflicts = (rows) => rows.flatMap((row) => row.settings.flatMap((s) => (s.conflict ? [`conflict: ${s.conflict}`] : [])));
|
|
33
|
+
export const runConfigList = async (opts, deps) => {
|
|
34
|
+
const rows = await (await deps.host()).values(opts.owner);
|
|
35
|
+
const cells = rows.flatMap((row) => [
|
|
36
|
+
...row.settings.map(settingCells),
|
|
37
|
+
...row.secrets.map(secretCells),
|
|
38
|
+
]);
|
|
39
|
+
const text = cells.length ? lines(cells) : ['no settings'];
|
|
40
|
+
// With --json the rows are the answer: no table on stderr.
|
|
41
|
+
if (!isJsonRun())
|
|
42
|
+
for (const line of [...text, ...conflicts(rows)])
|
|
43
|
+
console.log(line);
|
|
44
|
+
return rows;
|
|
45
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ValuesDone } from '../../lib/daemon/values.types.js';
|
|
2
|
+
import { type ConfigDeps } from './config-keys.js';
|
|
3
|
+
export interface ConfigSetOptions {
|
|
4
|
+
pairs: string[];
|
|
5
|
+
json?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface ConfigUnsetOptions {
|
|
8
|
+
keys: string[];
|
|
9
|
+
json?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare const runConfigSet: (opts: ConfigSetOptions, deps: ConfigDeps) => Promise<ValuesDone>;
|
|
12
|
+
export declare const runConfigUnset: (opts: ConfigUnsetOptions, deps: ConfigDeps) => Promise<ValuesDone>;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import {} from '../../lib/daemon/values.types.js';
|
|
2
|
+
import { CliError } from '../../lib/json-output.js';
|
|
3
|
+
import { secretValue } from '../extension/configure.js';
|
|
4
|
+
import { kindsOf, LIST_HINT, ownerOf, secretRefused, } from './config-keys.js';
|
|
5
|
+
const HISTORY = 'a value on the command line stays in the shell history';
|
|
6
|
+
const bareKey = (key, kinds) => {
|
|
7
|
+
if (kinds.get(key) === 'secret')
|
|
8
|
+
return key;
|
|
9
|
+
throw new CliError('invalid_argument', `${key}: expected ${key}=<value>; only a declared secret reads its value from stdin or a prompt`);
|
|
10
|
+
};
|
|
11
|
+
// `<owner>.<key>=<value>` pairs are settings; one bare key of a declared secret is read, never typed.
|
|
12
|
+
const split = (pairs, kinds) => {
|
|
13
|
+
const settings = {};
|
|
14
|
+
const bare = [];
|
|
15
|
+
for (const pair of pairs) {
|
|
16
|
+
const at = pair.indexOf('=');
|
|
17
|
+
const key = at < 0 ? pair : pair.slice(0, at);
|
|
18
|
+
ownerOf(key);
|
|
19
|
+
if (at < 0)
|
|
20
|
+
bare.push(bareKey(key, kinds));
|
|
21
|
+
else if (kinds.get(key) === 'secret')
|
|
22
|
+
throw secretRefused(key, `${HISTORY}; run agentage config set ${key} and type it, or pipe it`);
|
|
23
|
+
else
|
|
24
|
+
settings[key] = pair.slice(at + 1);
|
|
25
|
+
}
|
|
26
|
+
return { settings, bare };
|
|
27
|
+
};
|
|
28
|
+
const secretsOf = async (bare, deps) => {
|
|
29
|
+
if (bare.length > 1)
|
|
30
|
+
throw new CliError('invalid_argument', `one secret at a time: ${bare.join(', ')}`);
|
|
31
|
+
const [key] = bare;
|
|
32
|
+
if (key === undefined)
|
|
33
|
+
return {};
|
|
34
|
+
const value = await secretValue(key, deps.input);
|
|
35
|
+
if (!value)
|
|
36
|
+
throw new CliError('invalid_argument', `${key}: empty value; agentage config unset ${key}`);
|
|
37
|
+
return { [key]: value };
|
|
38
|
+
};
|
|
39
|
+
// The keys and each restarted extension; a restart that failed exits 1 with its reason.
|
|
40
|
+
const report = (verb, done) => {
|
|
41
|
+
console.log(`${verb}: ${done.changed.join(', ')}`);
|
|
42
|
+
for (const r of done.restarted)
|
|
43
|
+
console.log(['restarted:', r.id, r.version, r.state].filter(Boolean).join(' '));
|
|
44
|
+
const failed = done.restarted.filter((r) => r.state === 'failed');
|
|
45
|
+
if (failed.length)
|
|
46
|
+
throw new CliError('extension_failed', failed.map((r) => `${r.id} failed: ${r.error ?? 'no reason given'}`).join('; '), { changed: done.changed });
|
|
47
|
+
return done;
|
|
48
|
+
};
|
|
49
|
+
const patched = async (deps, verb, build) => {
|
|
50
|
+
const host = await deps.host();
|
|
51
|
+
const patch = await build(kindsOf(await host.values()));
|
|
52
|
+
return report(verb, await host.patchValues(patch));
|
|
53
|
+
};
|
|
54
|
+
export const runConfigSet = (opts, deps) => patched(deps, 'set', async (kinds) => {
|
|
55
|
+
const { settings, bare } = split(opts.pairs, kinds);
|
|
56
|
+
const secrets = await secretsOf(bare, deps);
|
|
57
|
+
return { ...(Object.keys(settings).length && { settings }), ...(bare.length && { secrets }) };
|
|
58
|
+
});
|
|
59
|
+
const unsetKind = (key, kinds) => {
|
|
60
|
+
ownerOf(key);
|
|
61
|
+
const kind = kinds.get(key);
|
|
62
|
+
if (!kind)
|
|
63
|
+
throw new CliError('invalid_argument', `${key}: not declared by an installed extension; ${LIST_HINT}`);
|
|
64
|
+
return kind;
|
|
65
|
+
};
|
|
66
|
+
export const runConfigUnset = (opts, deps) => patched(deps, 'unset', async (kinds) => {
|
|
67
|
+
const patch = { settings: {}, secrets: {} };
|
|
68
|
+
for (const key of opts.keys)
|
|
69
|
+
patch[`${unsetKind(key, kinds)}s`][key] = null;
|
|
70
|
+
return patch;
|
|
71
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Command } from 'commander';
|
|
2
|
+
import { type ConfigGetOptions } from './config-get.js';
|
|
3
|
+
import { type ConfigListOptions } from './config-list.js';
|
|
4
|
+
import { type ConfigSetOptions, type ConfigUnsetOptions } from './config-set.js';
|
|
5
|
+
type Action<T> = (opts: T) => Promise<void>;
|
|
6
|
+
export interface ConfigActions {
|
|
7
|
+
list: Action<ConfigListOptions>;
|
|
8
|
+
get: Action<ConfigGetOptions>;
|
|
9
|
+
set: Action<ConfigSetOptions>;
|
|
10
|
+
unset: Action<ConfigUnsetOptions>;
|
|
11
|
+
}
|
|
12
|
+
export declare const registerConfig: (program: Command, actions: ConfigActions) => void;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {} from 'commander';
|
|
2
|
+
import { addJson } from '../../lib/json-output.js';
|
|
3
|
+
import { helpOrUnknown } from '../extension/list.js';
|
|
4
|
+
import {} from './config-get.js';
|
|
5
|
+
import {} from './config-list.js';
|
|
6
|
+
import {} from './config-set.js';
|
|
7
|
+
const CONFIG_HELP = `
|
|
8
|
+
A key is <owner>.<key>: the owner is an extension id, or shared for a value every extension that
|
|
9
|
+
declares shared.<key> reads (agentage config set shared.userNickName=ann). The daemon checks each
|
|
10
|
+
value against the manifests, stores it, and restarts the extensions that read it; it starts when
|
|
11
|
+
none runs. A secret is never printed: config set <owner>.<name> with no =value reads it from stdin,
|
|
12
|
+
or asks for it on a terminal; a secret given as <key>=<value> is refused.`;
|
|
13
|
+
const addList = (group, list) => {
|
|
14
|
+
addJson(group
|
|
15
|
+
.command('list')
|
|
16
|
+
.description('Each key with its type, value and source (default or set)')
|
|
17
|
+
.argument('[owner]', 'only this extension id, or shared')).action((owner, opts) => list({ ...opts, owner }));
|
|
18
|
+
};
|
|
19
|
+
const addGet = (group, get) => {
|
|
20
|
+
addJson(group
|
|
21
|
+
.command('get')
|
|
22
|
+
.description('Print one value; never a secret')
|
|
23
|
+
.argument('<key>', '<owner>.<key>')).action((key, opts) => get({ ...opts, key }));
|
|
24
|
+
};
|
|
25
|
+
const addSet = (group, { set, unset }) => {
|
|
26
|
+
addJson(group
|
|
27
|
+
.command('set')
|
|
28
|
+
.description('Set values: <owner>.<key>=<value>, or <owner>.<secret> alone to type it')
|
|
29
|
+
.argument('<pairs...>', '<owner>.<key>=<value>, one or more')).action((pairs, opts) => set({ ...opts, pairs }));
|
|
30
|
+
addJson(group
|
|
31
|
+
.command('unset')
|
|
32
|
+
.description('Remove stored values: the declared default applies again')
|
|
33
|
+
.argument('<keys...>', '<owner>.<key>, one or more')).action((keys, opts) => unset({ ...opts, keys }));
|
|
34
|
+
};
|
|
35
|
+
// Bare `config` prints its help, an unknown subcommand is usage.
|
|
36
|
+
export const registerConfig = (program, actions) => {
|
|
37
|
+
const group = program
|
|
38
|
+
.command('config')
|
|
39
|
+
.description('Settings and secrets of the extensions on this machine')
|
|
40
|
+
.addHelpText('after', CONFIG_HELP)
|
|
41
|
+
.allowExcessArguments()
|
|
42
|
+
.action(helpOrUnknown);
|
|
43
|
+
addList(group, actions.list);
|
|
44
|
+
addGet(group, actions.get);
|
|
45
|
+
addSet(group, actions);
|
|
46
|
+
};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { Installer } from '@agentage/apphost';
|
|
2
2
|
import { type Npm, type NpmManifest } from '../../core/installer/npm.js';
|
|
3
3
|
import { type Market } from '../../lib/net/market.js';
|
|
4
|
+
import { type RepoInstallDeps } from './repo-installer.js';
|
|
4
5
|
export interface InstallerDeps {
|
|
5
6
|
npm: () => Promise<Npm>;
|
|
7
|
+
repo?: RepoInstallDeps;
|
|
6
8
|
manifest: () => Promise<NpmManifest>;
|
|
7
9
|
market: () => Market;
|
|
8
10
|
}
|
|
@@ -11,6 +11,8 @@ import { CliError, messageOf } from '../../lib/json-output.js';
|
|
|
11
11
|
import {} from '../../lib/net/market.js';
|
|
12
12
|
import { npmFallbackLine, noSiteMarket } from '../../lib/net/market-error.js';
|
|
13
13
|
import { siteFqdn } from '../../lib/net/origins.js';
|
|
14
|
+
import { parseRepoVersion } from '../../lib/market/repo-version.js';
|
|
15
|
+
import { installRepo } from './repo-installer.js';
|
|
14
16
|
// The kit sends an error with a string code to the client as that envelope (404, 502, else 400).
|
|
15
17
|
export const installError = (code, status, message) => Object.assign(new Error(message), { code, status });
|
|
16
18
|
// The market's own reason, in the daemon's case (market_failed is MARKET_FAILED).
|
|
@@ -95,6 +97,13 @@ const fetched = async (id, found, deps) => {
|
|
|
95
97
|
throw installError('INSTALL_FAILED', 502, messageOf(err));
|
|
96
98
|
});
|
|
97
99
|
};
|
|
100
|
+
const fromRepo = async (id, version, ref, deps) => {
|
|
101
|
+
if (!deps.repo)
|
|
102
|
+
throw installError('VALIDATION_ERROR', 400, `${id}: no repo market installer`);
|
|
103
|
+
const dir = await installRepo(id, ref, version, { ...deps.repo, fail: installError });
|
|
104
|
+
checkId(dir, id);
|
|
105
|
+
return { id, version, dir };
|
|
106
|
+
};
|
|
98
107
|
// A version on disk needs no network; else the market, then npm into one folder per version.
|
|
99
108
|
export const cliInstaller = (deps) => async ({ id, version }) => {
|
|
100
109
|
if (version !== undefined && !isVersionSpec(version))
|
|
@@ -102,6 +111,9 @@ export const cliInstaller = (deps) => async ({ id, version }) => {
|
|
|
102
111
|
const have = version ? installedDir(id, version) : null;
|
|
103
112
|
if (version && have)
|
|
104
113
|
return { id, version, dir: have };
|
|
114
|
+
const repo = version ? parseRepoVersion(version) : null;
|
|
115
|
+
if (repo && version)
|
|
116
|
+
return fromRepo(id, version, repo, deps);
|
|
105
117
|
const registry = registryLookup(deps.manifest, editableProfile().registries);
|
|
106
118
|
const found = await exact(await inputOf(id, version, deps.market()), registry);
|
|
107
119
|
const dir = packageDir(id, found.version) ?? (await fetched(id, found, deps));
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type NpmStep } from '../../lib/market/repo-build.js';
|
|
2
|
+
import { type Git } from '../../lib/market/repo-git.js';
|
|
3
|
+
import { type RepoVersion } from '../../lib/market/repo-version.js';
|
|
4
|
+
export interface RepoInstallDeps {
|
|
5
|
+
git: Git;
|
|
6
|
+
step: NpmStep;
|
|
7
|
+
}
|
|
8
|
+
type InstallError = (code: string, status: 400 | 404 | 502, message: string) => Error;
|
|
9
|
+
type InstallDeps = RepoInstallDeps & {
|
|
10
|
+
fail: InstallError;
|
|
11
|
+
};
|
|
12
|
+
export declare const installRepo: (id: string, ref: RepoVersion, full: string, deps: InstallDeps) => Promise<string>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { mkdirSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { packageDir, packagesDir } from '../../core/installer/package-dir.js';
|
|
4
|
+
import { clearStaging, commitTree, discardTree, manifestText, stageTree, treePath, withInstallLock, } from '../../core/installer/tree.js';
|
|
5
|
+
import { messageOf } from '../../lib/json-output.js';
|
|
6
|
+
import { runBuild } from '../../lib/market/repo-build.js';
|
|
7
|
+
import { commitOf, exportFolder } from '../../lib/market/repo-cache.js';
|
|
8
|
+
import { offersAt } from '../../lib/market/repo-entries.js';
|
|
9
|
+
import {} from '../../lib/market/repo-git.js';
|
|
10
|
+
import { escapingLink } from '../../lib/market/repo-links.js';
|
|
11
|
+
import { marketNamed } from '../../lib/market/repo-markets-file.js';
|
|
12
|
+
import { repoVersion } from '../../lib/market/repo-version.js';
|
|
13
|
+
import { pinCommit } from './repo-pins.js';
|
|
14
|
+
const noEscape = (dir) => {
|
|
15
|
+
const link = escapingLink(dir);
|
|
16
|
+
if (link !== null)
|
|
17
|
+
throw new Error(`${link.shown} is a link that points outside the extension folder`);
|
|
18
|
+
};
|
|
19
|
+
// The tree's own package.json names the one package, as an npm tree does: packageDir reads it.
|
|
20
|
+
const stagedTree = (name, version) => {
|
|
21
|
+
clearStaging(packagesDir());
|
|
22
|
+
const manifest = manifestText({ [name]: version });
|
|
23
|
+
return stageTree(packagesDir(), { manifest, npmrc: '', lock: null });
|
|
24
|
+
};
|
|
25
|
+
// The folder at the commit, built in a staged tree; a failure leaves no tree behind.
|
|
26
|
+
const buildTree = async (offer, at, deps) => {
|
|
27
|
+
const name = offer.name ?? offer.id;
|
|
28
|
+
const staging = stagedTree(name, at.version);
|
|
29
|
+
const dir = join(staging, 'node_modules', name);
|
|
30
|
+
try {
|
|
31
|
+
mkdirSync(dir, { recursive: true });
|
|
32
|
+
await exportFolder(deps.git, at.repo, { commit: at.commit, path: offer.path }, dir);
|
|
33
|
+
noEscape(dir);
|
|
34
|
+
await runBuild(dir, deps.step);
|
|
35
|
+
noEscape(dir);
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
discardTree(staging);
|
|
39
|
+
throw err;
|
|
40
|
+
}
|
|
41
|
+
return { staging, name };
|
|
42
|
+
};
|
|
43
|
+
const offerAt = async (id, at, git, fail) => {
|
|
44
|
+
const offers = await offersAt(git, { name: at.market, repo: at.repo, commit: at.commit });
|
|
45
|
+
const offer = offers.find((o) => o.id === id);
|
|
46
|
+
if (!offer)
|
|
47
|
+
throw fail('NOT_FOUND', 404, `${id}: the market ${at.market} has no ${id} at ${at.commit}`);
|
|
48
|
+
if (offer.problem)
|
|
49
|
+
throw fail('VALIDATION_ERROR', 400, `${at.market}/${id}: ${offer.problem}`);
|
|
50
|
+
const full = repoVersion(at.version, at.market, at.commit);
|
|
51
|
+
if (offer.version !== full)
|
|
52
|
+
throw fail('VALIDATION_ERROR', 400, `${id}@${full}: the package at that commit is ${offer.version}`);
|
|
53
|
+
return offer;
|
|
54
|
+
};
|
|
55
|
+
// The market by name and the commit in its clone: the cli fetched it, so no network here.
|
|
56
|
+
const cloneOf = async (id, ref, deps) => {
|
|
57
|
+
const market = marketNamed(ref.market);
|
|
58
|
+
if (!market)
|
|
59
|
+
throw deps.fail('MARKET_GONE', 404, `${id}: the market ${ref.market} is not on this machine`);
|
|
60
|
+
if (!(await commitOf(deps.git, market.repo, ref.commit)))
|
|
61
|
+
throw deps.fail('NOT_FOUND', 404, `${id}: commit ${ref.commit} is no longer in the clone of ${ref.market}; agentage extension update ${id} installs its newest ref`);
|
|
62
|
+
return { ...ref, repo: market.repo };
|
|
63
|
+
};
|
|
64
|
+
// A commit with no pin can go at the next gc, and a lost tree could not be built again.
|
|
65
|
+
const pinned = async (id, at, deps) => {
|
|
66
|
+
if (!(await pinCommit(deps.git, at, id)))
|
|
67
|
+
throw deps.fail('INSTALL_FAILED', 502, `${id}: cannot keep commit ${at.commit} in the clone of ${at.market}; nothing installed`);
|
|
68
|
+
};
|
|
69
|
+
// Pinned before the commit of the tree, so a failed pin leaves no tree a retry would reuse.
|
|
70
|
+
const builtTree = async (id, full, at, deps) => {
|
|
71
|
+
const built = await buildTree(at.offer, at, deps).catch((err) => {
|
|
72
|
+
throw deps.fail('BUILD_FAILED', 400, `${id}: ${messageOf(err)}`);
|
|
73
|
+
});
|
|
74
|
+
await pinned(id, at, deps).catch((err) => {
|
|
75
|
+
discardTree(built.staging);
|
|
76
|
+
throw err;
|
|
77
|
+
});
|
|
78
|
+
commitTree(packagesDir(), built.staging, `${id}@${full}`);
|
|
79
|
+
return join(treePath(packagesDir(), `${id}@${full}`), 'node_modules', built.name);
|
|
80
|
+
};
|
|
81
|
+
// `<version>+<market>.<commit>` is built from the clone, never from npm; pin and prune hold the lock.
|
|
82
|
+
export const installRepo = async (id, ref, full, deps) => {
|
|
83
|
+
const at = await cloneOf(id, ref, deps);
|
|
84
|
+
const offer = await offerAt(id, at, deps.git, deps.fail);
|
|
85
|
+
mkdirSync(packagesDir(), { recursive: true, mode: 0o700 });
|
|
86
|
+
return withInstallLock(packagesDir(), async () => {
|
|
87
|
+
const have = packageDir(id, full);
|
|
88
|
+
if (!have)
|
|
89
|
+
return builtTree(id, full, { ...at, offer }, deps);
|
|
90
|
+
await pinned(id, at, deps);
|
|
91
|
+
return have;
|
|
92
|
+
});
|
|
93
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { existsSync, readdirSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { packagesDir } from '../../core/installer/package-dir.js';
|
|
4
|
+
import { installedVersions } from '../../core/loader/installed.js';
|
|
5
|
+
import { keepCommit, withCloneLock } from '../../lib/market/repo-cache.js';
|
|
6
|
+
import {} from '../../lib/market/repo-git.js';
|
|
7
|
+
import { parseRepoVersion } from '../../lib/market/repo-version.js';
|
|
8
|
+
// Each tree on disk as `<id>@<version>`: the daemon writes a row only after its tree is there.
|
|
9
|
+
const treesOnDisk = () => {
|
|
10
|
+
const trees = join(packagesDir(), 'trees');
|
|
11
|
+
return (existsSync(trees) ? readdirSync(trees) : []).flatMap((name) => {
|
|
12
|
+
const at = name.indexOf('@');
|
|
13
|
+
return at > 0 ? [{ id: name.slice(0, at), version: name.slice(at + 1) }] : [];
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
// `<id>/<commit>` of each row or tree from this market: the commits it still needs.
|
|
17
|
+
const usedPins = (market) => new Set([...installedVersions(), ...treesOnDisk()].flatMap(({ id, version }) => {
|
|
18
|
+
const at = parseRepoVersion(version);
|
|
19
|
+
return at?.market === market ? [`${id}/${at.commit}`] : [];
|
|
20
|
+
}));
|
|
21
|
+
// Pins the commit and drops the pins no row and no tree names; false when the pin failed.
|
|
22
|
+
export const pinCommit = (git, at, id) => withCloneLock(at.repo, () => keepCommit(git, at.repo, usedPins(at.market), { id, commit: at.commit }));
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { WithMeta } from '../../lib/json-output.js';
|
|
2
|
+
import { type RepoDeps } from '../../lib/market/repo-resolve.js';
|
|
3
|
+
import { type MarketListing } from '../../lib/net/market.js';
|
|
4
|
+
export interface Skipped {
|
|
5
|
+
id: string;
|
|
6
|
+
reason: string;
|
|
7
|
+
}
|
|
8
|
+
export interface AvailableRow {
|
|
9
|
+
id: string;
|
|
10
|
+
version: string | null;
|
|
11
|
+
market: string;
|
|
12
|
+
commit?: string;
|
|
13
|
+
description?: string;
|
|
14
|
+
invalid?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare const repoRows: (deps: RepoDeps) => Promise<{
|
|
17
|
+
rows: AvailableRow[];
|
|
18
|
+
skipped: Skipped[];
|
|
19
|
+
}>;
|
|
20
|
+
export declare const printAll: (site: MarketListing, repo: Awaited<ReturnType<typeof repoRows>>) => WithMeta;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { messageOf, WithMeta } from '../../lib/json-output.js';
|
|
2
|
+
import {} from '../../lib/market/repo-entries.js';
|
|
3
|
+
import { SITE_MARKET } from '../../lib/market/repo-manifest.js';
|
|
4
|
+
import { marketOffers } from '../../lib/market/repo-resolve.js';
|
|
5
|
+
import { parseRepoVersion } from '../../lib/market/repo-version.js';
|
|
6
|
+
import {} from '../../lib/net/market.js';
|
|
7
|
+
import { table } from './table.js';
|
|
8
|
+
const rowOf = (offer) => {
|
|
9
|
+
const parsed = offer.version ? parseRepoVersion(offer.version) : null;
|
|
10
|
+
return {
|
|
11
|
+
id: offer.id,
|
|
12
|
+
version: parsed?.version ?? null,
|
|
13
|
+
market: offer.market,
|
|
14
|
+
...(parsed && { commit: parsed.commit }),
|
|
15
|
+
...(offer.description !== undefined && { description: offer.description }),
|
|
16
|
+
...(offer.problem !== undefined && { invalid: offer.problem }),
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
// Every repo market at its newest ref; one that fails is skipped, named by the market.
|
|
20
|
+
export const repoRows = async (deps) => {
|
|
21
|
+
const rows = [];
|
|
22
|
+
const skipped = [];
|
|
23
|
+
for (const market of deps.markets())
|
|
24
|
+
await marketOffers(deps, market).then((offers) => rows.push(...offers.map(rowOf)), (err) => skipped.push({ id: `market ${market.name}`, reason: messageOf(err) }));
|
|
25
|
+
return { rows, skipped };
|
|
26
|
+
};
|
|
27
|
+
const noteOf = (row) => row.invalid ? `invalid: ${row.invalid}` : (row.description ?? '');
|
|
28
|
+
// The site market's rows and the repo markets' rows in one table (exit 0 when some are silent).
|
|
29
|
+
export const printAll = (site, repo) => {
|
|
30
|
+
const down = site.down;
|
|
31
|
+
if (down)
|
|
32
|
+
console.error(down.message);
|
|
33
|
+
const offered = down ? [] : site.offered.map((o) => ({ ...o, market: SITE_MARKET }));
|
|
34
|
+
const rows = [...offered, ...repo.rows];
|
|
35
|
+
const cells = rows.map((r) => [r.id, r.version ?? '-', r.market, noteOf(r)]);
|
|
36
|
+
const lines = table([['ID', 'VERSION', 'MARKET', ''], ...cells]);
|
|
37
|
+
for (const line of rows.length > 0 ? lines : ['the markets list nothing'])
|
|
38
|
+
console.log(line);
|
|
39
|
+
const skipped = [...site.skipped, ...repo.skipped];
|
|
40
|
+
if (skipped.length > 0)
|
|
41
|
+
console.error(`skipped ${skipped.map((s) => `${s.id} (${s.reason})`).join(', ')}`);
|
|
42
|
+
const meta = { skipped, ...(down && { down: { code: down.code, message: down.message } }) };
|
|
43
|
+
return new WithMeta(rows, meta);
|
|
44
|
+
};
|
|
@@ -14,6 +14,7 @@ export declare const readHidden: (question: string, { stdin, stderr }?: {
|
|
|
14
14
|
stderr: Pick<NodeJS.WriteStream, "write">;
|
|
15
15
|
}) => Promise<string>;
|
|
16
16
|
export declare const stdinInput: (prompt: SecretInput["prompt"]) => SecretInput;
|
|
17
|
+
export declare const secretValue: (key: string, input: SecretInput) => Promise<string>;
|
|
17
18
|
export declare const runConfigure: (opts: ConfigureOptions, deps: LifecycleDeps & {
|
|
18
19
|
input: SecretInput;
|
|
19
20
|
}) => Promise<{
|
|
@@ -44,7 +44,7 @@ export const stdinInput = (prompt) => ({
|
|
|
44
44
|
readStdin: readAll,
|
|
45
45
|
prompt,
|
|
46
46
|
});
|
|
47
|
-
const secretValue = async (key, input) => {
|
|
47
|
+
export const secretValue = async (key, input) => {
|
|
48
48
|
if (!input.isTTY)
|
|
49
49
|
return (await input.readStdin()).replace(/\r?\n$/, '');
|
|
50
50
|
if (isJsonRun())
|
|
@@ -2,6 +2,7 @@ import { realpathSync } from 'node:fs';
|
|
|
2
2
|
import { existingOf } from '../../lib/daemon/daemon-answer.js';
|
|
3
3
|
import {} from '../../lib/daemon/host-client.js';
|
|
4
4
|
import { CliError, DaemonError } from '../../lib/json-output.js';
|
|
5
|
+
import { installVersion } from '../../core/loader/installed.js';
|
|
5
6
|
// The add is the check: of two cli runs, the second gets CONFLICT naming the installed entry.
|
|
6
7
|
const added = (host, body) => host.add(body).catch((err) => {
|
|
7
8
|
const existing = err instanceof DaemonError ? existingOf(err) : null;
|
|
@@ -27,7 +28,7 @@ export const installId = async (host, spec) => {
|
|
|
27
28
|
const { id, source } = got.row;
|
|
28
29
|
if (source !== 'market')
|
|
29
30
|
throw elsewhere(`${id} runs from the folder ${source}`, id);
|
|
30
|
-
if (spec.version && spec.version !== got.row.version)
|
|
31
|
+
if (spec.version && spec.version !== (installVersion(id) ?? got.row.version))
|
|
31
32
|
return { row: await host.change(id, { version: spec.version }), already: false };
|
|
32
33
|
return got;
|
|
33
34
|
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type RepoDeps } from '../../lib/market/repo-resolve.js';
|
|
2
|
+
import { type IdBody } from './install-once.js';
|
|
3
|
+
export interface RepoInstallDeps {
|
|
4
|
+
repo: RepoDeps;
|
|
5
|
+
siteKnows: (id: string) => Promise<boolean>;
|
|
6
|
+
}
|
|
7
|
+
export declare const installSpec: (name: string, deps?: RepoInstallDeps) => Promise<IdBody>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { installVersion } from '../../core/loader/installed.js';
|
|
2
|
+
import { CliError } from '../../lib/json-output.js';
|
|
3
|
+
import { SITE_MARKET } from '../../lib/market/repo-manifest.js';
|
|
4
|
+
import { qualifiedOf, resolveBare, resolveQualified, } from '../../lib/market/repo-resolve.js';
|
|
5
|
+
import { specOf } from './install-spec.js';
|
|
6
|
+
import {} from './install-once.js';
|
|
7
|
+
// No repo market configured: a qualified name finds none.
|
|
8
|
+
const none = {
|
|
9
|
+
git: async () => ({ code: 1, stdout: '', stderr: '' }),
|
|
10
|
+
markets: () => [],
|
|
11
|
+
};
|
|
12
|
+
const pinned = (name, version) => new CliError('invalid_argument', `${name}: a repo market installs its newest ref, so drop @${version}`);
|
|
13
|
+
// `acme/hello` is that market's; a bare id the site market lacks may come from one repo market.
|
|
14
|
+
export const installSpec = async (name, deps) => {
|
|
15
|
+
const qualified = qualifiedOf(name);
|
|
16
|
+
const spec = specOf(qualified?.name ?? name);
|
|
17
|
+
if (qualified && qualified.market !== SITE_MARKET) {
|
|
18
|
+
if (spec.version)
|
|
19
|
+
throw pinned(name, spec.version);
|
|
20
|
+
const version = await resolveQualified(deps?.repo ?? none, qualified.market, spec.id);
|
|
21
|
+
return version ? { id: spec.id, version } : spec;
|
|
22
|
+
}
|
|
23
|
+
if (qualified || spec.version || !deps)
|
|
24
|
+
return spec;
|
|
25
|
+
// An installed id answers from installation.json: no network, as with no repo market.
|
|
26
|
+
if (installVersion(spec.id) !== null)
|
|
27
|
+
return spec;
|
|
28
|
+
const version = await resolveBare(deps.repo, spec.id, () => deps.siteKnows(spec.id));
|
|
29
|
+
return version ? { id: spec.id, version } : spec;
|
|
30
|
+
};
|