@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
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isVersionSpec } from '../../core/installer/version-spec.js';
|
|
2
2
|
import { kitIdProblem } from '../../core/kit-id.js';
|
|
3
|
+
import { parseRepoVersion } from '../../lib/market/repo-version.js';
|
|
3
4
|
import { CliError } from '../../lib/json-output.js';
|
|
4
5
|
const ID = /^[a-z][a-z0-9-]*$/;
|
|
5
6
|
const PACKAGE_PREFIX = /^(@agentage\/extension-|agentage-extension-)/;
|
|
@@ -14,6 +15,16 @@ const refusedName = (name) => {
|
|
|
14
15
|
return `${name}: only @agentage/extension-<id> packages install, by id; for another package, install its folder (./path)`;
|
|
15
16
|
return null;
|
|
16
17
|
};
|
|
18
|
+
const checked = (name, id, version) => {
|
|
19
|
+
if (!ID.test(id) || version === '')
|
|
20
|
+
throw new CliError('invalid_argument', `${name}: not an id, id@version or a folder (./path)`);
|
|
21
|
+
if (version !== undefined && !isVersionSpec(version))
|
|
22
|
+
throw new CliError('invalid_argument', `${name}: after @ only a version, a range or a dist-tag`);
|
|
23
|
+
// The cli builds `<version>+<market>.<commit>` from the clone; a typed one could name any version.
|
|
24
|
+
const typed = version === undefined ? null : parseRepoVersion(version);
|
|
25
|
+
if (typed)
|
|
26
|
+
throw new CliError('invalid_argument', `${name}: install ${typed.market}/${id} instead`);
|
|
27
|
+
};
|
|
17
28
|
// `probe`, `probe@0.6.2`, or a package name of the id.
|
|
18
29
|
export const specOf = (name) => {
|
|
19
30
|
const refused = refusedName(name);
|
|
@@ -22,10 +33,7 @@ export const specOf = (name) => {
|
|
|
22
33
|
const at = name.indexOf('@', 1);
|
|
23
34
|
const id = (at < 0 ? name : name.slice(0, at)).replace(PACKAGE_PREFIX, '');
|
|
24
35
|
const version = at < 0 ? undefined : name.slice(at + 1);
|
|
25
|
-
|
|
26
|
-
throw new CliError('invalid_argument', `${name}: not an id, id@version or a folder (./path)`);
|
|
27
|
-
if (version !== undefined && !isVersionSpec(version))
|
|
28
|
-
throw new CliError('invalid_argument', `${name}: after @ only a version, a range or a dist-tag`);
|
|
36
|
+
checked(name, id, version);
|
|
29
37
|
const owned = kitIdProblem(id);
|
|
30
38
|
if (owned)
|
|
31
39
|
throw new CliError('invalid_argument', `${name}: ${owned}`);
|
|
@@ -4,14 +4,23 @@ import { getConfigDir } from '../../lib/fs/config.js';
|
|
|
4
4
|
import {} from '../../core/loader/discover.js';
|
|
5
5
|
import {} from '../../core/loader/verbs.js';
|
|
6
6
|
import {} from './kit-tool.js';
|
|
7
|
+
import { kitValues } from './kit-values.js';
|
|
7
8
|
import { helpOrUnknown } from './list.js';
|
|
8
9
|
// A kit command's own exit code: the program returns it as the CLI's.
|
|
9
10
|
export const KIT_EXIT = 'agentage.kitExit';
|
|
11
|
+
const HELP = ['--help', '-h'];
|
|
12
|
+
const dashes = (argv) => {
|
|
13
|
+
const at = argv.indexOf('--');
|
|
14
|
+
return at < 0 ? argv.length : at;
|
|
15
|
+
};
|
|
10
16
|
// The kit parses args and owns --json and --help; the token never reaches extension code.
|
|
11
|
-
const runKit = async (
|
|
12
|
-
const
|
|
17
|
+
const runKit = async (load, dir, command, argv) => {
|
|
18
|
+
const tool = await load();
|
|
13
19
|
delete process.env['AGENTAGE_TOKEN'];
|
|
14
|
-
const
|
|
20
|
+
const help = argv.slice(0, dashes(argv)).some((arg) => HELP.includes(arg));
|
|
21
|
+
const values = help ? {} : await kitValues(tool, dir, command);
|
|
22
|
+
const dataDir = join(getConfigDir(), 'data');
|
|
23
|
+
const code = await tool.runCommand({ dir, command, argv, dataDir, ...values });
|
|
15
24
|
if (code !== 0)
|
|
16
25
|
throw new CommanderError(code, KIT_EXIT, `${command} exited ${code}`);
|
|
17
26
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type * as Kit from '@agentage/extension/tool';
|
|
2
2
|
import { type KitCheck } from '../../core/loader/load.js';
|
|
3
|
-
export type KitTool = Pick<typeof Kit, 'check' | 'checkLines' | 'build' | 'buildLines' | 'runCommand' | 'checkCli' | 'up' | 'down' | 'token' | 'readManifest' | 'writeContracts' | 'appBuilder' | 'buildApp'>;
|
|
3
|
+
export type KitTool = Pick<typeof Kit, 'check' | 'checkLines' | 'build' | 'buildLines' | 'runCommand' | 'checkCli' | 'up' | 'down' | 'token' | 'readManifest' | 'resolveShared' | 'types' | 'writeContracts' | 'appBuilder' | 'buildApp'>;
|
|
4
4
|
export type LoadKitTool = () => Promise<KitTool>;
|
|
5
5
|
export declare const loadKitTool: LoadKitTool;
|
|
6
6
|
export declare const kitCheck: (tool?: LoadKitTool) => KitCheck;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ResolvedShared } from '@agentage/extension/tool';
|
|
2
|
+
import { type KitTool } from './kit-tool.js';
|
|
3
|
+
export interface KitValues {
|
|
4
|
+
shared: ResolvedShared;
|
|
5
|
+
owners: Record<string, string>;
|
|
6
|
+
}
|
|
7
|
+
export declare const kitValues: (tool: KitTool, dir: string, command: string) => Promise<KitValues>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { installationRows } from '../../core/loader/installed.js';
|
|
4
|
+
import { getConfigDir } from '../../lib/fs/config.js';
|
|
5
|
+
import { isRecord } from '../../lib/fs/json-file.js';
|
|
6
|
+
import { CliError, messageOf } from '../../lib/json-output.js';
|
|
7
|
+
import {} from './kit-tool.js';
|
|
8
|
+
// The daemon writes these files by rename, so a plain read sees one whole version, as its own reads do.
|
|
9
|
+
const rowsOf = (kind) => {
|
|
10
|
+
let text;
|
|
11
|
+
try {
|
|
12
|
+
text = readFileSync(join(getConfigDir(), `${kind}.json`), 'utf-8');
|
|
13
|
+
}
|
|
14
|
+
catch (err) {
|
|
15
|
+
if (err.code === 'ENOENT')
|
|
16
|
+
return {};
|
|
17
|
+
throw err;
|
|
18
|
+
}
|
|
19
|
+
let all;
|
|
20
|
+
try {
|
|
21
|
+
all = JSON.parse(text);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
throw new Error(`${kind}.json is not valid JSON`);
|
|
25
|
+
}
|
|
26
|
+
if (!isRecord(all) || !Object.values(all).every(isRecord))
|
|
27
|
+
throw new Error(`${kind}.json is not an object of rows by id`);
|
|
28
|
+
return all;
|
|
29
|
+
};
|
|
30
|
+
// Every installed folder with a readable manifest, the daemon's set of owners; disabled rows too.
|
|
31
|
+
const installedOwners = async (tool, own) => {
|
|
32
|
+
const manifests = new Map();
|
|
33
|
+
const dirs = {};
|
|
34
|
+
for (const { id, dir } of installationRows()) {
|
|
35
|
+
if (id === own || dir === null)
|
|
36
|
+
continue;
|
|
37
|
+
const pkg = await tool.readManifest(dir).catch(() => undefined);
|
|
38
|
+
if (pkg)
|
|
39
|
+
(manifests.set(id, pkg.agentage), (dirs[id] = dir));
|
|
40
|
+
}
|
|
41
|
+
return { manifests, dirs };
|
|
42
|
+
};
|
|
43
|
+
const resolve = async (tool, dir) => {
|
|
44
|
+
const { agentage } = await tool.readManifest(dir);
|
|
45
|
+
const { manifests, dirs } = await installedOwners(tool, agentage.id);
|
|
46
|
+
const buckets = {
|
|
47
|
+
settings: rowsOf('settings'),
|
|
48
|
+
secrets: rowsOf('secrets'),
|
|
49
|
+
};
|
|
50
|
+
return { shared: tool.resolveShared(agentage, manifests, buckets, process.env), owners: dirs };
|
|
51
|
+
};
|
|
52
|
+
const codeOf = (err) => {
|
|
53
|
+
const code = err.code;
|
|
54
|
+
return typeof code === 'string' ? ` (${code})` : '';
|
|
55
|
+
};
|
|
56
|
+
// What ctx.settings, ctx.secrets, setting(), secret() and db() read, as the daemon resolves them.
|
|
57
|
+
export const kitValues = (tool, dir, command) => resolve(tool, dir).catch((err) => {
|
|
58
|
+
const why = `${messageOf(err)}${codeOf(err)}`;
|
|
59
|
+
throw new CliError('extension_failed', `${command}: cannot resolve its values: ${why}`);
|
|
60
|
+
});
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { type HostRow } from '../../lib/daemon/host-client.js';
|
|
2
2
|
import { WithMeta } from '../../lib/json-output.js';
|
|
3
3
|
import { type Market, type MarketListing } from '../../lib/net/market.js';
|
|
4
|
+
import { type RepoDeps } from '../../lib/market/repo-resolve.js';
|
|
4
5
|
import { type LifecycleDeps } from './lifecycle.js';
|
|
6
|
+
export { table } from './table.js';
|
|
5
7
|
export interface ListOptions {
|
|
6
8
|
available?: boolean;
|
|
7
9
|
json?: boolean;
|
|
@@ -15,8 +17,8 @@ export interface ListDeps extends LifecycleDeps {
|
|
|
15
17
|
available: () => Promise<MarketListing>;
|
|
16
18
|
market: () => Market;
|
|
17
19
|
npmNewest: (id: string) => Promise<string>;
|
|
20
|
+
repo?: RepoDeps;
|
|
18
21
|
}
|
|
19
|
-
export declare const table: (rows: string[][]) => string[];
|
|
20
22
|
export declare const runList: (opts: ListOptions, deps: ListDeps) => Promise<WithMeta | HostRow[]>;
|
|
21
23
|
export declare const runUpdate: (opts: ExtensionUpdateOptions, deps: ListDeps) => Promise<{
|
|
22
24
|
updated: boolean;
|
|
@@ -4,24 +4,30 @@ import { CliError, messageOf, WithMeta } from '../../lib/json-output.js';
|
|
|
4
4
|
import {} from '../../lib/net/market.js';
|
|
5
5
|
import { fromNpmLine, noSiteMarket } from '../../lib/net/market-error.js';
|
|
6
6
|
import { siteFqdn } from '../../lib/net/origins.js';
|
|
7
|
+
import {} from '../../lib/market/repo-resolve.js';
|
|
8
|
+
import { printAll, repoRows } from './available.js';
|
|
7
9
|
import { pruneUnused } from './lifecycle.js';
|
|
10
|
+
import { repoMoves, repoOf, shortVersion, withMarket } from './lifecycle-repo.js';
|
|
11
|
+
import { table } from './table.js';
|
|
12
|
+
export { table } from './table.js';
|
|
8
13
|
// The daemon's rows as they are; a folder entry says `folder` and keeps its path.
|
|
9
14
|
const shown = (row) => row.source === 'market' ? row : { ...row, source: 'folder', path: row.source };
|
|
10
|
-
export const table = (rows) => {
|
|
11
|
-
const widths = rows[0]?.map((_, i) => Math.max(...rows.map((r) => (r[i] ?? '').length))) ?? [];
|
|
12
|
-
return rows.map((r) => r
|
|
13
|
-
.map((cell, i) => cell.padEnd(widths[i] ?? 0))
|
|
14
|
-
.join(' ')
|
|
15
|
-
.trimEnd());
|
|
16
|
-
};
|
|
17
15
|
const printRows = (rows) => {
|
|
18
|
-
const cells = rows.map((r) => [
|
|
16
|
+
const cells = rows.map((r) => [
|
|
17
|
+
r.id,
|
|
18
|
+
r.version,
|
|
19
|
+
String(r['market'] ?? r.source),
|
|
20
|
+
r.state,
|
|
21
|
+
r.error ?? '',
|
|
22
|
+
]);
|
|
19
23
|
const lines = table([['ID', 'VERSION', 'SOURCE', 'STATE', ''], ...cells]);
|
|
20
24
|
for (const line of rows.length > 0 ? lines : ['no extensions'])
|
|
21
25
|
console.log(line);
|
|
22
26
|
};
|
|
23
27
|
// A silent market is one stderr line and an empty list (exit 0), never a failed command.
|
|
24
28
|
const available = async (deps) => {
|
|
29
|
+
if (deps.repo && deps.repo.markets().length > 0)
|
|
30
|
+
return printAll(await deps.available(), await repoRows(deps.repo));
|
|
25
31
|
const { offered, skipped, down } = await deps.available();
|
|
26
32
|
if (down) {
|
|
27
33
|
console.error(down.message);
|
|
@@ -43,7 +49,7 @@ const goneHints = (rows) => {
|
|
|
43
49
|
export const runList = async (opts, deps) => {
|
|
44
50
|
if (opts.available)
|
|
45
51
|
return available(deps);
|
|
46
|
-
const rows = (await (await deps.host()).list()).map(shown);
|
|
52
|
+
const rows = (await (await deps.host()).list()).map(shown).map(withMarket);
|
|
47
53
|
printRows(rows);
|
|
48
54
|
goneHints(rows);
|
|
49
55
|
return rows;
|
|
@@ -80,6 +86,23 @@ const movesOf = async (rows, deps) => {
|
|
|
80
86
|
console.error(fromNpmLine(siteFqdn(), 'newest versions'));
|
|
81
87
|
return { moves, failed };
|
|
82
88
|
};
|
|
89
|
+
const siteMoves = (rows, deps) => movesOf(rows, deps).catch((err) => ({
|
|
90
|
+
moves: [],
|
|
91
|
+
failed: [messageOf(err)],
|
|
92
|
+
...(err instanceof CliError && { outage: err }),
|
|
93
|
+
}));
|
|
94
|
+
// With repo rows, a site outage is one failed line at the end and the repo markets still update.
|
|
95
|
+
const allMoves = async (rows, deps) => {
|
|
96
|
+
const repo = deps.repo ? rows.filter((r) => repoOf(r) !== null) : [];
|
|
97
|
+
const siteRows = rows.filter((r) => !repo.includes(r));
|
|
98
|
+
if (repo.length === 0 || !deps.repo)
|
|
99
|
+
return movesOf(siteRows, deps);
|
|
100
|
+
const site = await siteMoves(siteRows, deps);
|
|
101
|
+
const more = await repoMoves(repo, deps.repo);
|
|
102
|
+
const failed = [...site.failed, ...more.failed];
|
|
103
|
+
const outage = more.failed.length === 0 ? site.outage : undefined;
|
|
104
|
+
return { moves: [...site.moves, ...more.moves], failed, outage };
|
|
105
|
+
};
|
|
83
106
|
const marketRows = async (opts, rows) => {
|
|
84
107
|
const chosen = rows.filter((r) => r.source === 'market' && (!opts.id || r.id === opts.id));
|
|
85
108
|
if (opts.id && chosen.length === 0)
|
|
@@ -90,14 +113,17 @@ const marketRows = async (opts, rows) => {
|
|
|
90
113
|
// On a site with no market, an id npm cannot resolve fails the run at the end (exit 1).
|
|
91
114
|
export const runUpdate = async (opts, deps) => {
|
|
92
115
|
const host = await deps.host();
|
|
93
|
-
const { moves, failed } = await
|
|
116
|
+
const { moves, failed, outage } = await allMoves(await marketRows(opts, await host.list()), deps);
|
|
94
117
|
for (const { id, from, to } of moves) {
|
|
95
118
|
if (!opts.check)
|
|
96
119
|
await host.change(id, { version: to }).then(() => pruneUnused(id));
|
|
97
|
-
|
|
120
|
+
const line = `${id} ${shortVersion(from)} to ${shortVersion(to)}`;
|
|
121
|
+
console.log(`${line}${opts.check ? ' (available)' : ''}`);
|
|
98
122
|
}
|
|
99
123
|
if (moves.length === 0 && failed.length === 0)
|
|
100
124
|
console.log('every extension is at its newest version');
|
|
125
|
+
if (outage)
|
|
126
|
+
throw outage;
|
|
101
127
|
if (failed.length > 0)
|
|
102
128
|
throw new CliError('extension_failed', `no newest version found:\n ${failed.join('\n ')}`);
|
|
103
129
|
return moves.map((move) => ({ ...move, updated: !opts.check }));
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type HostRow } from '../../lib/daemon/host-client.js';
|
|
2
|
+
import { type RepoDeps } from '../../lib/market/repo-resolve.js';
|
|
3
|
+
import { type RepoVersion } from '../../lib/market/repo-version.js';
|
|
4
|
+
export interface Move {
|
|
5
|
+
id: string;
|
|
6
|
+
from: string;
|
|
7
|
+
to: string;
|
|
8
|
+
}
|
|
9
|
+
export interface Moves {
|
|
10
|
+
moves: Move[];
|
|
11
|
+
failed: string[];
|
|
12
|
+
}
|
|
13
|
+
export declare const repoOf: (row: HostRow) => RepoVersion | null;
|
|
14
|
+
export declare const withMarket: (row: HostRow) => HostRow;
|
|
15
|
+
export declare const shortVersion: (version: string) => string;
|
|
16
|
+
export declare const repoMoves: (rows: HostRow[], deps: RepoDeps) => Promise<Moves>;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { installVersion } from '../../core/loader/installed.js';
|
|
2
|
+
import { newestFirst } from '../../core/semver-range.js';
|
|
3
|
+
import {} from '../../lib/daemon/host-client.js';
|
|
4
|
+
import { messageOf } from '../../lib/json-output.js';
|
|
5
|
+
import {} from '../../lib/market/repo-entries.js';
|
|
6
|
+
import { marketOffers } from '../../lib/market/repo-resolve.js';
|
|
7
|
+
import { parseRepoVersion } from '../../lib/market/repo-version.js';
|
|
8
|
+
// A repo-market row: its installation.json version names the market and the commit.
|
|
9
|
+
export const repoOf = (row) => row.source === 'market' ? parseRepoVersion(installVersion(row.id) ?? '') : null;
|
|
10
|
+
// The row with its market and commit; the daemon's own fields stay as they are.
|
|
11
|
+
export const withMarket = (row) => {
|
|
12
|
+
const repo = repoOf(row);
|
|
13
|
+
return repo ? { ...row, market: repo.market, commit: repo.commit } : row;
|
|
14
|
+
};
|
|
15
|
+
// `1.0.0+acme.<commit>` as a person reads it.
|
|
16
|
+
export const shortVersion = (version) => {
|
|
17
|
+
const repo = parseRepoVersion(version);
|
|
18
|
+
return repo ? `${repo.version} (${repo.market} ${repo.commit.slice(0, 7)})` : version;
|
|
19
|
+
};
|
|
20
|
+
// Each market fetched once per run; null for a market no longer on this machine.
|
|
21
|
+
const offersOnce = (deps) => {
|
|
22
|
+
const seen = new Map();
|
|
23
|
+
return (name) => {
|
|
24
|
+
const market = deps.markets().find((m) => m.name === name);
|
|
25
|
+
if (!market)
|
|
26
|
+
return null;
|
|
27
|
+
const got = seen.get(name) ?? marketOffers(deps, market);
|
|
28
|
+
seen.set(name, got);
|
|
29
|
+
return got;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
const plain = (version) => parseRepoVersion(version)?.version ?? version;
|
|
33
|
+
// Forward only: a newer version, or the same version at another commit; never back to an older one.
|
|
34
|
+
const choose = (offer, from, into) => {
|
|
35
|
+
const to = offer.version;
|
|
36
|
+
if (offer.problem || !to)
|
|
37
|
+
into.failed.push(`${offer.id}: ${offer.problem}`);
|
|
38
|
+
else if (newestFirst(plain(from), plain(to)) < 0)
|
|
39
|
+
console.error(`${offer.id}: the newest ref of ${offer.market} is ${plain(to)}, older than the installed ${plain(from)}; it stays`);
|
|
40
|
+
else if (to !== from)
|
|
41
|
+
into.moves.push({ id: offer.id, from, to });
|
|
42
|
+
};
|
|
43
|
+
const moveOf = async (row, offers, into) => {
|
|
44
|
+
const repo = repoOf(row);
|
|
45
|
+
const from = installVersion(row.id) ?? row.version;
|
|
46
|
+
const listed = repo && offers(repo.market);
|
|
47
|
+
if (!repo || !listed) {
|
|
48
|
+
console.error(`${row.id}: the market ${repo?.market} is gone; ${shortVersion(from)} stays`);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const offer = (await listed).find((o) => o.id === row.id);
|
|
52
|
+
if (!offer)
|
|
53
|
+
console.error(`${row.id}: not in the market ${repo.market} any more; it stays`);
|
|
54
|
+
else
|
|
55
|
+
choose(offer, from, into);
|
|
56
|
+
};
|
|
57
|
+
// The newest ref of each row's market; a market that fails names the row, the others go on.
|
|
58
|
+
export const repoMoves = async (rows, deps) => {
|
|
59
|
+
const into = { moves: [], failed: [] };
|
|
60
|
+
const offers = offersOnce(deps);
|
|
61
|
+
for (const row of rows)
|
|
62
|
+
await moveOf(row, offers, into).catch((err) => {
|
|
63
|
+
into.failed.push(`${row.id}: ${messageOf(err)}`);
|
|
64
|
+
});
|
|
65
|
+
return into;
|
|
66
|
+
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type HostClient, type HostSummary } from '../../lib/daemon/host-client.js';
|
|
2
|
+
import { type RepoInstallDeps } from './install-repo.js';
|
|
2
3
|
export interface LifecycleDeps {
|
|
3
4
|
host: () => Promise<HostClient>;
|
|
4
5
|
}
|
|
@@ -24,6 +25,7 @@ export interface InstallDeps extends LifecycleDeps {
|
|
|
24
25
|
fromNpm?: (id: string, what: string) => Promise<string | null>;
|
|
25
26
|
hasMarket?: (id: string) => Promise<boolean>;
|
|
26
27
|
sealOff?: () => Promise<string | null>;
|
|
28
|
+
repo?: RepoInstallDeps;
|
|
27
29
|
}
|
|
28
30
|
export declare const runInstall: (opts: InstallOptions, deps: InstallDeps) => Promise<HostSummary>;
|
|
29
31
|
export declare const runEnabled: (id: string, enabled: boolean, deps: LifecycleDeps) => Promise<HostSummary>;
|
|
@@ -10,6 +10,7 @@ import {} from '../../lib/daemon/host-client.js';
|
|
|
10
10
|
import { installFolder, installId } from './install-once.js';
|
|
11
11
|
import { CliError, isJsonRun } from '../../lib/json-output.js';
|
|
12
12
|
import { specOf, unscoped, UNSCOPED } from './install-spec.js';
|
|
13
|
+
import { installSpec } from './install-repo.js';
|
|
13
14
|
const LOCAL = /^\.{1,2}(?:[/\\]|$)/;
|
|
14
15
|
// The real path; a folder another user can write runs code as you, so it is refused.
|
|
15
16
|
const folderOf = (input) => {
|
|
@@ -41,7 +42,7 @@ export const report = (done, note = '') => {
|
|
|
41
42
|
// The install string is checked before the daemon starts: a bad one starts nothing.
|
|
42
43
|
export const runInstall = async (opts, deps) => {
|
|
43
44
|
const folder = LOCAL.test(opts.name) || isAbsolute(opts.name) ? folderOf(opts.name) : null;
|
|
44
|
-
const spec = folder ? null :
|
|
45
|
+
const spec = folder ? null : await installSpec(opts.name, deps.repo);
|
|
45
46
|
if (spec && opts.name.startsWith(UNSCOPED) && (await deps.hasMarket?.(spec.id)))
|
|
46
47
|
throw unscoped(opts.name);
|
|
47
48
|
const host = await deps.host();
|
|
@@ -4,7 +4,9 @@ import { type ExtensionReleaseOptions } from './release.js';
|
|
|
4
4
|
import { type ExtensionCreateOptions } from './create.js';
|
|
5
5
|
import { type ExtensionDoctorOptions } from './doctor.js';
|
|
6
6
|
import { type LifecycleActions } from './lifecycle-commands.js';
|
|
7
|
+
import { type MarketActions } from './market-commands.js';
|
|
7
8
|
import { type ExtensionsGather } from './rows.js';
|
|
9
|
+
import { type ExtensionTypesOptions } from './types.js';
|
|
8
10
|
import { type KitActions } from './up-commands.js';
|
|
9
11
|
export declare const printReport: ({ status, warnings }: ExtensionsGather, json?: boolean) => void;
|
|
10
12
|
export declare const helpOrUnknown: (_opts: unknown, group: Command) => void;
|
|
@@ -12,5 +14,7 @@ export interface ExtensionActions extends KitActions, BuildActions, LifecycleAct
|
|
|
12
14
|
doctor: (opts: ExtensionDoctorOptions) => Promise<void>;
|
|
13
15
|
create: (opts: ExtensionCreateOptions) => Promise<void>;
|
|
14
16
|
release: (opts: ExtensionReleaseOptions) => Promise<void>;
|
|
17
|
+
types: (opts: ExtensionTypesOptions) => Promise<void>;
|
|
18
|
+
market: MarketActions;
|
|
15
19
|
}
|
|
16
20
|
export declare const registerExtension: (program: Command, actions: ExtensionActions) => void;
|
|
@@ -4,8 +4,10 @@ import { addRelease } from './release.js';
|
|
|
4
4
|
import { addCreate } from './create.js';
|
|
5
5
|
import {} from './doctor.js';
|
|
6
6
|
import { addLifecycle } from './lifecycle-commands.js';
|
|
7
|
+
import { addMarket } from './market-commands.js';
|
|
7
8
|
import { printWarnings, rowLines } from './row-lines.js';
|
|
8
9
|
import {} from './rows.js';
|
|
10
|
+
import { addTypes } from './types.js';
|
|
9
11
|
import { addKitTools } from './up-commands.js';
|
|
10
12
|
// The rows, or the whole report as JSON, on stdout; warnings on stderr (extension doctor).
|
|
11
13
|
export const printReport = ({ status, warnings }, json) => {
|
|
@@ -39,7 +41,7 @@ const addDoctor = (group, doctor) => {
|
|
|
39
41
|
.addHelpText('after', DOCTOR_HELP)
|
|
40
42
|
.action(doctor);
|
|
41
43
|
};
|
|
42
|
-
// Help order: C1 (install to remove), then doctor, create, check, build, release, up, down, token.
|
|
44
|
+
// Help order: C1 (install to remove), market, then doctor, create, check, build, release, up, down, token.
|
|
43
45
|
export const registerExtension = (program, actions) => {
|
|
44
46
|
const group = program
|
|
45
47
|
.command('extension')
|
|
@@ -47,9 +49,11 @@ export const registerExtension = (program, actions) => {
|
|
|
47
49
|
.allowExcessArguments()
|
|
48
50
|
.action(helpOrUnknown);
|
|
49
51
|
addLifecycle(group, actions);
|
|
52
|
+
addMarket(group, actions.market);
|
|
50
53
|
addDoctor(group, actions.doctor);
|
|
51
54
|
addCreate(group, actions.create);
|
|
52
55
|
addBuild(group, actions);
|
|
53
56
|
addRelease(group, actions.release);
|
|
54
57
|
addKitTools(group, actions);
|
|
58
|
+
addTypes(group, actions.types);
|
|
55
59
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type Command } from 'commander';
|
|
2
|
+
import { type MarketAddOptions, type MarketListOptions, type MarketRemoveOptions } from './market.js';
|
|
3
|
+
type Action<T> = (opts: T) => Promise<void>;
|
|
4
|
+
export interface MarketActions {
|
|
5
|
+
add: Action<MarketAddOptions>;
|
|
6
|
+
list: Action<MarketListOptions>;
|
|
7
|
+
remove: Action<MarketRemoveOptions>;
|
|
8
|
+
}
|
|
9
|
+
export declare const addMarket: (group: Command, actions: MarketActions) => void;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {} from 'commander';
|
|
2
|
+
import { addJson } from '../../lib/json-output.js';
|
|
3
|
+
import {} from './market.js';
|
|
4
|
+
const MARKET_HELP = `
|
|
5
|
+
A repo market is a GitHub repo with agentage-market.json at its root. Its extensions install by
|
|
6
|
+
id (the site market first) or as <market>/<id>, from the newest v* tag, else the default branch.
|
|
7
|
+
git's own credentials reach private repos (GH_TOKEN or GITHUB_TOKEN too); nothing is stored. An
|
|
8
|
+
extension with a build script is built on this machine: npm ci, then npm run build.`;
|
|
9
|
+
// `extension market add | list | remove`: this machine's repo markets, in markets.json.
|
|
10
|
+
export const addMarket = (group, actions) => {
|
|
11
|
+
const market = group
|
|
12
|
+
.command('market')
|
|
13
|
+
.description('Add, list or remove the GitHub repos that offer extensions')
|
|
14
|
+
.addHelpText('after', MARKET_HELP);
|
|
15
|
+
addJson(market
|
|
16
|
+
.command('add')
|
|
17
|
+
.description('Add a GitHub repo as a market (clones it, reads its manifest)')
|
|
18
|
+
.argument('<repo>', '<owner>/<repo>')).action((repo, opts) => actions.add({ ...opts, repo }));
|
|
19
|
+
addJson(market.command('list').description('Show each repo market: name, repo, extensions')).action(actions.list);
|
|
20
|
+
addJson(market
|
|
21
|
+
.command('remove')
|
|
22
|
+
.description('Forget a repo market; its installed extensions keep running')
|
|
23
|
+
.argument('<name>', 'the market name')).action((name, opts) => actions.remove({ ...opts, name }));
|
|
24
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type Git } from '../../lib/market/repo-git.js';
|
|
2
|
+
export interface MarketCmdDeps {
|
|
3
|
+
git: Git;
|
|
4
|
+
now?: () => Date;
|
|
5
|
+
}
|
|
6
|
+
export interface MarketAddOptions {
|
|
7
|
+
repo: string;
|
|
8
|
+
json?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface MarketListOptions {
|
|
11
|
+
json?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface MarketRemoveOptions {
|
|
14
|
+
name: string;
|
|
15
|
+
json?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface MarketRuns {
|
|
18
|
+
add: (opts: MarketAddOptions) => Promise<unknown>;
|
|
19
|
+
list: (opts: MarketListOptions) => Promise<unknown>;
|
|
20
|
+
remove: (opts: MarketRemoveOptions) => Promise<unknown>;
|
|
21
|
+
}
|
|
22
|
+
export declare const BUILD_NOTE = "installs from this market run its build scripts as you, outside the seal, with your files in reach; add only a market you trust";
|
|
23
|
+
export declare const runMarketAdd: (opts: MarketAddOptions, deps: MarketCmdDeps) => Promise<{
|
|
24
|
+
extensions: number;
|
|
25
|
+
already: boolean;
|
|
26
|
+
name: string;
|
|
27
|
+
repo: string;
|
|
28
|
+
added: string;
|
|
29
|
+
}>;
|
|
30
|
+
export declare const runMarketList: (_opts: MarketListOptions, deps: MarketCmdDeps) => Promise<{
|
|
31
|
+
extensions: number | null;
|
|
32
|
+
name: string;
|
|
33
|
+
repo: string;
|
|
34
|
+
added: string;
|
|
35
|
+
}[]>;
|
|
36
|
+
export declare const runMarketRemove: (opts: MarketRemoveOptions) => Promise<{
|
|
37
|
+
name: string;
|
|
38
|
+
repo: string;
|
|
39
|
+
}>;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { rmSync } from 'node:fs';
|
|
2
|
+
import { CliError } from '../../lib/json-output.js';
|
|
3
|
+
import { cacheDir, CURRENT, manifestAt, syncLocked, withCloneLock, } from '../../lib/market/repo-cache.js';
|
|
4
|
+
import { offersAt } from '../../lib/market/repo-entries.js';
|
|
5
|
+
import {} from '../../lib/market/repo-git.js';
|
|
6
|
+
import { marketsToWrite, readMarkets, REPO, withMarkets, writeMarkets, } from '../../lib/market/repo-markets-file.js';
|
|
7
|
+
import { table } from './table.js';
|
|
8
|
+
export const BUILD_NOTE = 'installs from this market run its build scripts as you, outside the seal, with your files in reach; add only a market you trust';
|
|
9
|
+
const repoOf = (input) => {
|
|
10
|
+
const repo = input.replace(/\.git$/, '');
|
|
11
|
+
if (!REPO.test(repo))
|
|
12
|
+
throw new CliError('invalid_argument', `${input}: not <owner>/<repo>`);
|
|
13
|
+
return repo;
|
|
14
|
+
};
|
|
15
|
+
const sameRepo = (a, b) => a.toLowerCase() === b.toLowerCase();
|
|
16
|
+
const claimed = (markets, name, repo) => {
|
|
17
|
+
const other = markets.find((m) => m.name === name && !sameRepo(m.repo, repo));
|
|
18
|
+
if (other)
|
|
19
|
+
throw new CliError('invalid_argument', `the market name ${name} is taken by ${other.repo}; nothing added`);
|
|
20
|
+
};
|
|
21
|
+
// The manifest name, read at the newest ref; a failed first add leaves no clone behind.
|
|
22
|
+
const nameAt = async (repo, markets, deps) => {
|
|
23
|
+
let name = '';
|
|
24
|
+
const { commit } = await syncLocked(deps.git, repo, async (at) => {
|
|
25
|
+
name = (await manifestAt(deps.git, { repo, commit: at })).name;
|
|
26
|
+
claimed(markets, name, repo);
|
|
27
|
+
});
|
|
28
|
+
return { commit, name };
|
|
29
|
+
};
|
|
30
|
+
const dropClone = (repo) => rmSync(cacheDir(repo), { recursive: true, force: true });
|
|
31
|
+
// The row, written under the lock from the file as it is now; another add may have landed first.
|
|
32
|
+
const record = (repo, name, now) => withMarkets((markets) => {
|
|
33
|
+
const had = markets.find((m) => sameRepo(m.repo, repo));
|
|
34
|
+
if (had)
|
|
35
|
+
return { row: had, already: true };
|
|
36
|
+
claimed(markets, name, repo);
|
|
37
|
+
const row = { name, repo, added: now.toISOString() };
|
|
38
|
+
writeMarkets([...markets, row]);
|
|
39
|
+
return { row, already: false };
|
|
40
|
+
});
|
|
41
|
+
// Under the clone lock, then the markets.json lock (one order everywhere): row and clone together.
|
|
42
|
+
const addLocked = async (repo, deps) => {
|
|
43
|
+
const markets = marketsToWrite();
|
|
44
|
+
const fresh = !markets.some((m) => sameRepo(m.repo, repo));
|
|
45
|
+
const { commit, name } = await nameAt(repo, markets, deps);
|
|
46
|
+
const recorded = await record(repo, name, deps.now?.() ?? new Date()).catch((err) => {
|
|
47
|
+
if (fresh && !readMarkets().some((m) => sameRepo(m.repo, repo)))
|
|
48
|
+
dropClone(repo);
|
|
49
|
+
throw err;
|
|
50
|
+
});
|
|
51
|
+
return { ...recorded, commit };
|
|
52
|
+
};
|
|
53
|
+
// Clones the repo, reads its manifest; the same repo again changes nothing.
|
|
54
|
+
export const runMarketAdd = async (opts, deps) => {
|
|
55
|
+
const repo = repoOf(opts.repo);
|
|
56
|
+
marketsToWrite();
|
|
57
|
+
const { row, already, commit } = await withCloneLock(repo, () => addLocked(repo, deps));
|
|
58
|
+
const offers = await offersAt(deps.git, { name: row.name, repo, commit });
|
|
59
|
+
console.log(`market ${row.name} ${repo}: ${offers.length} extensions${already ? ' (already added)' : ''}`);
|
|
60
|
+
console.error(BUILD_NOTE);
|
|
61
|
+
return { ...row, extensions: offers.length, already };
|
|
62
|
+
};
|
|
63
|
+
// The count at the last fetched ref: no network.
|
|
64
|
+
const countOf = async (market, git) => manifestAt(git, { repo: market.repo, commit: CURRENT }).then((m) => m.extensions.length, () => null);
|
|
65
|
+
export const runMarketList = async (_opts, deps) => {
|
|
66
|
+
const rows = await Promise.all(readMarkets().map(async (m) => ({ ...m, extensions: await countOf(m, deps.git) })));
|
|
67
|
+
const cells = rows.map((r) => [r.name, r.repo, String(r.extensions ?? '?')]);
|
|
68
|
+
const lines = table([['NAME', 'REPO', 'EXTENSIONS'], ...cells]);
|
|
69
|
+
for (const line of rows.length > 0 ? lines : ['no repo markets'])
|
|
70
|
+
console.log(line);
|
|
71
|
+
return rows;
|
|
72
|
+
};
|
|
73
|
+
const noMarket = (name) => new CliError('not_installed', `no market ${name} on this machine`);
|
|
74
|
+
// Forgets the market and its clone, both under the clone lock; installed extensions keep running.
|
|
75
|
+
export const runMarketRemove = async (opts) => {
|
|
76
|
+
const named = marketsToWrite().find((m) => m.name === opts.name);
|
|
77
|
+
if (!named)
|
|
78
|
+
throw noMarket(opts.name);
|
|
79
|
+
const gone = await withCloneLock(named.repo, () => withMarkets((markets) => {
|
|
80
|
+
const found = markets.find((m) => m.name === opts.name && sameRepo(m.repo, named.repo));
|
|
81
|
+
if (!found)
|
|
82
|
+
throw noMarket(opts.name);
|
|
83
|
+
writeMarkets(markets.filter((m) => m !== found));
|
|
84
|
+
dropClone(found.repo);
|
|
85
|
+
return found;
|
|
86
|
+
}));
|
|
87
|
+
console.log(`removed market ${gone.name} (${gone.repo}); its installed extensions stay`);
|
|
88
|
+
return { name: gone.name, repo: gone.repo };
|
|
89
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const table: (rows: string[][]) => string[];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Columns padded to the widest cell; trailing spaces trimmed.
|
|
2
|
+
export const table = (rows) => {
|
|
3
|
+
const widths = rows[0]?.map((_, i) => Math.max(...rows.map((r) => (r[i] ?? '').length))) ?? [];
|
|
4
|
+
return rows.map((r) => r
|
|
5
|
+
.map((cell, i) => cell.padEnd(widths[i] ?? 0))
|
|
6
|
+
.join(' ')
|
|
7
|
+
.trimEnd());
|
|
8
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type Command } from 'commander';
|
|
2
|
+
import { type LoadKitTool } from './kit-tool.js';
|
|
3
|
+
export interface ExtensionTypesOptions {
|
|
4
|
+
dir?: string;
|
|
5
|
+
check?: boolean;
|
|
6
|
+
owner?: string[];
|
|
7
|
+
json?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare const runExtensionTypes: ({ dir, check, owner }?: ExtensionTypesOptions, tool?: LoadKitTool) => Promise<{
|
|
10
|
+
owners: string[];
|
|
11
|
+
file: string;
|
|
12
|
+
changed: boolean;
|
|
13
|
+
}>;
|
|
14
|
+
export declare const addTypes: (group: Command, types: (opts: ExtensionTypesOptions) => Promise<void>) => Command;
|