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
@@ -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';
@@ -37,16 +37,17 @@ import { parseTimeArg, TIME_ARG_FORMATS, splitConfigBatchGetArgv } from '../../c
37
37
  import { auditCommandAuthorization, auditFullAccessEvent, hashArgv } from '../auth/authorization-audit.js';
38
38
  import { ResponseModeRegistry } from '../../response-system/registry.js';
39
39
  import { registerBuiltinModes } from '../../response-system/modes/index.js';
40
+ import { parseQuotaCommand, queryQuota } from '../../stats/quota-query.js';
40
41
  import { DirectoryQueryError, executeDirectoryQueryCommand, resolveDirectoryQueryCommand, } from '../../directory/owner-directory-query-operation.js';
41
42
  import { executeDirectoryRequestCommand, resolveDirectoryRequestCommand, } from '../../directory/owner-directory-request-operation.js';
42
43
  import { executeResolvedRoleCommand, resolveRoleCommand } from '../../config/role-command-service.js';
43
44
  import { applyApprovedRoleAssignment } from './role-menu.js';
44
- import { executeResolvedPeerCommand, resolvePeerCommand } from '../../config/peer-operation-service.js';
45
45
  import { hasTrustedFullAccessDelegation, trustedExecutionIdentityInput } from '../auth/agent-delegation.js';
46
46
  import { executeManagedAidOperation, ManagedAidOperationError, managedAidShowViewForRole, resolveManagedAidOperation, } from '../../aun/aid/managed-operation.js';
47
47
  import { MAX_AVATAR_SOURCE_BYTES } from '../../utils/avatar-upload.js';
48
48
  import { executeManagedGroupOperation, ManagedGroupOperationError, resolveManagedGroupOperation, executeManagedMsgOperation, ManagedMsgOperationError, resolveManagedMsgOperation, executeManagedFsOperation, ManagedFsOperationError, resolveManagedFsOperation, } from '../../aun/msg/managed-operation.js';
49
49
  import { authorizeFreshOperation, buildAuthSubject, executeAuditedOperation } from '../auth/auth-gateway.js';
50
+ import { resolveDelegatedIdentity } from '../auth/delegation-authorization.js';
50
51
  import { getExistingRelationAttachmentDirs, isHClassPath, isLClassPath, isSameOrDescendant } from '../permission/protected-paths.js';
51
52
  import { validateModelSelectionForRole } from '../model/model-permission.js';
52
53
  import { getModelInfo } from '../model/model-catalog.js';
@@ -137,6 +138,7 @@ export class CommandHandler {
137
138
  return { ok: false, code: 'SCOPE_MISMATCH', error: 'Menu requests must use the current Agent identity and session' };
138
139
  try {
139
140
  const channelId = parsePeerKey(grant.peerKey).channelId;
141
+ const managedTempPath = argv.includes('--request-file') ? await this.getManagedSessionTempDir(session) : undefined;
140
142
  const subject = buildAuthSubject({ selfAid: grant.selfAid, actorId: grant.actorId, channel: grant.channel,
141
143
  channelType: grant.channelType, channelId, chatType: grant.chatType, conversationId: channelId,
142
144
  processOwners: [], ...trustedExecutionIdentityInput(grant) });
@@ -147,7 +149,7 @@ export class CommandHandler {
147
149
  return { ok: false, code: decision.code, error: decision.reason };
148
150
  const options = parseMenuClientArgs(argv, file => {
149
151
  const target = fs.realpathSync(path.resolve(session.projectPath, file));
150
- const roots = [session.projectPath, this.getManagedSessionTempDir(session)].filter((v) => !!v)
152
+ const roots = [session.projectPath, managedTempPath].filter((v) => !!v)
151
153
  .map(root => fs.realpathSync(root));
152
154
  if (!roots.some(root => isSameOrDescendant(target, root))
153
155
  || (!hasTrustedFullAccessDelegation(grant) && (isHClassPath(target) || isLClassPath(target))))
@@ -270,7 +272,7 @@ export class CommandHandler {
270
272
  }
271
273
  /** Return the stable temporary root for a managed session, if available. */
272
274
  getManagedSessionTempDir(session) {
273
- return ensureSessionRuntimeDir(session.id);
275
+ return ensureSessionRuntimeDirAsync(session.id);
274
276
  }
275
277
  formatBaseagentUnavailable(error) {
276
278
  const available = error.availableBaseagents.length ? error.availableBaseagents.join(', ') : '(none)';
@@ -790,6 +792,12 @@ export class CommandHandler {
790
792
  updatedAt: now,
791
793
  ...(authorizedBy ? { authorizedBy } : {}),
792
794
  origin,
795
+ ...(channel !== 'daemon' ? { creator: {
796
+ actor: (await resolveFreshPeerRoleDetail({ selfAid: schedulerAid, channelKey: channel,
797
+ channelType: origin.channelType, chatType: originChatType, actorId: peerId,
798
+ conversationId: originConversationId })).actor,
799
+ chatType: originChatType, conversationId: originConversationId,
800
+ } } : {}),
793
801
  source,
794
802
  execution: {
795
803
  type: parsed.executionType,
@@ -1084,8 +1092,7 @@ export class CommandHandler {
1084
1092
  const item = {
1085
1093
  value: sessionTopicThreadId(s) ?? '',
1086
1094
  label: displayName,
1087
- topicLabel: s.label || null,
1088
- topicStatus: s.topicStatus ?? 'pending',
1095
+ topicStatus: s.topicStatus ?? 'active',
1089
1096
  };
1090
1097
  const forkSource = buildTopicForkSourcePayload(s);
1091
1098
  if (forkSource)
@@ -2027,69 +2034,8 @@ export class CommandHandler {
2027
2034
  ? { ok: true, result }
2028
2035
  : { ok: false, code: result.code, error: result.error, ...(result.data !== undefined ? { data: result.data } : {}) };
2029
2036
  }
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 } : {}) };
2037
+ async handleContactOperation(_argv, _sessionId, _delegationToken, _delegationCommandHash) {
2038
+ return { ok: false, code: 'NOT_SUPPORTED', error: 'peer has been retired; use directory' };
2093
2039
  }
2094
2040
  /** Agent-managed AID CLI entrypoint. Private key and CA access stay inside the daemon. */
2095
2041
  async handleOwnershipOperation(argv, sessionId, delegationToken, delegationCommandHash) {
@@ -2159,12 +2105,67 @@ export class CommandHandler {
2159
2105
  return ownershipFailure(error);
2160
2106
  }
2161
2107
  }
2108
+ /** Read quota status using daemon-owned identity, role resolution and statistics. */
2109
+ async handleQuotaOperation(argv, sessionId, delegationToken, delegationCommandHash, localControl = false) {
2110
+ try {
2111
+ const command = parseQuotaCommand(argv);
2112
+ if (localControl) {
2113
+ return { ok: true, result: await queryQuota(command, { canReadAgent: true, allowOtherAgent: true }) };
2114
+ }
2115
+ const delegation = await resolveDelegatedIdentity({ sessionId, delegationToken, delegationCommandHash }, {
2116
+ agentDelegationRegistry: this.agentDelegationRegistry,
2117
+ sessionManager: this.sessionManager,
2118
+ getProcessOwners: () => ownerResolver.daemonOwners(),
2119
+ }, 'INVALID_SESSION');
2120
+ if (!delegation.ok)
2121
+ return delegation;
2122
+ const { grant, subject } = delegation;
2123
+ const decision = await authorizeFreshOperation({
2124
+ source: 'agent-tool', subject,
2125
+ intent: {
2126
+ operation: 'quota.read', scope: 'relation', source: 'agent-tool',
2127
+ args: { self: command.selfAid ?? grant.selfAid, targetAgentAid: command.selfAid ?? grant.selfAid,
2128
+ peerKey: command.peerKey ?? grant.peerKey },
2129
+ },
2130
+ auditMetadata: { argvHash: hashArgv(argv), taskId: grant.taskId, messageId: grant.messageId },
2131
+ });
2132
+ if (!decision.allow)
2133
+ return { ok: false, code: decision.code, error: decision.reason };
2134
+ const fullAccess = hasTrustedFullAccessDelegation(grant);
2135
+ return { ok: true, result: await queryQuota(command, {
2136
+ selfAid: grant.selfAid, peerKey: grant.peerKey, actorId: grant.actorId,
2137
+ chatType: grant.chatType, channelKey: grant.channel,
2138
+ canReadAgent: isManagementRole(decision.subject?.role) || fullAccess,
2139
+ allowOtherAgent: fullAccess,
2140
+ }) };
2141
+ }
2142
+ catch (error) {
2143
+ return { ok: false, code: error?.code ?? 'QUOTA_QUERY_FAILED', error: error?.message ?? String(error) };
2144
+ }
2145
+ }
2162
2146
  /**
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.
2147
+ * Agent-managed role CLI. Quota policy uses the common authorization path;
2148
+ * the existing request workflow retains its Owner approval checks.
2166
2149
  */
2167
- async handleRoleOperation(argv, sessionId, delegationToken, delegationCommandHash) {
2150
+ async handleRoleOperation(argv, sessionId, delegationToken, delegationCommandHash, localControl = false) {
2151
+ if (localControl) {
2152
+ const resolved = resolveRoleCommand(argv);
2153
+ if (!resolved.ok)
2154
+ return { ok: false, code: resolved.code, error: resolved.reason };
2155
+ if (resolved.command.kind !== 'quota') {
2156
+ return { ok: false, code: 'NOT_ALLOWED', error: 'Host control role operations support quota commands only' };
2157
+ }
2158
+ try {
2159
+ const result = await executeResolvedRoleCommand(resolved.command, 'local-cli', applyApprovedRoleAssignment, {
2160
+ self: resolved.command.selfAid, actorRole: 'none', actorAid: 'local-cli',
2161
+ isDaemonOwner: true, fromControlChannel: true, chatType: 'private',
2162
+ });
2163
+ return result.ok ? { ok: true, result } : result;
2164
+ }
2165
+ catch (error) {
2166
+ return { ok: false, code: error?.code ?? 'ROLE_OPERATION_FAILED', error: error?.message ?? String(error), data: error?.data };
2167
+ }
2168
+ }
2168
2169
  if (!this.agentDelegationRegistry) {
2169
2170
  return { ok: false, code: 'DELEGATION_REQUIRED', error: 'Task delegation is not configured' };
2170
2171
  }
@@ -2175,21 +2176,55 @@ export class CommandHandler {
2175
2176
  if (!session)
2176
2177
  return { ok: false, code: 'INVALID_SESSION', error: 'Invalid session' };
2177
2178
  const grant = delegation.grant;
2179
+ if (session.selfAID !== grant.selfAid || grant.sessionId !== sessionId) {
2180
+ return { ok: false, code: 'INVALID_DELEGATION', error: 'Delegation does not match the current session' };
2181
+ }
2178
2182
  const resolvedArgv = argv.includes('--self') ? argv : [...argv, '--self', grant.selfAid];
2179
2183
  const resolved = resolveRoleCommand(resolvedArgv);
2180
2184
  if (!resolved.ok)
2181
2185
  return { ok: false, code: resolved.code, error: resolved.reason };
2182
- if (resolved.command.selfAid !== grant.selfAid) {
2186
+ const command = resolved.command;
2187
+ if (command.selfAid !== grant.selfAid && command.kind !== 'quota') {
2183
2188
  return { ok: false, code: 'SCOPE_MISMATCH', error: 'Only the current Agent role requests can be targeted' };
2184
2189
  }
2185
2190
  try {
2186
- const result = await executeResolvedRoleCommand(resolved.command, grant.actorId, applyApprovedRoleAssignment);
2191
+ if (command.kind === 'quota') {
2192
+ const conversationId = parsePeerKey(grant.peerKey).channelId;
2193
+ const subject = buildAuthSubject({
2194
+ selfAid: grant.selfAid, sessionId, actorId: grant.actorId,
2195
+ channel: grant.channel, channelType: grant.channelType, channelId: conversationId,
2196
+ chatType: grant.chatType, conversationId, processOwners: ownerResolver.daemonOwners(),
2197
+ ...trustedExecutionIdentityInput(grant),
2198
+ });
2199
+ if (command.selfAid !== grant.selfAid && !subject.isDaemonOwner && !hasTrustedFullAccessDelegation(grant)) {
2200
+ return { ok: false, code: 'SCOPE_MISMATCH', error: 'A different Agent requires DaemonOwner authorization or trusted fullaccess' };
2201
+ }
2202
+ return await executeAuditedOperation({
2203
+ source: 'agent-tool', subject,
2204
+ intent: {
2205
+ operation: command.action === 'show' ? 'role.policy.read' : 'role.policy.write',
2206
+ scope: 'agent', source: 'agent-tool',
2207
+ args: { self: command.selfAid, targetAgentAid: command.selfAid, roleId: command.roleId },
2208
+ },
2209
+ auditMetadata: { argvHash: hashArgv(command.canonicalArgv), taskId: grant.taskId, messageId: grant.messageId },
2210
+ }, async (onExecutionStarted) => {
2211
+ onExecutionStarted();
2212
+ const result = await executeResolvedRoleCommand(command, grant.actorId, applyApprovedRoleAssignment, {
2213
+ self: command.selfAid, actorRole: subject.role, actorAid: subject.principalId ?? subject.actorId,
2214
+ chatType: grant.chatType,
2215
+ isDaemonOwner: subject.isDaemonOwner, fromControlChannel: subject.fromControlChannel,
2216
+ trustedFullAccess: subject.processRole === 'fullaccess-run' && subject.dataScope === 'daemon',
2217
+ });
2218
+ return result.ok ? { ok: true, result } : result;
2219
+ });
2220
+ }
2221
+ const result = await executeResolvedRoleCommand(command, grant.actorId, applyApprovedRoleAssignment);
2187
2222
  if (!result.ok)
2188
2223
  return { ok: false, code: result.code, error: result.error, data: result.data };
2189
2224
  return { ok: true, result };
2190
2225
  }
2191
2226
  catch (error) {
2192
- return { ok: false, code: 'ROLE_OPERATION_FAILED', error: error?.message ?? String(error) };
2227
+ return { ok: false, code: error?.code ?? 'ROLE_OPERATION_FAILED', error: error?.message ?? String(error), data: error?.data };
2193
2228
  }
2194
2229
  }
2195
2230
  /**
@@ -2239,7 +2274,8 @@ export class CommandHandler {
2239
2274
  if (isRequest && targetAid !== grantSelfAid) {
2240
2275
  return { ok: false, code: 'SCOPE_MISMATCH', error: '加好友申请只能由当前任务所属 Agent 发起' };
2241
2276
  }
2242
- const operation = isRequest ? 'ec.directory.request' : 'ec.directory.query';
2277
+ const operation = isRequest ? 'ec.directory.request'
2278
+ : ['block', 'unblock'].includes(subArgv[0]) ? 'ec.directory.block' : 'ec.directory.query';
2243
2279
  const subject = buildAuthSubject({
2244
2280
  selfAid: grantSelfAid,
2245
2281
  sessionId,
@@ -2284,7 +2320,7 @@ export class CommandHandler {
2284
2320
  to: input.to, payload: input.payload, rawPayload: true, encrypt: true,
2285
2321
  log: { content: '[friend.invite.v1]', threadId: '', msgType: 'custom', payloadType: 'friend.invite.v1', source: 'msg' },
2286
2322
  });
2287
- return { ok: sent.ok, message_id: sent.message_id, error: sent.error, code: sent.code };
2323
+ return { ok: sent.ok, message_id: sent.message_id, outbox_id: sent.outbox_id, status: sent.status, error: sent.error, code: sent.code };
2288
2324
  });
2289
2325
  return result.ok ? { ok: true, result } : { ok: false, code: result.code, error: result.error };
2290
2326
  }
@@ -2309,7 +2345,7 @@ export class CommandHandler {
2309
2345
  return { ok: false, code: 'SCOPE_MISMATCH', error: 'Resolved Agent target does not match the authorized target' };
2310
2346
  }
2311
2347
  onExecutionStarted();
2312
- const result = await executeDirectoryQueryCommand(command);
2348
+ const result = await executeDirectoryQueryCommand(command, subject.principalId ?? subject.actorId);
2313
2349
  return result.ok
2314
2350
  ? { ok: true, result }
2315
2351
  : { ok: false, code: result.code, error: result.error };
@@ -2340,6 +2376,8 @@ export class CommandHandler {
2340
2376
  catch {
2341
2377
  return { ok: false, code: 'INVALID_DELEGATION', error: 'Delegation contains an invalid relation key' };
2342
2378
  }
2379
+ const managedTempPath = parsed.command.kind === 'avatar' && parsed.command.filePath
2380
+ ? await this.getManagedSessionTempDir(session) : undefined;
2343
2381
  const subject = buildAuthSubject({
2344
2382
  selfAid: delegation.grant.selfAid,
2345
2383
  sessionId,
@@ -2376,9 +2414,9 @@ export class CommandHandler {
2376
2414
  taskId: delegation.grant.taskId,
2377
2415
  messageId: delegation.grant.messageId,
2378
2416
  },
2379
- }, onExecutionStarted => this.executeAuthorizedAidOperation(parsed.command, session, subject, delegation.grant, onExecutionStarted));
2417
+ }, onExecutionStarted => this.executeAuthorizedAidOperation(parsed.command, session, subject, delegation.grant, onExecutionStarted, managedTempPath));
2380
2418
  }
2381
- async executeAuthorizedAidOperation(command, session, subject, grant, onExecutionStarted) {
2419
+ async executeAuthorizedAidOperation(command, session, subject, grant, onExecutionStarted, managedTempPath) {
2382
2420
  const grantSelfAid = grant.selfAid.replace(/^@/, '');
2383
2421
  let avatarBuffer;
2384
2422
  if (command.kind === 'avatar' && command.filePath) {
@@ -2387,7 +2425,6 @@ export class CommandHandler {
2387
2425
  return { ok: false, code: 'INVALID_AVATAR_PATH', error: 'Avatar file requires a current session project path' };
2388
2426
  }
2389
2427
  const projectPath = path.resolve(session.projectPath);
2390
- const managedTempPath = this.getManagedSessionTempDir(session);
2391
2428
  const resolvedPath = path.isAbsolute(filePath) ? path.resolve(filePath) : path.resolve(projectPath, filePath);
2392
2429
  // 对端发来的图片按原有机制落在本 Agent 的关系附件目录;直接引用原文件,
2393
2430
  // 不要求先复制到项目里。只放开本 Agent 自己的目录,其它 Agent 的不在其中。
@@ -2514,6 +2551,7 @@ export class CommandHandler {
2514
2551
  catch {
2515
2552
  return { ok: false, code: 'INVALID_DELEGATION', error: 'Delegation contains an invalid relation key' };
2516
2553
  }
2554
+ const managedTempPath = parsed.command.kind === 'rules.set' ? await this.getManagedSessionTempDir(session) : undefined;
2517
2555
  const subject = buildAuthSubject({
2518
2556
  selfAid: grant.selfAid,
2519
2557
  actorId: grant.actorId,
@@ -2572,7 +2610,6 @@ export class CommandHandler {
2572
2610
  const filePath = String(parsed.command.filePath || '');
2573
2611
  const projectPath = path.resolve(session.projectPath);
2574
2612
  const resolvedPath = path.resolve(projectPath, filePath);
2575
- const managedTempPath = this.getManagedSessionTempDir(session);
2576
2613
  const allowedPaths = [projectPath, managedTempPath].filter((value) => !!value);
2577
2614
  if (!filePath || !allowedPaths.some(root => isSameOrDescendant(resolvedPath, root))) {
2578
2615
  return { ok: false, code: 'INVALID_RULES_PATH', error: 'Rules file must be inside the current session project or managed TMPDIR' };
@@ -2897,6 +2934,7 @@ export class CommandHandler {
2897
2934
  : actorAid;
2898
2935
  const relationTarget = currentGroup
2899
2936
  ?? (grant.channelType === 'aun' && grant.chatType === 'private' ? relationId : undefined);
2937
+ const managedTempPath = parsed.command.kind === 'upload' ? await this.getManagedSessionTempDir(session) : undefined;
2900
2938
  const subject = buildAuthSubject({
2901
2939
  selfAid: grant.selfAid,
2902
2940
  actorId: grant.actorId,
@@ -2948,7 +2986,6 @@ export class CommandHandler {
2948
2986
  if (!localPath)
2949
2987
  return { ok: false, code: 'INVALID_ARGUMENT', error: 'Managed upload source is required' };
2950
2988
  const resolvedPath = path.resolve(projectPath, localPath);
2951
- const managedTempPath = this.getManagedSessionTempDir(session);
2952
2989
  const allowedRoots = [projectPath, managedTempPath].filter((value) => !!value);
2953
2990
  if (!allowedRoots.some(root => isSameOrDescendant(resolvedPath, root))) {
2954
2991
  return { ok: false, code: 'INVALID_LOCAL_PATH', error: 'Upload source must be inside the current session project or managed TMPDIR' };
@@ -3036,7 +3073,6 @@ export class CommandHandler {
3036
3073
  threadId: topic.threadId,
3037
3074
  name: topic.name,
3038
3075
  topicStatus: topic.topicStatus,
3039
- label: topic.label ?? null,
3040
3076
  },
3041
3077
  currentSummary: service.showSummary(input.selfAid, topic.sessionId) ?? null,
3042
3078
  summaries,
@@ -3121,7 +3157,10 @@ export class CommandHandler {
3121
3157
  const fullAccess = hasTrustedFullAccessDelegation(grant);
3122
3158
  if (hasModelSelector) {
3123
3159
  if (!isModelRead) {
3124
- return { ok: false, code: 'NOT_ALLOWED', error: 'Managed model selectors are available only for Owner bypass read-only previews' };
3160
+ // 托管写操作不接受任何选择器。`--self <本端 AID>` 的幂等写法由 CLI 层在发送前
3161
+ // 剥掉(src/cli/model.ts),守护进程不需要为此放宽:这里收到的选择器只可能
3162
+ // 指向别的 Agent,或者说明调用方绕过了 CLI。
3163
+ return { ok: false, code: 'NOT_ALLOWED', error: 'Managed model writes cannot select --self, --peer, or --role' };
3125
3164
  }
3126
3165
  if ((selector.peerKey || selector.role) && !selector.self)
3127
3166
  return invalid('--peer/--role requires --self');
@@ -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' },