@agentage/cli 0.51.0 → 0.52.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/README.md +95 -127
  2. package/dist/commands/auth/setup.d.ts +2 -0
  3. package/dist/commands/auth/setup.js +4 -1
  4. package/dist/commands/daemon/daemon.d.ts +38 -0
  5. package/dist/commands/daemon/daemon.js +75 -0
  6. package/dist/commands/daemon/installer.d.ts +11 -0
  7. package/dist/commands/daemon/installer.js +87 -0
  8. package/dist/commands/daemon/move-plan.d.ts +17 -0
  9. package/dist/commands/daemon/move-plan.js +67 -0
  10. package/dist/commands/daemon/move-settings.d.ts +5 -0
  11. package/dist/commands/daemon/move-settings.js +50 -0
  12. package/dist/commands/daemon/move.d.ts +17 -0
  13. package/dist/commands/daemon/move.js +106 -0
  14. package/dist/commands/daemon/run.d.ts +6 -0
  15. package/dist/commands/daemon/run.js +36 -0
  16. package/dist/commands/extension/build.d.ts +13 -4
  17. package/dist/commands/extension/build.js +67 -25
  18. package/dist/commands/extension/configure.d.ts +26 -0
  19. package/dist/commands/extension/configure.js +100 -0
  20. package/dist/commands/extension/create-install.d.ts +26 -0
  21. package/dist/commands/extension/create-install.js +81 -0
  22. package/dist/commands/extension/create.d.ts +6 -1
  23. package/dist/commands/extension/create.js +58 -16
  24. package/dist/commands/extension/delegate.js +3 -1
  25. package/dist/commands/extension/doctor.d.ts +1 -1
  26. package/dist/commands/extension/doctor.js +8 -7
  27. package/dist/commands/extension/install-once.d.ts +17 -0
  28. package/dist/commands/extension/install-once.js +57 -0
  29. package/dist/commands/extension/kit-tool.d.ts +1 -1
  30. package/dist/commands/extension/lifecycle-commands.d.ts +19 -0
  31. package/dist/commands/extension/lifecycle-commands.js +80 -0
  32. package/dist/commands/extension/lifecycle-list.d.ts +26 -0
  33. package/dist/commands/extension/lifecycle-list.js +92 -0
  34. package/dist/commands/extension/lifecycle.d.ts +41 -0
  35. package/dist/commands/extension/lifecycle.js +142 -0
  36. package/dist/commands/extension/line.d.ts +1 -0
  37. package/dist/commands/extension/line.js +2 -0
  38. package/dist/commands/extension/list.d.ts +4 -14
  39. package/dist/commands/extension/list.js +11 -95
  40. package/dist/commands/extension/package-build.d.ts +15 -0
  41. package/dist/commands/extension/package-build.js +51 -0
  42. package/dist/commands/extension/plan.d.ts +4 -2
  43. package/dist/commands/extension/plan.js +37 -37
  44. package/dist/commands/extension/profile-plan.d.ts +16 -0
  45. package/dist/commands/extension/profile-plan.js +48 -0
  46. package/dist/commands/extension/release.d.ts +2 -1
  47. package/dist/commands/extension/release.js +10 -9
  48. package/dist/commands/extension/row-lines.d.ts +1 -2
  49. package/dist/commands/extension/row-lines.js +5 -6
  50. package/dist/commands/extension/rows.js +6 -4
  51. package/dist/commands/extension/setup-cloud.d.ts +2 -2
  52. package/dist/commands/extension/setup-cloud.js +6 -5
  53. package/dist/commands/extension/setup-install.d.ts +8 -0
  54. package/dist/commands/extension/setup-install.js +56 -0
  55. package/dist/commands/extension/setup.d.ts +4 -1
  56. package/dist/commands/extension/setup.js +56 -18
  57. package/dist/commands/extension/stack-owner.d.ts +4 -0
  58. package/dist/commands/extension/stack-owner.js +45 -0
  59. package/dist/commands/extension/sync.d.ts +6 -11
  60. package/dist/commands/extension/sync.js +8 -50
  61. package/dist/commands/extension/up-commands.d.ts +9 -0
  62. package/dist/commands/extension/up-commands.js +74 -0
  63. package/dist/commands/extension/up-local.d.ts +21 -0
  64. package/dist/commands/extension/up-local.js +94 -0
  65. package/dist/commands/extension/up-run.d.ts +23 -0
  66. package/dist/commands/extension/up-run.js +75 -0
  67. package/dist/commands/extension/up.d.ts +12 -11
  68. package/dist/commands/extension/up.js +65 -71
  69. package/dist/commands/update/update.d.ts +9 -1
  70. package/dist/commands/update/update.js +20 -6
  71. package/dist/core/installer/compare-lock.d.ts +0 -2
  72. package/dist/core/installer/compare-lock.js +0 -12
  73. package/dist/core/installer/compat.js +5 -3
  74. package/dist/core/installer/npm.d.ts +1 -0
  75. package/dist/core/installer/npm.js +6 -0
  76. package/dist/core/installer/old-tree.d.ts +3 -0
  77. package/dist/core/installer/old-tree.js +45 -0
  78. package/dist/core/installer/package-dir.d.ts +11 -0
  79. package/dist/core/installer/package-dir.js +53 -0
  80. package/dist/core/installer/resolve.js +1 -2
  81. package/dist/core/installer/tree.d.ts +0 -5
  82. package/dist/core/installer/tree.js +1 -25
  83. package/dist/core/kit-id.d.ts +1 -0
  84. package/dist/core/kit-id.js +20 -0
  85. package/dist/core/loader/discover.d.ts +7 -1
  86. package/dist/core/loader/discover.js +5 -4
  87. package/dist/core/loader/installed.d.ts +9 -0
  88. package/dist/core/loader/installed.js +51 -0
  89. package/dist/core/loader/manifest.d.ts +4 -0
  90. package/dist/core/loader/manifest.js +25 -3
  91. package/dist/core/loader/scan.d.ts +2 -1
  92. package/dist/core/loader/scan.js +17 -4
  93. package/dist/core/loader/secrets.d.ts +0 -7
  94. package/dist/core/loader/secrets.js +0 -11
  95. package/dist/core/loader/verbs.d.ts +0 -1
  96. package/dist/core/loader/verbs.js +1 -13
  97. package/dist/core/profile/machine.d.ts +0 -1
  98. package/dist/core/profile/machine.js +0 -5
  99. package/dist/lib/auth/introspect.js +1 -2
  100. package/dist/lib/auth/sign-in.js +3 -0
  101. package/dist/lib/child-env.d.ts +1 -0
  102. package/dist/lib/child-env.js +6 -0
  103. package/dist/lib/daemon/daemon-answer.d.ts +8 -0
  104. package/dist/lib/daemon/daemon-answer.js +38 -0
  105. package/dist/lib/daemon/daemon-client.d.ts +17 -0
  106. package/dist/lib/daemon/daemon-client.js +112 -0
  107. package/dist/lib/daemon/daemon-file.d.ts +16 -0
  108. package/dist/lib/daemon/daemon-file.js +30 -0
  109. package/dist/lib/daemon/daemon-health.d.ts +16 -0
  110. package/dist/lib/daemon/daemon-health.js +36 -0
  111. package/dist/lib/daemon/daemon-probe.d.ts +32 -0
  112. package/dist/lib/daemon/daemon-probe.js +41 -0
  113. package/dist/lib/daemon/daemon-stop.d.ts +13 -0
  114. package/dist/lib/daemon/daemon-stop.js +42 -0
  115. package/dist/lib/daemon/host-client.d.ts +40 -0
  116. package/dist/lib/daemon/host-client.js +45 -0
  117. package/dist/lib/exit-code.d.ts +2 -0
  118. package/dist/lib/exit-code.js +8 -0
  119. package/dist/lib/fs/json-file.d.ts +1 -0
  120. package/dist/lib/fs/json-file.js +1 -1
  121. package/dist/lib/json-output.d.ts +36 -0
  122. package/dist/lib/json-output.js +163 -0
  123. package/dist/lib/net/market-error.d.ts +12 -0
  124. package/dist/lib/net/market-error.js +28 -0
  125. package/dist/lib/net/market.d.ts +17 -2
  126. package/dist/lib/net/market.js +92 -18
  127. package/dist/lib/wait.d.ts +6 -0
  128. package/dist/lib/wait.js +17 -0
  129. package/dist/lib/with-action.d.ts +12 -0
  130. package/dist/lib/with-action.js +33 -0
  131. package/dist/program-deps.d.ts +2 -0
  132. package/dist/program-deps.js +95 -0
  133. package/dist/program.d.ts +29 -21
  134. package/dist/program.js +41 -75
  135. package/package.json +8 -6
  136. package/CHANGELOG.md +0 -68
  137. package/dist/commands/extension/install-load.d.ts +0 -7
  138. package/dist/commands/extension/install-load.js +0 -42
  139. package/dist/commands/extension/install.d.ts +0 -12
  140. package/dist/commands/extension/install.js +0 -49
  141. package/dist/commands/extension/latest.d.ts +0 -2
  142. package/dist/commands/extension/latest.js +0 -71
  143. package/dist/commands/extension/remove.d.ts +0 -15
  144. package/dist/commands/extension/remove.js +0 -86
  145. package/dist/commands/extension/secrets-prompt.d.ts +0 -6
  146. package/dist/commands/extension/secrets-prompt.js +0 -47
  147. package/dist/core/installer/installer.d.ts +0 -28
  148. package/dist/core/installer/installer.js +0 -87
  149. package/dist/core/installer/latest.d.ts +0 -27
  150. package/dist/core/installer/latest.js +0 -90
  151. package/dist/core/profile/edit.d.ts +0 -4
  152. package/dist/core/profile/edit.js +0 -27
@@ -5,8 +5,7 @@ import {} from '../../lib/npm/npm-cli.js';
5
5
  import { PACKAGE_NAME, specProblem } from '../profile/schema.js';
6
6
  import { cliGate, needs, newestCompatible, parsePublished } from './compat.js';
7
7
  import { isKitShaped } from '../loader/kit-manifest.js';
8
- import { lastLines } from './installer.js';
9
- import {} from './npm.js';
8
+ import { lastLines } from './npm.js';
10
9
  // Every release: a range, not `*`, which npm view reads as the `latest` tag alone.
11
10
  const EVERY_RELEASE = '>=0.0.0';
12
11
  const LOCAL = /^\.{1,2}(?:[/\\]|$)/;
@@ -4,10 +4,8 @@ export interface TreeFiles {
4
4
  npmrc: string;
5
5
  lock: string | null;
6
6
  }
7
- export declare const sortedSet: (install: Record<string, string>) => Record<string, string>;
8
7
  export declare const manifestText: (install: Record<string, string>) => string;
9
8
  export declare const npmrcText: (registries: Record<string, string>) => string;
10
- export declare const treeName: (entries: string[]) => string;
11
9
  export declare const treePath: (extensionsDir: string, name: string) => string;
12
10
  export declare const isComplete: (extensionsDir: string, name: string) => boolean;
13
11
  export declare const readText: (path: string) => string | null;
@@ -15,7 +13,4 @@ export declare const clearStaging: (extensionsDir: string) => void;
15
13
  export declare const stageTree: (extensionsDir: string, files: TreeFiles) => string;
16
14
  export declare const discardTree: (dir: string) => void;
17
15
  export declare const commitTree: (extensionsDir: string, staging: string, name: string) => void;
18
- export declare const collectTrees: (extensionsDir: string, keep: string) => void;
19
- export declare const pointCurrent: (extensionsDir: string, name: string) => void;
20
- export declare const promoteFiles: (extensionsDir: string, files: Omit<TreeFiles, "npmrc">) => void;
21
16
  export declare const withInstallLock: <T>(extensionsDir: string, fn: () => Promise<T>) => Promise<T>;
@@ -1,8 +1,6 @@
1
- import { createHash } from 'node:crypto';
2
1
  import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync, } from 'node:fs';
3
2
  import { join } from 'node:path';
4
3
  import { refreshFileLock, withFileLock } from '../../lib/fs/file-lock.js';
5
- import { writeTextAtomic } from '../../lib/fs/json-file.js';
6
4
  export const LOCK_FILE = 'package-lock.json';
7
5
  const MANIFEST_FILE = 'package.json';
8
6
  const TREES = 'trees';
@@ -14,15 +12,13 @@ const STAGING_PREFIX = '.staging-';
14
12
  // An install runs for minutes: a long TTL plus a heartbeat keep a live holder from looking dead.
15
13
  const INSTALL_LOCK = { ttlMs: 2 * 60_000, hardStaleMs: 60 * 60_000, maxWaitMs: 30 * 60_000 };
16
14
  const HEARTBEAT_MS = 20_000;
17
- export const sortedSet = (install) => Object.fromEntries(Object.entries(install).sort(([a], [b]) => (a < b ? -1 : 1)));
15
+ const sortedSet = (install) => Object.fromEntries(Object.entries(install).sort(([a], [b]) => (a < b ? -1 : 1)));
18
16
  // Same install set, same bytes: no scripts, nothing machine-specific.
19
17
  export const manifestText = (install) => `${JSON.stringify({ name: MANIFEST_NAME, private: true, dependencies: sortedSet(install) }, null, 2)}\n`;
20
18
  // npm's own per-scope registry lines; every other package uses the --registry default.
21
19
  export const npmrcText = (registries) => Object.entries(sortedSet(registries))
22
20
  .map(([scope, url]) => `${scope}:registry=${url}\n`)
23
21
  .join('');
24
- // Content-addressed: the same normalized lock names the same tree on every machine.
25
- export const treeName = (entries) => createHash('sha256').update(entries.join('\n')).digest('hex').slice(0, 16);
26
22
  export const treePath = (extensionsDir, name) => join(extensionsDir, TREES, name);
27
23
  export const isComplete = (extensionsDir, name) => existsSync(join(treePath(extensionsDir, name), COMPLETE));
28
24
  export const readText = (path) => {
@@ -62,26 +58,6 @@ export const commitTree = (extensionsDir, staging, name) => {
62
58
  writeFileSync(join(staging, COMPLETE), '');
63
59
  renameSync(staging, target);
64
60
  };
65
- // Only `keep` stays: the lock in the extensions root can rebuild any other tree. Staging dirs are
66
- // left to clearStaging, so a run never removes another's.
67
- export const collectTrees = (extensionsDir, keep) => {
68
- const trees = join(extensionsDir, TREES);
69
- if (!existsSync(trees))
70
- return;
71
- for (const name of readdirSync(trees))
72
- if (name !== keep && !name.startsWith(STAGING_PREFIX))
73
- remove(join(trees, name));
74
- };
75
- export const pointCurrent = (extensionsDir, name) => writeTextAtomic(join(extensionsDir, 'current'), `${name}\n`);
76
- // The extensions root always describes the tree `current` names, never a failed attempt.
77
- export const promoteFiles = (extensionsDir, files) => {
78
- writeTextAtomic(join(extensionsDir, MANIFEST_FILE), files.manifest);
79
- const lock = join(extensionsDir, LOCK_FILE);
80
- if (files.lock === null)
81
- remove(lock);
82
- else
83
- writeTextAtomic(lock, files.lock);
84
- };
85
61
  const heartbeat = async (target, fn) => {
86
62
  const beat = setInterval(() => refreshFileLock(target), HEARTBEAT_MS);
87
63
  beat.unref();
@@ -0,0 +1 @@
1
+ export declare const kitIdProblem: (id: string) => string | null;
@@ -0,0 +1,20 @@
1
+ import { createRequire } from 'node:module';
2
+ import { isRecord, readJson } from '../lib/fs/json-file.js';
3
+ let cached;
4
+ // The kit's own id rule, read from the JSON schema it exports (data: no kit code is loaded).
5
+ const read = () => {
6
+ const file = '@agentage/extension/schemas/extension-package.schema.json';
7
+ const schema = readJson(createRequire(import.meta.url).resolve(file), isRecord);
8
+ const props = (o) => (isRecord(o) && isRecord(o['properties']) ? o['properties'] : {});
9
+ const id = props(props(schema)['agentage'])['id'];
10
+ if (!isRecord(id) || typeof id['pattern'] !== 'string' || typeof id['maxLength'] !== 'number')
11
+ throw new Error(`${file} has no agentage.id rule`);
12
+ return { pattern: new RegExp(id['pattern']), max: id['maxLength'] };
13
+ };
14
+ // Why the kit refuses the id (the daemon takes no such row), or null.
15
+ export const kitIdProblem = (id) => {
16
+ const rule = (cached ??= read());
17
+ if (id.length > rule.max)
18
+ return `the id ${id} is longer than ${rule.max} characters`;
19
+ return rule.pattern.test(id) ? null : `the id ${id} is a name the platform owns or not lowercase`;
20
+ };
@@ -18,6 +18,7 @@ export interface DiscoveredExtension {
18
18
  secrets: string[];
19
19
  descriptions: Record<string, string>;
20
20
  problem: string | null;
21
+ warning: string | null;
21
22
  missing: boolean;
22
23
  }
23
24
  export interface DiscoverInput {
@@ -25,7 +26,6 @@ export interface DiscoverInput {
25
26
  names: string[];
26
27
  dev: Record<string, string>;
27
28
  config: ConfigMap;
28
- tree?: string;
29
29
  }
30
30
  export interface Discovery {
31
31
  extensions: DiscoveredExtension[];
@@ -36,4 +36,10 @@ export interface CurrentTree {
36
36
  warning: string | null;
37
37
  }
38
38
  export declare const currentTree: (extensionsDir: string) => CurrentTree;
39
+ export interface Candidate {
40
+ pkg: string;
41
+ source: ExtensionSource;
42
+ dir: string | null;
43
+ }
44
+ export declare const inspect: ({ pkg, source, dir }: Candidate, configs: ConfigMap) => DiscoveredExtension;
39
45
  export declare const discover: (input: DiscoverInput) => Discovery;
@@ -5,7 +5,7 @@ import {} from '../profile/schema.js';
5
5
  import { checkConfig } from './config.js';
6
6
  import { unsafeDevPath } from './dev-path.js';
7
7
  import {} from './kit-manifest.js';
8
- import { manifestInfo, manifestProblem } from './manifest.js';
8
+ import { kitWarning, manifestInfo, manifestProblem, } from './manifest.js';
9
9
  const readText = (path) => {
10
10
  try {
11
11
  return readFileSync(path, 'utf-8');
@@ -65,9 +65,10 @@ const blank = (pkg, source, dir) => ({
65
65
  secrets: [],
66
66
  descriptions: {},
67
67
  problem: null,
68
+ warning: null,
68
69
  missing: false,
69
70
  });
70
- const inspect = ({ pkg, source, dir }, configs) => {
71
+ export const inspect = ({ pkg, source, dir }, configs) => {
71
72
  const base = blank(pkg, source, dir ?? '');
72
73
  if (source === 'dev' && !isAbsolute(base.dir))
73
74
  return { ...base, problem: 'dev path not absolute' };
@@ -82,7 +83,7 @@ const inspect = ({ pkg, source, dir }, configs) => {
82
83
  const unsafe = source === 'dev' ? unsafeDevPath(dir, process.getuid?.()) : null;
83
84
  const problem = unsafe ?? manifestProblem(pkg, info) ?? entryProblem(info, entry) ?? badConfig;
84
85
  const read = { kind, version, id, entry, commands, kitCommands, peers, optionalPeers };
85
- return { ...base, ...read, ...declared, problem };
86
+ return { ...base, ...read, ...declared, problem, warning: kitWarning(info) };
86
87
  };
87
88
  // Every claimant of a shared id is invalid; a dev copy of the same package never reaches here.
88
89
  const markDuplicates = (extensions) => extensions.map((p) => {
@@ -102,7 +103,7 @@ const extensionPeers = (p, known, nodeModules) => p.peers.filter((peer) => {
102
103
  return manifest === null || isRecord(manifest['agentage']);
103
104
  });
104
105
  export const discover = (input) => {
105
- const tree = input.tree ? { dir: input.tree, warning: null } : currentTree(input.extensionsDir);
106
+ const tree = currentTree(input.extensionsDir);
106
107
  const nodeModules = tree.dir === null ? null : join(tree.dir, 'node_modules');
107
108
  const installed = input.names.filter((name) => !(name in input.dev));
108
109
  const found = markDuplicates([
@@ -0,0 +1,9 @@
1
+ import { type DiscoveredExtension } from './discover.js';
2
+ export declare const installationPath: () => string;
3
+ export declare const settingsPath: () => string;
4
+ export declare const versionsInUse: (id: string) => string[];
5
+ export declare const installationRows: () => {
6
+ id: string;
7
+ dir: string | null;
8
+ }[];
9
+ export declare const installedExtensions: () => DiscoveredExtension[] | null;
@@ -0,0 +1,51 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { getConfigDir } from '../../lib/fs/config.js';
4
+ import { isRecord, readJson } from '../../lib/fs/json-file.js';
5
+ import { installedDir } from '../installer/old-tree.js';
6
+ import {} from '../profile/schema.js';
7
+ import { inspect } from './discover.js';
8
+ export const installationPath = () => join(getConfigDir(), 'installation.json');
9
+ export const settingsPath = () => join(getConfigDir(), 'settings.json');
10
+ // The C3 rows as written; an absent or unreadable file has none.
11
+ const rows = () => {
12
+ const doc = readJson(installationPath(), isRecord);
13
+ return Array.isArray(doc?.['extensions']) ? doc['extensions'] : [];
14
+ };
15
+ // The package folder of one C3 row: its source folder, or the tree that holds its version.
16
+ const dirOf = (row) => {
17
+ if (typeof row['source'] === 'string')
18
+ return { dir: row['source'], dev: true };
19
+ const { id, version } = row;
20
+ if (typeof id !== 'string' || typeof version !== 'string')
21
+ return null;
22
+ const dir = installedDir(id, version);
23
+ return dir === null ? null : { dir, dev: false };
24
+ };
25
+ // The daemon's settings by id: what a 1.0-API extension's ctx.config holds.
26
+ const settings = () => {
27
+ const all = readJson(settingsPath(), isRecord) ?? {};
28
+ return Object.fromEntries(Object.entries(all).filter((e) => isRecord(e[1])));
29
+ };
30
+ // The versions of id that installation.json names now.
31
+ export const versionsInUse = (id) => rows().flatMap((row) => isRecord(row) && row['id'] === id && typeof row['version'] === 'string' ? [row['version']] : []);
32
+ // Each row's id and package folder, disabled ones too (null: its version is on no disk here).
33
+ export const installationRows = () => rows().flatMap((row) => isRecord(row) && typeof row['id'] === 'string'
34
+ ? [{ id: row['id'], dir: dirOf(row)?.dir ?? null }]
35
+ : []);
36
+ const discovered = (row, configs) => {
37
+ const found = isRecord(row) && row['enabled'] !== false ? dirOf(row) : null;
38
+ if (found === null)
39
+ return [];
40
+ const name = readJson(join(found.dir, 'package.json'), isRecord)?.['name'];
41
+ const pkg = typeof name === 'string' ? name : String(row['id']);
42
+ const ext = inspect({ pkg, source: found.dev ? 'dev' : 'tree', dir: found.dir }, configs);
43
+ return ext.missing || ext.problem ? [] : [ext];
44
+ };
45
+ // What installation.json runs, read from the files (no daemon is asked); null before the move.
46
+ export const installedExtensions = () => {
47
+ if (!existsSync(installationPath()))
48
+ return null;
49
+ const configs = settings();
50
+ return rows().flatMap((row) => discovered(row, configs));
51
+ };
@@ -17,4 +17,8 @@ export interface ManifestInfo {
17
17
  shape: string | null;
18
18
  }
19
19
  export declare const manifestInfo: (pkg: Record<string, unknown>) => ManifestInfo;
20
+ export declare const OLDER_KIT_MINORS: string[];
21
+ export declare const olderKitWarning: (minor: string) => string;
22
+ export declare const onPreviousKit: (engine: string, kit?: string) => boolean;
23
+ export declare const kitWarning: (info: ManifestInfo, kit?: string) => string | null;
20
24
  export declare const manifestProblem: (pkg: string, info: ManifestInfo, api?: string, kit?: string) => string | null;
@@ -83,10 +83,32 @@ const engineProblem = (engine, version, against) => {
83
83
  return null;
84
84
  return `engines.agentage "${engine}" does not match ${against} ${version}`;
85
85
  };
86
+ // The older kit minors this kit still hosts: 0.12 is what cli 0.51 installed, 0.13 the one before
87
+ // this kit; their part modules and command contract are those of 0.14 (the update smoke proves it).
88
+ export const OLDER_KIT_MINORS = ['0.12', '0.13'];
89
+ const OLDER = OLDER_KIT_MINORS.map((minor) => ({
90
+ minor,
91
+ versions: Array.from({ length: 100 }, (_, patch) => `${minor}.${patch}`),
92
+ }));
93
+ const olderMinorOf = (engine, kit) => {
94
+ if (!isRange(engine) || satisfies(kit, engine))
95
+ return null;
96
+ return OLDER.find(({ versions }) => versions.some((v) => satisfies(v, engine)))?.minor ?? null;
97
+ };
98
+ export const olderKitWarning = (minor) => `built on kit ${minor}, update the extension`;
99
+ // A range this kit does not satisfy and an older hosted minor does: a warning, never a problem.
100
+ export const onPreviousKit = (engine, kit = kitVersion()) => olderMinorOf(engine, kit) !== null;
101
+ export const kitWarning = (info, kit = kitVersion()) => {
102
+ const minor = info.kind === 'kit' ? olderMinorOf(info.engine, kit) : null;
103
+ return minor ? olderKitWarning(minor) : null;
104
+ };
105
+ const kitRangeProblem = (engine, kit) => {
106
+ if (engine === '')
107
+ return 'engines.agentage is missing';
108
+ return onPreviousKit(engine, kit) ? null : engineProblem(engine, kit, 'kit');
109
+ };
86
110
  // A kit-shaped range is over the kit's version; it has no default.
87
- const kitProblem = (info, kit) => idProblem(info.id) ??
88
- info.shape ??
89
- (info.engine === '' ? 'engines.agentage is missing' : engineProblem(info.engine, kit, 'kit'));
111
+ const kitProblem = (info, kit) => idProblem(info.id) ?? info.shape ?? kitRangeProblem(info.engine, kit);
90
112
  // Commands are named after the id, so no two extensions, nor the core, can claim one.
91
113
  const commandsProblem = (id, commands) => {
92
114
  const ownSub = (name) => name.startsWith(`${id}:`) && SUBCOMMAND.test(name.slice(id.length + 1));
@@ -14,5 +14,6 @@ export interface Scan {
14
14
  removed: DiscoveredExtension[];
15
15
  drift: string[];
16
16
  }
17
- export declare const scan: (machine: MachineFile, tree?: string) => Scan;
17
+ export declare const scan: (machine: MachineFile) => Scan;
18
18
  export declare const loadSet: (found: Scan) => DiscoveredExtension[];
19
+ export declare const scanNow: (machine: MachineFile) => Scan;
@@ -5,6 +5,7 @@ import { readProfile } from '../profile/profile.js';
5
5
  import {} from '../profile/schema.js';
6
6
  import { extensionsDir } from '../paths.js';
7
7
  import { discover } from './discover.js';
8
+ import { installedExtensions } from './installed.js';
8
9
  import { staticStates } from './states.js';
9
10
  // A tree extension whose bytes the two locks disagree on is never trusted, so never imported.
10
11
  const withDrift = (found, drift) => ({
@@ -15,14 +16,13 @@ const withDrift = (found, drift) => ({
15
16
  return drifted ? { ...p, problem: `integrity drift: ${key}` } : p;
16
17
  }),
17
18
  });
18
- // Everything known about this machine's extensions without running any of them; `tree` reads
19
- // that tree instead of the current one.
20
- export const scan = (machine, tree) => {
19
+ // Everything known about this machine's extensions without running any of them.
20
+ export const scan = (machine) => {
21
21
  const parsed = readProfile();
22
22
  const eff = effective(parsed?.ok ? parsed.profile : null, machine);
23
23
  const dir = extensionsDir();
24
24
  const drift = lockDrift(dir).integrity;
25
- const input = { extensionsDir: dir, dev: eff.dev, config: eff.config, tree };
25
+ const input = { extensionsDir: dir, dev: eff.dev, config: eff.config };
26
26
  const found = withDrift(discover({ ...input, names: Object.keys(eff.install) }), drift);
27
27
  const plan = planChanges(eff, currentDependencies(dir));
28
28
  const gone = plan.extensions.filter((e) => e.verb === 'remove' && !(e.name in eff.dev));
@@ -32,3 +32,16 @@ export const scan = (machine, tree) => {
32
32
  };
33
33
  // What can load: a valid manifest, installed, not off here, and peers that can load too.
34
34
  export const loadSet = (found) => found.found.extensions.filter((ext) => found.states.get(ext.pkg)?.state === 'installed');
35
+ // Once installation.json exists it is this machine's list: no profile plan, no drift.
36
+ const scanInstalled = (machine, installed) => {
37
+ const eff = effective(null, machine);
38
+ const found = { extensions: installed, warnings: [] };
39
+ const plan = planChanges(eff, {});
40
+ const states = staticStates(installed, []);
41
+ return { machine, parsed: readProfile(), eff, found, states, plan, removed: [], drift: [] };
42
+ };
43
+ // What status and doctor read: installation.json when it exists, else the old lists.
44
+ export const scanNow = (machine) => {
45
+ const installed = installedExtensions();
46
+ return installed === null ? scan(machine) : scanInstalled(machine, installed);
47
+ };
@@ -1,9 +1,2 @@
1
1
  import { type ExtensionSecrets } from '../../extension.js';
2
- import { type DiscoveredExtension } from './discover.js';
3
- export interface SecretKey {
4
- id: string;
5
- key: string;
6
- description: string | null;
7
- }
8
2
  export declare const secretsFor: (id: string) => ExtensionSecrets;
9
- export declare const missingSecrets: (extensions: DiscoveredExtension[]) => SecretKey[];
@@ -2,7 +2,6 @@ import {} from '../../extension.js';
2
2
  import { withFileLock } from '../../lib/fs/file-lock.js';
3
3
  import { isRecord, readJson, writeJsonAtomic } from '../../lib/fs/json-file.js';
4
4
  import { secretsPath } from '../paths.js';
5
- import {} from './discover.js';
6
5
  const isStrings = (value) => isRecord(value) && Object.values(value).every((v) => typeof v === 'string');
7
6
  const isSecretsFile = (value) => isRecord(value) && Object.values(value).every(isStrings);
8
7
  const readSecrets = () => readJson(secretsPath(), isSecretsFile) ?? {};
@@ -16,13 +15,3 @@ export const secretsFor = (id) => ({
16
15
  set: (key, value) => change(id, (own) => ({ ...own, [key]: value })),
17
16
  delete: (key) => change(id, (own) => Object.fromEntries(Object.entries(own).filter(([k]) => k !== key))),
18
17
  });
19
- // The keys extensions declare `secret: true` that this machine has no value for yet.
20
- export const missingSecrets = (extensions) => {
21
- const stored = readSecrets();
22
- return extensions.flatMap((ext) => {
23
- const id = ext.id ?? '';
24
- return ext.secrets
25
- .filter((key) => stored[id]?.[key] === undefined)
26
- .map((key) => ({ id, key, description: ext.descriptions[key] ?? null }));
27
- });
28
- };
@@ -10,6 +10,5 @@ export interface Verbs {
10
10
  namespaced: Namespaced[];
11
11
  }
12
12
  export declare const readHeld: () => Map<string, string>;
13
- export declare const writeHeld: (top: Map<string, string>) => void;
14
13
  export declare const claimVerbs: (extensions: DiscoveredExtension[], held: Map<string, string>) => Verbs;
15
14
  export declare const commandNames: (ext: DiscoveredExtension, verbs: Verbs) => string[];
@@ -1,22 +1,10 @@
1
- import { mkdirSync } from 'node:fs';
2
- import { dirname } from 'node:path';
3
- import { isDeepStrictEqual } from 'node:util';
4
- import { isRecord, readJson, writeJsonAtomic } from '../../lib/fs/json-file.js';
1
+ import { isRecord, readJson } from '../../lib/fs/json-file.js';
5
2
  import { commandsPath } from '../paths.js';
6
3
  import {} from './discover.js';
7
4
  import { CORE_COMMANDS } from './manifest.js';
8
5
  const isHeld = (value) => isRecord(value) && Object.values(value).every((pkg) => typeof pkg === 'string');
9
6
  // Who held each top-level verb after the last install; absent or unreadable: nobody.
10
7
  export const readHeld = () => new Map(Object.entries(readJson(commandsPath(), isHeld) ?? {}));
11
- // Written only when it changed, so a machine without kit commands never gets the file.
12
- export const writeHeld = (top) => {
13
- const next = Object.fromEntries(top);
14
- const current = Object.fromEntries(readHeld());
15
- if (isDeepStrictEqual(next, current))
16
- return;
17
- mkdirSync(dirname(commandsPath()), { recursive: true, mode: 0o700 });
18
- writeJsonAtomic(commandsPath(), next);
19
- };
20
8
  // Core commands and every extension id are namespaces; 1.0 commands are named after their id.
21
9
  const takenNames = (extensions) => {
22
10
  const taken = new Map(CORE_COMMANDS.map((name) => [name, 'is a core command']));
@@ -11,7 +11,6 @@ export declare const NO_MACHINE: MachineFile;
11
11
  export declare const readMachine: () => MachineFile | null;
12
12
  export declare const loadMachine: () => Promise<MachineFile>;
13
13
  export declare const setProfileSource: (source: ProfileSource) => Promise<MachineFile>;
14
- export declare const setDev: (name: string, path: string | null) => Promise<MachineFile>;
15
14
  export declare const setCloud: (etag: string) => Promise<MachineFile>;
16
15
  export declare const setAccount: (accountId: string) => Promise<MachineFile>;
17
16
  export declare const forgetAccount: () => Promise<MachineFile>;
@@ -61,11 +61,6 @@ const update = async (change) => withFileLock(machinePath(), () => {
61
61
  return isDeepStrictEqual(next, machine) ? machine : save(next);
62
62
  });
63
63
  export const setProfileSource = async (source) => update((machine) => ({ ...machine, profileSource: source }));
64
- // One dev entry by package name: a real path adds or replaces it, null removes it.
65
- export const setDev = async (name, path) => update((machine) => {
66
- const dev = Object.fromEntries(Object.entries(machine.dev).filter(([pkg]) => pkg !== name));
67
- return { ...machine, dev: path === null ? dev : { ...dev, [name]: path } };
68
- });
69
64
  // After a pull or a push: profile.json mirrors the account's profile at `etag`.
70
65
  export const setCloud = async (etag) => update((machine) => ({ ...machine, profileSource: 'cloud', profileEtag: etag }));
71
66
  export const setAccount = async (accountId) => update((machine) => ({ ...machine, accountId }));
@@ -2,6 +2,7 @@ import {} from '../fs/config.js';
2
2
  import {} from '../net/origins.js';
3
3
  import { authedJson, refreshOrThrow } from './api.js';
4
4
  import { AuthRequiredError, TransientAuthError } from './auth-errors.js';
5
+ import { sleep } from '../wait.js';
5
6
  const isPast = (iso) => {
6
7
  if (!iso)
7
8
  return false;
@@ -9,8 +10,6 @@ const isPast = (iso) => {
9
10
  return !Number.isNaN(t) && t <= Date.now();
10
11
  };
11
12
  const RETRY_BACKOFF_MS = 300;
12
- // Ref'd on purpose: an unref'd backoff let Node exit 13 mid-retry once nothing else held the loop.
13
- const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
14
13
  // Any failure but a 401 is a transient: a network blip must never read as a dead session.
15
14
  const getSession = async (auth, links) => {
16
15
  const url = `${links.auth}/api/auth/mcp/get-session`;
@@ -2,6 +2,7 @@ import chalk from 'chalk';
2
2
  import { deleteAuth, ensureConfigDir, mutateAuth, readAuth } from '../fs/config.js';
3
3
  import { discoverTarget } from '../net/discovery.js';
4
4
  import { siteFqdn } from '../net/origins.js';
5
+ import { CliError, isJsonRun } from '../json-output.js';
5
6
  import { AuthRequiredError } from './auth-errors.js';
6
7
  import { startCallbackServer } from './callback-server.js';
7
8
  import { credentialLinks, detectEnvMismatch } from './env-match.js';
@@ -41,6 +42,8 @@ const authorize = async (server, state, opts, deps, authUrl) => {
41
42
  };
42
43
  // A fresh DCR client per run: the redirect URI binds this run's ephemeral callback port.
43
44
  export const signIn = async (opts, deps = defaultDeps) => {
45
+ if (isJsonRun() && opts.browser !== false)
46
+ throw new CliError('confirmation_required', 'sign-in opens a browser: pass --no-browser');
44
47
  const fqdn = siteFqdn();
45
48
  const to = await deps.discover(fqdn);
46
49
  const authUrl = to.auth;
@@ -0,0 +1 @@
1
+ export declare const childEnv: (env?: NodeJS.ProcessEnv) => NodeJS.ProcessEnv;
@@ -0,0 +1,6 @@
1
+ // The cli's own token never reaches a process it starts: npm, an author's script, the daemon.
2
+ export const childEnv = (env = process.env) => {
3
+ const copy = { ...env };
4
+ delete copy['AGENTAGE_TOKEN'];
5
+ return copy;
6
+ };
@@ -0,0 +1,8 @@
1
+ import { DaemonError } from '../json-output.js';
2
+ export declare const daemonFailure: (status: number, body: unknown) => DaemonError;
3
+ export interface Existing {
4
+ id: string;
5
+ version?: string;
6
+ source?: string;
7
+ }
8
+ export declare const existingOf: (err: DaemonError) => Existing | null;
@@ -0,0 +1,38 @@
1
+ import { isRecord } from '../fs/json-file.js';
2
+ import { DaemonError } from '../json-output.js';
3
+ const STATUS = 'agentage daemon status';
4
+ // After a 504 the kit records nothing; the npm tree an installer finishes later is reused.
5
+ const RECORDED_NOT = `the daemon recorded nothing: when ${STATUS} no longer shows it under pending, run the command again (a download that finished is reused)`;
6
+ // A 409 CONFLICT of a timed-out install that still runs names op and since, not an installed entry.
7
+ const stillRuns = (details) => details['timedOut'] === true || typeof details['op'] === 'string';
8
+ // One honest tail per answer the kit 0.14 daemon gives; the daemon's code stays the cli's code.
9
+ const tailOf = (status, code, details) => {
10
+ if (code === 'CONFLICT' && stillRuns(details))
11
+ return `; ${STATUS} shows it under pending; try again when it ends`;
12
+ if (code === 'INSTALLATION_UNREADABLE')
13
+ return `; ${STATUS} shows the reason`;
14
+ if (code === 'TIMEOUT')
15
+ return `; ${RECORDED_NOT}`;
16
+ if (status === 503)
17
+ return '; try again';
18
+ return '';
19
+ };
20
+ // The daemon's envelope as a DaemonError: its code, its message with the tail, status and details.
21
+ export const daemonFailure = (status, body) => {
22
+ const error = isRecord(body) && isRecord(body['error']) ? body['error'] : {};
23
+ const message = typeof error['message'] === 'string' ? error['message'] : `HTTP ${status}`;
24
+ const code = typeof error['code'] === 'string' && error['code'] ? error['code'] : 'error';
25
+ const details = isRecord(error['details']) ? error['details'] : {};
26
+ const tail = message.endsWith('try again') ? '' : tailOf(status, code, details);
27
+ return new DaemonError(code, `${message}${tail}`, status, details);
28
+ };
29
+ export const existingOf = (err) => {
30
+ const { id, version, source } = err.details;
31
+ if (err.code !== 'CONFLICT' || typeof id !== 'string' || stillRuns(err.details))
32
+ return null;
33
+ return {
34
+ id,
35
+ ...(typeof version === 'string' && { version }),
36
+ ...(typeof source === 'string' && { source }),
37
+ };
38
+ };
@@ -0,0 +1,17 @@
1
+ import { type Probe } from './daemon-probe.js';
2
+ import { type StopResult } from './daemon-stop.js';
3
+ export type SpawnOutcome = 'ok' | 'port-in-use' | 'unreachable';
4
+ export interface EnsureDeps {
5
+ probe: (port: number) => Promise<Probe>;
6
+ spawn: (port: number) => Promise<SpawnOutcome>;
7
+ stop: () => Promise<StopResult>;
8
+ log: (line: string) => void;
9
+ }
10
+ export declare const LOG_CAP: number;
11
+ export declare const waitForHealth: (port: number, timeoutMs?: number) => Promise<boolean>;
12
+ export declare const daemonLogPath: () => string;
13
+ export declare const openDaemonLog: (cap?: number) => number;
14
+ export declare const spawnDaemon: (port: number, entry?: string) => Promise<SpawnOutcome>;
15
+ export declare const defaultEnsureDeps: EnsureDeps;
16
+ export declare const ensureDaemon: (deps?: EnsureDeps) => Promise<number>;
17
+ export declare const restartIfRunning: (deps?: EnsureDeps) => Promise<boolean>;