evolcore 0.0.43-test.2 → 0.0.43-test.4

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 (173) hide show
  1. package/CHANGELOG.md +44 -1
  2. package/bin/ecmsg.js +229 -0
  3. package/bin/install-codex-managed-hooks.mjs +130 -8
  4. package/dist/ability/application-service.js +37 -0
  5. package/dist/ability/resources.js +28 -0
  6. package/dist/ability/runtime.js +6 -1
  7. package/dist/agents/claude-runner.js +7 -5
  8. package/dist/agents/codex/app-server-client.js +0 -12
  9. package/dist/agents/codex-runner.js +0 -37
  10. package/dist/agents/ecagent-runner.js +138 -36
  11. package/dist/aun/aid/agentmd.js +52 -13
  12. package/dist/aun/menu/client.js +8 -7
  13. package/dist/aun/menu/index.js +1 -1
  14. package/dist/aun/menu/transport.js +8 -5
  15. package/dist/aun/msg/p2p.js +4 -2
  16. package/dist/aun/service-proxy.js +3 -0
  17. package/dist/channels/aun.js +105 -53
  18. package/dist/channels/daemon.js +14 -2
  19. package/dist/cli/agent-command.js +5 -0
  20. package/dist/cli/agent-create.js +31 -11
  21. package/dist/cli/agent.js +9 -3
  22. package/dist/cli/aun-commands.js +19 -21
  23. package/dist/cli/daemon-commands.js +30 -18
  24. package/dist/cli/directory.js +98 -56
  25. package/dist/cli/getmeta-command.js +2 -1
  26. package/dist/cli/index.js +1 -1
  27. package/dist/cli/init.js +13 -5
  28. package/dist/cli/peer.js +2 -1
  29. package/dist/cli/task-context.js +3 -1
  30. package/dist/cli/trigger-command.js +20 -14
  31. package/dist/config/access-policy.js +0 -1
  32. package/dist/config/boot-log.js +12 -2
  33. package/dist/config/builtin-role-templates.js +2 -2
  34. package/dist/config/builtin-roles.js +2 -1
  35. package/dist/config/config-field-policy.js +7 -0
  36. package/dist/config/config-manager.js +30 -10
  37. package/dist/config/peer-role-resolver.js +23 -1
  38. package/dist/config/role-schema.js +25 -1
  39. package/dist/config/role-service.js +9 -4
  40. package/dist/config/role-store.js +30 -8
  41. package/dist/config/schema-migration.js +121 -0
  42. package/dist/core/agent-application-service.js +11 -0
  43. package/dist/core/agent-ipc-registration.js +2 -0
  44. package/dist/core/agent-runtime.js +41 -9
  45. package/dist/core/auth/auth-gateway.js +14 -4
  46. package/dist/core/auth/operation-authorizer.js +19 -1
  47. package/dist/core/auth/operation-catalog.js +12 -2
  48. package/dist/core/baseagent-loader.js +11 -3
  49. package/dist/core/bootstrap-service.js +8 -0
  50. package/dist/core/channel-loader.js +61 -23
  51. package/dist/core/channel-runtime.js +5 -0
  52. package/dist/core/command/agent-control.js +5 -2
  53. package/dist/core/command/agentmd-menu-request.js +50 -0
  54. package/dist/core/command/agentmd-menu.js +156 -0
  55. package/dist/core/command/chatmode-config.js +46 -0
  56. package/dist/core/command/command-handler.js +44 -17
  57. package/dist/core/command/daemon-diagnostics.js +2 -1
  58. package/dist/core/command/menu-catalog.js +14 -1
  59. package/dist/core/command/menu-handler.js +74 -24
  60. package/dist/core/command/menu-protocol.js +8 -0
  61. package/dist/core/command/role-menu.js +23 -9
  62. package/dist/core/command/slash-handler.js +52 -47
  63. package/dist/core/daemon-lifecycle.js +43 -17
  64. package/dist/core/event-catalog.js +19 -0
  65. package/dist/core/evolagent-registry.js +3 -0
  66. package/dist/core/evolagent.js +5 -4
  67. package/dist/core/ipc-registration.js +6 -0
  68. package/dist/core/lifecycle-notice.js +185 -0
  69. package/dist/core/message/aun-ipc-sender.js +30 -24
  70. package/dist/core/message/contact-admission.js +1 -19
  71. package/dist/core/message/im-renderer.js +81 -40
  72. package/dist/core/message/message-admission.js +21 -62
  73. package/dist/core/message/message-bridge.js +18 -5
  74. package/dist/core/message/message-utils.js +9 -0
  75. package/dist/core/message/peer-mode.js +16 -8
  76. package/dist/core/message/response-engine.js +67 -47
  77. package/dist/core/model/model-capabilities.js +37 -0
  78. package/dist/core/model/model-catalog.js +6 -2
  79. package/dist/core/ownership/owner-resolver.js +74 -36
  80. package/dist/core/permission/ec-command-parser.js +62 -13
  81. package/dist/core/plugin-lifecycle.js +6 -2
  82. package/dist/core/relation/pa-team.js +132 -0
  83. package/dist/core/role/runtime-policy.js +4 -3
  84. package/dist/core/thread/thread-service.js +6 -4
  85. package/dist/directory/owner-directory-admission.js +0 -3
  86. package/dist/directory/owner-directory-cache.js +201 -17
  87. package/dist/directory/owner-directory-markdown.js +44 -21
  88. package/dist/directory/owner-directory-policy.js +1 -1
  89. package/dist/directory/owner-directory-query-operation.js +218 -98
  90. package/dist/directory/owner-directory-request-operation.js +76 -0
  91. package/dist/directory/owner-directory-scope.js +35 -4
  92. package/dist/directory/owner-directory-search.js +76 -23
  93. package/dist/directory/owner-directory-store.js +5 -38
  94. package/dist/directory/owner-directory-text.js +60 -0
  95. package/dist/eck/kit-renderer.js +6 -3
  96. package/dist/eck/message-renderer.js +2 -5
  97. package/dist/ecweb/message-context-service.js +4 -0
  98. package/dist/ecweb/runtime/lifecycle.js +29 -5
  99. package/dist/ecweb/runtime/supervisor.js +83 -27
  100. package/dist/index.js +209 -38
  101. package/dist/paths.js +4 -2
  102. package/dist/product.js +1 -0
  103. package/dist/proxy/service-supervisor.js +377 -141
  104. package/dist/response-system/engines/v1/index.js +2 -4
  105. package/dist/response-system/modes/single-session/index.js +1 -1
  106. package/dist/trigger/audit.js +3 -2
  107. package/dist/trigger/authorization.js +2 -3
  108. package/dist/trigger/history.js +4 -3
  109. package/dist/trigger/ipc-service.js +24 -19
  110. package/dist/trigger/manager.js +3 -5
  111. package/dist/trigger/parser.js +4 -21
  112. package/dist/trigger/patch.js +3 -15
  113. package/dist/trigger/scheduler.js +53 -13
  114. package/dist/trigger/validation.js +0 -13
  115. package/dist/utils/error-utils.js +15 -5
  116. package/dist/utils/macos-autostart.js +31 -0
  117. package/dist/utils/model-prices.jsonl +15 -8
  118. package/dist/utils/process-introspect.js +21 -1
  119. package/dist/utils/startup-trace.js +7 -1
  120. package/dist/utils/windows-autostart.js +1 -0
  121. package/ecagent/README.md +18 -0
  122. package/ecagent/dist/harness/agent-harness.d.ts +2 -0
  123. package/ecagent/dist/harness/agent-harness.js +24 -8
  124. package/ecagent/dist/harness/compaction/branch-summarization.js +1 -1
  125. package/ecagent/dist/harness/compaction/compaction.js +7 -4
  126. package/ecagent/dist/harness/types.d.ts +1 -0
  127. package/kits/docs/channels/aun.md +1 -1
  128. package/kits/docs/context-assembly.md +1 -1
  129. package/kits/docs/evolcore/INDEX.md +5 -2
  130. package/kits/docs/evolcore/directory.md +125 -35
  131. package/kits/docs/evolcore/ecweb-lifecycle.md +26 -0
  132. package/kits/docs/evolcore/file-navigation.md +279 -0
  133. package/kits/docs/evolcore/menu-protocol.md +1 -0
  134. package/kits/docs/evolcore/model.md +5 -3
  135. package/kits/docs/evolcore/msg.md +1 -0
  136. package/kits/docs/evolcore/peer.md +2 -1
  137. package/kits/docs/evolcore/response.md +4 -2
  138. package/kits/docs/evolcore/task.md +2 -0
  139. package/kits/docs/evolcore/thread-chain.md +1 -1
  140. package/kits/docs/evolcore/tool-authorization.md +4 -1
  141. package/kits/docs/evolcore/trigger.md +10 -7
  142. package/kits/docs/identity/ROLE_DETAIL.md +2 -0
  143. package/kits/eck_manifest.json +6 -23
  144. package/kits/eck_manifest.memory.json +26 -1
  145. package/kits/rules/01-overview.md +42 -44
  146. package/kits/rules/02-navigation.md +44 -53
  147. package/kits/rules/03-identity.md +21 -25
  148. package/kits/rules/04-relation.md +23 -33
  149. package/kits/rules/05-venue.md +24 -25
  150. package/kits/schemas/_meta.json +10 -10
  151. package/kits/schemas/agent-config.schema.19.json +10 -6
  152. package/kits/schemas/relation-config.schema.12.json +2 -2
  153. package/kits/schemas/role-config.schema.2.json +5 -5
  154. package/kits/schemas/role-registry.schema.1.json +3 -2
  155. package/kits/skills/ec-service-proxy/SKILL.md +10 -0
  156. package/kits/skills/ec-trigger/SKILL.md +1 -1
  157. package/kits/templates/soul/00-GUIDE.md +20 -42
  158. package/kits/templates/system-fragments/channel.md +2 -2
  159. package/kits/templates/system-fragments/commands.md +1 -1
  160. package/kits/templates/system-fragments/directory-contacts.md +1 -1
  161. package/kits/templates/system-fragments/identity.md +0 -1
  162. package/kits/templates/system-fragments/personal-assistant.md +2 -17
  163. package/kits/templates/system-fragments/reply.md +7 -0
  164. package/kits/templates/system-fragments/session.md +6 -2
  165. package/package.json +18 -13
  166. package/dist/eck/paactive-context.js +0 -45
  167. package/dist/response-system/engines/v1/paactive-flow.js +0 -18
  168. package/kits/eck_manifest.paactive.json +0 -528
  169. package/kits/eck_message_manifest.paactive.json +0 -233
  170. package/kits/templates/message-fragments/paactive/item.md +0 -3
  171. package/kits/templates/system-fragments/paactive/channel.md +0 -25
  172. package/kits/templates/system-fragments/paactive/reply.md +0 -25
  173. package/kits/templates/system-fragments/paactive/session.md +0 -32
package/CHANGELOG.md CHANGED
@@ -5,6 +5,42 @@
5
5
 
6
6
  ## Unreleased
7
7
 
8
+ ## 0.0.43-test.4 (2026-11-06)
9
+
10
+ ### 模型、会话与自动化
11
+
12
+ - 统一 Claude Code 与 ecagent 的模型能力解析,按当前 Provider 的上下文和输出容量计算自动压缩阈值,并更新模型参数与价格数据。
13
+ - ecagent 支持只读访问当前 Agent 的入站附件,通过真实路径校验阻止目录逃逸;非法工具参数转为可恢复错误,摘要与压缩请求标注用途,摘要失败不再自动重试。
14
+ - Trigger 跟随所属 Agent 当前基座,迁移旧的独立覆盖字段;切换基座后使用匹配的新会话,阻止恢复基座不匹配的任务;取消操作按活动 runId 中止执行并记录中断状态。
15
+ - proactive 输出遵循活动显示配置,群聊默认静默并允许显式覆盖;仅对配置了静默哨兵的 Trigger 处理静默结果。
16
+
17
+ ### 身份、联系人与配置
18
+
19
+ - Agent 显示名跟随签名名片变化刷新,移除一次性自我介绍注入;新增 bootstrapWelcome 开关,可跳过首次欢迎消息。
20
+ - 名录查询统一为 list/info,移除 find/show 别名;修复名录拉取,区分指定联系人名单与全部联系人授权,防止开放策略扩大准入范围。
21
+ - 将同 Owner 默认角色资格扩展至验签及归属核验通过的内部 Agent,敏感操作前重新核验;拒绝将 Agent 自身声明为其 Owner。
22
+ - Agent、Relation、Role Schema 分别收敛为 v19、v12、v2;兼容的 Agent v20 与 Relation v13 配置启动时备份迁移,自定义 Role v3 需人工调整至 v2;统一 paactive 配置写入并核验私聊关系。
23
+ - 创建 Agent 时支持显式指定和校验 Provider,模型目录请求补充当前 Agent 身份。
24
+
25
+ ### 消息、权限与能力
26
+
27
+ - 新增 ecmsg 轻量消息入口,复用 ec msg 的委托身份和命令授权;AUN Menu 请求与响应改走独立 control 消息流。
28
+ - 允许经 daemon 核验的可信 fullaccess 托管任务读取原始日志,完善 PowerShell 环境变量赋值与嵌套引号解析;私聊可按既有权限执行群级操作。
29
+ - 停止向 Owner 观察通道转发 thought.put 返回结果;运行状态与会话创建提示统一为结构化系统通知。
30
+ - 能力插件资源代理增加批量存储操作和工作区批量读取,逐项返回结果并保留资源授权校验。
31
+
32
+ ### 服务、启动与安装
33
+
34
+ - 并行初始化 Agent Runner,记录逐 Agent 耗时并支持停机取消;按 Agent 就绪状态门控入站消息、渠道连接和管理操作。
35
+ - 并行关闭 EC Web 与 AUN 连接,合并重复停止操作并阻止停机期间重启;完善启动关联、耗时配对和 daemon 启动时间展示。
36
+ - 串行执行同名受管服务生命周期操作,强化实例身份核验;旧进程停止失败时阻止替代启动,端口冲突解除后自动恢复,并修复首次就绪前退出后的重启调度。
37
+ - 完善 Codex 托管 Hook 的归属校验与安全卸载,修正 TOML 配置比较;外部自启动配置冲突改为初始化告警。
38
+ - EC Web 的 PA 看板入口改为独立服务页面,仅对同源本机请求签发看板令牌;看板服务需单独部署。
39
+
40
+ ### 依赖与兼容性
41
+
42
+ - AUN SDK 依赖更新为 ^0.5.32,并更新相关依赖;Node.js 要求保持 >=22.16.0,与 ec-web@0.0.43-test.4 配套使用。
43
+
8
44
  ## 0.0.43 (2026-11-04)
9
45
 
10
46
  ### 身份、名录与联系人准入
@@ -14,14 +50,20 @@
14
50
  - 修复创建 Agent 时指定人格文本与 Soul 占位模板冲突的问题,保留对已有设定的覆盖保护。
15
51
  - 新增 App 联系人准入协议,按当前 Owner 共识和名录范围处理陌生消息、临时授权和黑名单;未准入的出站联系仅向本端 Owner 申请。
16
52
  - 完善 Owner 名录授权范围、缓存同步、查询、搜索和未知字段保留;名录备注支持直接编辑文件。
53
+ - 新增同 Owner PA 团队默认角色,缺省为 `member`;按双方签名名片和当前 Ownership 核验资格,变化后使授权缓存失效,并在执行前重新核验。
54
+ - 名录查询统一为 `ec directory list/info`,保留 `find/show` 别名;支持分页、结构化错误和加好友申请,Agent 条目增加双边归属核验。
55
+ - 新增加密 AUN 名片编辑与发布 Menu,仅允许当前协议 Owner 操作,保护身份、Ownership 字段及远端版本。
17
56
 
18
57
  ### 对话、任务与自动化
19
58
 
20
- - 新增 `paactive` 模式,用于已激活 AUN Agent 与人类 Owner/Admin 的私聊主会话,通过独立上下文和可靠 activity 投递展示助理活动。
59
+ - 新增 `paactive` 模式,用于已激活 AUN Agent 与人类 Owner 的私聊主会话及话题,复用 interactive 执行流和共享 ECK 上下文,通过可靠 activity 投递展示助理活动。
60
+ - 群聊固定使用 `proactive`;兼容读取旧 `interactive` 配置,新写入按当前模式约束校验。PA activity 串行重试并保留待发文本,避免重复记录或丢失。
21
61
  - AUN 消息增加受保护模型信息和模型切换通知;Slash 正常回执改用 notice,并新增 Slash 指令清单 Menu 查询。
22
62
  - Trigger 成功结果以 `[[NOOP]]` 开头时静默处理,支持前导空白和流式拆分,同时保留原始执行记录。
23
63
  - 完善 Fullaccess 提示范围、工具授权审计和只读命令解析;取消任务后停止后续模型请求,记忆整理失败时停止后续步骤并回报失败。
24
64
  - 将网关请求超时、输入未消费和空成功协议故障纳入可恢复错误处理。
65
+ - 修正 ecagent 压缩后的上下文用量,按末次模型调用报告当前占用;补齐百万上下文模型窗口,明确超限错误不再进入通用或传输重试。
66
+ - 手动压缩增加结构化进度通知,会话状态明确 Fullaccess 作用域和空闲触发状态;话题改名确认会话更新成功后才保存索引。
25
67
 
26
68
  ### 渠道、安装与管理
27
69
 
@@ -29,6 +71,7 @@
29
71
  - 修复 EC Web 脱管进程恢复、Provider 操作入口及受管服务运行信息校验;npm 元数据查询优先联网刷新。
30
72
  - 完善 Windows 安装器中文编码、Node.js 安装后的 PATH 刷新和初始化检查,并明确计划任务权限不足时的自启动回退提示。
31
73
  - 裸跑 `ec` 改为显示帮助;移除 `ec handoff` CLI 入口,跨话题协作继续使用话题与消息命令。
74
+ - 新增面向已确认 Owner 的 Agent 上下线通知;主动 AUN 发送默认明文,显式加密或渠道配置仍优先生效。
32
75
 
33
76
  ### AUN SDK
34
77
 
package/bin/ecmsg.js ADDED
@@ -0,0 +1,229 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * `ecmsg` —— `ec msg` 的轻量等价入口。
4
+ *
5
+ * 动机:`ec msg send` 单次约 1.4s,其中 95% 是 CLI 模块图加载
6
+ * (agent-delegation 单模块 382ms、task-context 429ms、aun-commands 更重)。
7
+ * daemon 侧本来就自己解析 argv(aun-ipc-sender 调 resolveManagedSendArgv),
8
+ * CLI 只负责透传,所以这条命令不需要那套模块。
9
+ *
10
+ * 语义:`ecmsg <args...>` ≡ `ec msg <args...>`。例如
11
+ * ecmsg send <from> <to> --content 'hi' ≡ ec msg send <from> <to> --content 'hi'
12
+ *
13
+ * 为什么必须走 ec-command-parser 归一而不是自己拼字符串:委托审批按「规范化
14
+ * argv 的 sha256」arm(codex-runner 的 armApprovedDelegationCommand)。`ecmsg`
15
+ * 必须归一到 `['ec','msg',...]`,才能与策略层 arm 的哈希对上;否则 daemon 返回
16
+ * INVALID_DELEGATION,且会绕过复合命令拦截与会话身份绑定,成为冒充发送的后门。
17
+ *
18
+ * 性能约束:本文件只允许 import node 内建模块 + ec-command-parser(纯函数,
19
+ * 实测 8ms)。**不要** import agent-delegation.js(382ms)——哈希算法在下面
20
+ * 内联实现,与 hashDelegatedCommandArgv 逐字节一致,改动时两处必须同步。
21
+ */
22
+ import net from 'node:net';
23
+ import fs from 'node:fs';
24
+ import path from 'node:path';
25
+ import crypto from 'node:crypto';
26
+ import { fileURLToPath, pathToFileURL } from 'node:url';
27
+
28
+ const here = path.dirname(fileURLToPath(import.meta.url));
29
+ const repoRoot = path.resolve(here, '..');
30
+
31
+ const ENV_DELEGATION_TOKEN = 'EVOLCORE_DELEGATION_TOKEN';
32
+ const ENV_CODEX_SESSION_TOKEN = 'EVOLCORE_CODEX_SESSION_TOKEN';
33
+ const ENV_TASK_RUNTIME_CONTEXT = 'EVOLCORE_TASK_RUNTIME_CONTEXT';
34
+ const ENV_SESSION_ID = 'EVOLCORE_SESSION_ID';
35
+ const ENV_EXECUTION_SPEC = 'EVOLCORE_DELEGATED_EXECUTION_SPEC';
36
+ /** 与 src/product.ts 的 MAIN_CLI_BIN 一致。 */
37
+ const MAIN_CLI_BIN = 'ec';
38
+
39
+ function fail(message) {
40
+ process.stderr.write(`❌ ${message}\n`);
41
+ process.exit(1);
42
+ }
43
+
44
+ const HELP = [
45
+ '用法: ecmsg <msg 子命令及参数>',
46
+ ' ecmsg 等价于 ec msg,参数原样透传:',
47
+ '',
48
+ " ecmsg send <from> <to> --content '正文'",
49
+ ' ecmsg send <from> <to> --file <path>',
50
+ ' ecmsg history <from> <to> --limit 20',
51
+ '',
52
+ '非托管环境请直接使用 ec msg。',
53
+ '',
54
+ ].join('\n');
55
+
56
+ /** 与 hashDelegatedCommandSpec 一致:v1 + 直接序列化原对象(顺序敏感,不可重排)。 */
57
+ function hashExecutionSpec(spec) {
58
+ if (!spec || typeof spec !== 'object') return undefined;
59
+ const values = [
60
+ ...(Array.isArray(spec.argv) ? spec.argv : []),
61
+ spec.dialect,
62
+ spec.wrapper,
63
+ spec.cwd,
64
+ spec.outputPath,
65
+ ...(spec.filterChain ?? []).flat(),
66
+ ...(spec.suffixArgv ?? []),
67
+ ];
68
+ if (spec.version !== 1
69
+ || [spec.mergeStderr, spec.discardStdout, spec.discardStderr]
70
+ .some(value => value !== undefined && typeof value !== 'boolean')
71
+ || values.some(value => value !== undefined && (typeof value !== 'string' || value.includes('\0')))) {
72
+ return undefined;
73
+ }
74
+ return crypto.createHash('sha256')
75
+ .update('evolcore-agent-delegation-spec-v1\0')
76
+ .update(JSON.stringify(spec))
77
+ .digest('hex');
78
+ }
79
+
80
+ /**
81
+ * 与 src/core/auth/agent-delegation.ts 的 hashDelegatedCommandArgv 逐字节一致。
82
+ * v1 无执行规格;v2 绑定执行规格(argv 必须与之相同)。
83
+ */
84
+ function hashDelegatedCommandArgv(argv, executionSpec) {
85
+ if (!Array.isArray(argv) || argv.length === 0) return undefined;
86
+ if (argv.some(value => typeof value !== 'string' || value.includes('\0'))) return undefined;
87
+ if (executionSpec !== undefined) {
88
+ if (hashExecutionSpec(executionSpec) === undefined) return undefined;
89
+ if (JSON.stringify(executionSpec.argv) !== JSON.stringify(argv)) return undefined;
90
+ }
91
+ return crypto.createHash('sha256')
92
+ .update(executionSpec ? 'evolcore-agent-delegation-command-v2\0' : 'evolcore-agent-delegation-command-v1\0')
93
+ .update(JSON.stringify(executionSpec ? { argv, executionSpec } : argv))
94
+ .digest('hex');
95
+ }
96
+
97
+ /** 读执行规格:仅在 argv 完全匹配当前命令时才生效(同 readDelegatedExecutionSpec)。 */
98
+ function readDelegatedExecutionSpec(normalizedArgv, env) {
99
+ const raw = env[ENV_EXECUTION_SPEC]?.trim();
100
+ if (!raw || raw.length > 16 * 1024) return undefined;
101
+ let spec;
102
+ try { spec = JSON.parse(raw); } catch { return undefined; }
103
+ if (!spec || typeof spec !== 'object' || Array.isArray(spec)) return undefined;
104
+ if (spec.version !== 1) return undefined;
105
+ if (!['posix', 'powershell', 'cmd'].includes(String(spec.dialect))) return undefined;
106
+ if (!['bounded-output', 'cd-prefixed'].includes(String(spec.wrapper))) return undefined;
107
+ if (!Array.isArray(spec.argv) || spec.argv[0] !== MAIN_CLI_BIN) return undefined;
108
+ if (JSON.stringify(spec.argv) !== JSON.stringify(normalizedArgv)) return undefined;
109
+ return spec;
110
+ }
111
+
112
+ /**
113
+ * 复用 dist/paths.js 的端点解析(实测 7ms)。
114
+ *
115
+ * 不要在这里手写管道名:root 的规范化规则(大小写、尾分隔符、canonical 变体)
116
+ * 一旦漂移,就会连不上 daemon。用官方实现是唯一可靠做法。
117
+ */
118
+ async function resolveSocketPath() {
119
+ const pathsUrl = pathToFileURL(path.join(repoRoot, 'dist', 'paths.js')).href;
120
+ const { resolvePaths } = await import(pathsUrl);
121
+ return resolvePaths().socket;
122
+ }
123
+
124
+ /** 一次请求一个连接:与 src/ipc.ts 的 ipcQueryOnce 同协议(单行 JSON + \n)。 */
125
+ function queryDaemonOnce(socketPath, payload, timeoutMs = 120_000) {
126
+ return new Promise(resolve => {
127
+ let settled = false;
128
+ let buffer = '';
129
+ let timer;
130
+ const finish = value => {
131
+ if (settled) return;
132
+ settled = true;
133
+ if (timer) clearTimeout(timer);
134
+ try { socket.destroy(); } catch {}
135
+ resolve(value);
136
+ };
137
+ const socket = net.createConnection(socketPath);
138
+ timer = setTimeout(() => finish(undefined), timeoutMs);
139
+ socket.once('connect', () => socket.write(`${JSON.stringify(payload)}\n`));
140
+ socket.on('data', chunk => {
141
+ buffer += String(chunk);
142
+ const index = buffer.indexOf('\n');
143
+ if (index < 0) return;
144
+ try { finish(JSON.parse(buffer.slice(0, index))); } catch { finish(undefined); }
145
+ });
146
+ socket.once('error', () => finish(undefined));
147
+ socket.once('close', () => finish(undefined));
148
+ });
149
+ }
150
+
151
+ async function main() {
152
+ const args = process.argv.slice(2);
153
+ if (args.length === 0 || args.includes('--help') || args.includes('-h')) {
154
+ process.stdout.write(HELP);
155
+ return;
156
+ }
157
+
158
+ const sessionId = process.env[ENV_SESSION_ID]?.trim();
159
+ const delegationToken = process.env[ENV_DELEGATION_TOKEN]?.trim()
160
+ || process.env[ENV_CODEX_SESSION_TOKEN]?.trim();
161
+ if (!sessionId) fail('ecmsg 只能在托管会话内使用(缺少 EVOLCORE_SESSION_ID)。宿主终端请用 ec msg。');
162
+ if (!delegationToken) fail('ecmsg 需要会话委托凭证(缺少 EVOLCORE_DELEGATION_TOKEN)。请改用 ec msg。');
163
+
164
+ // 归一化:['ecmsg','send','A','B'] -> ['ec','msg','send','A','B']
165
+ const parserUrl = pathToFileURL(path.join(repoRoot, 'dist', 'core', 'permission', 'ec-command-parser.js')).href;
166
+ let normalizeEvolcoreCommandArgv;
167
+ try {
168
+ ({ normalizeEvolcoreCommandArgv } = await import(parserUrl));
169
+ } catch {
170
+ fail('ecmsg 需要已构建的 dist。请先 npm run build,或改用 ec msg。');
171
+ }
172
+ const normalizedArgv = normalizeEvolcoreCommandArgv(['ecmsg', ...args]);
173
+ if (normalizedArgv[0] !== MAIN_CLI_BIN || normalizedArgv[1] !== 'msg') {
174
+ fail(`无法把参数规范化为 ec msg:${JSON.stringify(normalizedArgv.slice(0, 4))}`);
175
+ }
176
+
177
+ const executionSpec = readDelegatedExecutionSpec(normalizedArgv, process.env);
178
+ const delegationCommandHash = hashDelegatedCommandArgv(normalizedArgv, executionSpec);
179
+
180
+ // daemon 按 resolveManagedSendArgv(params.argv) 解析,argv[0] 必须是 'msg'。
181
+ const daemonArgv = normalizedArgv.slice(1);
182
+
183
+ const runtimeCtx = (() => {
184
+ const raw = process.env[ENV_TASK_RUNTIME_CONTEXT];
185
+ if (!raw) return undefined;
186
+ try { return JSON.parse(raw); } catch { return undefined; }
187
+ })();
188
+
189
+ const result = await queryDaemonOnce(await resolveSocketPath(), {
190
+ type: 'aun-msg-send',
191
+ argv: daemonArgv,
192
+ delegationToken,
193
+ ...(delegationCommandHash ? { delegationCommandHash } : {}),
194
+ originSessionId: sessionId,
195
+ ...(runtimeCtx?.messageId ? { originMessageId: runtimeCtx.messageId } : {}),
196
+ ...(process.env.EVOLCORE_DAEMON_RUNTIME_EPOCH
197
+ ? { daemonRuntimeEpoch: process.env.EVOLCORE_DAEMON_RUNTIME_EPOCH }
198
+ : {}),
199
+ });
200
+
201
+ if (!result) fail('无法连接 EvolCore daemon(AUN_DAEMON_UNAVAILABLE)。');
202
+ if (!result.ok) {
203
+ fail([
204
+ result.code ?? 'AUN_SEND_FAILED',
205
+ result.error ?? 'Send failed',
206
+ result.request_id ? `request_id=${result.request_id}` : '',
207
+ result.detail_code ? `detail_code=${result.detail_code}` : '',
208
+ ].filter(Boolean).join(' · '));
209
+ }
210
+
211
+ const formatIndex = args.indexOf('--format');
212
+ const wantJson = formatIndex >= 0 && args[formatIndex + 1] === 'json';
213
+ if (wantJson) {
214
+ process.stdout.write(`${JSON.stringify(result)}\n`);
215
+ return;
216
+ }
217
+ if (result.request_id) {
218
+ process.stdout.write(`sent message_id=${result.message_id ?? '-'} request_id=${result.request_id} state=${result.request_state ?? '-'}\n`);
219
+ return;
220
+ }
221
+ const seq = result.seq ?? result.message?.seq ?? '-';
222
+ process.stdout.write(`✓ 已发送 message_id=${result.message_id ?? '-'} seq=${seq} status=${result.status ?? '-'}\n`);
223
+ if (result.trigger_id) process.stdout.write(`✓ 复查 Trigger ${result.trigger_id}\n`);
224
+ else if (result.trigger_error) {
225
+ process.stderr.write(`⚠ 复查 Trigger 未创建: ${result.trigger_error}(消息已发出,需要复查请手动 ec trigger create)\n`);
226
+ }
227
+ }
228
+
229
+ void main();
@@ -121,6 +121,23 @@ function windowsPostinstallNotice() {
121
121
  );
122
122
  }
123
123
 
124
+ function normalizeTomlTables(value) {
125
+ if (Array.isArray(value)) return value.map(normalizeTomlTables);
126
+ if (value && typeof value === 'object') {
127
+ const prototype = Object.getPrototypeOf(value);
128
+ if (prototype === null || prototype === Object.prototype) {
129
+ const table = Object.create(null);
130
+ for (const [key, entry] of Object.entries(value)) table[key] = normalizeTomlTables(entry);
131
+ return table;
132
+ }
133
+ }
134
+ return value;
135
+ }
136
+
137
+ function equalTomlTables(left, right) {
138
+ return isDeepStrictEqual(normalizeTomlTables(left), normalizeTomlTables(right));
139
+ }
140
+
124
141
  function removeManagedBlock(source) {
125
142
  const original = parseToml(source);
126
143
  if (!source.includes(markerStart) && !source.includes(markerEnd)) return source;
@@ -131,7 +148,7 @@ function removeManagedBlock(source) {
131
148
  const block = parseToml(matches[0][0]);
132
149
  const groups = block.hooks?.PreToolUse;
133
150
  if (!Array.isArray(groups) || groups.length !== 1
134
- || !isDeepStrictEqual(block, { hooks: { PreToolUse: groups } })) throw unsafe();
151
+ || !equalTomlTables(block, { hooks: { PreToolUse: groups } })) throw unsafe();
135
152
  const content = source.replace(matches[0][0], '');
136
153
  const retained = parseToml(content);
137
154
  const originalGroups = original.hooks?.PreToolUse;
@@ -139,12 +156,12 @@ function removeManagedBlock(source) {
139
156
  // Markers inside a TOML string are not comments. Prove that removing the
140
157
  // block removes only its Hook group, with every other policy unchanged.
141
158
  const safe = originalGroups.some((group, index) => {
142
- if (!isDeepStrictEqual(group, groups[0])) return false;
143
- const expected = structuredClone(original);
159
+ if (!equalTomlTables(group, groups[0])) return false;
160
+ const expected = parseToml(source);
144
161
  expected.hooks.PreToolUse.splice(index, 1);
145
162
  if (!expected.hooks.PreToolUse.length && !retained.hooks?.PreToolUse) delete expected.hooks.PreToolUse;
146
163
  if (!Object.keys(expected.hooks).length && !retained.hooks) delete expected.hooks;
147
- return isDeepStrictEqual(expected, retained);
164
+ return equalTomlTables(expected, retained);
148
165
  });
149
166
  if (!safe) throw unsafe();
150
167
  return content;
@@ -255,7 +272,7 @@ export function buildManagedRequirements(source, { targetDirectory, nodePath, ho
255
272
  ],
256
273
  },
257
274
  };
258
- if (!isDeepStrictEqual(after, expected)) {
275
+ if (!equalTomlTables(after, expected)) {
259
276
  throw new Error('Could not safely update requirements.toml without changing unrelated policy. Existing configuration was not modified.');
260
277
  }
261
278
  return content;
@@ -344,7 +361,7 @@ export function managedBinding(source, launcher, hookPath) {
344
361
  const retainedConfig = parseToml(retained);
345
362
  const groups = original.hooks?.PreToolUse;
346
363
  const retainedGroups = retainedConfig.hooks?.PreToolUse || [];
347
- const owned = groups.filter(group => !retainedGroups.some(other => isDeepStrictEqual(group, other)));
364
+ const owned = groups.filter(group => !retainedGroups.some(other => equalTomlTables(group, other)));
348
365
  if (owned.length !== 1) return null;
349
366
  const group = owned[0];
350
367
  if (group.matcher !== '*' || !Array.isArray(group.hooks) || group.hooks.length !== 1) return null;
@@ -353,7 +370,7 @@ export function managedBinding(source, launcher, hookPath) {
353
370
  const command = parseManagedCommand(handler.command, hookPath);
354
371
  const windowsCommand = parseManagedCommand(handler.command_windows, hookPath);
355
372
  if (!command || !windowsCommand || normalizedPath(command.nodePath) !== normalizedPath(windowsCommand.nodePath)) return null;
356
- if (!isDeepStrictEqual(group, { matcher: '*', hooks: [{
373
+ if (!equalTomlTables(group, { matcher: '*', hooks: [{
357
374
  type: 'command', command: handler.command, command_windows: handler.command_windows,
358
375
  statusMessage: 'Checking EvolCore session policy',
359
376
  }] })) return null;
@@ -441,6 +458,87 @@ export function inspectManagedHookInstallation({ requirements, managedDir, packa
441
458
  }
442
459
  }
443
460
 
461
+ export function removeManagedHookInstallation(options, acl = windowsAcl) {
462
+ const { requirements, managedDir, packageRoot, nodePath = process.execPath } = options;
463
+ const canonicalRequirements = path.resolve(requirements);
464
+ const canonicalManagedDir = path.resolve(managedDir);
465
+ const hookPath = path.join(canonicalManagedDir, 'pre-tool-use.mjs');
466
+ if (!packageRoot || !path.isAbsolute(packageRoot)) throw new Error('An absolute --package-root is required for managed hook removal.');
467
+ for (const target of [path.dirname(canonicalRequirements), canonicalManagedDir]) {
468
+ for (let directory = target; ; directory = path.dirname(directory)) {
469
+ try {
470
+ const stat = fs.lstatSync(directory);
471
+ if (!stat.isDirectory() || stat.isSymbolicLink()) throw new Error(`Expected a real managed-hook directory: ${directory}`);
472
+ } catch (error) {
473
+ if (error?.code !== 'ENOENT') throw error;
474
+ }
475
+ if (directory === path.dirname(directory)) break;
476
+ }
477
+ }
478
+ const req = regularFile(canonicalRequirements);
479
+ const hook = regularFile(hookPath);
480
+ if (req.ok && !hook.ok && !hook.unsafe) {
481
+ const content = fs.readFileSync(canonicalRequirements, 'utf8');
482
+ const parsed = parseToml(content);
483
+ if (!sourceHasManagedMarker(content)
484
+ && !JSON.stringify(parsed.hooks?.PreToolUse || []).toLowerCase().includes('pre-tool-use.mjs')) {
485
+ return { status: 'absent', requirements: canonicalRequirements, managedDir: canonicalManagedDir, hookPath };
486
+ }
487
+ }
488
+ const state = inspectManagedHookInstallation({ requirements: canonicalRequirements, managedDir: canonicalManagedDir, packageRoot, nodePath });
489
+ if (state.status === 'missing') return { ...state, status: 'absent' };
490
+ if (state.status === 'stale' && !samePackageRoot(state.managedPackageRoot, packageRoot)) {
491
+ return { ...state, status: 'preserved', reason: 'managed-hook belongs to a different EvolCore installation' };
492
+ }
493
+ if (state.status !== 'installed') throw new Error(`Refusing managed-hook removal: ${state.reason}`);
494
+ const source = fs.readFileSync(canonicalRequirements, 'utf8');
495
+ const launcher = fs.readFileSync(hookPath, 'utf8');
496
+ if (createHash('sha256').update(source).update('\0').update(launcher).digest('hex') !== state.repairFingerprint) {
497
+ throw new Error('Managed-hook state changed during ownership verification; retry the uninstall.');
498
+ }
499
+ const retained = removeManagedBlock(source);
500
+ acl('preflight');
501
+ const lockPath = path.join(path.dirname(canonicalRequirements), '.evolcore-hooks.install.lock');
502
+ let lock;
503
+ try { lock = fs.openSync(lockPath, 'wx', 0o600); } catch (error) {
504
+ throw new Error(`Cannot acquire installer lock ${lockPath}: ${error.message}. Confirm the other installer has stopped before retrying.`, { cause: error });
505
+ }
506
+ const temporary = `${canonicalRequirements}.evolcore-${randomUUID()}.tmp`;
507
+ const warnings = [];
508
+ try {
509
+ fs.writeFileSync(lock, JSON.stringify({ pid: process.pid, started: new Date().toISOString(), operation: 'uninstall' }));
510
+ fs.writeFileSync(temporary, retained, { encoding: 'utf8', mode: 0o600, flag: 'wx' });
511
+ acl('prepare', { path: temporary, reference: canonicalRequirements });
512
+ acl('verify', { entries: [
513
+ { path: canonicalManagedDir, protected: true, execute: true },
514
+ { path: temporary, protected: true },
515
+ { path: hookPath, protected: true },
516
+ ] });
517
+ const unchanged = (file, expected) => () => {
518
+ existingFile(file, fs);
519
+ if (fs.readFileSync(file, 'utf8') !== expected) throw new Error(`Managed-hook file changed before removal: ${file}`);
520
+ };
521
+ warnings.push(...commitPreparedFiles([
522
+ { file: canonicalRequirements, temporary, validate: unchanged(canonicalRequirements, source) },
523
+ { file: hookPath, remove: true, validate: unchanged(hookPath, launcher) },
524
+ ], () => {
525
+ if (fs.readFileSync(canonicalRequirements, 'utf8') !== retained || fs.existsSync(hookPath)) {
526
+ throw new Error('Managed-hook removal could not be verified.');
527
+ }
528
+ acl('verify', { entries: [{ path: canonicalRequirements, protected: true }] });
529
+ }));
530
+ try { fs.rmdirSync(canonicalManagedDir); } catch (error) {
531
+ if (!['ENOTEMPTY', 'EEXIST', 'ENOENT'].includes(error?.code)) warnings.push(`Managed-hook directory was preserved: ${error.message}`);
532
+ }
533
+ } finally {
534
+ try { fs.rmSync(temporary, { force: true }); } catch (error) { warnings.push(`Could not remove staging file ${temporary}: ${error.message}`); }
535
+ fs.closeSync(lock);
536
+ try { fs.unlinkSync(lockPath); } catch (error) { warnings.push(`Could not remove installer lock ${lockPath}: ${error.message}`); }
537
+ }
538
+ warnings.push('Other Codex hooks and shared policy settings were preserved.');
539
+ return { status: 'removed', requirements: canonicalRequirements, managedDir: canonicalManagedDir, hookPath, warnings };
540
+ }
541
+
444
542
  /** Idempotently repair a missing or stale canonical installation; unsafe edits fail closed. */
445
543
  export function repairManagedHookInstallation(options, acl = windowsAcl) {
446
544
  const { requirements, managedDir, packageRoot, nodePath = process.execPath } = options;
@@ -527,9 +625,13 @@ export function commitPreparedFiles(entries, verify, io = fs) {
527
625
  }
528
626
  records.push(record);
529
627
  }
628
+ for (const record of records) {
629
+ record.validate?.();
630
+ }
530
631
  for (const record of records) {
531
632
  makeReplaceable(record.file, io);
532
- io.renameSync(record.temporary, record.file);
633
+ if (record.remove) io.unlinkSync(record.file);
634
+ else io.renameSync(record.temporary, record.file);
533
635
  record.installed = true;
534
636
  if (record.backup) io.chmodSync(record.backup, record.mode);
535
637
  }
@@ -666,6 +768,26 @@ async function main() {
666
768
  await checkClaudeSandboxDependencies();
667
769
  return;
668
770
  }
771
+ if (hasArgument('--uninstall-managed-hook')) {
772
+ if (process.platform !== 'win32') fail('Codex managed hook removal is only supported on Windows.');
773
+ if (!argument('--package-root')) fail('--package-root is required for managed hook removal.');
774
+ const packageRoot = path.resolve(argument('--package-root'));
775
+ const nodePath = path.resolve(argument('--node-path') || process.execPath);
776
+ const requirements = path.resolve(argument('--requirements')
777
+ || path.join(process.env.ProgramData || path.join(os.homedir(), 'ProgramData'), 'OpenAI', 'Codex', 'requirements.toml'));
778
+ const targetDirectory = path.resolve(argument('--managed-dir') || path.join(path.dirname(requirements), 'EvolCore', 'hooks'));
779
+ if (argument('--runtime-root')) {
780
+ const { configureAutostart } = await import('../dist/utils/autostart.js');
781
+ const autostart = configureAutostart(false, path.resolve(argument('--runtime-root')));
782
+ if (!autostart.ok) throw new Error(`Login autostart removal failed: ${autostart.error || 'unknown error'}`);
783
+ if (autostart.warning) process.stderr.write(`[evolcore] ${autostart.warning}\n`);
784
+ }
785
+ const result = removeManagedHookInstallation({ requirements, managedDir: targetDirectory, packageRoot, nodePath });
786
+ for (const warning of result.warnings || []) process.stderr.write(`[evolcore] ${warning}\n`);
787
+ if (result.status === 'preserved') process.stderr.write(`[evolcore] ${result.reason}; existing configuration was not modified.\n`);
788
+ process.stdout.write(`${JSON.stringify(result)}\n`);
789
+ return;
790
+ }
669
791
  // An explicit package root selects provisioning, even if the elevated
670
792
  // child inherited npm lifecycle variables. Ordinary postinstall skips it.
671
793
  if (!argument('--package-root') && (lifecycleEvent() === 'postinstall' || isGlobalInstall())) {
@@ -573,6 +573,43 @@ export class AbilityApplicationService {
573
573
  abilityAssert(this.store.get('instance', instanceId)?.revision === instance.revision, 'LEASE_EXPIRED', 'Resource authorization changed', 403);
574
574
  if (method === 'host.status')
575
575
  return { ready: instance.runtimeState === 'ready' };
576
+ // Storage batch operations (Protocol v2)
577
+ if (method === 'storage.batch') {
578
+ abilityAssert(this.validGrant(instance, 'storage'), 'RESOURCE_DENIED', 'Storage is not granted', 403);
579
+ abilityAssert(Array.isArray(args.operations) && args.operations.length >= 1 && args.operations.length <= 50, 'INVALID_BATCH_SIZE', 'Batch operations must contain 1-50 items');
580
+ const results = await Promise.all(args.operations.map(async (op) => {
581
+ try {
582
+ abilityAssert(typeof op.key === 'string' && /^[A-Za-z0-9._-]{1,128}$/.test(op.key), 'KEY_INVALID', 'Invalid storage key');
583
+ const entry = this.store.kvAddress(instance, op.key);
584
+ if (op.op === 'get') {
585
+ const value = this.store.get(entry.kind, entry.id) ?? null;
586
+ return { success: true, value };
587
+ }
588
+ else if (op.op === 'set') {
589
+ abilityAssert(Buffer.byteLength(JSON.stringify(op.value) ?? '') <= 65536, 'VALUE_TOO_LARGE', 'Storage value exceeds 64 KiB');
590
+ this.store.transaction(() => {
591
+ this.store.audit('invocation:' + invocationId, instance.target.aid, 'storage.set', instanceId);
592
+ this.store.put(entry.kind, entry.id, instance.target.aid, op.value);
593
+ });
594
+ return { success: true };
595
+ }
596
+ else if (op.op === 'delete') {
597
+ this.store.transaction(() => {
598
+ this.store.audit('invocation:' + invocationId, instance.target.aid, 'storage.delete', instanceId);
599
+ this.store.put(entry.kind, entry.id, instance.target.aid, null);
600
+ });
601
+ return { success: true };
602
+ }
603
+ else {
604
+ return { success: false, error: 'UNKNOWN_OPERATION' };
605
+ }
606
+ }
607
+ catch (error) {
608
+ return { success: false, error: error instanceof AbilityError ? error.code : 'OPERATION_FAILED' };
609
+ }
610
+ }));
611
+ return { results };
612
+ }
576
613
  if (!method.startsWith('storage.')) {
577
614
  const check = () => {
578
615
  const current = this.store.get('instance', instanceId);
@@ -42,6 +42,34 @@ for (const [network, prefix] of [['0.0.0.0', 8], ['10.0.0.0', 8], ['100.64.0.0',
42
42
  privateNetworks.addSubnet(network, prefix, 'ipv4');
43
43
  function publicAddress(address) { return isIP(address) === 4 && !privateNetworks.check(address, 'ipv4'); }
44
44
  export async function resourceCall(instance, pkg, secrets, refs, method, args, checkLease) {
45
+ // Note: storage.batch is now handled directly in application-service.ts broker()
46
+ // to access the store instance. This keeps workspace batch operations here.
47
+ // Workspace batch read (Protocol v2)
48
+ if (method === 'workspace.readMany') {
49
+ const grant = activeGrants(instance, 'workspace')[0]?.value;
50
+ abilityAssert(grant, 'RESOURCE_DENIED', 'Workspace is not granted', 403);
51
+ abilityAssert(Array.isArray(args.files) &&
52
+ args.files.length >= 1 &&
53
+ args.files.length <= 10, 'INVALID_FILE_COUNT', 'Can read 1-10 files at once');
54
+ const files = {};
55
+ await Promise.all(args.files.map(async (file) => {
56
+ try {
57
+ const fullPath = workspacePath(grant.root, file, false);
58
+ checkLease();
59
+ const stat = fs.statSync(fullPath);
60
+ abilityAssert(stat.isFile() && stat.size <= 1024 * 1024, 'RESOURCE_TOO_LARGE', 'File exceeds 1 MiB');
61
+ const content = fs.readFileSync(fullPath, 'utf8');
62
+ files[file] = { success: true, content };
63
+ }
64
+ catch (error) {
65
+ files[file] = {
66
+ success: false,
67
+ error: error instanceof AbilityError ? error.code : 'FILE_READ_FAILED'
68
+ };
69
+ }
70
+ }));
71
+ return { files };
72
+ }
45
73
  if (method.startsWith('workspace.')) {
46
74
  const grant = activeGrants(instance, 'workspace')[0]?.value;
47
75
  abilityAssert(grant, 'RESOURCE_DENIED', 'Workspace is not granted', 403);
@@ -39,6 +39,7 @@ export class AbilityRunner {
39
39
  this.broker = broker;
40
40
  this.exited = exited;
41
41
  }
42
+ supportedCapabilities = [];
42
43
  async start(pkg, instance, migration) {
43
44
  abilityAssert(packageDigest(pkg.root) === pkg.digest, 'PACKAGE_CHANGED', 'Stored package changed');
44
45
  const command = runtimeCommand(pkg);
@@ -101,11 +102,15 @@ export class AbilityRunner {
101
102
  this.child.once('exit', ended);
102
103
  try {
103
104
  const health = await this.call('initialize', {
105
+ protocolVersion: 'evolcore.ability-runtime/2',
106
+ capabilities: ['batch-operations', 'heartbeat', 'prefetch'],
104
107
  ...(pkg.manifest.runtime.kind === 'node-subprocess' ? { entry: packageFile(pkg.root, pkg.manifest.runtime.entry) } : {}),
105
- config: instance.config, handlers: pkg.manifest.abilities.map(item => item.handler), ...(migration ? { migration } : {})
108
+ config: instance.config, handlers: pkg.manifest.abilities.map(item => item.handler), ...(migration ? { migration } : {}),
109
+ runtimeOptions: { heartbeatMode: false, batchingEnabled: true }
106
110
  }, 30000);
107
111
  abilityAssert(health?.ready === true, 'RUNTIME_NOT_READY', 'Runner did not report readiness', 503);
108
112
  abilityAssert(Array.isArray(health.handlers) && JSON.stringify([...health.handlers].sort()) === JSON.stringify(pkg.manifest.abilities.map(row => row.handler).sort()), 'RUNTIME_HANDLERS_MISMATCH', 'Runner handler set differs from Manifest', 503);
113
+ this.supportedCapabilities = health.supportedCapabilities || [];
109
114
  this.healthTimer = setInterval(() => {
110
115
  if (!this.closing)
111
116
  void this.call('health', {}, 5000).then(value => {
@@ -34,7 +34,8 @@ import { buildClaudeUnixSocketAllowlist } from '../core/permission/unix-socket-p
34
34
  import { auditToolInfrastructureFailure, auditToolPreflightDenial } from '../core/auth/authorization-audit.js';
35
35
  import { getManagedTaskTempDir, isManagedSessionRuntimeDir } from '../cli/task-context.js';
36
36
  import { unsettledInterruptError, withInterruptDeadline, hasTrustedFullAccessContext } from './runner-types.js';
37
- import { getGatewayPricing as getSharedGatewayPricing, resolveModelSpec } from '../stats/price-resolver.js';
37
+ import { getGatewayPricing as getSharedGatewayPricing } from '../stats/price-resolver.js';
38
+ import { resolveModelCapabilities } from '../core/model/model-capabilities.js';
38
39
  import { contextTokensForUsage, usageForContext, realContextWindowForModel, autoCompactWindowForModel, sdkAutoCompactWindowForModel } from './runner-types.js';
39
40
  import { hasContextWindowSuffix, stripContextWindowSuffix } from '../core/model/context-window-suffix.js';
40
41
  const resolveModule = createRequire(import.meta.url);
@@ -463,12 +464,13 @@ function applyContextWindow(modelId, contextWindow, catalog) {
463
464
  return modelId;
464
465
  }
465
466
  function resolveClaudeModelContext(modelId, catalog) {
466
- const modelSpec = resolveModelSpec(resolvePaths().root, modelId, undefined, {
467
- context_window: realContextWindowForModel(modelId),
467
+ const capabilities = resolveModelCapabilities(resolvePaths().root, modelId, {
468
+ catalog,
469
+ fallbackContextWindow: realContextWindowForModel(modelId),
468
470
  });
469
471
  return {
470
- sdkModel: applyContextWindow(modelId, modelSpec.context_window, catalog),
471
- contextWindow: modelSpec.context_window,
472
+ sdkModel: applyContextWindow(capabilities.model, capabilities.contextWindow, catalog),
473
+ contextWindow: capabilities.contextWindow,
472
474
  };
473
475
  }
474
476
  class MessageStream {