evolcore 0.0.43-test.3 → 0.0.43-test.5

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 (192) hide show
  1. package/CHANGELOG.md +82 -0
  2. package/bin/ecmsg.js +492 -0
  3. package/bin/install-codex-managed-hooks.mjs +130 -8
  4. package/dist/ability/application-service.js +37 -0
  5. package/dist/ability/resources.js +28 -0
  6. package/dist/ability/runtime.js +6 -1
  7. package/dist/agents/claude-runner.js +7 -5
  8. package/dist/agents/codex/app-server-client.js +0 -12
  9. package/dist/agents/codex-runner.js +12 -54
  10. package/dist/agents/ecagent-runner.js +130 -35
  11. package/dist/aun/aid/agentmd.js +56 -12
  12. package/dist/aun/aid/control-aid.js +15 -0
  13. package/dist/aun/aid/identity.js +8 -0
  14. package/dist/aun/aid/ownership-operation.js +12 -3
  15. package/dist/aun/menu/client.js +8 -7
  16. package/dist/aun/menu/index.js +1 -1
  17. package/dist/aun/menu/transport.js +8 -5
  18. package/dist/aun/service-proxy.js +3 -0
  19. package/dist/channels/aun.js +56 -22
  20. package/dist/channels/daemon.js +12 -4
  21. package/dist/cli/agent-command.js +5 -0
  22. package/dist/cli/agent-create.js +32 -8
  23. package/dist/cli/agent.js +9 -3
  24. package/dist/cli/aid-bind-command.js +3 -0
  25. package/dist/cli/aun-commands.js +12 -5
  26. package/dist/cli/code-stats.js +451 -213
  27. package/dist/cli/ctl-command.js +1 -3
  28. package/dist/cli/daemon-commands.js +42 -21
  29. package/dist/cli/directory.js +7 -8
  30. package/dist/cli/ecmsg-gateway.js +204 -0
  31. package/dist/cli/getmeta-command.js +2 -1
  32. package/dist/cli/index.js +6 -0
  33. package/dist/cli/init.js +58 -18
  34. package/dist/cli/provider-command.js +82 -5
  35. package/dist/cli/restart-monitor.js +11 -19
  36. package/dist/cli/stats.js +8 -1
  37. package/dist/cli/task-context.js +3 -0
  38. package/dist/cli/trigger-command.js +20 -14
  39. package/dist/config/boot-log.js +23 -2
  40. package/dist/config/config-field-policy.js +2 -0
  41. package/dist/config/config-manager.js +13 -17
  42. package/dist/config/daemon-services.js +1 -0
  43. package/dist/config/peer-role-resolver.js +6 -6
  44. package/dist/config/provider-identity-migration.js +202 -0
  45. package/dist/config/provider-identity.js +37 -0
  46. package/dist/config/provider-ipc-service.js +40 -3
  47. package/dist/config/provider-local-sync.js +153 -0
  48. package/dist/config/providers-config.js +32 -4
  49. package/dist/config/providers-management.js +144 -68
  50. package/dist/config/providers.js +4 -1
  51. package/dist/config/role-schema.js +3 -3
  52. package/dist/config/schema-migration.js +188 -3
  53. package/dist/core/agent-application-service.js +11 -0
  54. package/dist/core/agent-ipc-registration.js +2 -0
  55. package/dist/core/agent-runtime.js +45 -11
  56. package/dist/core/auth/auth-gateway.js +8 -6
  57. package/dist/core/auth/delegation-diagnostics.js +6 -2
  58. package/dist/core/auth/operation-authorizer.js +5 -2
  59. package/dist/core/auth/operation-catalog.js +6 -4
  60. package/dist/core/baseagent-loader.js +11 -3
  61. package/dist/core/bootstrap-service.js +8 -0
  62. package/dist/core/channel-loader.js +61 -23
  63. package/dist/core/command/agent-control.js +4 -1
  64. package/dist/core/command/chatmode-config.js +46 -0
  65. package/dist/core/command/cli-intent-parser.js +2 -1
  66. package/dist/core/command/command-handler.js +16 -20
  67. package/dist/core/command/daemon-diagnostics.js +2 -1
  68. package/dist/core/command/menu-catalog.js +1 -1
  69. package/dist/core/command/menu-handler.js +16 -16
  70. package/dist/core/command/menu-protocol.js +4 -2
  71. package/dist/core/command/provider-menu.js +4 -2
  72. package/dist/core/command/role-menu.js +2 -2
  73. package/dist/core/command/slash-handler.js +56 -42
  74. package/dist/core/daemon-lifecycle.js +35 -17
  75. package/dist/core/event-catalog.js +19 -0
  76. package/dist/core/evolagent-registry.js +3 -0
  77. package/dist/core/handoff/runtime.js +9 -3
  78. package/dist/core/initialization/service.js +4 -3
  79. package/dist/core/ipc-registration.js +6 -0
  80. package/dist/core/message/aun-ipc-sender.js +81 -3
  81. package/dist/core/message/im-renderer.js +24 -19
  82. package/dist/core/message/message-admission.js +13 -2
  83. package/dist/core/message/response-engine.js +40 -41
  84. package/dist/core/message/send-options.js +40 -0
  85. package/dist/core/message/send-routing.js +310 -0
  86. package/dist/core/model/model-capabilities.js +37 -0
  87. package/dist/core/model/model-catalog.js +6 -2
  88. package/dist/core/ownership/owner-resolver.js +117 -14
  89. package/dist/core/permission/ec-command-parser.js +195 -27
  90. package/dist/core/permission/readonly-shell-query.js +66 -7
  91. package/dist/core/permission/tool-error-code.js +13 -1
  92. package/dist/core/permission/tool-policy.js +74 -20
  93. package/dist/core/plugin-lifecycle.js +6 -2
  94. package/dist/core/relation/pa-team.js +7 -2
  95. package/dist/core/relation/same-owner-proof.js +131 -0
  96. package/dist/core/session/session-idle-monitor.js +94 -16
  97. package/dist/core/session/session-manager.js +69 -16
  98. package/dist/core/thread/thread-route.js +5 -2
  99. package/dist/directory/owner-directory-cache.js +690 -99
  100. package/dist/directory/owner-directory-markdown.js +146 -36
  101. package/dist/directory/owner-directory-query-operation.js +7 -9
  102. package/dist/directory/owner-directory-scope.js +12 -0
  103. package/dist/directory/owner-directory-search.js +5 -1
  104. package/dist/directory/owner-directory-store.js +28 -0
  105. package/dist/ecweb/basic-settings-service.js +15 -1
  106. package/dist/ecweb/message-context-service.js +2 -2
  107. package/dist/ecweb/providers-service.js +3 -1
  108. package/dist/ecweb/runtime/lifecycle.js +38 -5
  109. package/dist/ecweb/runtime/supervisor.js +157 -49
  110. package/dist/index.js +202 -38
  111. package/dist/paths.js +2 -1
  112. package/dist/proxy/manager.js +2 -0
  113. package/dist/proxy/service-supervisor.js +379 -143
  114. package/dist/response-system/engines/v1/proactive-flow.js +4 -0
  115. package/dist/trigger/application-service.js +1 -0
  116. package/dist/trigger/audit.js +3 -2
  117. package/dist/trigger/authorization.js +2 -3
  118. package/dist/trigger/event-source.js +4 -0
  119. package/dist/trigger/feedback.js +26 -2
  120. package/dist/trigger/history.js +4 -3
  121. package/dist/trigger/ipc-service.js +24 -19
  122. package/dist/trigger/manager.js +3 -5
  123. package/dist/trigger/parser.js +4 -21
  124. package/dist/trigger/patch.js +3 -15
  125. package/dist/trigger/scheduler.js +48 -13
  126. package/dist/trigger/system-definitions.js +2 -2
  127. package/dist/trigger/validation.js +4 -13
  128. package/dist/utils/autostart.js +2 -2
  129. package/dist/utils/cross-platform.js +36 -8
  130. package/dist/utils/error-utils.js +8 -0
  131. package/dist/utils/macos-autostart.js +31 -0
  132. package/dist/utils/model-prices.jsonl +15 -8
  133. package/dist/utils/process-introspect.js +21 -1
  134. package/dist/utils/public-suffix.js +5811 -0
  135. package/dist/utils/startup-trace.js +7 -1
  136. package/dist/utils/windows-autostart.js +42 -7
  137. package/ecagent/dist/harness/compaction/branch-summarization.js +1 -1
  138. package/ecagent/dist/harness/compaction/compaction.js +4 -4
  139. package/ecagent/dist/harness/env/nodejs.js +46 -2
  140. package/kits/docs/aun/ABILITY_CALLING.md +3 -3
  141. package/kits/docs/channels/aun.md +1 -1
  142. package/kits/docs/channels/feishu.md +2 -2
  143. package/kits/docs/context-assembly.md +20 -4
  144. package/kits/docs/evolcore/INDEX.md +3 -2
  145. package/kits/docs/evolcore/agent.md +2 -2
  146. package/kits/docs/evolcore/aid.md +8 -2
  147. package/kits/docs/evolcore/ctl.md +13 -4
  148. package/kits/docs/evolcore/directory.md +48 -15
  149. package/kits/docs/evolcore/file-navigation.md +63 -49
  150. package/kits/docs/evolcore/group.md +6 -6
  151. package/kits/docs/evolcore/memory-consolidation.md +1 -1
  152. package/kits/docs/evolcore/menu-protocol.md +33 -3
  153. package/kits/docs/evolcore/model.md +5 -3
  154. package/kits/docs/evolcore/msg.md +28 -27
  155. package/kits/docs/evolcore/provider.md +39 -5
  156. package/kits/docs/evolcore/response.md +3 -1
  157. package/kits/docs/evolcore/thread-chain.md +12 -14
  158. package/kits/docs/evolcore/tool-authorization.md +21 -1
  159. package/kits/docs/evolcore/trigger.md +12 -9
  160. package/kits/docs/identity/ROLE_DETAIL.md +1 -1
  161. package/kits/docs/prompt-loading-architecture.md +30 -20
  162. package/kits/eck_manifest.auxiliary.json +5 -5
  163. package/kits/eck_manifest.json +28 -49
  164. package/kits/eck_manifest.memory.json +18 -18
  165. package/kits/rules/01-overview.md +43 -45
  166. package/kits/rules/02-navigation.md +44 -53
  167. package/kits/rules/03-identity.md +21 -25
  168. package/kits/rules/04-relation.md +23 -33
  169. package/kits/rules/05-venue.md +24 -25
  170. package/kits/rules/06-channel.md +3 -3
  171. package/kits/schemas/_meta.json +20 -27
  172. package/kits/schemas/agent-config.schema.19.json +10 -6
  173. package/kits/schemas/providers.schema.2.json +74 -0
  174. package/kits/schemas/relation-config.schema.12.json +2 -2
  175. package/kits/schemas/role-config.schema.2.json +5 -5
  176. package/kits/schemas/role-registry.schema.1.json +1 -1
  177. package/kits/skills/ec-agent-create/SKILL.md +1 -0
  178. package/kits/skills/ec-service-proxy/SKILL.md +3 -0
  179. package/kits/skills/ec-trigger/SKILL.md +4 -4
  180. package/kits/skills/ec-trigger/references/examples.md +1 -1
  181. package/kits/templates/system-fragments/channel.md +5 -5
  182. package/kits/templates/system-fragments/commands.md +3 -2
  183. package/kits/templates/system-fragments/directory-contacts.md +10 -3
  184. package/kits/templates/system-fragments/identity.md +0 -1
  185. package/kits/templates/system-fragments/personal-assistant.md +22 -3
  186. package/kits/templates/system-fragments/reply.md +47 -28
  187. package/kits/templates/system-fragments/session.md +2 -9
  188. package/kits/templates/system-fragments/thread.md +5 -5
  189. package/package.json +17 -13
  190. package/kits/schemas/agent-config.schema.20.json +0 -925
  191. package/kits/schemas/relation-config.schema.13.json +0 -289
  192. package/kits/schemas/role-config.schema.3.json +0 -1038
@@ -166,13 +166,14 @@ export function resumePendingSessions({ sessionManager, messageQueue, droppedTri
166
166
  });
167
167
  }
168
168
  }
169
- export function createDaemonShutdown({ disposePluginResources, lifecycleNotices, ipcServer, readySignalPath, bindService, ecwebSupervisor, messageQueue, permissionGateway, removePermissionConfigListener, stopStatsPersistence, triggerSchedulers, agentMap, eventBus, removeGroupInviteConfigListener, groupInviteReviewService, channelLoader, channelInstances, controlChannel, sessionManager, removeAll, exit, }) {
169
+ export function createDaemonShutdown({ disposePluginResources, lifecycleNotices, ipcServer, readySignalPath, bindService, ecwebSupervisor, messageQueue, permissionGateway, removePermissionConfigListener, stopStatsPersistence, triggerSchedulers, agentMap, eventBus, removeGroupInviteConfigListener, groupInviteReviewService, channelLoader, channelInstances, startupRunners, cancelStartup, controlChannel, sessionManager, removeAll, exit, }) {
170
170
  let shutdownSignal = 'unknown';
171
171
  let shutdownInProgress = false;
172
172
  return async (signal, traceId) => {
173
173
  if (shutdownInProgress)
174
174
  return;
175
175
  shutdownInProgress = true;
176
+ cancelStartup?.();
176
177
  if (signal)
177
178
  shutdownSignal = signal;
178
179
  // 先停掉还没发完的上线通知,避免和下面的下线通知交叉。
@@ -193,33 +194,45 @@ export function createDaemonShutdown({ disposePluginResources, lifecycleNotices,
193
194
  kind: 'stop',
194
195
  traceId: traceId || undefined,
195
196
  processStartMs: Date.now(),
196
- firstPhase: 'daemon.shutdown',
197
197
  });
198
198
  trace.setMeta('signal', shutdownSignal);
199
199
  trace.setMeta('via', traceId ? 'ipc' : 'signal');
200
+ trace.addSpan('daemon.shutdown', trace.startedAtMs, Date.now());
201
+ const ipcStopStartedAt = Date.now();
200
202
  ipcServer.stopCpuTracking();
201
- trace.mark('daemon.stopIpcServer');
202
203
  ipcServer.stop();
203
204
  try {
204
205
  fs.unlinkSync(readySignalPath);
205
206
  }
206
207
  catch { }
207
208
  bindService?.stopCleanup();
208
- // 每个阶段单独闭合一次,甘特图上才能看到"卡在哪一段"而不是一整块。
209
+ trace.addSpan('daemon.stopIpcServer', ipcStopStartedAt, Date.now());
210
+ // 每个任务独立记录区间,允许阶段重叠,不能共用线性 mark/note 游标。
211
+ let shutdownSucceeded = true;
209
212
  const shutdownStep = async (name, label, operation) => {
210
- trace.mark(name);
213
+ const startedAt = Date.now();
214
+ let detail;
211
215
  try {
212
- await operation();
216
+ detail = (await operation()) || undefined;
213
217
  }
214
218
  catch (error) {
215
- trace.note(`失败: ${error instanceof Error ? error.message : String(error)}`);
219
+ shutdownSucceeded = false;
220
+ detail = `失败: ${error instanceof Error ? error.message : String(error)}`;
216
221
  logger.error(`[Shutdown] ${label} failed: ${error instanceof Error ? error.message : String(error)}`);
217
222
  }
223
+ finally {
224
+ trace.addSpan(name, startedAt, Date.now(), detail);
225
+ }
218
226
  };
219
- try {
220
- await shutdownStep('daemon.stopEcweb', 'stop ECWeb supervisor', async () => {
221
- await ecwebSupervisor?.stop();
227
+ // 先启动 ECWeb 关闭,与其余停机工作重叠;finally 必须汇合,不能遗留受管子进程。
228
+ const ecwebShutdown = shutdownStep('daemon.stopEcweb', 'stop ECWeb supervisor', async () => {
229
+ await ecwebSupervisor?.stop(timing => {
230
+ trace.addSpan(`daemon.stopEcweb.${timing.phase}`, timing.startMs, timing.endMs, timing.detail);
231
+ logger.info(`[Shutdown] ECWeb ${timing.phase}: ${timing.endMs - timing.startMs}ms`
232
+ + (timing.detail ? `; ${timing.detail}` : ''));
222
233
  });
234
+ });
235
+ try {
223
236
  const queueShutdown = messageQueue.shutdownGracefully();
224
237
  await shutdownStep('daemon.stopPermissions', 'cancel pending permissions', () => permissionGateway.cancelAllPending('daemon_restart'));
225
238
  // 这两步各带超时(5s / 6.5s),退出慢的头号嫌疑就是它们空等到超时。
@@ -231,6 +244,8 @@ export function createDaemonShutdown({ disposePluginResources, lifecycleNotices,
231
244
  });
232
245
  await shutdownStep('daemon.queueDrain', 'interrupt active message queue tasks', async () => { await queueShutdown; });
233
246
  await shutdownStep('daemon.agentRunners', 'dispose agent runners', async () => {
247
+ if (startupRunners)
248
+ await Promise.allSettled([startupRunners]);
234
249
  const currentInstances = [...agentMap.entries()].map(([key, agent]) => {
235
250
  const split = key.lastIndexOf('::');
236
251
  return {
@@ -250,18 +265,22 @@ export function createDaemonShutdown({ disposePluginResources, lifecycleNotices,
250
265
  const { stopGlobalSkillWatcher } = await import('./skill/global-watcher.js');
251
266
  await stopGlobalSkillWatcher();
252
267
  });
253
- await shutdownStep('daemon.channels', 'disconnect channels', async () => {
268
+ const channelsShutdown = shutdownStep('daemon.channels', 'disconnect channels', async () => {
254
269
  const timings = await channelLoader.disconnectAll(channelInstances);
255
270
  // 慢的渠道和超时的渠道写进阶段附注,甘特图上悬停就能看到,不用再翻日志。
256
271
  const slowest = timings[0];
257
272
  const timedOut = timings.filter(t => t.timedOut);
258
273
  if (timedOut.length > 0) {
259
- trace.note(`${timings.length} 个渠道;${timedOut.length} 个超时放弃(最慢 ${slowest?.name} ${slowest?.durationMs}ms)`);
274
+ return `${timings.length} 个渠道;${timedOut.length} 个超时放弃(最慢 ${slowest?.name} ${slowest?.durationMs}ms)`;
260
275
  }
261
276
  else if (slowest && slowest.durationMs >= 1_000) {
262
- trace.note(`${timings.length} 个渠道;最慢 ${slowest.name} ${slowest.durationMs}ms`);
277
+ return `${timings.length} 个渠道;最慢 ${slowest.name} ${slowest.durationMs}ms`;
263
278
  }
264
279
  });
280
+ const controlShutdown = controlChannel
281
+ ? shutdownStep('daemon.controlAid', 'disconnect control AID', () => controlChannel.disconnect())
282
+ : Promise.resolve();
283
+ await Promise.all([channelsShutdown, controlShutdown]);
265
284
  for (const instance of channelInstances) {
266
285
  const type = instance.channelType || instance.adapter.channelName;
267
286
  eventBus.publish({
@@ -271,14 +290,13 @@ export function createDaemonShutdown({ disposePluginResources, lifecycleNotices,
271
290
  reason: 'shutdown',
272
291
  });
273
292
  }
274
- if (controlChannel) {
275
- await shutdownStep('daemon.controlAid', 'disconnect control AID', () => controlChannel?.disconnect());
276
- }
277
293
  }
278
294
  catch (error) {
295
+ shutdownSucceeded = false;
279
296
  logger.error(`[Shutdown] Unexpected shutdown failure: ${error instanceof Error ? error.stack || error.message : String(error)}`);
280
297
  }
281
298
  finally {
299
+ await ecwebShutdown;
282
300
  await shutdownStep('daemon.pluginResources', 'dispose plugin resources', async () => { await disposePluginResources?.(); });
283
301
  await shutdownStep('daemon.finalizers', 'remove permission config listener', () => removePermissionConfigListener?.());
284
302
  await shutdownStep('daemon.statsPersistence', 'stop stats persistence', () => stopStatsPersistence?.());
@@ -287,7 +305,7 @@ export function createDaemonShutdown({ disposePluginResources, lifecycleNotices,
287
305
  logger.info('✓ Shutdown complete');
288
306
  // 必须在 exit 之前落盘:appendFileSync 是同步写,记录不会随进程消失。
289
307
  trace.mark('daemon.exit');
290
- trace.finish(true);
308
+ trace.finish(shutdownSucceeded);
291
309
  exit(0);
292
310
  }
293
311
  };
@@ -781,6 +781,25 @@ const CATALOG = [
781
781
  { path: 'phase', type: 'string' },
782
782
  ],
783
783
  },
784
+ {
785
+ type: 'trigger:interrupted',
786
+ namespace: 'trigger',
787
+ name: 'interrupted',
788
+ description: 'trigger run 被操作员中止',
789
+ internal: true,
790
+ fields: [
791
+ { path: 'triggerId', type: 'string' },
792
+ { path: 'name', type: 'string' },
793
+ { path: 'runId', type: 'string' },
794
+ { path: 'originTriggerId', type: 'string' },
795
+ { path: 'messageId', type: 'string' },
796
+ { path: 'reason', type: 'string' },
797
+ { path: 'error', type: 'string' },
798
+ { path: 'targetChannel', type: 'string' },
799
+ { path: 'targetChannelId', type: 'string' },
800
+ { path: 'fireTime', type: 'number' },
801
+ ],
802
+ },
784
803
  {
785
804
  type: 'trigger:skipped',
786
805
  namespace: 'trigger',
@@ -287,6 +287,7 @@ export class EvolAgentRegistry {
287
287
  const oldAgent = this.agents.get(aidOrName);
288
288
  if (!oldAgent)
289
289
  throw new Error(`Agent "${aidOrName}" not found`);
290
+ await hooks.beforeAgentOperation?.(oldAgent.aid);
290
291
  const expandedRaw = loadAgent(oldAgent.aid);
291
292
  if (!expandedRaw)
292
293
  throw new Error(`Agent ${oldAgent.aid}/config.json missing on reload`);
@@ -513,6 +514,7 @@ export class EvolAgentRegistry {
513
514
  const agent = this.agents.get(aidOrName);
514
515
  if (!agent)
515
516
  throw new Error(`Agent "${aidOrName}" not found`);
517
+ await hooks.beforeAgentOperation?.(agent.aid);
516
518
  if (agent.status === 'disabled')
517
519
  throw new Error('Agent is disabled; use enable/disable instead');
518
520
  if (agent.status === 'stopped') {
@@ -539,6 +541,7 @@ export class EvolAgentRegistry {
539
541
  const agent = this.agents.get(aidOrName);
540
542
  if (!agent)
541
543
  throw new Error(`Agent "${aidOrName}" not found`);
544
+ await hooks.beforeAgentOperation?.(agent.aid);
542
545
  if (agent.status === 'disabled')
543
546
  throw new Error('Agent is disabled; use enable instead');
544
547
  if (agent.status === 'error')
@@ -1,4 +1,4 @@
1
- import { formatChannelKey } from '../channel-loader.js';
1
+ import { formatChannelKey, tryParseChannelKey } from '../channel-loader.js';
2
2
  import { classifyAunPayloadForLog } from '../message/message-log.js';
3
3
  import { HandoffDispatcher } from './dispatcher.js';
4
4
  import { KeyedFairMutex } from './mutex.js';
@@ -75,7 +75,13 @@ export class HandoffRuntime {
75
75
  throwIfAborted(input.signal);
76
76
  if (!origin || origin.selfAID !== input.selfAid)
77
77
  throw new Error('origin session not found');
78
- const targetChannelKey = formatChannelKey({ type: 'aun', selfAID: input.selfAid, name: 'main' });
78
+ // 目标渠道:缺省 AUN 主渠(历史行为);跨会话投递给其它渠道的会话时,
79
+ // 由调用方显式传入该会话真实的 channelKey / channelType。
80
+ const targetChannelKey = input.targetChannelKey
81
+ ?? formatChannelKey({ type: 'aun', selfAID: input.selfAid, name: 'main' });
82
+ const targetChannelType = input.targetChannelType
83
+ ?? tryParseChannelKey(targetChannelKey)?.type
84
+ ?? 'aun';
79
85
  if (!input.targetChatType) {
80
86
  throw Object.assign(new Error('AUN handoff requires an explicit target chat type'), {
81
87
  code: 'AUN_OUTBOUND_ROUTE_REQUIRED',
@@ -86,7 +92,7 @@ export class HandoffRuntime {
86
92
  channelKey: targetChannelKey,
87
93
  peerId: input.to,
88
94
  ...(targetChatType === 'group' ? { groupId: input.to } : {}),
89
- }, undefined, input.to, targetChatType, origin.baseagent, input.selfAid, 'aun', targetChatType === 'group' ? 'group' : 'agent');
95
+ }, undefined, input.to, targetChatType, origin.baseagent, input.selfAid, targetChannelType, targetChatType === 'group' ? 'group' : 'agent');
90
96
  throwIfAborted(input.signal);
91
97
  if (target.id === origin.id) {
92
98
  if (input.handoffContext !== undefined)
@@ -11,6 +11,7 @@ import { isValidAid } from '../../aun/aid/validation.js';
11
11
  import { listBaseagentImportSources, providerFromBaseagent } from '../../config/providers-import.js';
12
12
  import { importOrMergeBaseagentProvider, readProvidersSnapshot } from '../../config/providers-management.js';
13
13
  import { providerServiceTypesForBaseagent } from '../../config/providers.js';
14
+ import { resolveProviderId } from '../../config/providers-config.js';
14
15
  import { readInstalledEvolcoreVersion } from '../../utils/evolcore-version.js';
15
16
  import { agentProjectRootFromDefaults, defaultProjectsRoot } from '../../utils/project-path.js';
16
17
  import { resolveControlAidDomain } from '../../aun/aid/control-aid.js';
@@ -170,9 +171,9 @@ export class EcwebInitializationService {
170
171
  config.baseagents = record(config.baseagents) ? config.baseagents : {};
171
172
  for (const id of available) {
172
173
  const previous = record(config.baseagents[id]) ? config.baseagents[id] : {};
173
- const previousProvider = typeof previous.provider === 'string' ? previous.provider : '';
174
+ const previousProvider = typeof previous.provider === 'string' ? resolveProviderId(previous.provider, providers) : '';
174
175
  const provider = id === 'ecagent' ? ecagentProvider
175
- : state.providerIds?.[id]
176
+ : (state.providerIds?.[id] ? resolveProviderId(state.providerIds[id], providers) : undefined)
176
177
  || (providerSupportsBaseagent(providers.providers[previousProvider], id) ? previousProvider : undefined)
177
178
  || firstProvider(id);
178
179
  if (provider && providerSupportsBaseagent(providers.providers[provider], id))
@@ -199,7 +200,7 @@ export class EcwebInitializationService {
199
200
  const defaultsComplete = configured.every(item => {
200
201
  const selected = defaults[item.id];
201
202
  return !!selected?.provider
202
- && providerSupportsBaseagent(providers.providers[selected.provider], item.id)
203
+ && providerSupportsBaseagent(providers.providers[resolveProviderId(selected.provider, providers)], item.id)
203
204
  && (item.id !== 'ecagent' || !!selected.model?.trim());
204
205
  });
205
206
  const active = inventory.baseagents.find(item => item.id === inventory.active && item.detected);
@@ -721,6 +721,12 @@ export function registerOperationIpcProviders({ ipcServer, sessionManager, messa
721
721
  const authorization = await authorizeManagedAgentOperation(params, 'system.status');
722
722
  if (!authorization.ok)
723
723
  return authorization;
724
+ if (query.raw) {
725
+ if (!authorization.fullAccess) {
726
+ return { ok: false, code: 'NOT_ALLOWED', error: '--raw requires a trusted fullaccess task' };
727
+ }
728
+ return { ok: true, data: { rawAuthorized: true } };
729
+ }
724
730
  return { ok: true, data: queryDiagnosticLogs(query, authorization.aid) };
725
731
  }
726
732
  catch (error) {
@@ -16,6 +16,8 @@ import { sameGroupAid } from '../../aun/group/identity.js';
16
16
  import { resolveThreadRouteTarget } from '../thread/thread-route.js';
17
17
  import { isTopicThreadId, parseMainTopicId, safeFormatMainTopicId, sessionLocalTopicId } from '../thread/topic-id.js';
18
18
  import { ThreadService } from '../thread/thread-service.js';
19
+ import { buildEnvelope } from './message-utils.js';
20
+ import { sessionTopicThreadId } from '../thread/topic-id.js';
19
21
  import { getAunRequestRegistry, requestDiagnostics, requestTtlSeconds } from './aun-request-registry.js';
20
22
  import { parseJsonObjectArgument } from '../permission/ec-command-parser.js';
21
23
  import { parsePeerKey } from '../relation/peer-identity.js';
@@ -36,9 +38,18 @@ export function createAunHandoffSender(sessionManager, channelInstances, getOutb
36
38
  const targetSession = await sessionManager.getSessionById(handoff.target_session_id);
37
39
  if (!targetSession)
38
40
  return { ok: false, error: 'target session not found' };
39
- const instance = channelInstances.find(candidate => (candidate.channelType === 'aun' && (candidate.adapter.channelKey === targetSession.metadata?.channelKey
41
+ // 目标会话可能属于任意渠道。先按该会话自己的 channelKey/渠道实例匹配,
42
+ // 只有拿到 AUN 渠道实例时才走 AUN 专用发送路径;其它渠道走通用 adapter。
43
+ const instance = channelInstances.find(candidate => (candidate.adapter.channelKey === targetSession.metadata?.channelKey
40
44
  || candidate.adapter.channelName === targetSession.channel
41
- || tryParseChannelKey(candidate.adapter.channelKey)?.selfAID === targetSession.selfAID)));
45
+ || (candidate.channelType === 'aun'
46
+ && tryParseChannelKey(candidate.adapter.channelKey)?.selfAID === targetSession.selfAID)));
47
+ if (!instance) {
48
+ return { ok: false, error: `channel not found for session ${targetSession.id}` };
49
+ }
50
+ if (instance.channelType !== 'aun') {
51
+ return sendViaSessionAdapter(handoff, targetSession, instance, getOutboundDebug);
52
+ }
42
53
  const channel = instance?.channel;
43
54
  if (!channel) {
44
55
  return { ok: false, error: `AUN channel not found for ${targetSession.selfAID || '<unknown>'}` };
@@ -87,6 +98,57 @@ export function createAunHandoffSender(sessionManager, channelInstances, getOutb
87
98
  return { ok: result.ok, message_id: result.message_id, error: result.error };
88
99
  };
89
100
  }
101
+ /**
102
+ * 跨会话投递到**非 AUN 渠道**的目标会话。
103
+ *
104
+ * 与 AUN 路径的区别只在投递方式:非 AUN 渠道没有 `sendDaemonMsg`,统一走
105
+ * adapter 的通用 `send(envelope, payload)`。目标会话已由 `createOutbound`
106
+ * 建好(`channelKey` / `channelId` / `threadId` 都来自该会话),这里只负责
107
+ * 把正文投出去。
108
+ *
109
+ * 边界:只支持文本正文。文件/链接/payload 的跨渠道投递尚未验证,明确报错
110
+ * 而不是静默丢弃。
111
+ */
112
+ async function sendViaSessionAdapter(handoff, targetSession, instance, getOutboundDebug) {
113
+ const payload = handoff.request.payload;
114
+ const text = typeof payload?.text === 'string' ? payload.text : '';
115
+ if (!text.trim()) {
116
+ return { ok: false, error: 'cross-channel handoff currently supports text payloads only' };
117
+ }
118
+ const threadId = sessionTopicThreadId(targetSession);
119
+ // 投递目标以**目标会话自身**为准,不依赖 request.delivery(那是 AUN 路由字段)。
120
+ const delivery = targetSession.chatType === 'group'
121
+ ? { chatType: 'group', groupId: targetSession.metadata?.groupId ?? targetSession.channelId }
122
+ : { chatType: 'private' };
123
+ const envelope = buildEnvelope({
124
+ taskId: `handoff:${handoff.handoff_id}`,
125
+ channel: instance.adapter.channelKey,
126
+ channelId: targetSession.channelId,
127
+ agentName: targetSession.selfAID,
128
+ causation: handoff.causation,
129
+ replyContext: {
130
+ delivery,
131
+ ...(threadId ? { threadId } : {}),
132
+ ...(typeof handoff.request.encrypt === 'boolean'
133
+ ? { metadata: { encrypted: handoff.request.encrypt } }
134
+ : {}),
135
+ },
136
+ });
137
+ try {
138
+ const receipt = await instance.adapter.send(envelope, { kind: 'result.text', text, isFinal: true });
139
+ if (receipt && typeof receipt === 'object' && 'status' in receipt) {
140
+ const status = receipt.status;
141
+ if (status === 'failed') {
142
+ return { ok: false, error: String(receipt.error ?? 'send failed') };
143
+ }
144
+ return { ok: true, message_id: receipt.messageId };
145
+ }
146
+ return { ok: true };
147
+ }
148
+ catch (error) {
149
+ return { ok: false, error: error instanceof Error ? error.message : String(error) };
150
+ }
151
+ }
90
152
  async function applyManagedCrossThreadSendEffects(input) {
91
153
  const originSessionId = input.grant.sessionId;
92
154
  const originPeer = parsePeerKey(input.grant.peerKey).channelId;
@@ -134,7 +196,11 @@ async function applyManagedCrossThreadSendEffects(input) {
134
196
  prompt,
135
197
  everyMs: input.durationMs,
136
198
  checkEvery: input.checkEveryLabel,
137
- channelKey: formatChannelKey({ type: 'aun', selfAID: input.selfAid, name: 'main' }),
199
+ // 目标话题所属渠道:从话题索引取,取不到时按 AUN 主渠兜底(历史行为)。
200
+ // 硬写 AUN 会让飞书等渠道的目标话题把 Trigger 的 feedback.target 指向错渠道。
201
+ channelKey: targetEntry?.channelType
202
+ ? formatChannelKey({ type: targetEntry.channelType, selfAID: input.selfAid, name: 'main' })
203
+ : formatChannelKey({ type: 'aun', selfAID: input.selfAid, name: 'main' }),
138
204
  targetChannelId: input.targetChannelId,
139
205
  targetThreadId: input.targetThreadId,
140
206
  originThreadId,
@@ -545,6 +611,18 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
545
611
  encrypt,
546
612
  thread: params.thread,
547
613
  targetChatType: params.scope === 'group' ? 'group' : 'private',
614
+ // 目标会话可能属于别的渠道(如飞书话题):带上它自己的 channelKey,
615
+ // 否则会按 AUN 主渠建会话,投递到错误的渠道。
616
+ ...(threadRoute?.channelType
617
+ ? {
618
+ targetChannelType: threadRoute.channelType,
619
+ targetChannelKey: formatChannelKey({
620
+ type: threadRoute.channelType,
621
+ selfAID: params.aid,
622
+ name: 'main',
623
+ }),
624
+ }
625
+ : {}),
548
626
  explicitReturnPolicy: params.returnPolicy,
549
627
  handoffContext: params.handoffContext,
550
628
  // 跨话题发送的目标侧上下文由话题链(thread-inbox)负责注入;
@@ -118,10 +118,12 @@ export class IMRenderer {
118
118
  if (isFinal) {
119
119
  const pending = this.deferredProactiveText;
120
120
  this.deferredProactiveText = [];
121
- if (!isNoopText(pending.map(item => item.text).join(''), this.opts.noopSentinel || undefined)) {
121
+ if (!this.opts.noopSentinel || !isNoopText(pending.map(item => item.text).join(''), this.opts.noopSentinel)) {
122
122
  for (const item of pending) {
123
123
  this.recordActivity(item);
124
- await this.sendPayload({ kind: 'activity.batch', items: [item] });
124
+ if (!this.suppressProactiveItem(item)) {
125
+ await this.sendPayload({ kind: 'activity.batch', items: [item] });
126
+ }
125
127
  }
126
128
  }
127
129
  }
@@ -189,7 +191,7 @@ export class IMRenderer {
189
191
  this.itemsQueue = this.itemsQueue.filter(it => it.kind !== 'text');
190
192
  return;
191
193
  }
192
- if (mayBeNoopText(rawText, this.opts.noopSentinel || undefined))
194
+ if (this.opts.noopSentinel && mayBeNoopText(rawText, this.opts.noopSentinel))
193
195
  return;
194
196
  if (this.timer) {
195
197
  clearTimeout(this.timer);
@@ -617,21 +619,16 @@ export class IMRenderer {
617
619
  this.messageTimestamps.push(Date.now());
618
620
  this.scheduleFlush();
619
621
  }
620
- /** interactive 下,以普通非最终文本发送用户需要看到的运行状态。 */
621
- async sendOperationalNoticeAsText(text) {
622
- if (!this.opts.operationalNoticesAsText || this.opts.envelope.chatmode === 'proactive' || !text)
622
+ /** 通过系统通知发送运行状态,并保持与已有正文的发送顺序。 */
623
+ async sendOperationalNotice(text, subtype) {
624
+ if (!this.opts.operationalNoticesEnabled || this.opts.envelope.chatmode === 'proactive' || !text)
623
625
  return false;
624
626
  if (!this.hasSendableText(text, 'operational-notice'))
625
627
  return false;
626
628
  // 保持与流式正文的到达顺序:先发出已缓冲的正文,再投影运行状态。
627
629
  await this.flushText();
628
- const payload = {
629
- kind: 'result.text',
630
- text,
631
- isFinal: false,
632
- };
633
630
  this.sentContent = true;
634
- await this.sendAutomaticText(payload);
631
+ await this.sendSystemNotice(text, subtype);
635
632
  this.lastFlush = Date.now();
636
633
  this.flushCount++;
637
634
  return true;
@@ -715,11 +712,11 @@ export class IMRenderer {
715
712
  this.sendChain = handled.catch(() => { });
716
713
  return handled;
717
714
  }
718
- /** Model output and renderer text notices share PA's automatic-text outlet.
719
- * Explicit sends, command receipts and interaction fallbacks bypass it.
715
+ /** Model output uses PA's automatic-text outlet.
716
+ * System notices, explicit sends, command receipts and interaction fallbacks bypass it.
720
717
  */
721
718
  async sendAutomaticText(payload) {
722
- if (isNoopText(payload.text, this.opts.noopSentinel || undefined))
719
+ if (this.opts.noopSentinel && isNoopText(payload.text, this.opts.noopSentinel))
723
720
  return;
724
721
  if (this.opts.envelope.chatmode !== 'paactive')
725
722
  return this.sendPayload(payload);
@@ -864,7 +861,7 @@ export class IMRenderer {
864
861
  item.text = item.text.replace(this.opts.fileMarkerPattern, '');
865
862
  }
866
863
  }
867
- if (isFinal && isNoopText(this.textBuffer, this.opts.noopSentinel || undefined)) {
864
+ if (isFinal && this.opts.noopSentinel && isNoopText(this.textBuffer, this.opts.noopSentinel)) {
868
865
  this.discardPendingText();
869
866
  }
870
867
  else if (!this.hasSendableText(this.textBuffer, isFinal ? 'final' : 'flush')) {
@@ -912,7 +909,7 @@ export class IMRenderer {
912
909
  if (!isFinal && this.textBuffer.length > 0) {
913
910
  if (this.suppressIntermediateText())
914
911
  return;
915
- if (mayBeNoopText(this.textBuffer, this.opts.noopSentinel || undefined))
912
+ if (this.opts.noopSentinel && mayBeNoopText(this.textBuffer, this.opts.noopSentinel))
916
913
  return;
917
914
  // A timer cannot decide whether this is the final answer. Keep it for
918
915
  // an explicit boundary; known commentary can still be sent immediately.
@@ -1054,13 +1051,14 @@ export class IMRenderer {
1054
1051
  /** proactive:单个 ThoughtItem 包成 activity.batch[1] 发出。 */
1055
1052
  emitProactiveItem(item) {
1056
1053
  if (item.kind === 'text' || (item.kind === 'summary' && !item.is_error)) {
1057
- if (this.opts.noopSentinel || this.deferredProactiveText.length > 0
1058
- || mayBeNoopText(item.text)) {
1054
+ if (this.opts.noopSentinel || this.deferredProactiveText.length > 0) {
1059
1055
  this.deferredProactiveText.push(item);
1060
1056
  return;
1061
1057
  }
1062
1058
  }
1063
1059
  this.recordActivity(item);
1060
+ if (this.suppressProactiveItem(item))
1061
+ return;
1064
1062
  const evolCommand = item.kind === 'tool_call' ? item.evolCommand : undefined;
1065
1063
  const payload = evolCommand
1066
1064
  ? { kind: 'activity.batch', items: [item], ext: { evolCommand } }
@@ -1069,6 +1067,13 @@ export class IMRenderer {
1069
1067
  logger.debug(`[IMRenderer] proactive send failed: ${err.message}`);
1070
1068
  });
1071
1069
  }
1070
+ suppressProactiveItem(item) {
1071
+ if (item.kind === 'text' || item.kind === 'summary') {
1072
+ // noopSentinel only defers text until its full prefix can be checked.
1073
+ return this.opts.suppressIntermediateText ?? this.opts.suppressActivities ?? false;
1074
+ }
1075
+ return this.suppressActivityItems();
1076
+ }
1072
1077
  mapEventToItem(event) {
1073
1078
  switch (event.type) {
1074
1079
  case 'text':
@@ -4,6 +4,7 @@ import { isValidAid } from '../../aun/aid/validation.js';
4
4
  import { readOwnerDirectoryMembership } from '../../directory/owner-directory-admission.js';
5
5
  import { resolveAunPeerKind } from '../relation/peer-identity.js';
6
6
  import { evaluateAppContactAdmission } from './contact-admission.js';
7
+ import { ownerResolver, OWNERSHIP_CACHE_MAX_AGE_MS } from '../ownership/owner-resolver.js';
7
8
  /**
8
9
  * AUN 出站私聊固定使用 app-v1,与入站保持相同的绑定和联系人判定。
9
10
  * 群聊的准入单位是群,出站到群不做发言人判定。
@@ -21,13 +22,23 @@ export async function evaluateOutboundContactAdmission(input) {
21
22
  return { allow: true, status: 'group' };
22
23
  let decision;
23
24
  try {
25
+ await ownerResolver.refresh(selfAid, { maxAgeMs: OWNERSHIP_CACHE_MAX_AGE_MS, allowTransient: true });
24
26
  decision = evaluateAppContactAdmission(selfAid, targetAid);
25
27
  }
26
28
  catch (error) {
27
29
  return { allow: false, code: 'CONTACT_POLICY_INVALID', status: 'absent', error: error instanceof Error ? error.message : String(error) };
28
30
  }
29
- if (decision.allow)
30
- return { allow: true, status: decision.reason === 'owner' ? 'owner' : decision.reason === 'temporary' ? 'temporary' : 'contact' };
31
+ if (decision.allow) {
32
+ if (decision.reason === 'owner')
33
+ return { allow: true, status: 'owner' };
34
+ if (decision.reason === 'temporary')
35
+ return { allow: true, status: 'temporary' };
36
+ if (decision.reason === 'open') {
37
+ const policy = readAccessPolicy(selfAid);
38
+ return { allow: true, status: policy.allowedAids?.includes(targetAid) ? 'allowed_aid' : 'all_contacts' };
39
+ }
40
+ return { allow: true, status: 'contact' };
41
+ }
31
42
  return { allow: false, code: decision.reason === 'unavailable' ? 'CONTACT_DIRECTORY_UNAVAILABLE'
32
43
  : decision.reason === 'blocked' ? 'CONTACT_BLOCKED' : 'CONTACT_DENIED',
33
44
  status: decision.reason === 'unavailable' ? 'unavailable' : decision.reason === 'blocked' ? 'blocked' : 'denied',