evolcore 0.0.43-test.6 → 0.0.43-test.8

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 (249) hide show
  1. package/CHANGELOG.md +95 -0
  2. package/bin/ecmsg.js +188 -58
  3. package/dist/agent-template/jobs.js +62 -0
  4. package/dist/agent-template/runtime.js +214 -0
  5. package/dist/agent-template/service.js +465 -0
  6. package/dist/agent-template/tool-runner.js +45 -0
  7. package/dist/agent-template/types.js +5 -0
  8. package/dist/agents/baseagent-availability.js +1 -1
  9. package/dist/agents/claude-runner.js +1 -1
  10. package/dist/agents/codex/app-server-client.js +22 -0
  11. package/dist/agents/codex-runner.js +69 -2
  12. package/dist/aun/aid/agentmd.js +56 -1
  13. package/dist/aun/aid/client.js +3 -1
  14. package/dist/aun/menu/client.js +3 -2
  15. package/dist/aun/msg/p2p.js +6 -1
  16. package/dist/channels/aun.js +277 -49
  17. package/dist/cli/agent-command.js +5 -0
  18. package/dist/cli/agent-create.js +7 -3
  19. package/dist/cli/agent-template.js +124 -0
  20. package/dist/cli/aun-commands.js +2 -2
  21. package/dist/cli/ctl-command.js +2 -1
  22. package/dist/cli/daemon-commands.js +11 -66
  23. package/dist/cli/daemon-lifecycle-client.js +61 -0
  24. package/dist/cli/ecmsg-gateway.js +35 -2
  25. package/dist/cli/events-command.js +109 -0
  26. package/dist/cli/index.js +60 -14
  27. package/dist/cli/invoke-command.js +182 -0
  28. package/dist/cli/managed-command-guard.js +6 -1
  29. package/dist/cli/net-check.js +1 -1
  30. package/dist/cli/restart-monitor.js +160 -83
  31. package/dist/cli/services-command.js +137 -0
  32. package/dist/cli/team-workspace-command.js +134 -0
  33. package/dist/cli/thread-command.js +103 -13
  34. package/dist/cli/watch-msg.js +1 -1
  35. package/dist/config/boot-log.js +8 -8
  36. package/dist/config/config-field-policy.js +2 -2
  37. package/dist/config/config-manager.js +0 -7
  38. package/dist/config/invoke-ipc-service.js +118 -0
  39. package/dist/config/schema-migration.js +45 -15
  40. package/dist/config-store.js +2 -1
  41. package/dist/core/agent-ipc-registration.js +25 -4
  42. package/dist/core/agent-reload-coordinator.js +6 -4
  43. package/dist/core/agent-runtime.js +106 -10
  44. package/dist/core/auth/delegation-authorization.js +66 -0
  45. package/dist/core/auth/operation-authorizer.js +2 -0
  46. package/dist/core/auth/operation-catalog.js +29 -0
  47. package/dist/core/baseagent-loader.js +60 -130
  48. package/dist/core/channel-loader.js +10 -1
  49. package/dist/core/channel-runtime.js +20 -12
  50. package/dist/core/command/agent-control.js +12 -2
  51. package/dist/core/command/agent-storage-menu.js +1 -1
  52. package/dist/core/command/agent-template-menu.js +147 -0
  53. package/dist/core/command/chatmode-config.js +2 -36
  54. package/dist/core/command/command-handler.js +80 -17
  55. package/dist/core/command/data-root-resolver.js +32 -23
  56. package/dist/core/command/eventcenter-menu.js +468 -0
  57. package/dist/core/command/menu-catalog.js +15 -0
  58. package/dist/core/command/menu-handler.js +216 -90
  59. package/dist/core/command/menu-protocol.js +71 -13
  60. package/dist/core/command/menu-query-batch.js +194 -0
  61. package/dist/core/command/slash-gate.js +1 -1
  62. package/dist/core/command/slash-handler.js +34 -42
  63. package/dist/core/command/team-workspace-bootstrap.js +350 -0
  64. package/dist/core/command/{pa-workspace-calendar.js → team-workspace-calendar.js} +7 -7
  65. package/dist/core/command/team-workspace-initializer.js +2 -0
  66. package/dist/core/command/{pa-workspace-items.js → team-workspace-items.js} +83 -68
  67. package/dist/core/command/team-workspace-job-store.js +88 -0
  68. package/dist/core/command/team-workspace-management-service.js +2 -0
  69. package/dist/core/command/team-workspace-management-store.js +96 -0
  70. package/dist/core/command/team-workspace-management.js +265 -0
  71. package/dist/core/command/team-workspace-members-menu.js +88 -0
  72. package/dist/core/command/team-workspace-store.js +612 -0
  73. package/dist/core/command/team-workspace-team.js +193 -0
  74. package/dist/core/daemon-control.js +22 -5
  75. package/dist/core/daemon-lifecycle.js +323 -191
  76. package/dist/core/handoff/runtime.js +45 -13
  77. package/dist/core/invoke/executors/index.js +13 -0
  78. package/dist/core/invoke/executors/media.js +283 -0
  79. package/dist/core/invoke/executors/text.js +198 -0
  80. package/dist/core/invoke/invoke-service.js +157 -0
  81. package/dist/core/invoke/style-router.js +48 -0
  82. package/dist/core/invoke/types.js +19 -0
  83. package/dist/core/ipc-registration.js +50 -7
  84. package/dist/core/legacy-rename.js +41 -0
  85. package/dist/core/memory/consolidation.js +7 -5
  86. package/dist/core/message/aun-ipc-sender.js +252 -17
  87. package/dist/core/message/im-renderer.js +116 -85
  88. package/dist/core/message/message-bridge.js +4 -0
  89. package/dist/core/message/message-queue.js +66 -15
  90. package/dist/core/message/message-utils.js +10 -2
  91. package/dist/core/message/peer-mode.js +7 -34
  92. package/dist/core/message/pending-hints.js +29 -5
  93. package/dist/core/message/response-engine.js +194 -61
  94. package/dist/core/message/send-options.js +7 -4
  95. package/dist/core/message/send-routing.js +50 -5
  96. package/dist/core/ownership/owner-resolver.js +7 -0
  97. package/dist/core/pack-auth.js +94 -0
  98. package/dist/core/pack-install.js +194 -0
  99. package/dist/core/permission/ec-command-parser.js +51 -17
  100. package/dist/core/permission/protected-paths.js +12 -2
  101. package/dist/core/permission/shell-environment.js +9 -0
  102. package/dist/core/rate-window.js +48 -0
  103. package/dist/core/relation/peer-identity.js +28 -0
  104. package/dist/core/session/session-file-health.js +243 -0
  105. package/dist/core/session/session-fs-store.js +67 -28
  106. package/dist/core/session/session-idle-monitor.js +59 -19
  107. package/dist/core/session/session-manager.js +13 -4
  108. package/dist/core/task/task-recovery-service.js +13 -2
  109. package/dist/core/thread/command-parser.js +9 -2
  110. package/dist/core/thread/thread-operation.js +21 -2
  111. package/dist/core/thread/thread-route.js +13 -2
  112. package/dist/core/thread/thread-service.js +52 -3
  113. package/dist/directory/owner-directory-admission.js +40 -53
  114. package/dist/directory/owner-directory-cache.js +89 -113
  115. package/dist/directory/owner-directory-query-operation.js +8 -10
  116. package/dist/eck/kit-renderer.js +7 -5
  117. package/dist/eck/message-renderer.js +2 -0
  118. package/dist/ecweb/basic-settings-service.js +1 -1
  119. package/dist/ecweb/message-context-service.js +0 -4
  120. package/dist/ecweb/runtime/lifecycle.js +6 -2
  121. package/dist/ecweb/runtime/supervisor.js +19 -4
  122. package/dist/event-center/admission-materializer.js +124 -0
  123. package/dist/event-center/bus-gate.js +154 -0
  124. package/dist/event-center/bus-host.js +307 -0
  125. package/dist/event-center/bus-resolver.js +120 -0
  126. package/dist/event-center/center-config.js +127 -0
  127. package/dist/event-center/daemon.js +44 -0
  128. package/dist/event-center/directory-source.js +55 -0
  129. package/dist/event-center/dispatcher.js +157 -0
  130. package/dist/event-center/event-log.js +110 -0
  131. package/dist/event-center/index-generator.js +73 -0
  132. package/dist/event-center/ipc-operation.js +423 -0
  133. package/dist/event-center/ledger.js +52 -0
  134. package/dist/event-center/pack-loader.js +207 -0
  135. package/dist/event-center/pack-manager.js +85 -0
  136. package/dist/event-center/registry.js +463 -0
  137. package/dist/event-center/runtime.js +837 -0
  138. package/dist/event-center/script-runner.js +356 -0
  139. package/dist/event-center/types.js +51 -0
  140. package/dist/event-center/validation.js +435 -0
  141. package/dist/index.js +424 -135
  142. package/dist/ipc.js +106 -12
  143. package/dist/paths.js +20 -0
  144. package/dist/product.js +14 -0
  145. package/dist/proxy/manager.js +5 -1
  146. package/dist/proxy/service-supervisor.js +13 -4
  147. package/dist/response-system/engines/v1/index.js +0 -1
  148. package/dist/response-system/engines/v1/proactive-flow.js +4 -2
  149. package/dist/response-system/modes/single-session/index.js +1 -1
  150. package/dist/services/dispatcher.js +100 -0
  151. package/dist/services/idempotency.js +90 -0
  152. package/dist/services/identity.js +52 -0
  153. package/dist/services/index-generator.js +70 -0
  154. package/dist/services/index.js +449 -0
  155. package/dist/services/ipc-operation.js +550 -0
  156. package/dist/services/ledger.js +52 -0
  157. package/dist/services/message-log.js +112 -0
  158. package/dist/services/pack-manager.js +215 -0
  159. package/dist/services/reply.js +55 -0
  160. package/dist/services/router.js +98 -0
  161. package/dist/services/script-runner.js +422 -0
  162. package/dist/services/service-payload.js +70 -0
  163. package/dist/services/types.js +18 -0
  164. package/dist/services/validation.js +297 -0
  165. package/dist/trigger/application-service.js +18 -0
  166. package/dist/trigger/event-source.js +1 -1
  167. package/dist/trigger/ipc-service.js +3 -1
  168. package/dist/trigger/scheduler.js +38 -0
  169. package/dist/trigger/script-sandbox.js +170 -24
  170. package/dist/utils/cross-platform.js +24 -10
  171. package/dist/utils/evolcore-version.js +69 -27
  172. package/dist/utils/instance-registry.js +19 -13
  173. package/dist/utils/npm-ops.js +2 -1
  174. package/dist/utils/package-version-info.js +6 -3
  175. package/dist/utils/process-introspect.js +45 -9
  176. package/dist/utils/startup-trace.js +74 -37
  177. package/dist/utils/windows-shell-trust.js +80 -6
  178. package/kits/docs/INDEX.md +2 -2
  179. package/kits/docs/aun/ABILITY_CALLING.md +9 -15
  180. package/kits/docs/context-assembly.md +1 -1
  181. package/kits/docs/evolcore/INDEX.md +3 -1
  182. package/kits/docs/evolcore/ability.md +4 -0
  183. package/kits/docs/evolcore/agent.md +22 -1
  184. package/kits/docs/evolcore/aid.md +1 -1
  185. package/kits/docs/evolcore/event-center.md +227 -0
  186. package/kits/docs/evolcore/file-navigation.md +10 -264
  187. package/kits/docs/evolcore/fs.md +5 -3
  188. package/kits/docs/evolcore/group.md +1 -1
  189. package/kits/docs/evolcore/memory-architecture.md +2 -0
  190. package/kits/docs/evolcore/menu-protocol.md +28 -1
  191. package/kits/docs/evolcore/msg.md +21 -9
  192. package/kits/docs/evolcore/provider.md +3 -1
  193. package/kits/docs/evolcore/response.md +5 -5
  194. package/kits/docs/evolcore/services.md +294 -0
  195. package/kits/docs/evolcore/task.md +2 -0
  196. package/kits/docs/evolcore/team-workspace.md +41 -0
  197. package/kits/docs/evolcore/thread-chain.md +15 -3
  198. package/kits/eck_manifest.json +26 -0
  199. package/kits/rules/02-navigation.md +10 -1
  200. package/kits/rules/06-channel.md +1 -0
  201. package/kits/schemas/_meta.json +17 -6
  202. package/kits/schemas/agent-config.schema.19.json +5 -7
  203. package/kits/schemas/agent-config.schema.20.json +936 -0
  204. package/kits/schemas/relation-config.schema.12.json +2 -3
  205. package/kits/schemas/role-config.schema.2.json +4 -4
  206. package/kits/skills/.switches.json +1 -5
  207. package/kits/skills/ability/SKILL.md +56 -0
  208. package/kits/skills/ability/references/calling.md +56 -0
  209. package/kits/skills/{ec-ability → ability}/references/contract-checklist.md +1 -1
  210. package/kits/skills/{ec-ability → ability}/references/development.md +9 -33
  211. package/kits/skills/{ec-ability → ability}/references/management.md +2 -2
  212. package/kits/skills/{ec-ability → ability}/references/recovery.md +1 -1
  213. package/kits/skills/{ec-ability → ability}/references/runtime-protocol.md +2 -0
  214. package/kits/skills/ec-agent-create/SKILL.md +0 -1
  215. package/kits/skills/ec-group/SKILL.md +5 -8
  216. package/kits/skills/ec-group-collaboration/SKILL.md +7 -7
  217. package/kits/skills/ec-service-proxy/SKILL.md +34 -5
  218. package/kits/skills/ec-trigger/SKILL.md +4 -4
  219. package/kits/skills/personal-assistant/SKILL.md +6 -6
  220. package/kits/skills/personal-assistant/references/02-bootstrap.md +4 -4
  221. package/kits/skills/personal-assistant/scripts/clean.mjs +4 -4
  222. package/kits/skills/personal-assistant/scripts/init.mjs +2 -2
  223. package/kits/skills/personal-assistant/scripts/pa.mjs +4 -4
  224. package/kits/skills/thread-ops/SKILL.md +10 -10
  225. package/kits/templates/message-fragments/item.md +1 -1
  226. package/kits/templates/system-fragments/channel.md +3 -3
  227. package/kits/templates/system-fragments/commands.md +5 -3
  228. package/kits/templates/system-fragments/reply.md +1 -5
  229. package/kits/templates/system-fragments/thread.md +13 -10
  230. package/package.json +5 -6
  231. package/scripts/agent-template/index.mjs +40 -0
  232. package/scripts/agent-template/inspect.mjs +240 -0
  233. package/scripts/agent-template/overlay.mjs +71 -0
  234. package/scripts/agent-template/pack.mjs +169 -0
  235. package/scripts/agent-template/shared/common.mjs +235 -0
  236. package/scripts/agent-template/shared/evolcore.mjs +75 -0
  237. package/scripts/agent-template/shared/plan.mjs +129 -0
  238. package/scripts/agent-template/shared/team-schema.json +70 -0
  239. package/scripts/agent-template/shared/template-contract.mjs +154 -0
  240. package/scripts/agent-template/shared/template-package.mjs +265 -0
  241. package/scripts/agent-template/shared/template-runtime.mjs +80 -0
  242. package/scripts/agent-template/shared/template.mjs +142 -0
  243. package/dist/cli/pa-workspace-command.js +0 -225
  244. package/dist/core/command/pa-workspace-store.js +0 -468
  245. package/dist/core/relation/pa-team.js +0 -132
  246. package/kits/docs/evolcore/pa-workspace.md +0 -51
  247. package/kits/skills/aid-ability/SKILL.md +0 -244
  248. package/kits/skills/ec-ability/SKILL.md +0 -67
  249. package/kits/skills/ec-ability/references/workflows.md +0 -15
@@ -1,4 +1,3 @@
1
- import { randomUUID } from 'node:crypto';
2
1
  import { logger } from '../../utils/logger.js';
3
2
  import { summarizeToolInput, summarizeToolInputForDisplay, toolInputForDisplay } from '../../utils/tool-summary.js';
4
3
  import { getErrorMessage, getToolResultErrorText, isContextTooLongText } from '../../utils/error-utils.js';
@@ -38,9 +37,10 @@ export class IMRenderer {
38
37
  /** 串行发送队列:保证消息按序到达 */
39
38
  sendChain = Promise.resolve();
40
39
  activityRecordChain = Promise.resolve();
41
- pendingAutomaticText;
42
- /** proactive:是否已发过 text 文本(用于去重 complete.result) */
40
+ /** 是否已投影 text 文本(用于去重 complete.result)。 */
43
41
  hasEmittedText = false;
42
+ pendingProactiveFinal;
43
+ proactiveFinalReady = false;
44
44
  /** 自增 callId 兜底(runner 没提供时用) */
45
45
  syntheticCallSeq = 0;
46
46
  currentAssistantUuid;
@@ -79,6 +79,41 @@ export class IMRenderer {
79
79
  return true;
80
80
  return this.opts.suppressIntermediateText ?? this.opts.suppressActivities ?? false;
81
81
  }
82
+ usesProactiveBehavior() {
83
+ return this.opts.envelope.chatmode === 'proactive';
84
+ }
85
+ usesCustomFinal() {
86
+ return this.usesProactiveBehavior() && this.opts.envelope.activityTransport === 'message';
87
+ }
88
+ /** Only the engine's successful task commit can publish an automatic final. */
89
+ async flushProactiveFinal() {
90
+ if (!this.usesCustomFinal())
91
+ return;
92
+ const pending = this.pendingProactiveFinal;
93
+ this.pendingProactiveFinal = undefined;
94
+ const ready = this.proactiveFinalReady;
95
+ this.proactiveFinalReady = false;
96
+ if (!pending)
97
+ return;
98
+ const { item } = pending;
99
+ if (!ready) {
100
+ this.emitProactiveItem(item);
101
+ return;
102
+ }
103
+ if (!item.text.trim() || (this.opts.noopSentinel && isNoopText(item.text, this.opts.noopSentinel)))
104
+ return;
105
+ this.recordActivity(item);
106
+ if (!this.suppressProactiveItem(item)) {
107
+ await this.sendPayload({ kind: 'activity.batch', items: [item], isFinal: true });
108
+ }
109
+ }
110
+ releaseProactiveFinal() {
111
+ const pending = this.pendingProactiveFinal;
112
+ this.pendingProactiveFinal = undefined;
113
+ this.proactiveFinalReady = false;
114
+ if (pending)
115
+ this.emitProactiveItem(pending.item);
116
+ }
82
117
  // ── 公开接口 ──
83
118
  /** 推入 AgentEvent,按 chatmode 投影 */
84
119
  emit(event, suppressTextProjection = false) {
@@ -106,7 +141,7 @@ export class IMRenderer {
106
141
  catch {
107
142
  // logger.event 失败不影响业务
108
143
  }
109
- if (this.opts.envelope.chatmode === 'proactive' && !suppressTextProjection) {
144
+ if (this.usesProactiveBehavior() && !suppressTextProjection) {
110
145
  this.emitProactive(event);
111
146
  }
112
147
  // interactive 模式由 MessageProcessor 显式调 addText/addToolCall/... 推入 items
@@ -114,7 +149,9 @@ export class IMRenderer {
114
149
  /** 强制刷新所有 pending 事件 */
115
150
  async flush(isFinal, attention) {
116
151
  await this.activityRecordChain;
117
- if (this.opts.envelope.chatmode === 'proactive') {
152
+ if (this.usesProactiveBehavior()) {
153
+ if (isFinal === false && this.usesCustomFinal())
154
+ this.releaseProactiveFinal();
118
155
  if (isFinal) {
119
156
  const pending = this.deferredProactiveText;
120
157
  this.deferredProactiveText = [];
@@ -127,26 +164,28 @@ export class IMRenderer {
127
164
  }
128
165
  }
129
166
  }
130
- // proactive 是 fire-and-forget,无 pending buffer;只需放出仍被扣住的工具结果
167
+ // Proactive behavior is fire-and-forget; only release any held tool results.
131
168
  this.releaseHeldToolResults();
132
169
  await this.activityRecordChain;
170
+ if (this.usesCustomFinal())
171
+ await this.sendChain;
133
172
  return;
134
173
  }
135
174
  return this.flushInternal(isFinal, attention);
136
175
  }
137
176
  /** 仅 flush activities,保留 textBuffer(用于中间 complete 事件) */
138
177
  async flushActivitiesOnly() {
139
- if (this.opts.envelope.chatmode === 'proactive')
178
+ if (this.usesProactiveBehavior())
140
179
  return;
141
180
  return this.flushActivitiesInternal();
142
181
  }
143
182
  /** 是否有 pending 内容 */
144
183
  hasContent() {
145
- return !!this.pendingAutomaticText || this.textBuffer.length > 0 || this.deferredProactiveText.length > 0 || this.itemsQueue.some(it => it.kind !== 'text') || this.hasHeldToolResults();
184
+ return this.textBuffer.length > 0 || this.deferredProactiveText.length > 0 || this.itemsQueue.some(it => it.kind !== 'text') || this.hasHeldToolResults();
146
185
  }
147
186
  /** 是否有会抑制兜底错误消息的正文/过程内容;lifecycle 边界不算。 */
148
187
  hasNonLifecycleContent() {
149
- return !!this.pendingAutomaticText || this.textBuffer.trim().length > 0 || this.hasHeldToolResults() || this.itemsQueue.some(it => {
188
+ return this.textBuffer.trim().length > 0 || this.hasHeldToolResults() || this.itemsQueue.some(it => {
150
189
  if (it.kind === 'text')
151
190
  return it.text.trim().length > 0;
152
191
  if (this.subtaskItems.has(it))
@@ -162,14 +201,12 @@ export class IMRenderer {
162
201
  }
163
202
  /** 是否有待发送的文本 */
164
203
  hasTextPending() {
165
- return !!this.pendingAutomaticText || this.textBuffer.length > 0;
204
+ return this.textBuffer.length > 0;
166
205
  }
167
206
  /** flush 当前 textBuffer 作为独立的 result.text(非 final),然后清空 buffer */
168
207
  async flushText() {
169
- if (this.opts.envelope.chatmode === 'proactive')
208
+ if (this.usesProactiveBehavior())
170
209
  return;
171
- if (this.pendingAutomaticText)
172
- await this.retryAutomaticText();
173
210
  if (this.textBuffer.length === 0)
174
211
  return;
175
212
  // 文件标记过滤后若只剩空白,应立即消费;尤其避免 final-only
@@ -208,12 +245,10 @@ export class IMRenderer {
208
245
  };
209
246
  this.sentContent = true;
210
247
  try {
211
- await this.sendAutomaticText(payload);
248
+ await this.sendPayload(payload);
212
249
  }
213
250
  catch (error) {
214
- // A failed durable enqueue must remain retryable by the final flush.
215
- if (this.opts.envelope.chatmode !== 'paactive')
216
- this.textBuffer = rawText + this.textBuffer;
251
+ this.textBuffer = rawText + this.textBuffer;
217
252
  throw error;
218
253
  }
219
254
  this.lastFlush = Date.now();
@@ -237,7 +272,10 @@ export class IMRenderer {
237
272
  this.textBuffer = '';
238
273
  this.allText = '';
239
274
  this.deferredProactiveText = [];
240
- this.pendingAutomaticText = undefined;
275
+ this.pendingProactiveFinal = undefined;
276
+ this.proactiveFinalReady = false;
277
+ if (this.usesCustomFinal())
278
+ this.hasEmittedText = false;
241
279
  }
242
280
  /** 仅丢弃尚未发送的正文,保留 notice/tool 等活动项。 */
243
281
  discardPendingText() {
@@ -248,16 +286,17 @@ export class IMRenderer {
248
286
  this.itemsQueue = this.itemsQueue.filter(it => it.kind !== 'text');
249
287
  this.textBuffer = '';
250
288
  this.deferredProactiveText = [];
251
- this.pendingAutomaticText = undefined;
289
+ this.pendingProactiveFinal = undefined;
290
+ this.proactiveFinalReady = false;
252
291
  }
253
292
  /** 当前 buffer 中尚未 flush 的文本 */
254
293
  getRemainingText() {
255
- return (this.pendingAutomaticText?.item.text ?? '') + this.textBuffer;
294
+ return this.textBuffer;
256
295
  }
257
296
  // ── 文本/活动注入(替代 StreamFlusher.addText/addActivity)──
258
297
  /** 添加文本片段(流式 text) */
259
298
  async addText(text, outputTokens, turn, assistantUuid, phase) {
260
- if (this.opts.envelope.chatmode === 'proactive')
299
+ if (this.usesProactiveBehavior())
261
300
  return;
262
301
  const sameAssistant = this.currentAssistantUuid === assistantUuid;
263
302
  // In deferred AUN private delivery, only explicit text_start/tool_use
@@ -295,7 +334,7 @@ export class IMRenderer {
295
334
  addToolCall(name, input, callId, descText, turn, outputTokens, assistantUuid) {
296
335
  if (callId && this.preflightDenialCallIds.has(callId))
297
336
  return;
298
- if (this.opts.envelope.chatmode === 'proactive')
337
+ if (this.usesProactiveBehavior())
299
338
  return;
300
339
  this.emitProgress('tool_call', outputTokens, turn, { toolName: name, callId });
301
340
  const displayInput = toolInputForDisplay(name, input);
@@ -328,7 +367,7 @@ export class IMRenderer {
328
367
  addToolResult(name, ok, result, error, callId, durationMs, descText, classification, assistantUuid) {
329
368
  if (callId && this.preflightDenialCallIds.has(callId))
330
369
  return;
331
- if (this.opts.envelope.chatmode === 'proactive')
370
+ if (this.usesProactiveBehavior())
332
371
  return;
333
372
  const normalizedClassification = !ok
334
373
  ? normalizeToolErrorClassification(classification ?? {})
@@ -370,7 +409,7 @@ export class IMRenderer {
370
409
  if (item.kind !== 'tool_result')
371
410
  return;
372
411
  this.toolResultCallIds.add(item.call_id);
373
- if (this.opts.envelope.chatmode === 'proactive') {
412
+ if (this.usesProactiveBehavior()) {
374
413
  this.emitProactiveItem(item);
375
414
  return;
376
415
  }
@@ -495,7 +534,7 @@ export class IMRenderer {
495
534
  }
496
535
  /** 添加进度提示 */
497
536
  addProgress(text, opts = {}) {
498
- if (this.opts.envelope.chatmode === 'proactive')
537
+ if (this.usesProactiveBehavior())
499
538
  return;
500
539
  if (this.suppressActivityItems())
501
540
  return;
@@ -558,7 +597,7 @@ export class IMRenderer {
558
597
  ...(text !== undefined && { text }),
559
598
  ...(metadata !== undefined && { metadata }),
560
599
  };
561
- if (this.opts.envelope.chatmode === 'proactive') {
600
+ if (this.usesProactiveBehavior()) {
562
601
  this.emitProactiveItem(item);
563
602
  return;
564
603
  }
@@ -578,7 +617,7 @@ export class IMRenderer {
578
617
  */
579
618
  addSubtaskActivity(item) {
580
619
  this.subtaskItems.add(item);
581
- if (this.opts.envelope.chatmode === 'proactive') {
620
+ if (this.usesProactiveBehavior()) {
582
621
  this.emitProactiveItem(item);
583
622
  return;
584
623
  }
@@ -605,7 +644,7 @@ export class IMRenderer {
605
644
  /** 添加系统提示 / 通知。force=true 仅跳过入队门禁;最终 flush 仍遵守 activity 抑制。 */
606
645
  addNotice(text, severity, subtype, force = false) {
607
646
  // proactive 模式:只放行真·终态错误,机务噪音(压缩/重试)和 emit 已覆盖的 subtype 均不发。
608
- if (this.opts.envelope.chatmode === 'proactive') {
647
+ if (this.usesProactiveBehavior()) {
609
648
  if (subtype == null || !IMRenderer.PROACTIVE_NOTICE_ALLOW.has(subtype))
610
649
  return;
611
650
  this.emitProactiveItem({ kind: 'notice', text, severity, subtype });
@@ -621,7 +660,7 @@ export class IMRenderer {
621
660
  }
622
661
  /** 通过系统通知发送运行状态,并保持与已有正文的发送顺序。 */
623
662
  async sendOperationalNotice(text, subtype) {
624
- if (!this.opts.operationalNoticesEnabled || this.opts.envelope.chatmode === 'proactive' || !text)
663
+ if (!this.opts.operationalNoticesEnabled || this.usesProactiveBehavior() || !text)
625
664
  return false;
626
665
  if (!this.hasSendableText(text, 'operational-notice'))
627
666
  return false;
@@ -712,51 +751,6 @@ export class IMRenderer {
712
751
  this.sendChain = handled.catch(() => { });
713
752
  return handled;
714
753
  }
715
- /** Model output uses PA's automatic-text outlet.
716
- * System notices, explicit sends, command receipts and interaction fallbacks bypass it.
717
- */
718
- async sendAutomaticText(payload) {
719
- if (this.opts.noopSentinel && isNoopText(payload.text, this.opts.noopSentinel))
720
- return;
721
- if (this.opts.envelope.chatmode !== 'paactive')
722
- return this.sendPayload(payload);
723
- try {
724
- // Another flush may have started while this one awaited a tool batch.
725
- // Never replace its in-flight or failed text item with this payload.
726
- while (this.pendingAutomaticText)
727
- await this.retryAutomaticText();
728
- }
729
- catch (error) {
730
- // This payload has not been recorded yet; preserve it behind the older
731
- // pending item so a later flush can retry both without loss or overlap.
732
- this.textBuffer = payload.text + this.textBuffer;
733
- throw error;
734
- }
735
- const item = {
736
- kind: 'text',
737
- text: payload.text,
738
- ...(payload.metadata?.forkAnchor ? { forkAnchor: payload.metadata.forkAnchor } : {}),
739
- };
740
- this.recordActivity(item, `activity-${randomUUID().replace(/-/g, '')}`);
741
- this.pendingAutomaticText = { item };
742
- await this.retryAutomaticText();
743
- }
744
- /** Keep a failed, already-recorded text item separate from newly buffered text. */
745
- retryAutomaticText() {
746
- const pending = this.pendingAutomaticText;
747
- if (!pending)
748
- return Promise.resolve();
749
- if (!pending.delivery) {
750
- pending.delivery = this.sendPayload({ kind: 'activity.batch', items: [pending.item] }).then(() => {
751
- if (this.pendingAutomaticText === pending)
752
- this.pendingAutomaticText = undefined;
753
- }, error => {
754
- pending.delivery = undefined;
755
- throw error;
756
- });
757
- }
758
- return pending.delivery;
759
- }
760
754
  scheduleFlush() {
761
755
  if (this.timer) {
762
756
  return;
@@ -802,8 +796,6 @@ export class IMRenderer {
802
796
  const nonThinking = this.itemsQueue.filter(it => it.kind !== 'text');
803
797
  if (nonThinking.length === 0)
804
798
  return;
805
- if (this.pendingAutomaticText)
806
- await this.retryAutomaticText();
807
799
  if (this.timer) {
808
800
  clearTimeout(this.timer);
809
801
  this.timer = undefined;
@@ -838,8 +830,6 @@ export class IMRenderer {
838
830
  clearTimeout(this.timer);
839
831
  this.timer = undefined;
840
832
  }
841
- if (this.pendingAutomaticText)
842
- await this.retryAutomaticText();
843
833
  // 显式 flush(轮次结束、出错收尾)时放出被扣住的后台占位结果;定时 flush 不放,
844
834
  // 否则长时间后台任务会在终态到达前就把占位结果发出去。放出的结果随本次 flush 一起发,
845
835
  // 不需要它重新挂上的定时器。
@@ -925,11 +915,10 @@ export class IMRenderer {
925
915
  };
926
916
  this.sentContent = true;
927
917
  try {
928
- await this.sendAutomaticText(payload);
918
+ await this.sendPayload(payload);
929
919
  }
930
920
  catch (error) {
931
- if (this.opts.envelope.chatmode !== 'paactive')
932
- this.textBuffer = text + this.textBuffer;
921
+ this.textBuffer = text + this.textBuffer;
933
922
  throw error;
934
923
  }
935
924
  this.lastFlush = Date.now();
@@ -947,11 +936,10 @@ export class IMRenderer {
947
936
  payload.attention = attention;
948
937
  this.sentContent = true;
949
938
  try {
950
- await this.sendAutomaticText(payload);
939
+ await this.sendPayload(payload);
951
940
  }
952
941
  catch (error) {
953
- if (this.opts.envelope.chatmode !== 'paactive')
954
- this.textBuffer = finalText + this.textBuffer;
942
+ this.textBuffer = finalText + this.textBuffer;
955
943
  throw error;
956
944
  }
957
945
  this.lastFlush = Date.now();
@@ -993,6 +981,48 @@ export class IMRenderer {
993
981
  if ((event.type === 'tool_use' || event.type === 'tool_result')
994
982
  && event.callId && this.preflightDenialCallIds.has(event.callId))
995
983
  return;
984
+ if (this.usesCustomFinal()) {
985
+ if (event.type === 'text') {
986
+ if (event.synthetic || !event.text)
987
+ return;
988
+ if (event.text.trim())
989
+ this.hasEmittedText = true;
990
+ this.allText += event.text;
991
+ this.proactiveFinalReady = false;
992
+ const pending = this.pendingProactiveFinal;
993
+ if (pending && (pending.phase !== event.phase
994
+ || (pending.assistantUuid && event.assistantUuid && pending.assistantUuid !== event.assistantUuid)
995
+ || (pending.turn !== undefined && event.turn !== undefined && pending.turn !== event.turn))) {
996
+ this.releaseProactiveFinal();
997
+ }
998
+ if (event.phase === 'commentary') {
999
+ this.emitProactiveItem({ kind: 'text', text: event.text });
1000
+ }
1001
+ else if (this.pendingProactiveFinal) {
1002
+ this.pendingProactiveFinal.item.text += event.text;
1003
+ }
1004
+ else {
1005
+ this.pendingProactiveFinal = {
1006
+ item: { kind: 'text', text: event.text }, phase: event.phase,
1007
+ assistantUuid: event.assistantUuid, turn: event.turn,
1008
+ };
1009
+ }
1010
+ return;
1011
+ }
1012
+ if (event.type === 'tool_use' || event.type === 'error'
1013
+ || (event.type === 'complete' && (event.queryFinal === false || event.isError))) {
1014
+ this.releaseProactiveFinal();
1015
+ }
1016
+ if (event.type === 'complete' && event.queryFinal !== false && !event.isError) {
1017
+ if (!this.hasEmittedText && event.result?.trim()) {
1018
+ this.pendingProactiveFinal = { item: { kind: 'summary', text: event.result,
1019
+ ...(event.subtype ? { subtype: event.subtype } : {}),
1020
+ } };
1021
+ }
1022
+ this.proactiveFinalReady = true;
1023
+ return;
1024
+ }
1025
+ }
996
1026
  // 对齐 interactive 的 dedup:流式 text 已推过时,complete.result 不再重复发 summary
997
1027
  if (event.type === 'complete' &&
998
1028
  !event.isError &&
@@ -1063,7 +1093,8 @@ export class IMRenderer {
1063
1093
  const payload = evolCommand
1064
1094
  ? { kind: 'activity.batch', items: [item], ext: { evolCommand } }
1065
1095
  : { kind: 'activity.batch', items: [item] };
1066
- this.opts.send(payload).catch(err => {
1096
+ const sent = this.usesCustomFinal() ? this.sendPayload(payload) : this.opts.send(payload);
1097
+ sent.catch(err => {
1067
1098
  logger.debug(`[IMRenderer] proactive send failed: ${err.message}`);
1068
1099
  });
1069
1100
  }
@@ -2059,6 +2059,10 @@ export class MessageBridge {
2059
2059
  }
2060
2060
  return menuSuccess(header, this.cmdHandler.getMenuItems(identity.role, msg.chatType || 'private', msg.isControlChannel ? 'control' : 'agent', authSubject));
2061
2061
  case 'menu.query': {
2062
+ if (name === 'menu' && args?.view === 'queries') {
2063
+ const data = await this.cmdHandler.execMenuQueryBatch(channel, msg.channelId, authSubject, args, msg.isControlChannel ? 'control' : 'agent', transportReplyContext);
2064
+ return menuSuccess(header, data);
2065
+ }
2062
2066
  if (name === 'menu' && args?.view === 'values') {
2063
2067
  validateMenuValueBatchArgs(args);
2064
2068
  const data = await this.cmdHandler.execMenuValueBatch(channel, msg.channelId, authSubject, args, args.context, msg.isControlChannel ? 'control' : 'agent', transportReplyContext);
@@ -5,7 +5,7 @@ import { LogicalQueueBridge } from './logical-queue-bridge.js';
5
5
  import { normalizeCausation } from '../causation/context.js';
6
6
  import { KeyedFairMutex } from '../handoff/mutex.js';
7
7
  import { ExecutionTimeoutError, OrphanedTargetSessionError, isExecutionFailure } from '../../utils/error-utils.js';
8
- import { isTopicThreadId } from '../thread/topic-id.js';
8
+ import { isTopicThreadId, normalizeTopicAid, safeFormatMainTopicId } from '../thread/topic-id.js';
9
9
  const DEFAULT_AGENT_NAME = '<unknown>';
10
10
  const RESTART_RESUME_CONTENT = 'evolcore 服务已重启,请继续之前未完成的任务。';
11
11
  export class MessageQueue {
@@ -421,6 +421,7 @@ export class MessageQueue {
421
421
  projectPath: item.projectPath,
422
422
  agentName: item.agentName,
423
423
  role: item.role,
424
+ priority: item.priority,
424
425
  resolve: item.resolve,
425
426
  reject: item.reject,
426
427
  enqueuedAt: item.enqueuedAt ?? item.message.enqueuedAt,
@@ -432,6 +433,7 @@ export class MessageQueue {
432
433
  projectPath: part.projectPath,
433
434
  agentName: part.agentName,
434
435
  role: part.role,
436
+ priority: part.priority,
435
437
  resolve: part.resolve,
436
438
  reject: part.reject,
437
439
  enqueuedAt: part.enqueuedAt ?? part.message.enqueuedAt,
@@ -484,6 +486,7 @@ export class MessageQueue {
484
486
  projectPath: part.projectPath,
485
487
  agentName: part.agentName,
486
488
  role: part.role,
489
+ priority: part.priority,
487
490
  enqueuedAt,
488
491
  };
489
492
  }
@@ -495,6 +498,7 @@ export class MessageQueue {
495
498
  projectPath: item.projectPath,
496
499
  agentName: item.agentName,
497
500
  role: item.role,
501
+ priority: item.priority,
498
502
  enqueuedAt,
499
503
  parts: item.parts?.map(part => this.serializePart(part, enqueuedAt)),
500
504
  };
@@ -509,6 +513,7 @@ export class MessageQueue {
509
513
  projectPath: item.projectPath,
510
514
  agentName: item.agentName || DEFAULT_AGENT_NAME,
511
515
  role: item.role,
516
+ priority: item.priority,
512
517
  resolve: () => { },
513
518
  reject: () => { },
514
519
  enqueuedAt,
@@ -548,6 +553,7 @@ export class MessageQueue {
548
553
  projectPath: item.projectPath,
549
554
  agentName: item.agentName || DEFAULT_AGENT_NAME,
550
555
  role: item.role,
556
+ priority: item.priority,
551
557
  resolve: () => { },
552
558
  reject: () => { },
553
559
  enqueuedAt: sourceEnqueuedAt,
@@ -576,6 +582,7 @@ export class MessageQueue {
576
582
  projectPath: merged.projectPath,
577
583
  agentName: merged.agentName,
578
584
  role: this.highestRole(parts),
585
+ priority: parts.some(part => part.priority) || undefined,
579
586
  resolve: () => parts.forEach(part => part.resolve()),
580
587
  reject: (error) => parts.forEach(part => part.reject(error)),
581
588
  enqueuedAt: this.earliestPartEnqueuedAt(parts),
@@ -931,6 +938,16 @@ export class MessageQueue {
931
938
  for (const bucket of parsed.queues) {
932
939
  restored += this.restoreBucket(bucket, restoredKeys);
933
940
  }
941
+ // Include restored ordinary input in the logical FIFO before new input
942
+ // can arrive. Durable internal priority remains a physical queue prefix.
943
+ for (const key of restoredKeys) {
944
+ this.logicalQueue.clear(key);
945
+ for (const item of this.queues.get(key) ?? []) {
946
+ if (!item.priority && item.message.source !== 'owner-inject' && item.message.attentionPolicy !== 'interrupt') {
947
+ this.logicalQueue.enqueue(key, item.message);
948
+ }
949
+ }
950
+ }
934
951
  this.persistQueuesImmediate();
935
952
  this.persistDurableDedup();
936
953
  if (restored > 0) {
@@ -967,7 +984,7 @@ export class MessageQueue {
967
984
  this.blockedQueues.delete(key);
968
985
  continue;
969
986
  }
970
- if (!this.processing.has(key) && !this.blockedReason?.(head.message))
987
+ if (!this.processing.has(key) && !this.blockedReason?.(head.message, this.sessionKeyFromQueueKey(key)))
971
988
  void this.processNext(key);
972
989
  }
973
990
  if (this.blockedQueues.size)
@@ -1090,14 +1107,15 @@ export class MessageQueue {
1090
1107
  enqueuedAt,
1091
1108
  timestamp: message.receivedAt ?? message.timestamp ?? enqueuedAt,
1092
1109
  };
1093
- const queuedItem = { message, projectPath, agentName, role: options?.role, resolve: queuedResolve, reject: queuedReject, enqueuedAt };
1110
+ const queuedItem = { message, projectPath, agentName, role: options?.role, priority: options?.priority, resolve: queuedResolve, reject: queuedReject, enqueuedAt };
1094
1111
  if (options?.priority) {
1095
- const firstOrdinary = queue.findIndex(item => item.message.source !== 'owner-inject');
1112
+ const firstOrdinary = queue.findIndex(item => item.message.source !== 'owner-inject'
1113
+ && (message.source === 'owner-inject' || !item.priority));
1096
1114
  queue.splice(firstOrdinary < 0 ? queue.length : firstOrdinary, 0, queuedItem);
1097
1115
  }
1098
1116
  else
1099
1117
  queue.push(queuedItem);
1100
- if (message.source !== 'owner-inject' && message.attentionPolicy !== 'interrupt')
1118
+ if (!options?.priority && message.source !== 'owner-inject' && message.attentionPolicy !== 'interrupt')
1101
1119
  this.logicalQueue.enqueue(queueKey, message);
1102
1120
  abortHandler = () => {
1103
1121
  if (settled || aborting)
@@ -1266,9 +1284,10 @@ export class MessageQueue {
1266
1284
  return;
1267
1285
  }
1268
1286
  // 逻辑队列重排:让响应模式的出队策略决定队首(默认 FIFO,不改变顺序)
1269
- if (queue[0]?.message.source !== 'owner-inject' && queue[0]?.message.attentionPolicy !== 'interrupt')
1287
+ if (!queue[0]?.priority && queue[0]?.message.source !== 'owner-inject' && queue[0]?.message.attentionPolicy !== 'interrupt')
1270
1288
  this.logicalQueue.reorderPhysical(queueKey, queue);
1271
- const blocked = this.blockedReason?.(queue[0].message);
1289
+ const sessionId = this.sessionKeyFromQueueKey(queueKey);
1290
+ const blocked = this.blockedReason?.(queue[0].message, sessionId);
1272
1291
  if (blocked) {
1273
1292
  if (this.blockedQueues.get(queueKey) !== blocked) {
1274
1293
  logger.info(`[Queue] waiting: key=${queueKey} dependency=${blocked}`);
@@ -1282,7 +1301,7 @@ export class MessageQueue {
1282
1301
  }
1283
1302
  this.blockedQueues.delete(queueKey);
1284
1303
  // 贪心合并:群聊按完整时间线,旧路径/私聊按 peerId
1285
- const items = this.dequeueGreedy(queue);
1304
+ const items = this.dequeueGreedy(queue, sessionId);
1286
1305
  // 同步逻辑队列:移除所有被合并处理的消息
1287
1306
  if (items.length > 0) {
1288
1307
  const processedIds = items.map(item => item.message.messageId).filter((id) => !!id);
@@ -1301,6 +1320,7 @@ export class MessageQueue {
1301
1320
  projectPath: merged.projectPath,
1302
1321
  agentName: merged.agentName,
1303
1322
  role: this.highestRole(rawParts),
1323
+ priority: rawParts.some(part => part.priority) || undefined,
1304
1324
  resolve: () => rawParts.forEach(part => part.resolve()),
1305
1325
  reject: (error) => rawParts.forEach(part => part.reject(error)),
1306
1326
  enqueuedAt: this.earliestPartEnqueuedAt(rawParts),
@@ -1410,7 +1430,7 @@ export class MessageQueue {
1410
1430
  // 与 enqueue 路径保持同一条件,避免把 owner-inject/interrupt 消息写进逻辑队列。
1411
1431
  this.logicalQueue.clear(queueKey);
1412
1432
  for (const item of queue) {
1413
- if (item.message.source !== 'owner-inject' && item.message.attentionPolicy !== 'interrupt') {
1433
+ if (!item.priority && item.message.source !== 'owner-inject' && item.message.attentionPolicy !== 'interrupt') {
1414
1434
  this.logicalQueue.enqueue(queueKey, item.message);
1415
1435
  }
1416
1436
  }
@@ -1423,11 +1443,11 @@ export class MessageQueue {
1423
1443
  * 群聊入队携带 role,此时取出当前所有群聊 pending 并按时间线合并;
1424
1444
  * role 只作为逐条元数据,不作为分批边界。未携带 role 的旧路径/私聊按 peerId 合并。
1425
1445
  */
1426
- dequeueGreedy(queue) {
1446
+ dequeueGreedy(queue, sessionId) {
1427
1447
  const first = queue.shift();
1428
1448
  const result = [first];
1429
1449
  if (this.isOriginHandoff(first.message)) {
1430
- while (queue.length > 0 && !this.blockedReason?.(queue[0].message) && this.canMergeOriginHandoffs(first, queue[0])) {
1450
+ while (queue.length > 0 && !this.blockedReason?.(queue[0].message, sessionId) && this.canMergeOriginHandoffs(first, queue[0])) {
1431
1451
  result.push(queue.shift());
1432
1452
  }
1433
1453
  if (result.length > 1) {
@@ -1443,7 +1463,7 @@ export class MessageQueue {
1443
1463
  if (mergeSubmittedResume) {
1444
1464
  const remaining = [];
1445
1465
  for (const item of queue) {
1446
- if (!this.blockedReason?.(item.message) && !this.isMergeBarrier(item.message) && this.canDequeueAfterSubmittedResume(first, item)) {
1466
+ if (!this.blockedReason?.(item.message, sessionId) && !this.isMergeBarrier(item.message) && this.canDequeueAfterSubmittedResume(first, item)) {
1447
1467
  result.push(item);
1448
1468
  }
1449
1469
  else {
@@ -1463,7 +1483,7 @@ export class MessageQueue {
1463
1483
  else if (mergeGroupTimeline) {
1464
1484
  const remaining = [];
1465
1485
  for (const item of queue) {
1466
- if (!this.blockedReason?.(item.message) && !this.isMergeBarrier(item.message) && this.canDequeueGroupTimeline(first, item)) {
1486
+ if (!this.blockedReason?.(item.message, sessionId) && !this.isMergeBarrier(item.message) && this.canDequeueGroupTimeline(first, item)) {
1467
1487
  result.push(item);
1468
1488
  }
1469
1489
  else {
@@ -1475,7 +1495,7 @@ export class MessageQueue {
1475
1495
  result.sort((a, b) => this.firstTimestamp(a) - this.firstTimestamp(b));
1476
1496
  }
1477
1497
  else {
1478
- while (queue.length > 0 && !this.blockedReason?.(queue[0].message) && !this.isMergeBarrier(queue[0].message) && queue[0].message.peerId === mergeKey) {
1498
+ while (queue.length > 0 && !this.blockedReason?.(queue[0].message, sessionId) && !this.isMergeBarrier(queue[0].message) && queue[0].message.peerId === mergeKey) {
1479
1499
  result.push(queue.shift());
1480
1500
  }
1481
1501
  }
@@ -1616,8 +1636,14 @@ export class MessageQueue {
1616
1636
  subMessages.push(...m.items.map(sub => ({ ...sub, peerRole: sub.peerRole ?? item.role })));
1617
1637
  }
1618
1638
  else {
1639
+ // 跨话题自派:会话对端是话题对端(用于路由/权限),信封头署名仍是本端,
1640
+ // 否则模型会以为这条「我派的活」是对端说的话。
1641
+ const selfAddressed = m.source === 'self-address';
1619
1642
  subMessages.push({
1620
- peerId: m.peerId, peerName: m.peerName, peerType: m.peerType,
1643
+ peerId: selfAddressed ? (m.selfAID || m.peerId) : m.peerId,
1644
+ peerName: selfAddressed ? undefined : m.peerName,
1645
+ peerType: selfAddressed ? 'agent' : m.peerType,
1646
+ selfAddressed: selfAddressed || undefined,
1621
1647
  peerRole: item.role,
1622
1648
  sameDevice: m.sameDevice, sameNetwork: m.sameNetwork, sameEgressIp: m.sameEgressIp,
1623
1649
  encrypted: m.encrypted,
@@ -2026,6 +2052,31 @@ export class MessageQueue {
2026
2052
  }
2027
2053
  return total;
2028
2054
  }
2055
+ /** Live AUN private counterparts, deduplicated across topics and projects. */
2056
+ getActivePrivatePeerCountBySelfAID(selfAID) {
2057
+ const self = normalizeTopicAid(selfAID).toLowerCase();
2058
+ const peers = new Set();
2059
+ for (const [queueKey, item] of this.activeBatches) {
2060
+ if (!this.processing.has(queueKey))
2061
+ continue;
2062
+ const message = item.message;
2063
+ const queueSelf = this.selfAIDFromQueueKey(queueKey) ?? message.selfAID;
2064
+ if (!queueSelf || normalizeTopicAid(queueSelf).toLowerCase() !== self)
2065
+ continue;
2066
+ if (message.chatType !== 'private')
2067
+ continue;
2068
+ const sessionKey = this.queueKeyToSessionKey.get(queueKey);
2069
+ const route = sessionKey ? this.parseSessionKey(sessionKey) : message;
2070
+ if (route.channelType !== 'aun')
2071
+ continue;
2072
+ // Use the conversation route, not the sender of an owner-injected input.
2073
+ const peer = normalizeTopicAid(route.channelId).toLowerCase();
2074
+ if (peer === self || !safeFormatMainTopicId(self, peer))
2075
+ continue;
2076
+ peers.add(peer);
2077
+ }
2078
+ return peers.size;
2079
+ }
2029
2080
  /**
2030
2081
  * 获取指定 agent 的处理中队列详情列表(用于阻塞提示,帮助 agent 判断等待时长)。
2031
2082
  * 每项包含 queueKey(可从中解析 sessionId 和路径)和 agentName。
@@ -33,6 +33,7 @@ export function buildEnvelope(opts) {
33
33
  channelId: opts.channelId,
34
34
  agentName: opts.agentName ?? '<unknown>',
35
35
  chatmode: opts.chatmode ?? 'interactive',
36
+ ...(opts.activityTransport ? { activityTransport: opts.activityTransport } : {}),
36
37
  delivery,
37
38
  replyContext,
38
39
  causation: opts.causation,
@@ -64,8 +65,15 @@ export function isDeliveryTarget(value) {
64
65
  if (!value || typeof value !== 'object' || Array.isArray(value))
65
66
  return false;
66
67
  const route = value;
67
- if (route.chatType === 'private')
68
- return true;
68
+ if (route.chatType === 'private') {
69
+ if (route.service === undefined)
70
+ return true;
71
+ const service = route.service;
72
+ // fail-closed:形状不对就判为非法路由,让调用方拿到 AUN_OUTBOUND_ROUTE_REQUIRED,
73
+ // 而不是悄悄走上服务豁免分支绕过联系人准入。
74
+ return !!service && typeof service === 'object' && !Array.isArray(service)
75
+ && typeof service.type === 'string' && typeof service.requestId === 'string';
76
+ }
69
77
  return route.chatType === 'group'
70
78
  && typeof route.groupId === 'string'
71
79
  && route.groupId.trim().length > 0;