evolcore 0.0.43-test.5 → 0.0.43-test.7

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 (259) hide show
  1. package/CHANGELOG.md +95 -0
  2. package/bin/ecmsg.js +281 -81
  3. package/dist/agents/baseagent-availability.js +20 -5
  4. package/dist/agents/baseagent.js +2 -2
  5. package/dist/agents/claude-runner.js +19 -4
  6. package/dist/agents/codex/app-server-client.js +36 -3
  7. package/dist/agents/codex-runner.js +75 -8
  8. package/dist/aun/group/invite-service.js +3 -2
  9. package/dist/aun/msg/p2p.js +6 -1
  10. package/dist/aun/service-proxy.js +18 -6
  11. package/dist/channels/aun.js +306 -30
  12. package/dist/cli/agent-create.js +18 -8
  13. package/dist/cli/aun-commands.js +9 -1
  14. package/dist/cli/daemon-commands.js +34 -65
  15. package/dist/cli/daemon-lifecycle-client.js +61 -0
  16. package/dist/cli/ecmsg-gateway.js +38 -3
  17. package/dist/cli/events-command.js +73 -0
  18. package/dist/cli/index.js +31 -14
  19. package/dist/cli/init.js +75 -0
  20. package/dist/cli/invoke-command.js +182 -0
  21. package/dist/cli/managed-command-guard.js +6 -1
  22. package/dist/cli/provider-command.js +1 -1
  23. package/dist/cli/restart-monitor.js +67 -50
  24. package/dist/cli/services-command.js +111 -0
  25. package/dist/cli/task-context.js +38 -1
  26. package/dist/cli/team-workspace-command.js +134 -0
  27. package/dist/cli/thread-command.js +6 -2
  28. package/dist/cli/watch-logs.js +6 -4
  29. package/dist/cli/watch-msg.js +1 -1
  30. package/dist/config/boot-log.js +6 -4
  31. package/dist/config/builtin-roles.js +2 -2
  32. package/dist/config/config-field-policy.js +2 -2
  33. package/dist/config/config-manager.js +1 -8
  34. package/dist/config/invoke-ipc-service.js +118 -0
  35. package/dist/config/peer-role-resolver.js +1 -1
  36. package/dist/config/provider-identity-migration.js +92 -17
  37. package/dist/config/provider-local-sync.js +2 -0
  38. package/dist/config/providers-config.js +13 -0
  39. package/dist/config/providers-management.js +100 -10
  40. package/dist/config/role-service.js +8 -8
  41. package/dist/config/role-store.js +22 -22
  42. package/dist/config/schema-migration.js +86 -88
  43. package/dist/config/snapshot.js +70 -41
  44. package/dist/config-store.js +2 -1
  45. package/dist/core/agent-reload-coordinator.js +6 -4
  46. package/dist/core/agent-runtime.js +146 -15
  47. package/dist/core/auth/delegation-authorization.js +66 -0
  48. package/dist/core/auth/operation-catalog.js +20 -0
  49. package/dist/core/baseagent-loader.js +75 -42
  50. package/dist/core/channel-loader.js +45 -13
  51. package/dist/core/channel-runtime.js +116 -45
  52. package/dist/core/command/agent-control.js +1 -1
  53. package/dist/core/command/agent-storage-menu.js +1 -1
  54. package/dist/core/command/chatmode-config.js +2 -36
  55. package/dist/core/command/command-handler.js +58 -16
  56. package/dist/core/command/data-root-resolver.js +32 -23
  57. package/dist/core/command/eventcenter-menu.js +338 -0
  58. package/dist/core/command/menu-catalog.js +8 -0
  59. package/dist/core/command/menu-handler.js +206 -87
  60. package/dist/core/command/menu-protocol.js +142 -22
  61. package/dist/core/command/menu-query-batch.js +194 -0
  62. package/dist/core/command/role-menu.js +27 -15
  63. package/dist/core/command/slash-gate.js +1 -1
  64. package/dist/core/command/slash-handler.js +34 -42
  65. package/dist/core/command/team-workspace-bootstrap.js +350 -0
  66. package/dist/core/command/{pa-workspace-calendar.js → team-workspace-calendar.js} +7 -7
  67. package/dist/core/command/team-workspace-initializer.js +2 -0
  68. package/dist/core/command/{pa-workspace-items.js → team-workspace-items.js} +83 -68
  69. package/dist/core/command/team-workspace-job-store.js +88 -0
  70. package/dist/core/command/team-workspace-management-service.js +2 -0
  71. package/dist/core/command/team-workspace-management-store.js +96 -0
  72. package/dist/core/command/team-workspace-management.js +265 -0
  73. package/dist/core/command/team-workspace-members-menu.js +88 -0
  74. package/dist/core/command/team-workspace-store.js +612 -0
  75. package/dist/core/command/team-workspace-team.js +193 -0
  76. package/dist/core/daemon-control.js +45 -15
  77. package/dist/core/daemon-lifecycle.js +478 -75
  78. package/dist/core/handoff/dispatcher.js +9 -3
  79. package/dist/core/handoff/runtime.js +130 -42
  80. package/dist/core/handoff/store.js +190 -2
  81. package/dist/core/handoff/types.js +5 -0
  82. package/dist/core/initialization/service.js +4 -4
  83. package/dist/core/invoke/executors/index.js +13 -0
  84. package/dist/core/invoke/executors/media.js +283 -0
  85. package/dist/core/invoke/executors/text.js +198 -0
  86. package/dist/core/invoke/invoke-service.js +157 -0
  87. package/dist/core/invoke/style-router.js +48 -0
  88. package/dist/core/invoke/types.js +19 -0
  89. package/dist/core/ipc-registration.js +51 -11
  90. package/dist/core/lifecycle-notice.js +10 -4
  91. package/dist/core/memory/consolidation.js +7 -5
  92. package/dist/core/message/aun-ipc-sender.js +149 -19
  93. package/dist/core/message/im-renderer.js +28 -84
  94. package/dist/core/message/message-bridge.js +57 -4
  95. package/dist/core/message/message-queue.js +46 -4
  96. package/dist/core/message/message-utils.js +10 -2
  97. package/dist/core/message/peer-mode.js +7 -34
  98. package/dist/core/message/pending-hints.js +4 -10
  99. package/dist/core/message/response-engine.js +163 -52
  100. package/dist/core/message/send-options.js +7 -4
  101. package/dist/core/message/send-routing.js +55 -7
  102. package/dist/core/ownership/owner-resolver.js +8 -0
  103. package/dist/core/permission/ec-command-parser.js +14 -3
  104. package/dist/core/permission/protected-paths.js +12 -2
  105. package/dist/core/permission/shell-environment.js +9 -0
  106. package/dist/core/session/adapters/claude-session-file-adapter.js +24 -0
  107. package/dist/core/session/adapters/codex-session-file-adapter.js +80 -0
  108. package/dist/core/session/adapters/ecagent-session-file-adapter.js +22 -0
  109. package/dist/core/session/adapters/gemini-session-file-adapter.js +39 -0
  110. package/dist/core/session/session-file-health.js +243 -0
  111. package/dist/core/session/session-fs-store.js +163 -3
  112. package/dist/core/session/session-idle-monitor.js +9 -1
  113. package/dist/core/session/session-manager.js +36 -2
  114. package/dist/core/task/task-recovery-service.js +13 -2
  115. package/dist/core/thread/command-parser.js +9 -2
  116. package/dist/core/thread/thread-operation.js +21 -2
  117. package/dist/core/thread/thread-route.js +13 -2
  118. package/dist/directory/owner-directory-admission.js +42 -30
  119. package/dist/directory/owner-directory-cache.js +143 -126
  120. package/dist/directory/owner-directory-query-operation.js +9 -8
  121. package/dist/eck/kit-renderer.js +7 -5
  122. package/dist/ecweb/basic-settings-service.js +1 -1
  123. package/dist/ecweb/message-context-service.js +0 -4
  124. package/dist/ecweb/runtime/lifecycle.js +14 -8
  125. package/dist/ecweb/runtime/supervisor.js +62 -30
  126. package/dist/event-center/admission-materializer.js +114 -0
  127. package/dist/event-center/bus-gate.js +136 -0
  128. package/dist/event-center/bus-host.js +290 -0
  129. package/dist/event-center/bus-resolver.js +120 -0
  130. package/dist/event-center/center-config.js +100 -0
  131. package/dist/event-center/client-factory.js +50 -0
  132. package/dist/event-center/daemon.js +45 -0
  133. package/dist/event-center/directory-source.js +53 -0
  134. package/dist/event-center/dispatcher.js +157 -0
  135. package/dist/event-center/event-log.js +110 -0
  136. package/dist/event-center/index-generator.js +63 -0
  137. package/dist/event-center/ipc-operation.js +308 -0
  138. package/dist/event-center/ledger.js +52 -0
  139. package/dist/event-center/pack-loader.js +202 -0
  140. package/dist/event-center/pack-manager.js +85 -0
  141. package/dist/event-center/registry.js +238 -0
  142. package/dist/event-center/runtime.js +641 -0
  143. package/dist/event-center/script-runner.js +356 -0
  144. package/dist/event-center/types.js +35 -0
  145. package/dist/event-center/validation.js +413 -0
  146. package/dist/index.js +751 -268
  147. package/dist/ipc.js +66 -12
  148. package/dist/paths.js +20 -0
  149. package/dist/product.js +14 -0
  150. package/dist/proxy/manager.js +43 -18
  151. package/dist/proxy/service-supervisor.js +78 -35
  152. package/dist/response-system/engines/v1/index.js +0 -1
  153. package/dist/response-system/modes/single-session/index.js +1 -1
  154. package/dist/services/dispatcher.js +100 -0
  155. package/dist/services/idempotency.js +90 -0
  156. package/dist/services/identity.js +52 -0
  157. package/dist/services/index-generator.js +70 -0
  158. package/dist/services/index.js +449 -0
  159. package/dist/services/ipc-operation.js +458 -0
  160. package/dist/services/ledger.js +52 -0
  161. package/dist/services/message-log.js +112 -0
  162. package/dist/services/pack-manager.js +204 -0
  163. package/dist/services/reply.js +55 -0
  164. package/dist/services/router.js +95 -0
  165. package/dist/services/script-runner.js +422 -0
  166. package/dist/services/service-payload.js +70 -0
  167. package/dist/services/types.js +18 -0
  168. package/dist/services/validation.js +297 -0
  169. package/dist/trigger/application-service.js +21 -1
  170. package/dist/trigger/audit.js +19 -4
  171. package/dist/trigger/authorization.js +14 -5
  172. package/dist/trigger/event-source.js +1 -1
  173. package/dist/trigger/history.js +176 -7
  174. package/dist/trigger/ipc-service.js +3 -1
  175. package/dist/trigger/manager.js +1 -3
  176. package/dist/trigger/scheduler.js +78 -5
  177. package/dist/trigger/script-sandbox.js +118 -22
  178. package/dist/utils/cross-platform.js +175 -13
  179. package/dist/utils/evolcore-version.js +69 -27
  180. package/dist/utils/host-info.js +11 -8
  181. package/dist/utils/instance-registry.js +19 -13
  182. package/dist/utils/npm-ops.js +48 -0
  183. package/dist/utils/process-introspect.js +109 -10
  184. package/dist/utils/startup-trace.js +222 -44
  185. package/dist/utils/windows-shell-trust.js +80 -6
  186. package/kits/docs/INDEX.md +2 -2
  187. package/kits/docs/aun/ABILITY_CALLING.md +10 -17
  188. package/kits/docs/context-assembly.md +1 -1
  189. package/kits/docs/evolcore/INDEX.md +5 -2
  190. package/kits/docs/evolcore/ability.md +4 -0
  191. package/kits/docs/evolcore/aid.md +1 -1
  192. package/kits/docs/evolcore/ctl.md +2 -1
  193. package/kits/docs/evolcore/event-center.md +207 -0
  194. package/kits/docs/evolcore/file-navigation.md +10 -264
  195. package/kits/docs/evolcore/fs.md +3 -2
  196. package/kits/docs/evolcore/group.md +2 -2
  197. package/kits/docs/evolcore/memory-architecture.md +2 -0
  198. package/kits/docs/evolcore/menu-exec-schema-commands.md +1 -1
  199. package/kits/docs/evolcore/menu-protocol.md +21 -0
  200. package/kits/docs/evolcore/msg.md +27 -8
  201. package/kits/docs/evolcore/provider.md +23 -3
  202. package/kits/docs/evolcore/response.md +5 -5
  203. package/kits/docs/evolcore/services.md +277 -0
  204. package/kits/docs/evolcore/task.md +2 -0
  205. package/kits/docs/evolcore/team-workspace.md +41 -0
  206. package/kits/eck_manifest.json +45 -7
  207. package/kits/eck_message_manifest.json +3 -3
  208. package/kits/rules/02-navigation.md +10 -1
  209. package/kits/rules/06-channel.md +5 -6
  210. package/kits/schemas/_meta.json +17 -6
  211. package/kits/schemas/agent-config.schema.19.json +5 -7
  212. package/kits/schemas/agent-config.schema.20.json +936 -0
  213. package/kits/schemas/daemon.schema.1.json +5 -0
  214. package/kits/schemas/daemon.schema.2.json +5 -0
  215. package/kits/schemas/daemon.schema.3.json +2 -1
  216. package/kits/schemas/daemon.schema.4.json +2 -1
  217. package/kits/schemas/daemon.schema.5.json +2 -1
  218. package/kits/schemas/daemon.schema.6.json +1 -1
  219. package/kits/schemas/daemon.schema.7.json +1 -1
  220. package/kits/schemas/daemon.schema.8.json +2 -1
  221. package/kits/schemas/daemon.schema.9.json +2 -1
  222. package/kits/schemas/relation-config.schema.12.json +2 -3
  223. package/kits/schemas/role-config.schema.2.json +4 -4
  224. package/kits/schemas/role-registry.schema.1.json +2 -2
  225. package/kits/schemas/single-session.schema.1.json +1 -1
  226. package/kits/schemas/single-session.schema.2.json +1 -1
  227. package/kits/schemas/single-session.schema.3.json +1 -1
  228. package/kits/skills/.switches.json +1 -5
  229. package/kits/skills/ability/SKILL.md +56 -0
  230. package/kits/skills/ability/references/calling.md +56 -0
  231. package/kits/skills/{ec-ability → ability}/references/contract-checklist.md +1 -1
  232. package/kits/skills/{ec-ability → ability}/references/development.md +9 -33
  233. package/kits/skills/{ec-ability → ability}/references/management.md +2 -2
  234. package/kits/skills/{ec-ability → ability}/references/recovery.md +1 -1
  235. package/kits/skills/{ec-ability → ability}/references/runtime-protocol.md +2 -0
  236. package/kits/skills/ec-agent-create/SKILL.md +0 -1
  237. package/kits/skills/ec-group/SKILL.md +8 -5
  238. package/kits/skills/ec-group-collaboration/SKILL.md +7 -7
  239. package/kits/skills/ec-service-proxy/SKILL.md +34 -5
  240. package/kits/skills/ec-trigger/SKILL.md +4 -4
  241. package/kits/skills/personal-assistant/SKILL.md +6 -6
  242. package/kits/skills/personal-assistant/references/02-bootstrap.md +4 -4
  243. package/kits/skills/personal-assistant/scripts/clean.mjs +4 -4
  244. package/kits/skills/personal-assistant/scripts/init.mjs +2 -2
  245. package/kits/skills/personal-assistant/scripts/pa.mjs +4 -4
  246. package/kits/skills/thread-ops/SKILL.md +10 -10
  247. package/kits/templates/system-fragments/channel.md +3 -3
  248. package/kits/templates/system-fragments/commands.md +9 -7
  249. package/kits/templates/system-fragments/reply.md +2 -6
  250. package/kits/templates/system-fragments/session.md +1 -1
  251. package/kits/templates/system-fragments/thread.md +11 -9
  252. package/package.json +5 -6
  253. package/dist/cli/pa-workspace-command.js +0 -225
  254. package/dist/core/command/pa-workspace-store.js +0 -468
  255. package/dist/core/relation/pa-team.js +0 -132
  256. package/kits/docs/evolcore/pa-workspace.md +0 -51
  257. package/kits/skills/aid-ability/SKILL.md +0 -244
  258. package/kits/skills/ec-ability/SKILL.md +0 -67
  259. package/kits/skills/ec-ability/references/workflows.md +0 -15
@@ -5,9 +5,11 @@ import { execFileSync, execFile, spawn, spawnSync } from 'child_process';
5
5
  import { promisify, TextDecoder } from 'util';
6
6
  import fs from 'fs';
7
7
  import { getProcessStartTime, parseCimDate } from './process-introspect.js';
8
- import { resolveTrustedWindowsCmdPath } from './windows-shell-trust.js';
8
+ import { resolveTrustedWindowsCmdPath, resolveTrustedWindowsCmdPathAsync } from './windows-shell-trust.js';
9
9
  const execFileAsync = promisify(execFile);
10
10
  const CLI_PROBE_FAILURE_BACKOFF_MS = 5_000;
11
+ export const CODEX_CLI_PROBE_TIMEOUT_MS = 9_000;
12
+ export const CODEX_CLI_PROBE_RETRY_TIMEOUT_MS = 15_000;
11
13
  const CLI_PROBE_PACKAGES = {
12
14
  codex: '@openai/codex',
13
15
  claude: '@anthropic-ai/claude-code',
@@ -184,20 +186,61 @@ export function invalidateCliProbes() {
184
186
  cliProbeCache.clear();
185
187
  }
186
188
  function cliProbeTimeouts(command, options) {
187
- return options.timeouts?.length ? options.timeouts : command === 'codex' ? [3_000, 15_000] : [3_000];
189
+ return options.timeouts?.length ? options.timeouts : command === 'codex'
190
+ ? [CODEX_CLI_PROBE_TIMEOUT_MS, CODEX_CLI_PROBE_RETRY_TIMEOUT_MS] : [3_000];
188
191
  }
189
- function prepareCliProbe(command, args, options = {}) {
192
+ /** The stock npm shim adds cmd + node before Codex, outside a reliable Windows timeout. */
193
+ function codexProbeExecutable(executable) {
194
+ if (!isWindows || !/\.(?:cmd|bat)$/i.test(executable))
195
+ return executable;
196
+ try {
197
+ const shim = fs.readFileSync(executable, 'utf8');
198
+ // Preserve custom launchers. Only the stock npm entry for this installation
199
+ // may be shortened for read-only --version/app-server --help probes.
200
+ if (!/^@ECHO off\r?\nGOTO start\r?\n/i.test(shim)
201
+ || !shim.includes('%dp0%\\node_modules\\@openai\\codex\\bin\\codex.js'))
202
+ return executable;
203
+ const packageFile = path.join(path.dirname(executable), 'node_modules', '@openai', 'codex', 'package.json');
204
+ const manifest = JSON.parse(fs.readFileSync(packageFile, 'utf8'));
205
+ if (manifest.name !== '@openai/codex' || manifest.bin?.codex !== 'bin/codex.js')
206
+ return executable;
207
+ const arch = process.arch === 'x64' ? 'x86_64' : process.arch === 'arm64' ? 'aarch64' : null;
208
+ if (!arch)
209
+ return executable;
210
+ let vendorRoot;
211
+ try {
212
+ const platformFile = createRequire(packageFile).resolve(`@openai/codex-win32-${process.arch}/package.json`);
213
+ vendorRoot = path.join(path.dirname(platformFile), 'vendor');
214
+ }
215
+ catch {
216
+ vendorRoot = path.join(path.dirname(packageFile), 'vendor');
217
+ }
218
+ const binary = path.join(vendorRoot, `${arch}-pc-windows-msvc`, 'bin', 'codex.exe');
219
+ if (fs.statSync(binary).isFile())
220
+ return binary;
221
+ }
222
+ catch { /* Incomplete or non-npm installations retain their configured entrypoint. */ }
223
+ return executable;
224
+ }
225
+ function resolveCliProbe(command, args, options) {
190
226
  const executable = options.executable ?? resolveProbePath(command);
191
227
  if (!executable)
192
228
  throw Object.assign(new Error(`${command} CLI not found`), { code: 'ENOENT' });
193
- const launchCommand = buildCliLaunchCommand(executable, args);
229
+ const probeExecutable = command === 'codex'
230
+ && (args.length === 1 && args[0] === '--version'
231
+ || args.length === 2 && args[0] === 'app-server' && args[1] === '--help')
232
+ ? codexProbeExecutable(executable) : executable;
233
+ return { executable, probeExecutable };
234
+ }
235
+ function prepareCliProbe(command, args, options = {}, resolved = resolveCliProbe(command, args, options), resolveWindowsCmd) {
236
+ const launchCommand = buildCliLaunchCommand(resolved.probeExecutable, args, { resolveWindowsCmd });
194
237
  const launch = launchCommand;
195
- const identity = `${probeInstallationIdentity(command, executable)}|${cliFileIdentity(launch.launcherPath)}`;
238
+ const identity = `${probeInstallationIdentity(command, resolved.executable)}|${cliFileIdentity(launch.launcherPath)}`;
196
239
  const key = JSON.stringify([command, args]);
197
240
  let entry = cliProbeCache.get(key);
198
241
  if (!entry || entry.identity !== identity || (entry.retryAt !== undefined && Date.now() >= entry.retryAt)
199
242
  || (entry.output !== undefined && options.validateOutput && !options.validateOutput(entry.output))) {
200
- entry = { identity };
243
+ entry = { identity, launcherPath: launch.launcherPath };
201
244
  cliProbeCache.set(key, entry);
202
245
  }
203
246
  return {
@@ -250,7 +293,13 @@ export function probeCliSync(command, args, options = {}) {
250
293
  throw new Error('CLI probe exhausted');
251
294
  }
252
295
  export async function probeCli(command, args, options = {}) {
253
- const request = prepareCliProbe(command, args, options);
296
+ const resolved = resolveCliProbe(command, args, options);
297
+ let resolveWindowsCmd;
298
+ if (isWindows && /\.(?:cmd|bat)$/i.test(resolved.probeExecutable)) {
299
+ const trustedCmd = await resolveTrustedWindowsCmdPathAsync();
300
+ resolveWindowsCmd = () => trustedCmd;
301
+ }
302
+ const request = prepareCliProbe(command, args, options, resolved, resolveWindowsCmd);
254
303
  if (request.entry.output !== undefined)
255
304
  return request.entry.output;
256
305
  if (request.entry.error !== undefined)
@@ -312,9 +361,14 @@ export async function probeCli(command, args, options = {}) {
312
361
  /** Non-blocking version lookup used by status menus. */
313
362
  export function cachedCliVersion(command) {
314
363
  try {
315
- const { entry } = prepareCliProbe(command, ['--version']);
316
- if (entry.output !== undefined)
364
+ const executable = resolveProbePath(command);
365
+ if (!executable)
366
+ return null;
367
+ const entry = cliProbeCache.get(JSON.stringify([command, ['--version']]));
368
+ if (entry?.output !== undefined
369
+ && entry.identity === `${probeInstallationIdentity(command, executable)}|${cliFileIdentity(entry.launcherPath)}`) {
317
370
  return entry.output.match(/\b\d+\.\d+\.\d+(?:[-+][\w.-]+)?/)?.[0] ?? null;
371
+ }
318
372
  void probeCli(command, ['--version']).catch(() => { });
319
373
  }
320
374
  catch { /* Missing CLI. */ }
@@ -731,6 +785,42 @@ export function isProcessRunning(pid) {
731
785
  return e.code === 'EPERM';
732
786
  }
733
787
  }
788
+ const processLivenessQueries = new Map();
789
+ /** Share concurrent Windows probes, but never cache liveness across checks. */
790
+ export async function isProcessRunningAsync(pid) {
791
+ if (!Number.isInteger(pid) || pid <= 0)
792
+ return false;
793
+ if (!isWindows)
794
+ return isProcessRunning(pid);
795
+ const pending = processLivenessQueries.get(pid);
796
+ if (pending)
797
+ return pending;
798
+ const query = (async () => {
799
+ try {
800
+ const { stdout } = await execFileAsync('tasklist', ['/FI', `PID eq ${pid}`, '/FO', 'CSV', '/NH'], {
801
+ encoding: 'utf8', timeout: 3000, windowsHide: true,
802
+ });
803
+ if (new RegExp(`,"${pid}",`, 'i').test(stdout))
804
+ return true;
805
+ }
806
+ catch { /* Retain the conservative native fallback on query failure. */ }
807
+ try {
808
+ process.kill(pid, 0);
809
+ return true;
810
+ }
811
+ catch (error) {
812
+ return error.code === 'EPERM';
813
+ }
814
+ })();
815
+ processLivenessQueries.set(pid, query);
816
+ try {
817
+ return await query;
818
+ }
819
+ finally {
820
+ if (processLivenessQueries.get(pid) === query)
821
+ processLivenessQueries.delete(pid);
822
+ }
823
+ }
734
824
  function isWindowsProcessRunning(pid) {
735
825
  try {
736
826
  const result = spawnSync('tasklist', ['/FI', `PID eq ${pid}`, '/FO', 'CSV', '/NH'], { encoding: 'utf-8', timeout: 3000, stdio: ['ignore', 'pipe', 'ignore'], windowsHide: true });
@@ -833,11 +923,11 @@ export function killProcessTree(pid, force = false) {
833
923
  export async function waitForProcessExit(pid, timeoutMs = 10_000, intervalMs = 250) {
834
924
  const deadline = Date.now() + timeoutMs;
835
925
  while (Date.now() < deadline) {
836
- if (!isProcessRunning(pid))
926
+ if (!await isProcessRunningAsync(pid))
837
927
  return true;
838
928
  await new Promise(resolve => setTimeout(resolve, intervalMs));
839
929
  }
840
- return !isProcessRunning(pid);
930
+ return !await isProcessRunningAsync(pid);
841
931
  }
842
932
  /**
843
933
  * Cross-platform process search by command line pattern.
@@ -909,7 +999,7 @@ export function findProcessByPort(port) {
909
999
  const pids = new Set();
910
1000
  try {
911
1001
  if (isWindows) {
912
- const result = spawnSync('netstat', ['-ano', '-p', 'TCP'], { encoding: 'utf-8', windowsHide: true });
1002
+ const result = spawnSync('netstat', ['-ano', '-p', 'TCP'], { encoding: 'utf-8', windowsHide: true, timeout: 3000 });
913
1003
  const output = result.stdout || '';
914
1004
  for (const line of output.split('\n')) {
915
1005
  // 形如: TCP 0.0.0.0:42705 0.0.0.0:0 LISTENING 23004
@@ -924,7 +1014,7 @@ export function findProcessByPort(port) {
924
1014
  }
925
1015
  }
926
1016
  else {
927
- const output = execFileSync('lsof', ['-ti', `tcp:${port}`, '-sTCP:LISTEN'], { encoding: 'utf-8' }).trim();
1017
+ const output = execFileSync('lsof', ['-ti', `tcp:${port}`, '-sTCP:LISTEN'], { encoding: 'utf-8', timeout: 3000 }).trim();
928
1018
  for (const line of output.split('\n')) {
929
1019
  const pid = parseInt(line.trim(), 10);
930
1020
  if (pid && pid !== process.pid)
@@ -935,6 +1025,55 @@ export function findProcessByPort(port) {
935
1025
  catch { /* netstat/lsof missing or no match */ }
936
1026
  return [...pids];
937
1027
  }
1028
+ let tcpListenersQuery;
1029
+ /**
1030
+ * Share concurrent Windows port scans, without retaining stale ownership data.
1031
+ * Missing optional lsof yields no known PIDs; callers must still bind/probe the service.
1032
+ */
1033
+ export async function findProcessByPortAsync(port) {
1034
+ if (!Number.isInteger(port) || port < 1 || port > 65535)
1035
+ throw new Error('Invalid TCP port');
1036
+ let output;
1037
+ if (isWindows) {
1038
+ const query = tcpListenersQuery ??= execFileAsync('netstat', ['-ano', '-p', 'TCP'], {
1039
+ encoding: 'utf8', windowsHide: true, timeout: 3000, maxBuffer: 4 * 1024 * 1024,
1040
+ }).then(result => result.stdout);
1041
+ try {
1042
+ output = (await query) ?? '';
1043
+ }
1044
+ finally {
1045
+ if (tcpListenersQuery === query)
1046
+ tcpListenersQuery = undefined;
1047
+ }
1048
+ }
1049
+ else {
1050
+ try {
1051
+ output = ((await execFileAsync('lsof', ['-ti', `tcp:${port}`, '-sTCP:LISTEN'], {
1052
+ encoding: 'utf8', timeout: 3000,
1053
+ })).stdout ?? '');
1054
+ }
1055
+ catch (error) {
1056
+ const detail = error;
1057
+ // lsof is optional on Unix, as in the synchronous port lookup.
1058
+ if (detail.code === 'ENOENT')
1059
+ return [];
1060
+ // lsof uses exit 1, with no output, to report an empty selection.
1061
+ if (detail.code === 1 && !detail.stdout?.trim() && !detail.stderr?.trim())
1062
+ return [];
1063
+ throw error;
1064
+ }
1065
+ }
1066
+ const pids = new Set();
1067
+ for (const line of output.split('\n')) {
1068
+ const match = isWindows ? line.match(/:(\d+)\s+\S+\s+LISTENING\s+(\d+)/i) : null;
1069
+ if (isWindows && (!match || Number(match[1]) !== port))
1070
+ continue;
1071
+ const pid = Number(isWindows ? match[2] : line.trim());
1072
+ if (Number.isInteger(pid) && pid > 0 && pid !== process.pid)
1073
+ pids.add(pid);
1074
+ }
1075
+ return [...pids];
1076
+ }
938
1077
  export function getProcessInfo(pid) {
939
1078
  try {
940
1079
  if (isWindows) {
@@ -1014,6 +1153,29 @@ function parseDateString(value) {
1014
1153
  * Cross-platform command existence check.
1015
1154
  */
1016
1155
  const _commandExistsCache = new Map();
1156
+ const commandExistsPending = new Map();
1157
+ /** Daemon inventory probes must not block IPC on where/which. */
1158
+ export async function commandExistsAsync(cmd) {
1159
+ const cached = _commandExistsCache.get(cmd);
1160
+ if (cached !== undefined)
1161
+ return cached;
1162
+ const existing = commandExistsPending.get(cmd);
1163
+ if (existing)
1164
+ return existing;
1165
+ const pending = execFileAsync(isWindows ? 'where.exe' : 'which', [cmd], {
1166
+ encoding: 'utf8', windowsHide: true, timeout: 3_000,
1167
+ }).then(() => true, () => false);
1168
+ commandExistsPending.set(cmd, pending);
1169
+ try {
1170
+ const exists = await pending;
1171
+ _commandExistsCache.set(cmd, exists);
1172
+ return exists;
1173
+ }
1174
+ finally {
1175
+ if (commandExistsPending.get(cmd) === pending)
1176
+ commandExistsPending.delete(cmd);
1177
+ }
1178
+ }
1017
1179
  export function commandExists(cmd) {
1018
1180
  const cached = _commandExistsCache.get(cmd);
1019
1181
  if (cached !== undefined)
@@ -189,39 +189,81 @@ export function readBuildIdentity(distDir, version) {
189
189
  ...(version ? { version } : {}),
190
190
  };
191
191
  }
192
- export function reportEvolcoreStartup(entryUrl, report) {
193
- const packageRoot = getPackageRoot();
194
- const runtimeEntry = fileURLToPath(entryUrl);
195
- const diskDistDir = path.join(packageRoot, 'dist');
196
- const runtimeIsDist = path.resolve(path.dirname(runtimeEntry)) === path.resolve(diskDistDir);
197
- const runtimeBuildIdentity = readBuildIdentity(runtimeIsDist ? path.dirname(runtimeEntry) : diskDistDir, readInstalledEvolcoreVersion());
198
- const diskDistId = runtimeBuildIdentity.id;
199
- if (!runtimeIsDist)
200
- runtimeBuildIdentity.id = null;
201
- const isLinked = fs.existsSync(path.join(packageRoot, '.git'));
202
- const directoryType = runtimeIsDist ? (isLinked ? '开发仓/dist' : '安装路径/dist') : '源码(tsx)';
203
- const scanDir = runtimeIsDist ? path.join(packageRoot, 'dist') : path.join(packageRoot, 'src');
192
+ /** Keep the same content hash as computeBuildId without blocking the event loop. */
193
+ async function readBuildTreeAsync(root, hashFiles = true) {
204
194
  let latestMtime = 0;
205
- const scanRecursive = (directory) => {
206
- try {
207
- for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
208
- if (entry.name === 'node_modules')
195
+ try {
196
+ const files = [];
197
+ const collect = async (directory) => {
198
+ const entries = await fs.promises.readdir(directory, { withFileTypes: true });
199
+ for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {
200
+ if (!hashFiles && entry.name === 'node_modules')
209
201
  continue;
210
202
  const full = path.join(directory, entry.name);
211
- if (entry.isDirectory()) {
212
- scanRecursive(full);
213
- continue;
214
- }
215
- if (entry.name.endsWith('.js') || entry.name.endsWith('.ts')) {
216
- const modifiedAt = fs.statSync(full).mtimeMs;
217
- if (modifiedAt > latestMtime)
218
- latestMtime = modifiedAt;
203
+ if (entry.isDirectory())
204
+ await collect(full);
205
+ else if (entry.isFile())
206
+ files.push(full);
207
+ }
208
+ };
209
+ await collect(root);
210
+ const hash = crypto.createHash('sha256');
211
+ for (let offset = 0; offset < files.length; offset += 8) {
212
+ const batch = await Promise.all(files.slice(offset, offset + 8).map(async (file) => {
213
+ const [content, stat] = await Promise.all([
214
+ hashFiles ? fs.promises.readFile(file) : undefined,
215
+ /\.(js|ts)$/.test(file) ? fs.promises.stat(file) : undefined,
216
+ ]);
217
+ return { file, content, stat };
218
+ }));
219
+ for (const { file, content, stat } of batch) {
220
+ if (stat)
221
+ latestMtime = Math.max(latestMtime, stat.mtimeMs);
222
+ if (content) {
223
+ hash.update(path.relative(root, file).replaceAll(path.sep, '/'));
224
+ hash.update('\0');
225
+ hash.update(content);
226
+ hash.update('\0');
219
227
  }
220
228
  }
221
229
  }
222
- catch { }
230
+ return { id: hashFiles ? `sha256:${hash.digest('hex').slice(0, 24)}` : null, latestMtime };
231
+ }
232
+ catch {
233
+ return { id: null, latestMtime };
234
+ }
235
+ }
236
+ /** Cheap initial status; the full build identity is published after hashing. */
237
+ export function createEvolcoreStartupDiagnostics(entryUrl) {
238
+ const packageRoot = getPackageRoot();
239
+ const runtimeEntry = fileURLToPath(entryUrl);
240
+ const diskDistDir = path.join(packageRoot, 'dist');
241
+ const runtimeIsDist = path.resolve(path.dirname(runtimeEntry)) === path.resolve(diskDistDir);
242
+ return {
243
+ state: 'pending', runtimeIsDist, diskDistDir, diskDistId: null,
244
+ runtimeBuildIdentity: { id: null, entry: path.join(diskDistDir, 'index.js'), version: readInstalledEvolcoreVersion() },
245
+ };
246
+ }
247
+ export async function reportEvolcoreStartup(entryUrl, report, diagnostics = createEvolcoreStartupDiagnostics(entryUrl)) {
248
+ const packageRoot = getPackageRoot();
249
+ const { runtimeIsDist, diskDistDir } = diagnostics;
250
+ const [dist, source] = await Promise.all([
251
+ readBuildTreeAsync(diskDistDir),
252
+ runtimeIsDist ? undefined : readBuildTreeAsync(path.join(packageRoot, 'src'), false),
253
+ ]);
254
+ const diskDistId = dist.id;
255
+ const runtimeBuildIdentity = {
256
+ id: runtimeIsDist ? diskDistId : null,
257
+ entry: path.join(diskDistDir, 'index.js'),
258
+ version: readInstalledEvolcoreVersion(),
223
259
  };
224
- scanRecursive(scanDir);
260
+ // Publish both IDs together. Pending/failed reads must never claim a match.
261
+ Object.assign(diagnostics, {
262
+ state: diskDistId === null ? 'unavailable' : 'ready', runtimeBuildIdentity, diskDistId,
263
+ });
264
+ const isLinked = fs.existsSync(path.join(packageRoot, '.git'));
265
+ const directoryType = runtimeIsDist ? (isLinked ? '开发仓/dist' : '安装路径/dist') : '源码(tsx)';
266
+ const latestMtime = source?.latestMtime ?? dist.latestMtime;
225
267
  let version = '?';
226
268
  try {
227
269
  version = JSON.parse(fs.readFileSync(path.join(packageRoot, 'package.json'), 'utf-8')).version;
@@ -240,5 +282,5 @@ export function reportEvolcoreStartup(entryUrl, report) {
240
282
  console.error(`[EvolCore] 运行 build ID: ${runtimeIsDist ? (runtimeBuildIdentity.id ?? '?') : 'source'}`);
241
283
  console.error(`[EvolCore] 磁盘 dist build ID: ${diskBuildId ?? '?'}`);
242
284
  report(`[Build] runtimeMode=${runtimeIsDist ? 'dist' : 'source'} runtimeBuildId=${runtimeBuildIdentity.id ?? 'source'} diskDistBuildId=${diskBuildId ?? 'unknown'} match=${runtimeIsDist && runtimeBuildIdentity.id !== null && runtimeBuildIdentity.id === diskBuildId}`);
243
- return { runtimeIsDist, runtimeBuildIdentity, diskDistDir, diskDistId };
285
+ return diagnostics;
244
286
  }
@@ -17,7 +17,7 @@ import { execFile } from 'node:child_process';
17
17
  import { readSystemMemoryUsage } from './system-memory.js';
18
18
  import { getPackageRoot } from '../paths.js';
19
19
  import { WEB_PACKAGE_NAME } from '../product.js';
20
- import { buildCliLaunchCommand, resolveProbePath } from './cross-platform.js';
20
+ import { probeCli, resolveProbePath } from './cross-platform.js';
21
21
  function readJsonVersion(filePath) {
22
22
  try {
23
23
  const pkg = JSON.parse(fs.readFileSync(filePath, 'utf8'));
@@ -195,8 +195,8 @@ function runExec(command, args, timeoutMs, windowsVerbatimArguments = false) {
195
195
  * 按 PATH 探测一个 CLI 的版本。
196
196
  *
197
197
  * 不能直接 execFile('claude'):Windows 上 npm 装的是 claude.cmd,Node 25 对 .cmd
198
- * 直接 spawn 会报 EINVAL。走 resolveProbePath + buildCliLaunchCommand,与
199
- * baseagent 探测同一套启动规则(.cmd 经受信任的 cmd.exe 转发)。
198
+ * 直接 spawn 会报 EINVAL。复用 baseagent 的探测缓存和在途请求,保留原生
199
+ * Codex 入口探测及 .cmd 经受信任 cmd.exe 转发的规则。
200
200
  */
201
201
  async function probeCliVersion(command, args, timeoutMs) {
202
202
  try {
@@ -207,9 +207,10 @@ async function probeCliVersion(command, args, timeoutMs) {
207
207
  const raw = await runExec(command, args, timeoutMs);
208
208
  return raw.ok ? firstVersionLine(raw.stdout) : null;
209
209
  }
210
- const launch = buildCliLaunchCommand(executable, args);
211
- const result = await runExec(launch.command, launch.args, timeoutMs, launch.windowsVerbatimArguments);
212
- return result.ok ? firstVersionLine(result.stdout) : null;
210
+ const output = await probeCli(command, args, {
211
+ executable, timeouts: [timeoutMs], validateOutput: value => firstVersionLine(value) !== null,
212
+ });
213
+ return firstVersionLine(output);
213
214
  }
214
215
  catch {
215
216
  return null;
@@ -299,8 +300,10 @@ async function probeBundledClaudeVersion() {
299
300
  const executable = resolveBundledClaudeExecutable();
300
301
  if (!executable)
301
302
  return null;
302
- const result = await runExec(executable, ['--version'], 8000);
303
- return result.ok ? firstVersionLine(result.stdout) : null;
303
+ const output = await probeCli('bundled-claude', ['--version'], {
304
+ executable, timeouts: [8000], validateOutput: value => firstVersionLine(value) !== null,
305
+ });
306
+ return firstVersionLine(output);
304
307
  }
305
308
  catch {
306
309
  return null;
@@ -33,14 +33,14 @@ function safeParseJson(filePath) {
33
33
  return null;
34
34
  }
35
35
  }
36
- function lazySnapshot() {
37
- let cached = null;
36
+ function lazySnapshot(initial) {
37
+ let cached = initial ?? null;
38
38
  return {
39
39
  get() {
40
40
  cached ??= getProcessSnapshot();
41
41
  return cached;
42
42
  },
43
- taken: () => cached !== null,
43
+ provided: () => initial !== undefined,
44
44
  };
45
45
  }
46
46
  /**
@@ -56,6 +56,12 @@ function isAlive(pid, recordedStartedAt, snapshot) {
56
56
  const actual = getProcessStartTime(pid);
57
57
  return actual === null ? true : startTimeMatches(recordedStartedAt, actual);
58
58
  }
59
+ // A caller-scoped snapshot already covers this phase; avoid one tasklist per record.
60
+ if (snapshot.provided()) {
61
+ const verdict = snapshotProcessState(snapshot.get(), pid, recordedStartedAt);
62
+ if (verdict !== 'unknown')
63
+ return verdict === 'alive';
64
+ }
59
65
  // 廉价前置探测:不存在就直接判定为死,省掉整张进程表。
60
66
  if (!isProcessRunning(pid))
61
67
  return false;
@@ -115,7 +121,7 @@ export function removeMain(pid) {
115
121
  * @returns 当前进程是否赢家。false 表示应该让出(删自己的 record + exit)。
116
122
  */
117
123
  export function isMainWinner() {
118
- const status = scanInstances();
124
+ const status = scanInstances({ kind: 'main', includeAidActivity: false });
119
125
  const aliveMains = status.mains.filter(m => m.alive);
120
126
  if (aliveMains.length <= 1)
121
127
  return { winner: true };
@@ -173,7 +179,7 @@ export function removeRestartMonitor(pid) {
173
179
  * Post-write 自检:与 isMainWinner 同语义,用于 restart-monitor。
174
180
  */
175
181
  export function isRestartMonitorWinner() {
176
- const status = scanInstances();
182
+ const status = scanInstances({ kind: 'restart-monitor', includeAidActivity: false });
177
183
  const alive = status.restartMonitors.filter(m => m.alive);
178
184
  if (alive.length <= 1)
179
185
  return { winner: true };
@@ -243,10 +249,10 @@ export function readAidLastActivity(pid) {
243
249
  *
244
250
  * 损坏的 JSON 文件直接删除。aid-*.jsonl 在 scan 时不解析,由调用方按需读取。
245
251
  */
246
- export function scanInstances() {
252
+ export function scanInstances(options = {}) {
247
253
  // 惰性快照:每条记录先做廉价的单 pid 存活探测,只有确实活着才需要整张进程表。
248
254
  // 启动路径上绝大多数时候目录里只有本进程的记录或已死记录,这样可省掉约 0.45s。
249
- const snapshot = lazySnapshot();
255
+ const snapshot = lazySnapshot(options.processSnapshot);
250
256
  const status = {
251
257
  mains: [],
252
258
  restartMonitors: [],
@@ -264,12 +270,12 @@ export function scanInstances() {
264
270
  }
265
271
  for (const file of files) {
266
272
  const filePath = path.join(dir, file);
267
- if (file.startsWith('main-') && file.endsWith('.json')) {
273
+ if (file.startsWith('main-') && file.endsWith('.json') && options.kind !== 'restart-monitor') {
268
274
  const record = safeParseJson(filePath);
269
275
  if (record && record.pid && record.startedAt) {
270
276
  const alive = isAlive(record.pid, record.startedAt, snapshot);
271
277
  status.mains.push({ record, alive });
272
- if (alive) {
278
+ if (alive && options.includeAidActivity !== false) {
273
279
  // 合并所有活 main 的 AID 活动记录(按 ts 取最新)
274
280
  for (const [aid, info] of readAidLastActivity(record.pid)) {
275
281
  const prev = status.aidLastActivity.get(aid);
@@ -286,7 +292,7 @@ export function scanInstances() {
286
292
  catch { }
287
293
  }
288
294
  }
289
- else if (file.startsWith('restart-monitor-') && file.endsWith('.json')) {
295
+ else if (file.startsWith('restart-monitor-') && file.endsWith('.json') && options.kind !== 'main') {
290
296
  const record = safeParseJson(filePath);
291
297
  if (record && record.pid && record.startedAt) {
292
298
  const alive = isAlive(record.pid, record.startedAt, snapshot);
@@ -428,7 +434,7 @@ export function isEvolCoreMainCommand(cmdline, packageRoot = getPackageRoot()) {
428
434
  *
429
435
  * 不会主动 kill——清理由调用方决定。
430
436
  */
431
- export function findOrphanProcesses(status = scanInstances()) {
437
+ export function findOrphanProcesses(status = scanInstances({ includeAidActivity: false }), snapshot = getProcessSnapshot()) {
432
438
  // 1. 已登记 PID(自己 HOME 下的 main + 自己进程)。调用方刚扫过登记簿时可直接传入,
433
439
  // Windows 上每次 scanInstances 都要为活实例跑一遍 CIM 查询。
434
440
  const known = new Set([process.pid]);
@@ -449,8 +455,8 @@ export function findOrphanProcesses(status = scanInstances()) {
449
455
  // 所以先用快照里的命令行过滤,只对真正的 EvolCore 入口做后续探测。
450
456
  // 优先用启动期已经采过的进程快照:它同样带命令行,省掉这里再拉一次全表 CIM。
451
457
  // 快照不可用(非 Windows、或 CIM 查询失败)时回退到主动枚举。
452
- const snapshot = getProcessSnapshot();
453
- const candidates = snapshot.complete
458
+ // Linux identity snapshots do not contain command lines; retain native enumeration.
459
+ const candidates = snapshot.complete && isWindows
454
460
  ? [...snapshot.commandLines.entries()]
455
461
  .filter(([pid]) => pid !== process.pid)
456
462
  .map(([pid, commandLine]) => ({ pid, commandLine }))
@@ -334,6 +334,9 @@ export function getLocalVersion() {
334
334
  * 未安装或查询失败返回 null。
335
335
  */
336
336
  export function resolveGlobalPkg(pkgName) {
337
+ const local = resolveBundledPkg(pkgName);
338
+ if (local)
339
+ return local;
337
340
  try {
338
341
  const npm = resolveNpmInvocation();
339
342
  const globalRoot = execFileSync(npm.command, [...npm.argsPrefix, 'root', '-g'], {
@@ -356,6 +359,51 @@ export function resolveGlobalPkg(pkgName) {
356
359
  catch { /* not found */ }
357
360
  return null;
358
361
  }
362
+ function resolveBundledPkg(pkgName) {
363
+ if (pkgName !== WEB_PACKAGE_NAME)
364
+ return null;
365
+ const candidates = [
366
+ ...(isLinkedInstall() ? [path.join(getPackageRoot(), 'ecweb', 'package.json')] : []),
367
+ path.join(targetPackageRoot(), 'node_modules', ...pkgName.split('/'), 'package.json'),
368
+ ];
369
+ for (const file of candidates) {
370
+ try {
371
+ const pkg = JSON.parse(fs.readFileSync(file, 'utf8'));
372
+ if (pkg.name === pkgName && typeof pkg.version === 'string')
373
+ return { version: pkg.version, path: file };
374
+ }
375
+ catch { /* Try the next installation layout. */ }
376
+ }
377
+ return null;
378
+ }
379
+ /** Runtime callers must not block IPC and CLI probe callbacks while locating npm packages. */
380
+ export async function resolveGlobalPkgAsync(pkgName) {
381
+ const local = resolveBundledPkg(pkgName);
382
+ if (local)
383
+ return local;
384
+ try {
385
+ const npm = resolveNpmInvocation();
386
+ const { stdout } = await execFileAsync(npm.command, [...npm.argsPrefix, 'root', '-g'], {
387
+ encoding: 'utf8', timeout: 10_000, windowsHide: true,
388
+ });
389
+ const globalRoot = stdout.trim();
390
+ const candidates = [
391
+ ...(pkgName === WEB_PACKAGE_NAME
392
+ ? [path.join(globalRoot, MAIN_PACKAGE_NAME, 'node_modules', ...pkgName.split('/'), 'package.json')] : []),
393
+ path.join(globalRoot, ...pkgName.split('/'), 'package.json'),
394
+ ];
395
+ for (const file of candidates) {
396
+ try {
397
+ const pkg = JSON.parse(await fs.promises.readFile(file, 'utf8'));
398
+ if (pkg.name === pkgName && typeof pkg.version === 'string')
399
+ return { version: pkg.version, path: file };
400
+ }
401
+ catch { /* Try the next installation layout. */ }
402
+ }
403
+ }
404
+ catch { /* npm unavailable or package not installed. */ }
405
+ return null;
406
+ }
359
407
  /**
360
408
  * 查询 npm registry 上指定包的最新版本。
361
409
  * 使用 HTTP fetch 直接查 registry API,不依赖 npm CLI。