evolcore 0.0.41-test.2 → 0.0.42-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 (190) hide show
  1. package/CHANGELOG.md +38 -2
  2. package/bin/codex-managed-hook.mjs +9 -5
  3. package/dist/agents/baseagent.js +156 -16
  4. package/dist/agents/claude-runner.js +10 -3
  5. package/dist/agents/codex/catalog.js +8 -4
  6. package/dist/agents/codex-runner.js +236 -59
  7. package/dist/agents/ecagent-runner.js +82 -13
  8. package/dist/aun/aid/agentmd.js +106 -27
  9. package/dist/aun/aid/client.js +1 -1
  10. package/dist/aun/aid/control-aid.js +65 -13
  11. package/dist/aun/aid/identity.js +70 -4
  12. package/dist/aun/aid/index.js +2 -2
  13. package/dist/aun/service-proxy.js +25 -1
  14. package/dist/channels/aun.js +242 -209
  15. package/dist/channels/dingtalk.js +1 -1
  16. package/dist/channels/feishu.js +1 -1
  17. package/dist/channels/qqbot.js +1 -1
  18. package/dist/channels/wechat.js +1 -1
  19. package/dist/channels/wecom.js +1 -1
  20. package/dist/cli/agent-command.js +183 -3
  21. package/dist/cli/agent-create.js +92 -86
  22. package/dist/cli/agent.js +136 -1
  23. package/dist/cli/aun-commands.js +137 -35
  24. package/dist/cli/bench.js +8 -2
  25. package/dist/cli/command-log.js +1 -1
  26. package/dist/cli/daemon-commands.js +235 -51
  27. package/dist/cli/debug-mode.js +1 -1
  28. package/dist/cli/directory.js +170 -0
  29. package/dist/cli/index.js +40 -30
  30. package/dist/cli/init-channel.js +4 -4
  31. package/dist/cli/init.js +47 -32
  32. package/dist/cli/managed-command-guard.js +4 -1
  33. package/dist/cli/model.js +27 -18
  34. package/dist/cli/pa-workspace-command.js +191 -0
  35. package/dist/cli/{contact.js → peer.js} +19 -25
  36. package/dist/cli/restart-monitor.js +11 -4
  37. package/dist/cli/thread-command.js +47 -18
  38. package/dist/cli/version.js +18 -18
  39. package/dist/config/access-policy.js +29 -12
  40. package/dist/config/boot-log.js +65 -10
  41. package/dist/config/builtin-roles.js +2 -4
  42. package/dist/config/config-field-policy.js +3 -0
  43. package/dist/config/config-manager.js +28 -20
  44. package/dist/config/{contact-bind-code.js → peer-bind-code.js} +6 -6
  45. package/dist/config/{contact-book-store.js → peer-book-store.js} +75 -75
  46. package/dist/config/{contact-book-v2-startup.js → peer-book-v2-startup.js} +2 -2
  47. package/dist/config/{contact-book.js → peer-book.js} +47 -47
  48. package/dist/config/peer-operation-service.js +132 -0
  49. package/dist/config/{contact-request-service.js → peer-request-service.js} +90 -90
  50. package/dist/config/peer-role-resolver.js +3 -3
  51. package/dist/config/providers-config.js +17 -8
  52. package/dist/config/providers.js +1 -1
  53. package/dist/config/schema-migration.js +336 -39
  54. package/dist/core/agent-application-service.js +8 -2
  55. package/dist/core/agent-create-status.js +4 -5
  56. package/dist/core/agent-ipc-registration.js +5 -4
  57. package/dist/core/agent-runtime.js +30 -17
  58. package/dist/core/auth/operation-authorizer.js +0 -24
  59. package/dist/core/auth/operation-catalog.js +4 -20
  60. package/dist/core/baseagent-loader.js +27 -3
  61. package/dist/core/bootstrap-service.js +5 -22
  62. package/dist/core/capability/capability-manager.js +52 -35
  63. package/dist/core/channel-loader.js +43 -2
  64. package/dist/core/channel-runtime.js +2 -2
  65. package/dist/core/command/agent-control.js +54 -18
  66. package/dist/core/command/command-handler.js +92 -72
  67. package/dist/core/command/connect-menu.js +35 -42
  68. package/dist/core/command/daemon-diagnostics.js +41 -5
  69. package/dist/core/command/data-root-error.js +10 -0
  70. package/dist/core/command/data-root-resolver.js +53 -13
  71. package/dist/core/command/menu-catalog.js +1 -0
  72. package/dist/core/command/menu-handler.js +163 -65
  73. package/dist/core/command/menu-protocol.js +52 -0
  74. package/dist/core/command/pa-workspace-calendar.js +223 -0
  75. package/dist/core/command/pa-workspace-store.js +459 -0
  76. package/dist/core/command/role-menu.js +2 -2
  77. package/dist/core/command/slash-gate.js +1 -1
  78. package/dist/core/command/slash-handler.js +57 -41
  79. package/dist/core/daemon-lifecycle.js +90 -31
  80. package/dist/core/evolagent.js +6 -10
  81. package/dist/core/handoff/runtime.js +11 -4
  82. package/dist/core/host-snapshot.js +208 -0
  83. package/dist/core/initialization/service.js +152 -20
  84. package/dist/core/ipc-registration.js +33 -4
  85. package/dist/core/memory/batch-meta.js +27 -0
  86. package/dist/core/memory/consolidation-ops-records.js +44 -1
  87. package/dist/core/memory/consolidation.js +169 -27
  88. package/dist/core/message/aun-ipc-sender.js +2 -8
  89. package/dist/core/message/im-renderer.js +56 -3
  90. package/dist/core/message/message-admission.js +121 -124
  91. package/dist/core/message/message-bridge.js +38 -54
  92. package/dist/core/message/message-queue.js +7 -0
  93. package/dist/core/message/outbound.js +34 -9
  94. package/dist/core/message/response-engine.js +154 -73
  95. package/dist/core/model/catalog-service.js +1 -1
  96. package/dist/core/model/config-scope.js +2 -2
  97. package/dist/core/model/model-catalog.js +5 -4
  98. package/dist/core/model/model-diagnostics.js +6 -5
  99. package/dist/core/model/model-fallback.js +3 -6
  100. package/dist/core/model/model-permission.js +1 -1
  101. package/dist/core/ownership/owner-resolver.js +9 -9
  102. package/dist/core/permission/approval-gateway.js +1 -1
  103. package/dist/core/permission/ec-command-parser.js +2 -2
  104. package/dist/core/permission/tool-canonical.js +96 -46
  105. package/dist/core/permission/tool-error-code.js +41 -0
  106. package/dist/core/permission/tool-policy.js +71 -47
  107. package/dist/core/role/runtime-policy.js +1 -1
  108. package/dist/core/session/session-idle-monitor.js +10 -0
  109. package/dist/core/session/session-manager.js +2 -4
  110. package/dist/core/session/session-title.js +36 -8
  111. package/dist/core/system-session/memory.js +2 -7
  112. package/dist/core/thread/command-parser.js +6 -2
  113. package/dist/core/thread/ipc-operation.js +51 -36
  114. package/dist/core/thread/thread-operation.js +29 -61
  115. package/dist/core/thread/thread-service.js +57 -13
  116. package/dist/directory/canonical-digest.js +54 -0
  117. package/dist/directory/owner-directory-admission.js +114 -43
  118. package/dist/directory/owner-directory-agentmd-sync.js +89 -0
  119. package/dist/directory/owner-directory-cache.js +847 -459
  120. package/dist/directory/owner-directory-markdown.js +272 -0
  121. package/dist/directory/owner-directory-query-operation.js +195 -0
  122. package/dist/directory/owner-directory-remark-operation.js +147 -0
  123. package/dist/directory/owner-directory-remarks.js +145 -0
  124. package/dist/directory/owner-directory-scope.js +55 -0
  125. package/dist/directory/owner-directory-search.js +148 -0
  126. package/dist/directory/owner-directory-store.js +227 -0
  127. package/dist/eck/kit-renderer.js +1 -0
  128. package/dist/ecweb/basic-settings-service.js +4 -1
  129. package/dist/ecweb/message-context-service.js +13 -9
  130. package/dist/index.js +195 -37
  131. package/dist/ipc.js +86 -22
  132. package/dist/paths.js +11 -8
  133. package/dist/product.js +2 -0
  134. package/dist/proxy/manager.js +13 -2
  135. package/dist/proxy/service-supervisor.js +8 -1
  136. package/dist/trigger/history.js +23 -0
  137. package/dist/trigger/scheduler.js +3 -0
  138. package/dist/utils/atomic-write.js +21 -0
  139. package/dist/utils/cross-platform.js +35 -0
  140. package/dist/utils/ecweb-supervisor.js +42 -0
  141. package/dist/utils/error-utils.js +2 -1
  142. package/dist/utils/evolcore-version.js +19 -0
  143. package/dist/utils/host-info.js +242 -5
  144. package/dist/utils/instance-registry.js +28 -6
  145. package/dist/utils/logger.js +59 -14
  146. package/dist/utils/machine-info.js +46 -0
  147. package/dist/utils/process-introspect.js +166 -2
  148. package/dist/utils/startup-trace.js +245 -0
  149. package/ecagent/dist/agent-loop.js +27 -13
  150. package/ecagent/dist/harness/agent-harness.js +3 -3
  151. package/ecagent/dist/harness/types.d.ts +1 -0
  152. package/ecagent/dist/types.d.ts +1 -0
  153. package/kits/docs/INDEX.md +1 -1
  154. package/kits/docs/aun/AUN/346/266/210/346/201/257/347/261/273/345/236/213/344/270/216/345/261/236/346/200/247.md +72 -0
  155. package/kits/docs/evolcore/INDEX.md +3 -2
  156. package/kits/docs/evolcore/agent-create.md +17 -27
  157. package/kits/docs/evolcore/agent.md +4 -1
  158. package/kits/docs/evolcore/aid.md +3 -1
  159. package/kits/docs/evolcore/config.md +16 -5
  160. package/kits/docs/evolcore/ctl.md +9 -0
  161. package/kits/docs/evolcore/ec-capabilities.md +19 -0
  162. package/kits/docs/evolcore/memory-consolidation-batches.md +79 -5
  163. package/kits/docs/evolcore/menu-exec-schema-commands.md +2 -1
  164. package/kits/docs/evolcore/menu-protocol.md +1 -0
  165. package/kits/docs/evolcore/model.md +13 -4
  166. package/kits/docs/evolcore/msg.md +1 -1
  167. package/kits/docs/evolcore/pa-workspace.md +51 -0
  168. package/kits/docs/evolcore/peer.md +73 -0
  169. package/kits/docs/evolcore/thread-chain.md +4 -1
  170. package/kits/eck_manifest.json +21 -0
  171. package/kits/rules/06-channel.md +1 -1
  172. package/kits/schemas/_meta.json +12 -1
  173. package/kits/schemas/agent-config.schema.16.json +6 -0
  174. package/kits/schemas/agent-config.schema.17.json +897 -0
  175. package/kits/schemas/daemon.schema.9.json +8 -1
  176. package/kits/skills/ec-agent-create/SKILL.md +2 -2
  177. package/kits/skills/ec-identity/SKILL.md +45 -27
  178. package/kits/skills/ec-service-proxy/SKILL.md +7 -2
  179. package/kits/skills/personal-assistant/references/03-data-flow-and-gaps.md +4 -5
  180. package/kits/skills/thread-ops/SKILL.md +11 -11
  181. package/kits/templates/bootstrap-welcome.md +3 -15
  182. package/kits/templates/message-fragments/item.md +1 -1
  183. package/kits/templates/system-fragments/bootstrap.md +24 -23
  184. package/kits/templates/system-fragments/commands.md +12 -5
  185. package/kits/templates/system-fragments/thread.md +18 -3
  186. package/package.json +6 -4
  187. package/dist/config/contact-operation-service.js +0 -235
  188. package/dist/directory/owner-directory-authorization.js +0 -309
  189. package/kits/docs/evolcore/contact.md +0 -78
  190. /package/dist/config/{contact-alias.js → peer-alias.js} +0 -0
package/dist/ipc.js CHANGED
@@ -94,9 +94,9 @@ const MEMORY_COMMAND_ENDPOINTS = new Set([
94
94
  'memory.create', 'memory.update', 'memory.archive', 'memory.demote', 'memory.consolidate',
95
95
  ]);
96
96
  const DELEGATED_ARGV_ENDPOINTS = new Set([
97
- 'agent.op', 'config.op', 'contact.op', 'aid.op', 'aid.ownership', 'group.op', 'msg.op', 'fs.op', 'proxy.op',
97
+ 'agent.op', 'config.op', 'peer.op', 'aid.op', 'aid.ownership', 'group.op', 'msg.op', 'fs.op', 'proxy.op',
98
98
  'ctl', 'diag', 'menu-client.request', 'task.resume', 'queue.op', 'storage.auth', 'storage.upload',
99
- 'trigger.op', 'skill.refresh', 'thread.op', 'local-command-context', 'evolagent.bootstrapComplete', 'status.auth', ...MEMORY_COMMAND_ENDPOINTS,
99
+ 'trigger.op', 'skill.refresh', 'thread.op', 'local-command-context', 'evolagent.bootstrapComplete', 'status.auth', 'logs.query', ...MEMORY_COMMAND_ENDPOINTS,
100
100
  'handoff-return', 'handoff-recover-return', 'handoff-status', 'handoff-list', 'handoff-trace',
101
101
  ]);
102
102
  let ipcQuerySequence = 0;
@@ -196,9 +196,11 @@ export class IpcServer {
196
196
  statsProvider;
197
197
  agentStatsProvider;
198
198
  queueSnapshotProvider;
199
+ hostSnapshotProvider;
199
200
  queueActionExecutor;
200
201
  queueOperationExecutor;
201
202
  statusAuthorizationExecutor;
203
+ logsQueryExecutor;
202
204
  taskResumeExecutor;
203
205
  storageAuthorizationExecutor;
204
206
  storageUploadExecutor;
@@ -227,9 +229,10 @@ export class IpcServer {
227
229
  bindExecutor;
228
230
  aidOwnershipExecutor;
229
231
  configOperationExecutor;
230
- contactOperationExecutor;
232
+ peerOperationExecutor;
231
233
  roleOperationExecutor;
232
234
  aidOperationExecutor;
235
+ directoryOperationExecutor;
233
236
  groupOperationExecutor;
234
237
  msgOperationExecutor;
235
238
  fsOperationExecutor;
@@ -337,8 +340,11 @@ export class IpcServer {
337
340
  setConfigOperationExecutor(executor) {
338
341
  this.configOperationExecutor = executor;
339
342
  }
340
- setContactOperationExecutor(executor) {
341
- this.contactOperationExecutor = executor;
343
+ setPeerOperationExecutor(executor) {
344
+ this.peerOperationExecutor = executor;
345
+ }
346
+ setDirectoryOperationExecutor(executor) {
347
+ this.directoryOperationExecutor = executor;
342
348
  }
343
349
  setAidOperationExecutor(executor) {
344
350
  this.aidOperationExecutor = executor;
@@ -463,6 +469,14 @@ export class IpcServer {
463
469
  },
464
470
  };
465
471
  }
472
+ /** 主机信息快照提供者(/system view=host、ec agent host、ecweb 主机页共用)。 */
473
+ setHostSnapshotProvider(provider) {
474
+ this.hostSnapshotProvider = provider;
475
+ }
476
+ /** 系统级 CPU 占用百分比(由后台 1s 采样累积,供主机快照读取)。 */
477
+ getSystemCpuPercent() {
478
+ return typeof this.sysCpuPercent === 'number' ? Math.round(this.sysCpuPercent * 10) / 10 : null;
479
+ }
466
480
  /** Inject queue snapshot provider for queue-snapshot IPC handler (query mode) */
467
481
  setQueueSnapshotProvider(provider) {
468
482
  this.queueSnapshotProvider = provider;
@@ -477,6 +491,9 @@ export class IpcServer {
477
491
  setStatusAuthorizationExecutor(executor) {
478
492
  this.statusAuthorizationExecutor = executor;
479
493
  }
494
+ setLogsQueryExecutor(executor) {
495
+ this.logsQueryExecutor = executor;
496
+ }
480
497
  setTaskResumeExecutor(executor) {
481
498
  this.taskResumeExecutor = executor;
482
499
  }
@@ -968,17 +985,16 @@ export class IpcServer {
968
985
  }
969
986
  catch { }
970
987
  }
971
- const permissionsReady = isNamedPipe(this.socketPath)
972
- ? grantWindowsSandboxPipeAccess(this.socketPath)
973
- : Promise.resolve();
974
- void permissionsReady.then(() => {
975
- logger.info(`[IPC] Listening on ${this.socketPath}`);
976
- resolve();
977
- }, error => {
978
- this.stop();
979
- logger.error('[IPC] Unable to configure pipe permissions:', error);
980
- reject(error);
981
- });
988
+ logger.info(`[IPC] Listening on ${this.socketPath}`);
989
+ // 管道 ACL 只决定 Codex 沙箱账号能否连上控制面,不影响 daemon 自己用 IPC。
990
+ // 它是 Windows 上一次 PowerShell 启动(数百 ms),不能让它挡住就绪;
991
+ // 失败降级为 WARN:控制面照常可用,只是沙箱内进程连不进来。
992
+ if (isNamedPipe(this.socketPath)) {
993
+ void grantWindowsSandboxPipeAccess(this.socketPath).catch(error => {
994
+ logger.warn('[IPC] Unable to configure pipe permissions (daemon control plane is unaffected; Codex sandbox processes may not connect):', error);
995
+ });
996
+ }
997
+ resolve();
982
998
  });
983
999
  });
984
1000
  }
@@ -1228,6 +1244,12 @@ export class IpcServer {
1228
1244
  }
1229
1245
  case 'status':
1230
1246
  return this.getStatus();
1247
+ case 'host.snapshot': {
1248
+ if (!this.hostSnapshotProvider) {
1249
+ return { ok: false, code: 'NOT_CONFIGURED', error: 'host snapshot provider not configured' };
1250
+ }
1251
+ return { ok: true, snapshot: this.hostSnapshotProvider() };
1252
+ }
1231
1253
  case 'codex-pre-tool-use': {
1232
1254
  if (!this.codexPreToolUseExecutor) {
1233
1255
  return { ok: false, applicable: true, decision: 'deny', reason: 'EvolCore Codex policy executor is unavailable' };
@@ -1241,7 +1263,10 @@ export class IpcServer {
1241
1263
  const sessionToken = typeof cmd.sessionToken === 'string' && cmd.sessionToken
1242
1264
  ? cmd.sessionToken
1243
1265
  : undefined;
1244
- if (!sessionToken) {
1266
+ const hookToken = typeof cmd.hookToken === 'string' && cmd.hookToken
1267
+ ? cmd.hookToken
1268
+ : undefined;
1269
+ if (!sessionToken && !hookToken) {
1245
1270
  return { ok: true, applicable: true, decision: 'allow' };
1246
1271
  }
1247
1272
  try {
@@ -1251,6 +1276,7 @@ export class IpcServer {
1251
1276
  toolInput: cmd.toolInput,
1252
1277
  callId: typeof cmd.callId === 'string' ? cmd.callId : undefined,
1253
1278
  sessionToken,
1279
+ hookToken,
1254
1280
  signal: requestSignal,
1255
1281
  });
1256
1282
  }
@@ -1302,9 +1328,13 @@ export class IpcServer {
1302
1328
  const reason = typeof cmd.reason === 'string' && cmd.reason.trim()
1303
1329
  ? cmd.reason.trim().slice(0, 80)
1304
1330
  : 'ipc';
1331
+ // 发起方(ec stop)传入的 traceId,让 daemon 侧退出阶段落进同一条停止甘特图。
1332
+ const traceId = typeof cmd.traceId === 'string' && cmd.traceId.trim()
1333
+ ? cmd.traceId.trim().slice(0, 80)
1334
+ : undefined;
1305
1335
  // Let the response flush before shutdown closes the IPC server/process.
1306
1336
  setImmediate(() => {
1307
- Promise.resolve(this.shutdownExecutor?.(reason)).catch(error => {
1337
+ Promise.resolve(this.shutdownExecutor?.(reason, traceId)).catch(error => {
1308
1338
  logger.error(`[IPC] graceful shutdown failed: ${error instanceof Error ? error.message : String(error)}`);
1309
1339
  });
1310
1340
  });
@@ -1520,6 +1550,20 @@ export class IpcServer {
1520
1550
  argv: Array.isArray(cmd.argv) ? cmd.argv : undefined,
1521
1551
  });
1522
1552
  }
1553
+ case 'logs.query': {
1554
+ if (!this.logsQueryExecutor)
1555
+ return { ok: false, code: 'NOT_CONFIGURED', error: 'logs query not configured' };
1556
+ if (!Array.isArray(cmd.argv) || cmd.argv.some((value) => typeof value !== 'string')
1557
+ || typeof cmd.sessionId !== 'string' || !cmd.sessionId) {
1558
+ return { ok: false, code: 'INVALID_REQUEST', error: 'managed logs requires argv and sessionId' };
1559
+ }
1560
+ return this.logsQueryExecutor({
1561
+ argv: cmd.argv,
1562
+ sessionId: cmd.sessionId,
1563
+ delegationToken: typeof cmd.delegationToken === 'string' ? cmd.delegationToken : undefined,
1564
+ delegationCommandHash: typeof cmd.delegationCommandHash === 'string' ? cmd.delegationCommandHash : undefined,
1565
+ });
1566
+ }
1523
1567
  case 'storage.auth': {
1524
1568
  if (!this.storageAuthorizationExecutor)
1525
1569
  return { ok: false, code: 'NOT_CONFIGURED', error: 'storage authorization not configured' };
@@ -1605,7 +1649,7 @@ export class IpcServer {
1605
1649
  }
1606
1650
  case 'local-command-context': {
1607
1651
  if (!Array.isArray(cmd.argv) || cmd.argv.some((value) => typeof value !== 'string')
1608
- || !['skill', 'stats', 'session'].includes(cmd.argv[0]) || typeof cmd.sessionId !== 'string' || !cmd.sessionId
1652
+ || !['skill', 'stats', 'session', 'pa-workspace'].includes(cmd.argv[0]) || typeof cmd.sessionId !== 'string' || !cmd.sessionId
1609
1653
  || typeof cmd.delegationToken !== 'string' || !cmd.delegationToken) {
1610
1654
  return { ok: false, code: 'INVALID_REQUEST', error: 'Local command requires argv and task credentials' };
1611
1655
  }
@@ -1622,6 +1666,14 @@ export class IpcServer {
1622
1666
  if (!context?.selfAid || !context.peerRole || context.peerRole === 'none') {
1623
1667
  return { ok: false, code: 'NOT_ALLOWED', error: 'Current task identity and role are unavailable' };
1624
1668
  }
1669
+ if (cmd.argv[0] === 'pa-workspace'
1670
+ && (context.channel !== 'aun' || context.chatType !== 'private' || context.peerRole !== 'owner' || !context.peerId)) {
1671
+ return { ok: false, code: 'NOT_ALLOWED', error: 'PA workspace commands require the current Agent owner in an AUN private chat' };
1672
+ }
1673
+ if (cmd.argv[0] === 'pa-workspace' && context.permissionMode === 'readonly'
1674
+ && (cmd.argv[1] === 'init' || cmd.argv[1] === 'bind' || (cmd.argv[1] === 'navigation' && cmd.argv[2] === 'update'))) {
1675
+ return { ok: false, code: 'NOT_ALLOWED', error: 'Readonly tasks cannot change PA workspace state' };
1676
+ }
1625
1677
  const fullAccessTask = context.processRole === 'fullaccess-run'
1626
1678
  && context.dataScope === 'daemon' && context.permissionMode === 'fullaccess';
1627
1679
  if (cmd.argv[0] === 'stats' && !fullAccessTask
@@ -2251,8 +2303,8 @@ export class IpcServer {
2251
2303
  }
2252
2304
  return await this.configOperationExecutor(argv, sessionId, delegationToken, typeof cmd.delegationCommandHash === 'string' ? cmd.delegationCommandHash : undefined, requestId);
2253
2305
  }
2254
- case 'contact.op': {
2255
- if (!this.contactOperationExecutor)
2306
+ case 'peer.op': {
2307
+ if (!this.peerOperationExecutor)
2256
2308
  return { ok: false, code: 'NOT_CONFIGURED', error: 'contact.op not configured' };
2257
2309
  const { argv, sessionId, delegationToken } = cmd;
2258
2310
  if (!Array.isArray(argv) || argv.some(value => typeof value !== 'string') || !sessionId) {
@@ -2261,7 +2313,7 @@ export class IpcServer {
2261
2313
  if (delegationToken !== undefined && typeof delegationToken !== 'string') {
2262
2314
  return { ok: false, code: 'INVALID_DELEGATION', error: 'delegationToken must be a string' };
2263
2315
  }
2264
- return await this.contactOperationExecutor(argv, sessionId, delegationToken, typeof cmd.delegationCommandHash === 'string' ? cmd.delegationCommandHash : undefined);
2316
+ return await this.peerOperationExecutor(argv, sessionId, delegationToken, typeof cmd.delegationCommandHash === 'string' ? cmd.delegationCommandHash : undefined);
2265
2317
  }
2266
2318
  case 'role.op': {
2267
2319
  if (!this.roleOperationExecutor)
@@ -2275,6 +2327,18 @@ export class IpcServer {
2275
2327
  }
2276
2328
  return await this.roleOperationExecutor(argv, sessionId, delegationToken, typeof cmd.delegationCommandHash === 'string' ? cmd.delegationCommandHash : undefined);
2277
2329
  }
2330
+ case 'directory.op': {
2331
+ if (!this.directoryOperationExecutor)
2332
+ return { ok: false, code: 'NOT_CONFIGURED', error: 'directory.op not configured' };
2333
+ const { argv, sessionId, delegationToken } = cmd;
2334
+ if (!Array.isArray(argv) || argv.some(value => typeof value !== 'string') || !sessionId) {
2335
+ return { ok: false, code: 'INVALID_REQUEST', error: 'missing argv or sessionId' };
2336
+ }
2337
+ if (delegationToken !== undefined && typeof delegationToken !== 'string') {
2338
+ return { ok: false, code: 'INVALID_DELEGATION', error: 'delegationToken must be a string' };
2339
+ }
2340
+ return await this.directoryOperationExecutor(argv, sessionId, delegationToken, typeof cmd.delegationCommandHash === 'string' ? cmd.delegationCommandHash : undefined);
2341
+ }
2278
2342
  case 'aid.op': {
2279
2343
  if (!this.aidOperationExecutor)
2280
2344
  return { ok: false, code: 'NOT_CONFIGURED', error: 'aid.op not configured' };
package/dist/paths.js CHANGED
@@ -41,6 +41,8 @@ export function resolvePaths() {
41
41
  lineStats: path.join(root, 'logs', 'line-stats.log'),
42
42
  readySignal: path.join(root, 'data', 'instance', 'ready.signal'),
43
43
  controlToken: path.join(root, 'data', 'instance', 'control.token'),
44
+ /** 启动/停止阶段埋点记录(CLI 与 daemon 各写一行,按 traceId 关联) */
45
+ lifecycleTrace: path.join(root, 'data', 'instance', 'lifecycle-trace.jsonl'),
44
46
  selfHealLog: path.join(root, 'logs', 'self-heal.md'),
45
47
  socket: resolveInstanceSocketPath(root),
46
48
  // ── daemon/process 配置与 ECK ─────────────────────────────
@@ -87,17 +89,18 @@ export function agentDir(aid) {
87
89
  export function agentConfig(aid) {
88
90
  return path.join(agentDir(aid), 'config.json');
89
91
  }
90
- export function agentContactConfig(aid) {
91
- return path.join(agentDir(aid), 'contact.json');
92
+ /** 本 Agent 的对端身份映射(跨渠道别名、displayName、本地拉黑)。 */
93
+ export function agentPeerConfig(aid) {
94
+ return path.join(agentDir(aid), 'peers.json');
92
95
  }
93
- export function agentContactOperations(aid) {
94
- return path.join(agentDataDir(aid), 'contact', 'operations.jsonl');
96
+ export function agentPeerOperations(aid) {
97
+ return path.join(agentDataDir(aid), 'peer', 'operations.jsonl');
95
98
  }
96
- export function agentContactDataDir(aid) {
97
- return path.join(agentDataDir(aid), 'contact');
99
+ export function agentPeerDataDir(aid) {
100
+ return path.join(agentDataDir(aid), 'peer');
98
101
  }
99
- export function agentContactAuditPath(aid) {
100
- return path.join(agentContactDataDir(aid), 'audit.jsonl');
102
+ export function agentPeerAuditPath(aid) {
103
+ return path.join(agentPeerDataDir(aid), 'audit.jsonl');
101
104
  }
102
105
  export function agentPersonalDir(aid) {
103
106
  return path.join(agentDir(aid), 'personal');
package/dist/product.js CHANGED
@@ -8,6 +8,7 @@ export const PRODUCT_DISPLAY_NAME = 'EvolCore';
8
8
  export const MAIN_PACKAGE_NAME = 'evolcore';
9
9
  export const MAIN_CLI_BIN = 'ec';
10
10
  export const RESTART_REQUEST_ID_ENV = 'EVOLCORE_RESTART_REQUEST_ID';
11
+ export const CHANNEL_LOGS_ENV = 'CHANNEL_LOGS';
11
12
  export const WEB_PACKAGE_NAME = 'ec-web';
12
13
  export const WEB_CLI_BIN = 'ec-web';
13
14
  export const WEB_PACKAGE_LATEST = `${WEB_PACKAGE_NAME}@latest`;
@@ -18,6 +19,7 @@ export const RUNTIME_HOME_ENV = 'EVOLCORE_HOME';
18
19
  export const TARGET_PACKAGE_ROOT_ENV = 'EVOLCORE_TARGET_PACKAGE_ROOT';
19
20
  export const SESSION_ID_ENV = 'EVOLCORE_SESSION_ID';
20
21
  export const SELF_AID_ENV = 'EVOLCORE_SELF_AID';
22
+ export const CODEX_HOOK_TOKEN_ENV = 'EVOLCORE_CODEX_HOOK_TOKEN';
21
23
  export const DEFAULT_RUNTIME_HOME_DIRNAME = '.evolcore';
22
24
  export const INSTANCE_SOCKET_FILENAME = 'daemon.sock';
23
25
  export const WINDOWS_PIPE_PREFIX = 'daemon';
@@ -8,6 +8,7 @@ import { loadDaemonConfig } from '../config-store.js';
8
8
  import { resolvePaths } from '../paths.js';
9
9
  import { atomicWriteJson } from '../utils/atomic-write.js';
10
10
  import { logger as defaultLogger } from '../utils/logger.js';
11
+ import { probeServiceRoot } from '../aun/service-proxy.js';
11
12
  import { startServiceProxy } from '../aun/service-proxy.js';
12
13
  import { ServiceSupervisor } from './service-supervisor.js';
13
14
  const MUTATIONS = new Set([
@@ -51,6 +52,11 @@ function serviceRevision(service) {
51
52
  function findService(services, name) {
52
53
  return services.find(service => service.name === name);
53
54
  }
55
+ function serviceProxyAccessUrl(providerAid, serviceName) {
56
+ if (!/^[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)+$/.test(providerAid))
57
+ return null;
58
+ return `https://${providerAid}/proxy/${encodeURIComponent(serviceName)}/`;
59
+ }
54
60
  function validateOperationId(value) {
55
61
  if (typeof value !== 'string' || !/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/.test(value)) {
56
62
  throw Object.assign(new Error('operationId must contain 1-128 safe characters'), { code: 'INVALID_ARGUMENT' });
@@ -198,12 +204,17 @@ export class ServiceProxyManager {
198
204
  return { ok: true, jobId, state: 'completed', completedAt: record.completedAt, result: record.result };
199
205
  }
200
206
  if (request.operation === 'access') {
207
+ const url = serviceProxyAccessUrl(this.options.providerAid, service.name);
208
+ const probe = service.enabled === true && service.proxy?.enabled === true
209
+ ? await probeServiceRoot(service)
210
+ : { accessState: 'unavailable' };
201
211
  return {
202
212
  ok: true,
203
213
  providerAid: this.options.providerAid,
204
214
  service: this.describe(service),
205
- accessState: 'unresolved',
206
- url: null,
215
+ accessState: url ? probe.accessState : 'unresolved',
216
+ url,
217
+ ...(probe.statusCode === undefined ? {} : { statusCode: probe.statusCode }),
207
218
  };
208
219
  }
209
220
  if (request.operation === 'show')
@@ -353,7 +353,14 @@ export class ServiceSupervisor {
353
353
  detached: true,
354
354
  stdio: ['ignore', fd, fd],
355
355
  windowsHide: platform.isWindows,
356
- env: { ...process.env },
356
+ // The configured service port is authoritative. In particular, do
357
+ // not let a daemon-shell PORT value silently redirect a managed
358
+ // service away from services[].port and make readiness probe the
359
+ // wrong listener.
360
+ env: {
361
+ ...process.env,
362
+ ...(active.config.port === undefined ? {} : { PORT: String(active.config.port) }),
363
+ },
357
364
  });
358
365
  }
359
366
  catch (error) {
@@ -125,6 +125,29 @@ export class TriggerHistoryStore {
125
125
  }
126
126
  return out;
127
127
  }
128
+ runsInRange(fromTs, toTs, limit = 500, triggerIds) {
129
+ const runs = new Map();
130
+ let truncated = false;
131
+ const lines = this.readLines();
132
+ for (let i = lines.length - 1; i >= 0; i--) {
133
+ const event = parseHistoryEvent(lines[i], this.agentAid);
134
+ if (!event || !isRunEvent(event) || event.agentAid !== this.agentAid
135
+ || (triggerIds && !triggerIds.has(event.triggerId)))
136
+ continue;
137
+ const audit = hydrateTriggerAudit(event.audit);
138
+ if (audit.startedAt < fromTs || audit.startedAt >= toTs || runs.has(audit.runId))
139
+ continue;
140
+ if (runs.size === limit) {
141
+ truncated = true;
142
+ break;
143
+ }
144
+ runs.set(audit.runId, audit);
145
+ }
146
+ return {
147
+ runs: [...runs.values()].sort((a, b) => a.startedAt - b.startedAt || a.runId.localeCompare(b.runId)),
148
+ truncated,
149
+ };
150
+ }
128
151
  latestRuns(triggerIds) {
129
152
  const pending = new Set(triggerIds);
130
153
  const latest = new Map();
@@ -208,6 +208,9 @@ export class TriggerRuntimeScheduler {
208
208
  ...(run.error?.code ? { errorCode: run.error.code } : {}),
209
209
  }));
210
210
  }
211
+ runsInRange(fromTs, toTs, limit = 500, triggerIds) {
212
+ return this.manager.history.runsInRange(fromTs, toTs, limit, triggerIds);
213
+ }
211
214
  scriptPreview(definition) {
212
215
  if (definition.execution.type !== 'script' || !definition.execution.script)
213
216
  return undefined;
@@ -154,6 +154,27 @@ export function atomicRead(filePath) {
154
154
  }
155
155
  return null;
156
156
  }
157
+ /**
158
+ * Delete a file written by atomicWrite. Removing only the live path is not
159
+ * enough: atomicRead treats a lone hot backup as an interrupted rename and
160
+ * restores it, resurrecting the previous version.
161
+ */
162
+ export function atomicRemove(filePath) {
163
+ // Backup first: a crash after removing only the live path must not leave a
164
+ // hot backup behind for atomicRead to restore.
165
+ fs.rmSync(filePath + HOT, { force: true });
166
+ fs.rmSync(filePath + TMP, { force: true });
167
+ fs.rmSync(filePath, { force: true });
168
+ }
169
+ /**
170
+ * 文件是否存在——包含"只留下热备"的中断状态。
171
+ *
172
+ * 业务层不该知道 `_` 后缀这回事,所以把判断收在这里:只要正式名或热备存在,
173
+ * 就说明这条数据在盘上(`atomicRead` 会从热备恢复)。
174
+ */
175
+ export function existsAtomic(filePath) {
176
+ return fs.existsSync(filePath) || fs.existsSync(filePath + HOT);
177
+ }
157
178
  export function atomicReadJson(filePath) {
158
179
  const text = atomicRead(filePath);
159
180
  if (text === null)
@@ -723,6 +723,41 @@ export function killProcess(pid, force = false) {
723
723
  return !isProcessRunning(pid);
724
724
  }
725
725
  }
726
+ /**
727
+ * Terminate exactly one process, without recursively terminating its children.
728
+ *
729
+ * The restart monitor is launched by the daemon it supervises. Windows
730
+ * `taskkill /T` would therefore kill the monitor along with an unresponsive
731
+ * daemon, leaving no process to start the replacement daemon.
732
+ */
733
+ export function killProcessOnly(pid, force = false) {
734
+ if (!Number.isInteger(pid) || pid <= 0)
735
+ return false;
736
+ if (isWindows) {
737
+ try {
738
+ const args = ['/PID', String(pid)];
739
+ if (force)
740
+ args.push('/F');
741
+ const result = spawnSync('taskkill', args, {
742
+ encoding: 'utf-8',
743
+ timeout: 10_000,
744
+ stdio: ['ignore', 'pipe', 'pipe'],
745
+ windowsHide: true,
746
+ });
747
+ return result.status === 0 || !isProcessRunning(pid);
748
+ }
749
+ catch {
750
+ return !isProcessRunning(pid);
751
+ }
752
+ }
753
+ try {
754
+ process.kill(pid, force ? 'SIGKILL' : 'SIGTERM');
755
+ return true;
756
+ }
757
+ catch {
758
+ return !isProcessRunning(pid);
759
+ }
760
+ }
726
761
  /** Terminate a detached process group where supported, falling back to one PID. */
727
762
  export function killProcessTree(pid, force = false) {
728
763
  if (!Number.isInteger(pid) || pid <= 0)
@@ -9,10 +9,48 @@ import { ecwebVersionRequirementError, resolveEcwebLaunchCommand } from './ecweb
9
9
  import * as platform from './cross-platform.js';
10
10
  import { getProcessStartTime, startTimeMatches } from './process-introspect.js';
11
11
  import { matchesEcwebInstanceHealth, parseEcwebInstanceRecord } from '../contracts/ecweb-instance.js';
12
+ import { sanitizeMenuLogValue } from '../core/command/menu-protocol.js';
12
13
  const INSTANCE_FILE_RE = /^(?:ecweb|watch-web)-\d+\.json$/;
13
14
  function sleep(ms) {
14
15
  return new Promise(resolve => setTimeout(resolve, ms));
15
16
  }
17
+ function readExitDiagnostics(filePath, startOffset) {
18
+ let fd;
19
+ try {
20
+ fd = fs.openSync(filePath, 'r');
21
+ const size = fs.fstatSync(fd).size;
22
+ const length = Math.min(32_768, Math.max(0, size - startOffset));
23
+ if (length === 0)
24
+ return undefined;
25
+ const buffer = Buffer.alloc(length);
26
+ const bytesRead = fs.readSync(fd, buffer, 0, length, size - length);
27
+ let text = buffer.toString('utf8', 0, bytesRead).replace(/\x1b\[[0-?]*[ -/]*[@-~]/g, '');
28
+ if (size - length > startOffset) {
29
+ const nextLine = text.indexOf('\n');
30
+ if (nextLine < 0)
31
+ return undefined;
32
+ text = text.slice(nextLine + 1);
33
+ }
34
+ const lines = text.split(/\r?\n/).filter(Boolean).map(line => {
35
+ const withoutPairingCode = line.replace(/((?:配对码|pair(?:ing)?[_\s-]*code)\s*[:=]\s*)\S+/gi, '$1[REDACTED]');
36
+ const withoutJsonSecrets = withoutPairingCode.replace(/(["'](?:api[_-]?key|access[_-]?token|refresh[_-]?token|menu[_-]?token|token|password|passwd|secret|credentials?|authorization|cookie|private[_-]?key|pair(?:ing)?[_-]?code)["']\s*:\s*)(?:"(?:\\.|[^"\\\r\n])*"|'(?:\\.|[^'\\\r\n])*'|[^,}\s]+)/gi, '$1"[REDACTED]"').replace(/(["']code["']\s*:\s*["']?)\d{6}(?=["'\s,}])/gi, '$1[REDACTED]');
37
+ return String(sanitizeMenuLogValue(withoutJsonSecrets));
38
+ });
39
+ const tail = lines.slice(-40).join('\n').trim();
40
+ return tail ? tail.slice(-12_000) : undefined;
41
+ }
42
+ catch {
43
+ return undefined;
44
+ }
45
+ finally {
46
+ if (fd !== undefined) {
47
+ try {
48
+ fs.closeSync(fd);
49
+ }
50
+ catch { }
51
+ }
52
+ }
53
+ }
16
54
  function isAlive(record) {
17
55
  if (!Number.isInteger(record.pid) || record.pid <= 0)
18
56
  return false;
@@ -237,6 +275,7 @@ export function createEcwebSupervisor(options) {
237
275
  }
238
276
  fs.mkdirSync(resolvePaths().logs, { recursive: true });
239
277
  fs.appendFileSync(logFile, `\n# daemon supervisor start ${new Date().toISOString()}\n`);
278
+ const childLogStartOffset = fs.statSync(logFile).size;
240
279
  // `spawn()` accepts inherited file descriptors, but not a WriteStream
241
280
  // whose fd has not been opened yet. Open once and pass the numeric fd to
242
281
  // both stdout and stderr; the parent closes its copy after spawning.
@@ -275,6 +314,9 @@ export function createEcwebSupervisor(options) {
275
314
  });
276
315
  spawned.once('exit', (code, signal) => {
277
316
  options.logger.warn(`ECWeb 进程退出 (PID: ${spawned.pid ?? 'unknown'}, code=${code ?? 'null'}, signal=${signal ?? 'null'})`);
317
+ const diagnostics = child === spawned ? readExitDiagnostics(logFile, childLogStartOffset) : undefined;
318
+ if (diagnostics)
319
+ options.logger.warn(`ECWeb 退出诊断(最近日志,含异常栈如有):\n${diagnostics}`);
278
320
  if (child === spawned) {
279
321
  child = null;
280
322
  childStartedAt = 0;
@@ -261,6 +261,7 @@ const NON_INFRA_SUBTYPES = new Set([
261
261
  'stop',
262
262
  ]);
263
263
  const NON_INFRA_TERMINAL_REASONS = new Set([
264
+ 'interrupted',
264
265
  'max_output_tokens',
265
266
  'rapid_refill_breaker',
266
267
  'tool_deferred',
@@ -275,7 +276,7 @@ const NON_INFRA_TERMINAL_REASONS = new Set([
275
276
  * an infrastructure or agent execution failure.
276
277
  */
277
278
  export function isAbortTerminalReason(terminalReason) {
278
- return terminalReason === 'aborted_streaming' || terminalReason === 'aborted_tools';
279
+ return terminalReason === 'interrupted' || terminalReason === 'aborted_streaming' || terminalReason === 'aborted_tools';
279
280
  }
280
281
  export function isInfraError(subtype, terminalReason) {
281
282
  // terminalReason 优先级更高(更精确)
@@ -121,6 +121,25 @@ export function tagErrorTextWithEvolcoreVersion(text) {
121
121
  const decoration = text.match(LEADING_DECORATION)?.[0] ?? '';
122
122
  return `${decoration}${evolcoreErrorTag()} ${text.slice(decoration.length)}`;
123
123
  }
124
+ /**
125
+ * Test whether an error body already contains its raw diagnostic text.
126
+ *
127
+ * Outbound adapters may receive a payload after the user-visible body has
128
+ * been tagged with the EvolCore version. Strip that tag for the comparison so
129
+ * the adapter does not append the same diagnostic a second time.
130
+ */
131
+ export function errorTextContainsRaw(text, raw) {
132
+ if (!text || !raw)
133
+ return false;
134
+ if (text.includes(`原因:${raw}`))
135
+ return true;
136
+ const normalize = (value) => value
137
+ .replace(ERROR_TAG_PATTERN, '')
138
+ .replace(/[ \t]+/g, ' ')
139
+ .trim();
140
+ const normalizedRaw = normalize(raw);
141
+ return normalizedRaw.length > 0 && normalize(text).includes(normalizedRaw);
142
+ }
124
143
  export function _resetInstalledEvolcoreVersionForTests() {
125
144
  cachedVersion = undefined;
126
145
  cachedFlavor = undefined;