@agentage/cli 0.50.4 → 0.51.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.
@@ -1,4 +1,5 @@
1
1
  import { type NpmManifest } from '../../core/installer/npm.js';
2
+ import { type Market } from '../../lib/net/market.js';
2
3
  import { type EditDeps } from './sync.js';
3
4
  export interface ExtensionInstallOptions {
4
5
  name: string;
@@ -6,5 +7,6 @@ export interface ExtensionInstallOptions {
6
7
  }
7
8
  export interface ExtensionInstallDeps extends EditDeps {
8
9
  manifest: () => Promise<NpmManifest>;
10
+ market?: Market;
9
11
  }
10
12
  export declare const runExtensionInstall: (opts: ExtensionInstallOptions, deps: ExtensionInstallDeps) => Promise<void>;
@@ -4,6 +4,7 @@ import { registryLookup, resolveName } from '../../core/installer/resolve.js';
4
4
  import { addExtension } from '../../core/profile/edit.js';
5
5
  import { loadMachine, setDev } from '../../core/profile/machine.js';
6
6
  import { editableProfile } from '../../core/profile/profile.js';
7
+ import {} from '../../lib/net/market.js';
7
8
  import {} from '../../core/profile/schema.js';
8
9
  import { installAndLoad, line } from './install-load.js';
9
10
  import { finishEdit, pullForEdit } from './sync.js';
@@ -27,10 +28,20 @@ const addDev = async (target, off, deps) => {
27
28
  console.log(line('dev', `${target.name} ${target.path}`));
28
29
  await installAndLoad(editableProfile(), deps.npm);
29
30
  };
31
+ const ID = /^[a-z][a-z0-9-]*$/;
32
+ // A bare id takes the version the market's /latest names; a private entry has no npm package.
33
+ const marketName = async (name, market) => {
34
+ const latest = ID.test(name) ? await market?.latest(name) : null;
35
+ if (!latest)
36
+ return name;
37
+ if (latest.package === null)
38
+ throw new Error(`${name}: private entry, no npm package; it cannot be installed from npm`);
39
+ return `${latest.package}@${latest.version}`;
40
+ };
30
41
  // Never signs in: the name is looked up in the registries the local profile routes.
31
42
  export const runExtensionInstall = async (opts, deps) => {
32
43
  const { registries } = editableProfile();
33
- const target = await resolveName(opts.name, registryLookup(deps.manifest, registries));
44
+ const target = await resolveName(await marketName(opts.name, deps.market), registryLookup(deps.manifest, registries));
34
45
  if (target.kind === 'dev')
35
46
  await addDev(target, opts.off === true, deps);
36
47
  else
@@ -5,13 +5,15 @@ import { type ExtensionCreateOptions } from './create.js';
5
5
  import { type ExtensionDoctorOptions } from './doctor.js';
6
6
  import { type ExtensionInstallOptions } from './install.js';
7
7
  import { type ExtensionRemoveOptions } from './remove.js';
8
+ import { type Latest } from './row-lines.js';
9
+ import { type Market } from '../../lib/net/market.js';
8
10
  import { type ExtensionsGather } from './rows.js';
9
11
  import { type KitActions } from './up.js';
10
12
  export interface ExtensionListOptions {
11
13
  json?: boolean;
12
14
  }
13
- export declare const printReport: ({ status, warnings }: ExtensionsGather, json?: boolean) => void;
14
- export declare const runExtensionList: (opts?: ExtensionListOptions) => Promise<void>;
15
+ export declare const printReport: ({ status, warnings }: ExtensionsGather, json?: boolean, latest?: Latest) => void;
16
+ export declare const runExtensionList: (opts?: ExtensionListOptions, market?: Market) => Promise<void>;
15
17
  export declare const helpOrUnknown: (_opts: unknown, group: Command) => void;
16
18
  export interface ExtensionActions extends KitActions, BuildActions {
17
19
  install: (opts: ExtensionInstallOptions) => Promise<void>;
@@ -6,22 +6,46 @@ import {} from './doctor.js';
6
6
  import {} from './install.js';
7
7
  import {} from './remove.js';
8
8
  import { printWarnings, rowLines } from './row-lines.js';
9
+ import {} from '../../lib/net/market.js';
9
10
  import { gatherExtensions, invalidProfileError } from './rows.js';
10
11
  import { addKitTools } from './up.js';
12
+ const withLatest = (status, latest) => ({
13
+ ...status,
14
+ extensions: status.extensions.map((row) => ({
15
+ ...row,
16
+ latest: latest.get(row.id ?? '') ?? null,
17
+ })),
18
+ });
11
19
  // The rows, or the whole report as JSON, on stdout; warnings on stderr.
12
- export const printReport = ({ status, warnings }, json) => {
13
- const rows = status.extensions.length > 0 ? rowLines(status.extensions) : ['no extensions'];
20
+ export const printReport = ({ status, warnings }, json, latest) => {
21
+ const rows = status.extensions.length > 0 ? rowLines(status.extensions, latest) : ['no extensions'];
14
22
  if (json)
15
- console.log(JSON.stringify(status, null, 2));
23
+ console.log(JSON.stringify(latest ? withLatest(status, latest) : status, null, 2));
16
24
  else
17
25
  for (const text of rows)
18
26
  console.log(text);
19
27
  printWarnings(warnings);
20
28
  };
29
+ // A refused answer costs only its own row: one stderr line, no version.
30
+ const versionOf = async (market, id) => {
31
+ try {
32
+ return (await market.latest(id))?.version ?? null;
33
+ }
34
+ catch (err) {
35
+ console.error(err.message);
36
+ return null;
37
+ }
38
+ };
39
+ // The market's newest version for each installed id it knows; unknown or refused ids are null.
40
+ const newest = async ({ status }, market) => {
41
+ const ids = status.extensions.flatMap((row) => (row.id === null ? [] : [row.id]));
42
+ const found = await Promise.all(ids.map(async (id) => [id, await versionOf(market, id)]));
43
+ return market.down() ? undefined : new Map(found);
44
+ };
21
45
  // The rows always print; an invalid profile.json then fails the step (exit 1).
22
- export const runExtensionList = async (opts = {}) => {
46
+ export const runExtensionList = async (opts = {}, market) => {
23
47
  const gathered = await gatherExtensions();
24
- printReport(gathered, opts.json);
48
+ printReport(gathered, opts.json, market && (await newest(gathered, market)));
25
49
  const failure = invalidProfileError(gathered.status.profile);
26
50
  if (failure)
27
51
  throw failure;
@@ -1,4 +1,5 @@
1
1
  import { type ExtensionRow, type ExtensionsStatus } from './rows.js';
2
2
  export declare const summaryLines: (status: ExtensionsStatus) => string[];
3
- export declare const rowLines: (rows: ExtensionRow[]) => string[];
3
+ export type Latest = ReadonlyMap<string, string | null>;
4
+ export declare const rowLines: (rows: ExtensionRow[], latest?: Latest) => string[];
4
5
  export declare const printWarnings: (warnings: string[]) => void;
@@ -46,21 +46,22 @@ const wantedText = (row) => {
46
46
  return 'dev';
47
47
  return row.wanted === null ? 'not in profile' : `wants ${row.wanted}`;
48
48
  };
49
- const rowLine = (row, widths) => {
49
+ const rowLine = (row, widths, latest) => {
50
50
  const id = (row.id ?? '?').padEnd(widths.id);
51
51
  const state = COLOR[row.state](row.state.padEnd(STATE_WIDTH));
52
52
  const drift = widths.drift === 0 ? '' : `${driftOf(row).padEnd(widths.drift)} `;
53
53
  const pkg = `${row.package} ${row.installed ?? '-'} (${wantedText(row)})`;
54
+ const newest = latest ? ` latest ${latest.get(row.id ?? '') ?? '-'}` : '';
54
55
  const commands = row.commands.length > 0 ? ` commands: ${row.commands.join(', ')}` : '';
55
56
  // A failed load quotes the extension's own message; the core's reasons print as they are.
56
57
  const reason = row.state === 'failed' ? `"${row.error}"` : row.error;
57
58
  const error = row.error === null ? '' : chalk.dim(` ${reason}`);
58
- return `${id} ${state} ${drift}${pkg}${commands}${lastRunText(row.lastRun)}${error}`;
59
+ return `${id} ${state} ${drift}${pkg}${newest}${commands}${lastRunText(row.lastRun)}${error}`;
59
60
  };
60
- export const rowLines = (rows) => {
61
+ export const rowLines = (rows, latest) => {
61
62
  const id = Math.max(0, ...rows.map((row) => (row.id ?? '?').length));
62
63
  const drift = Math.max(0, ...rows.map((row) => driftOf(row).length));
63
- return rows.map((row) => rowLine(row, { id, drift }));
64
+ return rows.map((row) => rowLine(row, { id, drift }, latest));
64
65
  };
65
66
  export const printWarnings = (warnings) => {
66
67
  for (const warning of warnings)
@@ -1,7 +1,7 @@
1
1
  import chalk from 'chalk';
2
2
  import {} from 'commander';
3
3
  import { resolveAuth } from '../../lib/auth/credentials.js';
4
- import { siteFqdn } from '../../lib/net/origins.js';
4
+ import { DEFAULT_FQDN, siteFqdn } from '../../lib/net/origins.js';
5
5
  import { gatherStatus } from '../../lib/status/status-info.js';
6
6
  import { INSTALL_HINT } from '../../lib/update/update-check.js';
7
7
  import { signedInAccount } from '../extension/account.js';
@@ -44,7 +44,9 @@ export const printStatus = (report) => {
44
44
  row('update', updateLine(report.update));
45
45
  const t = report.target;
46
46
  const targetSuffix = t.reachable ? '' : ' - unreachable';
47
- row('target', `${mark(t.reachable)} ${t.fqdn} (${t.env})${targetSuffix}`);
47
+ // "production" is the default site only: any other production-shaped fqdn came from the override.
48
+ const source = t.env === 'production' && t.fqdn !== DEFAULT_FQDN ? 'from AGENTAGE_SITE_FQDN' : t.env;
49
+ row('target', `${mark(t.reachable)} ${t.fqdn} (${source})${targetSuffix}`);
48
50
  row('auth', authLine(report.auth));
49
51
  row('endpoint', `${mark(report.endpoint.reachable)} ${report.endpoint.url} ` +
50
52
  (report.endpoint.reachable ? 'reachable' : 'unreachable'));
@@ -74,10 +74,12 @@ const tokenFor = async (auth, links, renew, opts) => {
74
74
  // A discovered platform takes only a JWT PAT the session mints; an env PAT goes as is.
75
75
  export const platformFetch = async (auth, links, found, path, init, opts) => {
76
76
  const url = `${found.platform.machines}${path}`;
77
- if (!found.discovered || auth.kind === 'pat')
77
+ if (!found.discovered)
78
78
  return authedFetch(auth, links, url, init, opts);
79
79
  if (found.links.auth !== links.auth)
80
80
  throw refuse(links.auth, `platform token: the site's issuer is ${found.links.auth}`);
81
+ if (auth.kind === 'pat')
82
+ return authedFetch(auth, links, url, init, opts);
81
83
  const prior = refused.get(links.auth);
82
84
  if (prior)
83
85
  throw prior;
@@ -0,0 +1,11 @@
1
+ type Get = (url: string) => Promise<Response>;
2
+ export interface Latest {
3
+ version: string;
4
+ package: string | null;
5
+ }
6
+ export interface Market {
7
+ latest: (id: string) => Promise<Latest | null>;
8
+ down: () => boolean;
9
+ }
10
+ export declare const openMarket: (fqdn?: string, get?: Get) => Market;
11
+ export {};
@@ -0,0 +1,56 @@
1
+ import { isRecord } from '../fs/json-file.js';
2
+ import { cliFetch } from './fetch.js';
3
+ import { links, siteFqdn } from './origins.js';
4
+ const TIMEOUT_MS = 5_000;
5
+ const UNAVAILABLE = 'market unavailable, versions not checked';
6
+ const EXACT = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$/;
7
+ const timed = (url) => cliFetch(url, {}, { timeoutMs: TIMEOUT_MS });
8
+ const json = async (get, url) => {
9
+ const res = await get(url);
10
+ if (res.status === 404)
11
+ return null;
12
+ if (!res.ok)
13
+ throw new Error(`${url} answered ${res.status}`);
14
+ const body = await res.json();
15
+ return isRecord(body) ? body : null;
16
+ };
17
+ // The first market the site's discovery document names: https, or http when the site is local.
18
+ const marketUrl = async (fqdn, get) => {
19
+ const { site } = links(fqdn);
20
+ const doc = await json(get, `${site}/.well-known/agentage.json`);
21
+ const first = Array.isArray(doc?.['markets']) ? doc['markets'][0] : undefined;
22
+ const url = new URL(String(first));
23
+ if (url.protocol !== 'https:' && !(url.protocol === 'http:' && site.startsWith('http:')))
24
+ throw new Error('no market');
25
+ return url.origin;
26
+ };
27
+ // An answer is trusted only when it names this id's own package and one exact version.
28
+ const accept = (id, { version, package: pkg }) => {
29
+ const refuse = (why) => new Error(`market answer refused for ${id}: ${why}`);
30
+ if (typeof version !== 'string' || !EXACT.test(version))
31
+ throw refuse(`version ${JSON.stringify(version)} is not an exact version`);
32
+ if (pkg !== null && pkg !== `@agentage/extension-${id}` && pkg !== `agentage-extension-${id}`)
33
+ throw refuse(`package ${JSON.stringify(pkg)} is not an extension of that id`);
34
+ return { version, package: pkg };
35
+ };
36
+ // Never throws: a missing or silent market prints one line on stderr and answers null.
37
+ export const openMarket = (fqdn = siteFqdn(), get = timed) => {
38
+ let base;
39
+ let told = false;
40
+ const latest = async (id) => {
41
+ let data;
42
+ try {
43
+ base ??= marketUrl(fqdn, get);
44
+ const path = `/api/v1/extensions/${encodeURIComponent(id)}/latest`;
45
+ data = (await json(get, `${await base}${path}`))?.['data'];
46
+ }
47
+ catch {
48
+ if (!told)
49
+ console.error(UNAVAILABLE);
50
+ told = true;
51
+ return null;
52
+ }
53
+ return isRecord(data) ? accept(id, data) : null;
54
+ };
55
+ return { latest, down: () => told };
56
+ };
@@ -4,6 +4,7 @@ export interface Links {
4
4
  api: string;
5
5
  auth: string;
6
6
  }
7
+ export declare const DEFAULT_FQDN = "agentage.io";
7
8
  export declare const normalizeFqdn: (raw?: string) => string;
8
9
  export declare const siteFqdn: () => string;
9
10
  export declare const environment: (fqdn: string) => Env;
@@ -1,4 +1,4 @@
1
- const DEFAULT_FQDN = 'agentage.io';
1
+ export const DEFAULT_FQDN = 'agentage.io';
2
2
  export const normalizeFqdn = (raw) => {
3
3
  const value = (raw ?? '')
4
4
  .trim()
package/dist/program.js CHANGED
@@ -5,6 +5,7 @@ import { runExtensionBuild, runExtensionCheck, } from './commands/extension/buil
5
5
  import { runExtensionCreate } from './commands/extension/create.js';
6
6
  import { registerDelegates } from './commands/extension/delegate.js';
7
7
  import { runExtensionDoctor } from './commands/extension/doctor.js';
8
+ import { openMarket } from './lib/net/market.js';
8
9
  import { runExtensionInstall } from './commands/extension/install.js';
9
10
  import { registerExtension, runExtensionList, } from './commands/extension/list.js';
10
11
  import { runExtensionRemove, terminalIo, } from './commands/extension/remove.js';
@@ -31,9 +32,13 @@ const defaultDeps = {
31
32
  setup: (opts) => runExtensionSetup(opts, { ...setupDeps, ...editDeps }),
32
33
  status: (opts) => runStatus(opts),
33
34
  update: (opts) => runUpdate(opts),
34
- extensionInstall: (opts) => runExtensionInstall(opts, { ...editDeps, manifest: () => prepareManifest() }),
35
+ extensionInstall: (opts) => runExtensionInstall(opts, {
36
+ ...editDeps,
37
+ manifest: () => prepareManifest(),
38
+ market: openMarket(),
39
+ }),
35
40
  extensionRemove: (opts) => runExtensionRemove(opts, { ...editDeps, io: terminalIo() }),
36
- extensionList: (opts) => runExtensionList(opts),
41
+ extensionList: (opts) => runExtensionList(opts, openMarket()),
37
42
  extensionDoctor: (opts) => runExtensionDoctor(opts),
38
43
  extensionCreate: (opts) => runExtensionCreate(opts),
39
44
  extensionCheck: (opts) => runExtensionCheck(opts),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentage/cli",
3
- "version": "0.50.4",
3
+ "version": "0.51.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",
@@ -55,7 +55,7 @@
55
55
  "prepublishOnly": "npm run verify"
56
56
  },
57
57
  "dependencies": {
58
- "@agentage/extension": "^0.12.1",
58
+ "@agentage/extension": "^0.12.3",
59
59
  "chalk": "^6.0.0",
60
60
  "commander": "^15.0.0",
61
61
  "open": "^11.0.0"