evolcore 0.0.43-test.2 → 0.0.43-test.4

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 (173) hide show
  1. package/CHANGELOG.md +44 -1
  2. package/bin/ecmsg.js +229 -0
  3. package/bin/install-codex-managed-hooks.mjs +130 -8
  4. package/dist/ability/application-service.js +37 -0
  5. package/dist/ability/resources.js +28 -0
  6. package/dist/ability/runtime.js +6 -1
  7. package/dist/agents/claude-runner.js +7 -5
  8. package/dist/agents/codex/app-server-client.js +0 -12
  9. package/dist/agents/codex-runner.js +0 -37
  10. package/dist/agents/ecagent-runner.js +138 -36
  11. package/dist/aun/aid/agentmd.js +52 -13
  12. package/dist/aun/menu/client.js +8 -7
  13. package/dist/aun/menu/index.js +1 -1
  14. package/dist/aun/menu/transport.js +8 -5
  15. package/dist/aun/msg/p2p.js +4 -2
  16. package/dist/aun/service-proxy.js +3 -0
  17. package/dist/channels/aun.js +105 -53
  18. package/dist/channels/daemon.js +14 -2
  19. package/dist/cli/agent-command.js +5 -0
  20. package/dist/cli/agent-create.js +31 -11
  21. package/dist/cli/agent.js +9 -3
  22. package/dist/cli/aun-commands.js +19 -21
  23. package/dist/cli/daemon-commands.js +30 -18
  24. package/dist/cli/directory.js +98 -56
  25. package/dist/cli/getmeta-command.js +2 -1
  26. package/dist/cli/index.js +1 -1
  27. package/dist/cli/init.js +13 -5
  28. package/dist/cli/peer.js +2 -1
  29. package/dist/cli/task-context.js +3 -1
  30. package/dist/cli/trigger-command.js +20 -14
  31. package/dist/config/access-policy.js +0 -1
  32. package/dist/config/boot-log.js +12 -2
  33. package/dist/config/builtin-role-templates.js +2 -2
  34. package/dist/config/builtin-roles.js +2 -1
  35. package/dist/config/config-field-policy.js +7 -0
  36. package/dist/config/config-manager.js +30 -10
  37. package/dist/config/peer-role-resolver.js +23 -1
  38. package/dist/config/role-schema.js +25 -1
  39. package/dist/config/role-service.js +9 -4
  40. package/dist/config/role-store.js +30 -8
  41. package/dist/config/schema-migration.js +121 -0
  42. package/dist/core/agent-application-service.js +11 -0
  43. package/dist/core/agent-ipc-registration.js +2 -0
  44. package/dist/core/agent-runtime.js +41 -9
  45. package/dist/core/auth/auth-gateway.js +14 -4
  46. package/dist/core/auth/operation-authorizer.js +19 -1
  47. package/dist/core/auth/operation-catalog.js +12 -2
  48. package/dist/core/baseagent-loader.js +11 -3
  49. package/dist/core/bootstrap-service.js +8 -0
  50. package/dist/core/channel-loader.js +61 -23
  51. package/dist/core/channel-runtime.js +5 -0
  52. package/dist/core/command/agent-control.js +5 -2
  53. package/dist/core/command/agentmd-menu-request.js +50 -0
  54. package/dist/core/command/agentmd-menu.js +156 -0
  55. package/dist/core/command/chatmode-config.js +46 -0
  56. package/dist/core/command/command-handler.js +44 -17
  57. package/dist/core/command/daemon-diagnostics.js +2 -1
  58. package/dist/core/command/menu-catalog.js +14 -1
  59. package/dist/core/command/menu-handler.js +74 -24
  60. package/dist/core/command/menu-protocol.js +8 -0
  61. package/dist/core/command/role-menu.js +23 -9
  62. package/dist/core/command/slash-handler.js +52 -47
  63. package/dist/core/daemon-lifecycle.js +43 -17
  64. package/dist/core/event-catalog.js +19 -0
  65. package/dist/core/evolagent-registry.js +3 -0
  66. package/dist/core/evolagent.js +5 -4
  67. package/dist/core/ipc-registration.js +6 -0
  68. package/dist/core/lifecycle-notice.js +185 -0
  69. package/dist/core/message/aun-ipc-sender.js +30 -24
  70. package/dist/core/message/contact-admission.js +1 -19
  71. package/dist/core/message/im-renderer.js +81 -40
  72. package/dist/core/message/message-admission.js +21 -62
  73. package/dist/core/message/message-bridge.js +18 -5
  74. package/dist/core/message/message-utils.js +9 -0
  75. package/dist/core/message/peer-mode.js +16 -8
  76. package/dist/core/message/response-engine.js +67 -47
  77. package/dist/core/model/model-capabilities.js +37 -0
  78. package/dist/core/model/model-catalog.js +6 -2
  79. package/dist/core/ownership/owner-resolver.js +74 -36
  80. package/dist/core/permission/ec-command-parser.js +62 -13
  81. package/dist/core/plugin-lifecycle.js +6 -2
  82. package/dist/core/relation/pa-team.js +132 -0
  83. package/dist/core/role/runtime-policy.js +4 -3
  84. package/dist/core/thread/thread-service.js +6 -4
  85. package/dist/directory/owner-directory-admission.js +0 -3
  86. package/dist/directory/owner-directory-cache.js +201 -17
  87. package/dist/directory/owner-directory-markdown.js +44 -21
  88. package/dist/directory/owner-directory-policy.js +1 -1
  89. package/dist/directory/owner-directory-query-operation.js +218 -98
  90. package/dist/directory/owner-directory-request-operation.js +76 -0
  91. package/dist/directory/owner-directory-scope.js +35 -4
  92. package/dist/directory/owner-directory-search.js +76 -23
  93. package/dist/directory/owner-directory-store.js +5 -38
  94. package/dist/directory/owner-directory-text.js +60 -0
  95. package/dist/eck/kit-renderer.js +6 -3
  96. package/dist/eck/message-renderer.js +2 -5
  97. package/dist/ecweb/message-context-service.js +4 -0
  98. package/dist/ecweb/runtime/lifecycle.js +29 -5
  99. package/dist/ecweb/runtime/supervisor.js +83 -27
  100. package/dist/index.js +209 -38
  101. package/dist/paths.js +4 -2
  102. package/dist/product.js +1 -0
  103. package/dist/proxy/service-supervisor.js +377 -141
  104. package/dist/response-system/engines/v1/index.js +2 -4
  105. package/dist/response-system/modes/single-session/index.js +1 -1
  106. package/dist/trigger/audit.js +3 -2
  107. package/dist/trigger/authorization.js +2 -3
  108. package/dist/trigger/history.js +4 -3
  109. package/dist/trigger/ipc-service.js +24 -19
  110. package/dist/trigger/manager.js +3 -5
  111. package/dist/trigger/parser.js +4 -21
  112. package/dist/trigger/patch.js +3 -15
  113. package/dist/trigger/scheduler.js +53 -13
  114. package/dist/trigger/validation.js +0 -13
  115. package/dist/utils/error-utils.js +15 -5
  116. package/dist/utils/macos-autostart.js +31 -0
  117. package/dist/utils/model-prices.jsonl +15 -8
  118. package/dist/utils/process-introspect.js +21 -1
  119. package/dist/utils/startup-trace.js +7 -1
  120. package/dist/utils/windows-autostart.js +1 -0
  121. package/ecagent/README.md +18 -0
  122. package/ecagent/dist/harness/agent-harness.d.ts +2 -0
  123. package/ecagent/dist/harness/agent-harness.js +24 -8
  124. package/ecagent/dist/harness/compaction/branch-summarization.js +1 -1
  125. package/ecagent/dist/harness/compaction/compaction.js +7 -4
  126. package/ecagent/dist/harness/types.d.ts +1 -0
  127. package/kits/docs/channels/aun.md +1 -1
  128. package/kits/docs/context-assembly.md +1 -1
  129. package/kits/docs/evolcore/INDEX.md +5 -2
  130. package/kits/docs/evolcore/directory.md +125 -35
  131. package/kits/docs/evolcore/ecweb-lifecycle.md +26 -0
  132. package/kits/docs/evolcore/file-navigation.md +279 -0
  133. package/kits/docs/evolcore/menu-protocol.md +1 -0
  134. package/kits/docs/evolcore/model.md +5 -3
  135. package/kits/docs/evolcore/msg.md +1 -0
  136. package/kits/docs/evolcore/peer.md +2 -1
  137. package/kits/docs/evolcore/response.md +4 -2
  138. package/kits/docs/evolcore/task.md +2 -0
  139. package/kits/docs/evolcore/thread-chain.md +1 -1
  140. package/kits/docs/evolcore/tool-authorization.md +4 -1
  141. package/kits/docs/evolcore/trigger.md +10 -7
  142. package/kits/docs/identity/ROLE_DETAIL.md +2 -0
  143. package/kits/eck_manifest.json +6 -23
  144. package/kits/eck_manifest.memory.json +26 -1
  145. package/kits/rules/01-overview.md +42 -44
  146. package/kits/rules/02-navigation.md +44 -53
  147. package/kits/rules/03-identity.md +21 -25
  148. package/kits/rules/04-relation.md +23 -33
  149. package/kits/rules/05-venue.md +24 -25
  150. package/kits/schemas/_meta.json +10 -10
  151. package/kits/schemas/agent-config.schema.19.json +10 -6
  152. package/kits/schemas/relation-config.schema.12.json +2 -2
  153. package/kits/schemas/role-config.schema.2.json +5 -5
  154. package/kits/schemas/role-registry.schema.1.json +3 -2
  155. package/kits/skills/ec-service-proxy/SKILL.md +10 -0
  156. package/kits/skills/ec-trigger/SKILL.md +1 -1
  157. package/kits/templates/soul/00-GUIDE.md +20 -42
  158. package/kits/templates/system-fragments/channel.md +2 -2
  159. package/kits/templates/system-fragments/commands.md +1 -1
  160. package/kits/templates/system-fragments/directory-contacts.md +1 -1
  161. package/kits/templates/system-fragments/identity.md +0 -1
  162. package/kits/templates/system-fragments/personal-assistant.md +2 -17
  163. package/kits/templates/system-fragments/reply.md +7 -0
  164. package/kits/templates/system-fragments/session.md +6 -2
  165. package/package.json +18 -13
  166. package/dist/eck/paactive-context.js +0 -45
  167. package/dist/response-system/engines/v1/paactive-flow.js +0 -18
  168. package/kits/eck_manifest.paactive.json +0 -528
  169. package/kits/eck_message_manifest.paactive.json +0 -233
  170. package/kits/templates/message-fragments/paactive/item.md +0 -3
  171. package/kits/templates/system-fragments/paactive/channel.md +0 -25
  172. package/kits/templates/system-fragments/paactive/reply.md +0 -25
  173. package/kits/templates/system-fragments/paactive/session.md +0 -32
@@ -0,0 +1,185 @@
1
+ import { ownerResolver } from './ownership/owner-resolver.js';
2
+ import { resolveAgentDisplayName } from '../aun/aid/agentmd.js';
3
+ import { isValidAid } from '../aun/aid/validation.js';
4
+ import { logger } from '../utils/logger.js';
5
+ /** AUN volatile TTL for online/offline notices; the gateway caps this at 3600s. */
6
+ export const LIFECYCLE_NOTICE_TTL_SECONDS = 1_800;
7
+ /** Owner consensus checks are retried at these offsets after a channel connects. */
8
+ export const ONLINE_OWNER_RETRY_DELAYS_MS = [0, 2_000, 6_000];
9
+ /** Shutdown is time-boxed: a missed offline notice is acceptable, a hung exit is not. */
10
+ export const OFFLINE_SINGLE_SEND_MS = 1_200;
11
+ export const OFFLINE_TOTAL_BUDGET_MS = 1_500;
12
+ function normalizeAid(value) {
13
+ const aid = String(value ?? '').trim();
14
+ return aid.startsWith('@') ? aid.slice(1) : aid;
15
+ }
16
+ function confirmedOwner(view) {
17
+ if (!view || view.consensusStatus !== 'consensus')
18
+ return undefined;
19
+ const owner = normalizeAid(view.ownerAid);
20
+ return isValidAid(owner) ? owner : undefined;
21
+ }
22
+ function channelInstanceAid(instance, agent) {
23
+ const channel = instance.channel;
24
+ return normalizeAid(channel?.getAid?.() ?? agent?.aid);
25
+ }
26
+ function isAun(instance) {
27
+ return instance.channelType === 'aun';
28
+ }
29
+ function sleep(ms) {
30
+ if (ms <= 0)
31
+ return Promise.resolve();
32
+ return new Promise(resolve => {
33
+ const timer = setTimeout(resolve, ms);
34
+ timer.unref?.();
35
+ });
36
+ }
37
+ /** Await a promise at most `ms`, swallowing both timeout and rejection. */
38
+ async function settleWithin(promise, ms) {
39
+ let timer;
40
+ try {
41
+ await Promise.race([
42
+ promise.then(() => undefined, () => undefined),
43
+ new Promise(resolve => {
44
+ timer = setTimeout(resolve, ms);
45
+ timer.unref?.();
46
+ }),
47
+ ]);
48
+ }
49
+ finally {
50
+ if (timer)
51
+ clearTimeout(timer);
52
+ }
53
+ }
54
+ export function createLifecycleNoticeService(deps) {
55
+ const log = deps.log ?? logger;
56
+ const retryDelaysMs = deps.timing?.retryDelaysMs ?? ONLINE_OWNER_RETRY_DELAYS_MS;
57
+ const onlineSendMs = deps.timing?.onlineSendMs ?? OFFLINE_SINGLE_SEND_MS;
58
+ const offlineSingleMs = deps.timing?.offlineSingleMs ?? OFFLINE_SINGLE_SEND_MS;
59
+ const offlineTotalMs = deps.timing?.offlineTotalMs ?? OFFLINE_TOTAL_BUDGET_MS;
60
+ const lookup = deps.ownerLookup ?? {
61
+ refreshOwner: aid => ownerResolver.refresh(aid, {
62
+ force: true,
63
+ source: 'daemon.lifecycle.online',
64
+ }),
65
+ owner: aid => ownerResolver.owner(aid),
66
+ onChange: listener => ownerResolver.onChange(listener),
67
+ };
68
+ /**
69
+ * SIGINT/SIGTERM 会先跑 `onShutdown(() => ownerResolver.stop())`,进入 daemon
70
+ * shutdown 时共识缓存已被清空。上下线通知都依赖这份进程内缓存。
71
+ */
72
+ const confirmedOwners = new Map();
73
+ const onlineInFlight = new Set();
74
+ let onlineStopped = false;
75
+ let offlineSent = false;
76
+ const unsubscribe = lookup.onChange((subjectAid, ownerAid) => {
77
+ const aid = normalizeAid(subjectAid);
78
+ const owner = normalizeAid(ownerAid);
79
+ if (aid && owner && isValidAid(owner) && owner !== aid)
80
+ confirmedOwners.set(aid, owner);
81
+ else if (aid)
82
+ confirmedOwners.delete(aid);
83
+ });
84
+ const agentNameFor = (selfAid) => resolveAgentDisplayName(selfAid) || selfAid.split('.')[0] || selfAid;
85
+ async function sendOne(instance, selfAid, ownerAid, online) {
86
+ const channel = instance.channel;
87
+ if (typeof channel?.sendLifecycleNotice !== 'function') {
88
+ log.warn(`[Lifecycle] AUN channel for ${selfAid} does not expose sendLifecycleNotice`);
89
+ return;
90
+ }
91
+ try {
92
+ const result = await channel.sendLifecycleNotice({
93
+ to: ownerAid,
94
+ agentName: agentNameFor(selfAid),
95
+ online,
96
+ ttlSeconds: LIFECYCLE_NOTICE_TTL_SECONDS,
97
+ });
98
+ if (result?.ok !== true) {
99
+ log.warn(`[Lifecycle] ${online ? 'online' : 'offline'} notice ${selfAid} -> ${ownerAid} failed: `
100
+ + `${result?.code ?? ''} ${result?.error ?? ''}`.trim());
101
+ }
102
+ }
103
+ catch (error) {
104
+ log.warn(`[Lifecycle] ${online ? 'online' : 'offline'} notice ${selfAid} -> ${ownerAid} failed: `
105
+ + `${error instanceof Error ? error.message : String(error)}`);
106
+ }
107
+ }
108
+ async function runOnline(instance, selfAid) {
109
+ for (const delay of retryDelaysMs) {
110
+ if (delay > 0)
111
+ await sleep(delay);
112
+ if (onlineStopped)
113
+ return;
114
+ let owner;
115
+ try {
116
+ owner = confirmedOwner(await lookup.refreshOwner(selfAid));
117
+ }
118
+ catch (error) {
119
+ log.debug(`[Lifecycle] ownership refresh for ${selfAid} failed: `
120
+ + `${error instanceof Error ? error.message : String(error)}`);
121
+ }
122
+ if (!owner || owner === selfAid)
123
+ continue;
124
+ confirmedOwners.set(selfAid, owner);
125
+ await settleWithin(sendOne(instance, selfAid, owner, true), onlineSendMs);
126
+ return;
127
+ }
128
+ log.info(`[Lifecycle] ${selfAid} has no Ownership consensus; online notice skipped`);
129
+ }
130
+ function online(instance) {
131
+ if (onlineStopped || !isAun(instance))
132
+ return;
133
+ const agent = deps.resolveAgent(instance.adapter.channelKey, instance.adapter.channelName);
134
+ if (!agent)
135
+ return;
136
+ const selfAid = channelInstanceAid(instance, agent);
137
+ if (!selfAid || onlineInFlight.has(selfAid))
138
+ return;
139
+ onlineInFlight.add(selfAid);
140
+ void runOnline(instance, selfAid)
141
+ .catch(error => log.warn(`[Lifecycle] online notice for ${selfAid} failed: `
142
+ + `${error instanceof Error ? error.message : String(error)}`))
143
+ .finally(() => onlineInFlight.delete(selfAid));
144
+ }
145
+ function beginShutdown() {
146
+ onlineStopped = true;
147
+ unsubscribe();
148
+ }
149
+ async function sendOffline(signal) {
150
+ if (offlineSent)
151
+ return;
152
+ offlineSent = true;
153
+ const seen = new Set();
154
+ const jobs = [];
155
+ for (const instance of deps.channelInstances) {
156
+ if (!isAun(instance))
157
+ continue;
158
+ const agent = deps.resolveAgent(instance.adapter.channelKey, instance.adapter.channelName);
159
+ const selfAid = channelInstanceAid(instance, agent);
160
+ if (!selfAid || seen.has(selfAid))
161
+ continue;
162
+ seen.add(selfAid);
163
+ const owner = confirmedOwners.get(selfAid) ?? confirmedOwnerFromResolver(selfAid);
164
+ if (!owner) {
165
+ log.debug(`[Lifecycle] ${selfAid} has no confirmed Owner; offline notice skipped`);
166
+ continue;
167
+ }
168
+ jobs.push(settleWithin(sendOne(instance, selfAid, owner, false), offlineSingleMs));
169
+ }
170
+ if (jobs.length === 0)
171
+ return;
172
+ log.info(`[Lifecycle] sending ${jobs.length} offline notice(s) (signal=${signal ?? 'unknown'})`);
173
+ await settleWithin(Promise.allSettled(jobs), offlineTotalMs);
174
+ }
175
+ function confirmedOwnerFromResolver(selfAid) {
176
+ try {
177
+ const owner = normalizeAid(lookup.owner(selfAid));
178
+ return owner && isValidAid(owner) && owner !== selfAid ? owner : undefined;
179
+ }
180
+ catch {
181
+ return undefined;
182
+ }
183
+ }
184
+ return { online, beginShutdown, sendOffline };
185
+ }
@@ -7,7 +7,7 @@ import { classifyAunPayloadForLog } from './message-log.js';
7
7
  import { isValidAunDeliveryForChannel } from './outbound.js';
8
8
  import { isHClassPath } from '../permission/protected-paths.js';
9
9
  import { evaluateOutboundContactAdmission } from './message-admission.js';
10
- import { appContactAdmissionActive, contactIntroductionText, evaluateAppContactAdmission } from './contact-admission.js';
10
+ import { contactIntroductionText, evaluateAppContactAdmission, parseFriendInvite } from './contact-admission.js';
11
11
  import { normalizeAunMentionEntries, withAunAttention } from '../../aun/msg/mention-schema.js';
12
12
  import { resolveManagedSendArgv } from '../../cli/aun-commands.js';
13
13
  import { readTriggerLocalFile, resolveAttachmentLocalPath } from '../../trigger/local-files.js';
@@ -394,28 +394,34 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
394
394
  if (params.scope === 'msg') {
395
395
  const admission = await evaluateOutboundContactAdmission({ selfAid: params.aid, targetAid: params.to });
396
396
  if (!admission.allow) {
397
- const decision = appContactAdmissionActive(params.aid) ? evaluateAppContactAdmission(params.aid, params.to) : undefined;
398
- const canRequestOwner = !!decision && (decision.reason === 'not_in_contacts' || decision.reason === 'scope_extension')
399
- && !params.file && params.returnPolicy !== 'required' && contactIntroductionText(params.payload) !== undefined;
400
- if (!canRequestOwner || typeof ch.requestOutboundContact !== 'function') {
401
- return { ok: false, error: admission.error, code: admission.code, sent: false };
402
- }
403
- try {
404
- // Retries of the same task message share an event; never queue the original peer send.
405
- const sourceMessageId = 'outbound-' + crypto.createHash('sha256').update(JSON.stringify([
406
- params.originSessionId, params.originMessageId, params.to, contactIntroductionText(params.payload),
407
- ])).digest('hex');
408
- const request = await ch.requestOutboundContact({ to: params.to, payload: params.payload, sourceMessageId });
409
- if (!request.ok)
410
- return { ok: false, code: request.code, error: request.error, sent: false };
411
- const receipt = request.receipt;
412
- return { ok: false, code: 'CONTACT_APPROVAL_REQUIRED', sent: false, retryable: false,
413
- error: `目标 ${params.to} 未准入,${receipt.status === 'sent' ? '已向' : '已排队向'}本端 Owner ${receipt.owner_aid} 提交联系申请,等待审批;原消息未发送`,
414
- contact_request: receipt };
415
- }
416
- catch (error) {
417
- return { ok: false, code: 'CONTACT_OWNER_REQUEST_FAILED', sent: false,
418
- error: `向本端 Owner 提交联系申请失败:${error instanceof Error ? error.message : String(error)};原消息未发送` };
397
+ const decision = evaluateAppContactAdmission(params.aid, params.to);
398
+ const friendInvite = params.rawPayload === true && params.encrypt === true
399
+ && parseFriendInvite(params.payload, params.aid, params.to);
400
+ const inviteMayRequestContact = !!friendInvite
401
+ && (decision?.reason === 'not_in_contacts' || admission.code === 'CONTACT_ALL_CONTACTS_DISABLED');
402
+ if (!inviteMayRequestContact) {
403
+ const canRequestOwner = !!decision && (decision.reason === 'not_in_contacts' || decision.reason === 'scope_extension')
404
+ && !params.file && params.returnPolicy !== 'required' && contactIntroductionText(params.payload) !== undefined;
405
+ if (!canRequestOwner || typeof ch.requestOutboundContact !== 'function') {
406
+ return { ok: false, error: admission.error, code: admission.code, sent: false };
407
+ }
408
+ try {
409
+ // Retries of the same task message share an event; never queue the original peer send.
410
+ const sourceMessageId = 'outbound-' + crypto.createHash('sha256').update(JSON.stringify([
411
+ params.originSessionId, params.originMessageId, params.to, contactIntroductionText(params.payload),
412
+ ])).digest('hex');
413
+ const request = await ch.requestOutboundContact({ to: params.to, payload: params.payload, sourceMessageId });
414
+ if (!request.ok)
415
+ return { ok: false, code: request.code, error: request.error, sent: false };
416
+ const receipt = request.receipt;
417
+ return { ok: false, code: 'CONTACT_APPROVAL_REQUIRED', sent: false, retryable: false,
418
+ error: `目标 ${params.to} 未准入,${receipt.status === 'sent' ? '已向' : '已排队向'}本端 Owner ${receipt.owner_aid} 提交联系申请,等待审批;原消息未发送`,
419
+ contact_request: receipt };
420
+ }
421
+ catch (error) {
422
+ return { ok: false, code: 'CONTACT_OWNER_REQUEST_FAILED', sent: false,
423
+ error: `向本端 Owner 提交联系申请失败:${error instanceof Error ? error.message : String(error)};原消息未发送` };
424
+ }
419
425
  }
420
426
  }
421
427
  }
@@ -424,7 +430,7 @@ export function registerAunIpcSender({ ipcServer, channelInstances, agentDelegat
424
430
  // look group-like and a group identifier may use a future format.
425
431
  const encrypt = typeof params.encrypt === 'boolean'
426
432
  ? params.encrypt
427
- : (typeof ch.getDefaultEncrypt === 'function' ? ch.getDefaultEncrypt() : true);
433
+ : (typeof ch.getDefaultEncrypt === 'function' ? ch.getDefaultEncrypt() : false);
428
434
  let payload = params.payload;
429
435
  if (params.file) {
430
436
  if (isHClassPath(params.file.filePath) && !fullAccess) {
@@ -101,24 +101,6 @@ export function saveIsolatedContactSource(selfAid, aid, mid, source) {
101
101
  export function contactSourceDigest(payload) {
102
102
  return crypto.createHash('sha256').update(JSON.stringify(payload) ?? 'undefined').digest('hex');
103
103
  }
104
- export function appContactAdmissionEnabled(selfAid) {
105
- return readAccessPolicy(selfAid).contactAdmission === 'app-v1';
106
- }
107
- /**
108
- * app-v1 是否真正生效:配置已开启**且**当前 Ownership 能给出共识绑定。
109
- *
110
- * app-v1 的判定全部建立在 relation_version 之上;没有绑定(单边关系、未签署声明、
111
- * Ownership 暂不可用)时无法判定,此时必须退回 legacy 规则,而不是把所有人判成
112
- * unavailable 后静默丢信。旧格式授权由 OwnerDirectoryCache 的兼容读取放行,
113
- * 因此 legacy 规则对既有授权仍然有效。
114
- *
115
- * 绑定新鲜度不参与这里的判定:准入链路上反复核验 Ownership 既昂贵又会把健康关系
116
- * 误判成不可用。共识只在显式事件(ownership 变更、agent.md/owner.md 变化、配置
117
- * Owner 变化、断线过期)到达时被 invalidate,届时绑定自然消失并回退 legacy。
118
- */
119
- export function appContactAdmissionActive(selfAid) {
120
- return appContactAdmissionEnabled(selfAid) && !!currentContactBinding(selfAid);
121
- }
122
104
  /**
123
105
  * 当前生效的共识绑定,不要求授权处在 5 分钟窗口内。
124
106
  *
@@ -449,7 +431,7 @@ export function parseFriendInvite(payload, senderAid, selfAid) {
449
431
  if (!Number.isSafeInteger(value.created_at_ms) || value.created_at_ms <= 0
450
432
  || value.expires_at_ms !== value.created_at_ms + FRIEND_INVITE_TTL_MS)
451
433
  return undefined;
452
- if (typeof value.introduction !== 'string' || !value.introduction.trim())
434
+ if (typeof value.introduction !== 'string' || !value.introduction.trim() || value.introduction.includes('\0'))
453
435
  return undefined;
454
436
  return { invite_id: value.invite_id, applicant_aid: senderAid, target_aid: selfAid,
455
437
  created_at_ms: value.created_at_ms, expires_at_ms: value.expires_at_ms, introduction: value.introduction };
@@ -6,6 +6,7 @@ import { tagErrorTextWithEvolcoreVersion } from '../../utils/evolcore-version.js
6
6
  import { DEFAULT_FLUSH_DELAY_MS } from '../../types.js';
7
7
  import { classifyAunToolErrorCode, normalizeToolErrorClassification } from '../permission/tool-error-code.js';
8
8
  import { foldSubtaskTerminal } from './subtask-tool-projection.js';
9
+ import { isNoopText, mayBeNoopText } from './message-utils.js';
9
10
  function toolApprovalMetadata(event) {
10
11
  if (!event || event.executed !== false || !event.decisionSource || event.decisionSource === 'runner')
11
12
  return {};
@@ -117,10 +118,12 @@ export class IMRenderer {
117
118
  if (isFinal) {
118
119
  const pending = this.deferredProactiveText;
119
120
  this.deferredProactiveText = [];
120
- if (pending.map(item => item.text).join('').trim() !== this.opts.noopSentinel) {
121
+ if (!this.opts.noopSentinel || !isNoopText(pending.map(item => item.text).join(''), this.opts.noopSentinel)) {
121
122
  for (const item of pending) {
122
123
  this.recordActivity(item);
123
- await this.sendPayload({ kind: 'activity.batch', items: [item] });
124
+ if (!this.suppressProactiveItem(item)) {
125
+ await this.sendPayload({ kind: 'activity.batch', items: [item] });
126
+ }
124
127
  }
125
128
  }
126
129
  }
@@ -139,11 +142,11 @@ export class IMRenderer {
139
142
  }
140
143
  /** 是否有 pending 内容 */
141
144
  hasContent() {
142
- return this.textBuffer.length > 0 || this.deferredProactiveText.length > 0 || this.itemsQueue.some(it => it.kind !== 'text') || this.hasHeldToolResults();
145
+ return !!this.pendingAutomaticText || this.textBuffer.length > 0 || this.deferredProactiveText.length > 0 || this.itemsQueue.some(it => it.kind !== 'text') || this.hasHeldToolResults();
143
146
  }
144
147
  /** 是否有会抑制兜底错误消息的正文/过程内容;lifecycle 边界不算。 */
145
148
  hasNonLifecycleContent() {
146
- return this.textBuffer.trim().length > 0 || this.hasHeldToolResults() || this.itemsQueue.some(it => {
149
+ return !!this.pendingAutomaticText || this.textBuffer.trim().length > 0 || this.hasHeldToolResults() || this.itemsQueue.some(it => {
147
150
  if (it.kind === 'text')
148
151
  return it.text.trim().length > 0;
149
152
  if (this.subtaskItems.has(it))
@@ -159,12 +162,14 @@ export class IMRenderer {
159
162
  }
160
163
  /** 是否有待发送的文本 */
161
164
  hasTextPending() {
162
- return this.textBuffer.length > 0;
165
+ return !!this.pendingAutomaticText || this.textBuffer.length > 0;
163
166
  }
164
167
  /** flush 当前 textBuffer 作为独立的 result.text(非 final),然后清空 buffer */
165
168
  async flushText() {
166
169
  if (this.opts.envelope.chatmode === 'proactive')
167
170
  return;
171
+ if (this.pendingAutomaticText)
172
+ await this.retryAutomaticText();
168
173
  if (this.textBuffer.length === 0)
169
174
  return;
170
175
  // 文件标记过滤后若只剩空白,应立即消费;尤其避免 final-only
@@ -186,6 +191,8 @@ export class IMRenderer {
186
191
  this.itemsQueue = this.itemsQueue.filter(it => it.kind !== 'text');
187
192
  return;
188
193
  }
194
+ if (this.opts.noopSentinel && mayBeNoopText(rawText, this.opts.noopSentinel))
195
+ return;
189
196
  if (this.timer) {
190
197
  clearTimeout(this.timer);
191
198
  this.timer = undefined;
@@ -205,7 +212,8 @@ export class IMRenderer {
205
212
  }
206
213
  catch (error) {
207
214
  // A failed durable enqueue must remain retryable by the final flush.
208
- this.textBuffer = rawText + this.textBuffer;
215
+ if (this.opts.envelope.chatmode !== 'paactive')
216
+ this.textBuffer = rawText + this.textBuffer;
209
217
  throw error;
210
218
  }
211
219
  this.lastFlush = Date.now();
@@ -229,6 +237,7 @@ export class IMRenderer {
229
237
  this.textBuffer = '';
230
238
  this.allText = '';
231
239
  this.deferredProactiveText = [];
240
+ this.pendingAutomaticText = undefined;
232
241
  }
233
242
  /** 仅丢弃尚未发送的正文,保留 notice/tool 等活动项。 */
234
243
  discardPendingText() {
@@ -239,10 +248,11 @@ export class IMRenderer {
239
248
  this.itemsQueue = this.itemsQueue.filter(it => it.kind !== 'text');
240
249
  this.textBuffer = '';
241
250
  this.deferredProactiveText = [];
251
+ this.pendingAutomaticText = undefined;
242
252
  }
243
253
  /** 当前 buffer 中尚未 flush 的文本 */
244
254
  getRemainingText() {
245
- return this.textBuffer;
255
+ return (this.pendingAutomaticText?.item.text ?? '') + this.textBuffer;
246
256
  }
247
257
  // ── 文本/活动注入(替代 StreamFlusher.addText/addActivity)──
248
258
  /** 添加文本片段(流式 text) */
@@ -609,21 +619,16 @@ export class IMRenderer {
609
619
  this.messageTimestamps.push(Date.now());
610
620
  this.scheduleFlush();
611
621
  }
612
- /** interactive 下,以普通非最终文本发送用户需要看到的运行状态。 */
613
- async sendOperationalNoticeAsText(text) {
614
- if (!this.opts.operationalNoticesAsText || this.opts.envelope.chatmode === 'proactive' || !text)
622
+ /** 通过系统通知发送运行状态,并保持与已有正文的发送顺序。 */
623
+ async sendOperationalNotice(text, subtype) {
624
+ if (!this.opts.operationalNoticesEnabled || this.opts.envelope.chatmode === 'proactive' || !text)
615
625
  return false;
616
626
  if (!this.hasSendableText(text, 'operational-notice'))
617
627
  return false;
618
628
  // 保持与流式正文的到达顺序:先发出已缓冲的正文,再投影运行状态。
619
629
  await this.flushText();
620
- const payload = {
621
- kind: 'result.text',
622
- text,
623
- isFinal: false,
624
- };
625
630
  this.sentContent = true;
626
- await this.sendAutomaticText(payload);
631
+ await this.sendSystemNotice(text, subtype);
627
632
  this.lastFlush = Date.now();
628
633
  this.flushCount++;
629
634
  return true;
@@ -707,33 +712,50 @@ export class IMRenderer {
707
712
  this.sendChain = handled.catch(() => { });
708
713
  return handled;
709
714
  }
710
- /** Model output and renderer text notices share PA's automatic-text outlet.
711
- * Explicit sends, command receipts and interaction fallbacks bypass it.
715
+ /** Model output uses PA's automatic-text outlet.
716
+ * System notices, explicit sends, command receipts and interaction fallbacks bypass it.
712
717
  */
713
718
  async sendAutomaticText(payload) {
719
+ if (this.opts.noopSentinel && isNoopText(payload.text, this.opts.noopSentinel))
720
+ return;
714
721
  if (this.opts.envelope.chatmode !== 'paactive')
715
722
  return this.sendPayload(payload);
716
- const signature = JSON.stringify([
717
- payload.text,
718
- payload.metadata?.forkAnchor?.assistantMessageId,
719
- ]);
720
- const pending = this.pendingAutomaticText?.signature === signature
721
- ? this.pendingAutomaticText
722
- : undefined;
723
- const item = pending?.item ?? {
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 = {
724
736
  kind: 'text',
725
737
  text: payload.text,
726
738
  ...(payload.metadata?.forkAnchor ? { forkAnchor: payload.metadata.forkAnchor } : {}),
727
739
  };
728
- const activityId = pending?.activityId
729
- ?? `activity-${randomUUID().replace(/-/g, '')}`;
730
- if (!pending) {
731
- this.recordActivity(item, activityId);
732
- this.pendingAutomaticText = { signature, item, activityId };
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
+ });
733
757
  }
734
- await this.sendPayload({ kind: 'activity.batch', items: [item] });
735
- if (this.pendingAutomaticText?.activityId === activityId)
736
- this.pendingAutomaticText = undefined;
758
+ return pending.delivery;
737
759
  }
738
760
  scheduleFlush() {
739
761
  if (this.timer) {
@@ -780,6 +802,8 @@ export class IMRenderer {
780
802
  const nonThinking = this.itemsQueue.filter(it => it.kind !== 'text');
781
803
  if (nonThinking.length === 0)
782
804
  return;
805
+ if (this.pendingAutomaticText)
806
+ await this.retryAutomaticText();
783
807
  if (this.timer) {
784
808
  clearTimeout(this.timer);
785
809
  this.timer = undefined;
@@ -814,6 +838,8 @@ export class IMRenderer {
814
838
  clearTimeout(this.timer);
815
839
  this.timer = undefined;
816
840
  }
841
+ if (this.pendingAutomaticText)
842
+ await this.retryAutomaticText();
817
843
  // 显式 flush(轮次结束、出错收尾)时放出被扣住的后台占位结果;定时 flush 不放,
818
844
  // 否则长时间后台任务会在终态到达前就把占位结果发出去。放出的结果随本次 flush 一起发,
819
845
  // 不需要它重新挂上的定时器。
@@ -835,7 +861,7 @@ export class IMRenderer {
835
861
  item.text = item.text.replace(this.opts.fileMarkerPattern, '');
836
862
  }
837
863
  }
838
- if (isFinal && this.textBuffer.trim() === this.opts.noopSentinel) {
864
+ if (isFinal && this.opts.noopSentinel && isNoopText(this.textBuffer, this.opts.noopSentinel)) {
839
865
  this.discardPendingText();
840
866
  }
841
867
  else if (!this.hasSendableText(this.textBuffer, isFinal ? 'final' : 'flush')) {
@@ -883,6 +909,8 @@ export class IMRenderer {
883
909
  if (!isFinal && this.textBuffer.length > 0) {
884
910
  if (this.suppressIntermediateText())
885
911
  return;
912
+ if (this.opts.noopSentinel && mayBeNoopText(this.textBuffer, this.opts.noopSentinel))
913
+ return;
886
914
  // A timer cannot decide whether this is the final answer. Keep it for
887
915
  // an explicit boundary; known commentary can still be sent immediately.
888
916
  if (scheduled && this.opts.deferTextUntilBoundary && this.currentTextPhase !== 'commentary')
@@ -900,7 +928,8 @@ export class IMRenderer {
900
928
  await this.sendAutomaticText(payload);
901
929
  }
902
930
  catch (error) {
903
- this.textBuffer = text + this.textBuffer;
931
+ if (this.opts.envelope.chatmode !== 'paactive')
932
+ this.textBuffer = text + this.textBuffer;
904
933
  throw error;
905
934
  }
906
935
  this.lastFlush = Date.now();
@@ -921,7 +950,8 @@ export class IMRenderer {
921
950
  await this.sendAutomaticText(payload);
922
951
  }
923
952
  catch (error) {
924
- this.textBuffer = finalText + this.textBuffer;
953
+ if (this.opts.envelope.chatmode !== 'paactive')
954
+ this.textBuffer = finalText + this.textBuffer;
925
955
  throw error;
926
956
  }
927
957
  this.lastFlush = Date.now();
@@ -1020,11 +1050,15 @@ export class IMRenderer {
1020
1050
  }
1021
1051
  /** proactive:单个 ThoughtItem 包成 activity.batch[1] 发出。 */
1022
1052
  emitProactiveItem(item) {
1023
- if (this.opts.noopSentinel && (item.kind === 'text' || (item.kind === 'summary' && !item.is_error))) {
1024
- this.deferredProactiveText.push(item);
1025
- return;
1053
+ if (item.kind === 'text' || (item.kind === 'summary' && !item.is_error)) {
1054
+ if (this.opts.noopSentinel || this.deferredProactiveText.length > 0) {
1055
+ this.deferredProactiveText.push(item);
1056
+ return;
1057
+ }
1026
1058
  }
1027
1059
  this.recordActivity(item);
1060
+ if (this.suppressProactiveItem(item))
1061
+ return;
1028
1062
  const evolCommand = item.kind === 'tool_call' ? item.evolCommand : undefined;
1029
1063
  const payload = evolCommand
1030
1064
  ? { kind: 'activity.batch', items: [item], ext: { evolCommand } }
@@ -1033,6 +1067,13 @@ export class IMRenderer {
1033
1067
  logger.debug(`[IMRenderer] proactive send failed: ${err.message}`);
1034
1068
  });
1035
1069
  }
1070
+ suppressProactiveItem(item) {
1071
+ if (item.kind === 'text' || item.kind === 'summary') {
1072
+ // noopSentinel only defers text until its full prefix can be checked.
1073
+ return this.opts.suppressIntermediateText ?? this.opts.suppressActivities ?? false;
1074
+ }
1075
+ return this.suppressActivityItems();
1076
+ }
1036
1077
  mapEventToItem(event) {
1037
1078
  switch (event.type) {
1038
1079
  case 'text':