@cortex-agent/server 2026.8.3 → 2026.8.6

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 (224) hide show
  1. package/defaults/config/thread-templates/agents/benchmark-coder.json +2 -2
  2. package/defaults/config/thread-templates/agents/benchmark-fixer.json +17 -0
  3. package/defaults/config/thread-templates/agents/benchmark-reviewer.json +5 -5
  4. package/defaults/config/thread-templates/templates/benchmark-coder-review-fix.json +21 -0
  5. package/defaults/plugins/cortex-system/skills/thread/SKILL.md +1 -0
  6. package/defaults/prompts/directives/benchmark-coder.md +1 -0
  7. package/defaults/prompts/directives/benchmark-fixer.md +1 -0
  8. package/defaults/prompts/directives/benchmark-reviewer.md +1 -0
  9. package/defaults/prompts/systemPrompts/benchmark-coder.md +1 -0
  10. package/defaults/prompts/systemPrompts/benchmark-fixer.md +1 -0
  11. package/defaults/prompts/systemPrompts/benchmark-reviewer.md +1 -0
  12. package/dist/agent-adapter/capabilities.d.ts +32 -1
  13. package/dist/agent-adapter/capabilities.js +39 -1
  14. package/dist/agent-adapter/claude/adapter.d.ts +15 -0
  15. package/dist/agent-adapter/claude/adapter.js +29 -7
  16. package/dist/agent-adapter/claude/spawn-args.d.ts +5 -2
  17. package/dist/agent-adapter/claude/spawn-args.js +29 -6
  18. package/dist/agent-adapter/index.js +11 -1
  19. package/dist/agent-adapter/normalize/tool-names.d.ts +4 -0
  20. package/dist/agent-adapter/normalize/tool-names.js +10 -0
  21. package/dist/agent-adapter/pi/adapter.d.ts +20 -8
  22. package/dist/agent-adapter/pi/adapter.js +130 -35
  23. package/dist/agent-adapter/pi/agent-dir.d.ts +20 -53
  24. package/dist/agent-adapter/pi/agent-dir.js +48 -89
  25. package/dist/agent-adapter/pi/custom-catalog.d.ts +10 -0
  26. package/dist/agent-adapter/pi/custom-catalog.js +42 -0
  27. package/dist/agent-adapter/pi/defaults.d.ts +9 -0
  28. package/dist/agent-adapter/pi/defaults.js +14 -4
  29. package/dist/agent-adapter/pi/discovery.d.ts +1 -3
  30. package/dist/agent-adapter/pi/discovery.js +3 -15
  31. package/dist/agent-adapter/pi/event-parser.js +8 -0
  32. package/dist/agent-adapter/pi/mcp-bridge.d.ts +13 -0
  33. package/dist/agent-adapter/pi/mcp-bridge.js +31 -6
  34. package/dist/agent-adapter/pi/mcp-duration.d.ts +28 -0
  35. package/dist/agent-adapter/pi/mcp-duration.js +48 -0
  36. package/dist/agent-adapter/pi/policy-guard.d.ts +40 -0
  37. package/dist/agent-adapter/pi/policy-guard.js +111 -0
  38. package/dist/agent-adapter/pi/providers-config.d.ts +62 -0
  39. package/dist/agent-adapter/pi/providers-config.js +101 -0
  40. package/dist/agent-adapter/pi/quota-probe.d.ts +11 -0
  41. package/dist/agent-adapter/pi/quota-probe.js +36 -0
  42. package/dist/agent-adapter/pi/quota-sink.d.ts +25 -0
  43. package/dist/agent-adapter/pi/quota-sink.js +31 -0
  44. package/dist/agent-adapter/pi/session-files.d.ts +2 -0
  45. package/dist/agent-adapter/pi/session-files.js +19 -0
  46. package/dist/agent-adapter/pi/session-support.d.ts +14 -3
  47. package/dist/agent-adapter/pi/session-support.js +8 -0
  48. package/dist/agent-adapter/pi/spawn-args.d.ts +11 -1
  49. package/dist/agent-adapter/pi/spawn-args.js +13 -0
  50. package/dist/agent-adapter/pi/tool-shims.d.ts +2 -2
  51. package/dist/agent-adapter/pi/tool-shims.js +32 -21
  52. package/dist/agent-adapter/pi/web-search.js +36 -8
  53. package/dist/agent-adapter/types.d.ts +14 -0
  54. package/dist/core/locales/en.d.ts +54 -1
  55. package/dist/core/locales/en.js +2 -0
  56. package/dist/core/locales/slices/commands.d.ts +12 -1
  57. package/dist/core/locales/slices/commands.js +24 -2
  58. package/dist/core/locales/slices/providers.d.ts +45 -0
  59. package/dist/core/locales/slices/providers.js +95 -0
  60. package/dist/core/locales/zh.js +2 -0
  61. package/dist/core/resilient-watch.d.ts +28 -0
  62. package/dist/core/resilient-watch.js +110 -0
  63. package/dist/core/settings.js +15 -20
  64. package/dist/core/types/agent-types.d.ts +6 -0
  65. package/dist/core/types/thread-types.d.ts +21 -3
  66. package/dist/core/utils.d.ts +21 -1
  67. package/dist/core/utils.js +37 -1
  68. package/dist/domain/agent-run/agent-run-cli.js +3 -1
  69. package/dist/domain/agent-run/benchmark-local-thread-orchestrator.d.ts +31 -0
  70. package/dist/domain/agent-run/benchmark-local-thread-orchestrator.js +231 -24
  71. package/dist/domain/agent-run/benchmark-thread-identity.d.ts +15 -2
  72. package/dist/domain/agent-run/benchmark-thread-identity.js +123 -34
  73. package/dist/domain/agent-run/identity.d.ts +5 -0
  74. package/dist/domain/agent-run/identity.js +4 -1
  75. package/dist/domain/agent-run/journal.d.ts +3 -2
  76. package/dist/domain/agent-run/manifest.js +11 -4
  77. package/dist/domain/agent-run/pinned-node-process.d.ts +4 -0
  78. package/dist/domain/agent-run/pinned-node-process.js +9 -0
  79. package/dist/domain/agent-run/role-surface.d.ts +2 -2
  80. package/dist/domain/agent-run/role-surface.js +7 -3
  81. package/dist/domain/agent-run/run-config.d.ts +10 -1
  82. package/dist/domain/agent-run/run-config.js +57 -6
  83. package/dist/domain/agent-run/runner.js +149 -31
  84. package/dist/domain/agents/facade.d.ts +37 -122
  85. package/dist/domain/agents/facade.js +47 -115
  86. package/dist/domain/agents/spawn-config.d.ts +135 -0
  87. package/dist/domain/agents/spawn-config.js +121 -0
  88. package/dist/domain/benchmark/accounting-reconciliation.d.ts +98 -0
  89. package/dist/domain/benchmark/accounting-reconciliation.js +218 -0
  90. package/dist/domain/benchmark/arm-schema.d.ts +43 -0
  91. package/dist/domain/benchmark/arm-schema.js +243 -0
  92. package/dist/domain/benchmark/capabilities.d.ts +4 -0
  93. package/dist/domain/benchmark/capabilities.js +54 -0
  94. package/dist/domain/benchmark/decimal-text.d.ts +27 -0
  95. package/dist/domain/benchmark/decimal-text.js +67 -0
  96. package/dist/domain/benchmark/lease-echo.d.ts +43 -0
  97. package/dist/domain/benchmark/lease-echo.js +56 -0
  98. package/dist/domain/benchmark/policy-backed-runtime-deps.d.ts +14 -0
  99. package/dist/domain/benchmark/policy-backed-runtime-deps.js +47 -0
  100. package/dist/domain/benchmark/policy-compiler.d.ts +68 -0
  101. package/dist/domain/benchmark/policy-compiler.js +680 -0
  102. package/dist/domain/benchmark/resolved-policy.d.ts +110 -0
  103. package/dist/domain/benchmark/resolved-policy.js +195 -0
  104. package/dist/domain/benchmark/trial-adapter-factory.d.ts +38 -0
  105. package/dist/domain/benchmark/trial-adapter-factory.js +165 -0
  106. package/dist/domain/benchmark/trial-thread-adapter.d.ts +25 -0
  107. package/dist/domain/benchmark/trial-thread-adapter.js +106 -0
  108. package/dist/domain/benchmark/variant-proposal.d.ts +45 -0
  109. package/dist/domain/benchmark/variant-proposal.js +42 -0
  110. package/dist/domain/benchmark/workspace-lease.d.ts +99 -0
  111. package/dist/domain/benchmark/workspace-lease.js +272 -0
  112. package/dist/domain/costs/codex-quota.d.ts +29 -0
  113. package/dist/domain/costs/codex-quota.js +102 -0
  114. package/dist/domain/costs/cost-tracker.d.ts +48 -9
  115. package/dist/domain/costs/cost-tracker.js +74 -18
  116. package/dist/domain/costs/rate-limit-throttle.d.ts +23 -1
  117. package/dist/domain/costs/rate-limit-throttle.js +61 -6
  118. package/dist/domain/costs/resume-registry.d.ts +3 -1
  119. package/dist/domain/costs/resume-registry.js +10 -1
  120. package/dist/domain/mcp/tools/benchmark-thread-run.d.ts +26 -2
  121. package/dist/domain/mcp/tools/benchmark-thread-run.js +63 -20
  122. package/dist/domain/mcp/tools/cost.js +15 -6
  123. package/dist/domain/pi-providers/custom-provider-model.d.ts +53 -0
  124. package/dist/domain/pi-providers/custom-provider-model.js +122 -0
  125. package/dist/domain/pi-providers/custom-provider-service.d.ts +59 -0
  126. package/dist/domain/pi-providers/custom-provider-service.js +143 -0
  127. package/dist/domain/pi-providers/gateway-route-store.d.ts +23 -0
  128. package/dist/domain/pi-providers/gateway-route-store.js +78 -0
  129. package/dist/domain/pi-providers/index.d.ts +4 -0
  130. package/dist/domain/pi-providers/index.js +8 -0
  131. package/dist/domain/pi-providers/models-json-store.d.ts +6 -0
  132. package/dist/domain/pi-providers/models-json-store.js +77 -0
  133. package/dist/domain/remote/client-hot-reload.d.ts +9 -1
  134. package/dist/domain/remote/client-hot-reload.js +60 -12
  135. package/dist/domain/scheduling/jobs/_shared.d.ts +4 -1
  136. package/dist/domain/scheduling/jobs/_shared.js +11 -2
  137. package/dist/domain/scheduling/jobs/scheduled-task.js +1 -0
  138. package/dist/domain/scheduling/jobs/task-dispatch.js +49 -54
  139. package/dist/domain/sessions/session-lifecycle.d.ts +22 -0
  140. package/dist/domain/sessions/session-lifecycle.js +20 -1
  141. package/dist/domain/system/install-cli.js +8 -3
  142. package/dist/domain/system/system-notice.d.ts +4 -1
  143. package/dist/domain/system/system-notice.js +6 -2
  144. package/dist/domain/tasks/dispatch-utils.d.ts +0 -4
  145. package/dist/domain/tasks/dispatch-utils.js +24 -37
  146. package/dist/domain/threads/runner.d.ts +16 -1
  147. package/dist/domain/threads/runner.js +62 -8
  148. package/dist/domain/threads/template-loader.d.ts +5 -0
  149. package/dist/domain/threads/template-loader.js +120 -36
  150. package/dist/domain/threads/template-validate.d.ts +244 -0
  151. package/dist/domain/threads/template-validate.js +574 -0
  152. package/dist/domain/threads/template-validate.parity.d.ts +1 -0
  153. package/dist/domain/threads/template-validate.parity.js +47 -0
  154. package/dist/domain/threads/template-writer.d.ts +55 -0
  155. package/dist/domain/threads/template-writer.js +131 -0
  156. package/dist/domain/ui-service/app-router.d.ts +143 -1
  157. package/dist/domain/ui-service/app-router.js +29 -3
  158. package/dist/domain/ui-service/input-schemas.d.ts +228 -4
  159. package/dist/domain/ui-service/input-schemas.js +132 -1
  160. package/dist/domain/ui-service/mutate/config.d.ts +10 -1
  161. package/dist/domain/ui-service/mutate/config.js +45 -5
  162. package/dist/domain/ui-service/mutate/custom-providers.d.ts +8 -0
  163. package/dist/domain/ui-service/mutate/custom-providers.js +37 -0
  164. package/dist/domain/ui-service/mutate/profiles.d.ts +21 -0
  165. package/dist/domain/ui-service/mutate/profiles.js +156 -0
  166. package/dist/domain/ui-service/mutate/schedules.d.ts +2 -1
  167. package/dist/domain/ui-service/mutate/schedules.js +53 -3
  168. package/dist/domain/ui-service/mutate/sessions.d.ts +2 -1
  169. package/dist/domain/ui-service/mutate/sessions.js +25 -1
  170. package/dist/domain/ui-service/mutate/system.d.ts +2 -1
  171. package/dist/domain/ui-service/mutate/system.js +17 -3
  172. package/dist/domain/ui-service/mutate/thread-templates.d.ts +4 -0
  173. package/dist/domain/ui-service/mutate/thread-templates.js +71 -0
  174. package/dist/domain/ui-service/query/config.js +30 -0
  175. package/dist/domain/ui-service/query/custom-providers.d.ts +8 -0
  176. package/dist/domain/ui-service/query/custom-providers.js +13 -0
  177. package/dist/domain/ui-service/query/machine-detail.d.ts +2 -0
  178. package/dist/domain/ui-service/query/machine-detail.js +56 -0
  179. package/dist/domain/ui-service/query/machine-probe.d.ts +18 -0
  180. package/dist/domain/ui-service/query/machine-probe.js +136 -0
  181. package/dist/domain/ui-service/query/schedules.js +5 -0
  182. package/dist/domain/ui-service/query/sessions.js +8 -2
  183. package/dist/domain/ui-service/query/thread-template-detail.d.ts +8 -0
  184. package/dist/domain/ui-service/query/thread-template-detail.js +94 -0
  185. package/dist/domain/ui-service/query/thread-templates.d.ts +5 -3
  186. package/dist/domain/ui-service/query/thread-templates.js +44 -7
  187. package/dist/domain/ui-service/types.d.ts +298 -7
  188. package/dist/domain/ui-service/ui-service.js +27 -3
  189. package/dist/entry/app.js +24 -3
  190. package/dist/entry/auth-cli.d.ts +4 -1
  191. package/dist/entry/auth-cli.js +10 -2
  192. package/dist/entry/cli-help.js +6 -2
  193. package/dist/entry/cli.js +2 -1
  194. package/dist/entry/daemon.d.ts +0 -11
  195. package/dist/entry/daemon.js +5 -49
  196. package/dist/entry/provider-cli.d.ts +16 -0
  197. package/dist/entry/provider-cli.js +203 -0
  198. package/dist/events/event-types.d.ts +2 -1
  199. package/dist/orchestration/agent-runner.js +3 -2
  200. package/dist/orchestration/routing/commands/cost.d.ts +8 -0
  201. package/dist/orchestration/routing/commands/cost.js +93 -21
  202. package/dist/orchestration/routing/commands/login-custom.d.ts +26 -0
  203. package/dist/orchestration/routing/commands/login-custom.js +89 -0
  204. package/dist/orchestration/routing/commands/login.d.ts +3 -0
  205. package/dist/orchestration/routing/commands/login.js +7 -0
  206. package/dist/orchestration/routing/message-router.js +48 -33
  207. package/dist/orchestration/routing/webhook.js +1 -1
  208. package/dist/orchestration/session-events.d.ts +2 -1
  209. package/dist/orchestration/session-events.js +1 -0
  210. package/dist/orchestration/thread-callback.js +1 -1
  211. package/dist/store/conversation-history-repo.d.ts +5 -1
  212. package/dist/store/conversation-history-repo.js +2 -1
  213. package/dist/store/cost-repo.d.ts +17 -0
  214. package/dist/store/cost-repo.js +47 -5
  215. package/dist/store/profile-repo.d.ts +0 -10
  216. package/dist/store/profile-repo.js +34 -56
  217. package/dist/store/session-registry-repo.d.ts +12 -0
  218. package/dist/store/session-registry-repo.js +16 -0
  219. package/package.json +1 -1
  220. package/web/dist/assets/index-DYMfaAi4.css +1 -0
  221. package/web/dist/assets/index-uOoZjGKa.js +141 -0
  222. package/web/dist/index.html +2 -2
  223. package/web/dist/assets/index-DrNx9R6c.js +0 -139
  224. package/web/dist/assets/index-zpf3OSKC.css +0 -1
@@ -0,0 +1,95 @@
1
+ // input: none (static message table slice)
2
+ // output: providersEn / providersZh — custom PI provider copy
3
+ // pos: L0 locale slice for user-defined provider management
4
+ // >>> If I am updated, add the same keys to both objects and update the parent CORTEX.md <<<
5
+ export const providersEn = {
6
+ // --- custom provider CLI ---
7
+ 'provider.cli.description': 'Manage user-defined PI providers (self-hosted or proxied endpoints).',
8
+ 'provider.cli.listDescription': 'List the providers you have defined',
9
+ 'provider.cli.addDescription': 'Create or update a provider',
10
+ 'provider.cli.removeDescription': 'Delete a provider and its gateway route',
11
+ 'provider.cli.nameDescription': 'Provider name, letters, digits, dash and underscore only',
12
+ 'provider.cli.apiDescription': 'Request protocol the endpoint speaks',
13
+ 'provider.cli.urlDescription': 'Upstream endpoint URL, stored in the gateway route',
14
+ 'provider.cli.keyDescription': 'Upstream API key, or - to read it from stdin',
15
+ 'provider.cli.modelDescription': 'Model id offered by the endpoint, repeatable',
16
+ 'provider.cli.jsonDescription': 'Print the result as JSON',
17
+ 'provider.cli.dryRunDescription': 'Report what would be removed without removing it',
18
+ 'provider.cli.helpDescription': 'Show this help',
19
+ 'provider.cli.exampleAdd': 'Define a local endpoint that speaks the Anthropic protocol',
20
+ 'provider.cli.exampleAddPiped': 'Define a provider whose key comes from a secret store',
21
+ 'provider.cli.exampleList': 'Show every provider you have defined',
22
+ 'provider.cli.exampleRemove': 'Preview a deletion before running it',
23
+ 'provider.cli.unknownSubcommand': 'Unknown subcommand: `${command}`',
24
+ 'provider.cli.unknownFlag': 'Unknown flag: `${flag}`',
25
+ 'provider.cli.missingFlag': 'Missing required flag: `${flag}`',
26
+ 'provider.cli.flagNeedsValue': 'Flag `${flag}` needs a value',
27
+ 'provider.cli.notFound': 'No such custom provider: `${name}`',
28
+ 'provider.cli.writeFailed': 'Could not write the provider files — see the server log for the reason.',
29
+ 'provider.cli.validValues': 'Valid values:',
30
+ 'provider.cli.hint': 'Hint:',
31
+ 'provider.cli.listEmpty': 'No custom providers defined.',
32
+ 'provider.cli.listItem': '${name} ${api} ${upstream}',
33
+ 'provider.cli.listItemUnrouted': '${name} ${api} (no gateway route)',
34
+ 'provider.cli.added': 'Saved provider `${name}` — routed through the gateway to ${upstream}.',
35
+ 'provider.cli.removed': 'Removed provider `${name}`.',
36
+ // --- chat command (!login custom) ---
37
+ 'provider.chat.usage': 'Usage: `!login custom [list | add <name> <api> <url> <model…> | remove <name>]`',
38
+ 'provider.chat.keyNotice': 'An upstream key is never typed into a channel — add one with `cortex auth provider add --key -` or in Web settings.',
39
+ // --- validation issues, shared by every surface ---
40
+ 'provider.issue.name-required': 'A provider name is required.',
41
+ 'provider.issue.name-charset': 'A provider name may use letters, digits, dash and underscore only.',
42
+ 'provider.issue.name-reserved': 'That name belongs to a built-in PI provider — pick another.',
43
+ 'provider.issue.api-invalid': 'Unknown request protocol.',
44
+ 'provider.issue.upstream-required': 'An upstream URL is required.',
45
+ 'provider.issue.upstream-scheme': 'The upstream URL must start with http:// or https://.',
46
+ 'provider.issue.models-required': 'Define at least one model id.',
47
+ 'provider.issue.model-id-required': 'Every model needs an id.',
48
+ 'provider.issue.model-id-duplicate': 'Model ids must be unique.',
49
+ 'provider.issue.not-found': 'No such custom provider.',
50
+ 'provider.issue.write-failed': 'Writing the provider files failed.',
51
+ };
52
+ export const providersZh = {
53
+ 'provider.cli.description': '管理自定义 PI provider(自建或代理的推理端点)。',
54
+ 'provider.cli.listDescription': '列出已定义的 provider',
55
+ 'provider.cli.addDescription': '新建或更新一个 provider',
56
+ 'provider.cli.removeDescription': '删除一个 provider 及其网关路由',
57
+ 'provider.cli.nameDescription': 'provider 名称,仅限字母、数字、连字符和下划线',
58
+ 'provider.cli.apiDescription': '端点使用的请求协议',
59
+ 'provider.cli.urlDescription': '上游端点地址,保存在网关路由里',
60
+ 'provider.cli.keyDescription': '上游 API key,填 - 表示从标准输入读取',
61
+ 'provider.cli.modelDescription': '端点提供的模型 id,可重复',
62
+ 'provider.cli.jsonDescription': '以 JSON 输出结果',
63
+ 'provider.cli.dryRunDescription': '只显示会删除什么,不真的删除',
64
+ 'provider.cli.helpDescription': '显示帮助',
65
+ 'provider.cli.exampleAdd': '定义一个使用 Anthropic 协议的本地端点',
66
+ 'provider.cli.exampleAddPiped': '定义一个从密钥库取 key 的 provider',
67
+ 'provider.cli.exampleList': '查看已定义的全部 provider',
68
+ 'provider.cli.exampleRemove': '删除前先预览',
69
+ 'provider.cli.unknownSubcommand': '未知子命令:`${command}`',
70
+ 'provider.cli.unknownFlag': '未知参数:`${flag}`',
71
+ 'provider.cli.missingFlag': '缺少必填参数:`${flag}`',
72
+ 'provider.cli.flagNeedsValue': '参数 `${flag}` 需要一个值',
73
+ 'provider.cli.notFound': '没有这个自定义 provider:`${name}`',
74
+ 'provider.cli.writeFailed': '写入 provider 配置失败——原因见服务端日志。',
75
+ 'provider.cli.validValues': '可选值:',
76
+ 'provider.cli.hint': '提示:',
77
+ 'provider.cli.listEmpty': '尚未定义任何自定义 provider。',
78
+ 'provider.cli.listItem': '${name} ${api} ${upstream}',
79
+ 'provider.cli.listItemUnrouted': '${name} ${api} (没有网关路由)',
80
+ 'provider.cli.added': '已保存 provider `${name}`——经网关路由到 ${upstream}。',
81
+ 'provider.cli.removed': '已删除 provider `${name}`。',
82
+ 'provider.chat.usage': '用法:`!login custom [list | add <名称> <协议> <地址> <模型…> | remove <名称>]`',
83
+ 'provider.chat.keyNotice': '上游密钥不要打进聊天——请用 `cortex auth provider add --key -` 或 Web 设置页添加。',
84
+ 'provider.issue.name-required': '必须填写 provider 名称。',
85
+ 'provider.issue.name-charset': 'provider 名称只能使用字母、数字、连字符和下划线。',
86
+ 'provider.issue.name-reserved': '这个名字属于 PI 内置 provider,请换一个。',
87
+ 'provider.issue.api-invalid': '未知的请求协议。',
88
+ 'provider.issue.upstream-required': '必须填写上游地址。',
89
+ 'provider.issue.upstream-scheme': '上游地址必须以 http:// 或 https:// 开头。',
90
+ 'provider.issue.models-required': '至少定义一个模型 id。',
91
+ 'provider.issue.model-id-required': '每个模型都需要 id。',
92
+ 'provider.issue.model-id-duplicate': '模型 id 不能重复。',
93
+ 'provider.issue.not-found': '没有这个自定义 provider。',
94
+ 'provider.issue.write-failed': '写入 provider 配置失败。',
95
+ };
@@ -9,6 +9,7 @@ import { schedulingZh } from './slices/scheduling.js';
9
9
  import { interactionsZh } from './slices/interactions.js';
10
10
  import { startupZh } from './slices/startup.js';
11
11
  import { initZh } from './slices/init.js';
12
+ import { providersZh } from './slices/providers.js';
12
13
  /** Simplified-Chinese translations, aggregated from per-cluster slices. Must provide every
13
14
  * MessageKey (compiler-enforced via Record<MessageKey,string>) and add none. ${param}
14
15
  * placeholders and `code`/*bold* markdown are preserved verbatim from the en slices. */
@@ -20,4 +21,5 @@ export const zh = {
20
21
  ...interactionsZh,
21
22
  ...startupZh,
22
23
  ...initZh,
24
+ ...providersZh,
23
25
  };
@@ -0,0 +1,28 @@
1
+ import { type FSWatcher } from 'node:fs';
2
+ export declare const WATCH_FALLBACK_MS = 5000;
3
+ export interface WatchMonitor {
4
+ close(): void;
5
+ }
6
+ export interface ResilientWatchOptions {
7
+ label: string;
8
+ startWatching: () => FSWatcher[];
9
+ poll?: () => void;
10
+ warn?: (message: string) => void;
11
+ }
12
+ export interface SnapshotWatchOptions {
13
+ label: string;
14
+ snapshot: () => string | null;
15
+ startWatching: (onChange: () => void) => FSWatcher[];
16
+ onChange: () => void;
17
+ warn?: (message: string) => void;
18
+ }
19
+ export interface FileWatchOptions {
20
+ label: string;
21
+ filePath: string;
22
+ onChange: () => void;
23
+ warn?: (message: string) => void;
24
+ unref?: boolean;
25
+ }
26
+ export declare function createResilientWatchMonitor(options: ResilientWatchOptions): WatchMonitor;
27
+ export declare function createSnapshotWatchMonitor(options: SnapshotWatchOptions): WatchMonitor;
28
+ export declare function createFileWatchMonitor(options: FileWatchOptions): WatchMonitor;
@@ -0,0 +1,110 @@
1
+ // input: fs.watch factories and filesystem snapshots
2
+ // output: watcher monitors with polling fallback and cleanup
3
+ // pos: Shared resilient filesystem watch lifecycle
4
+ // >>> 一旦我被更新,务必更新我的开头注释与所属文件夹 CORTEX.md <<<
5
+ import { readFileSync, watch } from 'node:fs';
6
+ import { createHash } from 'node:crypto';
7
+ import path from 'node:path';
8
+ export const WATCH_FALLBACK_MS = 5_000;
9
+ function formatWatchError(error) {
10
+ if (!(error instanceof Error))
11
+ return String(error);
12
+ const code = error.code;
13
+ return code ? `${code}: ${error.message}` : error.message;
14
+ }
15
+ function closeWatchers(watchers) {
16
+ for (const watcher of watchers.splice(0)) {
17
+ try {
18
+ watcher.close();
19
+ }
20
+ catch { }
21
+ }
22
+ }
23
+ function pollSafely(options, warn) {
24
+ try {
25
+ options.poll?.();
26
+ }
27
+ catch (error) {
28
+ warn(`${options.label} polling failed (${formatWatchError(error)})`);
29
+ }
30
+ }
31
+ function startPolling(state, options, warn) {
32
+ state.pollTimer = setInterval(() => pollSafely(options, warn), WATCH_FALLBACK_MS);
33
+ state.pollTimer.unref?.();
34
+ }
35
+ function failWatchMonitor(state, options, warn, error) {
36
+ if (state.failed || state.closed)
37
+ return;
38
+ state.failed = true;
39
+ closeWatchers(state.watchers);
40
+ const detail = formatWatchError(error);
41
+ if (!options.poll)
42
+ return warn(`${options.label} watcher failed (${detail}); watcher disabled`);
43
+ warn(`${options.label} watcher failed (${detail}); polling every ${WATCH_FALLBACK_MS}ms`);
44
+ startPolling(state, options, warn);
45
+ }
46
+ function closeWatchMonitor(state) {
47
+ state.closed = true;
48
+ closeWatchers(state.watchers);
49
+ if (state.pollTimer)
50
+ clearInterval(state.pollTimer);
51
+ state.pollTimer = null;
52
+ }
53
+ export function createResilientWatchMonitor(options) {
54
+ const state = { watchers: [], pollTimer: null, failed: false, closed: false };
55
+ const warn = options.warn ?? console.warn;
56
+ const fallBack = (error) => failWatchMonitor(state, options, warn, error);
57
+ try {
58
+ state.watchers = options.startWatching();
59
+ for (const watcher of state.watchers)
60
+ watcher.on('error', fallBack);
61
+ }
62
+ catch (error) {
63
+ fallBack(error);
64
+ }
65
+ return { close: () => closeWatchMonitor(state) };
66
+ }
67
+ export function createSnapshotWatchMonitor(options) {
68
+ let observedSnapshot = options.snapshot();
69
+ const reconcile = () => {
70
+ const nextSnapshot = options.snapshot();
71
+ if (nextSnapshot === observedSnapshot)
72
+ return;
73
+ observedSnapshot = nextSnapshot;
74
+ options.onChange();
75
+ };
76
+ const monitor = createResilientWatchMonitor({
77
+ label: options.label,
78
+ startWatching: () => options.startWatching(reconcile),
79
+ poll: reconcile,
80
+ warn: options.warn,
81
+ });
82
+ reconcile();
83
+ return monitor;
84
+ }
85
+ function fileStamp(filePath) {
86
+ try {
87
+ return createHash('sha256').update(readFileSync(filePath)).digest('hex');
88
+ }
89
+ catch {
90
+ return null;
91
+ }
92
+ }
93
+ export function createFileWatchMonitor(options) {
94
+ const filename = path.basename(options.filePath);
95
+ return createSnapshotWatchMonitor({
96
+ label: options.label,
97
+ snapshot: () => fileStamp(options.filePath),
98
+ onChange: options.onChange,
99
+ warn: options.warn,
100
+ startWatching: (onChange) => {
101
+ const watcher = watch(path.dirname(options.filePath), (_event, changed) => {
102
+ if (changed === null || changed.toString() === filename)
103
+ onChange();
104
+ });
105
+ if (options.unref)
106
+ watcher.unref();
107
+ return [watcher];
108
+ },
109
+ });
110
+ }
@@ -1,13 +1,14 @@
1
- // input: CONFIG_DIR, settings spec, process env, filesystem
2
- // output: validated settings, disk updates, and test reset
3
- // pos: L0 file-backed runtime settings boundary
1
+ // input: CONFIG_DIR, settings spec, env, resilient file monitor
2
+ // output: validated settings, disk updates, hot reload, test reset
3
+ // pos: File-backed runtime settings boundary
4
4
  // >>> 一旦我被更新,务必更新我的开头注释与所属文件夹 CORTEX.md <<<
5
- import { readFileSync, watch } from 'node:fs';
5
+ import { readFileSync } from 'node:fs';
6
6
  import path from 'node:path';
7
7
  import { AsyncMutex } from './async-mutex.js';
8
8
  import { atomicWrite } from './atomic-write.js';
9
9
  import { createLogger } from './log.js';
10
10
  import { CONFIG_DIR } from './paths.js';
11
+ import { createFileWatchMonitor } from './resilient-watch.js';
11
12
  import { SETTINGS_SPEC, } from './settings-spec.js';
12
13
  export { SETTINGS_SPEC, } from './settings-spec.js';
13
14
  const log = createLogger('settings');
@@ -21,7 +22,7 @@ let initialized = false;
21
22
  let cachedOverrides = {};
22
23
  let cachedSettings = null;
23
24
  let cachedSettingsSnapshot = null;
24
- let settingsWatcher = null;
25
+ let settingsMonitor = null;
25
26
  let reloadTimer = null;
26
27
  let selfWriting = false;
27
28
  const typeValidators = {
@@ -153,20 +154,14 @@ function reloadSettings() {
153
154
  log.error(`Hot-reload settings.json failed: ${error.message} — keeping previous settings`);
154
155
  }
155
156
  }
156
- function handleWatchEvent(filename) {
157
- if (filename !== null && filename.toString() !== 'settings.json')
158
- return;
159
- scheduleReload();
160
- }
161
157
  function startWatcher() {
162
- try {
163
- settingsWatcher = watch(CONFIG_DIR, (_eventType, filename) => handleWatchEvent(filename));
164
- settingsWatcher.on('error', (error) => log.error('settings.json watcher failed:', error));
165
- settingsWatcher.unref();
166
- }
167
- catch (error) {
168
- log.error('Failed to watch settings.json:', error);
169
- }
158
+ settingsMonitor = createFileWatchMonitor({
159
+ label: 'settings.json',
160
+ filePath: SETTINGS_FILE,
161
+ onChange: scheduleReload,
162
+ warn: (message) => log.error(message),
163
+ unref: true,
164
+ });
170
165
  }
171
166
  function initialize() {
172
167
  if (initialized)
@@ -186,8 +181,8 @@ export function resetSettingsForTests() {
186
181
  if (reloadTimer)
187
182
  clearTimeout(reloadTimer);
188
183
  reloadTimer = null;
189
- settingsWatcher?.close();
190
- settingsWatcher = null;
184
+ settingsMonitor?.close();
185
+ settingsMonitor = null;
191
186
  initialized = false;
192
187
  cachedOverrides = {};
193
188
  cachedSettings = null;
@@ -6,6 +6,12 @@ export interface AuthNoticeAction {
6
6
  provider: string;
7
7
  authType: 'oauth' | 'api_key';
8
8
  }
9
+ /** A control the user can act on from a chat notice. Unlike AuthNoticeAction (an ephemeral
10
+ * live-tail hint) this is persisted with the message: the window it refers to can outlive a
11
+ * page reload by hours. */
12
+ export interface NoticeAction {
13
+ kind: 'cancel-resume';
14
+ }
9
15
  /** Backend-neutral snapshot of the tokens currently occupying an agent's context window. */
10
16
  export interface ContextUsage {
11
17
  usedTokens: number | null;
@@ -1,5 +1,5 @@
1
1
  import type { NormalizedEvent } from '../../agent-adapter/normalize/event-types.js';
2
- import type { AgentProcessSpawner, McpComposition } from '../../agent-adapter/types.js';
2
+ import type { AgentProcessSpawner, Backend, McpComposition } from '../../agent-adapter/types.js';
3
3
  export type ThreadId = string;
4
4
  export type AgentSlotId = string;
5
5
  export type ThreadStatus = 'running' | 'waiting' | 'rate_limited' | 'completed' | 'failed' | 'cancelled' | 'aborted';
@@ -404,17 +404,35 @@ export interface BenchmarkThreadEvent {
404
404
  event: NormalizedEvent;
405
405
  }
406
406
  export interface BenchmarkThreadRunOptions {
407
- /** Absolute grader workspace used by every benchmark step's backend process. */
407
+ /** Absolute shared writable grader workspace. It is the default cwd of a benchmark step's
408
+ * backend process, and the cwd of every step unless `resolveStepWorkspace` places that step
409
+ * somewhere else. */
408
410
  workspaceCwd: string;
409
411
  /** Frozen trial profile; benchmark templates cannot select a different identity. */
410
412
  resolvedProfileName: string;
411
- expectedBackend: 'claude';
413
+ /** The backend the trial's compiled arm declares. A step whose profile disagrees is a protocol
414
+ * violation, not a fallback. */
415
+ expectedBackend: Backend;
412
416
  expectedModel: string;
413
417
  disableHooks: true;
414
418
  disableControlPlane: true;
415
419
  failFastOnRateLimit: true;
416
420
  /** Optional containment-aware process boundary forwarded to every step. */
417
421
  spawner?: AgentProcessSpawner;
422
+ /** Per-step workspace placement: returns the cwd this step's backend process must run in.
423
+ * Absent → every step runs in `workspaceCwd`. */
424
+ resolveStepWorkspace?: (input: {
425
+ agentSlotId: AgentSlotId;
426
+ stepIndex: number;
427
+ }) => string;
428
+ /** Step-boundary settlement of whatever `resolveStepWorkspace` placed: invoked once per step
429
+ * after its process exited and before the next transition is evaluated, on the error path too. */
430
+ settleStepWorkspace?: (input: {
431
+ agentSlotId: AgentSlotId;
432
+ stepIndex: number;
433
+ stage: string | null;
434
+ terminalText: string | null;
435
+ }) => void;
418
436
  /** Required trajectory sink invoked synchronously for every normalized event. */
419
437
  requiredEventSink?: (input: BenchmarkThreadEvent) => void;
420
438
  limits?: {
@@ -26,6 +26,26 @@ declare function todayISO(): string;
26
26
  * `cortex-task lock-status`, `stats`, id-assignment, etc.).
27
27
  */
28
28
  declare function listProjectDirs(projectsDir?: string): string[];
29
+ /**
30
+ * Resolve the npm global prefix that an installed CLI actually lives under.
31
+ *
32
+ * `npm install/update -g` targets npm's *configured* prefix. When Cortex was installed
33
+ * with an explicit `--prefix ~/.npm-global` but no `prefix=` line was written to .npmrc,
34
+ * npm falls back to the system prefix (/usr/lib/node_modules), which is root-owned:
35
+ * self-update then dies with EACCES, and version probes report the package as missing.
36
+ *
37
+ * The installed binary is the ground truth — npm places it at `<prefix>/bin/<binName>`
38
+ * next to `<prefix>/lib/node_modules`. Walk PATH, find the binary, derive the prefix.
39
+ * `CORTEX_NPM_PREFIX` overrides. Returns null when nothing matches, so callers fall
40
+ * back to a plain `-g` (npm's own resolution).
41
+ */
42
+ declare function resolveNpmGlobalPrefix(binName: string, opts?: {
43
+ pathEnv?: string;
44
+ override?: string;
45
+ exists?: (p: string) => boolean;
46
+ }): string | null;
47
+ /** Append `--prefix <resolved>` to an npm argv when a prefix could be resolved. */
48
+ declare function withNpmPrefix(args: string[], binName: string): string[];
29
49
  /**
30
50
  * Sentinel ANTHROPIC_API_KEY value set when the gateway is healthy but no real key exists.
31
51
  * Its only purpose is to satisfy Claude Code's startup credential check on machines without
@@ -34,4 +54,4 @@ declare function listProjectDirs(projectsDir?: string): string[];
34
54
  * snapshots) must ignore this value.
35
55
  */
36
56
  declare const GATEWAY_MANAGED_KEY_PLACEHOLDER = "cortex-gateway-managed";
37
- export { INSTALL_ROOT, DEFAULTS_DIR, PACKAGE_ROOT, SERVER_ROOT, REPO_ROOT, DATA_DIR, CONFIG_DIR, STORE_DIR, CONTEXT_DIR, PROJECTS_DIR, WORKSPACE_DIR, resolveWorkspaceRelPath, PLUGINS_DIR, PROMPTS_DIR, HOOKS_DIR, SKIP_DIRS, GATEWAY_MANAGED_KEY_PLACEHOLDER, moduleDir, isMainModule, readableTimestamp, chunkText, formatDurationCompact, todayISO, listProjectDirs };
57
+ export { INSTALL_ROOT, DEFAULTS_DIR, PACKAGE_ROOT, SERVER_ROOT, REPO_ROOT, DATA_DIR, CONFIG_DIR, STORE_DIR, CONTEXT_DIR, PROJECTS_DIR, WORKSPACE_DIR, resolveWorkspaceRelPath, PLUGINS_DIR, PROMPTS_DIR, HOOKS_DIR, SKIP_DIRS, GATEWAY_MANAGED_KEY_PLACEHOLDER, moduleDir, isMainModule, readableTimestamp, chunkText, formatDurationCompact, todayISO, listProjectDirs, resolveNpmGlobalPrefix, withNpmPrefix };
@@ -1,6 +1,7 @@
1
1
  // input: nothing (leaf module)
2
2
  // output: INSTALL_ROOT / DEFAULTS_DIR / DATA_DIR / CONFIG_DIR / STORE_DIR / CONTEXT_DIR / PROJECTS_DIR / WORKSPACE_DIR / resolveWorkspaceRelPath / PLUGINS_DIR / PROMPTS_DIR / HOOKS_DIR
3
3
  // (deprecated re-exports: PACKAGE_ROOT, SERVER_ROOT, REPO_ROOT) + moduleDir + utility helpers
4
+ // + resolveNpmGlobalPrefix / withNpmPrefix (npm global prefix for self-update)
4
5
  // pos: cross-module shared constants and ESM/time/path utilities
5
6
  // >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
6
7
  import * as fs from 'fs';
@@ -95,6 +96,41 @@ function listProjectDirs(projectsDir = PROJECTS_DIR) {
95
96
  return [];
96
97
  }
97
98
  }
99
+ /**
100
+ * Resolve the npm global prefix that an installed CLI actually lives under.
101
+ *
102
+ * `npm install/update -g` targets npm's *configured* prefix. When Cortex was installed
103
+ * with an explicit `--prefix ~/.npm-global` but no `prefix=` line was written to .npmrc,
104
+ * npm falls back to the system prefix (/usr/lib/node_modules), which is root-owned:
105
+ * self-update then dies with EACCES, and version probes report the package as missing.
106
+ *
107
+ * The installed binary is the ground truth — npm places it at `<prefix>/bin/<binName>`
108
+ * next to `<prefix>/lib/node_modules`. Walk PATH, find the binary, derive the prefix.
109
+ * `CORTEX_NPM_PREFIX` overrides. Returns null when nothing matches, so callers fall
110
+ * back to a plain `-g` (npm's own resolution).
111
+ */
112
+ function resolveNpmGlobalPrefix(binName, opts = {}) {
113
+ const override = (opts.override ?? process.env.CORTEX_NPM_PREFIX)?.trim();
114
+ if (override)
115
+ return override;
116
+ const exists = opts.exists ?? fs.existsSync;
117
+ const pathEnv = opts.pathEnv ?? process.env.PATH ?? '';
118
+ for (const dir of pathEnv.split(path.delimiter)) {
119
+ if (!dir)
120
+ continue;
121
+ if (!exists(path.join(dir, binName)))
122
+ continue;
123
+ const prefix = path.dirname(dir); // <prefix>/bin/<binName> → <prefix>
124
+ if (exists(path.join(prefix, 'lib', 'node_modules')))
125
+ return prefix;
126
+ }
127
+ return null;
128
+ }
129
+ /** Append `--prefix <resolved>` to an npm argv when a prefix could be resolved. */
130
+ function withNpmPrefix(args, binName) {
131
+ const prefix = resolveNpmGlobalPrefix(binName);
132
+ return prefix ? [...args, '--prefix', prefix] : args;
133
+ }
98
134
  /**
99
135
  * Sentinel ANTHROPIC_API_KEY value set when the gateway is healthy but no real key exists.
100
136
  * Its only purpose is to satisfy Claude Code's startup credential check on machines without
@@ -103,4 +139,4 @@ function listProjectDirs(projectsDir = PROJECTS_DIR) {
103
139
  * snapshots) must ignore this value.
104
140
  */
105
141
  const GATEWAY_MANAGED_KEY_PLACEHOLDER = 'cortex-gateway-managed';
106
- export { INSTALL_ROOT, DEFAULTS_DIR, PACKAGE_ROOT, SERVER_ROOT, REPO_ROOT, DATA_DIR, CONFIG_DIR, STORE_DIR, CONTEXT_DIR, PROJECTS_DIR, WORKSPACE_DIR, resolveWorkspaceRelPath, PLUGINS_DIR, PROMPTS_DIR, HOOKS_DIR, SKIP_DIRS, GATEWAY_MANAGED_KEY_PLACEHOLDER, moduleDir, isMainModule, readableTimestamp, chunkText, formatDurationCompact, todayISO, listProjectDirs };
142
+ export { INSTALL_ROOT, DEFAULTS_DIR, PACKAGE_ROOT, SERVER_ROOT, REPO_ROOT, DATA_DIR, CONFIG_DIR, STORE_DIR, CONTEXT_DIR, PROJECTS_DIR, WORKSPACE_DIR, resolveWorkspaceRelPath, PLUGINS_DIR, PROMPTS_DIR, HOOKS_DIR, SKIP_DIRS, GATEWAY_MANAGED_KEY_PLACEHOLDER, moduleDir, isMainModule, readableTimestamp, chunkText, formatDurationCompact, todayISO, listProjectDirs, resolveNpmGlobalPrefix, withNpmPrefix };
@@ -7,7 +7,9 @@ import path from 'node:path';
7
7
  import { formatError, formatHelp } from '../../core/cli-utils.js';
8
8
  import { runOneShotAgent } from './runner.js';
9
9
  import { resolveSupervisorBinary } from './supervisor.js';
10
- const AGENT_SLOTS = ['parent', 'benchmark-coder', 'benchmark-reviewer'];
10
+ const AGENT_SLOTS = [
11
+ 'parent', 'benchmark-coder', 'benchmark-reviewer', 'benchmark-fixer',
12
+ ];
11
13
  const OUTPUT_FORMATS = ['jsonl'];
12
14
  const ROOT_RUN_ID_PATTERN = /^[A-Za-z0-9._-]+$/;
13
15
  const VALUE_FLAGS = new Set([
@@ -1,3 +1,7 @@
1
+ import type { ResolvedTrialPolicy } from '../benchmark/resolved-policy.js';
2
+ import { type ProposalIntent } from '../benchmark/variant-proposal.js';
3
+ import type { TrialThreadAdapterInput } from '../benchmark/trial-thread-adapter.js';
4
+ import { type CoderReviewVariant } from '../benchmark/workspace-lease.js';
1
5
  import { type LocalThreadRuntimeDeps } from '../threads/local-runtime-deps.js';
2
6
  interface BenchmarkThreadRequest {
3
7
  workspaceCwd: string;
@@ -7,6 +11,19 @@ interface BenchmarkThreadRequest {
7
11
  profileName: string;
8
12
  rootRunId: string;
9
13
  trajectoryRoot: string;
14
+ /** Absolute container path of the arm-resolution document the parent's `agent-run` was given.
15
+ * The production route always carries it — the `/2` thread-policy document makes it structurally
16
+ * required at the producer — and it is the single input the whole trial-adapter route is derived
17
+ * from. It stays optional here for the same reason `trialRoot` does: the requirement belongs at
18
+ * the producer, and enforcing it here would refuse the shipped policy-supplied route.
19
+ * Design section 16 (16.3.2) PW1 / PW1-PLACE. */
20
+ runConfigPath?: string;
21
+ /** Absolute trial root. Required for a variant that places a role in a disposable snapshot. */
22
+ trialRoot?: string;
23
+ /** Fixes each role's workspace placement. Absent → every step runs in the shared workspace. */
24
+ coderReviewVariant?: CoderReviewVariant;
25
+ /** The frozen trial policy this thread runs under. Absent → the shipped single-backend path. */
26
+ trialPolicy?: ResolvedTrialPolicy;
10
27
  limits: {
11
28
  maxSteps: number;
12
29
  maxCostUsd: number;
@@ -27,6 +44,20 @@ export interface BenchmarkThreadResult {
27
44
  costUsd: number;
28
45
  durationMs: number;
29
46
  summary: string;
47
+ /** What this pipeline concluded, decided and never applied. Null for a run that declares no
48
+ * coder-review variant and therefore has no verdict-speaking role. */
49
+ proposal: ProposalIntent | null;
30
50
  }
51
+ /**
52
+ * Everything the per-step trial adapter needs, derived from the two paths the request carries and
53
+ * from nothing else: the compiled policy and the resolved run config from ONE call of the shipped
54
+ * loader over the arm-resolution document, the pinned trial paths from the trial root, and the
55
+ * supervisor from the shipped resolver. The policy is RE-COMPILED here, in the process that will
56
+ * run the thread, rather than transported — which is what makes the parent role-hash equality a
57
+ * comparison of two independent compiles instead of a tautology. A request that carried a
58
+ * pre-built `ResolvedAgentRunConfig`, `PinnedTrialPaths` or supervisor descriptor would let a
59
+ * caller supply what production must derive. Design section 16 (16.3.2) PW1 and PW2.
60
+ */
61
+ export declare function trialThreadAdapterInput(runConfigPath: string, trialRoot: string): TrialThreadAdapterInput;
31
62
  export declare function runBenchmarkThread(request: BenchmarkThreadRequest, overrides?: Partial<LocalThreadRuntimeDeps>): Promise<BenchmarkThreadResult>;
32
63
  export {};