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
@@ -24,6 +24,8 @@ import { getDaemonOwners, ownerResolver, refreshOwnershipForAuthorization, OWNER
24
24
  import { authorizationNextStep, formatAuthorizationDenial } from '../auth/authorization-denial.js';
25
25
  import { resolvePermissionMode, writeAgentModelConfig } from '../model/config-scope.js';
26
26
  import { formatPeerKey } from '../relation/peer-identity.js';
27
+ import { writeChatmodeConfig } from './chatmode-config.js';
28
+ import { preparePaTeamQualification } from '../relation/pa-team.js';
27
29
  import { auditFullAccessEvent } from '../auth/authorization-audit.js';
28
30
  import { isMainSession, isTopicSession, isTopicThreadId, sessionTopicThreadId } from '../thread/topic-id.js';
29
31
  import { modelMatches, getCatalog, assertCatalogSelectable, resolveCatalogModel, CONFIGURABLE_EFFORTS, configurableEfforts } from '../model/model-catalog.js';
@@ -42,6 +44,9 @@ import { MAX_AUN_ATTACHMENT_SIZE } from '../../aun/msg/upload.js';
42
44
  import { DEFAULT_SESSION_LOOP_SECONDS, MAX_SESSION_LOOP_SECONDS, MIN_SESSION_LOOP_SECONDS, refreshSessionLoopTarget, resolveCurrentSessionLoopTarget, resolveSessionLoopTarget, sessionLoopPayload, validateIdleSeconds, writeSessionLoopConfig, } from '../session/session-idle-monitor.js';
43
45
  const allEfforts = CONFIGURABLE_EFFORTS;
44
46
  const PERMISSION_MODE_KEYS = PUBLIC_PERMISSION_MODES;
47
+ function formatSessionPolicyStatus(name, scope, enabled, updated = false) {
48
+ return `${updated ? '✅ ' : ''}${name} 当前生效:${enabled ? '开启' : '关闭'}(${scope})`;
49
+ }
45
50
  function formatUpgradeEvent(event) {
46
51
  if (event.event === 'upgrade.progress')
47
52
  return `⏳ ${event.message}`;
@@ -96,16 +101,6 @@ function readSlashChatmode(target) {
96
101
  return defaultSlashChatmode(target.field);
97
102
  }
98
103
  }
99
- function writeSlashChatmode(target, value) {
100
- const route = routeFieldPath(target.fieldPath, 'relation');
101
- const cur = cfgRead(route.target, target.sel) || {};
102
- const block = cur.chatmode && typeof cur.chatmode === 'object' && !Array.isArray(cur.chatmode)
103
- ? { ...cur.chatmode }
104
- : {};
105
- block[target.field] = value;
106
- cur.chatmode = block;
107
- cfgWrite(route.target, cur, target.sel);
108
- }
109
104
  function resolveSlashMentionModeTarget(params) {
110
105
  const self = params.selfAID
111
106
  ?? params.session?.selfAID
@@ -428,6 +423,9 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
428
423
  allowTransient: true,
429
424
  includeDaemon: /^\/(?:restart|upgrade|update|reload|pair|fa|fullaccess|diag)(?:\s|$)/i.test(normalizedContent),
430
425
  });
426
+ if (this.resolveChannelType(channel) === 'aun' && narrowedChatType === 'private') {
427
+ await preparePaTeamQualification(selfAID ?? this.agentRegistry?.resolveByChannel(channel)?.aid ?? this.resolveSelfAID(channel), userId);
428
+ }
431
429
  const identityConversationId = narrowedChatType === 'group' ? channelId : userId;
432
430
  const resolvedIdentity = overrideIdentity ?? this.sessionManager.resolveIdentity(channel, userId, narrowedChatType, identityConversationId);
433
431
  const authSubject = overrideSubject ?? buildAuthSubject({
@@ -492,6 +490,8 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
492
490
  || topicAuthSession?.chatType
493
491
  || activeSession?.chatType
494
492
  || (chatType === 'group' ? 'group' : 'private');
493
+ const chatmodeChoices = activeChatType === 'group' ? 'proactive'
494
+ : identity.role === 'owner' ? 'interactive|proactive|paactive' : 'interactive|proactive';
495
495
  const groupSlash = applyGroupSlashPolicy && activeChatType === 'group';
496
496
  if (applyGroupSlashPolicy) {
497
497
  const groupGuard = guardGroupSlashCommand(normalizedContent, activeChatType);
@@ -623,7 +623,8 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
623
623
  const payload = sessionLoopPayload(current);
624
624
  return {
625
625
  kind: 'system.notice',
626
- text: `当前 idle 触发(${current.level},session=${current.session.id}):${payload.value ? `开启,${payload.idleSeconds} 秒` : '关闭'}`,
626
+ text: formatSessionPolicyStatus('idle 触发', current.level, payload.value === true)
627
+ + (payload.value ? `(${payload.idleSeconds} 秒)` : ''),
627
628
  subtype: 'session.loop.current',
628
629
  };
629
630
  }
@@ -655,7 +656,8 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
655
656
  return null;
656
657
  return {
657
658
  kind: 'system.notice',
658
- text: `✅ idle 触发(${updated.level},session=${updated.session.id})已${payload.value ? `开启(${payload.idleSeconds} 秒)` : '关闭'}`,
659
+ text: formatSessionPolicyStatus('idle 触发', updated.level, payload.value === true, true)
660
+ + (payload.value ? `(${payload.idleSeconds} 秒)` : ''),
659
661
  subtype: 'session.loop.updated',
660
662
  };
661
663
  }
@@ -681,21 +683,21 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
681
683
  return { kind: 'command.error', text: '❌ /fa 需要同一身份同时具备 Agent Owner 和 daemon Owner 权限' };
682
684
  }
683
685
  const status = sessionFullAccessStatus(commandSession, principalId);
686
+ const formatStatus = (current, updated = false) => formatSessionPolicyStatus('fullaccess', current.scope, current.effective, updated)
687
+ + ';Agent 全局:' + (current.globalEnabled ? '开启' : '关闭')
688
+ + ';作用域设置:' + (current.localEnabled ? '开启' : '关闭')
689
+ + (current.globalEnabled ? '(被全局覆盖)' : '');
684
690
  if (fullAccessControl.action === 'status') {
685
- const scope = isTopicSession(commandSession) ? 'session' : 'relation';
686
691
  return {
687
692
  kind: 'system.notice',
688
- text: '当前 fullaccess(' + scope + ',session=' + commandSession.id + '):'
689
- + (status.effective ? '开启' : '关闭')
690
- + '\nAgent 全局:' + (status.globalEnabled ? '开启(局部开关不生效)' : '关闭')
691
- + '\n局部开关:' + (status.localEnabled ? '开启' : '关闭'),
693
+ text: formatStatus(status),
692
694
  subtype: 'session.fullaccess.current',
693
695
  };
694
696
  }
695
697
  if (status.globalEnabled) {
696
698
  return {
697
699
  kind: 'system.notice',
698
- text: 'Agent 全局 fullaccess 已开启,/fa on/off 不生效;局部设置未修改。',
700
+ text: formatStatus(status) + ';Agent 全局已开启,当前作用域设置未修改。',
699
701
  subtype: 'session.fullaccess.unchanged',
700
702
  };
701
703
  }
@@ -704,12 +706,13 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
704
706
  }
705
707
  const enabled = fullAccessControl.action === 'on';
706
708
  try {
709
+ let updatedSession;
707
710
  if (isTopicSession(commandSession)) {
708
711
  const latest = await this.sessionManager.getThreadSession(channel, channelId, threadId);
709
712
  if (!latest || latest.id !== commandSession.id || !isTopicSession(latest)) {
710
713
  return { kind: 'command.error', text: '❌ 当前话题已发生变化,请重新执行 /fa' };
711
714
  }
712
- this.sessionManager.updateSessionFullAccess(latest.id, { enabled, authorizedBy: principalId });
715
+ updatedSession = this.sessionManager.updateSessionFullAccess(latest.id, { enabled, authorizedBy: principalId });
713
716
  }
714
717
  else {
715
718
  const latest = await this.sessionManager.getActiveSession(channel, channelId);
@@ -717,6 +720,7 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
717
720
  return { kind: 'command.error', text: '❌ 当前主会话已发生变化,请重新执行 /fa' };
718
721
  }
719
722
  updateRelationSessionFullAccess(latest, { enabled, authorizedBy: principalId });
723
+ updatedSession = latest;
720
724
  }
721
725
  auditFullAccessEvent({
722
726
  event: enabled ? 'fullaccess.session-policy.configured' : 'fullaccess.session-policy.deescalated',
@@ -730,8 +734,7 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
730
734
  });
731
735
  return {
732
736
  kind: 'system.notice',
733
- text: '✅ 当前' + (isTopicSession(commandSession) ? '话题 EC 会话' : '主会话')
734
- + ' fullaccess 已' + (enabled ? '开启' : '关闭'),
737
+ text: formatStatus(sessionFullAccessStatus(updatedSession, principalId), true),
735
738
  subtype: 'session.fullaccess.updated',
736
739
  };
737
740
  }
@@ -908,7 +911,7 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
908
911
  ...((canReadChatmode || canSetChatmode || canReadMentionmode || canSetMentionmode) ? [
909
912
  '',
910
913
  '💬 聊天设置:',
911
- ...(canReadChatmode || canSetChatmode ? [` /chatmode${canSetChatmode ? ' [interactive|proactive|paactive]' : ''} - 查看${canSetChatmode ? '或切换' : ''}会话模式`] : []),
914
+ ...(canReadChatmode || canSetChatmode ? [` /chatmode${canSetChatmode ? ` [${chatmodeChoices}]` : ''} - 查看${canSetChatmode ? '或切换' : ''}会话模式`] : []),
912
915
  ...(canReadLoop ? [` /loop${canUpdateLoop ? ' [on [seconds]|off]' : ''} - 查看${canUpdateLoop ? '或设置' : ''}当前会话的单次闲置触发`] : []),
913
916
  ...(canReadMentionmode || canSetMentionmode ? [` /mention${canSetMentionmode ? ' [mention-only|disabled]' : ''} - 查看${canSetMentionmode ? '或切换' : ''}群聊 @ 处理模式`] : []),
914
917
  ] : []),
@@ -952,7 +955,7 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
952
955
  ...((canReadChatmode || canSetChatmode) ? [
953
956
  '',
954
957
  '💬 聊天设置:',
955
- ` /chatmode${canSetChatmode ? ' [interactive|proactive|paactive]' : ''} - 查看${canSetChatmode ? '或切换' : ''}会话模式`,
958
+ ` /chatmode${canSetChatmode ? ` [${chatmodeChoices}]` : ''} - 查看${canSetChatmode ? '或切换' : ''}会话模式`,
956
959
  ] : []),
957
960
  ...(canReadLoop ? ['', ` /loop${canUpdateLoop ? ' [on [seconds]|off]' : ''} - 查看${canUpdateLoop ? '或设置' : ''}当前会话的单次闲置触发`] : []),
958
961
  ...(canReadPermission || canAnswerPermission ? [
@@ -1000,7 +1003,7 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
1000
1003
  '',
1001
1004
  '💬 聊天设置:',
1002
1005
  ' /activity [all|text|none] - 查看/控制中间输出显示模式',
1003
- ...(canReadChatmode || canSetChatmode ? [` /chatmode${canSetChatmode ? ' [interactive|proactive|paactive]' : ''} - 查看${canSetChatmode ? '/切换' : ''}会话模式(被动响应或主动推进)`] : []),
1006
+ ...(canReadChatmode || canSetChatmode ? [` /chatmode${canSetChatmode ? ` [${chatmodeChoices}]` : ''} - 查看${canSetChatmode ? '/切换' : ''}会话模式(被动响应或主动推进)`] : []),
1004
1007
  ...(canReadMentionmode || canSetMentionmode ? [` /mention${canSetMentionmode ? ' [mention-only|disabled]' : ''} - 查看${canSetMentionmode ? '/切换' : ''}群聊 @ 处理模式`] : []),
1005
1008
  ...(canReadLoop ? [` /loop${canUpdateLoop ? ' [on [seconds]|off]' : ''} - 查看${canUpdateLoop ? '或设置' : ''}当前会话的单次闲置触发`] : []),
1006
1009
  '',
@@ -1212,7 +1215,7 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
1212
1215
  cmds.push({ command: '/file', args: isOwner ? '[channel] <path>' : '<path>', description: '发送项目内文件', category: '工具', roles: [identity.role] });
1213
1216
  // 聊天设置
1214
1217
  if (canReadChatmode || canSetChatmode)
1215
- cmds.push({ command: '/chatmode', ...(canSetChatmode ? { args: '[interactive|proactive|paactive]' } : {}), description: `查看${canSetChatmode ? '/切换' : ''}会话模式(被动响应或主动推进)`, category: '聊天设置', roles: [identity.role] });
1218
+ cmds.push({ command: '/chatmode', ...(canSetChatmode ? { args: `[${chatmodeChoices}]` } : {}), description: `查看${canSetChatmode ? '/切换' : ''}会话模式(被动响应或主动推进)`, category: '聊天设置', roles: [identity.role] });
1216
1219
  if (canReadMentionmode || canSetMentionmode)
1217
1220
  cmds.push({ command: '/mention', ...(canSetMentionmode ? { args: '[mention-only|disabled]' } : {}), description: `查看${canSetMentionmode ? '/切换' : ''}群聊 @ 处理模式`, category: '聊天设置', roles: [identity.role] });
1218
1221
  // 交互
@@ -2108,10 +2111,6 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
2108
2111
  // 带参(写操作)需 admin+;无参查询对所有人开放(owner 门在具体切换点还有一道)
2109
2112
  if (activityArg && !isAdmin)
2110
2113
  return { kind: 'command.error', text: '❌ 无权限:此命令仅限管理员使用' };
2111
- // proactive 模式下流式输出全部静默,activity 配置无意义
2112
- if (getEffectiveChatmode(activitySession) === 'proactive') {
2113
- return { kind: 'command.error', text: '❌ 当前会话为 proactive 模式,不支持 activity 配置(流式输出已全部静默)' };
2114
- }
2115
2114
  const modeMap = {
2116
2115
  all: 'all',
2117
2116
  text: 'text',
@@ -2121,7 +2120,7 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
2121
2120
  // 模式描述列表(用于 body 和文本降级)。
2122
2121
  // all = 文本 + activity;text = 仅文字进展;none = 全部静默。
2123
2122
  const modeDescriptions = [
2124
- { key: 'all', configVal: 'all', label: '私聊显示' },
2123
+ { key: 'all', configVal: 'all', label: '全部显示' },
2125
2124
  { key: 'text', configVal: 'text', label: '仅文字进展' },
2126
2125
  { key: 'none', configVal: 'none', label: '全部静默' },
2127
2126
  ];
@@ -2186,7 +2185,7 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
2186
2185
  return null;
2187
2186
  return { kind: 'command.result', text: `✅ 中间输出模式: ${activityArg}(${label})` };
2188
2187
  }
2189
- // /chatmode 命令:查看/切换当前 relation 的有效会话模式(interactive | proactive)
2188
+ // /chatmode 命令:私聊提供 interactive/proactive/paactive,群聊固定 proactive
2190
2189
  // - 查看:所有人可用
2191
2190
  // - 设置:单聊任何角色可设置;群聊仅管理员可设置
2192
2191
  if (normalizedContent === '/chatmode' || normalizedContent.startsWith('/chatmode ')) {
@@ -2196,10 +2195,11 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
2196
2195
  const currentMode = getEffectiveChatmode(existingChatmodeSession);
2197
2196
  // 尝试发送 CommandCard 卡片
2198
2197
  const modes = [
2199
- { key: 'interactive', name: '交互模式', desc: '被动响应:收到消息时才回复,回复直接显示' },
2198
+ ...(activeChatType !== 'group'
2199
+ ? [{ key: 'interactive', name: '交互模式', desc: '被动响应:收到消息时才回复,回复直接显示' }] : []),
2200
2200
  { key: 'proactive', name: '主动模式', desc: '主动推进:流式输出静默,由 Agent 自调 ctl send 发声' },
2201
2201
  ...((existingChatmodeSession?.channelType ?? this.resolveChannelType?.(channel)) === 'aun'
2202
- && activeChatType === 'private' && !isPrivateChatmodeRoleLocked('private', identity.role)
2202
+ && activeChatType === 'private' && identity.role === 'owner'
2203
2203
  ? [{ key: 'paactive', name: 'PA 模式', desc: '自动文本显示为 activity,正式回复由 Agent 显式发送' }] : []),
2204
2204
  ];
2205
2205
  const interaction = {
@@ -2232,10 +2232,13 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
2232
2232
  return null;
2233
2233
  // 卡片降级:fall through 到下方文本输出
2234
2234
  // 降级:文本
2235
- return { kind: 'command.result', text: `会话模式: ${currentMode} 用法: /chatmode <interactive|proactive|paactive>` };
2235
+ return { kind: 'command.result', text: `会话模式: ${currentMode} 用法: /chatmode <${chatmodeChoices}>` };
2236
2236
  }
2237
2237
  if (!isChatMode(arg)) {
2238
- return { kind: 'command.error', text: `❌ 无效模式: ${arg}\n可选: interactive / proactive / paactive` };
2238
+ return { kind: 'command.error', text: `❌ 无效模式: ${arg}\n可选: ${chatmodeChoices.split('|').join(' / ')}` };
2239
+ }
2240
+ if (activeChatType === 'group' && arg !== 'proactive') {
2241
+ return { kind: 'command.error', text: '❌ 群聊仅支持 proactive 模式' };
2239
2242
  }
2240
2243
  if (activeChatType === 'group' && !isAdmin) {
2241
2244
  return { kind: 'command.error', text: '❌ 群聊中切换会话模式仅限管理员使用' };
@@ -2254,6 +2257,12 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
2254
2257
  return { kind: 'command.error', text: `❌ ${target.error}` };
2255
2258
  }
2256
2259
  const currentMode = readSlashChatmode(target);
2260
+ if (target.field === 'group' && arg !== 'proactive') {
2261
+ return { kind: 'command.error', text: '❌ 群聊仅支持 proactive 模式' };
2262
+ }
2263
+ if (arg === 'paactive' && identity.role !== 'owner') {
2264
+ return { kind: 'command.error', text: '❌ paactive 模式仅限 owner' };
2265
+ }
2257
2266
  if (arg === currentMode) {
2258
2267
  return { kind: 'command.result', text: `📋 当前会话模式已是 ${arg}` };
2259
2268
  }
@@ -2300,7 +2309,7 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
2300
2309
  if (chatmodeAuthDenied)
2301
2310
  return chatmodeAuthDenied;
2302
2311
  try {
2303
- writeSlashChatmode(target, arg);
2312
+ writeChatmodeConfig({ ...target, scope: 'relation' }, arg, authSubject);
2304
2313
  }
2305
2314
  catch (e) {
2306
2315
  return { kind: 'command.error', text: `Failed to update relation chatmode: ${e?.message || e}` };
@@ -2577,7 +2586,12 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
2577
2586
  return { kind: 'command.error', text: `❌ 当前 Agent (${currentSessionAgent.name}) 不支持 /compact` };
2578
2587
  }
2579
2588
  if (sendMessage) {
2580
- await sendMessage(channelId, '⏳ 正在压缩会话上下文...', this.getReplyContext(session));
2589
+ const text = '⏳ 正在压缩会话上下文...';
2590
+ await sendMessage(channelId, text, this.getReplyContext(session), {
2591
+ kind: 'system.notice',
2592
+ text,
2593
+ subtype: 'session.compacting',
2594
+ });
2581
2595
  }
2582
2596
  // Resolve the same relation/agent effective model used for normal turns.
2583
2597
  // The runner instance's model is only the final fallback; without this
@@ -2795,16 +2809,7 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
2795
2809
  const projectPath = this.getEffectiveDefaultPath(channel);
2796
2810
  if (sendMessage && session) {
2797
2811
  const creatingText = `⏳ 正在创建新会话${sessionName ? `: ${sessionName}` : ''}...`;
2798
- // 私聊改回普通文本:AUN 私聊里 system.notice 会渲染成系统通知样式,
2799
- // 这里希望它像 /compact 等命令的占位提示一样,按普通消息发送。
2800
- const creatingPayload = activeChatType === 'private'
2801
- ? { kind: 'command.result', text: creatingText }
2802
- : {
2803
- kind: 'system.notice',
2804
- text: creatingText,
2805
- subtype: 'session.creating',
2806
- };
2807
- await sendMessage(channelId, creatingText, this.getReplyContext(session), creatingPayload);
2812
+ await sendMessage(channelId, creatingText, this.getReplyContext(session), { kind: 'system.notice', text: creatingText, subtype: 'session.creating' });
2808
2813
  }
2809
2814
  const newSessionBaseagent = this.agentRegistry?.resolveByChannel(channel)?.baseagent || this.parseDefaultBaseagent();
2810
2815
  const previousMetadata = session?.metadata || activeSession?.metadata || {};
@@ -166,15 +166,24 @@ export function resumePendingSessions({ sessionManager, messageQueue, droppedTri
166
166
  });
167
167
  }
168
168
  }
169
- export function createDaemonShutdown({ disposePluginResources, ipcServer, readySignalPath, bindService, ecwebSupervisor, messageQueue, permissionGateway, removePermissionConfigListener, stopStatsPersistence, triggerSchedulers, agentMap, eventBus, removeGroupInviteConfigListener, groupInviteReviewService, channelLoader, channelInstances, controlChannel, sessionManager, removeAll, exit, }) {
169
+ export function createDaemonShutdown({ disposePluginResources, lifecycleNotices, ipcServer, readySignalPath, bindService, ecwebSupervisor, messageQueue, permissionGateway, removePermissionConfigListener, stopStatsPersistence, triggerSchedulers, agentMap, eventBus, removeGroupInviteConfigListener, groupInviteReviewService, channelLoader, channelInstances, startupRunners, cancelStartup, controlChannel, sessionManager, removeAll, exit, }) {
170
170
  let shutdownSignal = 'unknown';
171
171
  let shutdownInProgress = false;
172
172
  return async (signal, traceId) => {
173
173
  if (shutdownInProgress)
174
174
  return;
175
175
  shutdownInProgress = true;
176
+ cancelStartup?.();
176
177
  if (signal)
177
178
  shutdownSignal = signal;
179
+ // 先停掉还没发完的上线通知,避免和下面的下线通知交叉。
180
+ try {
181
+ lifecycleNotices?.beginShutdown();
182
+ }
183
+ catch { }
184
+ // 下线提示是 best-effort:发起后不等待,退出流程照常继续。
185
+ // 注意必须在这里触发——后面 daemon.channels 会断开 AUN 连接。
186
+ void lifecycleNotices?.sendOffline(shutdownSignal)?.catch(() => { });
178
187
  const pid = process.pid;
179
188
  const ppid = process.ppid;
180
189
  logger.info(`\n\nShutting down gracefully... (signal=${shutdownSignal}, pid=${pid}, ppid=${ppid})`);
@@ -185,33 +194,45 @@ export function createDaemonShutdown({ disposePluginResources, ipcServer, readyS
185
194
  kind: 'stop',
186
195
  traceId: traceId || undefined,
187
196
  processStartMs: Date.now(),
188
- firstPhase: 'daemon.shutdown',
189
197
  });
190
198
  trace.setMeta('signal', shutdownSignal);
191
199
  trace.setMeta('via', traceId ? 'ipc' : 'signal');
200
+ trace.addSpan('daemon.shutdown', trace.startedAtMs, Date.now());
201
+ const ipcStopStartedAt = Date.now();
192
202
  ipcServer.stopCpuTracking();
193
- trace.mark('daemon.stopIpcServer');
194
203
  ipcServer.stop();
195
204
  try {
196
205
  fs.unlinkSync(readySignalPath);
197
206
  }
198
207
  catch { }
199
208
  bindService?.stopCleanup();
200
- // 每个阶段单独闭合一次,甘特图上才能看到"卡在哪一段"而不是一整块。
209
+ trace.addSpan('daemon.stopIpcServer', ipcStopStartedAt, Date.now());
210
+ // 每个任务独立记录区间,允许阶段重叠,不能共用线性 mark/note 游标。
211
+ let shutdownSucceeded = true;
201
212
  const shutdownStep = async (name, label, operation) => {
202
- trace.mark(name);
213
+ const startedAt = Date.now();
214
+ let detail;
203
215
  try {
204
- await operation();
216
+ detail = (await operation()) || undefined;
205
217
  }
206
218
  catch (error) {
207
- trace.note(`失败: ${error instanceof Error ? error.message : String(error)}`);
219
+ shutdownSucceeded = false;
220
+ detail = `失败: ${error instanceof Error ? error.message : String(error)}`;
208
221
  logger.error(`[Shutdown] ${label} failed: ${error instanceof Error ? error.message : String(error)}`);
209
222
  }
223
+ finally {
224
+ trace.addSpan(name, startedAt, Date.now(), detail);
225
+ }
210
226
  };
211
- try {
212
- await shutdownStep('daemon.stopEcweb', 'stop ECWeb supervisor', async () => {
213
- await ecwebSupervisor?.stop();
227
+ // 先启动 ECWeb 关闭,与其余停机工作重叠;finally 必须汇合,不能遗留受管子进程。
228
+ const ecwebShutdown = shutdownStep('daemon.stopEcweb', 'stop ECWeb supervisor', async () => {
229
+ await ecwebSupervisor?.stop(timing => {
230
+ trace.addSpan(`daemon.stopEcweb.${timing.phase}`, timing.startMs, timing.endMs, timing.detail);
231
+ logger.info(`[Shutdown] ECWeb ${timing.phase}: ${timing.endMs - timing.startMs}ms`
232
+ + (timing.detail ? `; ${timing.detail}` : ''));
214
233
  });
234
+ });
235
+ try {
215
236
  const queueShutdown = messageQueue.shutdownGracefully();
216
237
  await shutdownStep('daemon.stopPermissions', 'cancel pending permissions', () => permissionGateway.cancelAllPending('daemon_restart'));
217
238
  // 这两步各带超时(5s / 6.5s),退出慢的头号嫌疑就是它们空等到超时。
@@ -223,6 +244,8 @@ export function createDaemonShutdown({ disposePluginResources, ipcServer, readyS
223
244
  });
224
245
  await shutdownStep('daemon.queueDrain', 'interrupt active message queue tasks', async () => { await queueShutdown; });
225
246
  await shutdownStep('daemon.agentRunners', 'dispose agent runners', async () => {
247
+ if (startupRunners)
248
+ await Promise.allSettled([startupRunners]);
226
249
  const currentInstances = [...agentMap.entries()].map(([key, agent]) => {
227
250
  const split = key.lastIndexOf('::');
228
251
  return {
@@ -242,18 +265,22 @@ export function createDaemonShutdown({ disposePluginResources, ipcServer, readyS
242
265
  const { stopGlobalSkillWatcher } = await import('./skill/global-watcher.js');
243
266
  await stopGlobalSkillWatcher();
244
267
  });
245
- await shutdownStep('daemon.channels', 'disconnect channels', async () => {
268
+ const channelsShutdown = shutdownStep('daemon.channels', 'disconnect channels', async () => {
246
269
  const timings = await channelLoader.disconnectAll(channelInstances);
247
270
  // 慢的渠道和超时的渠道写进阶段附注,甘特图上悬停就能看到,不用再翻日志。
248
271
  const slowest = timings[0];
249
272
  const timedOut = timings.filter(t => t.timedOut);
250
273
  if (timedOut.length > 0) {
251
- trace.note(`${timings.length} 个渠道;${timedOut.length} 个超时放弃(最慢 ${slowest?.name} ${slowest?.durationMs}ms)`);
274
+ return `${timings.length} 个渠道;${timedOut.length} 个超时放弃(最慢 ${slowest?.name} ${slowest?.durationMs}ms)`;
252
275
  }
253
276
  else if (slowest && slowest.durationMs >= 1_000) {
254
- trace.note(`${timings.length} 个渠道;最慢 ${slowest.name} ${slowest.durationMs}ms`);
277
+ return `${timings.length} 个渠道;最慢 ${slowest.name} ${slowest.durationMs}ms`;
255
278
  }
256
279
  });
280
+ const controlShutdown = controlChannel
281
+ ? shutdownStep('daemon.controlAid', 'disconnect control AID', () => controlChannel.disconnect())
282
+ : Promise.resolve();
283
+ await Promise.all([channelsShutdown, controlShutdown]);
257
284
  for (const instance of channelInstances) {
258
285
  const type = instance.channelType || instance.adapter.channelName;
259
286
  eventBus.publish({
@@ -263,14 +290,13 @@ export function createDaemonShutdown({ disposePluginResources, ipcServer, readyS
263
290
  reason: 'shutdown',
264
291
  });
265
292
  }
266
- if (controlChannel) {
267
- await shutdownStep('daemon.controlAid', 'disconnect control AID', () => controlChannel?.disconnect());
268
- }
269
293
  }
270
294
  catch (error) {
295
+ shutdownSucceeded = false;
271
296
  logger.error(`[Shutdown] Unexpected shutdown failure: ${error instanceof Error ? error.stack || error.message : String(error)}`);
272
297
  }
273
298
  finally {
299
+ await ecwebShutdown;
274
300
  await shutdownStep('daemon.pluginResources', 'dispose plugin resources', async () => { await disposePluginResources?.(); });
275
301
  await shutdownStep('daemon.finalizers', 'remove permission config listener', () => removePermissionConfigListener?.());
276
302
  await shutdownStep('daemon.statsPersistence', 'stop stats persistence', () => stopStatsPersistence?.());
@@ -279,7 +305,7 @@ export function createDaemonShutdown({ disposePluginResources, ipcServer, readyS
279
305
  logger.info('✓ Shutdown complete');
280
306
  // 必须在 exit 之前落盘:appendFileSync 是同步写,记录不会随进程消失。
281
307
  trace.mark('daemon.exit');
282
- trace.finish(true);
308
+ trace.finish(shutdownSucceeded);
283
309
  exit(0);
284
310
  }
285
311
  };
@@ -781,6 +781,25 @@ const CATALOG = [
781
781
  { path: 'phase', type: 'string' },
782
782
  ],
783
783
  },
784
+ {
785
+ type: 'trigger:interrupted',
786
+ namespace: 'trigger',
787
+ name: 'interrupted',
788
+ description: 'trigger run 被操作员中止',
789
+ internal: true,
790
+ fields: [
791
+ { path: 'triggerId', type: 'string' },
792
+ { path: 'name', type: 'string' },
793
+ { path: 'runId', type: 'string' },
794
+ { path: 'originTriggerId', type: 'string' },
795
+ { path: 'messageId', type: 'string' },
796
+ { path: 'reason', type: 'string' },
797
+ { path: 'error', type: 'string' },
798
+ { path: 'targetChannel', type: 'string' },
799
+ { path: 'targetChannelId', type: 'string' },
800
+ { path: 'fireTime', type: 'number' },
801
+ ],
802
+ },
784
803
  {
785
804
  type: 'trigger:skipped',
786
805
  namespace: 'trigger',
@@ -287,6 +287,7 @@ export class EvolAgentRegistry {
287
287
  const oldAgent = this.agents.get(aidOrName);
288
288
  if (!oldAgent)
289
289
  throw new Error(`Agent "${aidOrName}" not found`);
290
+ await hooks.beforeAgentOperation?.(oldAgent.aid);
290
291
  const expandedRaw = loadAgent(oldAgent.aid);
291
292
  if (!expandedRaw)
292
293
  throw new Error(`Agent ${oldAgent.aid}/config.json missing on reload`);
@@ -513,6 +514,7 @@ export class EvolAgentRegistry {
513
514
  const agent = this.agents.get(aidOrName);
514
515
  if (!agent)
515
516
  throw new Error(`Agent "${aidOrName}" not found`);
517
+ await hooks.beforeAgentOperation?.(agent.aid);
516
518
  if (agent.status === 'disabled')
517
519
  throw new Error('Agent is disabled; use enable/disable instead');
518
520
  if (agent.status === 'stopped') {
@@ -539,6 +541,7 @@ export class EvolAgentRegistry {
539
541
  const agent = this.agents.get(aidOrName);
540
542
  if (!agent)
541
543
  throw new Error(`Agent "${aidOrName}" not found`);
544
+ await hooks.beforeAgentOperation?.(agent.aid);
542
545
  if (agent.status === 'disabled')
543
546
  throw new Error('Agent is disabled; use enable instead');
544
547
  if (agent.status === 'error')
@@ -294,10 +294,11 @@ export class EvolAgent {
294
294
  };
295
295
  }
296
296
  resolveChatMode(chatType, globalChatmode) {
297
- const key = chatType === 'group' ? 'group' : 'private';
298
- return (this.merged.chatmode?.[key]
299
- ?? globalChatmode?.[key]
300
- ?? (key === 'group' ? 'proactive' : 'interactive'));
297
+ if (chatType === 'group')
298
+ return 'proactive';
299
+ return (this.merged.chatmode?.private
300
+ ?? globalChatmode?.private
301
+ ?? 'interactive');
301
302
  }
302
303
  // ── Reload 支持:替换 in-memory config 并复用 channels Map ───────────
303
304
  /** 用新的 raw + merged 替换 in-memory 状态。channels 由调用方决定如何 reconcile。 */
@@ -721,6 +721,12 @@ export function registerOperationIpcProviders({ ipcServer, sessionManager, messa
721
721
  const authorization = await authorizeManagedAgentOperation(params, 'system.status');
722
722
  if (!authorization.ok)
723
723
  return authorization;
724
+ if (query.raw) {
725
+ if (!authorization.fullAccess) {
726
+ return { ok: false, code: 'NOT_ALLOWED', error: '--raw requires a trusted fullaccess task' };
727
+ }
728
+ return { ok: true, data: { rawAuthorized: true } };
729
+ }
724
730
  return { ok: true, data: queryDiagnosticLogs(query, authorization.aid) };
725
731
  }
726
732
  catch (error) {