evolcore 0.0.48 → 0.0.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (302) hide show
  1. package/CHANGELOG.md +97 -0
  2. package/bin/ecmsg.js +9 -4
  3. package/dist/ability/caller/authorization.js +21 -0
  4. package/dist/ability/caller/command.js +164 -0
  5. package/dist/ability/caller/contract.js +102 -0
  6. package/dist/ability/caller/daemon.js +158 -0
  7. package/dist/ability/caller/service.js +380 -0
  8. package/dist/ability/command-contract.js +5 -0
  9. package/dist/ability/daemon.js +5 -1
  10. package/dist/ability/interop-v1.js +10 -3
  11. package/dist/ability/management.js +1 -0
  12. package/dist/agent-template/jobs.js +173 -1
  13. package/dist/agent-template/runtime.js +285 -8
  14. package/dist/agent-template/service.js +1159 -40
  15. package/dist/agent-template/types.js +2 -1
  16. package/dist/agents/baseagent-availability.js +27 -3
  17. package/dist/agents/baseagent-capability-adapter.js +102 -0
  18. package/dist/agents/baseagent-plugin-descriptor.js +274 -0
  19. package/dist/agents/baseagent-plugin-loader.js +145 -0
  20. package/dist/agents/baseagent.js +68 -2
  21. package/dist/agents/claude-gateway/agent-registration.js +389 -0
  22. package/dist/agents/claude-gateway/binding.js +96 -0
  23. package/dist/agents/claude-gateway/inbox.js +138 -0
  24. package/dist/agents/claude-gateway/index.js +125 -0
  25. package/dist/agents/claude-gateway/listing.js +330 -0
  26. package/dist/agents/claude-gateway/router.js +328 -0
  27. package/dist/agents/claude-gateway/sessions.js +128 -0
  28. package/dist/agents/claude-gateway/terminal.js +250 -0
  29. package/dist/agents/claude-gateway/transcript.js +272 -0
  30. package/dist/agents/claude-gateway/types.js +14 -0
  31. package/dist/agents/claude-runner.js +6 -10
  32. package/dist/agents/codex-runner.js +9 -2
  33. package/dist/agents/{gemini-runner.js → gemini/gemini-runner.js} +17 -17
  34. package/dist/{core/session/adapters → agents/gemini}/gemini-session-file-adapter.js +2 -2
  35. package/dist/agents/gemini/index.js +51 -0
  36. package/dist/aun/aid/control-aid.js +52 -32
  37. package/dist/aun/group/invite-service.js +6 -36
  38. package/dist/aun/group/operations.js +6 -0
  39. package/dist/aun/msg/mention-schema.js +1 -1
  40. package/dist/aun/msg/p2p.js +31 -2
  41. package/dist/aun/msg/upload.js +126 -3
  42. package/dist/build-identity.json +1 -1
  43. package/dist/channels/aun.js +1175 -457
  44. package/dist/cli/ability-command.js +42 -0
  45. package/dist/cli/agent-command.js +20 -1
  46. package/dist/cli/agent-create.js +78 -18
  47. package/dist/cli/agent-template.js +5 -3
  48. package/dist/cli/agent.js +91 -0
  49. package/dist/cli/aun-commands.js +92 -34
  50. package/dist/cli/bench.js +5 -2
  51. package/dist/cli/config.js +22 -6
  52. package/dist/cli/daemon-commands.js +245 -101
  53. package/dist/cli/directory.js +6 -1
  54. package/dist/cli/ecmsg-gateway.js +11 -9
  55. package/dist/cli/index.js +30 -5
  56. package/dist/cli/init.js +39 -63
  57. package/dist/cli/managed-command-guard.js +3 -0
  58. package/dist/cli/menu-client.js +32 -7
  59. package/dist/cli/model.js +20 -5
  60. package/dist/cli/pay-command.js +30 -0
  61. package/dist/cli/provider-command.js +6 -2
  62. package/dist/cli/quota.js +89 -0
  63. package/dist/cli/restart-monitor.js +2 -2
  64. package/dist/cli/role.js +1 -0
  65. package/dist/cli/services-command.js +12 -9
  66. package/dist/cli/team-workspace-command.js +56 -2
  67. package/dist/cli/thread-command.js +78 -12
  68. package/dist/config/access-policy.js +16 -3
  69. package/dist/config/config-field-policy.js +88 -9
  70. package/dist/config/config-manager.js +97 -47
  71. package/dist/config/config-operation-service.js +22 -1
  72. package/dist/config/gateway-config.js +9 -8
  73. package/dist/config/owner-config.js +0 -16
  74. package/dist/config/peer-role-resolver.js +1 -7
  75. package/dist/config/providers-config.js +107 -20
  76. package/dist/config/providers-management.js +45 -21
  77. package/dist/config/resolved-config-op.js +4 -44
  78. package/dist/config/schema-migration.js +78 -5
  79. package/dist/config/schema-registry.js +52 -7
  80. package/dist/config-store.js +1309 -17
  81. package/dist/core/agent-application-service.js +220 -1
  82. package/dist/core/agent-ipc-registration.js +19 -2
  83. package/dist/core/agent-reload-coordinator.js +5 -0
  84. package/dist/core/agent-runtime.js +198 -54
  85. package/dist/core/auth/agent-delegation.js +14 -0
  86. package/dist/core/auth/delegation-authorization.js +33 -26
  87. package/dist/core/auth/operation-authorizer.js +16 -1
  88. package/dist/core/auth/operation-catalog.js +59 -7
  89. package/dist/core/baseagent-loader.js +30 -3
  90. package/dist/core/capability/capability-manager.js +16 -7
  91. package/dist/core/channel-runtime.js +4 -2
  92. package/dist/core/command/agent-control.js +20 -2
  93. package/dist/core/command/agent-template-menu.js +4 -3
  94. package/dist/core/command/cli-intent-parser.js +28 -0
  95. package/dist/core/command/command-handler.js +45 -2
  96. package/dist/core/command/menu-catalog.js +20 -4
  97. package/dist/core/command/menu-file-path.js +70 -0
  98. package/dist/core/command/menu-handler.js +97 -73
  99. package/dist/core/command/menu-protocol.js +29 -0
  100. package/dist/core/command/menu-query-batch.js +2 -2
  101. package/dist/core/command/private-mention-menu.js +71 -0
  102. package/dist/core/command/remote-shell.js +565 -0
  103. package/dist/core/command/slash-handler.js +17 -26
  104. package/dist/core/command/team-workspace-bootstrap.js +2 -1
  105. package/dist/core/command/topic-slash.js +7 -1
  106. package/dist/core/daemon-bootstrap.js +0 -4
  107. package/dist/core/daemon-control.js +58 -1
  108. package/dist/core/daemon-lifecycle.js +29 -7
  109. package/dist/core/evolagent-registry.js +18 -9
  110. package/dist/core/handoff/runtime.js +1 -1
  111. package/dist/core/host-snapshot.js +8 -3
  112. package/dist/core/initialization/service.js +3 -0
  113. package/dist/core/interaction-router.js +130 -0
  114. package/dist/core/ipc-registration.js +5 -0
  115. package/dist/core/memory/consolidation-context.js +2 -1
  116. package/dist/core/memory/consolidation.js +35 -64
  117. package/dist/core/message/aun-ipc-sender.js +213 -74
  118. package/dist/core/message/aun-request-registry.js +31 -0
  119. package/dist/core/message/contact-admission.js +91 -6
  120. package/dist/core/message/contact-pending-inbound.js +113 -0
  121. package/dist/core/message/contact-thread-approval.js +212 -0
  122. package/dist/core/message/im-renderer.js +40 -1
  123. package/dist/core/message/message-admission.js +5 -39
  124. package/dist/core/message/message-bridge.js +197 -45
  125. package/dist/core/message/message-log.js +32 -0
  126. package/dist/core/message/message-queue.js +102 -18
  127. package/dist/core/message/peer-mode.js +15 -4
  128. package/dist/core/message/response-engine.js +174 -26
  129. package/dist/core/message/send-options.js +37 -3
  130. package/dist/core/message/send-routing.js +11 -7
  131. package/dist/core/model/config-scope.js +6 -14
  132. package/dist/core/model/model-catalog.js +5 -5
  133. package/dist/core/model/model-diagnostics.js +19 -0
  134. package/dist/core/model/model-fallback.js +13 -2
  135. package/dist/core/ownership/owner-resolver.js +12 -86
  136. package/dist/core/pack-auth.js +7 -0
  137. package/dist/core/pack-install.js +1 -1
  138. package/dist/core/permission/ec-command-parser.js +288 -77
  139. package/dist/core/permission/protected-paths.js +64 -9
  140. package/dist/core/permission/services-path-acl.js +458 -0
  141. package/dist/core/permission/tool-policy.js +26 -10
  142. package/dist/core/relation/peer-identity.js +13 -0
  143. package/dist/core/session/adapters/claude-session-file-adapter.js +6 -2
  144. package/dist/core/session/adapters/codex-session-file-adapter.js +4 -0
  145. package/dist/core/session/session-manager.js +47 -10
  146. package/dist/core/session/session-mapper.js +16 -0
  147. package/dist/core/skill/index-generator.js +2 -3
  148. package/dist/core/skill/switch-resolver.js +3 -0
  149. package/dist/core/task/task-recovery-service.js +1 -0
  150. package/dist/core/thread/command-parser.js +4 -1
  151. package/dist/core/thread/ipc-operation.js +4 -2
  152. package/dist/core/thread/thread-operation.js +25 -10
  153. package/dist/core/thread/thread-service.js +294 -55
  154. package/dist/core/thread/topic-id.js +67 -2
  155. package/dist/core/thread/types.js +15 -1
  156. package/dist/directory/owner-directory-admission.js +11 -8
  157. package/dist/directory/owner-directory-cache.js +19 -0
  158. package/dist/directory/owner-directory-markdown.js +1 -1
  159. package/dist/directory/owner-directory-policy.js +5 -30
  160. package/dist/directory/owner-directory-request-operation.js +5 -2
  161. package/dist/eck/kit-renderer.js +3 -2
  162. package/dist/eck/message-renderer.js +28 -5
  163. package/dist/ecweb/basic-settings-service.js +5 -9
  164. package/dist/ecweb/providers-service.js +4 -2
  165. package/dist/ecweb/runtime/supervisor.js +36 -8
  166. package/dist/event-center/center-config.js +9 -5
  167. package/dist/event-center/dispatcher.js +10 -1
  168. package/dist/event-center/ipc-operation.js +19 -0
  169. package/dist/event-center/registry.js +20 -5
  170. package/dist/event-center/runtime.js +10 -7
  171. package/dist/index.js +120 -41
  172. package/dist/ipc.js +83 -3
  173. package/dist/outputs/authorization.js +16 -0
  174. package/dist/outputs/cards.js +336 -0
  175. package/dist/outputs/events.js +3 -2
  176. package/dist/outputs/protocol.js +1 -0
  177. package/dist/outputs/service.js +2 -15
  178. package/dist/paths.js +48 -1
  179. package/dist/pay/command.js +38 -0
  180. package/dist/pay/protocol.js +136 -0
  181. package/dist/pay/runtime.js +188 -0
  182. package/dist/pay/service.js +384 -0
  183. package/dist/pay/store.js +81 -0
  184. package/dist/response-system/engines/v1/proactive-flow.js +29 -2
  185. package/dist/services/dispatcher.js +23 -5
  186. package/dist/services/host/main.js +388 -0
  187. package/dist/services/host/protocol.js +118 -0
  188. package/dist/services/host/resident.js +310 -0
  189. package/dist/services/host-client.js +386 -0
  190. package/dist/services/host-deploy.js +180 -0
  191. package/dist/services/host-launch.js +117 -0
  192. package/dist/services/host-recycle.js +203 -0
  193. package/dist/services/host-runtime.js +802 -0
  194. package/dist/services/idempotency.js +44 -86
  195. package/dist/services/index-generator.js +4 -3
  196. package/dist/services/index.js +204 -22
  197. package/dist/services/ipc-operation.js +288 -44
  198. package/dist/services/pack-manager.js +1 -0
  199. package/dist/services/script-runner.js +515 -83
  200. package/dist/services/service-payload.js +13 -7
  201. package/dist/services/validation.js +109 -4
  202. package/dist/stats/budget.js +1 -1
  203. package/dist/stats/model-resolver.js +2 -2
  204. package/dist/stats/quota-query.js +95 -0
  205. package/dist/trigger/application-service.js +6 -4
  206. package/dist/trigger/local-files.js +19 -9
  207. package/dist/trigger/scheduler.js +22 -12
  208. package/dist/trigger/script-sandbox.js +51 -8
  209. package/dist/utils/aid-bind.js +3 -0
  210. package/dist/utils/atomic-write.js +22 -8
  211. package/dist/utils/evolcore-version.js +2 -2
  212. package/dist/utils/host-info.js +173 -1
  213. package/dist/utils/logger.js +2 -2
  214. package/dist/utils/media-cache.js +190 -43
  215. package/dist/utils/npm-ops.js +43 -8
  216. package/dist/utils/restart-safety.js +14 -1
  217. package/dist/utils/system-memory.js +113 -25
  218. package/dist/utils/systemd-lifecycle.js +154 -0
  219. package/dist/utils/windows-shell-trust.js +7 -3
  220. package/dist/workbench/service.js +1 -1
  221. package/kits/docs/INDEX.md +3 -2
  222. package/kits/docs/aun/AUN/346/266/210/346/201/257/347/261/273/345/236/213/344/270/216/345/261/236/346/200/247.md +1 -0
  223. package/kits/docs/channels/aun.md +1 -1
  224. package/kits/docs/evolcore/INDEX.md +9 -6
  225. package/kits/docs/evolcore/agent.md +36 -1
  226. package/kits/docs/evolcore/aid.md +45 -3
  227. package/kits/docs/evolcore/config.md +5 -2
  228. package/kits/docs/evolcore/directory.md +8 -9
  229. package/kits/docs/evolcore/group.md +2 -1
  230. package/kits/docs/evolcore/memory-tags.md +2 -0
  231. package/kits/docs/evolcore/menu-client.md +3 -3
  232. package/kits/docs/evolcore/menu-protocol.md +7 -0
  233. package/kits/docs/evolcore/model.md +3 -0
  234. package/kits/docs/evolcore/msg.md +77 -10
  235. package/kits/docs/evolcore/pay.md +34 -0
  236. package/kits/docs/evolcore/provider.md +22 -1
  237. package/kits/docs/evolcore/quota.md +54 -0
  238. package/kits/docs/evolcore/role.md +3 -0
  239. package/kits/docs/evolcore/services.md +46 -18
  240. package/kits/docs/evolcore/stats.md +2 -0
  241. package/kits/docs/evolcore/thread-chain.md +2 -0
  242. package/kits/docs/evolcore/tool-authorization.md +10 -0
  243. package/kits/docs/evolcore/trigger.md +2 -0
  244. package/kits/rules/01-overview.md +11 -32
  245. package/kits/rules/02-navigation.md +7 -0
  246. package/kits/rules/06-channel.md +3 -3
  247. package/kits/schemas/_meta.json +38 -5
  248. package/kits/schemas/agent-config.schema.20.json +24 -0
  249. package/kits/schemas/agent-config.schema.21.json +974 -0
  250. package/kits/schemas/agent-config.schema.22.json +977 -0
  251. package/kits/schemas/agent-config.schema.23.json +958 -0
  252. package/kits/schemas/daemon.schema.10.json +373 -0
  253. package/kits/schemas/daemon.schema.9.json +12 -0
  254. package/kits/schemas/defaults.schema.7.json +472 -0
  255. package/kits/schemas/providers.schema.3.json +18 -2
  256. package/kits/schemas/relation-config.schema.13.json +289 -0
  257. package/kits/skills/.switches.json +17 -1
  258. package/kits/skills/ability/SKILL.md +229 -34
  259. package/kits/skills/ability/STRUCTURE.md +333 -0
  260. package/kits/skills/ability/references/cli.md +208 -0
  261. package/kits/skills/ability/references/development.md +107 -37
  262. package/kits/skills/ability/references/management.md +106 -46
  263. package/kits/skills/ability/references/runtime-protocol.md +65 -63
  264. package/kits/skills/agent-output-cards/SKILL.md +64 -0
  265. package/kits/skills/ec-group/SKILL.md +8 -6
  266. package/kits/skills/ec-group/TASK.md +186 -0
  267. package/kits/skills/ec-group/WORKLOG.md +180 -0
  268. package/kits/skills/ec-group-collaboration/SKILL.md +3 -3
  269. package/kits/skills/ec-pay/SKILL.md +101 -0
  270. package/kits/skills/ec-pay/references/pay-cli.md +110 -0
  271. package/kits/skills/ec-provider/SKILL.md +58 -9
  272. package/kits/skills/{ec-service-proxy → ec-proxy}/SKILL.md +8 -5
  273. package/kits/skills/ec-service-call/SKILL.md +135 -0
  274. package/kits/skills/ec-service-pack/SKILL.md +277 -0
  275. package/kits/skills/ec-trigger/SKILL.md +1 -1
  276. package/kits/templates/memory-consolidation/notes.md +2 -2
  277. package/kits/templates/memory-consolidation/workflow.md +46 -0
  278. package/kits/templates/roles/visitor.json +1 -0
  279. package/kits/templates/system-fragments/channel.md +13 -4
  280. package/kits/templates/system-fragments/commands.md +5 -3
  281. package/kits/templates/system-fragments/directory-contacts.md +3 -4
  282. package/kits/templates/system-fragments/reply.md +1 -0
  283. package/kits/templates/system-fragments/session.md +1 -1
  284. package/kits/templates/system-fragments/thread.md +27 -128
  285. package/kits/templates/system-fragments/venue.md +27 -0
  286. package/package.json +4 -5
  287. package/scripts/agent-template/inspect.mjs +79 -29
  288. package/scripts/agent-template/overlay.mjs +20 -2
  289. package/scripts/agent-template/shared/common.mjs +24 -6
  290. package/scripts/agent-template/shared/team-schema.json +23 -5
  291. package/scripts/agent-template/shared/template-contract.mjs +107 -17
  292. package/scripts/agent-template/shared/template-package.mjs +254 -29
  293. package/scripts/agent-template/shared/template-runtime.mjs +145 -2
  294. package/scripts/agent-template/shared/template.mjs +67 -9
  295. package/scripts/agent-template/team-pack.mjs +132 -41
  296. package/scripts/agent-template/team-preview.mjs +249 -5
  297. package/kits/docs/aun/ABILITY_CALLING.md +0 -280
  298. package/kits/docs/evolcore/ability.md +0 -185
  299. package/kits/skills/ability/references/calling.md +0 -56
  300. package/kits/skills/ability/references/contract-checklist.md +0 -37
  301. package/kits/skills/ability/references/recovery.md +0 -27
  302. /package/dist/{core/capability/providers → agents/gemini}/gemini-capability-provider.js +0 -0
package/CHANGELOG.md CHANGED
@@ -5,6 +5,103 @@
5
5
 
6
6
  ## Unreleased
7
7
 
8
+ ## 0.0.50 (2026-11-17)
9
+
10
+ ### 能力调用与交互
11
+
12
+ - 新增 ec ability remote list/discover/info/devices/call/result,支持发现主体能力、筛选设备、读取契约、校验参数和加密调用;提供固定计划预览、操作去重及迟到结果查询,区分投递回执与业务完成。
13
+ - 远端能力使用协议专用授权,复用托管委托、共享发送器和请求索引;默认精简分页,支持搜索及按需读取契约和用法,完善参数错误诊断。
14
+ - 新增订单扫码付款卡片及 ec pay,支持微信、支付宝渠道选择、二维码刷新、订单核验和付款后继续任务;新增 WidgetCard HTML 表单交互及关联回复。
15
+ - 新增 Owner 可管理的私聊提及模式,默认关闭;开启后未提及消息仅保留历史,不创建模型回合,与群聊提及策略独立。
16
+
17
+ ### 基座与会话
18
+
19
+ - 新增随包基座插件发现、描述符校验、全局启用开关及运行组件注册回滚;初始化、模型目录、供应商诊断和模板采集使用已发现的基座,Gemini 迁入目录插件结构。
20
+ - 新增本机 Claude Code 会话网关,支持按话题绑定原生会话、投递消息和跟读输出;网关须显式启用。
21
+ - 支持单个及多选 Agent 项目地址迁移,展示分步进度,处理文件冲突、原生会话资源复用、失败回滚及中断恢复。
22
+
23
+ ### 模板与服务
24
+
25
+ - 团队模板支持可选成员、外部联系人声明及安装状态恢复,完善模板标识、内容打包和显式访问配置保留。
26
+ - 单 Agent 模板支持可信来源绑定、更新检查、固定版本预览及 Owner 手动确认执行;失败时回滚并恢复原作业,auto 声明暂不触发自动更新。
27
+ - 服务包新增常驻脚本宿主,完善调用关联、超时、空闲回收、重启退避及降级执行;代理管理、服务调用和建包分别使用对应技能。
28
+
29
+ ### 身份、安全与运行
30
+
31
+ - Owner 仅由 Ownership 2.1 协议共识授予,移除 daemon 与 Agent 配置中的 Owner 授权回退,保留协议来源的只读查询,并迁移旧配置字段。
32
+ - 附件统一归档至 Agent 目录,历史引用使用可迁移别名;修复新旧附件索引按文件名和附件 ID 解析的问题。
33
+ - 修复 Windows 文件校验及普通 Shell 命令误拦截,补齐设备标识签名伴随文件保护,修正 Claude 百万上下文识别,完善 systemd 重启接管和就绪确认。
34
+ - 精简 ECK 注入并收拢 Ability、付款和服务技能文档;完善消息发送参数、来源信息及失败诊断。
35
+
36
+ ### 兼容要求
37
+
38
+ - 需要 Node.js >=22.16.0,固定依赖 @agentunion/fastaun 0.5.38,配套 ec-web@0.0.50。
39
+ - EventService Bus 需要服务端支持会话绑定注册确认;Owner 配置字段不再授予权限。
40
+ - Gemini 插件当前仅声明 Linux 环境,保留 readonly/auto 的现有限制;Windows、macOS 暂不启用该插件,原生 CLI 和 Provider 仍须单独配置。
41
+ - Invoke 尚未完成,不作为本版可用功能验收,相关测试继续跳过。
42
+
43
+ ## 0.0.49 (2026-11-15)
44
+
45
+ ### 成果、联系人与话题
46
+
47
+ - 新增语义成果卡片,支持报告、文档、会议和媒体等类型,关联主文件及附件,提供发布、移除和增量查询;成果与工作台查询完善 Owner 核验、控制消息投递及变更通知。
48
+ - 出站消息不再受本端联系人准入审批拦截,仍执行发送授权;入站继续按联系人范围和黑名单管理,授权后恢复待处理消息并防止重复投递。
49
+ - 跨话题委托的未准入回复通过加密卡片回到原 Owner 话题,审批结果与名录同步关联,避免重复申请、重复执行及错误回流。
50
+ - 为跨话题消息补充来源标记,修复话题链和直发日志归属,任务恢复触发器保留原话题。
51
+ - 清洗消息携带的场景与定位信息,明确采集时间和精度语义,避免控制字符污染上下文。
52
+
53
+ ### 模板与事件
54
+
55
+ - 团队模板支持收集、导出和安装事件包,校验可移植资源;成员冻结期间暂停启动事件处理,避免模板操作与事件执行冲突。
56
+ - 规范模板标识和默认 AID 域名声明,兼容旧字段并拒绝冲突;支持保留成员版本与更新策略声明,更新执行机制尚未实现。
57
+
58
+ ### 模型与额度
59
+
60
+ - 新增 ec quota status,查询 Agent 预算及对端角色额度的上限、已用、剩余和限制状态;区分独立与共享额度,并按权限保护总用量。
61
+ - 支持配置 Agent 级模型降级链,校验供应商、模型和推理强度,并在连接诊断中展示被过滤的候选;托管模型写操作允许显式指定当前本端 AID。
62
+
63
+ ### 安全与运行管理
64
+
65
+ - 新增 DaemonOwner 远程单命令终端,仅限当前协议 Owner 的加密私聊,按设备和话题隔离;支持停止、退出及输出分片,最长开放 30 分钟,空闲 6 分钟自动退出。
66
+ - 支持 Codex 的 zsh 命令授权,按实际 Shell 校验字面参数和转义,阻止不安全展开及嵌套解释执行绕过授权。
67
+ - Windows 服务包目录增加后台 ACL 加固,清理残留写授权并保留读取和执行权限。
68
+ - 修复精确版本安装遇到 ETARGET 时的缓存恢复,在线重试关闭离线模式;保留安装和版本校验的具体失败阶段,并脱敏诊断信息。
69
+ - 修正容器 CPU 配额检测及小于一核时的占用率显示,完善控制 AID 名片补全时序和 Web 启动期间的端口占用恢复。
70
+
71
+ ### 兼容要求
72
+
73
+ - 需要 Node.js >=22.16.0,依赖 @agentunion/fastaun 0.5.37,配套 ec-web@0.0.49。
74
+ - 远程终端仅提供非交互单命令执行,不保留跨命令的目录或环境变量状态。
75
+ - Invoke 尚未完成,本版不将其列为可用功能;相关测试继续跳过。
76
+ ### 远端 Ability 工具
77
+
78
+ - 提示词与 ability skill 明确直接读取精简 JSON,优先用内置搜索/分页,不接 Python/Node/jq 管道;切换能力时重新核对当前参数 Schema,禁止照搬 action。参数 enum/const 报错展示字段及允许值,PARAMS_INVALID 明确 validation、sent=false 和修正参数指引。
79
+ - 远端 Ability 使用协议专用授权,不继承本机插件权限或普通聊天联系人准入准出,不设 Owner/admin/DaemonOwner 门槛;复用 daemon 共享发送器,保留任务/原命令绑定、readonly、契约、加密和 Provider 授权。回包在聊天准入前按原请求核验,未匹配回包不进模型;新增真实策略与传输回归。
80
+ - list/discover 默认精简分页(20项,最多100项),新增搜索与 --full;info 聚焦所选契约、用法及设备。统一位置 path 并兼容 --path,参数错误附正确用法;有效快照及指南复用。同步调整 skill、提示词和文档为按需 info → call,减少重复发现与资料读取。
81
+ - 修复远端发现被 `index.v1` 硬限制的问题:运行时从 well-known 按稳定目录字段读取,保留版本及兼容声明,沿 skill_ref/detail_ref 继续解析;支持 release 内嵌 definition/usage 及发布摘要校验,新增 list --usage,避免固化 Provider 能力和文件布局。
82
+ - 新增 `ec ability remote list/discover/info/devices/call/result`,从主体 AID 发现能力、读取契约、筛选设备,自动校验参数并加密定向调用;原宿主插件管理命令保持兼容。
83
+ - 支持 `call --dry-run` 固定计划、持久操作去重和迟到结果查询;区分投递 ACK、业务状态与结果验证,超时和崩溃恢复不自动重发。
84
+ - 远端工具复用托管会话的委托鉴权、共享 sender 和请求索引;同步更新 Ability 文档、skill 与 ECK 提示词。首次加载新 daemon 代码需要宿主重启。
85
+
86
+ ### 消息与提及
87
+
88
+ - 私聊提及模式新增专用 Menu 查询、选项与 Owner 修改接口 `private-mention-mode`,接入 `queries` 与 Catalog `privateMentionMode.agent` 的 `values` 批量获取;更新使用 revision 校验,无需 CLI。
89
+ - 新增私聊提及模式:Agent 级配置项 `privateMentionMode`(`disabled` / `mention-only`,默认 `disabled`,仅 Owner 可改),
90
+ 开启后未被 `@` 的私聊消息只记入本地历史、不创建模型回合;与群聊 `mentionMode` 完全独立,群聊行为不变。
91
+ - 私聊入站补齐 `isMentioned` 标记与本地过滤记录字段 `privateAttention`,过滤记录可用 `ec msg history` 读取。
92
+
93
+ ### 依赖与 SDK
94
+
95
+ - SDK 升级并固定为 @agentunion/fastaun 0.5.37,跟进派生密钥缓存、重连削峰、Ownership 共识缓存、
96
+ 消息交付与 ACK 及 UDP 待机改进。
97
+ - 该版本将 EventService Bus 注册改为连接会话绑定:注册结果必须返回匹配的 `registration_id` 与
98
+ `session_bound: true`,否则按 `SERVICE_UNAVAILABLE` 失败;服务端需同步支持会话绑定注册。
99
+ - SDK 继续升级并固定为 @agentunion/fastaun 0.5.38,跟进设备标识 v2、共享 worker 池、证书验签与
100
+ 网关发现缓存、日志分流及多 Client 恢复错峰。
101
+ - `connect()` 改为返回 `Promise<ConnectResult>`;本仓库所有调用点均丢弃返回值,无需改动。
102
+ - 审计表的 workflow 字节本版有变化:仅 `yaml` 由静态导入改为在解析路径内 `createRequire` 懒加载,
103
+ read/verify/execute 边界不变,已按新摘要补登 `0.5.38` 条目。
104
+
8
105
  ## 0.0.48 (2026-11-14)
9
106
 
10
107
  ### 成果、工作台与服务
package/bin/ecmsg.js CHANGED
@@ -49,6 +49,8 @@ const HELP = `用法: ecmsg send '<正文>' [选项]
49
49
  --to <对端ID> 发到指定对端(群 AID 或对方 AID,按本地关系判定类型)
50
50
  --from <本端AID> 托管会话可省略(恒等于会话本端);非托管必填
51
51
  --to <本端AID> 跨话题自派(self-dispatch):必须配合 --thread,换话题给自己派活
52
+ 注意:from/to 只接受上面这两个参数,不接受位置参数——写在正文位置的
53
+ AID 会被当成正文发出去。
52
54
 
53
55
  复查:
54
56
  跨话题(对端或话题与会话不同)自动创建复查 Trigger,默认 20m;
@@ -56,15 +58,18 @@ const HELP = `用法: ecmsg send '<正文>' [选项]
56
58
  同话题永不创建复查;此时传 --check-every 只在回执里说明,不报错。
57
59
 
58
60
  加密:
59
- --encrypt yes|no|auto 默认 auto:被对端消息触发时跟随该消息,否则明文
61
+ --encrypt yes|no|auto 必须带取值。省略此参数时默认 auto:被对端消息触发时
62
+ 跟随该消息的加密状态,否则明文
60
63
  只有目标对端在 AUN 网络上才能加密;非 AUN 目标用 yes 会被拒绝。
61
64
 
62
65
  正文来源:
63
66
  '<正文>' 位置参数
64
67
  --text-from-file <path> 从文件读取
65
- --file <path> 附件(可配 --as image|video|voice|file、--text 说明)
68
+ --file <path> 附件(可配 --as image|video|voice|file|widget_card、--text 说明)
69
+ --as widget_card 上传 HTML 表单并发送 WidgetCard(--title 标题)
66
70
  --link <url> [--title T] 链接卡片
67
71
  --payload '<json>' 自定义 payload
72
+ --payload-file <path> 从 UTF-8 文件读 payload(仅私聊;文件上限 1 MiB)
68
73
 
69
74
  @提及(仅群聊;私聊带 --mention 会被拒绝):
70
75
  --mention '<aid1>,<aid2>' @指定成员,逗号分隔
@@ -78,7 +83,8 @@ const HELP = `用法: ecmsg send '<正文>' [选项]
78
83
  ecmsg send '收到,稍后回你'
79
84
  ecmsg send '问题已记录' --thread thread-1793851439746-7477-6351
80
85
  ecmsg send '进度如何' --to wang.agentid.pub --check-every 10m
81
- ecmsg send '报告在这里' --file ./report.md --as file
86
+ ecmsg send --file ./report.md --as file --text '报告在这里'
87
+ ecmsg send --file ./meeting.html --as widget_card --title '会议安排'
82
88
  `;
83
89
 
84
90
  // ── 委托哈希(与 agent-delegation.ts 逐字节一致,改动时两处必须同步) ──
@@ -494,7 +500,6 @@ async function main() {
494
500
  from: routeOpts.from,
495
501
  checkEvery: routeOpts.checkEvery,
496
502
  encrypt: routeOpts.encrypt,
497
- noEncrypt: routeOpts.noEncrypt === true,
498
503
  // auto 的判据:本轮是否带着入站消息的加密态。有该状态说明是回复对端消息,
499
504
  // 沿用它的加密方式;没有(如 trigger 唤醒发起)则明文。
500
505
  inboundTriggered: runtime?.inboundEncrypted !== undefined,
@@ -0,0 +1,21 @@
1
+ /** Protocol execution identity, independent of local plugin and contact roles. */
2
+ export function createRemoteAbilityAuthorizer(deps) {
3
+ return async (params, operation) => {
4
+ const validation = params.delegationGrant ? { ok: true, grant: params.delegationGrant }
5
+ : deps.agentDelegationRegistry.validate(params.delegationToken, params.sessionId, params.delegationCommandHash);
6
+ if (!validation.ok)
7
+ return { ok: false, code: validation.code, error: validation.reason };
8
+ const grant = validation.grant;
9
+ const session = await deps.sessionManager.getSessionById(params.sessionId);
10
+ if (grant.sessionId !== params.sessionId || !session || session.selfAID !== grant.selfAid
11
+ || !deps.agentDelegationRegistry.isCurrentTaskGrant(grant)) {
12
+ return { ok: false, code: 'INVALID_DELEGATION', error: 'Remote Ability requires the current task and Caller identity' };
13
+ }
14
+ if (grant.channelType !== 'aun')
15
+ return { ok: false, code: 'AUN_SESSION_REQUIRED', error: 'Remote Ability requires an AUN managed session' };
16
+ if (operation === 'ability.remote.call' && grant.permissionMode === 'readonly') {
17
+ return { ok: false, code: 'NOT_ALLOWED', error: 'Readonly tasks may inspect or preview; business calls require a writable task' };
18
+ }
19
+ return { ok: true, grant };
20
+ };
21
+ }
@@ -0,0 +1,164 @@
1
+ export const REMOTE_CLI_VERSION = 'evolcore.ability-remote-cli/v1';
2
+ export const REMOTE_COMMANDS = {
3
+ list: { description: '从 well-known 或指定快照读取精简能力目录', positional: 1, options: ['path', 'search', 'page', 'limit', 'full', 'refresh', 'usage', 'discovery'] },
4
+ discover: { description: '按需在线发现并收集设备能力', positional: 1, options: ['path', 'window', 'full'] },
5
+ info: { description: '读取所选契约、设备和用法', positional: 2, options: ['discovery', 'definition-id', 'usage', 'refresh', 'full'] },
6
+ devices: { description: '从发现快照筛选匹配能力的设备', positional: 1, options: ['path', 'discovery'] },
7
+ call: { description: '校验、预览或加密定向调用远端能力', positional: 2, options: ['discovery', 'definition-id', 'device-id', 'params', 'params-file', 'timeout', 'ttl', 'operation-id', 'dry-run', 'plan'] },
8
+ result: { description: '查询并校验原请求结果,不重新发送', positional: 1, options: ['wait'] },
9
+ };
10
+ export function remoteUsage(action) {
11
+ const signature = action === 'result' ? '<request-id> [--wait 30s]'
12
+ : action === 'call' ? '<ProviderAID> <path> [--params \'<JSON对象>\'] [选项] | ec ability remote call --plan <plan-id>'
13
+ : action === 'info' ? '<ProviderAID> <path> [--usage] [--full] [选项]'
14
+ : action === 'devices' ? '<ProviderAID> <path> --discovery <id>'
15
+ : '<ProviderAID> [path] [选项]';
16
+ return `ec ability remote ${action} ${signature}`;
17
+ }
18
+ export class RemoteError extends Error {
19
+ code;
20
+ data;
21
+ constructor(code, message, data) {
22
+ super(message);
23
+ this.code = code;
24
+ this.data = data;
25
+ }
26
+ }
27
+ export function remoteAssert(value, code, message, data) {
28
+ if (!value)
29
+ throw new RemoteError(code, message, data);
30
+ }
31
+ export function durationSeconds(value, maximum = 3600) {
32
+ const match = /^(\d+)(s|m)?$/.exec(value);
33
+ const seconds = match ? Number(match[1]) * (match[2] === 'm' ? 60 : 1) : NaN;
34
+ remoteAssert(Number.isSafeInteger(seconds) && seconds >= 1 && seconds <= maximum, 'ARGUMENT_INVALID', `Duration must be an integer from 1 to ${maximum} seconds`);
35
+ return seconds;
36
+ }
37
+ export function assertAbilityPath(value) {
38
+ remoteAssert(value.length <= 256 && /^[a-z][a-z0-9_-]*(\/[a-z][a-z0-9_-]*)+$/.test(value), 'ARGUMENT_INVALID', 'An exact Ability path is required');
39
+ }
40
+ export function parseRemoteCommand(argv) {
41
+ try {
42
+ return parseRemoteArguments(argv);
43
+ }
44
+ catch (error) {
45
+ if (!(error instanceof RemoteError) || error.code !== 'ARGUMENT_INVALID')
46
+ throw error;
47
+ const action = argv[2];
48
+ const usage = Object.hasOwn(REMOTE_COMMANDS, action) ? remoteUsage(action) : 'ec ability remote --help';
49
+ throw new RemoteError(error.code, error.message.includes('Usage:') ? error.message : `${error.message}. Usage: ${usage}`, { ...error.data, usage });
50
+ }
51
+ }
52
+ function parseRemoteArguments(argv) {
53
+ remoteAssert(argv[0] === 'ability' && argv[1] === 'remote', 'ARGUMENT_INVALID', 'Expected ability remote command');
54
+ const action = argv[2];
55
+ remoteAssert(Object.hasOwn(REMOTE_COMMANDS, action), 'ACTION_UNSUPPORTED', 'Unknown remote Ability command');
56
+ const descriptor = REMOTE_COMMANDS[action];
57
+ const options = Object.create(null);
58
+ const positional = [];
59
+ for (let i = 3; i < argv.length; i++) {
60
+ const arg = argv[i];
61
+ remoteAssert(typeof arg === 'string' && !arg.includes('\0'), 'ARGUMENT_INVALID', 'Invalid argument');
62
+ if (!arg.startsWith('-')) {
63
+ positional.push(arg);
64
+ continue;
65
+ }
66
+ const key = arg.slice(2);
67
+ remoteAssert(arg.startsWith('--') && (key === 'format' || descriptor.options.includes(key)) && !Object.hasOwn(options, key), 'ARGUMENT_INVALID', `Unknown or duplicate option: ${arg}`);
68
+ if (['refresh', 'usage', 'dry-run', 'full'].includes(key))
69
+ options[key] = 'true';
70
+ else {
71
+ remoteAssert(!!argv[i + 1] && !argv[i + 1].startsWith('--'), 'ARGUMENT_INVALID', `Missing value: ${arg}`);
72
+ options[key] = argv[++i];
73
+ }
74
+ }
75
+ remoteAssert(!options.format || options.format === 'json', 'ARGUMENT_INVALID', 'Only --format json is supported');
76
+ if (action === 'call' && options.plan) {
77
+ remoteAssert(positional.length === 0 && Object.keys(options).every(key => ['plan', 'format'].includes(key)), 'ARGUMENT_INVALID', '--plan cannot be combined with call parameters');
78
+ return { action, options };
79
+ }
80
+ const optionalPath = ['list', 'discover', 'devices'].includes(action);
81
+ remoteAssert(positional.length === descriptor.positional || optionalPath && positional.length === 2, 'ARGUMENT_INVALID', `Invalid arguments. Usage: ${remoteUsage(action)}`, { usage: remoteUsage(action) });
82
+ remoteAssert(!(positional[1] && options.path), 'ARGUMENT_INVALID', 'Specify path once, as a positional argument or --path', { usage: remoteUsage(action) });
83
+ if (action === 'result') {
84
+ remoteAssert(/^[A-Za-z0-9_.:-]{1,256}$/.test(positional[0]), 'ARGUMENT_INVALID', 'Invalid request ID');
85
+ if (options.wait)
86
+ durationSeconds(options.wait, 60);
87
+ return { action, requestId: positional[0], options };
88
+ }
89
+ const labels = positional[0].split('.');
90
+ remoteAssert(positional[0].length <= 512 && labels.length >= 3 && labels.every(label => /^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/.test(label)), 'ARGUMENT_INVALID', 'Use an exact lowercase Provider AID');
91
+ const abilityPath = positional[1] ?? options.path;
92
+ if (abilityPath)
93
+ assertAbilityPath(abilityPath);
94
+ if (options['definition-id'])
95
+ remoteAssert(/^[a-z0-9][a-z0-9_-]{0,63}$/.test(options['definition-id']), 'ARGUMENT_INVALID', 'Invalid definition ID');
96
+ if (options['device-id'])
97
+ remoteAssert(options['device-id'].length <= 256 && !/[\s\x00-\x1f\x7f]/.test(options['device-id']), 'ARGUMENT_INVALID', 'Invalid device ID');
98
+ if (options['operation-id'])
99
+ remoteAssert(/^[A-Za-z0-9_.:-]{1,256}$/.test(options['operation-id']), 'ARGUMENT_INVALID', 'Invalid operation ID');
100
+ if (options.window)
101
+ durationSeconds(options.window, 30);
102
+ for (const [key, maximum] of [['page', 1000000], ['limit', 100]]) {
103
+ if (options[key])
104
+ remoteAssert(/^[1-9][0-9]*$/.test(options[key]) && Number(options[key]) <= maximum, 'ARGUMENT_INVALID', `--${key} must be an integer from 1 to ${maximum}`, { usage: remoteUsage(action) });
105
+ }
106
+ if (options.search)
107
+ remoteAssert(options.search.length <= 256, 'ARGUMENT_INVALID', '--search must be at most 256 characters');
108
+ remoteAssert(!(options.refresh && options.discovery), 'ARGUMENT_INVALID', '--refresh cannot be combined with a fixed --discovery snapshot');
109
+ for (const key of ['timeout', 'ttl'])
110
+ if (options[key])
111
+ durationSeconds(options[key]);
112
+ remoteAssert(!(options.params && options['params-file']), 'ARGUMENT_INVALID', '--params and --params-file are mutually exclusive');
113
+ if (action === 'devices')
114
+ remoteAssert(options.discovery && abilityPath, 'ARGUMENT_INVALID', `Usage: ${remoteUsage(action)} (--path is also supported)`, { usage: remoteUsage(action) });
115
+ if (action === 'call')
116
+ remoteAssert(abilityPath !== 'protocol/discover', 'ARGUMENT_INVALID', 'Use remote discover for protocol/discover');
117
+ return { action, provider: positional[0], path: abilityPath, options };
118
+ }
119
+ export function remoteOperation(command) {
120
+ return `ability.remote.${command.action === 'call' && command.options['dry-run'] ? 'preview' : command.action}`;
121
+ }
122
+ export function remoteCommandSchema(action) {
123
+ remoteAssert(Object.hasOwn(REMOTE_COMMANDS, action), 'ACTION_UNSUPPORTED', 'Unknown remote Ability command');
124
+ const descriptor = REMOTE_COMMANDS[action];
125
+ const string = { type: 'string', minLength: 1 };
126
+ const path = { type: 'string', maxLength: 256, pattern: '^[a-z][a-z0-9_-]*(/[a-z][a-z0-9_-]*)+$' };
127
+ const fields = {
128
+ path, refresh: { type: 'boolean' }, usage: { type: 'boolean' }, full: { type: 'boolean' }, 'dry-run': { type: 'boolean' },
129
+ page: { type: 'integer', minimum: 1, maximum: 1000000 }, limit: { type: 'integer', minimum: 1, maximum: 100 }, search: { type: 'string', minLength: 1, maxLength: 256 },
130
+ discovery: string, 'definition-id': { type: 'string', pattern: '^[a-z0-9][a-z0-9_-]{0,63}$' },
131
+ 'device-id': { type: 'string', minLength: 1, maxLength: 256, pattern: '^[^\\s\\u0000-\\u001f\\u007f]+$' },
132
+ params: { type: 'object', description: 'Decoded --params JSON; exact business Schema comes from remote info.' },
133
+ 'params-file': string, 'operation-id': { type: 'string', pattern: '^[A-Za-z0-9_.:-]{1,256}$' },
134
+ window: { type: 'string', pattern: '^(?:[1-9]|[12][0-9]|30)s?$' },
135
+ wait: { type: 'string', pattern: '^(?:(?:[1-9]|[1-5][0-9]|60)s?|1m)$' },
136
+ timeout: { type: 'string', pattern: '^\\d+[sm]?$', description: '1–3600 integer seconds after unit conversion; default 60s.' },
137
+ ttl: { type: 'string', pattern: '^\\d+[sm]?$', description: '1–3600 integer seconds after unit conversion; defaults to timeout.' },
138
+ };
139
+ const properties = Object.fromEntries(descriptor.options.filter(key => key !== 'plan').map(key => [key, fields[key]]));
140
+ properties.format = { const: 'json' };
141
+ const required = [];
142
+ if (action === 'result') {
143
+ properties.requestId = { ...string, pattern: '^[A-Za-z0-9_.:-]{1,256}$' };
144
+ required.push('requestId');
145
+ }
146
+ else {
147
+ properties.provider = { type: 'string', maxLength: 512, pattern: '^[a-z0-9]([a-z0-9-]*[a-z0-9])?(\\.[a-z0-9]([a-z0-9-]*[a-z0-9])?){2,}$' };
148
+ required.push('provider');
149
+ if (descriptor.positional === 2) {
150
+ properties.path = path;
151
+ required.push('path');
152
+ }
153
+ if (action === 'devices')
154
+ required.push('path', 'discovery');
155
+ }
156
+ const normal = { type: 'object', additionalProperties: false, properties, required,
157
+ ...(action === 'call' ? { not: { required: ['params', 'params-file'] } } : {}) };
158
+ const input = action === 'call' ? { oneOf: [normal, { type: 'object', additionalProperties: false,
159
+ properties: { plan: string, format: { const: 'json' } }, required: ['plan'] }] } : normal;
160
+ return { schemaVersion: REMOTE_CLI_VERSION, operation: `remote.${action}`, command: REMOTE_COMMANDS[action],
161
+ input: { $schema: 'http://json-schema.org/draft-07/schema#', description: 'Semantic CLI arguments, not an IPC body or --file input. Boolean options represent flags; params is decoded JSON. Duration limits and device/contract constraints are also checked at execution.', ...input },
162
+ params: { type: 'object', description: 'Business params; the exact Schema is returned by remote info. --params and --params-file are mutually exclusive.' },
163
+ durations: { window: { default: 5, minimum: 1, maximum: 30 }, timeout: { default: 60, minimum: 1, maximum: 3600 }, wait: { minimum: 1, maximum: 60 } } };
164
+ }
@@ -0,0 +1,102 @@
1
+ import { isDeepStrictEqual } from 'node:util';
2
+ import { AbilityProtocolError, parseAbilityDefinition, parseAbilityRelease, isJsonObject, validateAbilityValue } from '../interop-v1.js';
3
+ import { assertAbilityPath, remoteAssert, RemoteError } from './command.js';
4
+ export function sameProviderPath(reference, provider) {
5
+ remoteAssert(typeof reference === 'string' && reference.startsWith(`${provider}:/`), 'CONTRACT_INVALID', 'References must belong to the same Provider');
6
+ const pathname = reference.slice(provider.length + 1);
7
+ remoteAssert(pathname.length <= 2048 && !/[\\\x00-\x20\x7f%?#]/.test(pathname) && pathname.slice(1).split('/').every(part => part && part !== '.' && part !== '..'), 'CONTRACT_INVALID', 'Reference must be a canonical file path');
8
+ return pathname;
9
+ }
10
+ export function boundedJson(value, maximum = 128 * 1024) {
11
+ let bytes;
12
+ try {
13
+ bytes = Buffer.byteLength(JSON.stringify(value) ?? '');
14
+ }
15
+ catch {
16
+ throw new RemoteError('CONTRACT_INVALID', 'Expected bounded JSON');
17
+ }
18
+ remoteAssert(bytes <= maximum, 'INPUT_TOO_LARGE', 'JSON exceeds the read budget');
19
+ const visit = (item, depth) => {
20
+ remoteAssert(depth <= 32, 'INPUT_TOO_DEEP', 'JSON exceeds maximum nesting depth');
21
+ if (Array.isArray(item))
22
+ item.forEach(child => visit(child, depth + 1));
23
+ else if (isJsonObject(item))
24
+ Object.values(item).forEach(child => visit(child, depth + 1));
25
+ };
26
+ visit(value, 0);
27
+ }
28
+ export function parseCapability(value, provider, devices) {
29
+ remoteAssert(isJsonObject(value), 'CONTRACT_INVALID', 'Invalid capability entry');
30
+ assertAbilityPath(String(value.path ?? ''));
31
+ remoteAssert(typeof value.definition_id === 'string' && /^[a-z0-9][a-z0-9_-]{0,63}$/.test(value.definition_id), 'CONTRACT_INVALID', 'Invalid definition_id');
32
+ remoteAssert(typeof value.release_id === 'string' && /^[a-f0-9]{64}$/.test(value.release_id), 'CONTRACT_INVALID', 'Expected a SHA-256 release_id');
33
+ sameProviderPath(value.detail_ref, provider);
34
+ if (value.usage_ref !== undefined)
35
+ sameProviderPath(value.usage_ref, provider);
36
+ const candidates = devices ?? value.devices;
37
+ remoteAssert(candidates === undefined || Array.isArray(candidates) && candidates.every(device => typeof device === 'string' && device.length > 0 && device.length <= 256 && !/[\s\x00-\x1f\x7f]/.test(device)), 'CONTRACT_INVALID', 'Invalid capability devices');
38
+ return { ...value, ...(candidates ? { devices: [...new Set(candidates)].sort() } : {}) };
39
+ }
40
+ export function parseRemoteIndex(value, provider) {
41
+ boundedJson(value);
42
+ remoteAssert(isJsonObject(value), 'CONTRACT_INVALID', 'Expected an Ability directory object');
43
+ // The directory envelope version is metadata, not the call wire profile.
44
+ // Read the stable discovery fields structurally; additive future versions
45
+ // need no hardcoded version list or Provider-specific capability table.
46
+ remoteAssert(typeof value.schema === 'string' && /^aun\.ability\.index\.v[1-9][0-9]{0,8}$/.test(value.schema), 'PROFILE_UNSUPPORTED', 'Expected an AUN Ability directory schema', { schema: value.schema });
47
+ remoteAssert(value.publisher === provider, 'CONTRACT_INVALID', 'Directory publisher does not match the requested AID');
48
+ remoteAssert(Array.isArray(value.capabilities), 'CONTRACT_INVALID', 'Directory capabilities must be an array');
49
+ if (value.catalog_revision !== undefined)
50
+ remoteAssert(Number.isSafeInteger(value.catalog_revision) && value.catalog_revision >= 0, 'CONTRACT_INVALID', 'Invalid directory catalog_revision');
51
+ if (value.compatibility_schema !== undefined)
52
+ remoteAssert(typeof value.compatibility_schema === 'string' && value.compatibility_schema.length > 0 && value.compatibility_schema.length <= 128, 'CONTRACT_INVALID', 'Invalid directory compatibility_schema');
53
+ if (value.skill_ref !== undefined)
54
+ sameProviderPath(value.skill_ref, provider);
55
+ return { ...value, schema: value.schema, publisher: provider, capabilities: value.capabilities.map(row => parseCapability(row, provider)),
56
+ ...(value.skill_ref ? { skill_ref: String(value.skill_ref) } : {}) };
57
+ }
58
+ export function parseRemoteContract(raw, row, otherRows = []) {
59
+ boundedJson(raw);
60
+ let contract;
61
+ try {
62
+ const expected = { path: row.path, definitionId: row.definition_id };
63
+ if (isJsonObject(raw) && (Object.hasOwn(raw, 'definition') || typeof raw.schema === 'string' && raw.schema.startsWith('aun.ability.release.'))) {
64
+ const release = parseAbilityRelease(raw, expected);
65
+ remoteAssert(release.release_id === row.release_id && (row.plugin_version === undefined || release.plugin_version === row.plugin_version), 'CONTRACT_CHANGED', 'Referenced release does not match the directory; refresh discovery');
66
+ contract = { definition: release.definition, usage: release.usage,
67
+ release: { schema: release.schema, release_id: release.release_id, plugin_version: release.plugin_version } };
68
+ }
69
+ else
70
+ contract = { definition: parseAbilityDefinition(raw, expected) };
71
+ }
72
+ catch (error) {
73
+ if (error instanceof RemoteError)
74
+ throw error;
75
+ const code = error.code;
76
+ throw new RemoteError(code === 'contract_changed' ? 'CONTRACT_CHANGED' : 'PROFILE_UNSUPPORTED', error instanceof Error ? error.message : 'Unsupported contract');
77
+ }
78
+ const { definition } = contract;
79
+ for (const candidate of [row, ...otherRows]) {
80
+ remoteAssert(candidate.path === definition.path && candidate.definition_id === definition.definition_id, 'CONTRACT_CHANGED', 'Discovery and definition disagree');
81
+ if (contract.release)
82
+ remoteAssert(candidate.release_id === contract.release.release_id
83
+ && (candidate.plugin_version === undefined || candidate.plugin_version === contract.release.plugin_version), 'CONTRACT_CHANGED', 'Discovery and release disagree');
84
+ for (const key of ['effects', 'auth_required', 'require_confirm', 'idempotency', 'allowed_modes', 'aggregation', 'dedupe_retention_seconds']) {
85
+ if (Object.hasOwn(candidate, key))
86
+ remoteAssert(isDeepStrictEqual(candidate[key], definition[key]), 'CONTRACT_CHANGED', `Discovery and definition disagree on ${key}`);
87
+ }
88
+ }
89
+ return contract;
90
+ }
91
+ export function verifyDefinition(raw, row, otherRows = []) {
92
+ return parseRemoteContract(raw, row, otherRows).definition;
93
+ }
94
+ export function validateValue(schema, value, code) {
95
+ boundedJson(value, 1024 * 1024);
96
+ try {
97
+ validateAbilityValue(schema, value);
98
+ }
99
+ catch (error) {
100
+ throw new RemoteError(code, error instanceof Error ? error.message.replace(/^example\b/, 'Value') : 'Value does not match Schema', error instanceof AbilityProtocolError && error.path ? { field: error.path } : undefined);
101
+ }
102
+ }
@@ -0,0 +1,158 @@
1
+ import { TextDecoder } from 'node:util';
2
+ import path from 'node:path';
3
+ import { AbilityCallerService, remoteFailure } from './service.js';
4
+ import { parseRemoteCommand, remoteOperation, remoteAssert, RemoteError } from './command.js';
5
+ import { boundedJson, sameProviderPath } from './contract.js';
6
+ import { isJsonObject } from '../interop-v1.js';
7
+ import { createRemoteAbilityAuthorizer } from './authorization.js';
8
+ import { sessionTopicThreadId } from '../../core/thread/topic-id.js';
9
+ import { readTriggerLocalFile } from '../../trigger/local-files.js';
10
+ import { readPersonalFsBytesWithinBudget } from '../../aun/group/fs-download.js';
11
+ import { getAunRequestRegistry } from '../../core/message/aun-request-registry.js';
12
+ export function createRemoteAbilityExecutor(root, deps, channels) {
13
+ const service = new AbilityCallerService(path.join(root, 'caller'));
14
+ const authorize = createRemoteAbilityAuthorizer(deps);
15
+ return {
16
+ close: () => service.close(),
17
+ execute: async (input) => {
18
+ let stage = 'arguments';
19
+ let mayHaveSent = false;
20
+ try {
21
+ remoteAssert(input.type === 'ability.remote.op' && input.sessionId && input.delegationToken && input.delegationCommandHash, 'DELEGATION_REQUIRED', 'Remote Ability requires an approved AUN managed command');
22
+ const command = parseRemoteCommand(input.argv);
23
+ // Never accept the in-process delegationGrant/targetAid continuation
24
+ // fields from an IPC body.
25
+ const credentials = { sessionId: String(input.sessionId), delegationToken: String(input.delegationToken), delegationCommandHash: String(input.delegationCommandHash) };
26
+ stage = 'authorization';
27
+ const permitted = await authorize(credentials, remoteOperation(command));
28
+ remoteAssert(permitted.ok, permitted.ok ? '' : permitted.code, permitted.ok ? '' : permitted.error);
29
+ const grant = permitted.grant;
30
+ stage = 'session';
31
+ remoteAssert(grant.channelType === 'aun', 'AUN_SESSION_REQUIRED', 'Remote Ability requires an AUN managed session');
32
+ const session = await deps.sessionManager.getSessionById(grant.sessionId);
33
+ remoteAssert(session?.selfAID === grant.selfAid, 'INVALID_DELEGATION', 'Caller does not match the active session');
34
+ const context = { callerAid: grant.selfAid, sessionId: grant.sessionId, peerKey: grant.peerKey, threadId: sessionTopicThreadId(session) };
35
+ remoteAssert(deps.agentDelegationRegistry.isCurrentTaskGrant(grant), 'INVALID_DELEGATION', 'Origin task was replaced or revoked');
36
+ // Report local call policy alongside inspection results, before any
37
+ // remote reads. This does not authorize a send or consume approval.
38
+ const callPermission = ['list', 'info', 'devices', 'discover'].includes(command.action)
39
+ ? await authorize({ ...credentials, delegationGrant: grant }, 'ability.remote.call') : undefined;
40
+ // Read the approved input once, in the daemon, with the same path/link
41
+ // policy as ecmsg. Subsequent awaits use this immutable JSON snapshot.
42
+ let params = {};
43
+ stage = 'input';
44
+ const raw = command.options['params-file']
45
+ ? new TextDecoder('utf-8', { fatal: true }).decode(readTriggerLocalFile(command.options['params-file'], {
46
+ selfAid: grant.selfAid, projectPath: session.projectPath, sessionRuntimeDir: grant.sessionRuntimeDir, cwd: session.projectPath,
47
+ })) : command.options.params;
48
+ if (raw !== undefined) {
49
+ remoteAssert(Buffer.byteLength(raw) <= 1024 * 1024, 'INPUT_TOO_LARGE', 'Params exceed 1 MiB');
50
+ try {
51
+ params = JSON.parse(raw);
52
+ }
53
+ catch {
54
+ throw new RemoteError('PARAMS_INVALID', 'Params must be valid JSON');
55
+ }
56
+ remoteAssert(isJsonObject(params), 'PARAMS_INVALID', 'Params must be a JSON object');
57
+ boundedJson(params, 1024 * 1024);
58
+ }
59
+ const fresh = async () => {
60
+ remoteAssert(deps.agentDelegationRegistry.isCurrentTaskGrant(grant), 'INVALID_DELEGATION', 'Origin task was replaced or revoked');
61
+ const permission = await authorize({ ...credentials, delegationGrant: grant }, remoteOperation(command));
62
+ remoteAssert(permission.ok, permission.ok ? '' : permission.code, permission.ok ? '' : permission.error);
63
+ remoteAssert(deps.agentDelegationRegistry.isCurrentTaskGrant(grant), 'INVALID_DELEGATION', 'Origin task was replaced or revoked');
64
+ };
65
+ const internal = async (fn) => {
66
+ await fresh();
67
+ const issued = deps.agentDelegationRegistry.issueInternal(grant);
68
+ try {
69
+ return await fn(issued.token);
70
+ }
71
+ finally {
72
+ issued.release();
73
+ }
74
+ };
75
+ let sends = 0;
76
+ const transport = {
77
+ authorize: async () => {
78
+ stage = 'authorization';
79
+ await fresh();
80
+ // Provider protocol access is independent of social chat roles.
81
+ // The same active task/identity is checked again at send/query.
82
+ },
83
+ read: async (provider, pathname) => {
84
+ await fresh();
85
+ stage = 'read';
86
+ sameProviderPath(`${provider}:${pathname}`, provider);
87
+ const client = channels().find(channel => channel.getAid() === grant.selfAid)?.getClient();
88
+ remoteAssert(client, 'AUN_NOT_CONNECTED', 'Caller AID has no connected AUN channel');
89
+ try {
90
+ const bytes = await readPersonalFsBytesWithinBudget(client, pathname, 128 * 1024, { owner: provider });
91
+ const text = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
92
+ // Follow the published ref as-is: JSON contract objects need
93
+ // not use a .json suffix. Usage may also be plain Markdown.
94
+ let value;
95
+ try {
96
+ value = JSON.parse(text);
97
+ }
98
+ catch (error) {
99
+ if (pathname.endsWith('.json'))
100
+ throw error;
101
+ return text;
102
+ }
103
+ boundedJson(value);
104
+ return value;
105
+ }
106
+ catch (error) {
107
+ const backend = error;
108
+ throw new RemoteError(typeof backend.code === 'string' ? backend.code : 'REMOTE_READ_FAILED', backend.message ?? 'Remote file read failed');
109
+ }
110
+ },
111
+ send: async (provider, payload, deviceId, timeoutMs) => {
112
+ remoteAssert(sends++ === 0, 'SEND_LIMIT_EXCEEDED', 'One approved remote command permits at most one Ability message');
113
+ // Use the daemon-only protocol entry of the shared sender. Keep
114
+ // the approved remote hash and current task grant; never synthesize
115
+ // a chat command, an alternate identity or a public bypass flag.
116
+ return internal(token => {
117
+ stage = 'send';
118
+ mayHaveSent = true;
119
+ return deps.ipcServer.sendAbilityRequest({
120
+ aid: grant.selfAid, to: provider, payload, deviceId, timeoutMs, argv: input.argv,
121
+ originSessionId: grant.sessionId, originMessageId: grant.messageId,
122
+ delegationToken: token, delegationCommandHash: input.delegationCommandHash,
123
+ }, grant);
124
+ });
125
+ },
126
+ get: async (requestId, waitMs) => {
127
+ stage = 'result';
128
+ const get = () => internal(async (token) => {
129
+ const result = await deps.ipcServer.getAbilityRequest({ aid: grant.selfAid, requestId, sessionId: grant.sessionId,
130
+ delegationToken: token, delegationCommandHash: input.delegationCommandHash }, grant);
131
+ if (!result.ok && result.code === 'REQUEST_NOT_FOUND')
132
+ return undefined;
133
+ remoteAssert(result.ok, String(result.code ?? 'REQUEST_QUERY_FAILED'), result.error ?? 'Cannot query original request');
134
+ return result.request;
135
+ });
136
+ const record = await get();
137
+ if (record && waitMs && !['completed', 'failed'].includes(record.state)) {
138
+ await getAunRequestRegistry().observe(grant.selfAid, requestId, waitMs);
139
+ return get();
140
+ }
141
+ return record;
142
+ },
143
+ };
144
+ const result = await service.execute(command, context, transport, params);
145
+ if (callPermission && result.data)
146
+ result.data.call_permission = callPermission.ok
147
+ ? { allowed: true, scope: 'current-task', provider_authorization: 'checked_by_provider' }
148
+ : { allowed: false, scope: 'current-task', code: callPermission.code, reason: callPermission.error, next_action: 'stop_before_call' };
149
+ return result;
150
+ }
151
+ catch (error) {
152
+ const failure = remoteFailure(error);
153
+ return { ...failure, stage: failure.stage ?? stage, sent: mayHaveSent ? null : false,
154
+ ...(stage === 'authorization' ? { next_action: { action: 'stop', resend_allowed: false } } : {}) };
155
+ }
156
+ },
157
+ };
158
+ }