evolcore 0.0.41-test.0 → 0.0.41-test.2

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 (235) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/dist/agents/baseagent-availability.js +1 -1
  3. package/dist/agents/baseagent.js +88 -49
  4. package/dist/agents/claude-runner.js +177 -92
  5. package/dist/agents/codex-runner.js +146 -71
  6. package/dist/agents/ecagent-runner.js +1 -1
  7. package/dist/agents/gemini-runner.js +1 -1
  8. package/dist/aun/aid/agentmd.js +98 -11
  9. package/dist/aun/aid/client.js +1 -1
  10. package/dist/aun/aid/control-aid.js +26 -2
  11. package/dist/aun/aid/identity.js +91 -0
  12. package/dist/aun/aid/index.js +1 -1
  13. package/dist/aun/aid/managed-operation.js +1 -1
  14. package/dist/aun/aid/ownership-operation.js +23 -22
  15. package/dist/aun/group/fs-download.js +39 -0
  16. package/dist/aun/group/identity.js +36 -21
  17. package/dist/aun/group/operations.js +5 -0
  18. package/dist/aun/menu/client.js +27 -0
  19. package/dist/aun/msg/managed-operation.js +68 -7
  20. package/dist/aun/msg/p2p.js +8 -8
  21. package/dist/aun/service-proxy.js +53 -12
  22. package/dist/channels/aun.js +633 -32
  23. package/dist/channels/daemon.js +15 -1
  24. package/dist/cli/agent-command.js +5 -2
  25. package/dist/cli/agent-create.js +991 -233
  26. package/dist/cli/agent.js +49 -10
  27. package/dist/cli/aid-bind-command.js +48 -19
  28. package/dist/cli/aun-commands.js +48 -36
  29. package/dist/cli/daemon-commands.js +679 -697
  30. package/dist/cli/fs-command.js +64 -2
  31. package/dist/cli/index.js +72 -5
  32. package/dist/cli/init-channel.js +1 -1
  33. package/dist/cli/init.js +75 -1
  34. package/dist/cli/managed-command-guard.js +17 -1
  35. package/dist/cli/model.js +40 -40
  36. package/dist/cli/provider-command.js +57 -0
  37. package/dist/cli/proxy-command.js +92 -0
  38. package/dist/cli/restart-monitor.js +4 -2
  39. package/dist/cli/role.js +85 -0
  40. package/dist/cli/stats.js +10 -3
  41. package/dist/cli/task-context.js +19 -0
  42. package/dist/config/access-policy.js +7 -2
  43. package/dist/config/boot-log.js +39 -1
  44. package/dist/config/config-field-policy.js +17 -39
  45. package/dist/config/config-manager.js +183 -44
  46. package/dist/config/config-operation-service.js +5 -19
  47. package/dist/config/contact-book-store.js +47 -21
  48. package/dist/config/contact-book.js +18 -12
  49. package/dist/config/contact-operation-service.js +3 -4
  50. package/dist/config/contact-request-service.js +11 -0
  51. package/dist/config/daemon-services.js +11 -0
  52. package/dist/config/gateway-config.js +88 -594
  53. package/dist/config/owner-config.js +2 -2
  54. package/dist/config/peer-role-resolver.js +15 -12
  55. package/dist/config/provider-ipc-service.js +132 -0
  56. package/dist/config/provider-menu-request.js +58 -0
  57. package/dist/config/providers-config.js +12 -7
  58. package/dist/config/providers-import.js +3 -21
  59. package/dist/config/providers-management.js +78 -5
  60. package/dist/config/resolved-config-op.js +11 -1
  61. package/dist/config/role-command-service.js +166 -0
  62. package/dist/config/role-request-service.js +193 -0
  63. package/dist/config/schema-migration.js +1000 -25
  64. package/dist/config-store.js +89 -4
  65. package/dist/contracts/ecweb-instance.js +41 -0
  66. package/dist/contracts/ecweb-service-protocol.js +4 -1
  67. package/dist/core/agent-application-service.js +60 -11
  68. package/dist/core/agent-create-status.js +203 -0
  69. package/dist/core/agent-creation-claim.js +177 -0
  70. package/dist/core/agent-ipc-registration.js +39 -18
  71. package/dist/core/agent-runtime.js +194 -24
  72. package/dist/core/auth/agent-delegation.js +6 -3
  73. package/dist/core/auth/auth-gateway.js +67 -2
  74. package/dist/core/auth/authorization-audit.js +58 -11
  75. package/dist/core/auth/delegation-authorization.js +5 -2
  76. package/dist/core/auth/operation-authorizer.js +43 -6
  77. package/dist/core/auth/operation-catalog.js +45 -7
  78. package/dist/core/channel-loader.js +2 -0
  79. package/dist/core/command/agent-control.js +260 -21
  80. package/dist/core/command/agent-storage-menu.js +5 -3
  81. package/dist/core/command/cli-intent-parser.js +8 -3
  82. package/dist/core/command/command-handler.js +112 -154
  83. package/dist/core/command/connect-menu.js +11 -3
  84. package/dist/core/command/data-root-resolver.js +5 -4
  85. package/dist/core/command/memory-slash.js +16 -8
  86. package/dist/core/command/menu-catalog.js +10 -6
  87. package/dist/core/command/menu-handler.js +106 -73
  88. package/dist/core/command/menu-protocol.js +15 -1
  89. package/dist/core/command/provider-menu.js +46 -0
  90. package/dist/core/command/role-menu.js +147 -30
  91. package/dist/core/command/slash-handler.js +125 -255
  92. package/dist/core/daemon-control.js +26 -27
  93. package/dist/core/event-catalog.js +10 -0
  94. package/dist/core/evolagent-registry.js +7 -5
  95. package/dist/core/evolagent.js +10 -8
  96. package/dist/core/file-integrity/store.js +11 -0
  97. package/dist/core/handoff/ipc-registration.js +3 -0
  98. package/dist/core/inference/text-inference.js +31 -40
  99. package/dist/core/initialization/service.js +491 -0
  100. package/dist/core/ipc-registration.js +40 -24
  101. package/dist/core/memory/consolidation-context.js +51 -5
  102. package/dist/core/memory/consolidation-ops-records.js +96 -1
  103. package/dist/core/memory/consolidation-trigger.js +208 -191
  104. package/dist/core/memory/consolidation.js +333 -35
  105. package/dist/core/memory/index-manager.js +27 -5
  106. package/dist/core/memory/memory-admin.js +45 -5
  107. package/dist/core/memory/memory-writer.js +163 -18
  108. package/dist/core/memory/relation-idle-monitor.js +119 -58
  109. package/dist/core/memory/relation-sweep.js +55 -45
  110. package/dist/core/message/aun-ipc-sender.js +81 -69
  111. package/dist/core/message/im-renderer.js +25 -4
  112. package/dist/core/message/message-admission.js +89 -4
  113. package/dist/core/message/message-bridge.js +66 -21
  114. package/dist/core/message/response-engine.js +108 -35
  115. package/dist/core/model/catalog-service.js +5 -3
  116. package/dist/core/model/config-scope.js +29 -71
  117. package/dist/core/model/field-scope.js +1 -1
  118. package/dist/core/model/model-catalog.js +30 -41
  119. package/dist/core/model/model-diagnostics.js +4 -3
  120. package/dist/core/model/model-fallback.js +10 -7
  121. package/dist/core/model/model-permission.js +3 -2
  122. package/dist/core/ownership/owner-resolver.js +772 -158
  123. package/dist/core/permission/approval-gateway.js +103 -403
  124. package/dist/core/permission/ec-command-parser.js +62 -6
  125. package/dist/core/permission/index.js +1 -0
  126. package/dist/core/permission/permission-result.js +78 -0
  127. package/dist/core/permission/sandbox-runtime.js +18 -1
  128. package/dist/core/permission/tool-policy.js +21 -46
  129. package/dist/core/relation/peer-identity.js +64 -1
  130. package/dist/core/role/runtime-policy.js +72 -13
  131. package/dist/core/session/session-capsule.js +1 -1
  132. package/dist/core/session/session-idle-monitor.js +1 -1
  133. package/dist/core/session/session-manager.js +20 -0
  134. package/dist/core/session/session-renew.js +3 -3
  135. package/dist/core/skill/index-generator.js +15 -5
  136. package/dist/core/system-session/memory.js +43 -8
  137. package/dist/core/thread/thread-service.js +19 -6
  138. package/dist/directory/owner-directory-admission.js +95 -0
  139. package/dist/directory/owner-directory-authorization.js +309 -0
  140. package/dist/directory/owner-directory-cache.js +635 -0
  141. package/dist/eck/kit-renderer.js +2 -2
  142. package/dist/ecweb/basic-settings-service.js +33 -40
  143. package/dist/ecweb/init-menu.js +32 -0
  144. package/dist/ecweb/message-context-service.js +110 -0
  145. package/dist/index.js +93 -19
  146. package/dist/ipc.js +247 -29
  147. package/dist/paths.js +7 -0
  148. package/dist/proxy/command.js +122 -0
  149. package/dist/proxy/ipc-service.js +68 -0
  150. package/dist/proxy/manager.js +484 -0
  151. package/dist/proxy/service-supervisor.js +603 -0
  152. package/dist/response-system/engines/v1/proactive-flow.js +16 -6
  153. package/dist/trigger/authorization.js +27 -17
  154. package/dist/trigger/feedback.js +2 -3
  155. package/dist/trigger/ipc-service.js +105 -78
  156. package/dist/trigger/local-files.js +2 -1
  157. package/dist/trigger/manager.js +5 -3
  158. package/dist/trigger/scheduler.js +88 -6
  159. package/dist/utils/atomic-write.js +28 -0
  160. package/dist/utils/cross-platform.js +14 -0
  161. package/dist/utils/ecweb-supervisor.js +258 -83
  162. package/dist/utils/error-utils.js +26 -2
  163. package/dist/utils/logger.js +92 -6
  164. package/dist/utils/package-version-info.js +4 -2
  165. package/dist/utils/welcome.js +1 -1
  166. package/kits/docs/INDEX.md +1 -0
  167. package/kits/docs/aun/SDK.md +4 -1
  168. package/kits/docs/channels/aun.md +9 -0
  169. package/kits/docs/evolcore/INDEX.md +1 -0
  170. package/kits/docs/evolcore/agent.md +8 -1
  171. package/kits/docs/evolcore/aid.md +67 -17
  172. package/kits/docs/evolcore/config.md +28 -7
  173. package/kits/docs/evolcore/contact.md +3 -0
  174. package/kits/docs/evolcore/fs.md +11 -0
  175. package/kits/docs/evolcore/group.md +1 -1
  176. package/kits/docs/evolcore/memory-architecture.md +2 -2
  177. package/kits/docs/evolcore/memory-consolidation.md +32 -8
  178. package/kits/docs/evolcore/memory.md +1 -1
  179. package/kits/docs/evolcore/menu-protocol.md +4 -0
  180. package/kits/docs/evolcore/model.md +23 -20
  181. package/kits/docs/evolcore/msg.md +4 -7
  182. package/kits/docs/evolcore/provider.md +50 -0
  183. package/kits/docs/identity/AID_PROFILE_SPEC.md +52 -17
  184. package/kits/migrations/migrate-contact-book-v2.mjs +30 -11
  185. package/kits/rules/01-overview.md +3 -0
  186. package/kits/rules/04-relation.md +1 -1
  187. package/kits/schemas/_meta.json +37 -4
  188. package/kits/schemas/agent-config.schema.13.json +8 -3
  189. package/kits/schemas/agent-config.schema.16.json +891 -0
  190. package/kits/schemas/daemon.schema.9.json +366 -0
  191. package/kits/schemas/defaults.schema.5.json +406 -127
  192. package/kits/schemas/relation-config.schema.11.json +277 -0
  193. package/kits/schemas/role-config.schema.1.json +7 -7
  194. package/kits/skills/.switches.json +4 -0
  195. package/kits/skills/ec-agent-create/SKILL.md +3 -0
  196. package/kits/skills/ec-identity/SKILL.md +2 -2
  197. package/kits/skills/ec-service-proxy/SKILL.md +118 -0
  198. package/kits/skills/ec-skill/scripts/skill.mjs +6 -0
  199. package/kits/skills/personal-assistant/SKILL.md +176 -0
  200. package/kits/skills/personal-assistant/references/01-workspace-spec.md +333 -0
  201. package/kits/skills/personal-assistant/references/02-bootstrap.md +205 -0
  202. package/kits/skills/personal-assistant/references/03-data-flow-and-gaps.md +177 -0
  203. package/kits/skills/personal-assistant/references/04-frontend-contract.md +439 -0
  204. package/kits/skills/personal-assistant/references/05-directory-reference.md +292 -0
  205. package/kits/skills/personal-assistant/references/06-render-config.md +350 -0
  206. package/kits/skills/personal-assistant/schema/workspace.schema.json +85 -0
  207. package/kits/skills/personal-assistant/schema/workspace.v1.json +66 -0
  208. package/kits/skills/personal-assistant/scripts/archive.mjs +154 -0
  209. package/kits/skills/personal-assistant/scripts/check.mjs +114 -0
  210. package/kits/skills/personal-assistant/scripts/index-rebuild.mjs +252 -0
  211. package/kits/skills/personal-assistant/scripts/ingest.mjs +344 -0
  212. package/kits/skills/personal-assistant/scripts/init.mjs +270 -0
  213. package/kits/skills/personal-assistant/scripts/lib/apply.mjs +92 -0
  214. package/kits/skills/personal-assistant/scripts/lib/schema.mjs +96 -0
  215. package/kits/skills/personal-assistant/scripts/lib/time.mjs +28 -0
  216. package/kits/skills/personal-assistant/scripts/migrate.mjs +172 -0
  217. package/kits/skills/personal-assistant/scripts/search.mjs +172 -0
  218. package/kits/skills/personal-assistant/scripts/verify.mjs +196 -0
  219. package/kits/skills/personal-assistant/templates/INDEX.md.tpl +24 -0
  220. package/kits/skills/personal-assistant/templates/README.md.tpl +108 -0
  221. package/kits/skills/personal-assistant/triggers/ingest-daily.json +23 -0
  222. package/kits/skills/personal-assistant/triggers/memory-consolidate.json +23 -0
  223. package/kits/skills/personal-assistant/triggers/report-daily.json +23 -0
  224. package/kits/skills/personal-assistant/triggers/report-weekly.json +23 -0
  225. package/kits/skills/thread-ops/SKILL.md +5 -0
  226. package/kits/templates/memory-consolidation/forget.md +19 -6
  227. package/kits/templates/memory-consolidation/notes.md +1 -1
  228. package/kits/templates/memory-consolidation/profile.md +2 -2
  229. package/kits/templates/memory-consolidation/promote.md +20 -3
  230. package/kits/templates/roles/member.json +8 -1
  231. package/kits/templates/system-fragments/baseagent.md +2 -2
  232. package/kits/templates/system-fragments/memory.md +4 -4
  233. package/kits/templates/system-fragments/venue.md +1 -1
  234. package/package.json +7 -3
  235. package/dist/core/message/create-status.js +0 -96
@@ -1,12 +1,12 @@
1
1
  import { resolveAunSendDevice } from '../../aun/ability-device-routing.js';
2
2
  import crypto from 'crypto';
3
- import { authorizeDelegatedAunMsgSend, } from '../auth/agent-delegation.js';
3
+ import { authorizeDelegatedAunMsgSend, delegationFailureDetailCode, hasTrustedFullAccessDelegation, } from '../auth/agent-delegation.js';
4
4
  import { formatChannelKey, tryParseChannelKey } from '../channel-loader.js';
5
5
  import { AUN_HANDOFF_MARKER_FIELD } from '../../channels/aun.js';
6
6
  import { classifyAunPayloadForLog } from './message-log.js';
7
7
  import { isValidAunDeliveryForChannel } from './outbound.js';
8
8
  import { isHClassPath } from '../permission/protected-paths.js';
9
- import { evaluateOutboundContactAdmission } from './message-admission.js';
9
+ import { ensureOutboundContactForSend, evaluateOutboundContactAdmission } from './message-admission.js';
10
10
  import { normalizeAunMentionEntries, withAunAttention } from '../../aun/msg/mention-schema.js';
11
11
  import { resolveManagedSendArgv } from '../../cli/aun-commands.js';
12
12
  import { readTriggerLocalFile, resolveAttachmentLocalPath } from '../../trigger/local-files.js';
@@ -17,6 +17,7 @@ import { isTopicThreadId, parseMainTopicId, safeFormatMainTopicId, sessionLocalT
17
17
  import { ThreadService } from '../thread/thread-service.js';
18
18
  import { getAunRequestRegistry, requestDiagnostics, requestTtlSeconds } from './aun-request-registry.js';
19
19
  import { parseJsonObjectArgument } from '../permission/ec-command-parser.js';
20
+ import { parsePeerKey } from '../relation/peer-identity.js';
20
21
  const TASK_ID_MESSAGE_PAYLOAD_TYPES = new Set(['text', 'link', 'image', 'video', 'voice', 'file']);
21
22
  /** payload.debug 只是诊断字段:取不到时照常发送,不带 debug。 */
22
23
  async function resolveOutboundDebug(resolver, sessionId) {
@@ -84,29 +85,12 @@ export function createAunHandoffSender(sessionManager, channelInstances, getOutb
84
85
  };
85
86
  }
86
87
  async function applyManagedCrossThreadSendEffects(input) {
87
- const originSessionId = input.runtime?.sessionId;
88
- if (!originSessionId)
89
- return { triggerError: 'origin session context unavailable' };
90
- const originPeer = input.runtime?.channelId || input.targetChannelId;
88
+ const originSessionId = input.grant.sessionId;
89
+ const originPeer = parsePeerKey(input.grant.peerKey).channelId;
91
90
  // 来源话题 id:话题用原 id;主话题用"本端+对端"拼出的规范 id(展示与持久化用)。
92
91
  const originThreadId = isTopicThreadId(input.runtime?.threadId)
93
92
  ? input.runtime.threadId
94
93
  : (safeFormatMainTopicId(input.selfAid, originPeer) ?? '');
95
- // origin 指向复查目标对端(A),而非触发本次发送的会话对端(C)。
96
- // authorizeTriggerExecution 根据 origin 对端的角色决定 trigger 能否执行;
97
- // B 周期性地向 A 发消息,应检查 A 对 B 的角色,而不是 C 对 B 的角色。
98
- const targetChatType = input.feedbackChatType ?? 'private';
99
- const origin = {
100
- channelKey: formatChannelKey({ type: 'aun', selfAID: input.selfAid, name: 'main' }),
101
- channelType: 'aun',
102
- channelId: input.targetChannelId,
103
- session: isTopicThreadId(input.targetThreadId) ? 'thread' : 'main',
104
- ...(isTopicThreadId(input.targetThreadId) ? { threadId: input.targetThreadId } : {}),
105
- peerId: input.targetChannelId,
106
- delivery: targetChatType === 'group'
107
- ? { chatType: 'group', groupId: input.targetChannelId }
108
- : { chatType: 'private' },
109
- };
110
94
  const triggerSeed = `${Date.now()}_${crypto.randomBytes(4).toString('hex')}`;
111
95
  const triggerId = `trig_${triggerSeed}`;
112
96
  const triggerName = `check-${targetTopicLabel(input.targetThreadId)}-from-${targetTopicLabel(originThreadId)}-${triggerSeed.split('_')[1]}`;
@@ -137,37 +121,33 @@ async function applyManagedCrossThreadSendEffects(input) {
137
121
  let createdTriggerId;
138
122
  let triggerError;
139
123
  try {
140
- const scheduler = input.triggerSchedulers.get(input.selfAid);
141
- if (!scheduler)
142
- throw new Error(`trigger scheduler not found for agent: ${input.selfAid}`);
124
+ if (!input.createCrossThreadReviewTrigger)
125
+ throw new Error('cross-thread Trigger authorization is unavailable');
143
126
  const { buildThreadCheckTrigger } = await import('../../cli/aun-commands.js');
144
- // 触发本次发送的会话对端(C):originPeer 已按 chatType 取对端 AID(私聊 peerId、群聊群 AID)。
145
- // 即使 origin 已改指向 A,C 也需要保留操作权(cancel/delete/list),
146
- // 所以显式写入 operatorPeers = [C, A]。
147
- const operatorPeers = [...new Set([originPeer, input.targetChannelId].filter((p) => !!p))];
148
- const definition = {
149
- ...buildThreadCheckTrigger({
150
- agentAid: input.selfAid,
151
- id: triggerId,
152
- name: triggerName,
153
- prompt,
154
- everyMs: input.durationMs,
155
- checkEvery: input.checkEveryLabel,
156
- channelKey: formatChannelKey({ type: 'aun', selfAID: input.selfAid, name: 'main' }),
157
- targetChannelId: input.targetChannelId,
158
- targetThreadId: input.targetThreadId,
159
- originThreadId,
160
- originPeer,
161
- origin,
162
- feedbackChatType: input.feedbackChatType,
163
- originalText: input.contentSummary,
164
- firstSentAt: input.timestamp,
165
- originThreadName,
166
- targetThreadName,
167
- }),
168
- operatorPeers,
169
- };
170
- createdTriggerId = scheduler.create(definition, [], { enable: true }).id;
127
+ const definition = buildThreadCheckTrigger({
128
+ agentAid: input.selfAid,
129
+ id: triggerId,
130
+ name: triggerName,
131
+ prompt,
132
+ everyMs: input.durationMs,
133
+ checkEvery: input.checkEveryLabel,
134
+ channelKey: formatChannelKey({ type: 'aun', selfAID: input.selfAid, name: 'main' }),
135
+ targetChannelId: input.targetChannelId,
136
+ targetThreadId: input.targetThreadId,
137
+ originThreadId,
138
+ originPeer,
139
+ feedbackChatType: input.feedbackChatType,
140
+ originalText: input.contentSummary,
141
+ firstSentAt: input.timestamp,
142
+ originThreadName,
143
+ targetThreadName,
144
+ });
145
+ const created = await input.createCrossThreadReviewTrigger({
146
+ agentAid: input.selfAid,
147
+ grant: input.grant,
148
+ definition,
149
+ });
150
+ createdTriggerId = created.id;
171
151
  }
172
152
  catch (error) {
173
153
  // 失败原因随发送回执返回给调用方:只打 daemon 日志时,CLI 照样显示"已投递",
@@ -207,7 +187,7 @@ function targetTopicLabel(topicId) {
207
187
  return topicId;
208
188
  return 'main';
209
189
  }
210
- export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegationRegistry, responseEngine, handoffRuntime, triggerSchedulers, sessionManager, }) {
190
+ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegationRegistry, responseEngine, handoffRuntime, sessionManager, createCrossThreadReviewTrigger, }) {
211
191
  ipcServer.setAunRequestGetExecutor(async (params) => {
212
192
  if (!params.sessionId || !params.delegationToken) {
213
193
  return { ok: false, code: 'DELEGATION_REQUIRED', error: 'Request queries require an active delegated session' };
@@ -247,7 +227,38 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
247
227
  let payloadFile;
248
228
  try {
249
229
  if (params.argv !== undefined) {
250
- const command = resolveManagedSendArgv(params.argv);
230
+ if (!params.delegationCommandHash) {
231
+ return {
232
+ ok: false,
233
+ code: 'INVALID_DELEGATION',
234
+ detail_code: 'APPROVED_COMMAND_UNAVAILABLE',
235
+ error: 'Managed AUN sends require an approved command hash',
236
+ retryable: false,
237
+ sent: false,
238
+ };
239
+ }
240
+ if (!params.originSessionId) {
241
+ return { ok: false, code: 'DELEGATION_REQUIRED', error: 'Origin session is required', sent: false };
242
+ }
243
+ // 先核验原始命令和会话凭据,再使用 grant 补全路由;这里不消费审批。
244
+ const authorization = agentDelegationRegistry.validateForContext(params.delegationToken, params.originSessionId, params.delegationCommandHash);
245
+ if (!authorization.ok) {
246
+ return {
247
+ ok: false,
248
+ code: authorization.code,
249
+ error: authorization.reason,
250
+ detail_code: delegationFailureDetailCode(authorization.diagnosticCause),
251
+ retryable: false,
252
+ sent: false,
253
+ };
254
+ }
255
+ const grant = authorization.grant;
256
+ const command = resolveManagedSendArgv(params.argv, {
257
+ selfAid: grant.selfAid,
258
+ peerId: grant.channelType === 'aun' && grant.chatType === 'private'
259
+ ? parsePeerKey(grant.peerKey).channelId : undefined,
260
+ resolveThreadPeer: thread => resolveThreadRouteTarget(grant.selfAid, thread, 'msg')?.peer,
261
+ });
251
262
  textFile = command.textFile;
252
263
  payloadFile = command.payloadFile;
253
264
  params = { ...params, ...command };
@@ -297,16 +308,6 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
297
308
  ? threadRef
298
309
  : (safeFormatMainTopicId(params.aid, threadRoute.peer) ?? threadRef))
299
310
  : undefined;
300
- if (params.argv !== undefined && !params.delegationCommandHash) {
301
- return {
302
- ok: false,
303
- code: 'INVALID_DELEGATION',
304
- detail_code: 'APPROVED_COMMAND_UNAVAILABLE',
305
- error: 'Managed AUN sends require an approved command hash',
306
- retryable: false,
307
- sent: false,
308
- };
309
- }
310
311
  const isSystemEvent = params.trustedSystemEvent === true
311
312
  && params.payload?.type === 'event' && params.payload.event === 'topic.renamed';
312
313
  const delegation = await authorizeDelegatedAunMsgSend(agentDelegationRegistry, {
@@ -331,10 +332,12 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
331
332
  ...(delegation.sent === false ? { sent: false } : {}),
332
333
  };
333
334
  }
335
+ const fullAccess = !!delegation.grant && hasTrustedFullAccessDelegation(delegation.grant);
334
336
  try {
335
337
  const fileScope = runtime?.projectPath && delegation.grant
336
338
  ? { selfAid: delegation.grant.selfAid, projectPath: runtime.projectPath,
337
- sessionRuntimeDir: delegation.grant.sessionRuntimeDir, cwd: runtime.projectPath }
339
+ sessionRuntimeDir: delegation.grant.sessionRuntimeDir, cwd: runtime.projectPath,
340
+ ...(fullAccess ? { allowProtectedPaths: true } : {}) }
338
341
  : undefined;
339
342
  if ((textFile || payloadFile || params.file) && !fileScope)
340
343
  throw new Error('Current task project context is unavailable');
@@ -386,7 +389,13 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
386
389
  return { ok: false, error: `AUN channel not found for ${params.aid}`, code: 'AUN_CHANNEL_NOT_FOUND' };
387
390
  }
388
391
  if (params.scope === 'msg') {
389
- const admission = await evaluateOutboundContactAdmission({ selfAid: params.aid, targetAid: params.to });
392
+ const admission = params.argv !== undefined
393
+ ? await ensureOutboundContactForSend({
394
+ selfAid: params.aid,
395
+ targetAid: params.to,
396
+ actorId: delegation.grant?.actorId ?? 'managed-outbound-send',
397
+ })
398
+ : await evaluateOutboundContactAdmission({ selfAid: params.aid, targetAid: params.to });
390
399
  if (!admission.allow) {
391
400
  return { ok: false, error: admission.error, code: admission.code };
392
401
  }
@@ -399,7 +408,7 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
399
408
  : (typeof ch.getDefaultEncrypt === 'function' ? ch.getDefaultEncrypt() : true);
400
409
  let payload = params.payload;
401
410
  if (params.file) {
402
- if (isHClassPath(params.file.filePath)) {
411
+ if (isHClassPath(params.file.filePath) && !fullAccess) {
403
412
  return {
404
413
  ok: false,
405
414
  error: 'H-class protected files cannot be uploaded by an agent task',
@@ -539,7 +548,6 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
539
548
  // 承载目标侧上下文,跳过这里就会丢上下文。
540
549
  if (threadRouted && params.checkEveryMs !== undefined && threadRoute) {
541
550
  const effects = await applyManagedCrossThreadSendEffects({
542
- triggerSchedulers,
543
551
  runtime,
544
552
  selfAid: params.aid,
545
553
  targetThreadId: targetTopicId ?? params.thread ?? "",
@@ -552,6 +560,8 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
552
560
  durationMs: params.checkEveryMs,
553
561
  checkEveryLabel: params.checkEvery ?? '5m',
554
562
  triggerPromptExtra: params.triggerPromptExtra,
563
+ grant: delegation.grant,
564
+ createCrossThreadReviewTrigger,
555
565
  });
556
566
  if (effects.triggerId)
557
567
  response.trigger_id = effects.triggerId;
@@ -591,7 +601,6 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
591
601
  });
592
602
  if (params.thread && params.checkEveryMs !== undefined && sent.ok && sent.message_id && threadRoute) {
593
603
  const effects = await applyManagedCrossThreadSendEffects({
594
- triggerSchedulers,
595
604
  runtime,
596
605
  selfAid: params.aid,
597
606
  targetThreadId: params.thread,
@@ -604,6 +613,8 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
604
613
  durationMs: params.checkEveryMs,
605
614
  checkEveryLabel: params.checkEvery ?? '5m',
606
615
  triggerPromptExtra: params.triggerPromptExtra,
616
+ grant: delegation.grant,
617
+ createCrossThreadReviewTrigger,
607
618
  });
608
619
  if (effects.triggerId)
609
620
  sent.trigger_id = effects.triggerId;
@@ -652,7 +663,6 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
652
663
  }
653
664
  if (params.thread && params.checkEveryMs !== undefined && sent.ok && sent.message_id && threadRoute) {
654
665
  const effects = await applyManagedCrossThreadSendEffects({
655
- triggerSchedulers,
656
666
  runtime,
657
667
  selfAid: params.aid,
658
668
  targetThreadId: params.thread,
@@ -665,6 +675,8 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
665
675
  durationMs: params.checkEveryMs,
666
676
  checkEveryLabel: params.checkEvery ?? '5m',
667
677
  triggerPromptExtra: params.triggerPromptExtra,
678
+ grant: delegation.grant,
679
+ createCrossThreadReviewTrigger,
668
680
  });
669
681
  if (effects.triggerId)
670
682
  sent.trigger_id = effects.triggerId;
@@ -5,6 +5,22 @@ import { tagErrorTextWithEvolcoreVersion } from '../../utils/evolcore-version.js
5
5
  import { DEFAULT_FLUSH_DELAY_MS } from '../../types.js';
6
6
  import { classifyAunToolErrorCode, normalizeToolErrorClassification } from '../permission/tool-error-code.js';
7
7
  import { foldSubtaskTerminal } from './subtask-tool-projection.js';
8
+ function toolApprovalMetadata(event) {
9
+ if (!event || event.executed !== false || !event.decisionSource || event.decisionSource === 'runner')
10
+ return {};
11
+ return { approval: {
12
+ decision: 'deny',
13
+ decisionSource: event.decisionSource,
14
+ requestId: event.requestId,
15
+ approvalRequestId: event.approvalRequestId,
16
+ policyCode: event.policyCode,
17
+ errorDetailCode: normalizeToolErrorClassification(event).errorDetailCode,
18
+ reason: event.reason ?? event.error,
19
+ approverOperatorId: event.approverOperatorId,
20
+ approverChannelKey: event.approverChannelKey,
21
+ approverPrincipalId: event.approverPrincipalId,
22
+ } };
23
+ }
8
24
  export class IMRenderer {
9
25
  opts;
10
26
  itemsQueue = [];
@@ -15,6 +31,7 @@ export class IMRenderer {
15
31
  sentContent = false;
16
32
  flushCount = 0;
17
33
  messageTimestamps = [];
34
+ loggedBlankTextDiagnostic = false;
18
35
  /** 串行发送队列:保证消息按序到达 */
19
36
  sendChain = Promise.resolve();
20
37
  /** proactive:是否已发过 text 文本(用于去重 complete.result) */
@@ -119,7 +136,7 @@ export class IMRenderer {
119
136
  return;
120
137
  if (this.textBuffer.length === 0)
121
138
  return;
122
- // 文件标记过滤后若只剩空白,应立即消费并告警;尤其避免 final-only
139
+ // 文件标记过滤后若只剩空白,应立即消费;尤其避免 final-only
123
140
  // 模式把工具调用前的空白继续带到最终回复。
124
141
  const rawText = this.opts.fileMarkerPattern
125
142
  ? this.textBuffer.replace(this.opts.fileMarkerPattern, '')
@@ -283,6 +300,7 @@ export class IMRenderer {
283
300
  : {}),
284
301
  ...(classification?.outputKind ? { output_kind: classification.outputKind } : {}),
285
302
  ...(!ok && {
303
+ ...toolApprovalMetadata(classification),
286
304
  error_code: classifyAunToolErrorCode({
287
305
  ...(classification ?? {}),
288
306
  ...(normalizedClassification ?? {}),
@@ -538,10 +556,12 @@ export class IMRenderer {
538
556
  hasSendableText(text, source) {
539
557
  if (text.trim())
540
558
  return true;
541
- // An unused buffer is normal. A nonempty whitespace body is diagnostic evidence.
542
- if (text.length > 0) {
559
+ // One task can flush several whitespace-only stream deltas. Keep one debug
560
+ // signal for diagnosis without emitting a WARN for every expected empty body.
561
+ if (text.length > 0 && !this.loggedBlankTextDiagnostic) {
562
+ this.loggedBlankTextDiagnostic = true;
543
563
  const { envelope, agentAid } = this.opts;
544
- logger.warn(`[IMRenderer] Attempted to send empty message, skipping: code=EMPTY_MESSAGE source=${source} task=${envelope.taskId} session=${envelope.sessionId ?? '<none>'} agent=${agentAid ?? envelope.agentName} textLength=${text.length} text=${JSON.stringify(text.slice(0, 80))}`);
564
+ logger.debug(`[IMRenderer] Skipped whitespace-only text: code=EMPTY_MESSAGE source=${source} task=${envelope.taskId} session=${envelope.sessionId ?? '<none>'} agent=${agentAid ?? envelope.agentName} textLength=${text.length} text=${JSON.stringify(text.slice(0, 80))}`);
545
565
  }
546
566
  return false;
547
567
  }
@@ -928,6 +948,7 @@ export class IMRenderer {
928
948
  call_id: event.callId || this.synthCallId(),
929
949
  name: event.name,
930
950
  ok: false,
951
+ ...toolApprovalMetadata(event),
931
952
  ...executionFields,
932
953
  ...(event.result !== undefined ? { result: event.result } : {}),
933
954
  error_code: classifyAunToolErrorCode({ ...event, ...classification }),
@@ -1,7 +1,9 @@
1
1
  import { AccessPolicyError, readAccessPolicy, } from '../../config/access-policy.js';
2
2
  import { getContactSnapshot, isAcceptedContact, resolveContactView, resolvePrincipal, } from '../../config/contact-book.js';
3
3
  import { isValidAid } from '../../aun/aid/validation.js';
4
- import { expirePendingContactRequests } from '../../config/contact-request-service.js';
4
+ import { addContact, expirePendingContactRequests } from '../../config/contact-request-service.js';
5
+ import { readOwnerDirectoryMembership } from '../../directory/owner-directory-admission.js';
6
+ import { readAunPeerKind, resolveAunPeerKind } from '../relation/peer-identity.js';
5
7
  /** Validate managed private AUN sends against the sender's local contact policy. */
6
8
  export async function evaluateOutboundContactAdmission(input) {
7
9
  const selfAid = String(input.selfAid || '').trim();
@@ -34,8 +36,12 @@ export async function evaluateOutboundContactAdmission(input) {
34
36
  const view = resolveContactView(selfAid, targetAid);
35
37
  if (view.isOwner)
36
38
  return { allow: true, status: 'owner' };
37
- if (entry && (entry.status === undefined || entry.status === 'active'))
38
- return { allow: true, status: 'active' };
39
+ if (entry && (entry.status === undefined || entry.status === 'active')) {
40
+ const kind = readAunPeerKind(selfAid, targetAid);
41
+ return kind.kind === 'private' ? { allow: true, status: 'active' }
42
+ : { allow: false, code: 'CONTACT_POLICY_INVALID', status: 'absent',
43
+ error: `Cannot establish private contact type (${kind.reason}): ${targetAid}` };
44
+ }
39
45
  const status = entry?.status ?? 'absent';
40
46
  if (status === 'blocked')
41
47
  return { allow: false, code: 'CONTACT_BLOCKED', status, error: `目标联系人 ${targetAid} 已被拉黑。请先解除拉黑:ec contact unblock ${targetAid} --self ${selfAid}` };
@@ -50,6 +56,58 @@ export async function evaluateOutboundContactAdmission(input) {
50
56
  return { allow: false, code: 'CONTACT_POLICY_INVALID', status: 'absent', error: error instanceof Error ? error.message : String(error) };
51
57
  }
52
58
  }
59
+ /** An explicit managed private send establishes the target as an active contact. */
60
+ export async function ensureOutboundContactForSend(input) {
61
+ const selfAid = String(input.selfAid || '').trim();
62
+ const targetAid = String(input.targetAid || '').trim();
63
+ if (!isValidAid(selfAid) || !isValidAid(targetAid))
64
+ return evaluateOutboundContactAdmission(input);
65
+ input = { ...input, selfAid, targetAid };
66
+ const target = await resolveAunPeerKind(selfAid, targetAid);
67
+ if (target.kind !== 'private') {
68
+ return {
69
+ allow: false, code: 'CONTACT_POLICY_INVALID', status: 'absent',
70
+ error: target.kind === 'group' ? `Target ${targetAid} is a group AID; use group send`
71
+ : `Cannot establish private target type (${target.reason}): ${targetAid}`,
72
+ };
73
+ }
74
+ const admission = await evaluateOutboundContactAdmission(input);
75
+ if (!admission.allow && (admission.code === 'CONTACT_BLOCKED' || admission.code === 'CONTACT_POLICY_INVALID')) {
76
+ return admission;
77
+ }
78
+ try {
79
+ const view = resolveContactView(input.selfAid, input.targetAid);
80
+ if (view.isOwner || (view.source === 'contact' && view.status === 'active'))
81
+ return admission;
82
+ await addContact({
83
+ selfAid: input.selfAid,
84
+ primaryId: input.targetAid,
85
+ actorId: input.actorId,
86
+ });
87
+ return evaluateOutboundContactAdmission(input);
88
+ }
89
+ catch (error) {
90
+ const current = await evaluateOutboundContactAdmission(input);
91
+ if (!current.allow && current.code === 'CONTACT_BLOCKED')
92
+ return current;
93
+ if (current.allow) {
94
+ try {
95
+ const view = resolveContactView(input.selfAid, input.targetAid);
96
+ if (view.isOwner || (view.source === 'contact' && view.status === 'active'))
97
+ return current;
98
+ }
99
+ catch {
100
+ // Return the original mutation error below.
101
+ }
102
+ }
103
+ return {
104
+ allow: false,
105
+ code: 'CONTACT_POLICY_INVALID',
106
+ status: 'absent',
107
+ error: error instanceof Error ? error.message : String(error),
108
+ };
109
+ }
110
+ }
53
111
  export function evaluateInboundAdmissionPreflight(input) {
54
112
  const selfAid = String(input.selfAid || '').trim();
55
113
  const channelType = String(input.channelType || '').trim().toLowerCase();
@@ -122,6 +180,30 @@ export function evaluateInboundAdmissionPreflight(input) {
122
180
  }
123
181
  return { allow: true, context };
124
182
  }
183
+ /** Directory rules also guard control routes; a denied directory sender receives no automatic reply. */
184
+ export function evaluateOwnerDirectoryInboundAdmission(context) {
185
+ if (context.trustedHandoffEcho || context.isOwner || !context.primaryId || !context.policy)
186
+ return undefined;
187
+ const membership = readOwnerDirectoryMembership(context.selfAid, context.primaryId);
188
+ if (!membership)
189
+ return undefined;
190
+ if (membership.agents === 'found') {
191
+ return context.policy.allowOwnerAgentDirectory !== false
192
+ ? { allow: true, reason: 'owner_directory_agent', context }
193
+ : { allow: false, reason: 'owner_agent_directory_disabled', context };
194
+ }
195
+ // Resolve the higher-priority Agent category before admitting a contact.
196
+ if (membership.agents === 'unavailable')
197
+ return { allow: false, reason: 'owner_directory_unavailable', context };
198
+ if (membership.contacts === 'found') {
199
+ return context.policy.allowOwnerDirectoryContacts !== false
200
+ ? { allow: true, reason: 'owner_directory_contact', context }
201
+ : { allow: false, reason: 'owner_directory_contacts_disabled', context };
202
+ }
203
+ if (membership.contacts === 'unavailable')
204
+ return { allow: false, reason: 'owner_directory_unavailable', context };
205
+ return undefined;
206
+ }
125
207
  export function evaluateOrdinaryInboundAdmission(context) {
126
208
  if (context.trustedHandoffEcho)
127
209
  return { allow: true, reason: 'trusted_handoff', context };
@@ -130,6 +212,9 @@ export function evaluateOrdinaryInboundAdmission(context) {
130
212
  return { allow: false, reason: 'invalid_access_policy', context };
131
213
  if (context.isOwner)
132
214
  return { allow: true, reason: 'owner', context };
215
+ const directoryDecision = evaluateOwnerDirectoryInboundAdmission(context);
216
+ if (directoryDecision)
217
+ return directoryDecision;
133
218
  if (context.primaryId && policy.allowedAids?.includes(context.primaryId)) {
134
219
  return { allow: true, reason: 'allowed_aid', context };
135
220
  }
@@ -146,7 +231,7 @@ export function evaluateOrdinaryInboundAdmission(context) {
146
231
  return { allow: true, reason: 'open', context };
147
232
  if (policy.policyMode === 'owners')
148
233
  return { allow: false, reason: 'owners', context };
149
- if (context.primaryId && isAcceptedContact(context.selfAid, context.primaryId)) {
234
+ if (context.primaryId && isAcceptedContact(context.selfAid, context.primaryId, context.channelType === 'aun' && context.chatType === 'private' ? 'private' : undefined)) {
150
235
  return { allow: true, reason: 'contact', context };
151
236
  }
152
237
  return { allow: false, reason: 'contact_required', context };