evolcore 0.0.46 → 0.0.48

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 (237) hide show
  1. package/CHANGELOG.md +93 -0
  2. package/bin/ec-build.mjs +86 -0
  3. package/dist/agent-template/jobs.js +12 -4
  4. package/dist/agent-template/runtime.js +139 -39
  5. package/dist/agent-template/service.js +66 -13
  6. package/dist/agents/baseagent.js +60 -20
  7. package/dist/agents/claude-runner.js +43 -18
  8. package/dist/agents/codex/app-server-client.js +32 -23
  9. package/dist/agents/codex-runner.js +31 -16
  10. package/dist/agents/ecagent-runner.js +7 -4
  11. package/dist/agents/gemini-runner.js +5 -2
  12. package/dist/agents/runner-types.js +5 -21
  13. package/dist/aun/aid/agentmd.js +5 -1
  14. package/dist/aun/group/fs-download.js +1 -1
  15. package/dist/aun/service-proxy.js +4 -2
  16. package/dist/build-identity.json +1 -0
  17. package/dist/channels/aun.js +100 -32
  18. package/dist/channels/daemon.js +10 -26
  19. package/dist/cli/aun-commands.js +86 -51
  20. package/dist/cli/code-stats.js +19 -8
  21. package/dist/cli/command-log.js +1 -1
  22. package/dist/cli/daemon-commands.js +65 -76
  23. package/dist/cli/daemon-lifecycle-client.js +17 -3
  24. package/dist/cli/directory.js +7 -1
  25. package/dist/cli/ecmsg-gateway.js +5 -2
  26. package/dist/cli/index.js +2 -8
  27. package/dist/cli/init-channel.js +6 -8
  28. package/dist/cli/init.js +74 -46
  29. package/dist/cli/invoke-command.js +1 -1
  30. package/dist/cli/provider-command.js +74 -13
  31. package/dist/cli/restart-monitor.js +104 -28
  32. package/dist/cli/role.js +61 -17
  33. package/dist/cli/stats.js +3 -3
  34. package/dist/cli/task-context.js +83 -15
  35. package/dist/cli/thread-command.js +16 -51
  36. package/dist/cli/upgrade-command.js +4 -2
  37. package/dist/config/boot-log.js +3 -9
  38. package/dist/config/builtin-roles.js +5 -7
  39. package/dist/config/config-manager.js +31 -23
  40. package/dist/config/daemon-services.js +30 -3
  41. package/dist/config/gateway-config.js +2 -2
  42. package/dist/config/invoke-ipc-service.js +6 -4
  43. package/dist/config/peer-bind-code.js +3 -4
  44. package/dist/config/peer-book-store.js +59 -218
  45. package/dist/config/peer-book.js +26 -27
  46. package/dist/config/peer-role-resolver.js +16 -1
  47. package/dist/config/provider-identity-migration.js +161 -6
  48. package/dist/config/provider-ipc-service.js +56 -11
  49. package/dist/config/provider-menu-request.js +24 -5
  50. package/dist/config/provider-templates.js +127 -0
  51. package/dist/config/providers-config.js +59 -8
  52. package/dist/config/providers-management.js +467 -49
  53. package/dist/config/role-command-service.js +248 -1
  54. package/dist/config/schema-migration.js +228 -20
  55. package/dist/config/schema-registry.js +6 -2
  56. package/dist/core/agent-application-service.js +6 -1
  57. package/dist/core/agent-runtime.js +10 -5
  58. package/dist/core/auth/agent-delegation.js +10 -4
  59. package/dist/core/auth/auth-gateway.js +2 -1
  60. package/dist/core/auth/delegation-authorization.js +3 -0
  61. package/dist/core/auth/delegation-diagnostics.js +56 -15
  62. package/dist/core/auth/operation-authorizer.js +26 -1
  63. package/dist/core/auth/operation-catalog.js +28 -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/command-handler.js +81 -85
  68. package/dist/core/command/menu-catalog.js +1 -0
  69. package/dist/core/command/menu-handler.js +65 -153
  70. package/dist/core/command/menu-protocol.js +7 -1
  71. package/dist/core/command/provider-menu.js +13 -3
  72. package/dist/core/command/role-menu.js +47 -23
  73. package/dist/core/command/slash-handler.js +30 -49
  74. package/dist/core/command/team-workspace-items.js +81 -12
  75. package/dist/core/command/team-workspace-team.js +9 -71
  76. package/dist/core/command/topic-slash.js +9 -30
  77. package/dist/core/daemon-bootstrap.js +19 -10
  78. package/dist/core/daemon-control.js +8 -10
  79. package/dist/core/daemon-lifecycle.js +50 -40
  80. package/dist/core/evolagent-registry.js +22 -3
  81. package/dist/core/file-integrity/store.js +2 -0
  82. package/dist/core/handoff/runtime.js +37 -1
  83. package/dist/core/host-snapshot.js +9 -4
  84. package/dist/core/inference/text-inference.js +3 -1
  85. package/dist/core/initialization/service.js +31 -8
  86. package/dist/core/interaction-router.js +3 -0
  87. package/dist/core/invoke/executors/text.js +72 -19
  88. package/dist/core/ipc-registration.js +6 -4
  89. package/dist/core/memory/consolidation.js +6 -6
  90. package/dist/core/message/aun-ipc-sender.js +165 -55
  91. package/dist/core/message/im-renderer.js +1 -1
  92. package/dist/core/message/message-bridge.js +51 -334
  93. package/dist/core/message/message-log.js +5 -0
  94. package/dist/core/message/message-queue.js +22 -0
  95. package/dist/core/message/message-utils.js +8 -0
  96. package/dist/core/message/response-engine.js +429 -116
  97. package/dist/core/message/send-routing.js +5 -1
  98. package/dist/core/model/catalog-service.js +31 -11
  99. package/dist/core/model/model-capabilities.js +22 -4
  100. package/dist/core/model/model-catalog.js +1 -0
  101. package/dist/core/ownership/owner-resolver.js +355 -60
  102. package/dist/core/permission/protected-paths.js +6 -6
  103. package/dist/core/relation/peer-identity.js +28 -2
  104. package/dist/core/relation/same-owner-proof.js +81 -111
  105. package/dist/core/session/adapters/claude-session-file-adapter.js +1 -1
  106. package/dist/core/session/adapters/codex-session-file-adapter.js +96 -15
  107. package/dist/core/session/session-file-health.js +49 -14
  108. package/dist/core/session/session-fs-store.js +91 -35
  109. package/dist/core/session/session-manager.js +68 -24
  110. package/dist/core/session/session-mapper.js +14 -34
  111. package/dist/core/session/session-transcript.js +5 -1
  112. package/dist/core/task/task-activity-store.js +84 -0
  113. package/dist/core/task/task-image-resources.js +1 -1
  114. package/dist/core/task/task-recovery-service.js +12 -0
  115. package/dist/core/thread/command-parser.js +7 -12
  116. package/dist/core/thread/thread-context-storage.js +3 -2
  117. package/dist/core/thread/thread-operation.js +2 -13
  118. package/dist/core/thread/thread-service.js +15 -46
  119. package/dist/directory/owner-directory-admission.js +1 -1
  120. package/dist/directory/owner-directory-cache.js +45 -28
  121. package/dist/directory/owner-directory-markdown.js +13 -1
  122. package/dist/directory/owner-directory-query-operation.js +29 -3
  123. package/dist/directory/owner-directory-remarks.js +11 -3
  124. package/dist/eck/message-renderer.js +84 -24
  125. package/dist/ecweb/basic-settings-service.js +3 -1
  126. package/dist/ecweb/message-context-service.js +1 -1
  127. package/dist/ecweb/pairing.js +4 -3
  128. package/dist/ecweb/providers-service.js +26 -1
  129. package/dist/ecweb/runtime/lifecycle.js +82 -23
  130. package/dist/ecweb/runtime/proxy-access.js +74 -0
  131. package/dist/ecweb/runtime/supervisor.js +6 -17
  132. package/dist/event-center/registry.js +13 -2
  133. package/dist/event-center/runtime.js +103 -11
  134. package/dist/event-center/script-runner.js +5 -5
  135. package/dist/index.js +129 -93
  136. package/dist/ipc.js +15 -3
  137. package/dist/outputs/events.js +62 -0
  138. package/dist/outputs/protocol.js +102 -0
  139. package/dist/outputs/service.js +279 -0
  140. package/dist/paths.js +3 -0
  141. package/dist/proxy/manager.js +43 -13
  142. package/dist/services/index.js +89 -4
  143. package/dist/services/ipc-operation.js +4 -15
  144. package/dist/services/pack-manager.js +12 -1
  145. package/dist/services/router.js +21 -6
  146. package/dist/services/script-runner.js +5 -4
  147. package/dist/services/validation.js +1 -1
  148. package/dist/stats/budget.js +1 -1
  149. package/dist/stats/db.js +19 -0
  150. package/dist/stats/index.js +1 -1
  151. package/dist/stats/{price-resolver.js → model-resolver.js} +305 -24
  152. package/dist/stats/normalizer.js +2 -0
  153. package/dist/stats/query.js +35 -27
  154. package/dist/stats/role-budget.js +5 -2
  155. package/dist/stats/writer.js +10 -6
  156. package/dist/trigger/audit.js +7 -0
  157. package/dist/trigger/authorization.js +105 -11
  158. package/dist/trigger/feedback.js +10 -0
  159. package/dist/trigger/history.js +37 -11
  160. package/dist/trigger/ipc-service.js +12 -1
  161. package/dist/trigger/manager.js +1 -0
  162. package/dist/trigger/scheduler.js +11 -5
  163. package/dist/trigger/script-executor.js +2 -1
  164. package/dist/trigger/script-sandbox.js +9 -3
  165. package/dist/trigger/state.js +7 -0
  166. package/dist/trigger/validation.js +22 -0
  167. package/dist/utils/aid-bind.js +155 -18
  168. package/dist/utils/atomic-write.js +3 -3
  169. package/dist/utils/cross-platform.js +97 -31
  170. package/dist/utils/error-dict.json +94 -4
  171. package/dist/utils/error-utils.js +40 -4
  172. package/dist/utils/evolcore-version.js +36 -65
  173. package/dist/utils/instance-registry.js +61 -0
  174. package/dist/utils/msg-diag.js +1 -0
  175. package/dist/utils/process-introspect.js +158 -8
  176. package/dist/utils/process-tree.js +50 -2
  177. package/dist/utils/upgrade-jobs.js +4 -4
  178. package/dist/utils/windows-shell-trust.js +2 -0
  179. package/dist/workbench/protocol.js +80 -0
  180. package/dist/workbench/service.js +359 -0
  181. package/ecagent/dist/types.d.ts +6 -2
  182. package/kits/docs/context-assembly.md +1 -1
  183. package/kits/docs/evolcore/INDEX.md +2 -2
  184. package/kits/docs/evolcore/aid.md +3 -1
  185. package/kits/docs/evolcore/config.md +12 -0
  186. package/kits/docs/evolcore/directory.md +22 -3
  187. package/kits/docs/evolcore/ecweb-lifecycle.md +15 -0
  188. package/kits/docs/evolcore/model.md +10 -0
  189. package/kits/docs/evolcore/peer.md +19 -65
  190. package/kits/docs/evolcore/provider.md +133 -5
  191. package/kits/docs/evolcore/role.md +80 -0
  192. package/kits/docs/evolcore/services.md +6 -6
  193. package/kits/docs/evolcore/team-workspace.md +1 -1
  194. package/kits/docs/evolcore/thread-chain.md +14 -15
  195. package/kits/docs/evolcore/tool-authorization.md +5 -0
  196. package/kits/docs/evolcore/trigger.md +10 -0
  197. package/kits/eck_message_manifest.json +12 -0
  198. package/kits/provider-templates.json +1213 -0
  199. package/kits/rules/04-relation.md +3 -3
  200. package/kits/schemas/_meta.json +14 -2
  201. package/kits/schemas/contact-book.schema.4.json +52 -0
  202. package/kits/schemas/providers.schema.3.json +200 -0
  203. package/kits/skills/.switches.json +4 -0
  204. package/kits/skills/ability/references/calling.md +1 -1
  205. package/kits/skills/ec-group/SKILL.md +2 -2
  206. package/kits/skills/ec-identity/SKILL.md +19 -72
  207. package/kits/skills/ec-provider/SKILL.md +221 -0
  208. package/kits/skills/ec-provider/scripts/check-model.mjs +80 -0
  209. package/kits/skills/ec-trigger/SKILL.md +1 -1
  210. package/kits/skills/thread-ops/SKILL.md +34 -21
  211. package/kits/templates/message-fragments/group-batch-item.md +1 -1
  212. package/kits/templates/message-fragments/group-batch.md +1 -1
  213. package/kits/templates/message-fragments/inject-default.md +1 -1
  214. package/kits/templates/message-fragments/interrupt-insert.md +1 -0
  215. package/kits/templates/message-fragments/item-group.md +1 -1
  216. package/kits/templates/message-fragments/item-private.md +1 -1
  217. package/kits/templates/message-fragments/thread-context.md +1 -1
  218. package/kits/templates/message-fragments/trigger-session.md +1 -1
  219. package/kits/templates/message-fragments/trigger-thread-check.md +1 -1
  220. package/kits/templates/roles/admin.json +2 -19
  221. package/kits/templates/roles/member.json +0 -3
  222. package/kits/templates/system-fragments/baseagent.md +6 -0
  223. package/kits/templates/system-fragments/commands.md +3 -3
  224. package/kits/templates/system-fragments/managed-runtime.md +1 -1
  225. package/kits/templates/system-fragments/relation.md +1 -1
  226. package/kits/templates/system-fragments/thread.md +6 -5
  227. package/package.json +6 -4
  228. package/scripts/agent-template/inspect.mjs +4 -1
  229. package/scripts/agent-template/shared/common.mjs +2 -3
  230. package/scripts/agent-template/shared/template-contract.mjs +2 -1
  231. package/scripts/agent-template/shared/template-package.mjs +9 -2
  232. package/scripts/agent-template/shared/template-runtime.mjs +20 -5
  233. package/scripts/agent-template/team-pack.mjs +6 -3
  234. package/dist/cli/peer.js +0 -127
  235. package/dist/config/peer-operation-service.js +0 -132
  236. package/dist/config/peer-request-service.js +0 -532
  237. package/dist/core/command/connect-menu.js +0 -624
@@ -3,7 +3,7 @@ import { loadedBaseagentIds } from '../../agents/baseagent-availability.js';
3
3
  import { grantSessionPath, listRuntimePathGrants, revokeSessionPath } from '../permission/session-path-grants.js';
4
4
  import { closeDiagnosticSession, diagnosticTokenHash, isDiagnosticSessionActive } from './diag-service.js';
5
5
  import { parseMenuClientArgs } from '../../cli/menu-client.js';
6
- import { ensureSessionRuntimeDir } from '../../cli/task-context.js';
6
+ import { ensureSessionRuntimeDirAsync } from '../../cli/task-context.js';
7
7
  import { renderCommandCardAsText } from '../interaction-router.js';
8
8
  import { buildEnvelope, deliveryTargetFromSession, isInteractionSendAccepted, replyContextFromSession, sendInteractionPayload } from '../message/message-utils.js';
9
9
  import { sessionTopicThreadId } from '../thread/topic-id.js';
@@ -12,7 +12,7 @@ import { loadAgent, loadDaemonConfig } from '../../config-store.js';
12
12
  import { parseOwnershipCommand, executeOwnershipCommand, ownershipFailure } from '../../aun/aid/ownership-operation.js';
13
13
  import { ownerResolver, refreshOwnershipForAuthorization } from '../ownership/owner-resolver.js';
14
14
  import { logger } from '../../utils/logger.js';
15
- import { resolvePeerRoleDetail, roleToSessionIdentity } from '../../config/peer-role-resolver.js';
15
+ import { resolveFreshPeerRoleDetail, resolvePeerRoleDetail, roleToSessionIdentity } from '../../config/peer-role-resolver.js';
16
16
  import { ThreadService } from '../thread/thread-service.js';
17
17
  import { isManagementRole } from '../../config/builtin-roles.js';
18
18
  import { formatPeerKey } from '../relation/peer-identity.js';
@@ -41,7 +41,6 @@ import { DirectoryQueryError, executeDirectoryQueryCommand, resolveDirectoryQuer
41
41
  import { executeDirectoryRequestCommand, resolveDirectoryRequestCommand, } from '../../directory/owner-directory-request-operation.js';
42
42
  import { executeResolvedRoleCommand, resolveRoleCommand } from '../../config/role-command-service.js';
43
43
  import { applyApprovedRoleAssignment } from './role-menu.js';
44
- import { executeResolvedPeerCommand, resolvePeerCommand } from '../../config/peer-operation-service.js';
45
44
  import { hasTrustedFullAccessDelegation, trustedExecutionIdentityInput } from '../auth/agent-delegation.js';
46
45
  import { executeManagedAidOperation, ManagedAidOperationError, managedAidShowViewForRole, resolveManagedAidOperation, } from '../../aun/aid/managed-operation.js';
47
46
  import { MAX_AVATAR_SOURCE_BYTES } from '../../utils/avatar-upload.js';
@@ -137,6 +136,7 @@ export class CommandHandler {
137
136
  return { ok: false, code: 'SCOPE_MISMATCH', error: 'Menu requests must use the current Agent identity and session' };
138
137
  try {
139
138
  const channelId = parsePeerKey(grant.peerKey).channelId;
139
+ const managedTempPath = argv.includes('--request-file') ? await this.getManagedSessionTempDir(session) : undefined;
140
140
  const subject = buildAuthSubject({ selfAid: grant.selfAid, actorId: grant.actorId, channel: grant.channel,
141
141
  channelType: grant.channelType, channelId, chatType: grant.chatType, conversationId: channelId,
142
142
  processOwners: [], ...trustedExecutionIdentityInput(grant) });
@@ -147,7 +147,7 @@ export class CommandHandler {
147
147
  return { ok: false, code: decision.code, error: decision.reason };
148
148
  const options = parseMenuClientArgs(argv, file => {
149
149
  const target = fs.realpathSync(path.resolve(session.projectPath, file));
150
- const roots = [session.projectPath, this.getManagedSessionTempDir(session)].filter((v) => !!v)
150
+ const roots = [session.projectPath, managedTempPath].filter((v) => !!v)
151
151
  .map(root => fs.realpathSync(root));
152
152
  if (!roots.some(root => isSameOrDescendant(target, root))
153
153
  || (!hasTrustedFullAccessDelegation(grant) && (isHClassPath(target) || isLClassPath(target))))
@@ -270,7 +270,7 @@ export class CommandHandler {
270
270
  }
271
271
  /** Return the stable temporary root for a managed session, if available. */
272
272
  getManagedSessionTempDir(session) {
273
- return ensureSessionRuntimeDir(session.id);
273
+ return ensureSessionRuntimeDirAsync(session.id);
274
274
  }
275
275
  formatBaseagentUnavailable(error) {
276
276
  const available = error.availableBaseagents.length ? error.availableBaseagents.join(', ') : '(none)';
@@ -790,6 +790,12 @@ export class CommandHandler {
790
790
  updatedAt: now,
791
791
  ...(authorizedBy ? { authorizedBy } : {}),
792
792
  origin,
793
+ ...(channel !== 'daemon' ? { creator: {
794
+ actor: (await resolveFreshPeerRoleDetail({ selfAid: schedulerAid, channelKey: channel,
795
+ channelType: origin.channelType, chatType: originChatType, actorId: peerId,
796
+ conversationId: originConversationId })).actor,
797
+ chatType: originChatType, conversationId: originConversationId,
798
+ } } : {}),
793
799
  source,
794
800
  execution: {
795
801
  type: parsed.executionType,
@@ -1084,8 +1090,7 @@ export class CommandHandler {
1084
1090
  const item = {
1085
1091
  value: sessionTopicThreadId(s) ?? '',
1086
1092
  label: displayName,
1087
- topicLabel: s.label || null,
1088
- topicStatus: s.topicStatus ?? 'pending',
1093
+ topicStatus: s.topicStatus ?? 'active',
1089
1094
  };
1090
1095
  const forkSource = buildTopicForkSourcePayload(s);
1091
1096
  if (forkSource)
@@ -2027,69 +2032,8 @@ export class CommandHandler {
2027
2032
  ? { ok: true, result }
2028
2033
  : { ok: false, code: result.code, error: result.error, ...(result.data !== undefined ? { data: result.data } : {}) };
2029
2034
  }
2030
- /** Agent-managed contact CLI entrypoint. The daemon owns actor resolution and authorization. */
2031
- async handleContactOperation(argv, sessionId, delegationToken, delegationCommandHash) {
2032
- if (!this.agentDelegationRegistry) {
2033
- return { ok: false, code: 'DELEGATION_REQUIRED', error: 'Task delegation is not configured' };
2034
- }
2035
- const delegation = this.agentDelegationRegistry.validate(delegationToken, sessionId, delegationCommandHash);
2036
- if (!delegation.ok)
2037
- return { ok: false, code: delegation.code, error: delegation.reason };
2038
- const session = await this.sessionManager.getSessionById(sessionId);
2039
- if (!session)
2040
- return { ok: false, code: 'INVALID_SESSION', error: 'Invalid session' };
2041
- const grant = delegation.grant;
2042
- let conversationId;
2043
- try {
2044
- conversationId = parsePeerKey(grant.peerKey).channelId;
2045
- }
2046
- catch {
2047
- return { ok: false, code: 'INVALID_DELEGATION', error: 'Delegation contains an invalid relation key' };
2048
- }
2049
- const resolvedArgv = argv.includes('--self') ? argv : [...argv, '--self', grant.selfAid];
2050
- const resolved = resolvePeerCommand(resolvedArgv);
2051
- if (!resolved.ok)
2052
- return { ok: false, code: resolved.code, error: resolved.reason };
2053
- if (resolved.command.selfAid !== grant.selfAid && !hasTrustedFullAccessDelegation(grant)) {
2054
- return { ok: false, code: 'SCOPE_MISMATCH', error: 'Only the current Agent contact book can be targeted' };
2055
- }
2056
- const primaryId = 'primaryId' in resolved.command ? resolved.command.primaryId : undefined;
2057
- const subject = buildAuthSubject({
2058
- selfAid: grant.selfAid,
2059
- actorId: grant.actorId,
2060
- channel: grant.channel,
2061
- channelType: grant.channelType,
2062
- channelId: conversationId,
2063
- chatType: grant.chatType,
2064
- conversationId,
2065
- processOwners: ownerResolver.daemonOwners(),
2066
- ...trustedExecutionIdentityInput(grant),
2067
- });
2068
- const decision = await authorizeFreshOperation({
2069
- source: 'agent-tool',
2070
- subject,
2071
- intent: {
2072
- operation: resolved.command.operationId,
2073
- scope: 'agent',
2074
- source: 'agent-tool',
2075
- args: {
2076
- self: resolved.command.selfAid,
2077
- targetAgentAid: resolved.command.selfAid,
2078
- ...(primaryId ? { primaryId } : {}),
2079
- },
2080
- },
2081
- auditMetadata: {
2082
- argvHash: hashArgv(resolved.command.canonicalArgv),
2083
- taskId: grant.taskId,
2084
- messageId: grant.messageId,
2085
- },
2086
- });
2087
- if (!decision.allow)
2088
- return { ok: false, code: decision.code, error: decision.reason };
2089
- const result = await executeResolvedPeerCommand(resolved.command, grant.actorId);
2090
- return result.ok
2091
- ? { ok: true, result }
2092
- : { ok: false, code: result.code, error: result.error, ...(result.data ? { data: result.data } : {}) };
2035
+ async handleContactOperation(_argv, _sessionId, _delegationToken, _delegationCommandHash) {
2036
+ return { ok: false, code: 'NOT_SUPPORTED', error: 'peer has been retired; use directory' };
2093
2037
  }
2094
2038
  /** Agent-managed AID CLI entrypoint. Private key and CA access stay inside the daemon. */
2095
2039
  async handleOwnershipOperation(argv, sessionId, delegationToken, delegationCommandHash) {
@@ -2160,11 +2104,28 @@ export class CommandHandler {
2160
2104
  }
2161
2105
  }
2162
2106
  /**
2163
- * Agent-managed role-request CLI entrypoint. Submitting a request never
2164
- * changes permissions; only the Agent owner can approve it, and approval is
2165
- * what actually applies the relation role.
2107
+ * Agent-managed role CLI. Quota policy uses the common authorization path;
2108
+ * the existing request workflow retains its Owner approval checks.
2166
2109
  */
2167
- async handleRoleOperation(argv, sessionId, delegationToken, delegationCommandHash) {
2110
+ async handleRoleOperation(argv, sessionId, delegationToken, delegationCommandHash, localControl = false) {
2111
+ if (localControl) {
2112
+ const resolved = resolveRoleCommand(argv);
2113
+ if (!resolved.ok)
2114
+ return { ok: false, code: resolved.code, error: resolved.reason };
2115
+ if (resolved.command.kind !== 'quota') {
2116
+ return { ok: false, code: 'NOT_ALLOWED', error: 'Host control role operations support quota commands only' };
2117
+ }
2118
+ try {
2119
+ const result = await executeResolvedRoleCommand(resolved.command, 'local-cli', applyApprovedRoleAssignment, {
2120
+ self: resolved.command.selfAid, actorRole: 'none', actorAid: 'local-cli',
2121
+ isDaemonOwner: true, fromControlChannel: true, chatType: 'private',
2122
+ });
2123
+ return result.ok ? { ok: true, result } : result;
2124
+ }
2125
+ catch (error) {
2126
+ return { ok: false, code: error?.code ?? 'ROLE_OPERATION_FAILED', error: error?.message ?? String(error), data: error?.data };
2127
+ }
2128
+ }
2168
2129
  if (!this.agentDelegationRegistry) {
2169
2130
  return { ok: false, code: 'DELEGATION_REQUIRED', error: 'Task delegation is not configured' };
2170
2131
  }
@@ -2175,21 +2136,55 @@ export class CommandHandler {
2175
2136
  if (!session)
2176
2137
  return { ok: false, code: 'INVALID_SESSION', error: 'Invalid session' };
2177
2138
  const grant = delegation.grant;
2139
+ if (session.selfAID !== grant.selfAid || grant.sessionId !== sessionId) {
2140
+ return { ok: false, code: 'INVALID_DELEGATION', error: 'Delegation does not match the current session' };
2141
+ }
2178
2142
  const resolvedArgv = argv.includes('--self') ? argv : [...argv, '--self', grant.selfAid];
2179
2143
  const resolved = resolveRoleCommand(resolvedArgv);
2180
2144
  if (!resolved.ok)
2181
2145
  return { ok: false, code: resolved.code, error: resolved.reason };
2182
- if (resolved.command.selfAid !== grant.selfAid) {
2146
+ const command = resolved.command;
2147
+ if (command.selfAid !== grant.selfAid && command.kind !== 'quota') {
2183
2148
  return { ok: false, code: 'SCOPE_MISMATCH', error: 'Only the current Agent role requests can be targeted' };
2184
2149
  }
2185
2150
  try {
2186
- const result = await executeResolvedRoleCommand(resolved.command, grant.actorId, applyApprovedRoleAssignment);
2151
+ if (command.kind === 'quota') {
2152
+ const conversationId = parsePeerKey(grant.peerKey).channelId;
2153
+ const subject = buildAuthSubject({
2154
+ selfAid: grant.selfAid, sessionId, actorId: grant.actorId,
2155
+ channel: grant.channel, channelType: grant.channelType, channelId: conversationId,
2156
+ chatType: grant.chatType, conversationId, processOwners: ownerResolver.daemonOwners(),
2157
+ ...trustedExecutionIdentityInput(grant),
2158
+ });
2159
+ if (command.selfAid !== grant.selfAid && !subject.isDaemonOwner && !hasTrustedFullAccessDelegation(grant)) {
2160
+ return { ok: false, code: 'SCOPE_MISMATCH', error: 'A different Agent requires DaemonOwner authorization or trusted fullaccess' };
2161
+ }
2162
+ return await executeAuditedOperation({
2163
+ source: 'agent-tool', subject,
2164
+ intent: {
2165
+ operation: command.action === 'show' ? 'role.policy.read' : 'role.policy.write',
2166
+ scope: 'agent', source: 'agent-tool',
2167
+ args: { self: command.selfAid, targetAgentAid: command.selfAid, roleId: command.roleId },
2168
+ },
2169
+ auditMetadata: { argvHash: hashArgv(command.canonicalArgv), taskId: grant.taskId, messageId: grant.messageId },
2170
+ }, async (onExecutionStarted) => {
2171
+ onExecutionStarted();
2172
+ const result = await executeResolvedRoleCommand(command, grant.actorId, applyApprovedRoleAssignment, {
2173
+ self: command.selfAid, actorRole: subject.role, actorAid: subject.principalId ?? subject.actorId,
2174
+ chatType: grant.chatType,
2175
+ isDaemonOwner: subject.isDaemonOwner, fromControlChannel: subject.fromControlChannel,
2176
+ trustedFullAccess: subject.processRole === 'fullaccess-run' && subject.dataScope === 'daemon',
2177
+ });
2178
+ return result.ok ? { ok: true, result } : result;
2179
+ });
2180
+ }
2181
+ const result = await executeResolvedRoleCommand(command, grant.actorId, applyApprovedRoleAssignment);
2187
2182
  if (!result.ok)
2188
2183
  return { ok: false, code: result.code, error: result.error, data: result.data };
2189
2184
  return { ok: true, result };
2190
2185
  }
2191
2186
  catch (error) {
2192
- return { ok: false, code: 'ROLE_OPERATION_FAILED', error: error?.message ?? String(error) };
2187
+ return { ok: false, code: error?.code ?? 'ROLE_OPERATION_FAILED', error: error?.message ?? String(error), data: error?.data };
2193
2188
  }
2194
2189
  }
2195
2190
  /**
@@ -2239,7 +2234,8 @@ export class CommandHandler {
2239
2234
  if (isRequest && targetAid !== grantSelfAid) {
2240
2235
  return { ok: false, code: 'SCOPE_MISMATCH', error: '加好友申请只能由当前任务所属 Agent 发起' };
2241
2236
  }
2242
- const operation = isRequest ? 'ec.directory.request' : 'ec.directory.query';
2237
+ const operation = isRequest ? 'ec.directory.request'
2238
+ : ['block', 'unblock'].includes(subArgv[0]) ? 'ec.directory.block' : 'ec.directory.query';
2243
2239
  const subject = buildAuthSubject({
2244
2240
  selfAid: grantSelfAid,
2245
2241
  sessionId,
@@ -2309,7 +2305,7 @@ export class CommandHandler {
2309
2305
  return { ok: false, code: 'SCOPE_MISMATCH', error: 'Resolved Agent target does not match the authorized target' };
2310
2306
  }
2311
2307
  onExecutionStarted();
2312
- const result = await executeDirectoryQueryCommand(command);
2308
+ const result = await executeDirectoryQueryCommand(command, subject.principalId ?? subject.actorId);
2313
2309
  return result.ok
2314
2310
  ? { ok: true, result }
2315
2311
  : { ok: false, code: result.code, error: result.error };
@@ -2340,6 +2336,8 @@ export class CommandHandler {
2340
2336
  catch {
2341
2337
  return { ok: false, code: 'INVALID_DELEGATION', error: 'Delegation contains an invalid relation key' };
2342
2338
  }
2339
+ const managedTempPath = parsed.command.kind === 'avatar' && parsed.command.filePath
2340
+ ? await this.getManagedSessionTempDir(session) : undefined;
2343
2341
  const subject = buildAuthSubject({
2344
2342
  selfAid: delegation.grant.selfAid,
2345
2343
  sessionId,
@@ -2376,9 +2374,9 @@ export class CommandHandler {
2376
2374
  taskId: delegation.grant.taskId,
2377
2375
  messageId: delegation.grant.messageId,
2378
2376
  },
2379
- }, onExecutionStarted => this.executeAuthorizedAidOperation(parsed.command, session, subject, delegation.grant, onExecutionStarted));
2377
+ }, onExecutionStarted => this.executeAuthorizedAidOperation(parsed.command, session, subject, delegation.grant, onExecutionStarted, managedTempPath));
2380
2378
  }
2381
- async executeAuthorizedAidOperation(command, session, subject, grant, onExecutionStarted) {
2379
+ async executeAuthorizedAidOperation(command, session, subject, grant, onExecutionStarted, managedTempPath) {
2382
2380
  const grantSelfAid = grant.selfAid.replace(/^@/, '');
2383
2381
  let avatarBuffer;
2384
2382
  if (command.kind === 'avatar' && command.filePath) {
@@ -2387,7 +2385,6 @@ export class CommandHandler {
2387
2385
  return { ok: false, code: 'INVALID_AVATAR_PATH', error: 'Avatar file requires a current session project path' };
2388
2386
  }
2389
2387
  const projectPath = path.resolve(session.projectPath);
2390
- const managedTempPath = this.getManagedSessionTempDir(session);
2391
2388
  const resolvedPath = path.isAbsolute(filePath) ? path.resolve(filePath) : path.resolve(projectPath, filePath);
2392
2389
  // 对端发来的图片按原有机制落在本 Agent 的关系附件目录;直接引用原文件,
2393
2390
  // 不要求先复制到项目里。只放开本 Agent 自己的目录,其它 Agent 的不在其中。
@@ -2514,6 +2511,7 @@ export class CommandHandler {
2514
2511
  catch {
2515
2512
  return { ok: false, code: 'INVALID_DELEGATION', error: 'Delegation contains an invalid relation key' };
2516
2513
  }
2514
+ const managedTempPath = parsed.command.kind === 'rules.set' ? await this.getManagedSessionTempDir(session) : undefined;
2517
2515
  const subject = buildAuthSubject({
2518
2516
  selfAid: grant.selfAid,
2519
2517
  actorId: grant.actorId,
@@ -2572,7 +2570,6 @@ export class CommandHandler {
2572
2570
  const filePath = String(parsed.command.filePath || '');
2573
2571
  const projectPath = path.resolve(session.projectPath);
2574
2572
  const resolvedPath = path.resolve(projectPath, filePath);
2575
- const managedTempPath = this.getManagedSessionTempDir(session);
2576
2573
  const allowedPaths = [projectPath, managedTempPath].filter((value) => !!value);
2577
2574
  if (!filePath || !allowedPaths.some(root => isSameOrDescendant(resolvedPath, root))) {
2578
2575
  return { ok: false, code: 'INVALID_RULES_PATH', error: 'Rules file must be inside the current session project or managed TMPDIR' };
@@ -2897,6 +2894,7 @@ export class CommandHandler {
2897
2894
  : actorAid;
2898
2895
  const relationTarget = currentGroup
2899
2896
  ?? (grant.channelType === 'aun' && grant.chatType === 'private' ? relationId : undefined);
2897
+ const managedTempPath = parsed.command.kind === 'upload' ? await this.getManagedSessionTempDir(session) : undefined;
2900
2898
  const subject = buildAuthSubject({
2901
2899
  selfAid: grant.selfAid,
2902
2900
  actorId: grant.actorId,
@@ -2948,7 +2946,6 @@ export class CommandHandler {
2948
2946
  if (!localPath)
2949
2947
  return { ok: false, code: 'INVALID_ARGUMENT', error: 'Managed upload source is required' };
2950
2948
  const resolvedPath = path.resolve(projectPath, localPath);
2951
- const managedTempPath = this.getManagedSessionTempDir(session);
2952
2949
  const allowedRoots = [projectPath, managedTempPath].filter((value) => !!value);
2953
2950
  if (!allowedRoots.some(root => isSameOrDescendant(resolvedPath, root))) {
2954
2951
  return { ok: false, code: 'INVALID_LOCAL_PATH', error: 'Upload source must be inside the current session project or managed TMPDIR' };
@@ -3036,7 +3033,6 @@ export class CommandHandler {
3036
3033
  threadId: topic.threadId,
3037
3034
  name: topic.name,
3038
3035
  topicStatus: topic.topicStatus,
3039
- label: topic.label ?? null,
3040
3036
  },
3041
3037
  currentSummary: service.showSummary(input.selfAid, topic.sessionId) ?? null,
3042
3038
  summaries,
@@ -70,6 +70,7 @@ const ENTRIES = [
70
70
  { id: 'event.register', type: 'setting', contexts: ['agent'], name: 'events', label: '事件注册', section: 'agent', order: 82.5, query: { cmd: '/events', args: { view: 'register' }, operation: 'event.register.list', scope: 'agent' }, update: { cmd: '/events', args: { resource: 'register' }, operation: 'event.register.update', scope: 'agent' }, valueSchema: { type: 'object' }, control: 'json' },
71
71
  { id: 'event.subscribers', type: 'list', contexts: ['agent'], name: 'events', label: '事件订阅者', section: 'agent', order: 82.6, query: { cmd: '/events', args: { view: 'subscribers' }, operation: 'event.subscribers.list', scope: 'agent' }, control: 'list' },
72
72
  { id: 'provider.list', type: 'list', contexts: ['process'], name: 'provider', label: 'Provider 注册表', section: 'process', order: 80, query: { cmd: '/provider', args: { scope: 'process', view: 'list' }, operation: 'provider.list', scope: 'process' }, control: 'list' },
73
+ { id: 'provider.templates', type: 'list', contexts: ['process'], name: 'provider', label: '内置服务商模板', section: 'process', order: 80.5, query: { cmd: '/provider', args: { scope: 'process', view: 'templates' }, operation: 'provider.templates', scope: 'process' }, control: 'list' },
73
74
  { id: 'provider.create', type: 'action', contexts: ['process'], name: 'provider', label: '创建 Provider', section: 'process', order: 81, action: { cmd: '/provider', action: 'create', args: { scope: 'process' }, operation: 'provider.create', scope: 'process' } },
74
75
  { id: 'provider.import', type: 'action', contexts: ['process'], name: 'provider', label: '导入 Provider JSON', section: 'process', order: 82, action: { cmd: '/provider', action: 'import', args: { scope: 'process' }, operation: 'provider.import', scope: 'process' } },
75
76
  { id: 'provider.update', type: 'setting', contexts: ['process'], name: 'provider', label: '更新 Provider', section: 'process', order: 83, update: { cmd: '/provider', args: { scope: 'process', resource: 'provider' }, operation: 'provider.update', scope: 'process' }, valueSchema: { type: 'string' }, control: 'json' },