@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.
Files changed (87) hide show
  1. package/README.md +2 -0
  2. package/dist/commands/config/config-get.d.ts +11 -0
  3. package/dist/commands/config/config-get.js +17 -0
  4. package/dist/commands/config/config-keys.d.ts +13 -0
  5. package/dist/commands/config/config-keys.js +18 -0
  6. package/dist/commands/config/config-list.d.ts +8 -0
  7. package/dist/commands/config/config-list.js +45 -0
  8. package/dist/commands/config/config-set.d.ts +12 -0
  9. package/dist/commands/config/config-set.js +71 -0
  10. package/dist/commands/config/config.d.ts +13 -0
  11. package/dist/commands/config/config.js +46 -0
  12. package/dist/commands/daemon/installer.d.ts +2 -0
  13. package/dist/commands/daemon/installer.js +12 -0
  14. package/dist/commands/daemon/repo-installer.d.ts +13 -0
  15. package/dist/commands/daemon/repo-installer.js +93 -0
  16. package/dist/commands/daemon/repo-pins.d.ts +6 -0
  17. package/dist/commands/daemon/repo-pins.js +22 -0
  18. package/dist/commands/extension/available.d.ts +20 -0
  19. package/dist/commands/extension/available.js +44 -0
  20. package/dist/commands/extension/configure.d.ts +1 -0
  21. package/dist/commands/extension/configure.js +1 -1
  22. package/dist/commands/extension/install-once.js +2 -1
  23. package/dist/commands/extension/install-repo.d.ts +7 -0
  24. package/dist/commands/extension/install-repo.js +30 -0
  25. package/dist/commands/extension/install-spec.js +12 -4
  26. package/dist/commands/extension/kit-commands.js +12 -3
  27. package/dist/commands/extension/kit-tool.d.ts +1 -1
  28. package/dist/commands/extension/kit-values.d.ts +7 -0
  29. package/dist/commands/extension/kit-values.js +60 -0
  30. package/dist/commands/extension/lifecycle-list.d.ts +3 -1
  31. package/dist/commands/extension/lifecycle-list.js +37 -11
  32. package/dist/commands/extension/lifecycle-repo.d.ts +16 -0
  33. package/dist/commands/extension/lifecycle-repo.js +66 -0
  34. package/dist/commands/extension/lifecycle.d.ts +2 -0
  35. package/dist/commands/extension/lifecycle.js +2 -1
  36. package/dist/commands/extension/list.d.ts +4 -0
  37. package/dist/commands/extension/list.js +5 -1
  38. package/dist/commands/extension/market-commands.d.ts +10 -0
  39. package/dist/commands/extension/market-commands.js +24 -0
  40. package/dist/commands/extension/market.d.ts +39 -0
  41. package/dist/commands/extension/market.js +89 -0
  42. package/dist/commands/extension/table.d.ts +1 -0
  43. package/dist/commands/extension/table.js +8 -0
  44. package/dist/commands/extension/types.d.ts +14 -0
  45. package/dist/commands/extension/types.js +51 -0
  46. package/dist/core/installer/npm.d.ts +1 -0
  47. package/dist/core/installer/npm.js +1 -1
  48. package/dist/core/installer/resolve.js +3 -1
  49. package/dist/core/installer/tree.d.ts +1 -0
  50. package/dist/core/installer/tree.js +5 -4
  51. package/dist/core/loader/installed.d.ts +5 -0
  52. package/dist/core/loader/installed.js +6 -0
  53. package/dist/core/loader/manifest.js +12 -2
  54. package/dist/lib/daemon/host-client.d.ts +3 -0
  55. package/dist/lib/daemon/host-client.js +3 -0
  56. package/dist/lib/daemon/values.types.d.ts +30 -0
  57. package/dist/lib/daemon/values.types.js +1 -0
  58. package/dist/lib/json-codes.d.ts +2 -0
  59. package/dist/lib/json-codes.js +41 -0
  60. package/dist/lib/json-output.d.ts +4 -3
  61. package/dist/lib/json-output.js +8 -39
  62. package/dist/lib/market/repo-build.d.ts +7 -0
  63. package/dist/lib/market/repo-build.js +67 -0
  64. package/dist/lib/market/repo-cache.d.ts +25 -0
  65. package/dist/lib/market/repo-cache.js +96 -0
  66. package/dist/lib/market/repo-entries.d.ts +14 -0
  67. package/dist/lib/market/repo-entries.js +46 -0
  68. package/dist/lib/market/repo-git.d.ts +13 -0
  69. package/dist/lib/market/repo-git.js +76 -0
  70. package/dist/lib/market/repo-links.d.ts +4 -0
  71. package/dist/lib/market/repo-links.js +35 -0
  72. package/dist/lib/market/repo-manifest.d.ts +14 -0
  73. package/dist/lib/market/repo-manifest.js +73 -0
  74. package/dist/lib/market/repo-markets-file.d.ts +12 -0
  75. package/dist/lib/market/repo-markets-file.js +39 -0
  76. package/dist/lib/market/repo-resolve.d.ts +15 -0
  77. package/dist/lib/market/repo-resolve.js +55 -0
  78. package/dist/lib/market/repo-text.d.ts +2 -0
  79. package/dist/lib/market/repo-text.js +7 -0
  80. package/dist/lib/market/repo-version.d.ts +13 -0
  81. package/dist/lib/market/repo-version.js +35 -0
  82. package/dist/lib/npm/npm-cli.d.ts +1 -0
  83. package/dist/lib/npm/npm-cli.js +1 -1
  84. package/dist/program-deps.js +36 -1
  85. package/dist/program.d.ts +13 -0
  86. package/dist/program.js +18 -0
  87. package/package.json +3 -3
@@ -0,0 +1,76 @@
1
+ import { execFile } from 'node:child_process';
2
+ import { childEnv } from '../child-env.js';
3
+ import { CliError } from '../json-output.js';
4
+ import { oneLine } from './repo-text.js';
5
+ const GIT_TIMEOUT_MS = 5 * 60_000;
6
+ const MAX_BUFFER = 16 * 1024 * 1024;
7
+ const TOKEN_VARS = ['GH_TOKEN', 'GITHUB_TOKEN'];
8
+ // The one place a repo becomes a URL: a test redirects it with git's own `insteadOf`.
9
+ export const cloneUrl = (repo) => `https://github.com/${repo}.git`;
10
+ const tokenOf = (env) => TOKEN_VARS.map((name) => env[name]).find((value) => !!value) ?? null;
11
+ const basicOf = (token) => Buffer.from(`x-access-token:${token}`).toString('base64');
12
+ // The token rides in git's env config, scoped to github.com: never in argv, never in a file.
13
+ export const gitEnv = (env = process.env) => {
14
+ const copy = { ...childEnv(env), GIT_TERMINAL_PROMPT: '0' };
15
+ for (const name of TOKEN_VARS)
16
+ delete copy[name];
17
+ const token = tokenOf(env);
18
+ if (!token)
19
+ return copy;
20
+ const count = Number.parseInt(env['GIT_CONFIG_COUNT'] ?? '0', 10);
21
+ const at = Number.isInteger(count) && count > 0 ? count : 0;
22
+ return {
23
+ ...copy,
24
+ GIT_CONFIG_COUNT: String(at + 1),
25
+ [`GIT_CONFIG_KEY_${at}`]: 'http.https://github.com/.extraheader',
26
+ [`GIT_CONFIG_VALUE_${at}`]: `Authorization: Basic ${basicOf(token)}`,
27
+ };
28
+ };
29
+ // Whatever a git or npm run prints passes this before it reaches a message.
30
+ export const redact = (text, env = process.env) => {
31
+ const token = tokenOf(env);
32
+ if (!token)
33
+ return text;
34
+ return text.split(token).join('***').split(basicOf(token)).join('***');
35
+ };
36
+ // GitHub answers 404 for a private repo without access: "not found" and "no access" are one case.
37
+ const AUTH = /terminal prompts disabled|Authentication failed|could not read Username|Repository not found|repository '[^']*' not found|returned error: 40[134]/i;
38
+ const NETWORK = /Could not resolve host|Failed to connect|Connection timed out|Connection refused/i;
39
+ const execGit = (args, env, secrets) => new Promise((resolve) => {
40
+ const limits = { maxBuffer: MAX_BUFFER, windowsHide: true, timeout: GIT_TIMEOUT_MS };
41
+ execFile('git', args, { env, ...limits }, (err, stdout, stderr) => {
42
+ const missing = err?.code === 'ENOENT';
43
+ const code = !err ? 0 : typeof err.code === 'number' ? err.code : 1;
44
+ const why = missing ? 'git is not on the PATH' : redact(stderr, secrets);
45
+ resolve({ code, stdout, stderr: why });
46
+ });
47
+ });
48
+ const withoutToken = (env) => Object.fromEntries(Object.entries(env).filter(([key]) => !TOKEN_VARS.includes(key)));
49
+ // A stale token must not lock out what git's own credentials, or none, can read: one retry.
50
+ export const runGit = (env = process.env) => async (args, extra = {}) => {
51
+ const res = await execGit(args, { ...gitEnv(env), ...extra }, env);
52
+ if (res.code === 0 || !tokenOf(env) || !AUTH.test(res.stderr))
53
+ return res;
54
+ return execGit(args, { ...gitEnv(withoutToken(env)), ...extra }, env);
55
+ };
56
+ const lastLine = (text) => text
57
+ .split(/\r?\n/)
58
+ .map((line) => line.trim())
59
+ .filter((line) => line !== '')
60
+ .slice(-1)[0] ?? 'git failed';
61
+ // git's failure as the cli's code: no access is market_auth, nothing written by the caller.
62
+ export const gitError = (repo, res) => {
63
+ const why = oneLine(lastLine(res.stderr), 400);
64
+ if (AUTH.test(res.stderr))
65
+ return new CliError('market_auth', `${repo}: no such repo, or no access to it (${why}); git's credentials or GH_TOKEN give access`);
66
+ if (NETWORK.test(res.stderr))
67
+ return new CliError('market_unreachable', `${repo}: cannot reach it (${why})`);
68
+ return new CliError('market_failed', `${repo}: ${why}`);
69
+ };
70
+ // The output of a git run that must succeed.
71
+ export const gitOk = async (git, repo, args, extra) => {
72
+ const res = await git(args, extra);
73
+ if (res.code !== 0)
74
+ throw gitError(repo, res);
75
+ return res.stdout;
76
+ };
@@ -0,0 +1,4 @@
1
+ export interface EscapingLink {
2
+ shown: string;
3
+ }
4
+ export declare const escapingLink: (root: string) => EscapingLink | null;
@@ -0,0 +1,35 @@
1
+ import { lstatSync, readdirSync, realpathSync } from 'node:fs';
2
+ import { isAbsolute, join, relative, sep } from 'node:path';
3
+ import { oneLine } from './repo-text.js';
4
+ const inside = (root, path) => {
5
+ const rel = relative(root, path);
6
+ return rel !== '..' && !rel.startsWith(`..${sep}`) && !isAbsolute(rel);
7
+ };
8
+ // The kernel's answer: Node's JS realpathSync folds `..` after a link as text.
9
+ const landsInside = (realRoot, path) => {
10
+ try {
11
+ return inside(realRoot, realpathSync.native(path));
12
+ }
13
+ catch {
14
+ return false;
15
+ }
16
+ };
17
+ const walk = (root, realRoot, dir) => {
18
+ for (const name of readdirSync(dir)) {
19
+ const path = join(dir, name);
20
+ const stat = lstatSync(path);
21
+ if (stat.isSymbolicLink() && !landsInside(realRoot, path))
22
+ return relative(root, path);
23
+ const deeper = stat.isDirectory() ? walk(root, realRoot, path) : null;
24
+ if (deeper !== null)
25
+ return deeper;
26
+ }
27
+ return null;
28
+ };
29
+ // The first symlink that resolves outside the folder, or not at all (dangling, a loop).
30
+ export const escapingLink = (root) => {
31
+ const path = walk(root, realpathSync.native(root), root);
32
+ if (path === null)
33
+ return null;
34
+ return { shown: oneLine(path, 400) || '(a name of control characters only)' };
35
+ };
@@ -0,0 +1,14 @@
1
+ export declare const MANIFEST_FILE = "agentage-market.json";
2
+ export declare const MARKET_NAME: RegExp;
3
+ export declare const SITE_MARKET = "agentage";
4
+ export interface MarketEntry {
5
+ id: string;
6
+ path: string;
7
+ description?: string;
8
+ }
9
+ export interface MarketManifest {
10
+ name: string;
11
+ extensions: MarketEntry[];
12
+ }
13
+ export declare const pathProblem: (path: string) => string | null;
14
+ export declare const parseManifest: (text: string) => MarketManifest;
@@ -0,0 +1,73 @@
1
+ import { kitIdProblem } from '../../core/kit-id.js';
2
+ import { isRecord } from '../fs/json-file.js';
3
+ import { CliError } from '../json-output.js';
4
+ import { oneLine } from './repo-text.js';
5
+ export const MANIFEST_FILE = 'agentage-market.json';
6
+ export const MARKET_NAME = /^[a-z][a-z0-9-]*$/;
7
+ // The site's own market: no repo may take its name.
8
+ export const SITE_MARKET = 'agentage';
9
+ const invalid = (field, why) => new CliError('invalid_manifest', `${MANIFEST_FILE}: ${field ? `${field} ` : ''}${why}`);
10
+ // `.` or a relative folder that never leaves the repo; git refuses a symlink in the way.
11
+ export const pathProblem = (path) => {
12
+ if (path === '.')
13
+ return null;
14
+ if (oneLine(path, Infinity) !== path)
15
+ return 'has a control character';
16
+ if (/^([/\\]|[A-Za-z]:)/.test(path))
17
+ return 'is an absolute path';
18
+ const parts = path.replace(/\/$/, '').split(/[/\\]/);
19
+ if (parts.includes('..'))
20
+ return 'leaves the repo';
21
+ if (parts.some((part) => part === '' || part === '.'))
22
+ return 'is not a plain folder path';
23
+ return null;
24
+ };
25
+ const nameOf = (doc) => {
26
+ const name = doc['name'];
27
+ if (typeof name !== 'string' || !MARKET_NAME.test(name))
28
+ throw invalid('name', 'must match ^[a-z][a-z0-9-]*$');
29
+ if (name === SITE_MARKET)
30
+ throw invalid('name', `${SITE_MARKET} is reserved for the site market`);
31
+ return name;
32
+ };
33
+ const entryOf = (raw, at) => {
34
+ const field = `extensions[${at}]`;
35
+ if (!isRecord(raw))
36
+ throw invalid(field, 'is not an object');
37
+ const { id, path, description } = raw;
38
+ if (typeof id !== 'string' || !MARKET_NAME.test(id) || kitIdProblem(id))
39
+ throw invalid(`${field}.id`, 'is not an extension id');
40
+ if (typeof path !== 'string')
41
+ throw invalid(`${field}.path`, 'is missing');
42
+ const problem = pathProblem(path);
43
+ if (problem)
44
+ throw invalid(`${field}.path`, problem);
45
+ if (description !== undefined && typeof description !== 'string')
46
+ throw invalid(`${field}.description`, 'is not text');
47
+ const text = description === undefined ? {} : { description: oneLine(description) };
48
+ return { id, path: path.replace(/\/$/, ''), ...text };
49
+ };
50
+ const entriesOf = (raw) => {
51
+ if (!Array.isArray(raw))
52
+ throw invalid('extensions', 'is not a list');
53
+ const entries = raw.map(entryOf);
54
+ const twice = entries.find((e, at) => entries.findIndex((o) => o.id === e.id) !== at);
55
+ if (twice)
56
+ throw invalid('extensions', `lists ${twice.id} twice`);
57
+ return entries;
58
+ };
59
+ // The manifest at the repo root; a bad one is refused naming the field.
60
+ export const parseManifest = (text) => {
61
+ let doc;
62
+ try {
63
+ doc = JSON.parse(text);
64
+ }
65
+ catch {
66
+ throw invalid('', 'is not JSON');
67
+ }
68
+ if (!isRecord(doc))
69
+ throw invalid('', 'is not an object');
70
+ if (doc['version'] !== 1)
71
+ throw invalid('version', 'must be 1');
72
+ return { name: nameOf(doc), extensions: entriesOf(doc['extensions']) };
73
+ };
@@ -0,0 +1,12 @@
1
+ export interface RepoMarket {
2
+ name: string;
3
+ repo: string;
4
+ added: string;
5
+ }
6
+ export declare const REPO: RegExp;
7
+ export declare const marketsPath: () => string;
8
+ export declare const readMarkets: () => RepoMarket[];
9
+ export declare const marketsToWrite: () => RepoMarket[];
10
+ export declare const writeMarkets: (markets: RepoMarket[]) => void;
11
+ export declare const withMarkets: <T>(fn: (markets: RepoMarket[]) => T) => Promise<T>;
12
+ export declare const marketNamed: (name: string) => RepoMarket | null;
@@ -0,0 +1,39 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { ensureConfigDir, getConfigDir } from '../fs/config.js';
4
+ import { withFileLock } from '../fs/file-lock.js';
5
+ import { isRecord, readJson, writeJsonAtomic } from '../fs/json-file.js';
6
+ import { CliError } from '../json-output.js';
7
+ import { MARKET_NAME } from './repo-manifest.js';
8
+ export const REPO = /^[A-Za-z0-9][A-Za-z0-9-]*\/[A-Za-z0-9_][A-Za-z0-9._-]*$/;
9
+ export const marketsPath = () => join(getConfigDir(), 'markets.json');
10
+ const isMarket = (value) => isRecord(value) &&
11
+ typeof value['name'] === 'string' &&
12
+ MARKET_NAME.test(value['name']) &&
13
+ typeof value['repo'] === 'string' &&
14
+ REPO.test(value['repo']) &&
15
+ typeof value['added'] === 'string';
16
+ // The valid rows of markets.json; a missing or broken file has none.
17
+ export const readMarkets = () => {
18
+ const doc = readJson(marketsPath(), isRecord);
19
+ return Array.isArray(doc?.['markets']) ? doc['markets'].filter(isMarket) : [];
20
+ };
21
+ // Every row for a rewrite: a row the reader would drop is someone's edit, never written away.
22
+ export const marketsToWrite = () => {
23
+ if (!existsSync(marketsPath()))
24
+ return [];
25
+ const rows = readJson(marketsPath(), isRecord)?.['markets'];
26
+ if (Array.isArray(rows) && rows.every(isMarket))
27
+ return rows;
28
+ throw new CliError('market_failed', `${marketsPath()} holds rows this cli cannot read; fix or remove them (nothing changed)`);
29
+ };
30
+ export const writeMarkets = (markets) => {
31
+ ensureConfigDir();
32
+ writeJsonAtomic(marketsPath(), { version: 1, markets });
33
+ };
34
+ // A read-modify-write of markets.json: under its lock, from the file as it is now.
35
+ export const withMarkets = (fn) => {
36
+ ensureConfigDir();
37
+ return withFileLock(marketsPath(), () => fn(marketsToWrite()));
38
+ };
39
+ export const marketNamed = (name) => readMarkets().find((m) => m.name === name) ?? null;
@@ -0,0 +1,15 @@
1
+ import { type RepoOffer } from './repo-entries.js';
2
+ import { type Git } from './repo-git.js';
3
+ import { type RepoMarket } from './repo-markets-file.js';
4
+ export interface RepoDeps {
5
+ git: Git;
6
+ markets: () => RepoMarket[];
7
+ }
8
+ export interface Qualified {
9
+ market: string;
10
+ name: string;
11
+ }
12
+ export declare const qualifiedOf: (name: string) => Qualified | null;
13
+ export declare const marketOffers: (deps: RepoDeps, market: RepoMarket) => Promise<RepoOffer[]>;
14
+ export declare const resolveQualified: (deps: RepoDeps, market: string, id: string) => Promise<string | null>;
15
+ export declare const resolveBare: (deps: RepoDeps, id: string, siteKnows: () => Promise<boolean>) => Promise<string | null>;
@@ -0,0 +1,55 @@
1
+ import { CliError } from '../json-output.js';
2
+ import { commitOf, CURRENT, syncRepo } from './repo-cache.js';
3
+ import { offersAt } from './repo-entries.js';
4
+ import {} from './repo-git.js';
5
+ import { MARKET_NAME, SITE_MARKET } from './repo-manifest.js';
6
+ import {} from './repo-markets-file.js';
7
+ // `acme/hello`: the market, then the rest (`hello`, `hello@1.0.0`); anything else is not one.
8
+ export const qualifiedOf = (name) => {
9
+ const at = name.indexOf('/');
10
+ const market = name.slice(0, at);
11
+ return at > 0 && MARKET_NAME.test(market) ? { market, name: name.slice(at + 1) } : null;
12
+ };
13
+ // Each entry of a market at its newest ref, fetched now.
14
+ export const marketOffers = async (deps, market) => {
15
+ const { commit } = await syncRepo(deps.git, market.repo);
16
+ return offersAt(deps.git, { name: market.name, repo: market.repo, commit });
17
+ };
18
+ // A market that cannot be fetched now answers from its last fetch, so it blocks no other install.
19
+ const lastOffers = async (deps, market) => {
20
+ const commit = await commitOf(deps.git, market.repo, CURRENT);
21
+ if (!commit)
22
+ return [];
23
+ return offersAt(deps.git, { name: market.name, repo: market.repo, commit }).catch(() => []);
24
+ };
25
+ const installable = (offer) => {
26
+ if (offer.problem || !offer.version)
27
+ throw new CliError('invalid_argument', `${offer.market}/${offer.id}: invalid entry (${offer.problem ?? 'no version'}); nothing installed`);
28
+ return offer.version;
29
+ };
30
+ const noMarket = (name) => new CliError('invalid_argument', `no market ${name} on this machine: agentage extension market add <owner/repo>`);
31
+ // The exact version to send for `<market>/<id>` (the site market's name is never a repo).
32
+ export const resolveQualified = async (deps, market, id) => {
33
+ if (market === SITE_MARKET)
34
+ return null;
35
+ const found = deps.markets().find((m) => m.name === market);
36
+ if (!found)
37
+ throw noMarket(market);
38
+ const offer = (await marketOffers(deps, found)).find((o) => o.id === id);
39
+ if (!offer)
40
+ throw new CliError('invalid_argument', `the market ${market} has no ${id}`);
41
+ return installable(offer);
42
+ };
43
+ // A bare id the site market does not know: the one repo market that lists it, else none.
44
+ export const resolveBare = async (deps, id, siteKnows) => {
45
+ const markets = deps.markets();
46
+ if (markets.length === 0 || (await siteKnows()))
47
+ return null;
48
+ const offers = await Promise.all(markets.map((m) => marketOffers(deps, m).catch(() => lastOffers(deps, m))));
49
+ const hits = offers.flat().filter((o) => o.id === id);
50
+ if (hits.length > 1) {
51
+ const named = hits.map((o) => `${o.market}/${id}`).join(', ');
52
+ throw new CliError('invalid_argument', `${id} is in more than one market: install ${named}`);
53
+ }
54
+ return hits[0] ? installable(hits[0]) : null;
55
+ };
@@ -0,0 +1,2 @@
1
+ export declare const oneLine: (text: string, max?: number) => string;
2
+ export declare const printable: (text: string) => string;
@@ -0,0 +1,7 @@
1
+ // C0 and C1 controls (ESC among them) and the bidi overrides: a repo never steers the terminal.
2
+ const CONTROL = /[\u0000-\u001f\u007f-\u009f‪-‮⁦-⁩]/g;
3
+ const CONTROL_BUT_NEWLINE = /[\u0000-\u0009\u000b-\u001f\u007f-\u009f‪-‮⁦-⁩]/g;
4
+ // Repo text for one line of the terminal: printable, at most `max` characters.
5
+ export const oneLine = (text, max = 200) => text.replace(CONTROL, '').slice(0, max);
6
+ // Repo or build output of several lines: printable, its line breaks kept.
7
+ export const printable = (text) => text.replace(CONTROL_BUT_NEWLINE, '');
@@ -0,0 +1,13 @@
1
+ export interface RepoRef {
2
+ ref: string;
3
+ sha: string;
4
+ }
5
+ export interface RepoVersion {
6
+ version: string;
7
+ market: string;
8
+ commit: string;
9
+ }
10
+ export declare const PLAIN_VERSION: RegExp;
11
+ export declare const newestRef: (lsRemote: string) => RepoRef | null;
12
+ export declare const repoVersion: (version: string, market: string, commit: string) => string;
13
+ export declare const parseRepoVersion: (text: string) => RepoVersion | null;
@@ -0,0 +1,35 @@
1
+ import { newestFirst, parseVersion } from '../../core/semver-range.js';
2
+ const TAG = /^refs\/tags\/(v\d+\.\d+\.\d+)(\^\{\})?$/;
3
+ // A package version with no build part: the build part carries the market and the commit.
4
+ export const PLAIN_VERSION = /^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/;
5
+ const REPO_VERSION = /^(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)\+([a-z][a-z0-9-]*)\.([0-9a-f]{40})$/;
6
+ const linesOf = (lsRemote) => lsRemote
7
+ .split(/\r?\n/)
8
+ .map((line) => line.split('\t'))
9
+ .flatMap(([sha, ref]) => (sha && ref && /^[0-9a-f]{40}$/.test(sha) ? [[sha, ref]] : []));
10
+ // Each release tag with its commit: an annotated tag's peeled line (`^{}`) wins.
11
+ const tagsOf = (lines) => {
12
+ const tags = new Map();
13
+ for (const [sha, ref] of lines) {
14
+ const m = TAG.exec(ref);
15
+ if (m?.[1] && (m[2] || !tags.has(m[1])))
16
+ tags.set(m[1], sha);
17
+ }
18
+ return tags;
19
+ };
20
+ // The newest release tag `v<major>.<minor>.<patch>`, else HEAD; null when the repo has neither.
21
+ export const newestRef = (lsRemote) => {
22
+ const lines = linesOf(lsRemote);
23
+ const tags = tagsOf(lines);
24
+ const [tag] = [...tags.keys()].filter((t) => parseVersion(t)).sort(newestFirst);
25
+ if (tag)
26
+ return { ref: `refs/tags/${tag}`, sha: tags.get(tag) ?? '' };
27
+ const head = lines.find(([, ref]) => ref === 'HEAD');
28
+ return head ? { ref: 'HEAD', sha: head[0] } : null;
29
+ };
30
+ // The version a row is installed under: the package version, the market and the commit.
31
+ export const repoVersion = (version, market, commit) => `${version}+${market}.${commit}`;
32
+ export const parseRepoVersion = (text) => {
33
+ const m = REPO_VERSION.exec(text);
34
+ return m?.[1] && m[2] && m[3] ? { version: m[1], market: m[2], commit: m[3] } : null;
35
+ };
@@ -6,6 +6,7 @@ export interface NpmResult {
6
6
  export interface RunNpmOptions {
7
7
  cwd?: string;
8
8
  env?: NodeJS.ProcessEnv;
9
+ baseEnv?: NodeJS.ProcessEnv;
9
10
  timeoutMs: number;
10
11
  npmCli?: string;
11
12
  }
@@ -58,7 +58,7 @@ export const runNpm = (args, opts) => new Promise((resolve) => {
58
58
  const argv = [opts.npmCli ?? resolveNpmCli(), ...args, '--no-audit', '--no-fund'];
59
59
  const options = {
60
60
  cwd: opts.cwd,
61
- env: scrubNpmEnv(process.env, opts.env),
61
+ env: scrubNpmEnv(opts.baseEnv ?? process.env, opts.env),
62
62
  timeout: opts.timeoutMs,
63
63
  maxBuffer: MAX_BUFFER,
64
64
  windowsHide: true,
@@ -1,6 +1,9 @@
1
1
  import { runAuthToken } from './commands/auth/token.js';
2
2
  import {} from './commands/auth/setup.js';
3
3
  import { runDaemonRestart, runDaemonStatus, runDaemonStop } from './commands/daemon/daemon.js';
4
+ import { runConfigGet } from './commands/config/config-get.js';
5
+ import { runConfigList } from './commands/config/config-list.js';
6
+ import { runConfigSet, runConfigUnset } from './commands/config/config-set.js';
4
7
  import { runDaemonStart } from './commands/daemon/start.js';
5
8
  import { cliInstaller, npmNewest } from './commands/daemon/installer.js';
6
9
  import { moveBeforeStart } from './commands/daemon/move.js';
@@ -13,7 +16,9 @@ import { readHidden, runConfigure, stdinInput } from './commands/extension/confi
13
16
  import { runEnabled, runInstall, runRemove, terminalIo } from './commands/extension/lifecycle.js';
14
17
  import { runList, runUpdate as runExtensionUpdate } from './commands/extension/lifecycle-list.js';
15
18
  import { loadKitTool } from './commands/extension/kit-tool.js';
19
+ import { runMarketAdd, runMarketList, runMarketRemove } from './commands/extension/market.js';
16
20
  import { runRelease } from './commands/extension/release.js';
21
+ import { runExtensionTypes } from './commands/extension/types.js';
17
22
  import { runExtensionSetup } from './commands/extension/setup.js';
18
23
  import { runExtensionDown, runExtensionToken, runExtensionUp } from './commands/extension/up.js';
19
24
  import { runStatus, statusDeps } from './commands/status/status.js';
@@ -24,6 +29,9 @@ import { ensureDaemon } from './lib/daemon/daemon-client.js';
24
29
  import { sealOffLine } from './lib/daemon/daemon-health.js';
25
30
  import { hostClient } from './lib/daemon/host-client.js';
26
31
  import { listMarket, openMarket } from './lib/net/market.js';
32
+ import { npmStep } from './lib/market/repo-build.js';
33
+ import { runGit } from './lib/market/repo-git.js';
34
+ import { readMarkets } from './lib/market/repo-markets-file.js';
27
35
  import { noSiteMarket, npmFallbackLine } from './lib/net/market-error.js';
28
36
  import { siteFqdn } from './lib/net/origins.js';
29
37
  import { refreshUpdateCache, updateHint } from './lib/update/update-cache.js';
@@ -40,14 +48,29 @@ const installer = () => cliInstaller({
40
48
  npm: () => prepareNpm(),
41
49
  manifest: () => prepareManifest(),
42
50
  market: () => openMarket(),
51
+ repo: { git: runGit(), step: npmStep() },
43
52
  });
53
+ // This machine's repo markets: git with the user's own credentials, markets.json.
54
+ const repo = { git: runGit(), markets: () => readMarkets() };
55
+ // The site market lists the id; an outage is its error, as an install without repo markets has it.
56
+ const siteKnows = async (id) => {
57
+ const market = openMarket();
58
+ if (await market.latest(id))
59
+ return true;
60
+ const down = market.down();
61
+ if (down && !noSiteMarket(down))
62
+ throw down;
63
+ return false;
64
+ };
44
65
  // The daemon is started on request by every lifecycle command.
45
66
  const lifecycle = { host: async () => hostClient(await ensureDaemon()) };
67
+ const configDeps = () => ({ ...lifecycle, input: stdinInput(readHidden) });
46
68
  const listDeps = {
47
69
  ...lifecycle,
48
70
  available: () => listMarket(),
49
71
  market: () => openMarket(),
50
72
  npmNewest: npmNewest(() => prepareManifest()),
73
+ repo,
51
74
  };
52
75
  // After a bare-id install: the line when npm resolved it (no market, or one without the id).
53
76
  const fromNpm = async (id, what) => {
@@ -72,7 +95,7 @@ export const defaultDeps = {
72
95
  status: (opts) => runStatus(opts),
73
96
  update: (opts) => runUpdate(opts),
74
97
  authToken: (opts) => runAuthToken(opts),
75
- extensionInstall: (opts) => runInstall(opts, { ...lifecycle, fromNpm, hasMarket, sealOff }),
98
+ extensionInstall: (opts) => runInstall(opts, { ...lifecycle, fromNpm, hasMarket, sealOff, repo: { repo, siteKnows } }),
76
99
  extensionRemove: (opts) => runRemove(opts, { ...lifecycle, io: terminalIo() }),
77
100
  extensionList: (opts) => runList(opts, listDeps),
78
101
  extensionUpdate: (opts) => runExtensionUpdate(opts, listDeps),
@@ -86,6 +109,12 @@ export const defaultDeps = {
86
109
  extensionUp: (opts) => runExtensionUp(opts),
87
110
  extensionDown: (opts) => runExtensionDown(opts),
88
111
  extensionToken: (opts) => runExtensionToken(opts),
112
+ extensionTypes: (opts) => runExtensionTypes(opts),
113
+ market: {
114
+ add: (opts) => runMarketAdd(opts, repo),
115
+ list: (opts) => runMarketList(opts, repo),
116
+ remove: (opts) => runMarketRemove(opts),
117
+ },
89
118
  daemon: {
90
119
  start: () => runDaemonStart(),
91
120
  status: () => runDaemonStatus(),
@@ -93,6 +122,12 @@ export const defaultDeps = {
93
122
  restart: () => runDaemonRestart(),
94
123
  run: () => runDaemon({ installer, before: () => moveBeforeStart() }),
95
124
  },
125
+ config: {
126
+ list: (opts) => runConfigList(opts, configDeps()),
127
+ get: (opts) => runConfigGet(opts, configDeps()),
128
+ set: (opts) => runConfigSet(opts, configDeps()),
129
+ unset: (opts) => runConfigUnset(opts, configDeps()),
130
+ },
96
131
  kitTool: loadKitTool,
97
132
  updateHint,
98
133
  refreshUpdateCache: () => refreshUpdateCache(),
package/dist/program.d.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  import { Command } from 'commander';
2
2
  import { type SetupOptions } from './commands/auth/setup.js';
3
3
  import { type AuthTokenOptions } from './commands/auth/token.js';
4
+ import { type ConfigGetOptions } from './commands/config/config-get.js';
5
+ import { type ConfigListOptions } from './commands/config/config-list.js';
6
+ import { type ConfigSetOptions, type ConfigUnsetOptions } from './commands/config/config-set.js';
4
7
  import { type DaemonOptions } from './commands/daemon/daemon.js';
5
8
  import { type ExtensionBuildOptions, type ExtensionCheckOptions } from './commands/extension/build.js';
6
9
  import { type ExtensionCreateOptions } from './commands/extension/create.js';
@@ -8,8 +11,10 @@ import { type ExtensionDoctorOptions } from './commands/extension/doctor.js';
8
11
  import { type ConfigureOptions } from './commands/extension/configure.js';
9
12
  import { type InstallOptions, type RemoveOptions } from './commands/extension/lifecycle.js';
10
13
  import { type ExtensionUpdateOptions, type ListOptions } from './commands/extension/lifecycle-list.js';
14
+ import { type MarketRuns } from './commands/extension/market.js';
11
15
  import { type LoadKitTool } from './commands/extension/kit-tool.js';
12
16
  import { type ExtensionReleaseOptions } from './commands/extension/release.js';
17
+ import { type ExtensionTypesOptions } from './commands/extension/types.js';
13
18
  import { type ExtensionDownOptions, type ExtensionTokenOptions, type ExtensionUpFlags } from './commands/extension/up.js';
14
19
  import { type StatusOptions } from './commands/status/status.js';
15
20
  import { type UpdateOptions } from './commands/update/update.js';
@@ -37,7 +42,15 @@ export interface ProgramDeps {
37
42
  extensionUp: Run<ExtensionUpFlags>;
38
43
  extensionDown: Run<ExtensionDownOptions>;
39
44
  extensionToken: Run<ExtensionTokenOptions>;
45
+ extensionTypes: Run<ExtensionTypesOptions>;
46
+ market: MarketRuns;
40
47
  daemon: Record<'start' | 'status' | 'stop' | 'restart' | 'run', Run<DaemonOptions>>;
48
+ config: {
49
+ list: Run<ConfigListOptions>;
50
+ get: Run<ConfigGetOptions>;
51
+ set: Run<ConfigSetOptions>;
52
+ unset: Run<ConfigUnsetOptions>;
53
+ };
41
54
  kitTool: LoadKitTool;
42
55
  updateHint: () => string | null;
43
56
  refreshUpdateCache: () => Promise<void>;
package/dist/program.js CHANGED
@@ -2,6 +2,10 @@ import chalk from 'chalk';
2
2
  import { Command, CommanderError } from 'commander';
3
3
  import { registerSetup } from './commands/auth/setup.js';
4
4
  import { registerAuth } from './commands/auth/token.js';
5
+ import { registerConfig } from './commands/config/config.js';
6
+ import {} from './commands/config/config-get.js';
7
+ import {} from './commands/config/config-list.js';
8
+ import {} from './commands/config/config-set.js';
5
9
  import { registerDaemon } from './commands/daemon/daemon.js';
6
10
  import {} from './commands/extension/build.js';
7
11
  import {} from './commands/extension/create.js';
@@ -11,9 +15,11 @@ import {} from './commands/extension/configure.js';
11
15
  import {} from './commands/extension/lifecycle.js';
12
16
  import {} from './commands/extension/lifecycle-list.js';
13
17
  import { registerExtension } from './commands/extension/list.js';
18
+ import {} from './commands/extension/market.js';
14
19
  import { KIT_EXIT } from './commands/extension/kit-commands.js';
15
20
  import {} from './commands/extension/kit-tool.js';
16
21
  import {} from './commands/extension/release.js';
22
+ import {} from './commands/extension/types.js';
17
23
  import {} from './commands/extension/up.js';
18
24
  import { registerStatus } from './commands/status/status.js';
19
25
  import { registerUpdate } from './commands/update/update.js';
@@ -48,6 +54,12 @@ const addExtensions = (program, deps, argv) => {
48
54
  up: withAction(deps, deps.extensionUp),
49
55
  down: withAction(deps, deps.extensionDown),
50
56
  token: withAction(deps, deps.extensionToken),
57
+ types: withAction(deps, deps.extensionTypes),
58
+ market: {
59
+ add: withAction(deps, deps.market.add),
60
+ list: withAction(deps, deps.market.list),
61
+ remove: withAction(deps, deps.market.remove),
62
+ },
51
63
  });
52
64
  try {
53
65
  registerDelegates(program, argv, (fn) => withAction(deps, fn), deps.kitTool);
@@ -78,6 +90,12 @@ export const createProgram = (deps = defaultDeps, argv = process.argv) => {
78
90
  restart: daemon(deps.daemon.restart),
79
91
  run: daemon(deps.daemon.run),
80
92
  });
93
+ registerConfig(program, {
94
+ list: withAction(deps, deps.config.list),
95
+ get: withAction(deps, deps.config.get),
96
+ set: withAction(deps, deps.config.set),
97
+ unset: withAction(deps, deps.config.unset),
98
+ });
81
99
  addExtensions(program, deps, argv);
82
100
  return program;
83
101
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentage/cli",
3
- "version": "0.78.2",
3
+ "version": "0.80.0",
4
4
  "description": "The agentage CLI - connect this machine to agentage from the terminal",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -54,8 +54,8 @@
54
54
  "prepublishOnly": "npm run verify"
55
55
  },
56
56
  "dependencies": {
57
- "@agentage/apphost": "0.8.4",
58
- "@agentage/extension": "0.25.6",
57
+ "@agentage/apphost": "0.8.5",
58
+ "@agentage/extension": "0.25.7",
59
59
  "@electric-sql/pglite": "^0.6.0",
60
60
  "@tailwindcss/postcss": "^4.3.5",
61
61
  "chalk": "^6.0.0",