evolcore 0.0.43-test.1 → 0.0.43-test.3

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 (200) hide show
  1. package/CHANGELOG.md +31 -1
  2. package/README.md +22 -0
  3. package/dist/agents/claude-runner.js +26 -2
  4. package/dist/agents/codex/app-server-client.js +12 -0
  5. package/dist/agents/codex-runner.js +49 -8
  6. package/dist/agents/ecagent-runner.js +39 -15
  7. package/dist/agents/gemini-runner.js +15 -12
  8. package/dist/agents/tool-time-context.js +55 -0
  9. package/dist/aun/aid/agentmd.js +21 -1
  10. package/dist/aun/menu/client.js +1 -1
  11. package/dist/aun/model-headers.js +17 -0
  12. package/dist/aun/msg/p2p.js +7 -2
  13. package/dist/channels/aun.js +522 -50
  14. package/dist/channels/builtin-plugins.js +16 -11
  15. package/dist/channels/daemon.js +4 -0
  16. package/dist/channels/dingtalk.js +83 -31
  17. package/dist/channels/feishu.js +29 -13
  18. package/dist/channels/qqbot.js +32 -11
  19. package/dist/channels/wechat.js +13 -3
  20. package/dist/channels/wecom.js +67 -27
  21. package/dist/cli/agent-command.js +3 -86
  22. package/dist/cli/agent-create.js +20 -6
  23. package/dist/cli/agent.js +1 -79
  24. package/dist/cli/aun-commands.js +18 -19
  25. package/dist/cli/config.js +1 -1
  26. package/dist/cli/daemon-commands.js +47 -2
  27. package/dist/cli/data-command.js +9 -1
  28. package/dist/cli/debug-mode.js +1 -1
  29. package/dist/cli/diag.js +1 -1
  30. package/dist/cli/directory.js +149 -91
  31. package/dist/cli/getmeta-command.js +1 -1
  32. package/dist/cli/index.js +79 -22
  33. package/dist/cli/init.js +1 -23
  34. package/dist/cli/link-rules.js +1 -1
  35. package/dist/cli/managed-command-guard.js +0 -1
  36. package/dist/cli/pa-workspace-command.js +36 -2
  37. package/dist/cli/peer.js +3 -2
  38. package/dist/cli/restart-monitor.js +17 -3
  39. package/dist/cli/role.js +1 -1
  40. package/dist/cli/session-command.js +1 -1
  41. package/dist/cli/stats.js +2 -2
  42. package/dist/cli/task-context.js +3 -1
  43. package/dist/cli/thread-command.js +1 -1
  44. package/dist/cli/watch-msg.js +1 -1
  45. package/dist/config/builtin-role-templates.js +2 -2
  46. package/dist/config/builtin-roles.js +2 -1
  47. package/dist/config/config-field-policy.js +7 -2
  48. package/dist/config/config-manager.js +32 -10
  49. package/dist/config/peer-role-resolver.js +23 -1
  50. package/dist/config/role-schema.js +29 -4
  51. package/dist/config/role-service.js +12 -7
  52. package/dist/config/role-store.js +30 -8
  53. package/dist/config-store.js +75 -4
  54. package/dist/core/agent-ipc-registration.js +16 -59
  55. package/dist/core/auth/auth-gateway.js +14 -4
  56. package/dist/core/auth/authorization-audit.js +52 -14
  57. package/dist/core/auth/operation-authorizer.js +17 -11
  58. package/dist/core/auth/operation-catalog.js +5 -13
  59. package/dist/core/channel-loader.js +152 -16
  60. package/dist/core/channel-runtime.js +5 -0
  61. package/dist/core/command/agent-control.js +2 -1
  62. package/dist/core/command/agentmd-menu-request.js +50 -0
  63. package/dist/core/command/agentmd-menu.js +156 -0
  64. package/dist/core/command/cli-intent-parser.js +0 -8
  65. package/dist/core/command/command-handler.js +47 -40
  66. package/dist/core/command/connect-menu.js +7 -3
  67. package/dist/core/command/menu-catalog.js +16 -2
  68. package/dist/core/command/menu-handler.js +107 -14
  69. package/dist/core/command/menu-protocol.js +28 -0
  70. package/dist/core/command/role-menu.js +23 -9
  71. package/dist/core/command/slash-handler.js +139 -51
  72. package/dist/core/daemon-file-cache.js +3 -3
  73. package/dist/core/daemon-lifecycle.js +9 -1
  74. package/dist/core/evolagent-registry.js +5 -4
  75. package/dist/core/evolagent.js +10 -12
  76. package/dist/core/handoff/argv-parse.js +115 -0
  77. package/dist/core/handoff/ipc-registration.js +1 -1
  78. package/dist/core/ipc-registration.js +19 -2
  79. package/dist/core/lifecycle-notice.js +185 -0
  80. package/dist/core/memory/consolidation.js +8 -1
  81. package/dist/core/memory/relation-sweep.js +20 -8
  82. package/dist/core/message/aun-ipc-sender.js +35 -2
  83. package/dist/core/message/contact-admission.js +530 -0
  84. package/dist/core/message/im-renderer.js +111 -16
  85. package/dist/core/message/message-admission.js +29 -54
  86. package/dist/core/message/message-bridge.js +62 -8
  87. package/dist/core/message/message-utils.js +9 -5
  88. package/dist/core/message/peer-mode.js +55 -13
  89. package/dist/core/message/response-engine.js +298 -78
  90. package/dist/core/message/retry-scheduler.js +4 -0
  91. package/dist/core/ownership/owner-resolver.js +72 -34
  92. package/dist/core/permission/ec-command-parser.js +25 -38
  93. package/dist/core/permission/readonly-shell-query.js +34 -8
  94. package/dist/core/permission/tool-policy.js +50 -5
  95. package/dist/core/relation/pa-team.js +127 -0
  96. package/dist/core/role/runtime-policy.js +18 -5
  97. package/dist/core/session/session-manager.js +9 -1
  98. package/dist/core/soul.js +66 -0
  99. package/dist/core/system-session/memory.js +2 -2
  100. package/dist/core/thread/thread-service.js +6 -4
  101. package/dist/directory/contact-admission-paths.js +9 -0
  102. package/dist/directory/owner-directory-admission.js +125 -29
  103. package/dist/directory/owner-directory-cache.js +554 -58
  104. package/dist/directory/owner-directory-identity.js +60 -0
  105. package/dist/directory/owner-directory-markdown.js +154 -58
  106. package/dist/directory/owner-directory-policy.js +108 -0
  107. package/dist/directory/owner-directory-query-operation.js +399 -90
  108. package/dist/directory/owner-directory-remarks.js +29 -2
  109. package/dist/directory/owner-directory-request-operation.js +76 -0
  110. package/dist/directory/owner-directory-scope.js +35 -4
  111. package/dist/directory/owner-directory-search.js +118 -33
  112. package/dist/directory/owner-directory-store.js +117 -30
  113. package/dist/directory/owner-directory-text.js +60 -0
  114. package/dist/eck/kit-renderer.js +18 -8
  115. package/dist/eck/manifest-engine.js +55 -6
  116. package/dist/ecweb/basic-settings-service.js +2 -2
  117. package/dist/ecweb/message-context-service.js +28 -16
  118. package/dist/index.js +20 -5
  119. package/dist/ipc.js +1 -1
  120. package/dist/paths.js +29 -1
  121. package/dist/product.js +1 -0
  122. package/dist/response-system/config-resolver.js +1 -1
  123. package/dist/response-system/engines/v1/index.js +2 -1
  124. package/dist/response-system/modes/single-session/index.js +7 -2
  125. package/dist/trigger/scheduler.js +7 -4
  126. package/dist/trigger/validation.js +4 -0
  127. package/dist/utils/error-utils.js +12 -7
  128. package/dist/utils/logger.js +13 -4
  129. package/dist/utils/npm-ops.js +2 -2
  130. package/dist/utils/windows-autostart.js +1 -1
  131. package/ecagent/README.md +18 -0
  132. package/ecagent/dist/agent-loop.js +43 -1
  133. package/ecagent/dist/harness/agent-harness.d.ts +2 -0
  134. package/ecagent/dist/harness/agent-harness.js +24 -8
  135. package/ecagent/dist/harness/compaction/compaction.js +3 -0
  136. package/ecagent/dist/harness/types.d.ts +1 -0
  137. package/kits/docs/INDEX.md +1 -0
  138. package/kits/docs/channels/aun.md +1 -1
  139. package/kits/docs/context-assembly.md +21 -6
  140. package/kits/docs/eck_templates/INDEX.template.md +1 -2
  141. package/kits/docs/evolcore/INDEX.md +4 -1
  142. package/kits/docs/evolcore/agent-create.md +5 -5
  143. package/kits/docs/evolcore/agent.md +4 -9
  144. package/kits/docs/evolcore/directory.md +227 -0
  145. package/kits/docs/evolcore/ecweb-lifecycle.md +26 -0
  146. package/kits/docs/evolcore/file-navigation.md +265 -0
  147. package/kits/docs/evolcore/menu-protocol.md +55 -0
  148. package/kits/docs/evolcore/msg.md +1 -0
  149. package/kits/docs/evolcore/peer.md +2 -1
  150. package/kits/docs/evolcore/response.md +7 -1
  151. package/kits/docs/evolcore/task.md +2 -0
  152. package/kits/docs/evolcore/tool-authorization.md +1 -1
  153. package/kits/docs/evolcore/trigger.md +4 -0
  154. package/kits/docs/identity/ROLE_DETAIL.md +2 -0
  155. package/kits/docs/prompt-loading-architecture.md +6 -2
  156. package/kits/eck_manifest.auxiliary.json +1 -0
  157. package/kits/eck_manifest.json +64 -7
  158. package/kits/eck_manifest.memory.json +93 -4
  159. package/kits/rules/01-overview.md +2 -2
  160. package/kits/rules/03-identity.md +10 -9
  161. package/kits/rules/05-venue.md +2 -4
  162. package/kits/rules/06-channel.md +1 -1
  163. package/kits/schemas/_meta.json +44 -3
  164. package/kits/schemas/agent-config.schema.18.json +5 -0
  165. package/kits/schemas/agent-config.schema.19.json +924 -0
  166. package/kits/schemas/agent-config.schema.20.json +925 -0
  167. package/kits/schemas/relation-config.schema.12.json +289 -0
  168. package/kits/schemas/relation-config.schema.13.json +289 -0
  169. package/kits/schemas/role-config.schema.2.json +215 -0
  170. package/kits/schemas/role-config.schema.3.json +1038 -0
  171. package/kits/schemas/role-registry.schema.1.json +3 -2
  172. package/kits/skills/ec-skill/scripts/cli.mjs +3 -2
  173. package/kits/skills/ec-trigger/SKILL.md +4 -4
  174. package/kits/skills/personal-assistant/SKILL.md +109 -53
  175. package/kits/skills/personal-assistant/references/02-bootstrap.md +73 -30
  176. package/kits/skills/personal-assistant/scripts/clean.mjs +35 -18
  177. package/kits/skills/personal-assistant/scripts/init.mjs +41 -2
  178. package/kits/skills/personal-assistant/scripts/lib/persona.mjs +185 -0
  179. package/kits/skills/personal-assistant/scripts/migrate.mjs +55 -4
  180. package/kits/skills/personal-assistant/scripts/pa.mjs +173 -0
  181. package/kits/skills/personal-assistant/scripts/uninstall.mjs +130 -0
  182. package/kits/skills/personal-assistant/templates/persona-section.md +3 -3
  183. package/kits/templates/message-fragments/handoff-request-to-target.md +1 -1
  184. package/kits/templates/soul/00-GUIDE.md +39 -0
  185. package/kits/templates/soul/01-identity.md +5 -0
  186. package/kits/templates/soul/02-persona.md +11 -0
  187. package/kits/templates/soul/03-duties.md +5 -0
  188. package/kits/templates/soul/04-working-style.md +5 -0
  189. package/kits/templates/system-fragments/bootstrap.md +7 -7
  190. package/kits/templates/system-fragments/channel.md +2 -2
  191. package/kits/templates/system-fragments/commands.md +3 -2
  192. package/kits/templates/system-fragments/directory-contacts.md +9 -0
  193. package/kits/templates/system-fragments/memory.md +1 -1
  194. package/kits/templates/system-fragments/personal-assistant.md +50 -0
  195. package/kits/templates/system-fragments/reply.md +7 -0
  196. package/kits/templates/system-fragments/session.md +6 -2
  197. package/package.json +3 -2
  198. package/dist/cli/handoff-command.js +0 -353
  199. package/dist/directory/owner-directory-remark-operation.js +0 -147
  200. package/kits/docs/evolcore/self-summary.md +0 -29
@@ -495,6 +495,8 @@ export class WechatChannel {
495
495
  }
496
496
  throw err;
497
497
  }
498
+ if (signal.aborted)
499
+ return;
498
500
  // 更新服务端建议的轮询超时
499
501
  if (resp.longpolling_timeout_ms != null && resp.longpolling_timeout_ms > 0) {
500
502
  nextTimeoutMs = resp.longpolling_timeout_ms;
@@ -521,7 +523,9 @@ export class WechatChannel {
521
523
  }
522
524
  // 处理消息
523
525
  for (const msg of resp.msgs ?? []) {
524
- await this.handleInboundMessage(msg);
526
+ if (signal.aborted)
527
+ return;
528
+ await this.handleInboundMessage(msg, signal);
525
529
  }
526
530
  }
527
531
  catch (err) {
@@ -579,7 +583,9 @@ export class WechatChannel {
579
583
  }
580
584
  }
581
585
  // ── Inbound Message Handler ──────────────────────────────────────────
582
- async handleInboundMessage(msg) {
586
+ async handleInboundMessage(msg, signal) {
587
+ if (signal?.aborted)
588
+ return;
583
589
  if (msg.message_type !== MSG_TYPE_USER)
584
590
  return;
585
591
  const fromUserId = msg.from_user_id ?? '';
@@ -597,6 +603,8 @@ export class WechatChannel {
597
603
  const text = extractTextFromMessage(msg);
598
604
  // 提取媒体 → 下载
599
605
  const media = await this.extractMedia(msg, fromUserId);
606
+ if (signal?.aborted)
607
+ return;
600
608
  // 合成最终内容
601
609
  const finalContent = media.prompt
602
610
  ? (text ? `${text}\n\n${media.prompt}` : media.prompt)
@@ -608,10 +616,12 @@ export class WechatChannel {
608
616
  this.acknowledgeMessage(fromUserId, msg.context_token).catch(() => { });
609
617
  // 首次交互欢迎消息(使用共享帮助函数)
610
618
  await sendWelcomeIfNeeded(this.welcomeManager, fromUserId, fromUserId, (id, text) => this.sendMessage(id, text), 'WeChat');
619
+ if (signal?.aborted)
620
+ return;
611
621
  // 回调主流程
612
622
  if (this.messageHandler) {
613
623
  const task = Promise.resolve()
614
- .then(() => this.messageHandler(fromUserId, finalContent || '', fromUserId, media.images.length ? media.images : undefined, 'private'))
624
+ .then(() => signal?.aborted ? undefined : this.messageHandler(fromUserId, finalContent || '', fromUserId, media.images.length ? media.images : undefined, 'private'))
615
625
  .catch(err => {
616
626
  logger.error('[WeChat] Message handler error:', err);
617
627
  });
@@ -485,6 +485,7 @@ export class WecomChannel {
485
485
  config;
486
486
  client = null;
487
487
  connectionState = 'idle';
488
+ connectionGeneration = 0;
488
489
  lastConnectionError;
489
490
  messageHandler = null;
490
491
  seenMessages = new Map();
@@ -551,11 +552,16 @@ export class WecomChannel {
551
552
  }
552
553
  }
553
554
  async connectOnce() {
555
+ this.lifecycle?.assertActive();
556
+ const generation = ++this.connectionGeneration;
554
557
  const { botId, secret } = this.config;
555
558
  if (!botId || !secret) {
556
559
  throw new Error('WeCom botId/secret not configured');
557
560
  }
558
- const sdk = await requireOptional('@wecom/aibot-node-sdk');
561
+ const sdk = await requireOptional('@wecom/aibot-node-sdk', false);
562
+ if (generation !== this.connectionGeneration)
563
+ throw new Error('wecom connection cancelled');
564
+ this.lifecycle?.assertActive();
559
565
  this.connectionState = 'connecting';
560
566
  this.lastConnectionError = undefined;
561
567
  const client = new sdk.WSClient({
@@ -662,11 +668,18 @@ export class WecomChannel {
662
668
  }
663
669
  throw error;
664
670
  }
671
+ if (generation !== this.connectionGeneration || this.client !== client
672
+ || (this.lifecycle && this.lifecycle.state !== 'active')) {
673
+ this.removeClientListeners(client);
674
+ client.disconnect();
675
+ return;
676
+ }
665
677
  // Hourly cleanup of old dedup entries
666
678
  this.startCleanupTask();
667
679
  logger.info('[WeCom] Channel connected');
668
680
  }
669
681
  async disconnect() {
682
+ this.connectionGeneration++;
670
683
  this.connectionState = 'idle';
671
684
  this.cancelAuthenticationWait?.(new Error('WeCom connection cancelled'));
672
685
  if (this.cleanupInterval) {
@@ -706,6 +719,12 @@ export class WecomChannel {
706
719
  : setInterval(cleanup, 60 * 60 * 1000);
707
720
  }
708
721
  listenClient(client, event, listener) {
722
+ const callback = listener;
723
+ listener = (...args) => {
724
+ if (this.client !== client || (this.lifecycle && this.lifecycle.state !== 'active'))
725
+ return;
726
+ callback(...args);
727
+ };
709
728
  client.on(event, listener);
710
729
  const listeners = this.clientListeners.get(client) ?? [];
711
730
  listeners.push({ event, listener });
@@ -720,7 +739,11 @@ export class WecomChannel {
720
739
  client.off(event, listener);
721
740
  }
722
741
  onMessage(handler) {
723
- this.messageHandler = handler;
742
+ this.messageHandler = async (event) => {
743
+ if (this.lifecycle && this.lifecycle.state !== 'active')
744
+ return;
745
+ await handler(event);
746
+ };
724
747
  }
725
748
  onProjectPathRequest(provider) {
726
749
  this.projectPathProvider = provider;
@@ -782,6 +805,8 @@ export class WecomChannel {
782
805
  async waitForAuthentication(client, timeoutMs) {
783
806
  if (this.connectionState === 'authenticated')
784
807
  return;
808
+ if (this.client !== client || this.lifecycle?.signal.aborted)
809
+ throw new Error('WeCom connection cancelled');
785
810
  await new Promise((resolve, reject) => {
786
811
  let settled = false;
787
812
  const finish = (error) => {
@@ -792,6 +817,7 @@ export class WecomChannel {
792
817
  client.off('authenticated', onAuthenticated);
793
818
  client.off('error', onError);
794
819
  client.off('disconnected', onDisconnected);
820
+ this.lifecycle?.signal.removeEventListener('abort', onAbort);
795
821
  if (this.cancelAuthenticationWait === cancel)
796
822
  this.cancelAuthenticationWait = undefined;
797
823
  if (error)
@@ -800,6 +826,7 @@ export class WecomChannel {
800
826
  resolve();
801
827
  };
802
828
  const cancel = (error) => finish(error);
829
+ const onAbort = () => cancel(new Error('WeCom connection cancelled'));
803
830
  const onAuthenticated = () => finish();
804
831
  const onError = (error) => {
805
832
  if (isWecomAuthError(error))
@@ -813,7 +840,10 @@ export class WecomChannel {
813
840
  client.on('error', onError);
814
841
  client.on('disconnected', onDisconnected);
815
842
  this.cancelAuthenticationWait = cancel;
816
- if (this.connectionState === 'authenticated')
843
+ this.lifecycle?.signal.addEventListener('abort', onAbort, { once: true });
844
+ if (this.lifecycle?.signal.aborted)
845
+ onAbort();
846
+ else if (this.connectionState === 'authenticated')
817
847
  finish();
818
848
  });
819
849
  }
@@ -877,6 +907,13 @@ export class WecomChannel {
877
907
  }
878
908
  // ── Inbound message handling ──────────────────────────────────────────────
879
909
  async handleIncoming(frame) {
910
+ const generation = this.connectionGeneration;
911
+ const isCurrent = () => generation === this.connectionGeneration
912
+ && (!this.lifecycle || this.lifecycle.state === 'active');
913
+ const dispatchMessage = async (event) => {
914
+ if (isCurrent())
915
+ await this.messageHandler?.(event);
916
+ };
880
917
  const body = frame?.body;
881
918
  if (!body)
882
919
  return;
@@ -904,14 +941,17 @@ export class WecomChannel {
904
941
  if (!this.messageHandler)
905
942
  return;
906
943
  // 首次交互欢迎消息(使用共享帮助函数)
907
- await sendWelcomeIfNeeded(this.welcomeManager, userid, channelId, (id, text) => this.sendMessage(id, text), 'WeCom');
944
+ await sendWelcomeIfNeeded(this.welcomeManager, userid, channelId, async (id, text) => { if (isCurrent())
945
+ await this.sendMessage(id, text); }, 'WeCom');
946
+ if (!isCurrent())
947
+ return;
908
948
  if (msgtype === 'text') {
909
949
  const text = body.text?.content?.trim();
910
950
  if (!text)
911
951
  return;
912
952
  const quote = await this.processQuote(body.quote, channelId);
913
953
  const content = quote.prefix ? `${quote.prefix}\n${text}` : text;
914
- await this.messageHandler({
954
+ await dispatchMessage({
915
955
  channelId, content, chatType: chatTypeNorm,
916
956
  peerId: userid, messageId: msgId,
917
957
  images: quote.images.length > 0 ? quote.images : undefined,
@@ -919,28 +959,28 @@ export class WecomChannel {
919
959
  });
920
960
  }
921
961
  else if (msgtype === 'image') {
922
- await this.handleImageMessage(body, channelId, chatTypeNorm, userid, msgId, replyContext);
962
+ await this.handleImageMessage(body, channelId, chatTypeNorm, userid, msgId, replyContext, dispatchMessage);
923
963
  }
924
964
  else if (msgtype === 'voice') {
925
965
  const voiceText = body.voice?.content?.trim();
926
966
  if (voiceText) {
927
- await this.messageHandler({
967
+ await dispatchMessage({
928
968
  channelId, content: voiceText, chatType: chatTypeNorm,
929
969
  peerId: userid, messageId: msgId, replyContext,
930
970
  });
931
971
  }
932
972
  }
933
973
  else if (msgtype === 'file') {
934
- await this.handleFileMessage(body, channelId, chatTypeNorm, userid, msgId, replyContext);
974
+ await this.handleFileMessage(body, channelId, chatTypeNorm, userid, msgId, replyContext, dispatchMessage);
935
975
  }
936
976
  else if (msgtype === 'video') {
937
- await this.handleVideoMessage(body, channelId, chatTypeNorm, userid, msgId, replyContext);
977
+ await this.handleVideoMessage(body, channelId, chatTypeNorm, userid, msgId, replyContext, dispatchMessage);
938
978
  }
939
979
  else if (msgtype === 'mixed') {
940
- await this.handleMixedMessage(body, channelId, chatTypeNorm, userid, msgId, replyContext);
980
+ await this.handleMixedMessage(body, channelId, chatTypeNorm, userid, msgId, replyContext, dispatchMessage);
941
981
  }
942
982
  else {
943
- await this.messageHandler({
983
+ await dispatchMessage({
944
984
  channelId,
945
985
  content: `[不支持的消息类型: ${msgtype}]`,
946
986
  chatType: chatTypeNorm, peerId: userid, messageId: msgId, replyContext,
@@ -1019,12 +1059,12 @@ export class WecomChannel {
1019
1059
  }
1020
1060
  return result;
1021
1061
  }
1022
- async handleImageMessage(body, channelId, chatType, peerId, msgId, replyContext) {
1062
+ async handleImageMessage(body, channelId, chatType, peerId, msgId, replyContext, dispatchMessage = this.messageHandler) {
1023
1063
  const imageUrl = body.image?.url;
1024
1064
  const aeskey = body.image?.aeskey;
1025
1065
  if (!imageUrl) {
1026
1066
  logger.warn('[WeCom] Image message without url');
1027
- await this.messageHandler({
1067
+ await dispatchMessage({
1028
1068
  channelId, content: '[图片下载失败:缺少下载链接]',
1029
1069
  chatType, peerId, messageId: msgId, replyContext,
1030
1070
  });
@@ -1034,7 +1074,7 @@ export class WecomChannel {
1034
1074
  const media = await this.downloadInboundMedia(imageUrl, aeskey);
1035
1075
  const image = await bufferToInboundImage(media.buffer, { filename: media.filename });
1036
1076
  if (image) {
1037
- await this.messageHandler({
1077
+ await dispatchMessage({
1038
1078
  channelId,
1039
1079
  content: '用户发送了一张图片,请分析这张图片的内容。',
1040
1080
  chatType, peerId, messageId: msgId,
@@ -1043,7 +1083,7 @@ export class WecomChannel {
1043
1083
  }
1044
1084
  else {
1045
1085
  logger.warn(`[WeCom] Image validation failed`);
1046
- await this.messageHandler({
1086
+ await dispatchMessage({
1047
1087
  channelId, content: '[图片验证失败]',
1048
1088
  chatType, peerId, messageId: msgId, replyContext,
1049
1089
  });
@@ -1051,13 +1091,13 @@ export class WecomChannel {
1051
1091
  }
1052
1092
  catch (error) {
1053
1093
  logger.error('[WeCom] Failed to download image:', error);
1054
- await this.messageHandler({
1094
+ await dispatchMessage({
1055
1095
  channelId, content: '[图片下载失败]',
1056
1096
  chatType, peerId, messageId: msgId, replyContext,
1057
1097
  });
1058
1098
  }
1059
1099
  }
1060
- async handleFileMessage(body, channelId, chatType, peerId, msgId, replyContext) {
1100
+ async handleFileMessage(body, channelId, chatType, peerId, msgId, replyContext, dispatchMessage = this.messageHandler) {
1061
1101
  const fileUrl = body.file?.url;
1062
1102
  const aeskey = body.file?.aeskey;
1063
1103
  const callbackFileName = body.file?.filename
@@ -1066,7 +1106,7 @@ export class WecomChannel {
1066
1106
  const displayFileName = callbackFileName || 'file';
1067
1107
  if (!fileUrl) {
1068
1108
  logger.warn('[WeCom] File message without url');
1069
- await this.messageHandler({
1109
+ await dispatchMessage({
1070
1110
  channelId, content: `[文件下载失败:缺少下载链接] ${displayFileName}`,
1071
1111
  chatType, peerId, messageId: msgId, replyContext,
1072
1112
  });
@@ -1079,7 +1119,7 @@ export class WecomChannel {
1079
1119
  ? await this.projectPathProvider(channelId)
1080
1120
  : process.cwd();
1081
1121
  const { filePath } = saveToUploads(media.buffer, fileName, projectPath);
1082
- await this.messageHandler({
1122
+ await dispatchMessage({
1083
1123
  channelId,
1084
1124
  content: `用户发送了文件:${fileName}\n文件已保存到:${filePath}\n请使用 Read 工具读取并分析文件内容。`,
1085
1125
  chatType, peerId, messageId: msgId, replyContext,
@@ -1087,17 +1127,17 @@ export class WecomChannel {
1087
1127
  }
1088
1128
  catch (error) {
1089
1129
  logger.error('[WeCom] Failed to download file:', error);
1090
- await this.messageHandler({
1130
+ await dispatchMessage({
1091
1131
  channelId, content: `[文件下载失败] ${displayFileName}`,
1092
1132
  chatType, peerId, messageId: msgId, replyContext,
1093
1133
  });
1094
1134
  }
1095
1135
  }
1096
- async handleVideoMessage(body, channelId, chatType, peerId, msgId, replyContext) {
1136
+ async handleVideoMessage(body, channelId, chatType, peerId, msgId, replyContext, dispatchMessage = this.messageHandler) {
1097
1137
  const videoUrl = body.video?.url;
1098
1138
  const aeskey = body.video?.aeskey;
1099
1139
  if (!videoUrl) {
1100
- await this.messageHandler({
1140
+ await dispatchMessage({
1101
1141
  channelId, content: '[视频下载失败:缺少下载链接]',
1102
1142
  chatType, peerId, messageId: msgId, replyContext,
1103
1143
  });
@@ -1110,7 +1150,7 @@ export class WecomChannel {
1110
1150
  : process.cwd();
1111
1151
  const fileName = `video_${Date.now()}.mp4`;
1112
1152
  const { filePath } = saveToUploads(media.buffer, fileName, projectPath);
1113
- await this.messageHandler({
1153
+ await dispatchMessage({
1114
1154
  channelId,
1115
1155
  content: `用户发送了视频:${fileName}\n文件已保存到:${filePath}`,
1116
1156
  chatType, peerId, messageId: msgId, replyContext,
@@ -1118,16 +1158,16 @@ export class WecomChannel {
1118
1158
  }
1119
1159
  catch (error) {
1120
1160
  logger.error('[WeCom] Failed to download video:', error);
1121
- await this.messageHandler({
1161
+ await dispatchMessage({
1122
1162
  channelId, content: '[视频下载失败]',
1123
1163
  chatType, peerId, messageId: msgId, replyContext,
1124
1164
  });
1125
1165
  }
1126
1166
  }
1127
- async handleMixedMessage(body, channelId, chatType, peerId, msgId, replyContext) {
1167
+ async handleMixedMessage(body, channelId, chatType, peerId, msgId, replyContext, dispatchMessage = this.messageHandler) {
1128
1168
  const msgItems = body.mixed?.msg_item;
1129
1169
  if (!Array.isArray(msgItems)) {
1130
- await this.messageHandler({
1170
+ await dispatchMessage({
1131
1171
  channelId, content: '[不支持的图文混排格式]',
1132
1172
  chatType, peerId, messageId: msgId, replyContext,
1133
1173
  });
@@ -1152,7 +1192,7 @@ export class WecomChannel {
1152
1192
  }
1153
1193
  }
1154
1194
  const prompt = text.trim() || (images.length > 0 ? '用户发送了一张图片,请分析这张图片的内容。' : '[空消息]');
1155
- await this.messageHandler({
1195
+ await dispatchMessage({
1156
1196
  channelId, content: prompt, chatType,
1157
1197
  peerId, messageId: msgId,
1158
1198
  images: images.length > 0 ? images : undefined,
@@ -112,7 +112,7 @@ export async function cmdAgent(args) {
112
112
  assertEcSingleLine(args[nameIndex + 1], '--name');
113
113
  }
114
114
  const formatJson = getArgValue(args, '--format') === 'json';
115
- const commands = new Set(['list', 'show', 'new', 'initialize', 'enable', 'disable', 'get', 'set', 'persona', 'welcome', 'rename', 'ready', 'reload', 'delete', 'host']);
115
+ const commands = new Set(['list', 'show', 'new', 'initialize', 'enable', 'disable', 'get', 'set', 'welcome', 'rename', 'ready', 'reload', 'delete', 'host']);
116
116
  if (sub === 'create') {
117
117
  const error = { ok: false, code: 'INVALID_COMMAND', error: '`ec agent create` is not a command; use `ec agent new`.' };
118
118
  if (formatJson)
@@ -136,9 +136,6 @@ Commands:
136
136
  disable <aid> 停用 agent
137
137
  get <aid> <key> 读取单个配置字段(支持点路径)
138
138
  set <aid> <key> <val> 修改单个配置字段(支持点路径)
139
- persona show 查看当前 Agent 的 persona.md
140
- persona --text <text> 用文本设置当前 Agent 的 persona.md
141
- persona --file <path> 用 .md/.txt 文件设置当前 Agent 的 persona.md
142
139
  welcome show 查看 Agent 自主准备的 Bootstrap welcome 文案
143
140
  welcome --text <text> 保存 Agent 自主准备的 Bootstrap welcome 文案
144
141
  rename <aid> <name> 修改 agent.md 中的显示名称
@@ -157,7 +154,6 @@ Options:
157
154
  ec agent enable mybot.agentid.pub
158
155
  ec agent get mybot.agentid.pub active_baseagent
159
156
  ec agent set mybot.agentid.pub active_baseagent codex
160
- ec agent persona --text "你是一名严谨的诊断工程师。"
161
157
  ec agent rename mybot.agentid.pub "New Name"
162
158
  ec agent ready mybot.agentid.pub
163
159
  ec agent delete mybot.agentid.pub --purge`);
@@ -211,10 +207,10 @@ Options:
211
207
  }
212
208
  return;
213
209
  }
214
- const { agentList, agentShow, agentCreateNonInteractive, agentReload, agentEnable, agentDisable, agentGet, agentSet, agentPersona, agentWelcome, agentRename, agentDelete, agentReady, runManagedAgentOperation, } = await import('./agent.js');
210
+ const { agentList, agentShow, agentCreateNonInteractive, agentReload, agentEnable, agentDisable, agentGet, agentSet, agentWelcome, agentRename, agentDelete, agentReady, runManagedAgentOperation, } = await import('./agent.js');
215
211
  const { parseAgentOwnerArgs, parseAgentTags, resolveAgentCreatePlan, validateAgentCreatePlan } = await import('./agent-create.js');
216
212
  // host 走 status.auth 授权(与 ec status 同门),不经过 agent.op 的子命令映射。
217
- if (process.env.EVOLCORE_SESSION_ID && !wantsHelp(args) && !new Set(['get', 'set', 'persona', 'welcome', 'ready', 'host']).has(sub)) {
213
+ if (process.env.EVOLCORE_SESSION_ID && !wantsHelp(args) && !new Set(['get', 'set', 'welcome', 'ready', 'host']).has(sub)) {
218
214
  const result = await runManagedAgentOperation(args);
219
215
  if (!result.ok) {
220
216
  if (formatJson)
@@ -587,85 +583,6 @@ Options:
587
583
  }
588
584
  return;
589
585
  }
590
- // --- get ---
591
- if (sub === 'persona') {
592
- if (wantsHelp(args)) {
593
- console.log(`用法: ec agent persona show [--format json]
594
- ec agent persona --text <text> [--format json]
595
- ec agent persona --file <path> [--format json]
596
-
597
- 读取或设置当前 Agent 的 persona.md。--file 只接受 .md/.txt 文本文件。`);
598
- return;
599
- }
600
- const formatSuffix = args.length >= 3
601
- && args.at(-2) === '--format'
602
- && args.at(-1) === 'json';
603
- const commandArgs = formatSuffix ? args.slice(0, -2) : args;
604
- const personaArgs = commandArgs.slice(1);
605
- const invalid = (error) => {
606
- const result = { ok: false, code: 'INVALID_ARGS', error };
607
- if (formatJson)
608
- console.log(JSON.stringify(result));
609
- else
610
- console.error(`❌ ${result.error}`);
611
- process.exitCode = 1;
612
- return;
613
- };
614
- if (!formatSuffix && args.includes('--format')) {
615
- invalid('persona 仅支持末尾的 --format json');
616
- return;
617
- }
618
- let text;
619
- let file;
620
- if (personaArgs.length === 1 && personaArgs[0] === 'show') {
621
- // show is the only read form; no payload is accepted.
622
- }
623
- else if (personaArgs.length === 2 && personaArgs[0] === '--text') {
624
- text = personaArgs[1];
625
- if (text === undefined) {
626
- invalid('persona --text 缺少参数');
627
- return;
628
- }
629
- }
630
- else if (personaArgs.length === 2 && personaArgs[0] === '--file') {
631
- file = personaArgs[1];
632
- if (!file || file.startsWith('-')) {
633
- invalid('persona --file 缺少有效路径');
634
- return;
635
- }
636
- }
637
- else {
638
- invalid('用法: ec agent persona show | --text <text> | --file <path>');
639
- return;
640
- }
641
- const taskAid = process.env.EVOLCORE_SESSION_ID ? (readTaskRuntimeContextFromEnv()?.selfAid || '') : '';
642
- const aid = taskAid || process.env.EVOLCORE_SELF_AID || '';
643
- if (!aid) {
644
- const result = { ok: false, code: 'INVALID_ARGS', error: '无法确定当前 Agent AID' };
645
- if (formatJson)
646
- console.log(JSON.stringify(result));
647
- else
648
- console.error(`❌ ${result.error}`);
649
- process.exitCode = 1;
650
- return;
651
- }
652
- const result = await agentPersona(aid, { text, file, argv: args });
653
- if (!result.ok) {
654
- if (formatJson)
655
- console.log(JSON.stringify(result));
656
- else
657
- console.error(`❌ ${result.error}`);
658
- process.exitCode = 1;
659
- return;
660
- }
661
- if (formatJson)
662
- console.log(JSON.stringify(result, null, 2));
663
- else if (result.saved)
664
- console.log(`✓ ${aid} persona.md 已保存`);
665
- else
666
- console.log(result.content ?? '(persona.md 不存在)');
667
- return;
668
- }
669
586
  if (sub === 'welcome') {
670
587
  let text;
671
588
  try {
@@ -3,13 +3,14 @@ import { randomBytes, randomUUID, createHash } from 'crypto';
3
3
  import path from 'path';
4
4
  import readline from 'readline';
5
5
  import { parse } from 'yaml';
6
- import { resolvePaths, aunPath as defaultAunPath, agentConfig, agentDataDir, agentPersonalDir, aidLocalDir, agentMdPath } from '../paths.js';
6
+ import { resolvePaths, aunPath as defaultAunPath, agentConfig, agentDataDir, agentSoulDir, SOUL_PERSONA_FILE, aidLocalDir, agentMdPath } from '../paths.js';
7
7
  import { loadDefaults, loadAgent, saveAgent, ensureAgentDirSkeleton } from '../config-store.js';
8
8
  import { ConfigTarget, assertAgentAidAvailable, write as cfgWrite, ensureFile as cfgEnsure, read as cfgRead } from '../config/config-manager.js';
9
9
  import { daemonUnavailableMessage, queryDaemon } from './help.js';
10
10
  import { ipcQuery } from '../ipc.js';
11
11
  import { CONFIG_SCHEMA_VERSION } from '../types.js';
12
12
  import { ensureInitialRoleRegistry } from '../config/role-service.js';
13
+ import { isSoulPlaceholder } from '../core/soul.js';
13
14
  import { getCodexAppServerAvailability } from '../agents/codex-runner.js';
14
15
  import { AUTO_BASEAGENT_CANDIDATES, BASEAGENT_CANDIDATES, detectAvailableBaseagents, } from '../agents/baseagent-availability.js';
15
16
  import { agentProjectRootFromDefaults, deriveAgentProjectPath } from '../utils/project-path.js';
@@ -237,6 +238,17 @@ function saveInitialBehavior(aid, baseagent) {
237
238
  };
238
239
  const sel = { self: aid };
239
240
  const existingBehavior = cfgRead(ConfigTarget.Agent, sel) || {};
241
+ // New agents use app-v1 in code; these values control only explicit openness rules.
242
+ if (!existingBehavior.access) {
243
+ behavior.access = {
244
+ allowInternalContacts: true,
245
+ allowExternalContacts: false,
246
+ allowAllContacts: false,
247
+ allowedAids: [],
248
+ deniedAids: [],
249
+ requestLimit: { maxTimes: 600, coolDown: 60 * 60 },
250
+ };
251
+ }
240
252
  cfgEnsure(ConfigTarget.Agent, sel);
241
253
  cfgWrite(ConfigTarget.Agent, { ...existingBehavior, ...behavior }, sel);
242
254
  }
@@ -1093,8 +1105,8 @@ export function validateInitializationPlan(plan) {
1093
1105
  if (plan.chatmode !== undefined) {
1094
1106
  if (!plan.chatmode || typeof plan.chatmode !== 'object' || Array.isArray(plan.chatmode)
1095
1107
  || Object.entries(plan.chatmode).some(([scope, value]) => !['private', 'group', 'nothuman'].includes(scope)
1096
- || !['interactive', 'proactive'].includes(value))) {
1097
- failure('INVALID_ARGS', 'chatmode must contain only private/group/nothuman interactive/proactive values');
1108
+ || !(scope === 'group' ? ['proactive'] : ['interactive', 'proactive', ...(scope === 'private' ? ['paactive'] : [])]).includes(value))) {
1109
+ failure('INVALID_ARGS', 'chatmode.group must be proactive; paactive is private AUN only');
1098
1110
  }
1099
1111
  }
1100
1112
  if (plan.avatarFile !== undefined && plan.avatarUrl !== undefined)
@@ -1756,8 +1768,10 @@ export class AgentInitializationService {
1756
1768
  ensureAgentDirSkeleton(p.aid);
1757
1769
  ensureInitialRoleRegistry(p.aid);
1758
1770
  if (p.persona !== undefined) {
1759
- const file = path.join(agentPersonalDir(p.aid), 'persona.md');
1760
- if (fs.existsSync(file) && fs.readFileSync(file, 'utf8') !== p.persona)
1771
+ // 创建时给的 persona 落进 soul 的性格分册,未填写的骨架允许替换。
1772
+ const file = path.join(agentSoulDir(p.aid), SOUL_PERSONA_FILE);
1773
+ const current = fs.existsSync(file) ? fs.readFileSync(file, 'utf8') : '';
1774
+ if (current !== p.persona && !isSoulPlaceholder(SOUL_PERSONA_FILE, current))
1761
1775
  failure('INITIALIZE_PLAN_CONFLICT');
1762
1776
  fs.writeFileSync(file, p.persona, { encoding: 'utf8', mode: 0o600 });
1763
1777
  }
@@ -1889,7 +1903,7 @@ export class AgentInitializationService {
1889
1903
  saveInitialization(r);
1890
1904
  }
1891
1905
  this.phase(r, 'activating');
1892
- if (p.persona !== undefined && fs.readFileSync(path.join(agentPersonalDir(p.aid), 'persona.md'), 'utf8') !== p.persona) {
1906
+ if (p.persona !== undefined && fs.readFileSync(path.join(agentSoulDir(p.aid), SOUL_PERSONA_FILE), 'utf8') !== p.persona) {
1893
1907
  failure('INITIALIZE_PLAN_CONFLICT');
1894
1908
  }
1895
1909
  r.activationPrepared = true;
package/dist/cli/agent.js CHANGED
@@ -2,7 +2,7 @@ import fs from 'fs';
2
2
  import { getOwners } from '../core/ownership/owner-resolver.js';
3
3
  import path from 'path';
4
4
  import { SESSION_ID_ENV } from '../product.js';
5
- import { resolvePaths, agentMdPath as getAgentMdPathFromPaths, agentPersonalDir, agentWelcomePath, aunPath as defaultAunPath } from '../paths.js';
5
+ import { resolvePaths, agentMdPath as getAgentMdPathFromPaths, agentWelcomePath, aunPath as defaultAunPath } from '../paths.js';
6
6
  import { loadDefaults, loadAllAgents, loadAgent, saveAgent, ensureAgentDirSkeleton } from '../config-store.js';
7
7
  import { assertAgentAidAvailable, assertAgentModelConfigured, resolveEffective, initConfigManager } from '../config/config-manager.js';
8
8
  import { resolveRuntimeBaseagentModelSelection } from '../agents/baseagent.js';
@@ -510,84 +510,6 @@ export async function agentSet(aid, key, rawValue, options = {}) {
510
510
  catch { }
511
511
  return { ok: true, aid, key, value, reloaded };
512
512
  }
513
- export const AGENT_PERSONA_MAX_BYTES = 64 * 1024;
514
- export function validatePersonaContent(content) {
515
- if (content.includes('\0'))
516
- return 'persona 只能包含文本内容';
517
- if (Buffer.byteLength(content, 'utf8') > AGENT_PERSONA_MAX_BYTES) {
518
- return `persona 不能超过 ${AGENT_PERSONA_MAX_BYTES} bytes`;
519
- }
520
- return null;
521
- }
522
- function readPersonaSource(file) {
523
- const resolved = path.resolve(file);
524
- if (!/\.(?:md|txt)$/i.test(resolved)) {
525
- return { ok: false, code: 'INVALID_ARGS', error: '--file 只接受 .md 或 .txt 文本文件' };
526
- }
527
- try {
528
- const stat = fs.statSync(resolved);
529
- if (!stat.isFile())
530
- return { ok: false, code: 'INVALID_ARGS', error: `--file 必须指向普通文件: ${resolved}` };
531
- const content = fs.readFileSync(resolved, 'utf8');
532
- const error = validatePersonaContent(content);
533
- return error ? { ok: false, code: 'INVALID_ARGS', error } : { ok: true, content };
534
- }
535
- catch (e) {
536
- return { ok: false, code: 'READ_FAILED', error: `无法读取 --file: ${e?.message || e}` };
537
- }
538
- }
539
- /** Read or replace the current Agent's personal/persona.md. */
540
- export async function agentPersona(aid, options = {}) {
541
- try {
542
- assertAgentAidAvailable(aid);
543
- }
544
- catch (error) {
545
- return { ok: false, code: 'CONTROL_AID_RESERVED', error: error.message };
546
- }
547
- if (options.text !== undefined && options.file !== undefined)
548
- return { ok: false, code: 'INVALID_ARGS', error: '--text 与 --file 不能同时使用' };
549
- const managedSession = !!process.env.EVOLCORE_SESSION_ID && !options.trustedLocal;
550
- let text = options.text;
551
- if (options.file !== undefined && !managedSession) {
552
- const source = readPersonaSource(options.file);
553
- if (!source.ok)
554
- return source;
555
- text = source.content;
556
- }
557
- if (text !== undefined) {
558
- const error = validatePersonaContent(text);
559
- if (error)
560
- return { ok: false, code: 'INVALID_ARGS', error };
561
- }
562
- const managedArgs = options.text !== undefined
563
- ? ['persona', '--text', text]
564
- : options.file !== undefined
565
- ? ['persona', '--file', options.file]
566
- : ['persona', 'show'];
567
- if (managedSession) {
568
- const managed = await runManagedAgentOperation(options.argv ?? managedArgs);
569
- if (!managed.ok)
570
- return managed;
571
- return { ok: true, aid, content: managed.content ?? null, ...(managed.path ? { path: managed.path } : {}), ...(managed.saved ? { saved: true } : {}) };
572
- }
573
- const personaPath = path.join(agentPersonalDir(aid), 'persona.md');
574
- if (text === undefined) {
575
- try {
576
- return { ok: true, aid, content: fs.existsSync(personaPath) ? fs.readFileSync(personaPath, 'utf8') : null, path: personaPath };
577
- }
578
- catch (e) {
579
- return { ok: false, code: 'READ_FAILED', error: e?.message || String(e) };
580
- }
581
- }
582
- try {
583
- fs.mkdirSync(path.dirname(personaPath), { recursive: true });
584
- fs.writeFileSync(personaPath, text, 'utf8');
585
- return { ok: true, aid, content: text, path: personaPath, saved: true };
586
- }
587
- catch (e) {
588
- return { ok: false, code: 'WRITE_FAILED', error: e?.message || String(e) };
589
- }
590
- }
591
513
  /** Read or replace the current Agent's self-prepared Bootstrap welcome template. */
592
514
  export async function agentWelcome(aid, options = {}) {
593
515
  try {