evolcore 0.0.42-test.0 → 0.0.43-test.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 (187) hide show
  1. package/CHANGELOG.md +31 -2
  2. package/bin/ec-safe-output.js +4 -1
  3. package/dist/ability/application-service.js +882 -0
  4. package/dist/ability/authorization.js +70 -0
  5. package/dist/ability/command-contract.js +105 -0
  6. package/dist/ability/daemon.js +137 -0
  7. package/dist/ability/development.js +450 -0
  8. package/dist/ability/environment.js +75 -0
  9. package/dist/ability/interop-v1.js +547 -0
  10. package/dist/ability/management.js +79 -0
  11. package/dist/ability/package.js +264 -0
  12. package/dist/ability/provider.js +73 -0
  13. package/dist/ability/publication.js +107 -0
  14. package/dist/ability/resources.js +106 -0
  15. package/dist/ability/runtime.js +212 -0
  16. package/dist/ability/secrets.js +47 -0
  17. package/dist/ability/store.js +112 -0
  18. package/dist/ability/toolchain.js +69 -0
  19. package/dist/ability/types.js +14 -0
  20. package/dist/ability/versions.js +32 -0
  21. package/dist/agents/baseagent.js +2 -2
  22. package/dist/agents/claude-runner.js +4 -0
  23. package/dist/agents/codex-runner.js +81 -17
  24. package/dist/agents/ecagent-plugin-lazy.js +41 -0
  25. package/dist/agents/ecagent-runner.js +18 -11
  26. package/dist/aun/ability-device-routing.js +12 -1
  27. package/dist/aun/aid/agentmd.js +2 -2
  28. package/dist/aun/aid/identity.js +45 -0
  29. package/dist/aun/aid/index.js +1 -0
  30. package/dist/aun/aid/managed-operation.js +73 -2
  31. package/dist/channels/aun.js +64 -18
  32. package/dist/channels/builtin-plugins.js +14 -0
  33. package/dist/channels/dingtalk.js +78 -26
  34. package/dist/channels/feishu.js +89 -14
  35. package/dist/channels/qqbot.js +84 -19
  36. package/dist/channels/wechat.js +77 -19
  37. package/dist/channels/wecom.js +67 -22
  38. package/dist/cli/ability-command.js +92 -0
  39. package/dist/cli/aun-commands.js +124 -85
  40. package/dist/cli/daemon-commands.js +37 -85
  41. package/dist/cli/index.js +14 -0
  42. package/dist/cli/init.js +11 -13
  43. package/dist/cli/managed-command-guard.js +6 -0
  44. package/dist/cli/model.js +101 -104
  45. package/dist/cli/provider-command.js +6 -4
  46. package/dist/cli/restart-monitor.js +52 -11
  47. package/dist/cli/upgrade-command.js +102 -0
  48. package/dist/cli/version.js +1 -1
  49. package/dist/config/access-policy.js +4 -2
  50. package/dist/config/builtin-roles.js +1 -0
  51. package/dist/config/config-field-policy.js +4 -0
  52. package/dist/config/config-manager.js +7 -0
  53. package/dist/config/provider-ipc-service.js +10 -0
  54. package/dist/config/providers-config.js +12 -3
  55. package/dist/config/providers-management.js +45 -9
  56. package/dist/config/schema-migration.js +40 -22
  57. package/dist/contracts/ecweb-service-protocol.js +2 -1
  58. package/dist/core/auth/agent-delegation.js +21 -5
  59. package/dist/core/auth/auth-gateway.js +31 -9
  60. package/dist/core/auth/authorization-audit.js +52 -4
  61. package/dist/core/auth/delegation-authorization.js +140 -4
  62. package/dist/core/auth/operation-authorizer.js +114 -13
  63. package/dist/core/auth/operation-catalog.js +118 -4
  64. package/dist/core/baseagent-loader.js +14 -1
  65. package/dist/core/channel-loader.js +47 -9
  66. package/dist/core/channel-runtime.js +1 -1
  67. package/dist/core/command/agent-storage-menu.js +1 -1
  68. package/dist/core/command/cli-intent-parser.js +26 -13
  69. package/dist/core/command/command-handler.js +232 -76
  70. package/dist/core/command/connect-menu.js +10 -4
  71. package/dist/core/command/daemon-diagnostics.js +3 -3
  72. package/dist/core/command/data-root-resolver.js +2 -3
  73. package/dist/core/command/menu-catalog.js +10 -3
  74. package/dist/core/command/menu-handler.js +321 -46
  75. package/dist/core/command/menu-protocol.js +53 -7
  76. package/dist/core/command/pa-workspace-calendar.js +1 -2
  77. package/dist/core/command/pa-workspace-items.js +486 -0
  78. package/dist/core/command/pa-workspace-store.js +10 -1
  79. package/dist/core/command/slash-gate.js +2 -2
  80. package/dist/core/command/slash-handler.js +67 -25
  81. package/dist/core/contact-bind-registry.js +27 -0
  82. package/dist/core/daemon-control.js +3 -3
  83. package/dist/core/daemon-lifecycle.js +2 -1
  84. package/dist/core/event-bus.js +9 -2
  85. package/dist/core/handoff/ipc-registration.js +1 -0
  86. package/dist/core/host-snapshot.js +1 -2
  87. package/dist/core/initialization/service.js +32 -11
  88. package/dist/core/ipc-registration.js +18 -5
  89. package/dist/core/memory/consolidation-context.js +2 -2
  90. package/dist/core/message/aun-request-registry.js +99 -18
  91. package/dist/core/message/im-renderer.js +16 -11
  92. package/dist/core/message/message-admission.js +25 -20
  93. package/dist/core/message/message-bridge.js +21 -47
  94. package/dist/core/message/message-queue.js +3 -0
  95. package/dist/core/message/response-engine.js +7 -5
  96. package/dist/core/model/catalog-service.js +1 -1
  97. package/dist/core/permission/ec-command-parser.js +41 -9
  98. package/dist/core/permission/permission-result.js +1 -0
  99. package/dist/core/permission/protected-paths.js +25 -14
  100. package/dist/core/permission/tool-policy.js +108 -107
  101. package/dist/core/plugin-lifecycle.js +133 -0
  102. package/dist/core/runner-reload-transaction.js +4 -1
  103. package/dist/core/system-session/memory.js +16 -3
  104. package/dist/core/task/task-activity-store.js +50 -0
  105. package/dist/core/task/task-image-resources.js +140 -0
  106. package/dist/core/thread/ipc-operation.js +1 -1
  107. package/dist/core/thread/thread-service.js +0 -1
  108. package/dist/directory/canonical-digest.js +5 -3
  109. package/dist/directory/owner-directory-admission.js +22 -2
  110. package/dist/directory/owner-directory-cache.js +394 -60
  111. package/dist/directory/owner-directory-markdown.js +29 -2
  112. package/dist/directory/owner-directory-scope.js +35 -16
  113. package/dist/ecweb/basic-settings-service.js +4 -1
  114. package/dist/ecweb/pairing.js +41 -0
  115. package/dist/ecweb/providers-service.js +8 -1
  116. package/dist/{utils/ecweb-utils.js → ecweb/runtime/launch.js} +3 -27
  117. package/dist/ecweb/runtime/lifecycle.js +184 -0
  118. package/dist/{utils/ecweb-supervisor.js → ecweb/runtime/supervisor.js} +32 -27
  119. package/dist/index.js +34 -25
  120. package/dist/ipc.js +124 -7
  121. package/dist/response-system/engines/v1/proactive-flow.js +1 -1
  122. package/dist/trigger/authorization.js +2 -2
  123. package/dist/utils/atomic-write.js +24 -0
  124. package/dist/utils/avatar-upload.js +3 -1
  125. package/dist/utils/cross-platform.js +31 -2
  126. package/dist/utils/host-info.js +36 -0
  127. package/dist/utils/instance-registry.js +38 -11
  128. package/dist/utils/logger.js +9 -0
  129. package/dist/utils/{process-tree-stats.js → process-tree.js} +29 -0
  130. package/dist/utils/tool-summary.js +9 -1
  131. package/dist/utils/upgrade-jobs.js +96 -15
  132. package/dist/utils/windows-autostart.js +1 -1
  133. package/ecagent/README.md +19 -0
  134. package/ecagent/dist/harness/agent-harness.js +9 -0
  135. package/ecagent/dist/harness/env/nodejs.js +71 -11
  136. package/ecagent/dist/harness/env/windows-shell.d.ts +7 -0
  137. package/ecagent/dist/harness/env/windows-shell.js +132 -0
  138. package/kits/docs/aun/ABILITY_CALLING.md +38 -9
  139. package/kits/docs/evolcore/INDEX.md +5 -1
  140. package/kits/docs/evolcore/ability.md +181 -0
  141. package/kits/docs/evolcore/aid.md +20 -0
  142. package/kits/docs/evolcore/config.md +10 -6
  143. package/kits/docs/evolcore/menu-protocol.md +40 -1
  144. package/kits/docs/evolcore/provider.md +2 -2
  145. package/kits/docs/evolcore/tool-authorization.md +270 -0
  146. package/kits/runtime/ability-job.ps1 +41 -0
  147. package/kits/runtime/ability-runner.mjs +67 -0
  148. package/kits/runtime/ability-secret.ps1 +59 -0
  149. package/kits/runtime/ability-templates/go/main.go +59 -0
  150. package/kits/runtime/ability-templates/java/Json.java +67 -0
  151. package/kits/runtime/ability-templates/java/Runner.java +42 -0
  152. package/kits/runtime/ability-templates/python/runner.py +48 -0
  153. package/kits/runtime/ability-templates/rust/json.rs +87 -0
  154. package/kits/runtime/ability-templates/rust/runner.rs +35 -0
  155. package/kits/schemas/_meta.json +12 -1
  156. package/kits/schemas/ability-plugin.schema.1.json +107 -0
  157. package/kits/schemas/ability-project.schema.1.json +31 -0
  158. package/kits/schemas/agent-config.schema.16.json +20 -0
  159. package/kits/schemas/agent-config.schema.17.json +20 -0
  160. package/kits/schemas/agent-config.schema.18.json +917 -0
  161. package/kits/skills/.switches.json +4 -0
  162. package/kits/skills/aid-ability/SKILL.md +5 -4
  163. package/kits/skills/ec-ability/SKILL.md +67 -0
  164. package/kits/skills/ec-ability/references/contract-checklist.md +37 -0
  165. package/kits/skills/ec-ability/references/development.md +104 -0
  166. package/kits/skills/ec-ability/references/management.md +117 -0
  167. package/kits/skills/ec-ability/references/recovery.md +27 -0
  168. package/kits/skills/ec-ability/references/runtime-protocol.md +109 -0
  169. package/kits/skills/ec-ability/references/workflows.md +15 -0
  170. package/kits/skills/ec-service-proxy/SKILL.md +12 -0
  171. package/kits/skills/personal-assistant/SKILL.md +240 -6
  172. package/kits/skills/personal-assistant/references/02-bootstrap.md +78 -4
  173. package/kits/skills/personal-assistant/scripts/clean.mjs +397 -0
  174. package/kits/skills/personal-assistant/scripts/init.mjs +113 -25
  175. package/kits/skills/personal-assistant/scripts/lock.mjs +189 -0
  176. package/kits/skills/personal-assistant/scripts/migrate.mjs +35 -10
  177. package/kits/skills/personal-assistant/scripts/verify.mjs +2 -1
  178. package/kits/skills/personal-assistant/templates/persona-section.md +54 -0
  179. package/kits/skills/personal-assistant/triggers/ingest-daily.json +1 -1
  180. package/kits/templates/memory-consolidation/notes.md +1 -1
  181. package/kits/templates/system-fragments/channel.md +2 -1
  182. package/kits/templates/system-fragments/commands.md +1 -0
  183. package/package.json +4 -2
  184. package/dist/core/command/data-root-error.js +0 -10
  185. package/dist/utils/machine-info.js +0 -46
  186. package/dist/utils/process-tree-worker.js +0 -31
  187. package/dist/utils/windows-output.js +0 -36
package/dist/index.js CHANGED
@@ -28,15 +28,13 @@ import { SessionIdleMonitor, readSessionLoopIdleSeconds } from './core/session/s
28
28
  import { ClaudeAgentPlugin } from './agents/claude-runner.js';
29
29
  import { CodexAgentPlugin } from './agents/codex-runner.js';
30
30
  import { GeminiAgentPlugin } from './agents/gemini-runner.js';
31
- import { EcagentAgentPlugin } from './agents/ecagent-runner.js';
32
- import { FeishuChannelPlugin, registerPendingFeishuContactBind } from './channels/feishu.js';
33
- import { WechatChannelPlugin, registerPendingWechatContactBind } from './channels/wechat.js';
34
- import { AUNChannelPlugin } from './channels/aun.js';
31
+ // 不要静态导入 ecagent-runner:它连带整个 ecagent 运行时(typebox 占了模块图
32
+ // 三分之一的 resolve),而绝大多数部署并不使用 ecagent。这里用懒加载外壳。
33
+ import { EcagentAgentPluginLazy } from './agents/ecagent-plugin-lazy.js';
34
+ import { registerBuiltinChannelPlugins } from './channels/builtin-plugins.js';
35
+ import { registerAbilityPlatform } from './ability/daemon.js';
35
36
  import { assertAunEncryptionSeedPolicy } from './aun/aid/encryption-seed-policy.js';
36
37
  import { BindService } from './utils/aid-bind.js';
37
- import { DingtalkChannelPlugin, registerPendingDingtalkContactBind } from './channels/dingtalk.js';
38
- import { QQBotChannelPlugin, registerPendingQQBotContactBind } from './channels/qqbot.js';
39
- import { WecomChannelPlugin, registerPendingWecomContactBind } from './channels/wecom.js';
40
38
  import { buildEnvelope } from './core/message/message-utils.js';
41
39
  import { ResponseEngine } from './core/message/response-engine.js';
42
40
  import { MessageQueue } from './core/message/message-queue.js';
@@ -74,13 +72,14 @@ import { ChannelLoader } from './core/channel-loader.js';
74
72
  import { registerChannelInstance as registerChannelRuntimeInstance, createChannelStartupNotifications, registerChannelHealthNotifications, bindStartupChannelsToAgents, createAgentStorageClientResolver, createDefaultChannelPolicy, createChannelConnectionRuntime, preloadChannelThreads, } from './core/channel-runtime.js';
75
73
  import { createIpcStatusProvider, registerDaemonIpc } from './core/ipc-registration.js';
76
74
  import { AgentLoader } from './core/baseagent-loader.js';
75
+ import { PluginHandle } from './core/plugin-lifecycle.js';
77
76
  import { EvolAgentRegistry } from './core/evolagent-registry.js';
78
77
  import { createAgentInitializationRuntime, createAgentReloadRuntime, createAgentRuntimeOperations, createStartupAgentRunners, completeStartupAgentRuntime, bindAgentCreationOwner, loadStartupAgentRegistry, recoverIncompleteAgentInitializations, } from './core/agent-runtime.js';
79
78
  import { IpcServer } from './ipc.js';
80
79
  import { installChannelSdkConsoleFilter, logger, logOwnershipEvent, ownershipErrorCode, setChannelLogsEnabled, setLogLevel } from './utils/logger.js';
81
80
  import { StartupTracer, STARTUP_TRACE_ID_ENV } from './utils/startup-trace.js';
82
81
  import { DiagService } from './core/command/diag-service.js';
83
- import { createEcwebSupervisor } from './utils/ecweb-supervisor.js';
82
+ import { createEcwebSupervisor } from './ecweb/runtime/supervisor.js';
84
83
  import { writeMain, removeAll, isMainWinner, scanInstances } from './utils/instance-registry.js';
85
84
  import { loadKitManifest, cleanEckDebug } from './eck/kit-renderer.js';
86
85
  import { initEck } from './eck/init.js';
@@ -299,16 +298,17 @@ async function main() {
299
298
  // 创建事件总线
300
299
  trace.mark('daemon.eventBus');
301
300
  const eventBus = new EventBus();
301
+ const daemonPluginLifecycle = new PluginHandle('daemon');
302
302
  logger.info('✓ Event bus initialized');
303
303
  // 把所有事件录到 events.log(受 EVENT_LOG 环境变量控制)
304
- eventBus.subscribeAll((event) => logger.event(event));
305
- eventBus.subscribe('agent:updated', (event) => {
304
+ daemonPluginLifecycle.subscribe(eventBus, '*', (event) => logger.event(event));
305
+ daemonPluginLifecycle.subscribe(eventBus, 'agent:updated', (event) => {
306
306
  if (event.nameChanged)
307
307
  agentRegistry?.invalidateAgentDisplayCache?.(event.aid);
308
308
  });
309
309
  // 运行时路径授权以会话为归属:会话被删除后不再有身份去消费它,随之释放。
310
310
  // 只挂 session:deleted——session:idle 只表示空闲,会话仍会继续服务。
311
- eventBus.subscribe('session:deleted', (event) => {
311
+ daemonPluginLifecycle.subscribe(eventBus, 'session:deleted', (event) => {
312
312
  if ('sessionId' in event && event.sessionId)
313
313
  releaseSessionPathGrants(event.sessionId);
314
314
  });
@@ -333,7 +333,7 @@ async function main() {
333
333
  agentLoader.register(new ClaudeAgentPlugin());
334
334
  agentLoader.register(new CodexAgentPlugin());
335
335
  agentLoader.register(new GeminiAgentPlugin());
336
- agentLoader.register(new EcagentAgentPlugin());
336
+ agentLoader.register(new EcagentAgentPluginLazy());
337
337
  trace.mark('daemon.agentRunners');
338
338
  const { agentInstances, agentMap, primaryBaseagent, primaryRunnerKey, runtimeError: runnerStartupError, } = await createStartupAgentRunners({ agentRegistry, agentLoader, sessionManager, primaryAgent });
339
339
  if (runnerStartupError) {
@@ -360,18 +360,13 @@ async function main() {
360
360
  const messageCache = new MessageCache();
361
361
  logger.info('✓ Message cache initialized');
362
362
  // 定期清理过期消息(每小时)
363
- setInterval(() => {
363
+ daemonPluginLifecycle.setInterval(() => {
364
364
  messageCache.cleanupExpired();
365
365
  }, 60 * 60 * 1000);
366
366
  // 渠道插件系统
367
367
  trace.mark('daemon.channelCreate');
368
368
  const channelLoader = new ChannelLoader(daemonCfg.debug, daemonCfg.aun?.defaultEncrypt);
369
- channelLoader.register(new FeishuChannelPlugin());
370
- channelLoader.register(new WechatChannelPlugin());
371
- channelLoader.register(new AUNChannelPlugin());
372
- channelLoader.register(new DingtalkChannelPlugin());
373
- channelLoader.register(new QQBotChannelPlugin());
374
- channelLoader.register(new WecomChannelPlugin());
369
+ registerBuiltinChannelPlugins(channelLoader);
375
370
  // Create channel instances: 每个 self-agent 各自的 channels
376
371
  const evolagentInstances = [];
377
372
  for (const agent of agentRegistry.runnableAgents()) {
@@ -389,7 +384,7 @@ async function main() {
389
384
  trace.mark('daemon.channelInstances', `${channelInstances.length} 个渠道实例`);
390
385
  logger.info(`✓ Created ${channelInstances.length} channel instance(s)`);
391
386
  let bootstrapService;
392
- const contactRequestExpiryTimer = setInterval(() => {
387
+ const contactRequestExpiryTimer = daemonPluginLifecycle.setInterval(() => {
393
388
  for (const agent of agentRegistry.runnableAgents()) {
394
389
  void expirePendingPeerRequests(agent.aid).catch(error => {
395
390
  logger.warn(`[contact-request] Pending expiry sweep failed: self=${agent.aid} error=${error instanceof Error ? error.message : String(error)}`);
@@ -692,6 +687,12 @@ async function main() {
692
687
  const inst = channelInstances.find(candidate => candidate.adapter.channelKey === channelKey);
693
688
  return !!inst && inst.channel.getStatus?.().connected === true;
694
689
  };
690
+ const contactBindIpcExecutor = (channelType) => {
691
+ const provider = channelLoader.contactBindRegistry.get(channelType);
692
+ if (!provider)
693
+ throw new Error(`Contact-bind provider '${channelType}' was not registered`);
694
+ return { register: provider.register, isChannelReady: isContactBindChannelReady };
695
+ };
695
696
  cmdHandler.setAgentStorageClientResolver(createAgentStorageClientResolver(channelInstances));
696
697
  const msgBridge = new MessageBridge(defaultProjectPath, sessionManager, processor, messageQueue, cmdHandler, eventBus, primaryAgent?.config.debounce, processLevelOwners);
697
698
  msgBridge.setAgentRegistry(agentRegistry);
@@ -699,6 +700,7 @@ async function main() {
699
700
  msgBridge.setGroupInviteReviewService(groupInviteReviewService);
700
701
  cmdHandler.setGroupInviteDecisionResolver((selfAid, ownerAid, inviteId, action) => groupInviteReviewService.decideManaged(selfAid, ownerAid, inviteId, action));
701
702
  msgBridge.setContactBindRuntimeChecker(isContactBindChannelReady);
703
+ msgBridge.setContactBindRegistry(channelLoader.contactBindRegistry);
702
704
  msgBridge.setAidStatsCollector(aidStatsCollector);
703
705
  bootstrapService = new BootstrapService(agentRegistry, eventBus);
704
706
  msgBridge.setBootstrapService(bootstrapService);
@@ -983,6 +985,7 @@ async function main() {
983
985
  trace.mark('daemon.ipcRegister');
984
986
  console.error('[EvolCore] ✓ Configuring IPC...');
985
987
  registerDaemonIpc({
988
+ lifecycle: daemonPluginLifecycle,
986
989
  ipcServer,
987
990
  agentRegistry,
988
991
  agentDelegationRegistry,
@@ -1004,11 +1007,11 @@ async function main() {
1004
1007
  isConsolidationPending: params => consolidationQueue.isPendingOrActive(params),
1005
1008
  completeAgentBootstrap,
1006
1009
  contactBinds: {
1007
- dingtalk: { register: registerPendingDingtalkContactBind, isChannelReady: isContactBindChannelReady },
1008
- feishu: { register: registerPendingFeishuContactBind, isChannelReady: isContactBindChannelReady },
1009
- qqbot: { register: registerPendingQQBotContactBind, isChannelReady: isContactBindChannelReady },
1010
- wecom: { register: registerPendingWecomContactBind, isChannelReady: isContactBindChannelReady },
1011
- wechat: { register: registerPendingWechatContactBind, isChannelReady: isContactBindChannelReady },
1010
+ dingtalk: contactBindIpcExecutor('dingtalk'),
1011
+ feishu: contactBindIpcExecutor('feishu'),
1012
+ qqbot: contactBindIpcExecutor('qqbot'),
1013
+ wecom: contactBindIpcExecutor('wecom'),
1014
+ wechat: contactBindIpcExecutor('wechat'),
1012
1015
  },
1013
1016
  bindService,
1014
1017
  diagService,
@@ -1028,6 +1031,11 @@ async function main() {
1028
1031
  },
1029
1032
  });
1030
1033
  recoverIncompleteAgentInitializations(agentInitializationService, paths.agentsDir);
1034
+ const abilityPlatform = registerAbilityPlatform(path.join(paths.dataDir, 'ability'), {
1035
+ ipcServer, agentRegistry, agentDelegationRegistry, sessionManager, getProcessOwners: getDaemonOwners,
1036
+ daemonAid: daemonCfg.aid, channelInstances, getControlChannel: () => controlChannel,
1037
+ });
1038
+ onShutdown(() => abilityPlatform.close());
1031
1039
  trace.mark('daemon.ipcStart');
1032
1040
  console.error('[EvolCore] ✓ Starting IPC server...');
1033
1041
  await ipcServer.start();
@@ -1217,6 +1225,7 @@ async function main() {
1217
1225
  // 双 rename 原子写下 watchFile 的语义会被破坏,且新结构有 N 个 config.json 要监控;
1218
1226
  // 显式触发更可控。
1219
1227
  shutdown = createDaemonShutdown({
1228
+ disposePluginResources: () => daemonPluginLifecycle.dispose(),
1220
1229
  ipcServer,
1221
1230
  readySignalPath,
1222
1231
  bindService,
package/dist/ipc.js CHANGED
@@ -14,7 +14,7 @@ import { HANDOFF_QUERY_MAX_LIMIT, HANDOFF_STATES } from './core/handoff/types.js
14
14
  import { AgentReloadBusyError } from './core/agent-reload-coordinator.js';
15
15
  import { getPackageRoot, getWindowsInstanceSocketPathCandidates, normalizeIpcEndpoint, resolvePaths } from './paths.js';
16
16
  import { getProcessStartTime, isSameOrOlderProcess } from './utils/process-introspect.js';
17
- import { classifyProcessTree, ProcessTreeSampler, readProcessMetrics } from './utils/process-tree-stats.js';
17
+ import { classifyProcessTree, ProcessTreeSampler, readProcessMetrics } from './utils/process-tree.js';
18
18
  import { readSystemMemoryUsage } from './utils/system-memory.js';
19
19
  import { AGENT_DELEGATION_TOKEN_ENV, CODEX_SESSION_TOKEN_ENV, hashCurrentDelegatedCommand, hashDelegatedCommandArgv, parseDelegatedExecutionSpec, readDelegatedExecutionSpec } from './core/auth/agent-delegation.js';
20
20
  import { resolveSkillRefreshArgv } from './core/skill/command-parser.js';
@@ -73,6 +73,8 @@ const LOCAL_CONTROL_COMMANDS = new Set([
73
73
  'evolagent.resync',
74
74
  'menu.exec',
75
75
  'ecweb.providers',
76
+ 'ecweb.ability',
77
+ 'upgrade.op',
76
78
  'provider.op',
77
79
  'ecweb.init',
78
80
  'ecweb.basic-settings',
@@ -94,7 +96,8 @@ const MEMORY_COMMAND_ENDPOINTS = new Set([
94
96
  'memory.create', 'memory.update', 'memory.archive', 'memory.demote', 'memory.consolidate',
95
97
  ]);
96
98
  const DELEGATED_ARGV_ENDPOINTS = new Set([
97
- 'agent.op', 'config.op', 'peer.op', 'aid.op', 'aid.ownership', 'group.op', 'msg.op', 'fs.op', 'proxy.op',
99
+ 'agent.op', 'ability.op', 'config.op', 'peer.op', 'aid.op', 'aid.ownership', 'group.op', 'msg.op', 'fs.op', 'proxy.op', 'provider.op',
100
+ 'upgrade.op',
98
101
  'ctl', 'diag', 'menu-client.request', 'task.resume', 'queue.op', 'storage.auth', 'storage.upload',
99
102
  'trigger.op', 'skill.refresh', 'thread.op', 'local-command-context', 'evolagent.bootstrapComplete', 'status.auth', 'logs.query', ...MEMORY_COMMAND_ENDPOINTS,
100
103
  'handoff-return', 'handoff-recover-return', 'handoff-status', 'handoff-list', 'handoff-trace',
@@ -123,6 +126,8 @@ function requiresLocalControlToken(cmd) {
123
126
  const type = String(cmd.type ?? '');
124
127
  const sessionId = typeof cmd.sessionId === 'string' && cmd.sessionId.trim();
125
128
  const delegated = typeof cmd.delegationToken === 'string' && cmd.delegationToken.trim();
129
+ if (type === 'provider.op' || type === 'upgrade.op')
130
+ return !sessionId || !delegated || cmd.actorSessionId !== undefined;
126
131
  if (cmd.type === 'evolagent.initialize' || LOCAL_CONTROL_COMMANDS.has(type))
127
132
  return true;
128
133
  if (type === 'debug-issue-token')
@@ -132,6 +137,8 @@ function requiresLocalControlToken(cmd) {
132
137
  return false;
133
138
  if (type === 'skill.refresh' || type === 'thread.op')
134
139
  return !sessionId || !delegated;
140
+ if (type === 'ability.op')
141
+ return !sessionId && !delegated;
135
142
  return ['evolagent.bootstrapComplete', 'diag', 'handoff-status', 'handoff-list', 'handoff-trace', 'task.resume'].includes(type)
136
143
  && !sessionId;
137
144
  }
@@ -181,6 +188,7 @@ export function summarizeMonitorAgents(agents, aids) {
181
188
  export class IpcServer {
182
189
  getStatus;
183
190
  commandExecutor;
191
+ providerRegistrations = new Map();
184
192
  socketPath;
185
193
  server = null;
186
194
  agentRegistry;
@@ -189,6 +197,7 @@ export class IpcServer {
189
197
  aunAidStatsProvider;
190
198
  aunAidStatsRecorder;
191
199
  menuExecutor;
200
+ abilityExecutor;
192
201
  ecwebMessageContextProvider;
193
202
  agentOperationExecutor;
194
203
  skillRefreshExecutor;
@@ -206,6 +215,8 @@ export class IpcServer {
206
215
  storageUploadExecutor;
207
216
  triggerExecutor;
208
217
  proxyExecutor;
218
+ providerExecutor;
219
+ upgradeExecutor;
209
220
  consolidationLaunchExecutor;
210
221
  consolidationCheckExecutor;
211
222
  bootstrapCompleteExecutor;
@@ -321,9 +332,26 @@ export class IpcServer {
321
332
  /** Inject menu.* executor (ECWeb Control proxies menu requests through this) */
322
333
  setMenuExecutor(executor) {
323
334
  this.menuExecutor = executor;
335
+ const unregister = () => {
336
+ if (this.providerRegistrations.get('menu.exec') !== unregister)
337
+ return;
338
+ this.providerRegistrations.delete('menu.exec');
339
+ this.menuExecutor = undefined;
340
+ };
341
+ this.providerRegistrations.set('menu.exec', unregister);
342
+ return unregister;
324
343
  }
344
+ setAbilityExecutor(executor) { this.abilityExecutor = executor; }
325
345
  setEcwebMessageContextProvider(provider) {
326
346
  this.ecwebMessageContextProvider = provider;
347
+ const unregister = () => {
348
+ if (this.providerRegistrations.get('ecweb.message.context') !== unregister)
349
+ return;
350
+ this.providerRegistrations.delete('ecweb.message.context');
351
+ this.ecwebMessageContextProvider = undefined;
352
+ };
353
+ this.providerRegistrations.set('ecweb.message.context', unregister);
354
+ return unregister;
327
355
  }
328
356
  setInitializationExecutor(executor) {
329
357
  this.initializationExecutor = executor;
@@ -510,6 +538,12 @@ export class IpcServer {
510
538
  setProxyExecutor(executor) {
511
539
  this.proxyExecutor = executor;
512
540
  }
541
+ setProviderExecutor(executor) {
542
+ this.providerExecutor = executor;
543
+ }
544
+ setUpgradeExecutor(executor) {
545
+ this.upgradeExecutor = executor;
546
+ }
513
547
  /** Inject daemon-level consolidation launcher (BackgroundSessionLauncher, via executor closure). */
514
548
  setConsolidationLaunchExecutor(executor) {
515
549
  this.consolidationLaunchExecutor = executor;
@@ -594,22 +628,62 @@ export class IpcServer {
594
628
  /** Inject DingTalk contact binding-code executor. */
595
629
  setDingtalkContactBindExecutor(executor) {
596
630
  this.dingtalkContactBindExecutor = executor;
631
+ const unregister = () => {
632
+ if (this.providerRegistrations.get('channel.dingtalk.contact-bind') !== unregister)
633
+ return;
634
+ this.providerRegistrations.delete('channel.dingtalk.contact-bind');
635
+ this.dingtalkContactBindExecutor = undefined;
636
+ };
637
+ this.providerRegistrations.set('channel.dingtalk.contact-bind', unregister);
638
+ return unregister;
597
639
  }
598
640
  /** Inject Feishu contact binding-code executor. */
599
641
  setFeishuContactBindExecutor(executor) {
600
642
  this.feishuContactBindExecutor = executor;
643
+ const unregister = () => {
644
+ if (this.providerRegistrations.get('channel.feishu.contact-bind') !== unregister)
645
+ return;
646
+ this.providerRegistrations.delete('channel.feishu.contact-bind');
647
+ this.feishuContactBindExecutor = undefined;
648
+ };
649
+ this.providerRegistrations.set('channel.feishu.contact-bind', unregister);
650
+ return unregister;
601
651
  }
602
652
  /** Inject QQ contact binding-code executor. */
603
653
  setQQBotContactBindExecutor(executor) {
604
654
  this.qqbotContactBindExecutor = executor;
655
+ const unregister = () => {
656
+ if (this.providerRegistrations.get('channel.qqbot.contact-bind') !== unregister)
657
+ return;
658
+ this.providerRegistrations.delete('channel.qqbot.contact-bind');
659
+ this.qqbotContactBindExecutor = undefined;
660
+ };
661
+ this.providerRegistrations.set('channel.qqbot.contact-bind', unregister);
662
+ return unregister;
605
663
  }
606
664
  /** Inject WeCom contact binding-code executor. */
607
665
  setWecomContactBindExecutor(executor) {
608
666
  this.wecomContactBindExecutor = executor;
667
+ const unregister = () => {
668
+ if (this.providerRegistrations.get('channel.wecom.contact-bind') !== unregister)
669
+ return;
670
+ this.providerRegistrations.delete('channel.wecom.contact-bind');
671
+ this.wecomContactBindExecutor = undefined;
672
+ };
673
+ this.providerRegistrations.set('channel.wecom.contact-bind', unregister);
674
+ return unregister;
609
675
  }
610
676
  /** Inject WeChat contact binding-code executor. */
611
677
  setWechatContactBindExecutor(executor) {
612
678
  this.wechatContactBindExecutor = executor;
679
+ const unregister = () => {
680
+ if (this.providerRegistrations.get('channel.wechat.contact-bind') !== unregister)
681
+ return;
682
+ this.providerRegistrations.delete('channel.wechat.contact-bind');
683
+ this.wechatContactBindExecutor = undefined;
684
+ };
685
+ this.providerRegistrations.set('channel.wechat.contact-bind', unregister);
686
+ return unregister;
613
687
  }
614
688
  /** Start the lightweight background CPU sampling loop. Call after start(). */
615
689
  startCpuTracking() {
@@ -787,7 +861,9 @@ export class IpcServer {
787
861
  if (this.processTreeWorker)
788
862
  return this.processTreeWorker;
789
863
  try {
790
- const worker = new Worker(new URL('./utils/process-tree-worker.js', import.meta.url));
864
+ const worker = new Worker(new URL('./utils/process-tree.js', import.meta.url), {
865
+ workerData: 'process-tree-sampler',
866
+ });
791
867
  worker.unref();
792
868
  worker.on('message', (message) => {
793
869
  if (this.processTreeWorker !== worker
@@ -999,6 +1075,8 @@ export class IpcServer {
999
1075
  });
1000
1076
  }
1001
1077
  stop() {
1078
+ for (const unregister of this.providerRegistrations.values())
1079
+ unregister();
1002
1080
  setModelCatalogDaemonOwner(false);
1003
1081
  if (this.server) {
1004
1082
  this.server.close();
@@ -1041,10 +1119,6 @@ export class IpcServer {
1041
1119
  };
1042
1120
  }
1043
1121
  async dispatchCommand(cmd, requestSignal, receivedAtMono = performance.now(), requestId) {
1044
- if (cmd.type === 'provider.op' && (cmd.sessionId !== undefined || cmd.actorSessionId !== undefined
1045
- || cmd.delegationToken !== undefined)) {
1046
- return { ok: false, code: 'FORBIDDEN', error: 'Provider management requires host process control, not Agent task delegation' };
1047
- }
1048
1122
  if (requiresLocalControlToken(cmd) && !this.hasValidControlToken(cmd.controlToken)) {
1049
1123
  return { ok: false, code: 'INVALID_CONTROL_TOKEN', error: 'valid local control token is required' };
1050
1124
  }
@@ -1159,13 +1233,56 @@ export class IpcServer {
1159
1233
  case 'menu-client.request':
1160
1234
  return this.menuClientExecutor ? this.menuClientExecutor(cmd) : { ok: false, code: 'NOT_CONFIGURED', error: 'Managed Menu client is not configured' };
1161
1235
  case 'provider.op': {
1236
+ const hasDelegatedFields = cmd.sessionId !== undefined || cmd.delegationToken !== undefined
1237
+ || cmd.actorSessionId !== undefined;
1238
+ if (hasDelegatedFields) {
1239
+ if (typeof cmd.sessionId !== 'string' || !cmd.sessionId
1240
+ || typeof cmd.delegationToken !== 'string' || !cmd.delegationToken
1241
+ || cmd.actorSessionId !== undefined) {
1242
+ return { ok: false, code: 'INVALID_REQUEST', error: 'provider.op requires a session and task delegation token' };
1243
+ }
1244
+ if (!this.providerExecutor)
1245
+ return { ok: false, code: 'NOT_CONFIGURED', error: 'managed Provider executor is unavailable' };
1246
+ return this.providerExecutor({
1247
+ argv: cmd.argv,
1248
+ sessionId: cmd.sessionId,
1249
+ delegationToken: cmd.delegationToken,
1250
+ delegationCommandHash: cmd.delegationCommandHash,
1251
+ requestId,
1252
+ });
1253
+ }
1162
1254
  const { executeProviderOperation } = await import('./config/provider-ipc-service.js');
1163
1255
  return executeProviderOperation({ argv: cmd.argv });
1164
1256
  }
1257
+ case 'upgrade.op': {
1258
+ const hasDelegatedFields = cmd.sessionId !== undefined || cmd.delegationToken !== undefined
1259
+ || cmd.actorSessionId !== undefined;
1260
+ if (hasDelegatedFields) {
1261
+ if (typeof cmd.sessionId !== 'string' || !cmd.sessionId
1262
+ || typeof cmd.delegationToken !== 'string' || !cmd.delegationToken
1263
+ || cmd.actorSessionId !== undefined) {
1264
+ return { ok: false, code: 'INVALID_REQUEST', error: 'upgrade.op requires a session and task delegation token' };
1265
+ }
1266
+ if (!this.upgradeExecutor)
1267
+ return { ok: false, code: 'NOT_CONFIGURED', error: 'managed upgrade executor is unavailable' };
1268
+ return this.upgradeExecutor({
1269
+ argv: cmd.argv,
1270
+ sessionId: cmd.sessionId,
1271
+ delegationToken: cmd.delegationToken,
1272
+ delegationCommandHash: cmd.delegationCommandHash,
1273
+ requestId,
1274
+ });
1275
+ }
1276
+ const { executeUpgradeOperation } = await import('./cli/upgrade-command.js');
1277
+ return executeUpgradeOperation({ argv: cmd.argv, requestId: requestId ?? crypto.randomUUID() });
1278
+ }
1165
1279
  case 'ecweb.providers': {
1166
1280
  const { handleProvidersService } = await import('./ecweb/providers-service.js');
1167
1281
  return handleProvidersService(cmd.request);
1168
1282
  }
1283
+ case 'ability.op':
1284
+ case 'ecweb.ability':
1285
+ return this.abilityExecutor ? this.abilityExecutor(cmd) : { ok: false, code: 'ABILITY_UNAVAILABLE', error: 'Ability service is unavailable', status: 503 };
1169
1286
  case 'ecweb.init': {
1170
1287
  const { handleInitService } = await import('./core/initialization/service.js');
1171
1288
  return handleInitService(cmd.request);
@@ -60,7 +60,7 @@ function hasSuccessfulSendReceipt(result, isError, requiresBusinessReturn = fals
60
60
  if (!normalized || /^(?:null|undefined|-)$/.test(normalized))
61
61
  return false;
62
62
  // Contact admission/refusal is a real reply, but it is not task completion.
63
- if (/(?:当前不接受陌生人消息|可发送\s*\/request|contact\s+(?:required|request)|stranger message)/i.test(normalized))
63
+ if (/(?:当前不接受非联系人消息|当前不接受陌生人消息|可发送\s*\/request|contact\s+(?:required|request)|stranger message)/i.test(normalized))
64
64
  return false;
65
65
  return true;
66
66
  };
@@ -253,7 +253,7 @@ export async function authorizeTriggerExecution(definition, dependencies) {
253
253
  operation: 'trigger.run',
254
254
  scope: 'relation',
255
255
  source: 'control',
256
- args: { self: definition.agentAid, peer: origin.peerId, peerKey: subject.peerKey, triggerId: definition.id },
256
+ args: { self: definition.agentAid, targetAgentAid: definition.agentAid, peer: origin.peerId, peerKey: subject.peerKey, triggerId: definition.id },
257
257
  },
258
258
  });
259
259
  return decision.allow
@@ -301,7 +301,7 @@ export async function authorizeTriggerExecution(definition, dependencies) {
301
301
  operation: 'trigger.run',
302
302
  scope: 'relation',
303
303
  source: 'agent-tool',
304
- args: { self: definition.agentAid, peer: origin.peerId, peerKey: subject.peerKey, triggerId: definition.id },
304
+ args: { self: definition.agentAid, targetAgentAid: definition.agentAid, peer: origin.peerId, peerKey: subject.peerKey, triggerId: definition.id },
305
305
  },
306
306
  });
307
307
  if (!operationDecision.allow)
@@ -154,6 +154,30 @@ export function atomicRead(filePath) {
154
154
  }
155
155
  return null;
156
156
  }
157
+ /**
158
+ * `atomicRead` 的字节版:恢复规则完全一致,只是不解码。
159
+ *
160
+ * 用于必须以原始字节为准的场合——比如按字节重算摘要,或者这份文件本身
161
+ * 就是远端对象的逐字节副本,任何重新编码都会破坏"与远端一致"的语义。
162
+ */
163
+ export function atomicReadBytes(filePath) {
164
+ const hot = filePath + HOT;
165
+ const tmp = filePath + TMP;
166
+ if (fs.existsSync(tmp)) {
167
+ try {
168
+ fs.unlinkSync(tmp);
169
+ }
170
+ catch { /* best effort */ }
171
+ }
172
+ if (fs.existsSync(filePath)) {
173
+ return fs.readFileSync(filePath);
174
+ }
175
+ if (fs.existsSync(hot)) {
176
+ fs.renameSync(hot, filePath);
177
+ return fs.readFileSync(filePath);
178
+ }
179
+ return null;
180
+ }
157
181
  /**
158
182
  * Delete a file written by atomicWrite. Removing only the live path is not
159
183
  * enough: atomicRead treats a lone hot backup as an interrupted rename and
@@ -5,7 +5,8 @@ import net from 'net';
5
5
  import { agentmdGet, agentmdPut, updateAgentMdFrontmatterAvatar } from '../aun/aid/agentmd.js';
6
6
  import { storageRm, storageUpload } from '../aun/storage/index.js';
7
7
  import { logger } from './logger.js';
8
- import sharp from 'sharp';
8
+ // sharp 是原生模块(加载 .node 二进制约 80ms),只有真正处理头像时才需要。
9
+ // 静态导入会让每个启动都付这笔钱,所以改到 normalizeAvatarImage 里按需加载。
9
10
  import { validateImage } from './media-cache.js';
10
11
  const MAX_AVATAR_BYTES = 500 * 1024;
11
12
  export const MAX_AVATAR_SOURCE_BYTES = 10 * 1024 * 1024;
@@ -26,6 +27,7 @@ const MIME_EXT = {
26
27
  export async function normalizeAvatarImage(buffer) {
27
28
  if (buffer.length > MAX_AVATAR_SOURCE_BYTES)
28
29
  throw new Error('头像源文件超过 10 MiB 限制');
30
+ const { default: sharp } = await import('sharp');
29
31
  const input = sharp(buffer, { failOn: 'error', limitInputPixels: 80_000_000, animated: false });
30
32
  const metadata = await input.metadata();
31
33
  const sourceMimeType = metadata.format === 'jpeg' ? 'image/jpeg' : `image/${metadata.format ?? ''}`;
@@ -2,10 +2,9 @@ import path from 'path';
2
2
  import { fileURLToPath, pathToFileURL } from 'url';
3
3
  import { createRequire } from 'module';
4
4
  import { execFileSync, execFile, spawn, spawnSync } from 'child_process';
5
- import { promisify } from 'util';
5
+ import { promisify, TextDecoder } from 'util';
6
6
  import fs from 'fs';
7
7
  import { getProcessStartTime, parseCimDate } from './process-introspect.js';
8
- import { decodeWindowsOutput } from './windows-output.js';
9
8
  import { resolveTrustedWindowsCmdPath } from './windows-shell-trust.js';
10
9
  const execFileAsync = promisify(execFile);
11
10
  const CLI_PROBE_FAILURE_BACKOFF_MS = 5_000;
@@ -18,6 +17,36 @@ const cliPathCache = new Map();
18
17
  const cliInstallationCache = new Map();
19
18
  const cliProbeCache = new Map();
20
19
  export const isWindows = process.platform === 'win32';
20
+ export function decodeWindowsOutput(value) {
21
+ if (!value)
22
+ return '';
23
+ const bytes = Buffer.isBuffer(value) ? value : Buffer.from(value);
24
+ if (bytes.length === 0)
25
+ return '';
26
+ if (bytes.length >= 2 && bytes[0] === 0xff && bytes[1] === 0xfe) {
27
+ return bytes.subarray(2).toString('utf16le').replace(/^\uFEFF/, '');
28
+ }
29
+ if (bytes.length >= 2 && bytes[0] === 0xfe && bytes[1] === 0xff) {
30
+ const swapped = Buffer.allocUnsafe(bytes.length - 2);
31
+ for (let index = 2; index + 1 < bytes.length; index += 2) {
32
+ swapped[index - 2] = bytes[index + 1];
33
+ swapped[index - 1] = bytes[index];
34
+ }
35
+ return swapped.toString('utf16le').replace(/^\uFEFF/, '');
36
+ }
37
+ const utf8Loose = bytes.toString('utf8');
38
+ if (utf8Loose.includes('\u0000')) {
39
+ const utf16 = bytes.toString('utf16le').replace(/^\uFEFF/, '');
40
+ if (!utf16.includes('\u0000'))
41
+ return utf16;
42
+ }
43
+ try {
44
+ return new TextDecoder('utf-8', { fatal: true }).decode(bytes).replace(/^\uFEFF/, '');
45
+ }
46
+ catch {
47
+ return new TextDecoder('gb18030').decode(bytes).replace(/^\uFEFF/, '');
48
+ }
49
+ }
21
50
  // Keep this in sync with the Windows command-line metacharacters. The whole
22
51
  // `/c` expression is passed as one verbatim argument so paths with spaces and
23
52
  // shim-forwarded values such as `%`, `!`, `&`, and quotes stay data.
@@ -16,7 +16,43 @@ import path from 'node:path';
16
16
  import { execFile } from 'node:child_process';
17
17
  import { readSystemMemoryUsage } from './system-memory.js';
18
18
  import { getPackageRoot } from '../paths.js';
19
+ import { WEB_PACKAGE_NAME } from '../product.js';
19
20
  import { buildCliLaunchCommand, resolveProbePath } from './cross-platform.js';
21
+ function readJsonVersion(filePath) {
22
+ try {
23
+ const pkg = JSON.parse(fs.readFileSync(filePath, 'utf8'));
24
+ return typeof pkg.version === 'string' && pkg.version ? pkg.version : null;
25
+ }
26
+ catch {
27
+ return null;
28
+ }
29
+ }
30
+ /**
31
+ * Read the EC Web copy in use: the development checkout takes precedence over a stale
32
+ * node_modules copy. A globally installed EC Web package is resolved by the daemon.
33
+ */
34
+ export function readLocalEcwebVersion() {
35
+ const pkgRoot = getPackageRoot();
36
+ return readJsonVersion(path.join(pkgRoot, 'ecweb', 'package.json'))
37
+ ?? readJsonVersion(path.join(pkgRoot, 'node_modules', ...WEB_PACKAGE_NAME.split('/'), 'package.json'));
38
+ }
39
+ export function readVersionInfo(options = {}) {
40
+ const pkgRoot = getPackageRoot();
41
+ return {
42
+ evolcore: readJsonVersion(path.join(pkgRoot, 'package.json')),
43
+ fastaun: readJsonVersion(path.join(pkgRoot, 'node_modules', '@agentunion', 'fastaun', 'package.json')),
44
+ ecweb: options.ecweb !== undefined ? options.ecweb : readLocalEcwebVersion(),
45
+ node: process.version,
46
+ };
47
+ }
48
+ export function readRuntimeInfo(runMode) {
49
+ const packagePath = getPackageRoot();
50
+ return {
51
+ packagePath,
52
+ installationType: packagePath.includes('node_modules') ? 'npm-global' : 'development-link',
53
+ runMode: runMode ?? null,
54
+ };
55
+ }
20
56
  function readOsRelease() {
21
57
  if (process.platform !== 'linux')
22
58
  return { id: null, version: null };