evolcore 0.0.48 → 0.0.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (302) hide show
  1. package/CHANGELOG.md +97 -0
  2. package/bin/ecmsg.js +9 -4
  3. package/dist/ability/caller/authorization.js +21 -0
  4. package/dist/ability/caller/command.js +164 -0
  5. package/dist/ability/caller/contract.js +102 -0
  6. package/dist/ability/caller/daemon.js +158 -0
  7. package/dist/ability/caller/service.js +380 -0
  8. package/dist/ability/command-contract.js +5 -0
  9. package/dist/ability/daemon.js +5 -1
  10. package/dist/ability/interop-v1.js +10 -3
  11. package/dist/ability/management.js +1 -0
  12. package/dist/agent-template/jobs.js +173 -1
  13. package/dist/agent-template/runtime.js +285 -8
  14. package/dist/agent-template/service.js +1159 -40
  15. package/dist/agent-template/types.js +2 -1
  16. package/dist/agents/baseagent-availability.js +27 -3
  17. package/dist/agents/baseagent-capability-adapter.js +102 -0
  18. package/dist/agents/baseagent-plugin-descriptor.js +274 -0
  19. package/dist/agents/baseagent-plugin-loader.js +145 -0
  20. package/dist/agents/baseagent.js +68 -2
  21. package/dist/agents/claude-gateway/agent-registration.js +389 -0
  22. package/dist/agents/claude-gateway/binding.js +96 -0
  23. package/dist/agents/claude-gateway/inbox.js +138 -0
  24. package/dist/agents/claude-gateway/index.js +125 -0
  25. package/dist/agents/claude-gateway/listing.js +330 -0
  26. package/dist/agents/claude-gateway/router.js +328 -0
  27. package/dist/agents/claude-gateway/sessions.js +128 -0
  28. package/dist/agents/claude-gateway/terminal.js +250 -0
  29. package/dist/agents/claude-gateway/transcript.js +272 -0
  30. package/dist/agents/claude-gateway/types.js +14 -0
  31. package/dist/agents/claude-runner.js +6 -10
  32. package/dist/agents/codex-runner.js +9 -2
  33. package/dist/agents/{gemini-runner.js → gemini/gemini-runner.js} +17 -17
  34. package/dist/{core/session/adapters → agents/gemini}/gemini-session-file-adapter.js +2 -2
  35. package/dist/agents/gemini/index.js +51 -0
  36. package/dist/aun/aid/control-aid.js +52 -32
  37. package/dist/aun/group/invite-service.js +6 -36
  38. package/dist/aun/group/operations.js +6 -0
  39. package/dist/aun/msg/mention-schema.js +1 -1
  40. package/dist/aun/msg/p2p.js +31 -2
  41. package/dist/aun/msg/upload.js +126 -3
  42. package/dist/build-identity.json +1 -1
  43. package/dist/channels/aun.js +1175 -457
  44. package/dist/cli/ability-command.js +42 -0
  45. package/dist/cli/agent-command.js +20 -1
  46. package/dist/cli/agent-create.js +78 -18
  47. package/dist/cli/agent-template.js +5 -3
  48. package/dist/cli/agent.js +91 -0
  49. package/dist/cli/aun-commands.js +92 -34
  50. package/dist/cli/bench.js +5 -2
  51. package/dist/cli/config.js +22 -6
  52. package/dist/cli/daemon-commands.js +245 -101
  53. package/dist/cli/directory.js +6 -1
  54. package/dist/cli/ecmsg-gateway.js +11 -9
  55. package/dist/cli/index.js +30 -5
  56. package/dist/cli/init.js +39 -63
  57. package/dist/cli/managed-command-guard.js +3 -0
  58. package/dist/cli/menu-client.js +32 -7
  59. package/dist/cli/model.js +20 -5
  60. package/dist/cli/pay-command.js +30 -0
  61. package/dist/cli/provider-command.js +6 -2
  62. package/dist/cli/quota.js +89 -0
  63. package/dist/cli/restart-monitor.js +2 -2
  64. package/dist/cli/role.js +1 -0
  65. package/dist/cli/services-command.js +12 -9
  66. package/dist/cli/team-workspace-command.js +56 -2
  67. package/dist/cli/thread-command.js +78 -12
  68. package/dist/config/access-policy.js +16 -3
  69. package/dist/config/config-field-policy.js +88 -9
  70. package/dist/config/config-manager.js +97 -47
  71. package/dist/config/config-operation-service.js +22 -1
  72. package/dist/config/gateway-config.js +9 -8
  73. package/dist/config/owner-config.js +0 -16
  74. package/dist/config/peer-role-resolver.js +1 -7
  75. package/dist/config/providers-config.js +107 -20
  76. package/dist/config/providers-management.js +45 -21
  77. package/dist/config/resolved-config-op.js +4 -44
  78. package/dist/config/schema-migration.js +78 -5
  79. package/dist/config/schema-registry.js +52 -7
  80. package/dist/config-store.js +1309 -17
  81. package/dist/core/agent-application-service.js +220 -1
  82. package/dist/core/agent-ipc-registration.js +19 -2
  83. package/dist/core/agent-reload-coordinator.js +5 -0
  84. package/dist/core/agent-runtime.js +198 -54
  85. package/dist/core/auth/agent-delegation.js +14 -0
  86. package/dist/core/auth/delegation-authorization.js +33 -26
  87. package/dist/core/auth/operation-authorizer.js +16 -1
  88. package/dist/core/auth/operation-catalog.js +59 -7
  89. package/dist/core/baseagent-loader.js +30 -3
  90. package/dist/core/capability/capability-manager.js +16 -7
  91. package/dist/core/channel-runtime.js +4 -2
  92. package/dist/core/command/agent-control.js +20 -2
  93. package/dist/core/command/agent-template-menu.js +4 -3
  94. package/dist/core/command/cli-intent-parser.js +28 -0
  95. package/dist/core/command/command-handler.js +45 -2
  96. package/dist/core/command/menu-catalog.js +20 -4
  97. package/dist/core/command/menu-file-path.js +70 -0
  98. package/dist/core/command/menu-handler.js +97 -73
  99. package/dist/core/command/menu-protocol.js +29 -0
  100. package/dist/core/command/menu-query-batch.js +2 -2
  101. package/dist/core/command/private-mention-menu.js +71 -0
  102. package/dist/core/command/remote-shell.js +565 -0
  103. package/dist/core/command/slash-handler.js +17 -26
  104. package/dist/core/command/team-workspace-bootstrap.js +2 -1
  105. package/dist/core/command/topic-slash.js +7 -1
  106. package/dist/core/daemon-bootstrap.js +0 -4
  107. package/dist/core/daemon-control.js +58 -1
  108. package/dist/core/daemon-lifecycle.js +29 -7
  109. package/dist/core/evolagent-registry.js +18 -9
  110. package/dist/core/handoff/runtime.js +1 -1
  111. package/dist/core/host-snapshot.js +8 -3
  112. package/dist/core/initialization/service.js +3 -0
  113. package/dist/core/interaction-router.js +130 -0
  114. package/dist/core/ipc-registration.js +5 -0
  115. package/dist/core/memory/consolidation-context.js +2 -1
  116. package/dist/core/memory/consolidation.js +35 -64
  117. package/dist/core/message/aun-ipc-sender.js +213 -74
  118. package/dist/core/message/aun-request-registry.js +31 -0
  119. package/dist/core/message/contact-admission.js +91 -6
  120. package/dist/core/message/contact-pending-inbound.js +113 -0
  121. package/dist/core/message/contact-thread-approval.js +212 -0
  122. package/dist/core/message/im-renderer.js +40 -1
  123. package/dist/core/message/message-admission.js +5 -39
  124. package/dist/core/message/message-bridge.js +197 -45
  125. package/dist/core/message/message-log.js +32 -0
  126. package/dist/core/message/message-queue.js +102 -18
  127. package/dist/core/message/peer-mode.js +15 -4
  128. package/dist/core/message/response-engine.js +174 -26
  129. package/dist/core/message/send-options.js +37 -3
  130. package/dist/core/message/send-routing.js +11 -7
  131. package/dist/core/model/config-scope.js +6 -14
  132. package/dist/core/model/model-catalog.js +5 -5
  133. package/dist/core/model/model-diagnostics.js +19 -0
  134. package/dist/core/model/model-fallback.js +13 -2
  135. package/dist/core/ownership/owner-resolver.js +12 -86
  136. package/dist/core/pack-auth.js +7 -0
  137. package/dist/core/pack-install.js +1 -1
  138. package/dist/core/permission/ec-command-parser.js +288 -77
  139. package/dist/core/permission/protected-paths.js +64 -9
  140. package/dist/core/permission/services-path-acl.js +458 -0
  141. package/dist/core/permission/tool-policy.js +26 -10
  142. package/dist/core/relation/peer-identity.js +13 -0
  143. package/dist/core/session/adapters/claude-session-file-adapter.js +6 -2
  144. package/dist/core/session/adapters/codex-session-file-adapter.js +4 -0
  145. package/dist/core/session/session-manager.js +47 -10
  146. package/dist/core/session/session-mapper.js +16 -0
  147. package/dist/core/skill/index-generator.js +2 -3
  148. package/dist/core/skill/switch-resolver.js +3 -0
  149. package/dist/core/task/task-recovery-service.js +1 -0
  150. package/dist/core/thread/command-parser.js +4 -1
  151. package/dist/core/thread/ipc-operation.js +4 -2
  152. package/dist/core/thread/thread-operation.js +25 -10
  153. package/dist/core/thread/thread-service.js +294 -55
  154. package/dist/core/thread/topic-id.js +67 -2
  155. package/dist/core/thread/types.js +15 -1
  156. package/dist/directory/owner-directory-admission.js +11 -8
  157. package/dist/directory/owner-directory-cache.js +19 -0
  158. package/dist/directory/owner-directory-markdown.js +1 -1
  159. package/dist/directory/owner-directory-policy.js +5 -30
  160. package/dist/directory/owner-directory-request-operation.js +5 -2
  161. package/dist/eck/kit-renderer.js +3 -2
  162. package/dist/eck/message-renderer.js +28 -5
  163. package/dist/ecweb/basic-settings-service.js +5 -9
  164. package/dist/ecweb/providers-service.js +4 -2
  165. package/dist/ecweb/runtime/supervisor.js +36 -8
  166. package/dist/event-center/center-config.js +9 -5
  167. package/dist/event-center/dispatcher.js +10 -1
  168. package/dist/event-center/ipc-operation.js +19 -0
  169. package/dist/event-center/registry.js +20 -5
  170. package/dist/event-center/runtime.js +10 -7
  171. package/dist/index.js +120 -41
  172. package/dist/ipc.js +83 -3
  173. package/dist/outputs/authorization.js +16 -0
  174. package/dist/outputs/cards.js +336 -0
  175. package/dist/outputs/events.js +3 -2
  176. package/dist/outputs/protocol.js +1 -0
  177. package/dist/outputs/service.js +2 -15
  178. package/dist/paths.js +48 -1
  179. package/dist/pay/command.js +38 -0
  180. package/dist/pay/protocol.js +136 -0
  181. package/dist/pay/runtime.js +188 -0
  182. package/dist/pay/service.js +384 -0
  183. package/dist/pay/store.js +81 -0
  184. package/dist/response-system/engines/v1/proactive-flow.js +29 -2
  185. package/dist/services/dispatcher.js +23 -5
  186. package/dist/services/host/main.js +388 -0
  187. package/dist/services/host/protocol.js +118 -0
  188. package/dist/services/host/resident.js +310 -0
  189. package/dist/services/host-client.js +386 -0
  190. package/dist/services/host-deploy.js +180 -0
  191. package/dist/services/host-launch.js +117 -0
  192. package/dist/services/host-recycle.js +203 -0
  193. package/dist/services/host-runtime.js +802 -0
  194. package/dist/services/idempotency.js +44 -86
  195. package/dist/services/index-generator.js +4 -3
  196. package/dist/services/index.js +204 -22
  197. package/dist/services/ipc-operation.js +288 -44
  198. package/dist/services/pack-manager.js +1 -0
  199. package/dist/services/script-runner.js +515 -83
  200. package/dist/services/service-payload.js +13 -7
  201. package/dist/services/validation.js +109 -4
  202. package/dist/stats/budget.js +1 -1
  203. package/dist/stats/model-resolver.js +2 -2
  204. package/dist/stats/quota-query.js +95 -0
  205. package/dist/trigger/application-service.js +6 -4
  206. package/dist/trigger/local-files.js +19 -9
  207. package/dist/trigger/scheduler.js +22 -12
  208. package/dist/trigger/script-sandbox.js +51 -8
  209. package/dist/utils/aid-bind.js +3 -0
  210. package/dist/utils/atomic-write.js +22 -8
  211. package/dist/utils/evolcore-version.js +2 -2
  212. package/dist/utils/host-info.js +173 -1
  213. package/dist/utils/logger.js +2 -2
  214. package/dist/utils/media-cache.js +190 -43
  215. package/dist/utils/npm-ops.js +43 -8
  216. package/dist/utils/restart-safety.js +14 -1
  217. package/dist/utils/system-memory.js +113 -25
  218. package/dist/utils/systemd-lifecycle.js +154 -0
  219. package/dist/utils/windows-shell-trust.js +7 -3
  220. package/dist/workbench/service.js +1 -1
  221. package/kits/docs/INDEX.md +3 -2
  222. package/kits/docs/aun/AUN/346/266/210/346/201/257/347/261/273/345/236/213/344/270/216/345/261/236/346/200/247.md +1 -0
  223. package/kits/docs/channels/aun.md +1 -1
  224. package/kits/docs/evolcore/INDEX.md +9 -6
  225. package/kits/docs/evolcore/agent.md +36 -1
  226. package/kits/docs/evolcore/aid.md +45 -3
  227. package/kits/docs/evolcore/config.md +5 -2
  228. package/kits/docs/evolcore/directory.md +8 -9
  229. package/kits/docs/evolcore/group.md +2 -1
  230. package/kits/docs/evolcore/memory-tags.md +2 -0
  231. package/kits/docs/evolcore/menu-client.md +3 -3
  232. package/kits/docs/evolcore/menu-protocol.md +7 -0
  233. package/kits/docs/evolcore/model.md +3 -0
  234. package/kits/docs/evolcore/msg.md +77 -10
  235. package/kits/docs/evolcore/pay.md +34 -0
  236. package/kits/docs/evolcore/provider.md +22 -1
  237. package/kits/docs/evolcore/quota.md +54 -0
  238. package/kits/docs/evolcore/role.md +3 -0
  239. package/kits/docs/evolcore/services.md +46 -18
  240. package/kits/docs/evolcore/stats.md +2 -0
  241. package/kits/docs/evolcore/thread-chain.md +2 -0
  242. package/kits/docs/evolcore/tool-authorization.md +10 -0
  243. package/kits/docs/evolcore/trigger.md +2 -0
  244. package/kits/rules/01-overview.md +11 -32
  245. package/kits/rules/02-navigation.md +7 -0
  246. package/kits/rules/06-channel.md +3 -3
  247. package/kits/schemas/_meta.json +38 -5
  248. package/kits/schemas/agent-config.schema.20.json +24 -0
  249. package/kits/schemas/agent-config.schema.21.json +974 -0
  250. package/kits/schemas/agent-config.schema.22.json +977 -0
  251. package/kits/schemas/agent-config.schema.23.json +958 -0
  252. package/kits/schemas/daemon.schema.10.json +373 -0
  253. package/kits/schemas/daemon.schema.9.json +12 -0
  254. package/kits/schemas/defaults.schema.7.json +472 -0
  255. package/kits/schemas/providers.schema.3.json +18 -2
  256. package/kits/schemas/relation-config.schema.13.json +289 -0
  257. package/kits/skills/.switches.json +17 -1
  258. package/kits/skills/ability/SKILL.md +229 -34
  259. package/kits/skills/ability/STRUCTURE.md +333 -0
  260. package/kits/skills/ability/references/cli.md +208 -0
  261. package/kits/skills/ability/references/development.md +107 -37
  262. package/kits/skills/ability/references/management.md +106 -46
  263. package/kits/skills/ability/references/runtime-protocol.md +65 -63
  264. package/kits/skills/agent-output-cards/SKILL.md +64 -0
  265. package/kits/skills/ec-group/SKILL.md +8 -6
  266. package/kits/skills/ec-group/TASK.md +186 -0
  267. package/kits/skills/ec-group/WORKLOG.md +180 -0
  268. package/kits/skills/ec-group-collaboration/SKILL.md +3 -3
  269. package/kits/skills/ec-pay/SKILL.md +101 -0
  270. package/kits/skills/ec-pay/references/pay-cli.md +110 -0
  271. package/kits/skills/ec-provider/SKILL.md +58 -9
  272. package/kits/skills/{ec-service-proxy → ec-proxy}/SKILL.md +8 -5
  273. package/kits/skills/ec-service-call/SKILL.md +135 -0
  274. package/kits/skills/ec-service-pack/SKILL.md +277 -0
  275. package/kits/skills/ec-trigger/SKILL.md +1 -1
  276. package/kits/templates/memory-consolidation/notes.md +2 -2
  277. package/kits/templates/memory-consolidation/workflow.md +46 -0
  278. package/kits/templates/roles/visitor.json +1 -0
  279. package/kits/templates/system-fragments/channel.md +13 -4
  280. package/kits/templates/system-fragments/commands.md +5 -3
  281. package/kits/templates/system-fragments/directory-contacts.md +3 -4
  282. package/kits/templates/system-fragments/reply.md +1 -0
  283. package/kits/templates/system-fragments/session.md +1 -1
  284. package/kits/templates/system-fragments/thread.md +27 -128
  285. package/kits/templates/system-fragments/venue.md +27 -0
  286. package/package.json +4 -5
  287. package/scripts/agent-template/inspect.mjs +79 -29
  288. package/scripts/agent-template/overlay.mjs +20 -2
  289. package/scripts/agent-template/shared/common.mjs +24 -6
  290. package/scripts/agent-template/shared/team-schema.json +23 -5
  291. package/scripts/agent-template/shared/template-contract.mjs +107 -17
  292. package/scripts/agent-template/shared/template-package.mjs +254 -29
  293. package/scripts/agent-template/shared/template-runtime.mjs +145 -2
  294. package/scripts/agent-template/shared/template.mjs +67 -9
  295. package/scripts/agent-template/team-pack.mjs +132 -41
  296. package/scripts/agent-template/team-preview.mjs +249 -5
  297. package/kits/docs/aun/ABILITY_CALLING.md +0 -280
  298. package/kits/docs/evolcore/ability.md +0 -185
  299. package/kits/skills/ability/references/calling.md +0 -56
  300. package/kits/skills/ability/references/contract-checklist.md +0 -37
  301. package/kits/skills/ability/references/recovery.md +0 -27
  302. /package/dist/{core/capability/providers → agents/gemini}/gemini-capability-provider.js +0 -0
@@ -1,5 +1,6 @@
1
1
  import { memoryHelpEntries } from './memory-slash.js';
2
2
  import { executeProviderMenu } from './provider-menu.js';
3
+ import { executePrivateMentionMenu, validatePrivateMentionMenuRequest } from './private-mention-menu.js';
3
4
  import { executeTemplateMenu, executeProviderModelCatalog } from './agent-template-menu.js';
4
5
  import { getBaseagentSnapshot, loadedBaseagentIds } from '../../agents/baseagent-availability.js';
5
6
  import { resolveBaseagentModelSelection } from '../../agents/baseagent.js';
@@ -15,7 +16,10 @@ import { isMainSession, isTopicSession, sessionLocalTopicId, sessionTopicThreadI
15
16
  import path from 'path';
16
17
  import fs from 'fs';
17
18
  import { parseFileSearchArgs, searchProjectFiles } from './file-search.js';
19
+ import { menuFileFallbackRoots, resolveMenuFilePath } from './menu-file-path.js';
18
20
  import os from 'os';
21
+ import { readEffectiveCpuCount } from '../../utils/host-info.js';
22
+ import { readSystemMemoryUsage } from '../../utils/system-memory.js';
19
23
  import crypto from 'crypto';
20
24
  import { CronExpressionParser } from 'cron-parser';
21
25
  import { parseDuration } from '../../trigger/parser.js';
@@ -28,6 +32,7 @@ import { loadDefaults, loadDaemonConfig } from '../../config-store.js';
28
32
  import { buildEcwebPairingUrl } from '../../ecweb/pairing.js';
29
33
  import { WEB_PACKAGE_NAME, RESTART_REQUEST_ID_ENV, RUNTIME_HOME_ENV, SESSION_ID_ENV } from '../../product.js';
30
34
  import { read as cfgRead, resolveEffective, resolveEffectiveFieldWithSource, routeFieldPath, write as cfgWrite, ConfigTarget, } from '../../config/config-manager.js';
35
+ import { fieldSchemaDefault } from '../../config/schema-registry.js';
31
36
  import { agentCreateCapabilities, execAgentAction, execAgentQuery, execAgentOptions, execAidAvatar, resolveProjectPath } from './agent-control.js';
32
37
  import { readInitialization } from '../../cli/agent-create.js';
33
38
  import { agentMdMenuService } from './agentmd-menu.js';
@@ -276,60 +281,6 @@ async function resolveTopicForkSource(sessionManager, channel, channelId, source
276
281
  const active = await sessionManager.getActiveSession(channel, channelId);
277
282
  return active && isMainSession(active) ? active : undefined;
278
283
  }
279
- /**
280
- * 解析并校验 menu `name=file` 的目标路径(query/fetch 共用)。
281
- *
282
- * 与文本 `/file` 的差异(见设计文档 §6.2):
283
- * - 接受项目内**绝对路径**(文本 /file 仍拒绝绝对路径)
284
- * - 项目外文件仅 aid channel owner(identity.role === 'owner')可取
285
- *
286
- * 沿用 /file 的安全校验链:拒绝 `..` 穿越、realpathSync 后验证落点。
287
- * 成功返回 `{ realPath, projectPath, stat }`;失败返回 `{ error, code }`。
288
- */
289
- function resolveMenuFilePath(input, projectPath, role, expectType) {
290
- if (!projectPath)
291
- return { error: '无法解析当前 agent projectPath', code: 'NO_PROJECT' };
292
- const raw = (input ?? '').toString().trim();
293
- if (!raw)
294
- return { error: '缺少 path 参数', code: 'MISSING_VALUE' };
295
- // 拒绝 .. 路径穿越(兼容两种分隔符)
296
- if (raw.split(path.sep).includes('..') || raw.split('/').includes('..')) {
297
- return { error: '不支持 .. 路径穿越', code: 'NO_PERMISSION' };
298
- }
299
- // 相对路径基于 projectPath 解析;绝对路径原样
300
- const resolved = path.isAbsolute(raw) ? raw : path.resolve(projectPath, raw);
301
- if (!fs.existsSync(resolved)) {
302
- return { error: '文件不存在', code: 'NOT_FOUND' };
303
- }
304
- let realPath;
305
- let realProjectPath;
306
- try {
307
- realPath = fs.realpathSync(resolved);
308
- realProjectPath = fs.realpathSync(projectPath);
309
- }
310
- catch {
311
- return { error: '文件不存在', code: 'NOT_FOUND' };
312
- }
313
- const inProject = realPath === realProjectPath || realPath.startsWith(realProjectPath + path.sep);
314
- // 项目外文件:仅 aid channel owner 可取(§6.2)
315
- if (!inProject && role !== 'owner') {
316
- return { error: '无权限:项目外文件仅 owner 可取', code: 'NO_PERMISSION' };
317
- }
318
- let stat;
319
- try {
320
- stat = fs.statSync(realPath);
321
- }
322
- catch {
323
- return { error: '文件不存在', code: 'NOT_FOUND' };
324
- }
325
- if (expectType === 'file' && stat.isDirectory()) {
326
- return { error: '暂不支持目录', code: 'NOT_SUPPORTED' };
327
- }
328
- if (expectType === 'directory' && !stat.isDirectory()) {
329
- return { error: '不是目录', code: 'NOT_A_DIRECTORY' };
330
- }
331
- return { realPath, projectPath: realProjectPath, stat };
332
- }
333
284
  function parseProjectRelativePath(input) {
334
285
  if (typeof input !== 'string' || !input.trim()) {
335
286
  return { error: '缺少 path 参数', code: 'MISSING_VALUE' };
@@ -709,7 +660,14 @@ function menuChatmodeField(args, session, explicitChatType) {
709
660
  }
710
661
  return chatmodeFieldForPeer(session?.chatType ?? explicitChatType, session?.metadata?.peerType);
711
662
  }
663
+ /**
664
+ * chatmode 未配置时的展示值:优先取 agent-config schema 的 `chatmode.<field>.default`
665
+ * (v22 起三个子字段各自有声明),schema 没声明才回落到内置表。
666
+ */
712
667
  function defaultChatmodeForField(field) {
668
+ const fromSchema = fieldSchemaDefault('agent-config', `chatmode.${field}`);
669
+ if (isChatMode(fromSchema))
670
+ return fromSchema;
713
671
  return field === 'private' ? 'interactive' : 'proactive';
714
672
  }
715
673
  function normalizeMenuPeer(input) {
@@ -850,7 +808,14 @@ function readMenuMentionMode(target, fallback = null, fallbackSource = null) {
850
808
  }
851
809
  }
852
810
  catch { }
853
- return { value: fallback, source: fallback === null ? null : fallbackSource };
811
+ if (fallback !== null)
812
+ return { value: fallback, source: fallbackSource };
813
+ // 配置链与会话元数据都未设:展示 schema 声明的出厂默认(v22 起 mentionMode 有 default)。
814
+ const fromSchema = fieldSchemaDefault(target.scope === 'agent' ? 'agent-config' : 'relation-config', target.fieldPath);
815
+ if (fromSchema === 'disabled' || fromSchema === 'mention-only' || fromSchema === 'auto') {
816
+ return { value: fromSchema, source: 'builtin' };
817
+ }
818
+ return { value: null, source: null };
854
819
  }
855
820
  function writeMenuMentionMode(target, value) {
856
821
  const route = routeFieldPath(target.fieldPath, target.scope);
@@ -1050,7 +1015,7 @@ export function isProcessLevelOwner(peerId, owners) {
1050
1015
  // ── 控制面双轨鉴权(见 docs/.../2026-06-10-control-channel-auth-design.md)──
1051
1016
  // 白名单而非黑名单:默认安全,新增进程级 action 需显式加入。
1052
1017
  /** /agent 的进程级 action:仅控制 channel 可执行。 */
1053
- export const PROCESS_LEVEL_AGENT_ACTIONS = new Set(['create', 'initialize', 'delete', 'enable', 'disable']);
1018
+ export const PROCESS_LEVEL_AGENT_ACTIONS = new Set(['create', 'initialize', 'delete', 'enable', 'disable', 'project']);
1054
1019
  /** /agent 的「本 agent 自管理」action:agent channel 仅 owner/admin 可对自身 aid 执行;update 另行收紧为 owner。 */
1055
1020
  export const SELF_MANAGE_AGENT_ACTIONS = new Set(['update', 'reload']);
1056
1021
  /** 判断 (cmdBase, action) 是否为进程级操作(仅控制 channel 可执行)。
@@ -1101,6 +1066,10 @@ function gateControlScope(opts) {
1101
1066
  function buildMenuIntent(verb, cmdBase, args, action, value, fromControlChannel = false) {
1102
1067
  if (cmdBase === '/agent-data-root' || cmdBase === '/relation-data-root')
1103
1068
  return null;
1069
+ if (cmdBase === '/private-mention-mode' && ['query', 'options', 'update'].includes(verb)) {
1070
+ return { operation: `privatementionmode.${verb === 'update' ? 'update' : 'current'}`,
1071
+ scope: 'agent', source: 'menu', args: { ...(args ?? {}), ...(value !== undefined ? { value } : {}) } };
1072
+ }
1104
1073
  if (cmdBase === '/file' && args?.rootId !== undefined)
1105
1074
  return null;
1106
1075
  const payload = { ...(args ?? {}), ...(value !== undefined ? { value } : {}) };
@@ -1249,6 +1218,8 @@ function buildMenuIntent(verb, cmdBase, args, action, value, fromControlChannel
1249
1218
  if (cmdBase === '/agent') {
1250
1219
  if (action === 'set-access')
1251
1220
  return intent('agent.access.write', 'agent', { action });
1221
+ if (action === 'project')
1222
+ return intent('agent.project.' + String(args?.operation ?? ''), 'process', { action });
1252
1223
  if (action === 'update' && args?.patch && Object.hasOwn(args.patch, 'avatar')) {
1253
1224
  return intent('ec.aid.avatar', 'agent', { action });
1254
1225
  }
@@ -1830,7 +1801,7 @@ async function loadMenuTopicSession(sessionManager, channel, channelId, threadId
1830
1801
  }
1831
1802
  /** 动态子菜单:根据 cmd 路径返回选项列表(供 menu.query + cmd 使用) */
1832
1803
  export async function getSubMenuItems(cmd, channel, channelId, userId, args, overrideIdentity, explicitChatType, fromControlChannel = false, authSubject, source = 'menu', transportReplyContext) {
1833
- const session = transportReplyContext?.threadId
1804
+ const session = transportReplyContext?.threadId && cmd.trim().split(' ')[0] !== '/private-mention-mode'
1834
1805
  ? await loadMenuTopicSession(this.sessionManager, channel, channelId, transportReplyContext.threadId)
1835
1806
  : await this.sessionManager.getActiveSession(channel, channelId);
1836
1807
  const subject = buildMenuAuthSubject(this, {
@@ -1891,6 +1862,9 @@ export async function getSubMenuItems(cmd, channel, channelId, userId, args, ove
1891
1862
  });
1892
1863
  if (optionsAuthDenied)
1893
1864
  throw { code: optionsAuthDenied.code, message: optionsAuthDenied.error, data: optionsAuthDenied.data };
1865
+ if (cmdBase0 === '/private-mention-mode') {
1866
+ return executePrivateMentionMenu('options', subject.selfAid, subject.role, args);
1867
+ }
1894
1868
  if (cmdBase0 === '/system') {
1895
1869
  if (args?.option !== 'logs')
1896
1870
  throw { code: 'NOT_SUPPORTED', message: `Unsupported system option: ${String(args?.option ?? '')}` };
@@ -2255,6 +2229,11 @@ export async function execMenuQuery(cmd, channel, channelId, userId, args, expli
2255
2229
  const cmdBase = cmd.trim().split(' ')[0];
2256
2230
  if (!cmdBase)
2257
2231
  return { error: '缺少命令', code: 'MISSING_CMD' };
2232
+ if (cmdBase === '/private-mention-mode') {
2233
+ const invalid = validatePrivateMentionMenuRequest({ type: 'menu.query', args });
2234
+ if (invalid)
2235
+ return { error: invalid.message, code: invalid.code };
2236
+ }
2258
2237
  if (cmdBase === '/template') {
2259
2238
  return executeTemplateMenu({ name: 'template', type: 'menu.query', args }, fromControlChannel ? authSubject : undefined, source);
2260
2239
  }
@@ -2298,7 +2277,7 @@ export async function execMenuQuery(cmd, channel, channelId, userId, args, expli
2298
2277
  }
2299
2278
  }
2300
2279
  }
2301
- if (transportReplyContext?.threadId && !groupResourceSession) {
2280
+ if (transportReplyContext?.threadId && !groupResourceSession && cmdBase !== '/private-mention-mode') {
2302
2281
  try {
2303
2282
  session = await loadMenuTopicSession(this.sessionManager, channel, channelId, transportReplyContext.threadId);
2304
2283
  }
@@ -2627,6 +2606,14 @@ export async function execMenuQuery(cmd, channel, channelId, userId, args, expli
2627
2606
  });
2628
2607
  if (authDenied)
2629
2608
  return authDenied;
2609
+ if (cmdBase === '/private-mention-mode') {
2610
+ try {
2611
+ return { data: executePrivateMentionMenu('query', subject.selfAid, subject.role, args) };
2612
+ }
2613
+ catch (error) {
2614
+ return menuResultFailure(error);
2615
+ }
2616
+ }
2630
2617
  if (cmdBase === '/aid' && args?.view === 'agentmd') {
2631
2618
  try {
2632
2619
  return { data: await agentMdMenuService.query(subject, args) };
@@ -2679,6 +2666,10 @@ export async function execMenuQuery(cmd, channel, channelId, userId, args, expli
2679
2666
  protocolVersion: 1, enabled: peekServiceRouter(root.targetAid)?.enabled
2680
2667
  ?? loadRouterConfig(agentServicesDir(root.targetAid)).config.enabled,
2681
2668
  notifications: this.eventCenter?.get(root.targetAid)?.runtime.nativeOutputAvailable === true,
2669
+ }, outputCards: {
2670
+ protocolVersion: 1, enabled: peekServiceRouter(root.targetAid)?.enabled
2671
+ ?? loadRouterConfig(agentServicesDir(root.targetAid)).config.enabled,
2672
+ notifications: this.eventCenter?.get(root.targetAid)?.runtime.nativeOutputAvailable === true,
2682
2673
  }, workbench: {
2683
2674
  protocolVersion: 1, enabled: peekServiceRouter(root.targetAid)?.enabled
2684
2675
  ?? loadRouterConfig(agentServicesDir(root.targetAid)).config.enabled,
@@ -3232,8 +3223,8 @@ export async function execMenuQuery(cmd, channel, channelId, userId, args, expli
3232
3223
  osName: os.type(),
3233
3224
  osRelease: os.release(),
3234
3225
  cpuModel: cpus[0]?.model ?? null,
3235
- cpuCount: cpus.length,
3236
- memoryTotalBytes: os.totalmem(),
3226
+ cpuCount: readEffectiveCpuCount(),
3227
+ memoryTotalBytes: readSystemMemoryUsage().memTotal,
3237
3228
  systemUptime: Math.floor(os.uptime()),
3238
3229
  };
3239
3230
  // 首屏只读本机基本信息,不定位全局 npm 包,也不等待 CLI 可用性探测。
@@ -3278,10 +3269,20 @@ export async function execMenuQuery(cmd, channel, channelId, userId, args, expli
3278
3269
  else {
3279
3270
  const role = identity.role;
3280
3271
  const projectPath = session?.projectPath ?? evolagent?.projectPath ?? this.getOwningAgent?.(channel)?.projectPath;
3281
- const resolved = resolveMenuFilePath(args?.path, projectPath, role, 'file');
3272
+ const resolved = resolveMenuFilePath(args?.path, projectPath, role, 'file', menuFileFallbackRoots(subject));
3282
3273
  if ('error' in resolved)
3283
3274
  return resolved;
3284
3275
  ({ realPath, stat } = resolved);
3276
+ if (role === 'owner') {
3277
+ const denied = await authorizeMenuIntent.call(this, {
3278
+ intent: buildMenuIntent('query', cmdBase, { ...args, path: realPath }),
3279
+ identity, subject, session, explicitChatType, channel, channelId, userId, fromControlChannel, source,
3280
+ });
3281
+ if (denied)
3282
+ return denied;
3283
+ // Pin the subsequent fetch/cache to the file that actually matched.
3284
+ responsePath = realPath;
3285
+ }
3285
3286
  }
3286
3287
  // sha256 仅对 ≤ 2 MB 文件计算,超过返回 null,客户端降级到 size+mtime(§4、§7 决策 2)
3287
3288
  let sha256 = null;
@@ -3318,6 +3319,11 @@ export async function execMenuUpdate(cmd, value, channel, channelId, userId, ove
3318
3319
  const cmdBase = cmd.trim().split(' ')[0];
3319
3320
  if (!cmdBase)
3320
3321
  return { error: '缺少命令', code: 'MISSING_CMD' };
3322
+ if (cmdBase === '/private-mention-mode') {
3323
+ const invalid = validatePrivateMentionMenuRequest({ type: 'menu.update', args, value });
3324
+ if (invalid)
3325
+ return { error: invalid.message, code: invalid.code };
3326
+ }
3321
3327
  if (cmdBase === '/provider') {
3322
3328
  return executeProviderMenu({ name: 'provider', cmd, type: 'menu.update', args, value }, fromControlChannel ? authSubject : undefined, source);
3323
3329
  }
@@ -3358,7 +3364,7 @@ export async function execMenuUpdate(cmd, value, channel, channelId, userId, ove
3358
3364
  let session = loadedContext.session;
3359
3365
  const evolagent = loadedContext.evolagent;
3360
3366
  if (transportReplyContext?.threadId) {
3361
- const modelAgentScope = (cmdBase === '/model' || cmdBase === '/effort')
3367
+ const modelAgentScope = (cmdBase === '/model' || cmdBase === '/effort' || cmdBase === '/private-mention-mode')
3362
3368
  && (menuStringArg(args, 'scope') ?? 'agent') === 'agent';
3363
3369
  if (modelAgentScope) {
3364
3370
  // Model settings belong to the Agent and can be changed from a locally
@@ -3533,6 +3539,14 @@ export async function execMenuUpdate(cmd, value, channel, channelId, userId, ove
3533
3539
  });
3534
3540
  if (authDenied)
3535
3541
  return authDenied;
3542
+ if (cmdBase === '/private-mention-mode') {
3543
+ try {
3544
+ return { data: executePrivateMentionMenu('update', subject.selfAid, subject.role, args, value) };
3545
+ }
3546
+ catch (error) {
3547
+ return menuResultFailure(error);
3548
+ }
3549
+ }
3536
3550
  // ── 进程级 /gateway update(网关配置,value 为 JSON:{scope,type,patch}) ──
3537
3551
  if (cmdBase === '/gateway') {
3538
3552
  let body;
@@ -4105,6 +4119,9 @@ export async function execMenuAction(cmd, action, args, channel, channelId, user
4105
4119
  args = { ...(args ?? {}), aid: selfAid };
4106
4120
  }
4107
4121
  const a = { ...(args ?? {}) };
4122
+ if (action === 'project') {
4123
+ return execAgentAction(action, a, userId ?? '', this.eventBus, this.agentApplicationService, agentFullAccessMenuSubject(subject, source));
4124
+ }
4108
4125
  if (action === 'create' && a.resume !== true && a.cancel !== true) {
4109
4126
  if (a.project !== undefined && typeof a.project !== 'string')
4110
4127
  return { error: 'project 必须是字符串', code: 'INVALID_ARGS' };
@@ -4213,10 +4230,6 @@ export async function execMenuAction(cmd, action, args, channel, channelId, user
4213
4230
  if (!result.ok)
4214
4231
  return { error: result.error, code: result.code || 'INTERNAL' };
4215
4232
  this.eventBus.publish({ type: 'agent:stopped', aid: a.aid, timestamp: Date.now() });
4216
- // 中断该 agent 正在执行的大模型调用
4217
- const handle = this.agentRegistry?.get(a.aid);
4218
- if (handle)
4219
- this.messageQueue.interruptByAgent(handle.name);
4220
4233
  }
4221
4234
  else {
4222
4235
  const result = this.agentApplicationService
@@ -4942,7 +4955,8 @@ export async function execMenuAction(cmd, action, args, channel, channelId, user
4942
4955
  isPendingInRegistry: () => hasLiveRestartMonitor({ requestId }),
4943
4956
  });
4944
4957
  if (!restartLaunch.ok) {
4945
- if (restartLaunch.pending) {
4958
+ const pending = readRestartRequest(pendingFile, requestId);
4959
+ if (restartLaunch.pending || (pending?.backend === 'systemd' && ['requested', 'accepted'].includes(pending.status))) {
4946
4960
  logger.error(`[System] Restart ownership is still unconfirmed (requestId=${restartRequestId}, PID=${restartLaunch.pid ?? 'unknown'})`);
4947
4961
  return {
4948
4962
  error: `重启请求状态暂不可确认(requestId=${restartRequestId})。启动链仍在运行,可能继续执行;请勿立即重复发起。诊断日志:${logFilePath},monitor 记录见 restart.log。`,
@@ -4956,13 +4970,14 @@ export async function execMenuAction(cmd, action, args, channel, channelId, user
4956
4970
  },
4957
4971
  };
4958
4972
  }
4959
- removeRestartRequest(pendingFile, requestId);
4973
+ if (pending?.backend !== 'systemd')
4974
+ removeRestartRequest(pendingFile, requestId);
4960
4975
  logger.error(`[System] Refusing menu restart: restart-monitor did not take ownership (${restartLaunch.reason})`);
4961
4976
  for (const line of (restartLaunch.stderrTail ?? '').split(/\r?\n/).filter(Boolean).slice(-8)) {
4962
4977
  logger.error(`[System] | ${line}`);
4963
4978
  }
4964
4979
  return {
4965
- error: `重启已中止:重启监控未接管(${restartLaunch.reason})。服务未停止,仍在运行当前版本。`,
4980
+ error: `重启未确认完成:${pending?.reason ?? restartLaunch.reason}。请检查重启日志和所属服务状态。`,
4966
4981
  code: 'RESTART_MONITOR_DEAD',
4967
4982
  data: {
4968
4983
  reasonCode: 'RESTART_MONITOR_DEAD',
@@ -4972,7 +4987,7 @@ export async function execMenuAction(cmd, action, args, channel, channelId, user
4972
4987
  },
4973
4988
  };
4974
4989
  }
4975
- logger.info(`[System] Restart monitor accepted request ${restartRequestId} (PID ${restartLaunch.pid ?? 'unknown'})`);
4990
+ logger.info(`[System] Restart lifecycle accepted request ${restartRequestId} (PID ${restartLaunch.pid ?? 'unknown'})`);
4976
4991
  }
4977
4992
  else {
4978
4993
  logger.info('[System] Suppressed real menu restart in test runtime');
@@ -5381,10 +5396,19 @@ export async function execMenuAction(cmd, action, args, channel, channelId, user
5381
5396
  }
5382
5397
  else {
5383
5398
  const projectPath = session?.projectPath ?? evolagent?.projectPath ?? this.getOwningAgent?.(channel)?.projectPath;
5384
- const resolved = resolveMenuFilePath(args?.path, projectPath, identity.role, 'file');
5399
+ const resolved = resolveMenuFilePath(args?.path, projectPath, identity.role, 'file', menuFileFallbackRoots(subject));
5385
5400
  if ('error' in resolved)
5386
5401
  return resolved;
5387
5402
  ({ realPath, stat } = resolved);
5403
+ if (identity.role === 'owner') {
5404
+ const denied = await authorizeMenuIntent.call(this, {
5405
+ intent: buildMenuIntent('action', cmdBase, { ...args, path: realPath }, 'fetch'),
5406
+ identity: authIdentity, subject, session: authSession, explicitChatType,
5407
+ channel, channelId, userId, fromControlChannel, source,
5408
+ });
5409
+ if (denied)
5410
+ return denied;
5411
+ }
5388
5412
  }
5389
5413
  if (stat.size > FILE_FETCH_MAX_SIZE) {
5390
5414
  return { error: `文件过大: ${(stat.size / 1024 / 1024).toFixed(1)} MB (限制 ${FILE_FETCH_MAX_SIZE / 1024 / 1024} MB)`, code: 'FILE_TOO_LARGE' };
@@ -5528,9 +5552,9 @@ async function execMenuForSystemControl(payload, context) {
5528
5552
  const isConnectRequest = name === 'connect' || compatCmd === '/connect';
5529
5553
  const requiresAgentTarget = (name === 'menu' && payload?.type === 'menu.query' && payload?.args?.view === 'queries')
5530
5554
  || isRoleRequest || isConnectRequest || [
5531
- 'observable', 'baseagent', 'model', 'effort', 'trigger', 'capability', 'group', 'aid', 'team-workspace', 'slash-commands', 'events',
5555
+ 'observable', 'baseagent', 'model', 'effort', 'trigger', 'capability', 'group', 'aid', 'team-workspace', 'slash-commands', 'events', 'private-mention-mode',
5532
5556
  ].includes(name)
5533
- || ['/observable', '/baseagent', '/model', '/effort', '/trigger', '/capability', '/group', '/aid', '/team-workspace', '/evolhelp', '/events'].includes(compatCmd ?? '')
5557
+ || ['/observable', '/baseagent', '/model', '/effort', '/trigger', '/capability', '/group', '/aid', '/team-workspace', '/evolhelp', '/events', '/private-mention-mode'].includes(compatCmd ?? '')
5534
5558
  || (!isProcessLevel && requestedContextKind !== undefined && requestedContextKind !== 'process');
5535
5559
  const target = isProcessLevel
5536
5560
  ? { channel: SYSTEM_CONTROL_CHANNEL }
@@ -12,6 +12,7 @@ import { validateTeamWorkspaceItemsArgs } from './team-workspace-items.js';
12
12
  import { isTeamMembersMenuRequest, validateTeamMembersMenuRequest } from './team-workspace-members-menu.js';
13
13
  import { validateAgentMdMenuRequest } from './agentmd-menu-request.js';
14
14
  import { validateEventsMenuRequest } from './eventcenter-menu.js';
15
+ import { validatePrivateMentionMenuRequest } from './private-mention-menu.js';
15
16
  const RETRY_DELAYS_MS = [250, 750, 2_000];
16
17
  const RETRY_WINDOW_MS = 5_000;
17
18
  export function isRetryableMenuTransportError(error) {
@@ -194,6 +195,7 @@ export const MENU_NAME_COMMANDS = Object.freeze({
194
195
  effort: '/effort',
195
196
  chatmode: '/chatmode',
196
197
  mentionmode: '/mention',
198
+ 'private-mention-mode': '/private-mention-mode',
197
199
  group: '/group',
198
200
  permission: '/perm',
199
201
  activity: '/activity',
@@ -425,6 +427,9 @@ export function validateMenuRequest(request) {
425
427
  }
426
428
  if (isTemplateRequest(request))
427
429
  return validateTemplateRequest(request);
430
+ if (request.name === 'private-mention-mode' || firstCommandToken(request.cmd) === '/private-mention-mode') {
431
+ return validatePrivateMentionMenuRequest(request);
432
+ }
428
433
  if ((request.name === 'aid' || firstCommandToken(request.cmd) === '/aid')
429
434
  && (request.args?.view === 'agentmd'
430
435
  || (typeof request.action === 'string' && request.action.startsWith('agentmd.')))) {
@@ -1040,6 +1045,30 @@ function writeMenuFlowRecord(record) {
1040
1045
  // Observability must never affect Menu execution.
1041
1046
  }
1042
1047
  }
1048
+ /** Paired records identify an unfinished await as well as completed slow work.
1049
+ * Only correlation metadata is logged, never request arguments or credentials. */
1050
+ export async function traceMenuStage(request, context, timing, stage, operation) {
1051
+ if (!request)
1052
+ return operation();
1053
+ const started = performance.now();
1054
+ const record = (phase) => writeMenuFlowRecord({
1055
+ ...menuFlowBaseRecord(request, context),
1056
+ event: 'menu.stage', stage, phase,
1057
+ receivedAt: timing.receivedAt,
1058
+ elapsedMs: menuElapsedMs(timing),
1059
+ ...(phase === 'started' ? {} : { durationMs: Math.max(0, Math.round(performance.now() - started)) }),
1060
+ });
1061
+ record('started');
1062
+ try {
1063
+ const result = await operation();
1064
+ record('completed');
1065
+ return result;
1066
+ }
1067
+ catch (error) {
1068
+ record('failed');
1069
+ throw error;
1070
+ }
1071
+ }
1043
1072
  export function logMenuRequestReceived(request, context) {
1044
1073
  writeMenuFlowRecord({
1045
1074
  ...menuFlowBaseRecord(request, context),
@@ -4,7 +4,7 @@ export const MENU_QUERY_BATCH_MAX_ITEMS = 32;
4
4
  export const MENU_QUERY_BATCH_CONCURRENCY = 6;
5
5
  // An explicit read-only surface. Never dispatch a client-supplied cmd or verb.
6
6
  export const MENU_QUERY_BATCH_NAMES = [
7
- 'role', 'agent', 'baseagent', 'activity', 'effort', 'model', 'chatmode', 'team-workspace',
7
+ 'role', 'agent', 'baseagent', 'activity', 'effort', 'model', 'chatmode', 'team-workspace', 'private-mention-mode',
8
8
  ];
9
9
  const QUERY_NAMES = new Set(MENU_QUERY_BATCH_NAMES);
10
10
  const ROLE_VIEWS = new Set(['capabilities', 'target', 'role', 'requester']);
@@ -168,7 +168,7 @@ export async function execMenuQueryBatch(input) {
168
168
  subject = context.subject;
169
169
  channelId = context.channelId;
170
170
  // These resource queries have their own exact argument contracts.
171
- if (!['role', 'agent', 'team-workspace'].includes(item.name)) {
171
+ if (!['role', 'agent', 'team-workspace', 'private-mention-mode'].includes(item.name)) {
172
172
  queryArgs = bindMenuExecutionContextArgs(args, context) ?? {};
173
173
  }
174
174
  }
@@ -0,0 +1,71 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { ConfigTarget, mutateConfig, read } from '../../config/config-manager.js';
3
+ const MODES = ['disabled', 'mention-only'];
4
+ export function validatePrivateMentionMenuRequest(request) {
5
+ if (!['menu.query', 'menu.options', 'menu.update'].includes(String(request.type))) {
6
+ return { code: 'NOT_SUPPORTED', message: 'private-mention-mode supports query, options and update' };
7
+ }
8
+ const args = request.args;
9
+ if (args !== undefined && (!args || typeof args !== 'object' || Array.isArray(args))) {
10
+ return { code: 'INVALID_ARGUMENT', message: 'args must be an object' };
11
+ }
12
+ if (args?.scope !== undefined && args.scope !== 'agent') {
13
+ return { code: 'SCOPE_MISMATCH', message: 'Private mention mode is Agent-scoped' };
14
+ }
15
+ const allowed = ['scope', 'self', 'context', ...(request.type === 'menu.update' ? ['expectedRevision'] : [])];
16
+ if (Object.keys(args ?? {}).some(key => !allowed.includes(key))) {
17
+ return { code: 'INVALID_ARGUMENT', message: 'Unsupported private-mention-mode argument' };
18
+ }
19
+ if (request.type === 'menu.update') {
20
+ if (!MODES.includes(request.value)) {
21
+ return { code: 'INVALID_ARGUMENT', message: 'value must be disabled or mention-only' };
22
+ }
23
+ if (typeof args?.expectedRevision !== 'string' || !args.expectedRevision.trim()) {
24
+ return { code: 'INVALID_ARGUMENT', message: 'args.expectedRevision is required' };
25
+ }
26
+ }
27
+ return null;
28
+ }
29
+ function state(self, config) {
30
+ const override = MODES.includes(config?.privateMentionMode)
31
+ ? config.privateMentionMode : null;
32
+ return {
33
+ scope: 'agent',
34
+ mode: override ?? 'disabled',
35
+ override,
36
+ source: override === null ? 'builtin' : 'agent',
37
+ revision: 'sha256:' + createHash('sha256').update(JSON.stringify([self, 'privateMentionMode', override])).digest('hex'),
38
+ };
39
+ }
40
+ /** Called after the standard Menu operation authorization; never spawns a CLI. */
41
+ export function executePrivateMentionMenu(kind, self, role, args, value) {
42
+ const invalid = validatePrivateMentionMenuRequest({ type: `menu.${kind}`, args, value });
43
+ if (invalid)
44
+ throw invalid;
45
+ if (!self)
46
+ throw { code: 'MISSING_AID', message: 'A target Agent is required' };
47
+ if (args?.self !== undefined && args.self !== self) {
48
+ throw { code: 'FORBIDDEN', message: 'Only the receiving Agent may be targeted' };
49
+ }
50
+ if (kind === 'update') {
51
+ // Keep this invariant even if a trusted fullaccess policy bypasses role rules.
52
+ if (role !== 'owner')
53
+ throw { code: 'FORBIDDEN', message: 'Private mention mode can only be changed by the Agent Owner' };
54
+ const mutation = mutateConfig(ConfigTarget.Agent, { self }, config => {
55
+ const current = state(self, config);
56
+ if (current.revision !== args.expectedRevision) {
57
+ throw { code: 'CONFLICT', message: 'Private mention mode has changed', data: { currentRevision: current.revision } };
58
+ }
59
+ config.privateMentionMode = value;
60
+ return state(self, config);
61
+ });
62
+ return { ...mutation.value, changed: mutation.changed, effectiveFrom: 'next-message' };
63
+ }
64
+ const current = state(self, read(ConfigTarget.Agent, { self }, { cache: false }));
65
+ if (kind === 'query')
66
+ return current;
67
+ return [
68
+ { value: 'disabled', label: '处理所有私聊消息' },
69
+ { value: 'mention-only', label: '只处理被 @ 的私聊消息' },
70
+ ].map(item => ({ ...item, selected: item.value === current.mode, revision: current.revision }));
71
+ }