evolcore 0.0.48 → 0.0.50

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 (302) hide show
  1. package/CHANGELOG.md +97 -0
  2. package/bin/ecmsg.js +9 -4
  3. package/dist/ability/caller/authorization.js +21 -0
  4. package/dist/ability/caller/command.js +164 -0
  5. package/dist/ability/caller/contract.js +102 -0
  6. package/dist/ability/caller/daemon.js +158 -0
  7. package/dist/ability/caller/service.js +380 -0
  8. package/dist/ability/command-contract.js +5 -0
  9. package/dist/ability/daemon.js +5 -1
  10. package/dist/ability/interop-v1.js +10 -3
  11. package/dist/ability/management.js +1 -0
  12. package/dist/agent-template/jobs.js +173 -1
  13. package/dist/agent-template/runtime.js +285 -8
  14. package/dist/agent-template/service.js +1159 -40
  15. package/dist/agent-template/types.js +2 -1
  16. package/dist/agents/baseagent-availability.js +27 -3
  17. package/dist/agents/baseagent-capability-adapter.js +102 -0
  18. package/dist/agents/baseagent-plugin-descriptor.js +274 -0
  19. package/dist/agents/baseagent-plugin-loader.js +145 -0
  20. package/dist/agents/baseagent.js +68 -2
  21. package/dist/agents/claude-gateway/agent-registration.js +389 -0
  22. package/dist/agents/claude-gateway/binding.js +96 -0
  23. package/dist/agents/claude-gateway/inbox.js +138 -0
  24. package/dist/agents/claude-gateway/index.js +125 -0
  25. package/dist/agents/claude-gateway/listing.js +330 -0
  26. package/dist/agents/claude-gateway/router.js +328 -0
  27. package/dist/agents/claude-gateway/sessions.js +128 -0
  28. package/dist/agents/claude-gateway/terminal.js +250 -0
  29. package/dist/agents/claude-gateway/transcript.js +272 -0
  30. package/dist/agents/claude-gateway/types.js +14 -0
  31. package/dist/agents/claude-runner.js +6 -10
  32. package/dist/agents/codex-runner.js +9 -2
  33. package/dist/agents/{gemini-runner.js → gemini/gemini-runner.js} +17 -17
  34. package/dist/{core/session/adapters → agents/gemini}/gemini-session-file-adapter.js +2 -2
  35. package/dist/agents/gemini/index.js +51 -0
  36. package/dist/aun/aid/control-aid.js +52 -32
  37. package/dist/aun/group/invite-service.js +6 -36
  38. package/dist/aun/group/operations.js +6 -0
  39. package/dist/aun/msg/mention-schema.js +1 -1
  40. package/dist/aun/msg/p2p.js +31 -2
  41. package/dist/aun/msg/upload.js +126 -3
  42. package/dist/build-identity.json +1 -1
  43. package/dist/channels/aun.js +1175 -457
  44. package/dist/cli/ability-command.js +42 -0
  45. package/dist/cli/agent-command.js +20 -1
  46. package/dist/cli/agent-create.js +78 -18
  47. package/dist/cli/agent-template.js +5 -3
  48. package/dist/cli/agent.js +91 -0
  49. package/dist/cli/aun-commands.js +92 -34
  50. package/dist/cli/bench.js +5 -2
  51. package/dist/cli/config.js +22 -6
  52. package/dist/cli/daemon-commands.js +245 -101
  53. package/dist/cli/directory.js +6 -1
  54. package/dist/cli/ecmsg-gateway.js +11 -9
  55. package/dist/cli/index.js +30 -5
  56. package/dist/cli/init.js +39 -63
  57. package/dist/cli/managed-command-guard.js +3 -0
  58. package/dist/cli/menu-client.js +32 -7
  59. package/dist/cli/model.js +20 -5
  60. package/dist/cli/pay-command.js +30 -0
  61. package/dist/cli/provider-command.js +6 -2
  62. package/dist/cli/quota.js +89 -0
  63. package/dist/cli/restart-monitor.js +2 -2
  64. package/dist/cli/role.js +1 -0
  65. package/dist/cli/services-command.js +12 -9
  66. package/dist/cli/team-workspace-command.js +56 -2
  67. package/dist/cli/thread-command.js +78 -12
  68. package/dist/config/access-policy.js +16 -3
  69. package/dist/config/config-field-policy.js +88 -9
  70. package/dist/config/config-manager.js +97 -47
  71. package/dist/config/config-operation-service.js +22 -1
  72. package/dist/config/gateway-config.js +9 -8
  73. package/dist/config/owner-config.js +0 -16
  74. package/dist/config/peer-role-resolver.js +1 -7
  75. package/dist/config/providers-config.js +107 -20
  76. package/dist/config/providers-management.js +45 -21
  77. package/dist/config/resolved-config-op.js +4 -44
  78. package/dist/config/schema-migration.js +78 -5
  79. package/dist/config/schema-registry.js +52 -7
  80. package/dist/config-store.js +1309 -17
  81. package/dist/core/agent-application-service.js +220 -1
  82. package/dist/core/agent-ipc-registration.js +19 -2
  83. package/dist/core/agent-reload-coordinator.js +5 -0
  84. package/dist/core/agent-runtime.js +198 -54
  85. package/dist/core/auth/agent-delegation.js +14 -0
  86. package/dist/core/auth/delegation-authorization.js +33 -26
  87. package/dist/core/auth/operation-authorizer.js +16 -1
  88. package/dist/core/auth/operation-catalog.js +59 -7
  89. package/dist/core/baseagent-loader.js +30 -3
  90. package/dist/core/capability/capability-manager.js +16 -7
  91. package/dist/core/channel-runtime.js +4 -2
  92. package/dist/core/command/agent-control.js +20 -2
  93. package/dist/core/command/agent-template-menu.js +4 -3
  94. package/dist/core/command/cli-intent-parser.js +28 -0
  95. package/dist/core/command/command-handler.js +45 -2
  96. package/dist/core/command/menu-catalog.js +20 -4
  97. package/dist/core/command/menu-file-path.js +70 -0
  98. package/dist/core/command/menu-handler.js +97 -73
  99. package/dist/core/command/menu-protocol.js +29 -0
  100. package/dist/core/command/menu-query-batch.js +2 -2
  101. package/dist/core/command/private-mention-menu.js +71 -0
  102. package/dist/core/command/remote-shell.js +565 -0
  103. package/dist/core/command/slash-handler.js +17 -26
  104. package/dist/core/command/team-workspace-bootstrap.js +2 -1
  105. package/dist/core/command/topic-slash.js +7 -1
  106. package/dist/core/daemon-bootstrap.js +0 -4
  107. package/dist/core/daemon-control.js +58 -1
  108. package/dist/core/daemon-lifecycle.js +29 -7
  109. package/dist/core/evolagent-registry.js +18 -9
  110. package/dist/core/handoff/runtime.js +1 -1
  111. package/dist/core/host-snapshot.js +8 -3
  112. package/dist/core/initialization/service.js +3 -0
  113. package/dist/core/interaction-router.js +130 -0
  114. package/dist/core/ipc-registration.js +5 -0
  115. package/dist/core/memory/consolidation-context.js +2 -1
  116. package/dist/core/memory/consolidation.js +35 -64
  117. package/dist/core/message/aun-ipc-sender.js +213 -74
  118. package/dist/core/message/aun-request-registry.js +31 -0
  119. package/dist/core/message/contact-admission.js +91 -6
  120. package/dist/core/message/contact-pending-inbound.js +113 -0
  121. package/dist/core/message/contact-thread-approval.js +212 -0
  122. package/dist/core/message/im-renderer.js +40 -1
  123. package/dist/core/message/message-admission.js +5 -39
  124. package/dist/core/message/message-bridge.js +197 -45
  125. package/dist/core/message/message-log.js +32 -0
  126. package/dist/core/message/message-queue.js +102 -18
  127. package/dist/core/message/peer-mode.js +15 -4
  128. package/dist/core/message/response-engine.js +174 -26
  129. package/dist/core/message/send-options.js +37 -3
  130. package/dist/core/message/send-routing.js +11 -7
  131. package/dist/core/model/config-scope.js +6 -14
  132. package/dist/core/model/model-catalog.js +5 -5
  133. package/dist/core/model/model-diagnostics.js +19 -0
  134. package/dist/core/model/model-fallback.js +13 -2
  135. package/dist/core/ownership/owner-resolver.js +12 -86
  136. package/dist/core/pack-auth.js +7 -0
  137. package/dist/core/pack-install.js +1 -1
  138. package/dist/core/permission/ec-command-parser.js +288 -77
  139. package/dist/core/permission/protected-paths.js +64 -9
  140. package/dist/core/permission/services-path-acl.js +458 -0
  141. package/dist/core/permission/tool-policy.js +26 -10
  142. package/dist/core/relation/peer-identity.js +13 -0
  143. package/dist/core/session/adapters/claude-session-file-adapter.js +6 -2
  144. package/dist/core/session/adapters/codex-session-file-adapter.js +4 -0
  145. package/dist/core/session/session-manager.js +47 -10
  146. package/dist/core/session/session-mapper.js +16 -0
  147. package/dist/core/skill/index-generator.js +2 -3
  148. package/dist/core/skill/switch-resolver.js +3 -0
  149. package/dist/core/task/task-recovery-service.js +1 -0
  150. package/dist/core/thread/command-parser.js +4 -1
  151. package/dist/core/thread/ipc-operation.js +4 -2
  152. package/dist/core/thread/thread-operation.js +25 -10
  153. package/dist/core/thread/thread-service.js +294 -55
  154. package/dist/core/thread/topic-id.js +67 -2
  155. package/dist/core/thread/types.js +15 -1
  156. package/dist/directory/owner-directory-admission.js +11 -8
  157. package/dist/directory/owner-directory-cache.js +19 -0
  158. package/dist/directory/owner-directory-markdown.js +1 -1
  159. package/dist/directory/owner-directory-policy.js +5 -30
  160. package/dist/directory/owner-directory-request-operation.js +5 -2
  161. package/dist/eck/kit-renderer.js +3 -2
  162. package/dist/eck/message-renderer.js +28 -5
  163. package/dist/ecweb/basic-settings-service.js +5 -9
  164. package/dist/ecweb/providers-service.js +4 -2
  165. package/dist/ecweb/runtime/supervisor.js +36 -8
  166. package/dist/event-center/center-config.js +9 -5
  167. package/dist/event-center/dispatcher.js +10 -1
  168. package/dist/event-center/ipc-operation.js +19 -0
  169. package/dist/event-center/registry.js +20 -5
  170. package/dist/event-center/runtime.js +10 -7
  171. package/dist/index.js +120 -41
  172. package/dist/ipc.js +83 -3
  173. package/dist/outputs/authorization.js +16 -0
  174. package/dist/outputs/cards.js +336 -0
  175. package/dist/outputs/events.js +3 -2
  176. package/dist/outputs/protocol.js +1 -0
  177. package/dist/outputs/service.js +2 -15
  178. package/dist/paths.js +48 -1
  179. package/dist/pay/command.js +38 -0
  180. package/dist/pay/protocol.js +136 -0
  181. package/dist/pay/runtime.js +188 -0
  182. package/dist/pay/service.js +384 -0
  183. package/dist/pay/store.js +81 -0
  184. package/dist/response-system/engines/v1/proactive-flow.js +29 -2
  185. package/dist/services/dispatcher.js +23 -5
  186. package/dist/services/host/main.js +388 -0
  187. package/dist/services/host/protocol.js +118 -0
  188. package/dist/services/host/resident.js +310 -0
  189. package/dist/services/host-client.js +386 -0
  190. package/dist/services/host-deploy.js +180 -0
  191. package/dist/services/host-launch.js +117 -0
  192. package/dist/services/host-recycle.js +203 -0
  193. package/dist/services/host-runtime.js +802 -0
  194. package/dist/services/idempotency.js +44 -86
  195. package/dist/services/index-generator.js +4 -3
  196. package/dist/services/index.js +204 -22
  197. package/dist/services/ipc-operation.js +288 -44
  198. package/dist/services/pack-manager.js +1 -0
  199. package/dist/services/script-runner.js +515 -83
  200. package/dist/services/service-payload.js +13 -7
  201. package/dist/services/validation.js +109 -4
  202. package/dist/stats/budget.js +1 -1
  203. package/dist/stats/model-resolver.js +2 -2
  204. package/dist/stats/quota-query.js +95 -0
  205. package/dist/trigger/application-service.js +6 -4
  206. package/dist/trigger/local-files.js +19 -9
  207. package/dist/trigger/scheduler.js +22 -12
  208. package/dist/trigger/script-sandbox.js +51 -8
  209. package/dist/utils/aid-bind.js +3 -0
  210. package/dist/utils/atomic-write.js +22 -8
  211. package/dist/utils/evolcore-version.js +2 -2
  212. package/dist/utils/host-info.js +173 -1
  213. package/dist/utils/logger.js +2 -2
  214. package/dist/utils/media-cache.js +190 -43
  215. package/dist/utils/npm-ops.js +43 -8
  216. package/dist/utils/restart-safety.js +14 -1
  217. package/dist/utils/system-memory.js +113 -25
  218. package/dist/utils/systemd-lifecycle.js +154 -0
  219. package/dist/utils/windows-shell-trust.js +7 -3
  220. package/dist/workbench/service.js +1 -1
  221. package/kits/docs/INDEX.md +3 -2
  222. 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 +1 -0
  223. package/kits/docs/channels/aun.md +1 -1
  224. package/kits/docs/evolcore/INDEX.md +9 -6
  225. package/kits/docs/evolcore/agent.md +36 -1
  226. package/kits/docs/evolcore/aid.md +45 -3
  227. package/kits/docs/evolcore/config.md +5 -2
  228. package/kits/docs/evolcore/directory.md +8 -9
  229. package/kits/docs/evolcore/group.md +2 -1
  230. package/kits/docs/evolcore/memory-tags.md +2 -0
  231. package/kits/docs/evolcore/menu-client.md +3 -3
  232. package/kits/docs/evolcore/menu-protocol.md +7 -0
  233. package/kits/docs/evolcore/model.md +3 -0
  234. package/kits/docs/evolcore/msg.md +77 -10
  235. package/kits/docs/evolcore/pay.md +34 -0
  236. package/kits/docs/evolcore/provider.md +22 -1
  237. package/kits/docs/evolcore/quota.md +54 -0
  238. package/kits/docs/evolcore/role.md +3 -0
  239. package/kits/docs/evolcore/services.md +46 -18
  240. package/kits/docs/evolcore/stats.md +2 -0
  241. package/kits/docs/evolcore/thread-chain.md +2 -0
  242. package/kits/docs/evolcore/tool-authorization.md +10 -0
  243. package/kits/docs/evolcore/trigger.md +2 -0
  244. package/kits/rules/01-overview.md +11 -32
  245. package/kits/rules/02-navigation.md +7 -0
  246. package/kits/rules/06-channel.md +3 -3
  247. package/kits/schemas/_meta.json +38 -5
  248. package/kits/schemas/agent-config.schema.20.json +24 -0
  249. package/kits/schemas/agent-config.schema.21.json +974 -0
  250. package/kits/schemas/agent-config.schema.22.json +977 -0
  251. package/kits/schemas/agent-config.schema.23.json +958 -0
  252. package/kits/schemas/daemon.schema.10.json +373 -0
  253. package/kits/schemas/daemon.schema.9.json +12 -0
  254. package/kits/schemas/defaults.schema.7.json +472 -0
  255. package/kits/schemas/providers.schema.3.json +18 -2
  256. package/kits/schemas/relation-config.schema.13.json +289 -0
  257. package/kits/skills/.switches.json +17 -1
  258. package/kits/skills/ability/SKILL.md +229 -34
  259. package/kits/skills/ability/STRUCTURE.md +333 -0
  260. package/kits/skills/ability/references/cli.md +208 -0
  261. package/kits/skills/ability/references/development.md +107 -37
  262. package/kits/skills/ability/references/management.md +106 -46
  263. package/kits/skills/ability/references/runtime-protocol.md +65 -63
  264. package/kits/skills/agent-output-cards/SKILL.md +64 -0
  265. package/kits/skills/ec-group/SKILL.md +8 -6
  266. package/kits/skills/ec-group/TASK.md +186 -0
  267. package/kits/skills/ec-group/WORKLOG.md +180 -0
  268. package/kits/skills/ec-group-collaboration/SKILL.md +3 -3
  269. package/kits/skills/ec-pay/SKILL.md +101 -0
  270. package/kits/skills/ec-pay/references/pay-cli.md +110 -0
  271. package/kits/skills/ec-provider/SKILL.md +58 -9
  272. package/kits/skills/{ec-service-proxy → ec-proxy}/SKILL.md +8 -5
  273. package/kits/skills/ec-service-call/SKILL.md +135 -0
  274. package/kits/skills/ec-service-pack/SKILL.md +277 -0
  275. package/kits/skills/ec-trigger/SKILL.md +1 -1
  276. package/kits/templates/memory-consolidation/notes.md +2 -2
  277. package/kits/templates/memory-consolidation/workflow.md +46 -0
  278. package/kits/templates/roles/visitor.json +1 -0
  279. package/kits/templates/system-fragments/channel.md +13 -4
  280. package/kits/templates/system-fragments/commands.md +5 -3
  281. package/kits/templates/system-fragments/directory-contacts.md +3 -4
  282. package/kits/templates/system-fragments/reply.md +1 -0
  283. package/kits/templates/system-fragments/session.md +1 -1
  284. package/kits/templates/system-fragments/thread.md +27 -128
  285. package/kits/templates/system-fragments/venue.md +27 -0
  286. package/package.json +4 -5
  287. package/scripts/agent-template/inspect.mjs +79 -29
  288. package/scripts/agent-template/overlay.mjs +20 -2
  289. package/scripts/agent-template/shared/common.mjs +24 -6
  290. package/scripts/agent-template/shared/team-schema.json +23 -5
  291. package/scripts/agent-template/shared/template-contract.mjs +107 -17
  292. package/scripts/agent-template/shared/template-package.mjs +254 -29
  293. package/scripts/agent-template/shared/template-runtime.mjs +145 -2
  294. package/scripts/agent-template/shared/template.mjs +67 -9
  295. package/scripts/agent-template/team-pack.mjs +132 -41
  296. package/scripts/agent-template/team-preview.mjs +249 -5
  297. package/kits/docs/aun/ABILITY_CALLING.md +0 -280
  298. package/kits/docs/evolcore/ability.md +0 -185
  299. package/kits/skills/ability/references/calling.md +0 -56
  300. package/kits/skills/ability/references/contract-checklist.md +0 -37
  301. package/kits/skills/ability/references/recovery.md +0 -27
  302. /package/dist/{core/capability/providers → agents/gemini}/gemini-capability-provider.js +0 -0
@@ -1,3 +1,4 @@
1
+ import { trustedContactInboundDelivery } from './contact-pending-inbound.js';
1
2
  import { loadAgent } from '../../config-store.js';
2
3
  import { subscribeUpgradeJob } from '../../utils/upgrade-jobs.js';
3
4
  import { initializationBlocksTasks } from '../../cli/agent-create.js';
@@ -7,10 +8,10 @@ import path from 'path';
7
8
  import { agentStorageMenuService, isAgentStorageMenuRequest } from '../command/agent-storage-menu.js';
8
9
  import { agentMdMenuService } from '../command/agentmd-menu.js';
9
10
  import { containsAgentMdMenuRequest } from '../command/agentmd-menu-request.js';
10
- import { currentContactBinding, sameContactBinding } from './contact-admission.js';
11
+ import { currentContactBinding, sameContactBinding, verifiedContactBinding } from './contact-admission.js';
11
12
  import { logger, logPreview } from '../../utils/logger.js';
12
13
  import { StreamDebouncer } from './stream-debouncer.js';
13
- import { appendMessageLog, appendMessageLogStrict, buildInboundEntry, isTransientProtocolMessage } from './message-log.js';
14
+ import { appendMessageLog, appendMessageLogStrict, appendInboundMessageLogOnce, buildInboundEntry, isTransientProtocolMessage } from './message-log.js';
14
15
  import { buildEnvelope } from './message-utils.js';
15
16
  import { chatDirPath } from '../session/session-fs-store.js';
16
17
  import { readTopicStatus } from '../session/session-mapper.js';
@@ -22,14 +23,14 @@ import { isValidAid } from '../../aun/aid/validation.js';
22
23
  import { prepareOwnerDirectoryAdmission } from '../../directory/owner-directory-admission.js';
23
24
  import { PeerIdentityCache, formatPeerKey } from '../relation/peer-identity.js';
24
25
  import { ownerResolver, refreshOwnershipForAuthorization, OWNERSHIP_CACHE_MAX_AGE_MS } from '../ownership/owner-resolver.js';
25
- import { isTopicSession, sessionLocalTopicId } from '../thread/topic-id.js';
26
+ import { isTopicSession, isTopicThreadId, sessionLocalTopicId, sessionTopicThreadId } from '../thread/topic-id.js';
26
27
  import { resolveEffective } from '../../config/config-manager.js';
27
28
  import { createDecisionInferenceProvider } from '../inference/text-inference.js';
28
29
  import { AutoMentionGate } from './auto-mention-gate.js';
29
30
  import { syncGroupRulesContext } from '../../eck/group-rules-sync.js';
30
31
  import { readSoulContent } from '../soul.js';
31
32
  import { authorizeAccess, buildAuthSubject } from '../auth/auth-gateway.js';
32
- import { MenuDiagnosticLimiter, deliverMenuResponse, isRetryableMenuTransportError, MenuRequestDeduper, hasValidMenuId, menuFailure, menuPayloadFingerprint, menuSuccess, normalizeMenuError, parseMenuControl, validateMenuRequest, evaluateEvolMenuVersionGate, evolMenuResponseTransportMetadata, isAunMenuTokenRequired, menuCommandForName, normalizeMenuResponseTiming, withMenuProcessingTime, beginMenuDeliveryTiming, logMenuRequestCompleted, logMenuRequestReceived, logMenuResponseRetry, } from '../command/menu-protocol.js';
33
+ import { MenuDiagnosticLimiter, deliverMenuResponse, isRetryableMenuTransportError, MenuRequestDeduper, hasValidMenuId, menuFailure, menuPayloadFingerprint, menuSuccess, normalizeMenuError, parseMenuControl, validateMenuRequest, evaluateEvolMenuVersionGate, evolMenuResponseTransportMetadata, isAunMenuTokenRequired, menuCommandForName, normalizeMenuResponseTiming, withMenuProcessingTime, beginMenuDeliveryTiming, logMenuRequestCompleted, logMenuRequestReceived, logMenuResponseRetry, traceMenuStage, } from '../command/menu-protocol.js';
33
34
  import { resolveExplicitMenuExecutionContext, validateMenuCatalogArgs, validateMenuValueBatchArgs } from '../command/menu-catalog.js';
34
35
  import { MenuTokenStore } from '../command/menu-token-store.js';
35
36
  import { SessionRenewService } from '../session/session-renew.js';
@@ -39,14 +40,19 @@ import { guardGroupSlashCommand, parseFullAccessCommand } from '../command/slash
39
40
  import { createAgentPolicyAuthorization, createSessionFullAccessAuthorization } from '../role/runtime-policy.js';
40
41
  import { auditFullAccessEvent } from '../auth/authorization-audit.js';
41
42
  import { DIAGNOSTIC_AGENT_AID, DiagnosticSessionRouter, parseDiagnosticEvent, isDiagnosticSessionActive } from '../command/diag-service.js';
43
+ import { isCcAgentAid, routeToGateway, stopGatewayOutputs } from '../../agents/claude-gateway/router.js';
42
44
  import { consumeAdmissionReplyBudget, clearAdmissionReplyBudgets, evaluateInboundAdmissionPreflight, evaluateOrdinaryInboundAdmission, evaluateOwnerDirectoryInboundAdmission, } from './message-admission.js';
43
45
  const CONTACT_REJECTION_NOTICE = '[rejection] Not accepting messages from you.';
44
46
  const REJECTABLE_PEER_TYPES = new Set(['ai', 'bot', 'agent', 'service']);
45
47
  const REJECTION_MAX = 3;
46
48
  const REJECTION_WINDOW_MS = 60 * 60 * 1000;
47
49
  const rejectionState = new Map();
48
- /** Topic admission runs after session resolution and before task queueing. */
49
- function decideTopicInbound(input) {
50
+ /**
51
+ * Topic admission runs after session resolution and before task queueing.
52
+ *
53
+ * 纯函数,导出以便单测直接覆盖各状态组合(回退 / 丢弃 / 是否回文案)。
54
+ */
55
+ export function decideTopicInbound(input) {
50
56
  if (!input.isTopic)
51
57
  return { action: 'proceed', reopen: false, replyArchived: false };
52
58
  if (input.topicStatus === 'archived') {
@@ -99,6 +105,61 @@ export function clearContactRejectionRateLimits() {
99
105
  rejectionState.clear();
100
106
  clearAdmissionReplyBudgets();
101
107
  }
108
+ /**
109
+ * 网关的回复文本。
110
+ *
111
+ * 成功投递不回话——那时用户看到的是 Claude Code 终端里真正的输出。
112
+ * 主会话回会话列表;话题会话不在线时如实说明(不自动拉起)。
113
+ */
114
+ function gatewayNotice(result) {
115
+ switch (result.kind) {
116
+ case 'listing': {
117
+ const sessions = result.sessions ?? [];
118
+ if (sessions.length === 0) {
119
+ return '这台机器上还没有可用的 Claude Code 会话。\n\n'
120
+ + '发「新建」可以选一个项目目录,在那里开一个新会话。';
121
+ }
122
+ const lines = sessions.map((s, i) => {
123
+ const state = s.online ? (s.status ?? 'online') : '未运行';
124
+ const preview = s.lastMessage ? `\n ${s.lastMessage}` : '';
125
+ return `${i + 1}. ${s.title} (${state})${preview}`;
126
+ });
127
+ return `这台机器上的 Claude Code 会话:\n\n${lines.join('\n')}\n\n`
128
+ + '发序号或会话 ID 就能打开它(会带上之前的对话记录)。\n'
129
+ + '发「新建」可以在某个项目目录开一个新会话。';
130
+ }
131
+ case 'directory_listing': {
132
+ const directories = result.directories ?? [];
133
+ if (directories.length === 0) {
134
+ return '还没有记录到用过的项目目录。先在终端里用 Claude Code 打开一个目录,之后这里就能看到。';
135
+ }
136
+ const lines = directories.map((d, i) => `${i + 1}. ${d.path} (${d.sessionCount} 个会话)`);
137
+ return `用过的项目目录:\n\n${lines.join('\n')}\n\n发「新建 序号」就在那个目录开一个新会话。`;
138
+ }
139
+ case 'launched':
140
+ return result.alreadyOnline
141
+ ? `「${result.title}」正在运行,已经可以对话了。`
142
+ : `已打开「${result.title}」,之前的对话记录都在里面。`;
143
+ case 'new_session': {
144
+ const where = result.cwd;
145
+ if (result.bound) {
146
+ return `已在 ${where} 开好新会话,接下来的消息都会发给它。`;
147
+ }
148
+ if (result.sessionId) {
149
+ return `已在 ${where} 开好新会话(${result.sessionId.slice(0, 8)})。`
150
+ + '在话题里发「新建 序号」可以直接绑定它。';
151
+ }
152
+ return `窗口已在 ${where} 打开,但没等到会话上线——检查一下那个终端里的提示。`;
153
+ }
154
+ case 'offline':
155
+ return `这个会话目前没有运行(${result.title ?? result.sessionId?.slice(0, 8) ?? '未知'})。`
156
+ + '在终端里重新打开它之后,消息才会送达。';
157
+ case 'unbound':
158
+ return result.message ?? '该话题尚未绑定 Claude Code 会话。';
159
+ default:
160
+ return result.message ?? '网关处理失败。';
161
+ }
162
+ }
102
163
  /**
103
164
  * MessageBridge — Channel 与 Core 之间的消息桥梁
104
165
  *
@@ -254,8 +315,8 @@ export class MessageBridge {
254
315
  }
255
316
  /**
256
317
  * Handle AUN's two slash-bind forms: bare `/bind` requests protocol
257
- * ownership from the first configured Owner; `/bind <channel>` creates an
258
- * external-channel contact mapping.
318
+ * ownership on behalf of the sending Daemon Owner; `/bind <channel>` creates
319
+ * an external-channel contact mapping.
259
320
  */
260
321
  async handleAunBindCommand(input) {
261
322
  const match = /^\s*\/bind(?:\s+(.+?))?\s*$/i.exec(input.content);
@@ -279,9 +340,11 @@ export class MessageBridge {
279
340
  }
280
341
  const args = String(match[1] || '').trim().split(/\s+/).filter(Boolean);
281
342
  if (args.length === 0) {
282
- const configuredOwner = ownerResolver.configuredOwnerList(selfAid)[0];
283
- if (configuredOwner !== actorId) {
284
- return { handled: true, status: 'not-first-owner', reply: '仅兼容绑定目标中的首个 AID 可在 AUN 私聊发送 /bind 发起 ownership 绑定。' };
343
+ // Ownership is granted by the protocol, never by a configured field. An
344
+ // unbound Agent therefore has no Owner to name here, so only the host
345
+ // Daemon Owner may nominate itself as the binding target.
346
+ if (!ownerResolver.daemonOwners().includes(actorId)) {
347
+ return { handled: true, status: 'not-daemon-owner', reply: '当前 Agent 尚未绑定协议 Owner。纯 /bind 仅接受本机 Daemon Owner 发起;其它 AID 请由 Daemon Owner 在宿主端为该 Agent 指定绑定目标。' };
285
348
  }
286
349
  try {
287
350
  const current = await ownerResolver.refresh(selfAid, { force: true });
@@ -553,6 +616,19 @@ export class MessageBridge {
553
616
  register(channelName, onMessage, sendReply, adapter, channelType) {
554
617
  const effectiveChannelType = channelType || channelName;
555
618
  onMessage(async (msg) => {
619
+ const contactDelivery = trustedContactInboundDelivery(msg.contactDelivery);
620
+ const logInbound = contactDelivery
621
+ ? (dir, entry) => appendInboundMessageLogOnce(dir, entry, `contact-inbound-${contactDelivery.key}`)
622
+ : appendMessageLog;
623
+ let contactFailed = false;
624
+ if (contactDelivery) {
625
+ const receipt = this.messageQueue.contactDeliveryReceipt(contactDelivery.key);
626
+ if (receipt) {
627
+ contactDelivery.receipt = receipt;
628
+ return;
629
+ }
630
+ contactDelivery.validate();
631
+ }
556
632
  let releaseAdmission;
557
633
  let releaseSessionIngress;
558
634
  const releaseIngress = () => {
@@ -587,6 +663,10 @@ export class MessageBridge {
587
663
  const menuControl = resolvedChannelType === 'aun'
588
664
  ? parseMenuControl(content)
589
665
  : { isMenu: false };
666
+ if (menuControl.isMenu) {
667
+ Object.assign(msg, menuTiming);
668
+ this.logMenuInbound(channelName, msg, menuControl);
669
+ }
590
670
  const isPrivateMenuTokenRequest = menuControl.isMenu
591
671
  && menuControl.type === 'menu.token.request'
592
672
  && chatType === 'private';
@@ -605,10 +685,10 @@ export class MessageBridge {
605
685
  // a sender against an expired or invalidated ownership cache.
606
686
  const ownership = ownerResolver.snapshot(selfAid);
607
687
  if (ownership.connected || ownership.relation) {
608
- await ownerResolver.refresh(selfAid, {
688
+ await traceMenuStage(menuControl.isMenu ? menuControl.request : undefined, this.menuFlowContext(channelName, msg), menuTiming, 'bridge.ownership', () => ownerResolver.refresh(selfAid, {
609
689
  maxAgeMs: OWNERSHIP_CACHE_MAX_AGE_MS,
610
690
  allowTransient: true,
611
- });
691
+ }));
612
692
  }
613
693
  }
614
694
  const admissionPreflight = evaluateInboundAdmissionPreflight({
@@ -680,6 +760,8 @@ export class MessageBridge {
680
760
  return;
681
761
  }
682
762
  if (!trustedHandoffEcho && selfAid && actorId && this.groupInviteReviewService) {
763
+ if (contactDelivery && /^\s*\/invites(?:\s|$)/i.test(content))
764
+ contactDelivery.startCommand();
683
765
  const inviteCommand = await this.groupInviteReviewService.handleCommand({
684
766
  selfAid,
685
767
  ownerAid: actorId,
@@ -743,10 +825,6 @@ export class MessageBridge {
743
825
  });
744
826
  return;
745
827
  }
746
- // AUN captures this mark at its adapter boundary. Legacy/test
747
- // adapters fall back to the bridge entry mark captured above.
748
- Object.assign(msg, menuTiming);
749
- this.logMenuInbound(channelName, msg, menuControl);
750
828
  if (!hasValidMenuId(menuControl)) {
751
829
  this.logMenuDiagnostic('missing-id', channelName, msg, menuControl);
752
830
  logMenuRequestCompleted(menuControl.request, undefined, this.menuFlowContext(channelName, msg), {
@@ -865,6 +943,46 @@ export class MessageBridge {
865
943
  await this.sendAccessDenied(adapter, channelName, msg, sendReply);
866
944
  return;
867
945
  }
946
+ // ccagent:消息不进 baseagent、不跑模型,直接投递到绑定的 Claude Code 会话。
947
+ // AID 从 defaults.json 读,每台机器可能不同,所以按配置判断而不是写死常量。
948
+ if (isCcAgentAid(selfAid)) {
949
+ try {
950
+ const authorizeGateway = async () => {
951
+ if (resolvedChannelType !== 'aun' || chatType !== 'private' || msg.encrypted !== true || !msg.peerDeviceId)
952
+ return false;
953
+ await refreshOwnershipForAuthorization(selfAid, { includeDaemon: true, allowTransient: false, maxAgeMs: 30_000, source: 'claude-gateway' });
954
+ const binding = verifiedContactBinding(selfAid, ownerResolver.snapshot(selfAid));
955
+ const daemonAid = ownerResolver.getDaemonAid();
956
+ return !!binding && binding.owner_aid === actorId && !!daemonAid
957
+ && ownerResolver.protocolOwners(daemonAid).includes(actorId ?? '');
958
+ };
959
+ if (!await authorizeGateway()) {
960
+ await sendReply(msg.channelId, 'Claude 网关仅接受同时拥有本机与网关的 Owner 通过加密设备私聊操作。', msg.replyContext);
961
+ return;
962
+ }
963
+ const routed = await routeToGateway(selfAid, {
964
+ from: actorId ?? '',
965
+ fromName: msg.peerName,
966
+ threadId: msg.threadId,
967
+ content,
968
+ ownerBinding: currentContactBinding(selfAid),
969
+ deviceId: msg.peerDeviceId,
970
+ authorize: authorizeGateway,
971
+ sendOutput: text => sendReply(msg.channelId, text, { ...msg.replyContext,
972
+ metadata: { ...msg.replyContext?.metadata, encrypted: true }, toDeviceId: msg.peerDeviceId }),
973
+ });
974
+ if (routed.kind === 'delivered') {
975
+ // 已经写进对方会话,回复由那边的输出驱动,这里不再回话。
976
+ return;
977
+ }
978
+ await sendReply(msg.channelId, gatewayNotice(routed), msg.replyContext);
979
+ }
980
+ catch (error) {
981
+ logger.warn(`[MessageBridge] 网关路由失败: ${error instanceof Error ? error.message : String(error)}`);
982
+ await sendReply(msg.channelId, '网关处理失败,请稍后重试。', msg.replyContext);
983
+ }
984
+ return;
985
+ }
868
986
  // Diagnostic invitations carry their own execution boundary. Resolve
869
987
  // that boundary before ordinary command/session routing so a new case
870
988
  // cannot inherit an older Codex thread.
@@ -1041,7 +1159,7 @@ export class MessageBridge {
1041
1159
  const inboundReplyTo = typeof msg.replyContext?.metadata?.refMessageId === 'string'
1042
1160
  ? msg.replyContext.metadata.refMessageId
1043
1161
  : null;
1044
- appendMessageLog(chatDir, buildInboundEntry({
1162
+ logInbound(chatDir, buildInboundEntry({
1045
1163
  from: msg.peerId || 'unknown',
1046
1164
  to: msg.selfAID || 'self',
1047
1165
  threadId: msg.threadId ?? '',
@@ -1067,6 +1185,8 @@ export class MessageBridge {
1067
1185
  logger.debug(`[MessageBridge] Failed to log inbound command: ${e}`);
1068
1186
  }
1069
1187
  }
1188
+ if (contactDelivery && isCmd)
1189
+ contactDelivery.startCommand();
1070
1190
  if (msg.source !== 'handoff'
1071
1191
  && !executionPermissionOverride
1072
1192
  && await this.handleCommand(cmdContent, channelName, msg.channelId, (text) => {
@@ -1075,6 +1195,10 @@ export class MessageBridge {
1075
1195
  return sendReply(msg.channelId, text, msg.replyContext);
1076
1196
  }, msg.peerId, msg.threadId, msg.chatType, msg.source, msg.replyContext, msg.messageId, msg.selfAID, authSubject))
1077
1197
  return;
1198
+ // A quick-command prefix may be unknown to the handler and fall through
1199
+ // to model input. No command ran, so a failed queue commit may retry it.
1200
+ if (contactDelivery && isCmd)
1201
+ contactDelivery.cancelCommand?.();
1078
1202
  // 3. session 解析(使用 Channel 层填充的 chatType)
1079
1203
  if (!(await this.canCreateThreadSession(channelName, msg, chatType))) {
1080
1204
  // 静默丢弃:绝不向群里注入回复。
@@ -1185,7 +1309,15 @@ export class MessageBridge {
1185
1309
  if (!releaseAdmission)
1186
1310
  releaseAdmission = await this.acquireAdmission(admissionRoute);
1187
1311
  const hadMainSession = msg.threadId ? true : this.sessionManager.hasMainSession(channelName, msg.channelId, msg.channelType || effectiveChannelType, msg.selfAID || selfAid);
1188
- let session = diagnosticSession ?? await this.sessionManager.getOrCreateSession(channelName, msg.channelId, effectiveProjectPath, msg.threadId, Object.keys(metadata).length ? metadata : undefined, this.extractTopicName(msg), msg.peerId, chatType, owningAgent?.baseagent, msg.selfAID, msg.channelType || effectiveChannelType, msg.peerType, identity, readTopicStatus(msg) ?? readTopicStatus(msg.replyContext?.metadata));
1312
+ const boundContactSession = contactDelivery?.sessionId
1313
+ ? await this.sessionManager.getSessionById(contactDelivery.sessionId) : undefined;
1314
+ if (contactDelivery?.sessionId && (!boundContactSession || boundContactSession.selfAID !== selfAid
1315
+ || boundContactSession.channelId !== msg.channelId
1316
+ || (sessionTopicThreadId(boundContactSession) ?? '') !== (isTopicThreadId(msg.threadId) ? msg.threadId : '')))
1317
+ throw new Error('contact replay bound session is unavailable');
1318
+ if (boundContactSession)
1319
+ boundContactSession.identity = identity;
1320
+ let session = boundContactSession ?? diagnosticSession ?? await this.sessionManager.getOrCreateSession(channelName, msg.channelId, effectiveProjectPath, msg.threadId, Object.keys(metadata).length ? metadata : undefined, this.extractTopicName(msg), msg.peerId, chatType, owningAgent?.baseagent, msg.selfAID, msg.channelType || effectiveChannelType, msg.peerType, identity, readTopicStatus(msg) ?? readTopicStatus(msg.replyContext?.metadata));
1189
1321
  // 归档话题不再入队;closed 收到新消息时回退 active,主话题不受此状态影响。
1190
1322
  const topicGate = decideTopicInbound({
1191
1323
  isTopic: isTopicSession(session),
@@ -1226,7 +1358,7 @@ export class MessageBridge {
1226
1358
  const inboundCausation = restoredCausation
1227
1359
  ? deriveCausation(restoredCausation)
1228
1360
  : createRootCausation();
1229
- const renewResult = session.metadata?.diagnostic ? { session } : await this.sessionRenewService.resolve({
1361
+ const renewResult = session.metadata?.diagnostic || boundContactSession ? { session } : await this.sessionRenewService.resolve({
1230
1362
  session,
1231
1363
  channelName,
1232
1364
  channelType: msg.channelType || effectiveChannelType,
@@ -1243,6 +1375,8 @@ export class MessageBridge {
1243
1375
  causation: inboundCausation,
1244
1376
  });
1245
1377
  session = renewResult.session;
1378
+ if (contactDelivery)
1379
+ contactDelivery.bindSession(session.id);
1246
1380
  if (!executionPermissionOverride && selfAid && owningAgent?.aid === selfAid) {
1247
1381
  executionPermissionOverride = createAgentPolicyAuthorization({
1248
1382
  agentAid: selfAid, actor: roleDetail.actor, chatType,
@@ -1426,7 +1560,7 @@ export class MessageBridge {
1426
1560
  }
1427
1561
  }
1428
1562
  if (!handoffCandidate)
1429
- appendMessageLog(inboundEntry.chatDir, inboundEntry.entry);
1563
+ logInbound(inboundEntry.chatDir, inboundEntry.entry);
1430
1564
  if (autoResult && autoResult.batch.length > 1) {
1431
1565
  for (const item of autoResult.batch.slice(0, -1)) {
1432
1566
  const member = item.value;
@@ -1461,20 +1595,24 @@ export class MessageBridge {
1461
1595
  if (fullMessage.messageId && currentSessionBusy) {
1462
1596
  adapter?.acknowledge?.(fullMessage.messageId).catch(() => { });
1463
1597
  }
1464
- const isInterrupt = chatType !== 'group' && !handoffCandidate;
1465
- const attentionPolicy = fullMessage.attentionPolicy;
1598
+ const isInterrupt = chatType !== 'group' && !handoffCandidate && !contactDelivery;
1599
+ const attentionPolicy = contactDelivery ? 'defer' : fullMessage.attentionPolicy;
1466
1600
  const shouldInterrupt = isInterrupt || attentionPolicy === 'interrupt';
1467
1601
  const enqueueAgentName = owningAgent?.name ?? '<unknown>';
1468
1602
  const selfAID = session.selfAID;
1469
1603
  const doEnqueue = async (m) => {
1470
1604
  // A cancellation can arrive while this message is being debounced.
1471
- if (!isDiagnosticSessionActive(session, this.sessionManager.getChatDir(session)))
1605
+ if (!isDiagnosticSessionActive(session, this.sessionManager.getChatDir(session))) {
1606
+ if (contactDelivery)
1607
+ throw new Error('contact replay session is no longer active');
1472
1608
  return;
1473
- const enqueue = handoffCandidate ? this.messageQueue.enqueuePersisted.bind(this.messageQueue) : this.messageQueue.enqueue.bind(this.messageQueue);
1609
+ }
1610
+ const enqueue = handoffCandidate || contactDelivery ? this.messageQueue.enqueuePersisted.bind(this.messageQueue) : this.messageQueue.enqueue.bind(this.messageQueue);
1474
1611
  try {
1475
1612
  return await enqueue(session.id, m, session.projectPath, {
1476
1613
  interruptible: shouldInterrupt,
1477
1614
  attentionPolicy,
1615
+ contactDelivery,
1478
1616
  interruptSamePeer: !shouldInterrupt && !attentionPolicy, // 旧群聊路径保留同人连发打断
1479
1617
  priority: attentionPolicy === 'interrupt',
1480
1618
  agentName: enqueueAgentName,
@@ -1497,7 +1635,7 @@ export class MessageBridge {
1497
1635
  throw error;
1498
1636
  }
1499
1637
  };
1500
- if (handoffCandidate) {
1638
+ if (handoffCandidate || contactDelivery) {
1501
1639
  await doEnqueue(fullMessage);
1502
1640
  }
1503
1641
  else if (isInterrupt) {
@@ -1516,6 +1654,7 @@ export class MessageBridge {
1516
1654
  }
1517
1655
  }
1518
1656
  catch (error) {
1657
+ contactFailed = true;
1519
1658
  if (isRetryableMenuTransportError(error)) {
1520
1659
  logger.warn(`[MessageBridge] Retryable response delivery unavailable for ${channelName}:`, error);
1521
1660
  }
@@ -1525,9 +1664,18 @@ export class MessageBridge {
1525
1664
  finally {
1526
1665
  releaseAdmission?.();
1527
1666
  releaseIngress();
1667
+ if (contactDelivery && !contactFailed && !contactDelivery.receipt) {
1668
+ this.messageQueue.finishContactDelivery(contactDelivery);
1669
+ }
1528
1670
  }
1529
1671
  });
1530
1672
  }
1673
+ contactDeliveryReceipt(key) {
1674
+ return this.messageQueue.contactDeliveryReceipt(key);
1675
+ }
1676
+ finishContactDelivery(delivery) {
1677
+ this.messageQueue.finishContactDelivery(delivery);
1678
+ }
1531
1679
  async acquireAdmission(key) {
1532
1680
  const previous = this.admissionLocks.get(key) ?? Promise.resolve();
1533
1681
  let release;
@@ -1586,23 +1734,26 @@ export class MessageBridge {
1586
1734
  // Menu IDs are the protocol's stable correlation key. Bind it, together
1587
1735
  // with the active EvolCore session, before authorization so every
1588
1736
  // CommandAudit record and denial can be joined to the same request.
1589
- let activeSession;
1590
- if (msg.threadId && typeof this.sessionManager.getThreadSession === 'function') {
1591
- try {
1592
- activeSession = await this.sessionManager.getThreadSession(channel, msg.channelId, msg.threadId);
1593
- }
1594
- catch {
1595
- activeSession = undefined;
1596
- }
1597
- }
1598
- if (!activeSession && typeof this.sessionManager.getActiveSession === 'function') {
1599
- try {
1600
- activeSession = await this.sessionManager.getActiveSession(channel, msg.channelId);
1737
+ const activeSession = await traceMenuStage(parsed.request, this.menuFlowContext(channel, msg), msg, 'menu.context', async () => {
1738
+ let session;
1739
+ if (msg.threadId && typeof this.sessionManager.getThreadSession === 'function') {
1740
+ try {
1741
+ session = await this.sessionManager.getThreadSession(channel, msg.channelId, msg.threadId);
1742
+ }
1743
+ catch {
1744
+ session = undefined;
1745
+ }
1601
1746
  }
1602
- catch {
1603
- activeSession = undefined;
1747
+ if (!session && typeof this.sessionManager.getActiveSession === 'function') {
1748
+ try {
1749
+ session = await this.sessionManager.getActiveSession(channel, msg.channelId);
1750
+ }
1751
+ catch {
1752
+ session = undefined;
1753
+ }
1604
1754
  }
1605
- }
1755
+ return session;
1756
+ });
1606
1757
  const menuAuthSubject = {
1607
1758
  ...authSubject,
1608
1759
  requestId: parsed.id,
@@ -1656,9 +1807,9 @@ export class MessageBridge {
1656
1807
  const dedupKey = [msg.selfAID || channel, channelType, msg.chatType || 'private', scope, msg.peerId,
1657
1808
  msg.peerDeviceId || '', msg.peerSlotId || '', msg.threadId || '', parsed.id].join('\u001f');
1658
1809
  let afterResponse;
1659
- const deduped = await this.menuDeduper.execute(dedupKey, menuPayloadFingerprint(parsed.raw), () => isTokenRequest
1810
+ const deduped = await traceMenuStage(parsed.request, this.menuFlowContext(channel, msg), msg, 'menu.execute', () => this.menuDeduper.execute(dedupKey, menuPayloadFingerprint(parsed.raw), () => isTokenRequest
1660
1811
  ? this.issueMenuTokenResponse(header, channel, msg)
1661
- : this.dispatchMenuRequest(parsed.request, header, channel, msg, menuAuthSubject, effect => { afterResponse = effect; }));
1812
+ : this.dispatchMenuRequest(parsed.request, header, channel, msg, menuAuthSubject, effect => { afterResponse = effect; })));
1662
1813
  if ('conflict' in deduped) {
1663
1814
  this.logMenuDiagnostic('request-conflict', channel, msg, parsed, 'CONFLICT');
1664
1815
  await this.sendMenuResponse(adapter, channel, msg, menuFailure(header, {
@@ -1936,7 +2087,7 @@ export class MessageBridge {
1936
2087
  const deliveryTiming = beginMenuDeliveryTiming(msg);
1937
2088
  let deliveryOutcome;
1938
2089
  try {
1939
- await deliverMenuResponse(async () => {
2090
+ await traceMenuStage(request, flowContext, msg, 'menu.delivery', () => deliverMenuResponse(async () => {
1940
2091
  Object.assign(timedResponse, withMenuProcessingTime(timedResponse, msg));
1941
2092
  await adapter.send(envelope, { kind: 'custom', channelType: channel, payload: timedResponse });
1942
2093
  }, {
@@ -1964,7 +2115,7 @@ export class MessageBridge {
1964
2115
  },
1965
2116
  onRetry: (attempt, error, delay) => logMenuResponseRetry(request, flowContext, attempt, delay, error),
1966
2117
  onComplete: outcome => { deliveryOutcome = outcome; },
1967
- });
2118
+ }));
1968
2119
  logMenuRequestCompleted(request, timedResponse, flowContext, { delivery: 'sent', ...deliveryOutcome, ...deliveryTiming() });
1969
2120
  const upgradeData = 'data' in response ? response.data : undefined;
1970
2121
  if (request.type === 'menu.action' && request.action === 'upgrade' && (request.name === 'system' || request.cmd === '/system') && upgradeData?.jobId) {
@@ -2219,6 +2370,7 @@ export class MessageBridge {
2219
2370
  }
2220
2371
  /** 清理资源 */
2221
2372
  dispose() {
2373
+ stopGatewayOutputs();
2222
2374
  for (const d of this.debouncers.values())
2223
2375
  d.dispose();
2224
2376
  this.debouncers.clear();
@@ -34,6 +34,8 @@ const KNOWN_AUN_PAYLOAD_TYPES = new Set([
34
34
  'link',
35
35
  'action_card',
36
36
  'action_card_reply',
37
+ 'widget_card',
38
+ 'widget_card_reply',
37
39
  'merge',
38
40
  'personal_card',
39
41
  'status',
@@ -103,6 +105,9 @@ export function classifyAunPayloadForLog(payload) {
103
105
  if (record.type === 'action_card_reply') {
104
106
  return { msgType: 'action_card_reply', payloadType: 'action_card_reply', content: '[卡片回复]' };
105
107
  }
108
+ if (record.type === 'widget_card_reply') {
109
+ return { msgType: 'widget_card_reply', payloadType: 'widget_card_reply', content: '[WidgetCard 回复]' };
110
+ }
106
111
  const rawType = typeof record.type === 'string' && record.type.trim()
107
112
  ? record.type.trim()
108
113
  : undefined;
@@ -156,9 +161,11 @@ export function classifyAunPayloadForLog(payload) {
156
161
  content = prefixedPayloadSummary('link', title ?? url ?? text);
157
162
  break;
158
163
  case 'action_card':
164
+ case 'widget_card':
159
165
  content = prefixedPayloadSummary('card', title ?? text);
160
166
  break;
161
167
  case 'action_card_reply':
168
+ case 'widget_card_reply':
162
169
  content = firstPayloadString(record, ['text', 'action_value', 'value', 'action_label', 'label']) ?? '[action_card_reply]';
163
170
  break;
164
171
  case 'merge':
@@ -334,6 +341,30 @@ export function appendMessageLog(chatDir, entry) {
334
341
  }
335
342
  notifyInbound(chatDir, entry);
336
343
  }
344
+ /** Durable replay history deduplication across daemon restarts. */
345
+ export function appendInboundMessageLogOnce(chatDir, entry, operationId) {
346
+ const file = messageLogPath(chatDir);
347
+ let lines = [];
348
+ try {
349
+ lines = fs.readFileSync(file, 'utf8').split('\n');
350
+ }
351
+ catch (error) {
352
+ if (error.code !== 'ENOENT')
353
+ throw error;
354
+ }
355
+ for (const line of lines) {
356
+ let previous;
357
+ try {
358
+ previous = JSON.parse(line);
359
+ }
360
+ catch {
361
+ continue;
362
+ }
363
+ if (previous.dir === 'in' && previous.operationId === operationId)
364
+ return;
365
+ }
366
+ appendMessageLogStrict(chatDir, { ...entry, operationId }, true);
367
+ }
337
368
  /** Strict conversation-history append used by handoff reply binding. */
338
369
  export function appendMessageLogStrict(chatDir, entry, durable = false) {
339
370
  if (isTransientProtocolMessage(entry))
@@ -422,6 +453,7 @@ export function buildInboundEntry(opts) {
422
453
  payloadSummary: opts.payloadSummary,
423
454
  groupAttention: opts.groupAttention,
424
455
  groupDelivery: opts.groupDelivery,
456
+ privateAttention: opts.privateAttention,
425
457
  attentionDecision: opts.attentionDecision,
426
458
  content: opts.content,
427
459
  replyTo: opts.replyTo ?? null,