evolcore 0.0.47 → 0.0.49

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 (266) hide show
  1. package/CHANGELOG.md +90 -1
  2. package/bin/ec-build.mjs +86 -0
  3. package/dist/agent-template/jobs.js +12 -4
  4. package/dist/agent-template/runtime.js +143 -40
  5. package/dist/agent-template/service.js +66 -13
  6. package/dist/agents/baseagent.js +60 -20
  7. package/dist/agents/claude-runner.js +34 -17
  8. package/dist/agents/codex-runner.js +36 -17
  9. package/dist/agents/ecagent-runner.js +7 -4
  10. package/dist/agents/gemini-runner.js +5 -2
  11. package/dist/agents/runner-types.js +5 -21
  12. package/dist/aun/aid/agentmd.js +5 -1
  13. package/dist/aun/msg/p2p.js +2 -1
  14. package/dist/aun/service-proxy.js +4 -2
  15. package/dist/build-identity.json +1 -0
  16. package/dist/channels/aun.js +722 -295
  17. package/dist/channels/daemon.js +9 -25
  18. package/dist/cli/aun-commands.js +86 -51
  19. package/dist/cli/code-stats.js +19 -8
  20. package/dist/cli/command-log.js +1 -1
  21. package/dist/cli/daemon-commands.js +44 -43
  22. package/dist/cli/directory.js +13 -2
  23. package/dist/cli/ecmsg-gateway.js +5 -2
  24. package/dist/cli/index.js +9 -9
  25. package/dist/cli/init-channel.js +4 -6
  26. package/dist/cli/init.js +72 -50
  27. package/dist/cli/invoke-command.js +1 -1
  28. package/dist/cli/managed-command-guard.js +2 -0
  29. package/dist/cli/model.js +20 -5
  30. package/dist/cli/provider-command.js +74 -13
  31. package/dist/cli/quota.js +89 -0
  32. package/dist/cli/role.js +62 -17
  33. package/dist/cli/services-command.js +1 -0
  34. package/dist/cli/stats.js +3 -3
  35. package/dist/cli/team-workspace-command.js +56 -2
  36. package/dist/cli/thread-command.js +16 -51
  37. package/dist/config/boot-log.js +3 -9
  38. package/dist/config/builtin-roles.js +5 -7
  39. package/dist/config/config-field-policy.js +71 -1
  40. package/dist/config/config-manager.js +13 -7
  41. package/dist/config/daemon-services.js +30 -3
  42. package/dist/config/gateway-config.js +2 -2
  43. package/dist/config/invoke-ipc-service.js +6 -4
  44. package/dist/config/peer-bind-code.js +3 -4
  45. package/dist/config/peer-book-store.js +62 -229
  46. package/dist/config/peer-book.js +26 -27
  47. package/dist/config/peer-role-resolver.js +16 -1
  48. package/dist/config/provider-identity-migration.js +4 -1
  49. package/dist/config/provider-ipc-service.js +56 -11
  50. package/dist/config/provider-menu-request.js +24 -5
  51. package/dist/config/provider-templates.js +127 -0
  52. package/dist/config/providers-config.js +67 -12
  53. package/dist/config/providers-management.js +477 -51
  54. package/dist/config/resolved-config-op.js +3 -2
  55. package/dist/config/role-command-service.js +248 -1
  56. package/dist/config/schema-migration.js +105 -4
  57. package/dist/core/agent-application-service.js +6 -1
  58. package/dist/core/agent-runtime.js +4 -0
  59. package/dist/core/auth/agent-delegation.js +2 -1
  60. package/dist/core/auth/auth-gateway.js +2 -1
  61. package/dist/core/auth/delegation-authorization.js +36 -26
  62. package/dist/core/auth/operation-authorizer.js +25 -0
  63. package/dist/core/auth/operation-catalog.js +37 -64
  64. package/dist/core/capability/providers/codex-capability-provider.js +7 -8
  65. package/dist/core/channel-loader.js +18 -0
  66. package/dist/core/command/agent-control.js +32 -0
  67. package/dist/core/command/cli-intent-parser.js +13 -0
  68. package/dist/core/command/command-handler.js +126 -87
  69. package/dist/core/command/menu-catalog.js +1 -0
  70. package/dist/core/command/menu-handler.js +67 -150
  71. package/dist/core/command/menu-protocol.js +31 -1
  72. package/dist/core/command/provider-menu.js +13 -3
  73. package/dist/core/command/remote-shell.js +565 -0
  74. package/dist/core/command/role-menu.js +47 -23
  75. package/dist/core/command/slash-handler.js +26 -43
  76. package/dist/core/command/team-workspace-items.js +81 -12
  77. package/dist/core/command/team-workspace-team.js +9 -71
  78. package/dist/core/command/topic-slash.js +9 -30
  79. package/dist/core/daemon-bootstrap.js +8 -1
  80. package/dist/core/daemon-control.js +64 -8
  81. package/dist/core/daemon-lifecycle.js +16 -2
  82. package/dist/core/evolagent-registry.js +20 -3
  83. package/dist/core/file-integrity/store.js +2 -0
  84. package/dist/core/handoff/runtime.js +37 -1
  85. package/dist/core/inference/text-inference.js +3 -1
  86. package/dist/core/initialization/service.js +11 -6
  87. package/dist/core/interaction-router.js +3 -0
  88. package/dist/core/invoke/executors/text.js +72 -19
  89. package/dist/core/ipc-registration.js +3 -1
  90. package/dist/core/message/aun-ipc-sender.js +279 -107
  91. package/dist/core/message/contact-admission.js +91 -6
  92. package/dist/core/message/contact-pending-inbound.js +113 -0
  93. package/dist/core/message/contact-thread-approval.js +212 -0
  94. package/dist/core/message/im-renderer.js +41 -2
  95. package/dist/core/message/message-admission.js +5 -39
  96. package/dist/core/message/message-bridge.js +140 -370
  97. package/dist/core/message/message-log.js +29 -0
  98. package/dist/core/message/message-queue.js +119 -15
  99. package/dist/core/message/message-utils.js +8 -0
  100. package/dist/core/message/response-engine.js +580 -134
  101. package/dist/core/message/send-routing.js +5 -1
  102. package/dist/core/model/catalog-service.js +31 -11
  103. package/dist/core/model/config-scope.js +6 -14
  104. package/dist/core/model/model-capabilities.js +22 -4
  105. package/dist/core/model/model-catalog.js +1 -0
  106. package/dist/core/model/model-diagnostics.js +19 -0
  107. package/dist/core/model/model-fallback.js +13 -2
  108. package/dist/core/ownership/owner-resolver.js +328 -50
  109. package/dist/core/pack-auth.js +3 -0
  110. package/dist/core/pack-install.js +1 -1
  111. package/dist/core/permission/ec-command-parser.js +106 -19
  112. package/dist/core/permission/protected-paths.js +6 -6
  113. package/dist/core/permission/services-path-acl.js +451 -0
  114. package/dist/core/permission/tool-policy.js +5 -1
  115. package/dist/core/relation/peer-identity.js +36 -1
  116. package/dist/core/relation/same-owner-proof.js +81 -112
  117. package/dist/core/session/adapters/codex-session-file-adapter.js +96 -15
  118. package/dist/core/session/session-file-health.js +13 -7
  119. package/dist/core/session/session-fs-store.js +91 -35
  120. package/dist/core/session/session-manager.js +68 -24
  121. package/dist/core/session/session-mapper.js +14 -34
  122. package/dist/core/session/session-transcript.js +5 -1
  123. package/dist/core/task/task-activity-store.js +84 -0
  124. package/dist/core/task/task-recovery-service.js +13 -0
  125. package/dist/core/thread/command-parser.js +7 -12
  126. package/dist/core/thread/thread-context-storage.js +3 -2
  127. package/dist/core/thread/thread-operation.js +2 -13
  128. package/dist/core/thread/thread-service.js +15 -46
  129. package/dist/core/thread/topic-id.js +15 -0
  130. package/dist/directory/owner-directory-admission.js +12 -9
  131. package/dist/directory/owner-directory-cache.js +64 -28
  132. package/dist/directory/owner-directory-markdown.js +14 -2
  133. package/dist/directory/owner-directory-policy.js +5 -30
  134. package/dist/directory/owner-directory-query-operation.js +29 -3
  135. package/dist/directory/owner-directory-remarks.js +11 -3
  136. package/dist/directory/owner-directory-request-operation.js +5 -2
  137. package/dist/eck/kit-renderer.js +1 -1
  138. package/dist/eck/message-renderer.js +112 -29
  139. package/dist/ecweb/basic-settings-service.js +3 -1
  140. package/dist/ecweb/message-context-service.js +1 -1
  141. package/dist/ecweb/pairing.js +4 -3
  142. package/dist/ecweb/providers-service.js +26 -1
  143. package/dist/ecweb/runtime/lifecycle.js +18 -8
  144. package/dist/ecweb/runtime/proxy-access.js +74 -0
  145. package/dist/ecweb/runtime/supervisor.js +36 -6
  146. package/dist/event-center/center-config.js +9 -5
  147. package/dist/event-center/dispatcher.js +10 -1
  148. package/dist/event-center/ipc-operation.js +19 -0
  149. package/dist/event-center/registry.js +29 -3
  150. package/dist/event-center/runtime.js +106 -11
  151. package/dist/event-center/script-runner.js +5 -5
  152. package/dist/index.js +96 -59
  153. package/dist/ipc.js +38 -3
  154. package/dist/outputs/authorization.js +16 -0
  155. package/dist/outputs/cards.js +336 -0
  156. package/dist/outputs/events.js +63 -0
  157. package/dist/outputs/protocol.js +103 -0
  158. package/dist/outputs/service.js +266 -0
  159. package/dist/paths.js +3 -0
  160. package/dist/proxy/manager.js +43 -13
  161. package/dist/services/index.js +114 -5
  162. package/dist/services/ipc-operation.js +88 -15
  163. package/dist/services/pack-manager.js +13 -1
  164. package/dist/services/router.js +21 -6
  165. package/dist/services/script-runner.js +5 -4
  166. package/dist/services/service-payload.js +13 -7
  167. package/dist/services/validation.js +1 -1
  168. package/dist/stats/budget.js +2 -2
  169. package/dist/stats/db.js +19 -0
  170. package/dist/stats/index.js +1 -1
  171. package/dist/stats/{price-resolver.js → model-resolver.js} +304 -23
  172. package/dist/stats/normalizer.js +2 -0
  173. package/dist/stats/query.js +35 -27
  174. package/dist/stats/quota-query.js +95 -0
  175. package/dist/stats/role-budget.js +5 -2
  176. package/dist/stats/writer.js +10 -6
  177. package/dist/trigger/audit.js +7 -0
  178. package/dist/trigger/authorization.js +105 -11
  179. package/dist/trigger/feedback.js +10 -0
  180. package/dist/trigger/history.js +37 -11
  181. package/dist/trigger/ipc-service.js +12 -1
  182. package/dist/trigger/manager.js +1 -0
  183. package/dist/trigger/scheduler.js +7 -5
  184. package/dist/trigger/script-executor.js +2 -1
  185. package/dist/trigger/script-sandbox.js +21 -3
  186. package/dist/trigger/validation.js +22 -0
  187. package/dist/utils/atomic-write.js +22 -8
  188. package/dist/utils/cross-platform.js +73 -26
  189. package/dist/utils/error-dict.json +94 -4
  190. package/dist/utils/error-utils.js +27 -4
  191. package/dist/utils/evolcore-version.js +36 -65
  192. package/dist/utils/host-info.js +100 -1
  193. package/dist/utils/msg-diag.js +1 -0
  194. package/dist/utils/npm-ops.js +43 -8
  195. package/dist/utils/process-introspect.js +12 -7
  196. package/dist/utils/process-tree.js +50 -2
  197. package/dist/utils/windows-shell-trust.js +2 -0
  198. package/dist/workbench/protocol.js +80 -0
  199. package/dist/workbench/service.js +359 -0
  200. package/ecagent/dist/types.d.ts +6 -2
  201. package/kits/docs/context-assembly.md +1 -1
  202. package/kits/docs/evolcore/INDEX.md +4 -2
  203. package/kits/docs/evolcore/aid.md +25 -0
  204. package/kits/docs/evolcore/config.md +16 -1
  205. package/kits/docs/evolcore/directory.md +30 -12
  206. package/kits/docs/evolcore/ecweb-lifecycle.md +15 -0
  207. package/kits/docs/evolcore/model.md +10 -0
  208. package/kits/docs/evolcore/msg.md +9 -0
  209. package/kits/docs/evolcore/peer.md +19 -65
  210. package/kits/docs/evolcore/provider.md +124 -4
  211. package/kits/docs/evolcore/quota.md +54 -0
  212. package/kits/docs/evolcore/role.md +83 -0
  213. package/kits/docs/evolcore/services.md +6 -6
  214. package/kits/docs/evolcore/stats.md +2 -0
  215. package/kits/docs/evolcore/team-workspace.md +1 -1
  216. package/kits/docs/evolcore/thread-chain.md +14 -15
  217. package/kits/docs/evolcore/tool-authorization.md +5 -0
  218. package/kits/docs/evolcore/trigger.md +12 -0
  219. package/kits/eck_message_manifest.json +12 -0
  220. package/kits/provider-templates.json +1213 -0
  221. package/kits/rules/04-relation.md +3 -3
  222. package/kits/schemas/_meta.json +14 -2
  223. package/kits/schemas/agent-config.schema.20.json +24 -0
  224. package/kits/schemas/contact-book.schema.4.json +52 -0
  225. package/kits/schemas/providers.schema.3.json +200 -0
  226. package/kits/skills/.switches.json +8 -0
  227. package/kits/skills/ability/references/calling.md +1 -1
  228. package/kits/skills/agent-output-cards/SKILL.md +57 -0
  229. package/kits/skills/ec-group/SKILL.md +2 -2
  230. package/kits/skills/ec-identity/SKILL.md +19 -72
  231. package/kits/skills/ec-provider/SKILL.md +270 -0
  232. package/kits/skills/ec-provider/scripts/check-model.mjs +80 -0
  233. package/kits/skills/ec-trigger/SKILL.md +1 -1
  234. package/kits/skills/thread-ops/SKILL.md +34 -21
  235. package/kits/templates/message-fragments/group-batch-item.md +1 -1
  236. package/kits/templates/message-fragments/group-batch.md +1 -1
  237. package/kits/templates/message-fragments/inject-default.md +1 -1
  238. package/kits/templates/message-fragments/interrupt-insert.md +1 -0
  239. package/kits/templates/message-fragments/item-group.md +1 -1
  240. package/kits/templates/message-fragments/item-private.md +1 -1
  241. package/kits/templates/message-fragments/thread-context.md +1 -1
  242. package/kits/templates/message-fragments/trigger-session.md +1 -1
  243. package/kits/templates/message-fragments/trigger-thread-check.md +1 -1
  244. package/kits/templates/roles/admin.json +2 -19
  245. package/kits/templates/roles/member.json +0 -3
  246. package/kits/templates/roles/visitor.json +1 -0
  247. package/kits/templates/system-fragments/baseagent.md +6 -0
  248. package/kits/templates/system-fragments/commands.md +4 -3
  249. package/kits/templates/system-fragments/directory-contacts.md +3 -4
  250. package/kits/templates/system-fragments/managed-runtime.md +1 -1
  251. package/kits/templates/system-fragments/relation.md +1 -1
  252. package/kits/templates/system-fragments/thread.md +7 -5
  253. package/kits/templates/system-fragments/venue.md +11 -0
  254. package/package.json +6 -4
  255. package/scripts/agent-template/inspect.mjs +50 -11
  256. package/scripts/agent-template/shared/common.mjs +11 -6
  257. package/scripts/agent-template/shared/team-schema.json +6 -4
  258. package/scripts/agent-template/shared/template-contract.mjs +62 -11
  259. package/scripts/agent-template/shared/template-package.mjs +189 -21
  260. package/scripts/agent-template/shared/template-runtime.mjs +54 -6
  261. package/scripts/agent-template/shared/template.mjs +2 -2
  262. package/scripts/agent-template/team-pack.mjs +52 -14
  263. package/dist/cli/peer.js +0 -127
  264. package/dist/config/peer-operation-service.js +0 -132
  265. package/dist/config/peer-request-service.js +0 -532
  266. package/dist/core/command/connect-menu.js +0 -624
@@ -16,6 +16,7 @@ import path from 'path';
16
16
  import fs from 'fs';
17
17
  import { parseFileSearchArgs, searchProjectFiles } from './file-search.js';
18
18
  import os from 'os';
19
+ import { readEffectiveCpuCount } from '../../utils/host-info.js';
19
20
  import crypto from 'crypto';
20
21
  import { CronExpressionParser } from 'cron-parser';
21
22
  import { parseDuration } from '../../trigger/parser.js';
@@ -40,7 +41,7 @@ import { isCapabilityType, listCapabilityOptions, queryCapabilityTypes, resolveC
40
41
  import { normalizeCliArgv, parseCliIntent, parseLegacyCliCommand, validateCliArgv, withDefaultRelationContext } from './cli-intent-parser.js';
41
42
  import { auditCommandAuthorization, auditFullAccessEvent, hashArgv } from '../auth/authorization-audit.js';
42
43
  import { authorizeOperation, authorizeFreshOperation, buildAuthSubject } from '../auth/auth-gateway.js';
43
- import { ownerResolver, getDaemonOwners, refreshOwnershipForAuthorization, OWNERSHIP_CACHE_MAX_AGE_MS } from '../ownership/owner-resolver.js';
44
+ import { ownerResolver, getDaemonOwners, refreshOwnershipForAuthorization, OWNERSHIP_CACHE_MAX_AGE_MS, OWNERSHIP_AUTHORIZATION_MAX_AGE_MS, } from '../ownership/owner-resolver.js';
44
45
  import { parseOwnershipCommand, executeOwnershipCommand, ownershipFailure } from '../../aun/aid/ownership-operation.js';
45
46
  import { authorizationDenialData, formatAuthorizationDenial } from '../auth/authorization-denial.js';
46
47
  import { evaluateRoleOperationCapability } from '../auth/operation-authorizer.js';
@@ -62,7 +63,6 @@ import { DEFAULT_SESSION_LOOP_SECONDS, MAX_SESSION_LOOP_SECONDS, MIN_SESSION_LOO
62
63
  import { remoteAccessService, validateAndRenewRemoteAccessToken } from '../auth/remote-access-store.js';
63
64
  import { listDiagnosticLogOptions, listRawConfigResources, queryDiagnosticLogs, readRawConfigResource, } from './daemon-diagnostics.js';
64
65
  import { roleMenuAction, roleMenuOperation, roleMenuOptions, roleMenuQuery, roleMenuUpdate, } from './role-menu.js';
65
- import { handleConnectMenu, connectMenuOperation } from './connect-menu.js';
66
66
  import { groupMenuAuthorizationArgs, groupMenuIntent, handleGroupMenu, } from './group-menu.js';
67
67
  import { getMenuCatalog, execMenuValueBatch, resolveExplicitMenuExecutionContext, resolveMenuCatalogContext, validateMenuCatalogArgs, validateMenuValueBatchArgs } from './menu-catalog.js';
68
68
  import { execMenuQueryBatch } from './menu-query-batch.js';
@@ -71,10 +71,13 @@ import { dataRootFailure, dataRootResolver } from './data-root-resolver.js';
71
71
  import { DataRootError, teamWorkspaceStore, readTeamWorkspaceNavigation } from './team-workspace-store.js';
72
72
  import { queryTeamWorkspaceCalendar } from './team-workspace-calendar.js';
73
73
  import { teamWorkspaceItemsIndex, validateTeamWorkspaceItemsArgs } from './team-workspace-items.js';
74
+ import { peekServiceRouter } from '../../services/index.js';
75
+ import { loadRouterConfig } from '../../services/router.js';
76
+ import { agentServicesDir } from '../../paths.js';
74
77
  import { executeTeamMembersAction, executeTeamMembersQuery, isTeamMembersMenuRequest } from './team-workspace-members-menu.js';
75
78
  import { agentStorageMenuService, isAgentStorageMenuRequest } from './agent-storage-menu.js';
76
79
  import { MAX_AUN_ATTACHMENT_SIZE } from '../../aun/msg/upload.js';
77
- import { normalizeTopicLabel, normalizeTopicStatus, resolveTopicArchiveFilter, } from '../session/session-mapper.js';
80
+ import { normalizeTopicStatus, resolveTopicArchiveFilter, } from '../session/session-mapper.js';
78
81
  import { notifyThreadRename } from '../thread/thread-operation.js';
79
82
  import { executeEventsQuery, executeEventsUpdate } from './eventcenter-menu.js';
80
83
  import { isAgentScopePath, isHClassPath, isLClassPath } from '../permission/protected-paths.js';
@@ -85,6 +88,27 @@ import { isAgentScopePath, isHClassPath, isLClassPath } from '../permission/prot
85
88
  function getBaseagentVersion(cmd) {
86
89
  return cachedCliVersion(cmd);
87
90
  }
91
+ /** Retained task details use immutable task relations and the current protocol Owner. */
92
+ async function canReadRetainedOwnerTask(input) {
93
+ const { selfAid, actorId, channelType, session, meta, requestedThreadId } = input;
94
+ if (channelType !== 'aun' || session.chatType !== 'private' || session.selfAID !== selfAid
95
+ || session.channelId !== actorId || meta.selfAid !== selfAid || meta.channel !== 'aun'
96
+ || meta.chatType !== 'private' || meta.peerId !== actorId || meta.channelId !== actorId
97
+ || requestedThreadId !== undefined && meta.threadId !== requestedThreadId)
98
+ return false;
99
+ try {
100
+ const owner = await ownerResolver.refresh(selfAid, { source: 'workbench.task-detail',
101
+ maxAgeMs: OWNERSHIP_AUTHORIZATION_MAX_AGE_MS, allowTransient: false });
102
+ const current = ownerResolver.snapshot(selfAid);
103
+ return owner.authorizationStatus === 'verified' && !owner.refreshFailure?.fallbackUsed
104
+ && (owner.validUntil ?? 0) > Date.now() && owner.ownerAid === actorId
105
+ && current.authorizationStatus === 'verified' && !current.refreshFailure?.fallbackUsed
106
+ && (current.validUntil ?? 0) > Date.now() && current.ownerAid === actorId && current.revision === owner.revision;
107
+ }
108
+ catch {
109
+ return false;
110
+ }
111
+ }
88
112
  const allEfforts = CONFIGURABLE_EFFORTS;
89
113
  const PERMISSION_MODE_KEYS = PUBLIC_PERMISSION_MODES;
90
114
  /** menu file: fetch 文件大小上限(与 /file 和 AUN sendFile 一致) */
@@ -225,10 +249,8 @@ export function buildTopicForkSourcePayload(session) {
225
249
  }
226
250
  function buildSessionPayload(session, name) {
227
251
  const payload = { id: session.id, name };
228
- if (session.label)
229
- payload.label = session.label;
230
252
  if (isTopicSession(session))
231
- payload.topicStatus = session.topicStatus ?? 'pending';
253
+ payload.topicStatus = session.topicStatus ?? 'active';
232
254
  if (session.agentSessionId)
233
255
  payload.agentSessionId = session.agentSessionId;
234
256
  const forkSource = buildTopicForkSourcePayload(session);
@@ -1136,6 +1158,8 @@ function buildMenuIntent(verb, cmdBase, args, action, value, fromControlChannel
1136
1158
  if (cmdBase === '/system')
1137
1159
  return intent('system.status', 'process');
1138
1160
  if (cmdBase === '/agent') {
1161
+ if (args?.view === 'access')
1162
+ return intent('agent.access.read', 'agent');
1139
1163
  return intent(fromControlChannel && !args?.aid ? 'agent.list' : 'agent.show', fromControlChannel ? 'control' : 'agent');
1140
1164
  }
1141
1165
  if (cmdBase === '/trigger')
@@ -1224,6 +1248,8 @@ function buildMenuIntent(verb, cmdBase, args, action, value, fromControlChannel
1224
1248
  return intent('system.paircode', 'process', { action });
1225
1249
  }
1226
1250
  if (cmdBase === '/agent') {
1251
+ if (action === 'set-access')
1252
+ return intent('agent.access.write', 'agent', { action });
1227
1253
  if (action === 'update' && args?.patch && Object.hasOwn(args.patch, 'avatar')) {
1228
1254
  return intent('ec.aid.avatar', 'agent', { action });
1229
1255
  }
@@ -1834,30 +1860,6 @@ export async function getSubMenuItems(cmd, channel, channelId, userId, args, ove
1834
1860
  throw authorized;
1835
1861
  return await roleMenuOptions(authorized.context, args);
1836
1862
  }
1837
- if (cmdBase0 === '/connect') {
1838
- const identity = overrideIdentity ?? this.sessionManager.resolveIdentity(channel, userId, ...menuIdentityArgs(session));
1839
- const authorized = await authorizeRoleMenu(this, {
1840
- kind: 'options', args, operation: connectMenuOperation('options', args), identity, subject: authSubject, session, channel, channelId,
1841
- userId, fromControlChannel, source,
1842
- });
1843
- if ('error' in authorized)
1844
- throw authorized;
1845
- try {
1846
- const result = await handleConnectMenu({ type: 'menu.options', subtype: 'options', args }, authorized.context);
1847
- if ('error' in result)
1848
- throw result.error;
1849
- const opts = result.data?.options ?? [];
1850
- return opts.map((opt) => ({
1851
- value: opt.option,
1852
- label: opt.label,
1853
- desc: opt.description,
1854
- ...(typeof opt.selected === 'boolean' ? { selected: opt.selected } : {}),
1855
- }));
1856
- }
1857
- catch (error) {
1858
- throw menuResultFailure(error);
1859
- }
1860
- }
1861
1863
  if (cmdBase0 === '/group') {
1862
1864
  const result = await executeGroupMenu(this, {
1863
1865
  kind: 'options', args,
@@ -2017,16 +2019,6 @@ export async function getSubMenuItems(cmd, channel, channelId, userId, args, ove
2017
2019
  forkHistoryVersion: 1,
2018
2020
  }));
2019
2021
  }
2020
- const hasLabel = args && (Object.hasOwn(args, 'label') || Object.hasOwn(args, 'lable'));
2021
- let label;
2022
- if (hasLabel) {
2023
- try {
2024
- label = normalizeTopicLabel(Object.hasOwn(args, 'label') ? args.label : args.lable);
2025
- }
2026
- catch (error) {
2027
- throw { code: 'INVALID_ARGS', message: error.message };
2028
- }
2029
- }
2030
2022
  let archiveFilter;
2031
2023
  try {
2032
2024
  archiveFilter = resolveTopicArchiveFilter(args?.archived === undefined && args?.topicStatus === 'archived' ? true : args?.archived);
@@ -2046,7 +2038,7 @@ export async function getSubMenuItems(cmd, channel, channelId, userId, args, ove
2046
2038
  }
2047
2039
  const metadataOnly = args?.metadataOnly === true;
2048
2040
  const topics = sessions.filter((s) => isTopicSession(s)
2049
- && (!hasLabel || s.label === label) && (!topicStatus || s.topicStatus === topicStatus));
2041
+ && (!topicStatus || s.topicStatus === topicStatus));
2050
2042
  const items = [];
2051
2043
  for (let offset = 0; offset < topics.length; offset += 4) {
2052
2044
  items.push(...await Promise.all(topics.slice(offset, offset + 4)
@@ -2058,10 +2050,10 @@ export async function getSubMenuItems(cmd, channel, channelId, userId, args, ove
2058
2050
  const sessions = await this.sessionManager.listSessions(channel, channelId);
2059
2051
  const active = cmd === '/del' ? await this.sessionManager.getActiveSession(channel, channelId) : null;
2060
2052
  const currentSession = session;
2061
- const items = sessions
2053
+ const items = [];
2054
+ for (const s of sessions
2062
2055
  .filter((s) => isMainSession(s))
2063
- .filter((s) => !active || s.id !== active.id)
2064
- .map((s) => {
2056
+ .filter((s) => !active || s.id !== active.id)) {
2065
2057
  const displayName = displaySessionTitle(s.name, s.id.slice(0, 8));
2066
2058
  const item = {
2067
2059
  value: s.name || s.id.slice(0, 8),
@@ -2070,17 +2062,17 @@ export async function getSubMenuItems(cmd, channel, channelId, userId, args, ove
2070
2062
  };
2071
2063
  if (s.agentSessionId) {
2072
2064
  item.agentSessionId = s.agentSessionId;
2073
- const fileInfo = this.sessionManager.getSessionFileInfo(s.projectPath, s.agentSessionId, s.baseagent, s.selfAID);
2074
- if (fileInfo.turns)
2075
- item.turns = fileInfo.turns;
2076
- const firstMsg = this.sessionManager.readSessionFirstMessage(s.projectPath, s.agentSessionId, s.baseagent, s.selfAID);
2065
+ const summary = await this.sessionManager.readSessionMenuSummary(s.projectPath, s.agentSessionId, s.baseagent, s.selfAID);
2066
+ if (summary.turns)
2067
+ item.turns = summary.turns;
2068
+ const firstMsg = summary.firstMessage;
2077
2069
  if (firstMsg)
2078
2070
  item.preview = firstMsg.length > 80 ? firstMsg.slice(0, 80) + '…' : firstMsg;
2079
2071
  }
2080
2072
  if (s.updatedAt)
2081
2073
  item.lastActive = s.updatedAt;
2082
- return item;
2083
- });
2074
+ items.push(item);
2075
+ }
2084
2076
  if (cmd === '/s' || cmd === '/session') {
2085
2077
  items.push({ value: 'cli', label: '查看 CLI 会话', desc: '列出未导入的 CLI 本地会话' });
2086
2078
  }
@@ -2558,28 +2550,6 @@ export async function execMenuQuery(cmd, channel, channelId, userId, args, expli
2558
2550
  return menuResultFailure(error);
2559
2551
  }
2560
2552
  }
2561
- if (cmdBase === '/connect') {
2562
- const authorized = await authorizeRoleMenu(this, {
2563
- kind: 'query', args, operation: connectMenuOperation('query', args), identity, subject, session, channel, channelId,
2564
- userId, fromControlChannel, source,
2565
- });
2566
- if ('error' in authorized)
2567
- return authorized;
2568
- try {
2569
- const result = await handleConnectMenu({ type: 'menu.query', subtype: 'query', args }, authorized.context);
2570
- if (result.error) {
2571
- return {
2572
- error: result.error.message,
2573
- code: result.error.code,
2574
- ...(result.error.data === undefined ? {} : { data: result.error.data }),
2575
- };
2576
- }
2577
- return { data: result.data };
2578
- }
2579
- catch (error) {
2580
- return menuResultFailure(error);
2581
- }
2582
- }
2583
2553
  if (cmdBase === '/group') {
2584
2554
  return await executeGroupMenu(this, {
2585
2555
  kind: 'query', args, identity, subject, session,
@@ -2620,12 +2590,15 @@ export async function execMenuQuery(cmd, channel, channelId, userId, args, expli
2620
2590
  if (!meta)
2621
2591
  return { error: 'Task not found', code: 'NOT_FOUND' };
2622
2592
  const groupId = session.metadata?.groupId || session.channelId;
2623
- if (meta.selfAid !== subject.selfAid || meta.sessionId !== session.id
2593
+ const sameSession = !(meta.selfAid !== subject.selfAid || meta.sessionId !== session.id
2624
2594
  || meta.channel !== (subject.channelType || channel.split('#')[0])
2625
2595
  || meta.chatType !== session.chatType
2626
2596
  || (meta.chatType === 'group'
2627
2597
  ? meta.groupId !== groupId || meta.channelId !== groupId
2628
- : meta.peerId !== subject.actorId || meta.channelId !== subject.actorId)) {
2598
+ : meta.peerId !== subject.actorId || meta.channelId !== subject.actorId));
2599
+ if (!sameSession && !await canReadRetainedOwnerTask({ selfAid: subject.selfAid, actorId: subject.actorId,
2600
+ channelType: subject.channelType || channel.split('#')[0], session, meta,
2601
+ requestedThreadId: transportReplyContext?.threadId })) {
2629
2602
  return { error: 'Task is not available in this session', code: 'FORBIDDEN' };
2630
2603
  }
2631
2604
  return { data: args.view === 'activities'
@@ -2702,7 +2675,20 @@ export async function execMenuQuery(cmd, channel, channelId, userId, args, expli
2702
2675
  return { error: 'agent-data-root does not accept args', code: 'INVALID_ARGUMENT' };
2703
2676
  }
2704
2677
  try {
2705
- return { data: dataRootResolver.issueAgentRoot(subject) };
2678
+ const root = dataRootResolver.issueAgentRoot(subject);
2679
+ return { data: { ...root, outputs: {
2680
+ protocolVersion: 1, enabled: peekServiceRouter(root.targetAid)?.enabled
2681
+ ?? loadRouterConfig(agentServicesDir(root.targetAid)).config.enabled,
2682
+ notifications: this.eventCenter?.get(root.targetAid)?.runtime.nativeOutputAvailable === true,
2683
+ }, outputCards: {
2684
+ protocolVersion: 1, enabled: peekServiceRouter(root.targetAid)?.enabled
2685
+ ?? loadRouterConfig(agentServicesDir(root.targetAid)).config.enabled,
2686
+ notifications: this.eventCenter?.get(root.targetAid)?.runtime.nativeOutputAvailable === true,
2687
+ }, workbench: {
2688
+ protocolVersion: 1, enabled: peekServiceRouter(root.targetAid)?.enabled
2689
+ ?? loadRouterConfig(agentServicesDir(root.targetAid)).config.enabled,
2690
+ notifications: this.eventCenter?.get(root.targetAid)?.runtime.nativeOutputAvailable === true,
2691
+ } } };
2706
2692
  }
2707
2693
  catch (error) {
2708
2694
  return dataRootFailure(error);
@@ -2847,7 +2833,7 @@ export async function execMenuQuery(cmd, channel, channelId, userId, args, expli
2847
2833
  }
2848
2834
  let turns = 0;
2849
2835
  if (session.agentSessionId) {
2850
- const fileInfo = this.sessionManager.getSessionFileInfo(session.projectPath, session.agentSessionId, session.baseagent, session.selfAID);
2836
+ const fileInfo = await this.sessionManager.getSessionFileInfoAsync(session.projectPath, session.agentSessionId, session.baseagent, session.selfAID);
2851
2837
  turns = fileInfo.turns;
2852
2838
  }
2853
2839
  const data = {
@@ -2976,13 +2962,12 @@ export async function execMenuQuery(cmd, channel, channelId, userId, args, expli
2976
2962
  }
2977
2963
  let turns = 0;
2978
2964
  if (topic.agentSessionId) {
2979
- turns = this.sessionManager.getSessionFileInfo(topic.projectPath, topic.agentSessionId, topic.baseagent, topic.selfAID).turns;
2965
+ turns = (await this.sessionManager.getSessionFileInfoAsync(topic.projectPath, topic.agentSessionId, topic.baseagent, topic.selfAID)).turns;
2980
2966
  }
2981
2967
  const data = {
2982
2968
  threadId: sessionLocalTopicId(topic) ?? '',
2983
2969
  name: topic.name || null,
2984
- label: topic.label || null,
2985
- topicStatus: topic.topicStatus ?? 'pending',
2970
+ topicStatus: topic.topicStatus ?? 'active',
2986
2971
  agentSessionId: topic.agentSessionId || null,
2987
2972
  status: executionState === 'interrupting' ? 'interrupting' : isProcessing || queueLength > 0 ? 'processing' : 'idle',
2988
2973
  createdAt: topic.createdAt,
@@ -3252,7 +3237,7 @@ export async function execMenuQuery(cmd, channel, channelId, userId, args, expli
3252
3237
  osName: os.type(),
3253
3238
  osRelease: os.release(),
3254
3239
  cpuModel: cpus[0]?.model ?? null,
3255
- cpuCount: cpus.length,
3240
+ cpuCount: readEffectiveCpuCount(),
3256
3241
  memoryTotalBytes: os.totalmem(),
3257
3242
  systemUptime: Math.floor(os.uptime()),
3258
3243
  };
@@ -3534,28 +3519,6 @@ export async function execMenuUpdate(cmd, value, channel, channelId, userId, ove
3534
3519
  return menuResultFailure(error);
3535
3520
  }
3536
3521
  }
3537
- if (cmdBase === '/connect') {
3538
- const authorized = await authorizeRoleMenu(this, {
3539
- kind: 'update', args, value: arg, operation: connectMenuOperation('update', args, arg), identity, subject: authSubject, session, channel, channelId,
3540
- userId, fromControlChannel, source,
3541
- });
3542
- if ('error' in authorized)
3543
- return authorized;
3544
- try {
3545
- const result = await handleConnectMenu({ type: 'menu.update', subtype: 'update', args, value: arg }, authorized.context);
3546
- if (result.error) {
3547
- return {
3548
- error: result.error.message,
3549
- code: result.error.code,
3550
- ...(result.error.data === undefined ? {} : { data: result.error.data }),
3551
- };
3552
- }
3553
- return { data: result.data };
3554
- }
3555
- catch (error) {
3556
- return menuResultFailure(error);
3557
- }
3558
- }
3559
3522
  if (cmdBase === '/group') {
3560
3523
  return await executeGroupMenu(this, {
3561
3524
  kind: 'update', args, value: arg, identity, subject, session,
@@ -4039,28 +4002,6 @@ export async function execMenuAction(cmd, action, args, channel, channelId, user
4039
4002
  return menuResultFailure(error);
4040
4003
  }
4041
4004
  }
4042
- if (cmdBase === '/connect') {
4043
- const authorized = await authorizeRoleMenu(this, {
4044
- kind: 'action', args, operation: connectMenuOperation('action', args), identity: authIdentity, subject, session: authSession,
4045
- channel, channelId, userId, fromControlChannel, source,
4046
- });
4047
- if ('error' in authorized)
4048
- return authorized;
4049
- try {
4050
- const result = await handleConnectMenu({ type: 'menu.action', subtype: 'action', action, args }, authorized.context);
4051
- if (result.error) {
4052
- return {
4053
- error: result.error.message,
4054
- code: result.error.code,
4055
- ...(result.error.data === undefined ? {} : { data: result.error.data }),
4056
- };
4057
- }
4058
- return { data: result.data };
4059
- }
4060
- catch (error) {
4061
- return menuResultFailure(error);
4062
- }
4063
- }
4064
4005
  if ((cmdBase === '/agent' || cmdBase === '/aid') && !args?.aid) {
4065
4006
  const selfAid = this.getOwningAgent?.(channel)?.aid;
4066
4007
  if (selfAid)
@@ -4498,16 +4439,6 @@ export async function execMenuAction(cmd, action, args, channel, channelId, user
4498
4439
  return { error: `不支持的 trigger action: ${action}`, code: 'INVALID_ARGS' };
4499
4440
  }
4500
4441
  if (cmdBase === '/topic') {
4501
- const hasLabel = args && (Object.hasOwn(args, 'label') || Object.hasOwn(args, 'lable'));
4502
- let label;
4503
- if (hasLabel && (action === 'fork' || action === 'label')) {
4504
- try {
4505
- label = normalizeTopicLabel(Object.hasOwn(args, 'label') ? args.label : args.lable);
4506
- }
4507
- catch (error) {
4508
- return { error: error.message, code: 'INVALID_ARGS' };
4509
- }
4510
- }
4511
4442
  if (action === 'fork') {
4512
4443
  if (!this.canReadTopics(identity.role))
4513
4444
  return { error: '无权限创建话题分支', code: 'FORBIDDEN' };
@@ -4599,7 +4530,6 @@ export async function execMenuAction(cmd, action, args, channel, channelId, user
4599
4530
  const forkedAgentSessionId = await currentAgent.forkSessionAt(current.agentSessionId, current.projectPath, actualSourceMessageId, name || undefined, { sessionId: current.id, permissionMode: subject.permissionMode, role: subject.role });
4600
4531
  const topic = await this.sessionManager.createForkedThreadSession(current, forkedAgentSessionId, targetThreadId, {
4601
4532
  name: name || undefined,
4602
- ...(hasLabel ? { label: label ?? null } : {}),
4603
4533
  creatorPeerId: userId,
4604
4534
  sourceAssistantMessageId: actualSourceMessageId,
4605
4535
  sourceTurn: forkTurn.index,
@@ -4721,7 +4651,7 @@ export async function execMenuAction(cmd, action, args, channel, channelId, user
4721
4651
  topicForkTargetsInFlight.delete(targetKey);
4722
4652
  }
4723
4653
  }
4724
- if (action !== 'delete' && action !== 'rename' && action !== 'label' && action !== 'status') {
4654
+ if (action !== 'delete' && action !== 'rename' && action !== 'status') {
4725
4655
  return { error: `不支持的 topic action: ${action}`, code: 'NOT_SUPPORTED' };
4726
4656
  }
4727
4657
  const target = (args?.target ?? '').toString().trim();
@@ -4730,8 +4660,6 @@ export async function execMenuAction(cmd, action, args, channel, channelId, user
4730
4660
  const renameName = action === 'rename' ? getRenameName(args) : '';
4731
4661
  if (action === 'rename' && !renameName)
4732
4662
  return { error: '缺少 args.name', code: 'MISSING_VALUE' };
4733
- if (action === 'label' && !hasLabel)
4734
- return { error: '缺少 args.label', code: 'MISSING_VALUE' };
4735
4663
  let topicStatus;
4736
4664
  if (action === 'status') {
4737
4665
  try {
@@ -4753,18 +4681,7 @@ export async function execMenuAction(cmd, action, args, channel, channelId, user
4753
4681
  ? 'private'
4754
4682
  : this.resolveMenuChatType(channel, channelId, explicitChatType);
4755
4683
  if (!this.canDeleteTopic(identity.role, chatType, topic, userId)) {
4756
- return { error: action === 'label' ? '无权限修改话题分类' : action === 'status' ? '无权限修改话题状态' : action === 'rename' ? '无权限重命名话题' : '无权限删除话题', code: 'FORBIDDEN' };
4757
- }
4758
- if (action === 'label') {
4759
- const success = await this.sessionManager.setTopicLabel(topic.id, label ?? null);
4760
- if (!success)
4761
- return { error: '话题不存在', code: 'NOT_FOUND' };
4762
- return {
4763
- data: {
4764
- action: 'label', success: true,
4765
- topic: { ...buildSessionPayload(topic, topic.name || ''), threadId: sessionLocalTopicId(topic) ?? '', label: label ?? null },
4766
- },
4767
- };
4684
+ return { error: action === 'status' ? '无权限修改话题状态' : action === 'rename' ? '无权限重命名话题' : '无权限删除话题', code: 'FORBIDDEN' };
4768
4685
  }
4769
4686
  if (action === 'status') {
4770
4687
  const success = await this.sessionManager.setTopicStatus(topic.id, topicStatus);
@@ -36,6 +36,13 @@ export async function deliverMenuResponse(send, options) {
36
36
  await send();
37
37
  }
38
38
  catch (error) {
39
+ // Directory synchronization has its own recovery lifecycle. Retrying the
40
+ // same response at 250/750/2000ms cannot supply a missing snapshot. Keep
41
+ // the error retryable for callers, but end this short transport retry loop.
42
+ if (error && typeof error === 'object'
43
+ && error.code === 'CONTACT_DIRECTORY_UNAVAILABLE') {
44
+ fail('dependency-unavailable', error);
45
+ }
39
46
  const delay = RETRY_DELAYS_MS[attempt];
40
47
  if (!isRetryableMenuTransportError(error))
41
48
  fail('transport-error', error);
@@ -211,7 +218,6 @@ export const MENU_NAME_COMMANDS = Object.freeze({
211
218
  config: '/config',
212
219
  capability: '/capability',
213
220
  role: '/role',
214
- connect: '/connect',
215
221
  events: '/events',
216
222
  });
217
223
  export function menuCommandForName(name) {
@@ -1034,6 +1040,30 @@ function writeMenuFlowRecord(record) {
1034
1040
  // Observability must never affect Menu execution.
1035
1041
  }
1036
1042
  }
1043
+ /** Paired records identify an unfinished await as well as completed slow work.
1044
+ * Only correlation metadata is logged, never request arguments or credentials. */
1045
+ export async function traceMenuStage(request, context, timing, stage, operation) {
1046
+ if (!request)
1047
+ return operation();
1048
+ const started = performance.now();
1049
+ const record = (phase) => writeMenuFlowRecord({
1050
+ ...menuFlowBaseRecord(request, context),
1051
+ event: 'menu.stage', stage, phase,
1052
+ receivedAt: timing.receivedAt,
1053
+ elapsedMs: menuElapsedMs(timing),
1054
+ ...(phase === 'started' ? {} : { durationMs: Math.max(0, Math.round(performance.now() - started)) }),
1055
+ });
1056
+ record('started');
1057
+ try {
1058
+ const result = await operation();
1059
+ record('completed');
1060
+ return result;
1061
+ }
1062
+ catch (error) {
1063
+ record('failed');
1064
+ throw error;
1065
+ }
1066
+ }
1037
1067
  export function logMenuRequestReceived(request, context) {
1038
1068
  writeMenuFlowRecord({
1039
1069
  ...menuFlowBaseRecord(request, context),
@@ -1,4 +1,5 @@
1
- import { createProvider, parseProviderImport, readProvidersSnapshot, updateProvider } from '../../config/providers-management.js';
1
+ import { applyProviderTemplate, createProvider, parseProviderImport, previewProviderTemplate, readProvidersSnapshot, updateProvider } from '../../config/providers-management.js';
2
+ import { providerTemplateDetail, readProviderTemplates } from '../../config/provider-templates.js';
2
3
  import { parseProviderObject, providerFailure } from '../../config/provider-ipc-service.js';
3
4
  import { resolveProviderId } from '../../config/providers-config.js';
4
5
  import { validateProviderMenuRequest } from '../../config/provider-menu-request.js';
@@ -14,8 +15,9 @@ export async function executeProviderMenu(request, subject, source) {
14
15
  return { error: 'Provider mutations require an encrypted Control Menu request', code: 'FORBIDDEN' };
15
16
  }
16
17
  const args = request.args;
17
- const operation = request.type === 'menu.query' ? args.view === 'detail' ? 'show' : 'list'
18
- : request.type === 'menu.update' ? 'update' : request.action;
18
+ const operation = request.action === 'preview-template' || args.view === 'templates' ? 'templates'
19
+ : request.type === 'menu.query' ? args.view === 'detail' ? 'show' : 'list'
20
+ : request.type === 'menu.update' ? 'update' : request.action;
19
21
  const decision = await authorizeFreshOperation({
20
22
  source, subject,
21
23
  intent: { operation: 'provider.' + operation, scope: 'process', source,
@@ -25,6 +27,14 @@ export async function executeProviderMenu(request, subject, source) {
25
27
  if (!decision.allow)
26
28
  return { error: 'Provider operation is not permitted', code: 'FORBIDDEN' };
27
29
  try {
30
+ if (operation === 'templates')
31
+ return { data: request.action === 'preview-template'
32
+ ? previewProviderTemplate(args.templateId, args.config)
33
+ : args.templateId ? providerTemplateDetail(args.templateId) : readProviderTemplates() };
34
+ if (args.templateId)
35
+ return { data: await applyProviderTemplate({ templateId: args.templateId,
36
+ config: request.type === 'menu.update' ? JSON.parse(String(request.value)) : args.config,
37
+ providerId: request.type === 'menu.update' ? args.providerId : undefined, revision: args.expectedRevision }) };
28
38
  if (operation === 'list' || operation === 'show') {
29
39
  const snapshot = readProvidersSnapshot();
30
40
  if (operation === 'list')