@cortex-agent/server 2026.7.30 → 2026.8.3-2

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 (353) hide show
  1. package/README.md +1 -1
  2. package/defaults/CORTEX.md +1 -0
  3. package/defaults/config/CORTEX.md +2 -1
  4. package/defaults/config/hooks/13-status-md-guard.json +11 -0
  5. package/defaults/config/hooks/CORTEX.md +1 -0
  6. package/defaults/config/mcp-config-empty.json +3 -0
  7. package/defaults/config/thread-templates/agents/benchmark-coder.json +22 -0
  8. package/defaults/config/thread-templates/agents/benchmark-reviewer.json +22 -0
  9. package/defaults/config/thread-templates/agents/coder-reviewer.json +4 -9
  10. package/defaults/config/thread-templates/agents/coder.json +4 -14
  11. package/defaults/config/thread-templates/templates/benchmark-coder-review.json +37 -0
  12. package/defaults/config/thread-templates/templates/coder-review.json +3 -27
  13. package/defaults/context/projects/CORTEX.md +1 -1
  14. package/defaults/data/schedules.json +12 -0
  15. package/defaults/hooks/CORTEX.md +1 -0
  16. package/defaults/hooks/new-session-hook.mjs +2 -2
  17. package/defaults/hooks/status-md-guard.mjs +193 -0
  18. package/defaults/plugins/cortex-coder/.claude-plugin/plugin.json +1 -1
  19. package/defaults/plugins/cortex-coder/skills/develop/SKILL.md +28 -2
  20. package/defaults/plugins/cortex-common/.claude-plugin/plugin.json +1 -1
  21. package/defaults/plugins/cortex-common/skills/compound/SKILL.md +1 -1
  22. package/defaults/plugins/cortex-common/skills/compound-simple/SKILL.md +4 -2
  23. package/defaults/plugins/cortex-common/skills/postmortem/SKILL.md +1 -1
  24. package/defaults/plugins/cortex-stage-gate/.claude-plugin/plugin.json +1 -1
  25. package/defaults/plugins/cortex-stage-gate/skills/director-method/SKILL.md +1 -1
  26. package/defaults/plugins/cortex-stage-gate/skills/need-approval/SKILL.md +1 -0
  27. package/defaults/plugins/cortex-stage-gate/skills/reorient/SKILL.md +2 -2
  28. package/defaults/plugins/cortex-stage-gate/skills/task/SKILL.md +11 -8
  29. package/defaults/plugins/cortex-system/skills/feedback/SKILL.md +1 -1
  30. package/defaults/plugins/cortex-system/skills/project-init/SKILL.md +13 -16
  31. package/defaults/prompts/directives/coder-reviewer.md +24 -20
  32. package/defaults/prompts/directives/coder.md +4 -5
  33. package/defaults/prompts/directives/director.md +4 -10
  34. package/defaults/prompts/directives/manager.md +9 -10
  35. package/defaults/prompts/systemPrompts/worker.md +2 -2
  36. package/defaults/rules/cortex-md.md +31 -0
  37. package/defaults/rules/experiment-format.md +8 -1
  38. package/defaults/rules/issues-md.md +10 -9
  39. package/defaults/rules/meta-conventions.md +5 -4
  40. package/defaults/rules/mission-md.md +2 -1
  41. package/defaults/rules/status-md.md +39 -21
  42. package/dist/agent-adapter/bg-wait.d.ts +10 -12
  43. package/dist/agent-adapter/bg-wait.js +209 -129
  44. package/dist/agent-adapter/claude/adapter-tui.d.ts +3 -1
  45. package/dist/agent-adapter/claude/adapter-tui.js +8 -5
  46. package/dist/agent-adapter/claude/adapter.d.ts +43 -14
  47. package/dist/agent-adapter/claude/adapter.js +276 -161
  48. package/dist/agent-adapter/claude/defaults.d.ts +2 -0
  49. package/dist/agent-adapter/claude/defaults.js +5 -5
  50. package/dist/agent-adapter/claude/event-parser.d.ts +3 -8
  51. package/dist/agent-adapter/claude/event-parser.js +28 -31
  52. package/dist/agent-adapter/claude/hooks-builder.js +4 -3
  53. package/dist/agent-adapter/claude/jsonl-tail.js +54 -35
  54. package/dist/agent-adapter/claude/spawn-args.d.ts +15 -12
  55. package/dist/agent-adapter/claude/spawn-args.js +44 -38
  56. package/dist/agent-adapter/claude/tmux-control.d.ts +4 -17
  57. package/dist/agent-adapter/claude/tmux-control.js +39 -32
  58. package/dist/agent-adapter/event-tee.d.ts +19 -0
  59. package/dist/agent-adapter/event-tee.js +145 -0
  60. package/dist/agent-adapter/index.d.ts +1 -0
  61. package/dist/agent-adapter/index.js +7 -3
  62. package/dist/agent-adapter/normalize/event-types.d.ts +17 -9
  63. package/dist/agent-adapter/normalize/event-types.js +4 -4
  64. package/dist/agent-adapter/pi/adapter.d.ts +16 -4
  65. package/dist/agent-adapter/pi/adapter.js +69 -36
  66. package/dist/agent-adapter/pi/discovery.d.ts +19 -3
  67. package/dist/agent-adapter/pi/discovery.js +81 -43
  68. package/dist/agent-adapter/pi/event-parser.js +4 -2
  69. package/dist/agent-adapter/pi/spawn-args.d.ts +2 -4
  70. package/dist/agent-adapter/pi/spawn-args.js +6 -5
  71. package/dist/agent-adapter/types.d.ts +43 -2
  72. package/dist/agent-adapter/types.js +8 -4
  73. package/dist/core/atomic-write.d.ts +6 -1
  74. package/dist/core/atomic-write.js +183 -7
  75. package/dist/core/cli-utils.d.ts +15 -2
  76. package/dist/core/cli-utils.js +46 -41
  77. package/dist/core/config-generator.d.ts +4 -0
  78. package/dist/core/config-generator.js +34 -21
  79. package/dist/core/json-repository.d.ts +4 -0
  80. package/dist/core/json-repository.js +6 -3
  81. package/dist/core/locales/en.d.ts +94 -0
  82. package/dist/core/locales/slices/commands.d.ts +76 -0
  83. package/dist/core/locales/slices/commands.js +155 -1
  84. package/dist/core/locales/slices/status.d.ts +18 -0
  85. package/dist/core/locales/slices/status.js +43 -2
  86. package/dist/core/log.d.ts +5 -0
  87. package/dist/core/log.js +25 -23
  88. package/dist/core/pi-session-filename.d.ts +2 -0
  89. package/dist/core/pi-session-filename.js +18 -0
  90. package/dist/core/resume-reminder.d.ts +5 -0
  91. package/dist/core/resume-reminder.js +18 -0
  92. package/dist/core/runtime-env.d.ts +1 -0
  93. package/dist/core/runtime-env.js +15 -0
  94. package/dist/core/settings-migration.d.ts +5 -0
  95. package/dist/core/settings-migration.js +128 -0
  96. package/dist/core/settings-spec.d.ts +174 -0
  97. package/dist/core/settings-spec.js +150 -0
  98. package/dist/core/settings.d.ts +10 -0
  99. package/dist/core/settings.js +235 -0
  100. package/dist/core/task-parser.d.ts +11 -1
  101. package/dist/core/task-parser.js +34 -3
  102. package/dist/core/types/agent-types.d.ts +19 -0
  103. package/dist/core/types/agent-types.js +1 -1
  104. package/dist/core/types/thread-types.d.ts +48 -3
  105. package/dist/core/types/thread-types.js +2 -2
  106. package/dist/core/utils.d.ts +21 -1
  107. package/dist/core/utils.js +37 -1
  108. package/dist/domain/agent-run/access-probe-cli.d.ts +7 -0
  109. package/dist/domain/agent-run/access-probe-cli.js +139 -0
  110. package/dist/domain/agent-run/access-probe-policy.d.ts +61 -0
  111. package/dist/domain/agent-run/access-probe-policy.js +614 -0
  112. package/dist/domain/agent-run/access-probe.d.ts +21 -0
  113. package/dist/domain/agent-run/access-probe.js +194 -0
  114. package/dist/domain/agent-run/agent-run-cli.d.ts +19 -0
  115. package/dist/domain/agent-run/agent-run-cli.js +171 -0
  116. package/dist/domain/agent-run/atif.d.ts +54 -0
  117. package/dist/domain/agent-run/atif.js +211 -0
  118. package/dist/domain/agent-run/benchmark-local-thread-orchestrator.d.ts +32 -0
  119. package/dist/domain/agent-run/benchmark-local-thread-orchestrator.js +616 -0
  120. package/dist/domain/agent-run/benchmark-thread-identity.d.ts +34 -0
  121. package/dist/domain/agent-run/benchmark-thread-identity.js +106 -0
  122. package/dist/domain/agent-run/identity.d.ts +62 -0
  123. package/dist/domain/agent-run/identity.js +118 -0
  124. package/dist/domain/agent-run/journal.d.ts +51 -0
  125. package/dist/domain/agent-run/journal.js +259 -0
  126. package/dist/domain/agent-run/manifest-contract.d.ts +44 -0
  127. package/dist/domain/agent-run/manifest-contract.js +134 -0
  128. package/dist/domain/agent-run/manifest.d.ts +51 -0
  129. package/dist/domain/agent-run/manifest.js +801 -0
  130. package/dist/domain/agent-run/pinned-node-process.d.ts +35 -0
  131. package/dist/domain/agent-run/pinned-node-process.js +206 -0
  132. package/dist/domain/agent-run/role-surface.d.ts +4 -0
  133. package/dist/domain/agent-run/role-surface.js +99 -0
  134. package/dist/domain/agent-run/run-config.d.ts +22 -0
  135. package/dist/domain/agent-run/run-config.js +135 -0
  136. package/dist/domain/agent-run/runner.d.ts +7 -0
  137. package/dist/domain/agent-run/runner.js +518 -0
  138. package/dist/domain/agent-run/supervisor.d.ts +78 -0
  139. package/dist/domain/agent-run/supervisor.js +425 -0
  140. package/dist/domain/agent-run/trajectory-merge-cli.d.ts +11 -0
  141. package/dist/domain/agent-run/trajectory-merge-cli.js +111 -0
  142. package/dist/domain/agent-run/trajectory-merge.d.ts +39 -0
  143. package/dist/domain/agent-run/trajectory-merge.js +505 -0
  144. package/dist/domain/agents/config.d.ts +10 -0
  145. package/dist/domain/agents/config.js +149 -44
  146. package/dist/domain/agents/facade.d.ts +42 -7
  147. package/dist/domain/agents/facade.js +174 -170
  148. package/dist/domain/agents/provider-run-lifecycle.d.ts +18 -0
  149. package/dist/domain/agents/provider-run-lifecycle.js +60 -0
  150. package/dist/domain/auth/auth-events.d.ts +18 -0
  151. package/dist/domain/auth/auth-events.js +38 -0
  152. package/dist/domain/auth/auth-format.d.ts +2 -0
  153. package/dist/domain/auth/auth-format.js +58 -0
  154. package/dist/domain/auth/auth-status.d.ts +61 -0
  155. package/dist/domain/auth/auth-status.js +304 -0
  156. package/dist/domain/auth/auth-watch.d.ts +16 -0
  157. package/dist/domain/auth/auth-watch.js +125 -0
  158. package/dist/domain/auth/cc-login.d.ts +7 -0
  159. package/dist/domain/auth/cc-login.js +16 -0
  160. package/dist/domain/auth/cc-subscription.d.ts +38 -0
  161. package/dist/domain/auth/cc-subscription.js +204 -0
  162. package/dist/domain/auth/index.d.ts +12 -0
  163. package/dist/domain/auth/index.js +16 -0
  164. package/dist/domain/auth/login-flow.d.ts +120 -0
  165. package/dist/domain/auth/login-flow.js +253 -0
  166. package/dist/domain/auth/login-service.d.ts +32 -0
  167. package/dist/domain/auth/login-service.js +97 -0
  168. package/dist/domain/auth/logout.d.ts +32 -0
  169. package/dist/domain/auth/logout.js +123 -0
  170. package/dist/domain/auth/pi-login.d.ts +36 -0
  171. package/dist/domain/auth/pi-login.js +72 -0
  172. package/dist/domain/auth/pi-oauth.d.ts +36 -0
  173. package/dist/domain/auth/pi-oauth.js +84 -0
  174. package/dist/domain/auth/pi-runtime.d.ts +72 -0
  175. package/dist/domain/auth/pi-runtime.js +86 -0
  176. package/dist/domain/mcp/benchmark-thread-server.d.ts +1 -0
  177. package/dist/domain/mcp/benchmark-thread-server.js +26 -0
  178. package/dist/domain/mcp/tools/benchmark-thread-run.d.ts +23 -0
  179. package/dist/domain/mcp/tools/benchmark-thread-run.js +146 -0
  180. package/dist/domain/memory/user-context.js +6 -8
  181. package/dist/domain/monitor/disk-monitor.js +47 -16
  182. package/dist/domain/projects/project-store.js +23 -6
  183. package/dist/domain/remote/client-hot-reload.d.ts +9 -1
  184. package/dist/domain/remote/client-hot-reload.js +60 -12
  185. package/dist/domain/remote/client-manager.js +12 -6
  186. package/dist/domain/scheduling/jobs/auth-expiry-scan.d.ts +14 -0
  187. package/dist/domain/scheduling/jobs/auth-expiry-scan.js +86 -0
  188. package/dist/domain/scheduling/jobs/task-dispatch.js +36 -40
  189. package/dist/domain/scheduling/runner.d.ts +2 -0
  190. package/dist/domain/scheduling/runner.js +7 -4
  191. package/dist/domain/sessions/session-backup.d.ts +14 -20
  192. package/dist/domain/sessions/session-backup.js +57 -68
  193. package/dist/domain/system/doctor.d.ts +4 -0
  194. package/dist/domain/system/doctor.js +113 -28
  195. package/dist/domain/system/install-cli.js +8 -3
  196. package/dist/domain/system/server-update-check.js +7 -5
  197. package/dist/domain/system/system-notice.d.ts +3 -1
  198. package/dist/domain/system/system-notice.js +6 -11
  199. package/dist/domain/tasks/archiver.d.ts +1 -0
  200. package/dist/domain/tasks/archiver.js +13 -7
  201. package/dist/domain/tasks/claim-recovery.d.ts +3 -3
  202. package/dist/domain/tasks/claim-recovery.js +12 -8
  203. package/dist/domain/tasks/dispatch-utils.d.ts +15 -14
  204. package/dist/domain/tasks/dispatch-utils.js +22 -18
  205. package/dist/domain/tasks/dispatcher.d.ts +1 -0
  206. package/dist/domain/tasks/dispatcher.js +9 -5
  207. package/dist/domain/tasks/mutator.d.ts +21 -11
  208. package/dist/domain/tasks/mutator.js +30 -24
  209. package/dist/domain/tasks/pending-tracker.d.ts +5 -2
  210. package/dist/domain/tasks/pending-tracker.js +11 -5
  211. package/dist/domain/tasks/system/cortex-run.d.ts +2 -1
  212. package/dist/domain/tasks/system/cortex-run.js +24 -4
  213. package/dist/domain/tasks/system/task-cli.d.ts +1 -0
  214. package/dist/domain/tasks/system/task-cli.js +72 -22
  215. package/dist/domain/tasks/system/task-completion.d.ts +19 -2
  216. package/dist/domain/tasks/system/task-completion.js +31 -17
  217. package/dist/domain/tasks/system/task-file-input.d.ts +10 -0
  218. package/dist/domain/tasks/system/task-file-input.js +57 -0
  219. package/dist/domain/tasks/system/task-id-utils.d.ts +9 -9
  220. package/dist/domain/tasks/system/task-id-utils.js +13 -4
  221. package/dist/domain/tasks/system/task-lifecycle-edit.d.ts +6 -2
  222. package/dist/domain/tasks/system/task-lifecycle-edit.js +200 -6
  223. package/dist/domain/tasks/system/task-lock.js +19 -5
  224. package/dist/domain/tasks/system/task-mutations.d.ts +22 -12
  225. package/dist/domain/tasks/system/task-mutations.js +28 -4
  226. package/dist/domain/tasks/system/task-process.js +10 -8
  227. package/dist/domain/tasks/system/task-state.d.ts +65 -11
  228. package/dist/domain/tasks/system/task-state.js +86 -13
  229. package/dist/domain/threads/local-runtime-deps.d.ts +32 -0
  230. package/dist/domain/threads/local-runtime-deps.js +91 -0
  231. package/dist/domain/threads/local-runtime-scope.d.ts +6 -0
  232. package/dist/domain/threads/local-runtime-scope.js +12 -0
  233. package/dist/domain/threads/pending-user-inputs.d.ts +3 -0
  234. package/dist/domain/threads/pending-user-inputs.js +37 -0
  235. package/dist/domain/threads/prompt-builder.d.ts +12 -1
  236. package/dist/domain/threads/prompt-builder.js +73 -26
  237. package/dist/domain/threads/runner.d.ts +15 -3
  238. package/dist/domain/threads/runner.js +261 -105
  239. package/dist/domain/threads/state-machine.d.ts +1 -1
  240. package/dist/domain/threads/state-machine.js +17 -8
  241. package/dist/domain/ui-service/app-router.d.ts +86 -6
  242. package/dist/domain/ui-service/app-router.js +171 -133
  243. package/dist/domain/ui-service/input-schemas.d.ts +132 -10
  244. package/dist/domain/ui-service/input-schemas.js +59 -5
  245. package/dist/domain/ui-service/mutate/approvals.d.ts +2 -1
  246. package/dist/domain/ui-service/mutate/approvals.js +2 -1
  247. package/dist/domain/ui-service/mutate/auth.d.ts +6 -0
  248. package/dist/domain/ui-service/mutate/auth.js +83 -0
  249. package/dist/domain/ui-service/mutate/config.js +11 -10
  250. package/dist/domain/ui-service/query/approvals.js +3 -0
  251. package/dist/domain/ui-service/query/auth.d.ts +6 -0
  252. package/dist/domain/ui-service/query/auth.js +12 -0
  253. package/dist/domain/ui-service/query/config.d.ts +5 -5
  254. package/dist/domain/ui-service/query/config.js +27 -17
  255. package/dist/domain/ui-service/query/tasks.d.ts +1 -1
  256. package/dist/domain/ui-service/query/tasks.js +69 -30
  257. package/dist/domain/ui-service/query/threads.js +3 -3
  258. package/dist/domain/ui-service/types.d.ts +67 -8
  259. package/dist/domain/ui-service/types.js +2 -2
  260. package/dist/domain/ui-service/ui-service.js +16 -2
  261. package/dist/entry/admin-channel-hot-reload.d.ts +4 -0
  262. package/dist/entry/admin-channel-hot-reload.js +22 -0
  263. package/dist/entry/app.js +38 -38
  264. package/dist/entry/auth-cli.d.ts +10 -0
  265. package/dist/entry/auth-cli.js +52 -0
  266. package/dist/entry/cli-help.d.ts +5 -0
  267. package/dist/entry/cli-help.js +130 -0
  268. package/dist/entry/cli.d.ts +5 -5
  269. package/dist/entry/cli.js +174 -248
  270. package/dist/entry/daemon.d.ts +11 -0
  271. package/dist/entry/daemon.js +204 -103
  272. package/dist/entry/draft-attachments.d.ts +8 -0
  273. package/dist/entry/draft-attachments.js +83 -0
  274. package/dist/entry/feishu-login.d.ts +2 -6
  275. package/dist/entry/feishu-login.js +16 -21
  276. package/dist/entry/init.js +6 -4
  277. package/dist/entry/start-ui-http.d.ts +2 -8
  278. package/dist/entry/start-ui-http.js +7 -34
  279. package/dist/events/event-logger.js +11 -13
  280. package/dist/events/event-types.d.ts +19 -1
  281. package/dist/events/event-types.js +3 -3
  282. package/dist/events/index.d.ts +1 -1
  283. package/dist/events/index.js +3 -3
  284. package/dist/hooks/new-session-hook.mjs +2 -2
  285. package/dist/hooks/status-md-guard.mjs +193 -0
  286. package/dist/orchestration/agent-file-send.js +44 -14
  287. package/dist/orchestration/agent-runner.d.ts +7 -3
  288. package/dist/orchestration/agent-runner.js +65 -41
  289. package/dist/orchestration/conversation-runner.d.ts +5 -1
  290. package/dist/orchestration/conversation-runner.js +16 -7
  291. package/dist/orchestration/lifecycle.d.ts +23 -1
  292. package/dist/orchestration/lifecycle.js +103 -40
  293. package/dist/orchestration/mid-turn-inject.d.ts +2 -0
  294. package/dist/orchestration/mid-turn-inject.js +29 -13
  295. package/dist/orchestration/resume-dispatcher.d.ts +3 -5
  296. package/dist/orchestration/resume-dispatcher.js +9 -17
  297. package/dist/orchestration/routing/commands/index.d.ts +4 -1
  298. package/dist/orchestration/routing/commands/index.js +83 -61
  299. package/dist/orchestration/routing/commands/login-notice.d.ts +21 -0
  300. package/dist/orchestration/routing/commands/login-notice.js +97 -0
  301. package/dist/orchestration/routing/commands/login.d.ts +12 -0
  302. package/dist/orchestration/routing/commands/login.js +555 -0
  303. package/dist/orchestration/routing/commands/status.js +45 -59
  304. package/dist/orchestration/routing/edit-handler.d.ts +5 -0
  305. package/dist/orchestration/routing/edit-handler.js +127 -73
  306. package/dist/orchestration/routing/webhook.js +5 -4
  307. package/dist/orchestration/session-rewind.d.ts +5 -1
  308. package/dist/orchestration/session-rewind.js +106 -62
  309. package/dist/orchestration/session-send.d.ts +2 -0
  310. package/dist/orchestration/session-send.js +5 -6
  311. package/dist/orchestration/status-helpers.d.ts +1 -2
  312. package/dist/orchestration/status-helpers.js +7 -10
  313. package/dist/orchestration/thread-callback.d.ts +19 -11
  314. package/dist/orchestration/thread-callback.js +132 -61
  315. package/dist/orchestration/thread-executor.js +37 -27
  316. package/dist/orchestration/turn-mutation-lock.d.ts +3 -0
  317. package/dist/orchestration/turn-mutation-lock.js +36 -0
  318. package/dist/orchestration/turn-notify.d.ts +2 -5
  319. package/dist/orchestration/turn-notify.js +9 -21
  320. package/dist/platform/adapter.d.ts +1 -0
  321. package/dist/platform/adapter.js +2 -2
  322. package/dist/platform/adapters/composite-adapter.d.ts +2 -0
  323. package/dist/platform/adapters/composite-adapter.js +13 -3
  324. package/dist/platform/adapters/feishu.d.ts +2 -4
  325. package/dist/platform/adapters/feishu.js +38 -59
  326. package/dist/platform/adapters/index.d.ts +1 -1
  327. package/dist/platform/adapters/index.js +13 -12
  328. package/dist/platform/adapters/slack.d.ts +1 -1
  329. package/dist/platform/adapters/slack.js +12 -35
  330. package/dist/platform/index.d.ts +2 -1
  331. package/dist/platform/index.js +3 -3
  332. package/dist/platform/testing.d.ts +1 -0
  333. package/dist/platform/testing.js +13 -4
  334. package/dist/platform/tool-trace.js +6 -11
  335. package/dist/platform/ui-http/ui-http-server.d.ts +1 -1
  336. package/dist/platform/ui-http/ui-http-server.js +6 -18
  337. package/dist/store/execution-repo.d.ts +17 -1
  338. package/dist/store/execution-repo.js +55 -4
  339. package/dist/store/prompt-migration-replacements.d.ts +4 -0
  340. package/dist/store/prompt-migration-replacements.js +149 -0
  341. package/dist/store/thread-repo.d.ts +15 -4
  342. package/dist/store/thread-repo.js +61 -24
  343. package/dist/store/version-migrations.js +36 -1
  344. package/native/cortex-supervisor/dist/build-manifest.json +22 -0
  345. package/native/cortex-supervisor/dist/cortex-supervisor +0 -0
  346. package/package.json +5 -2
  347. package/web/dist/assets/index-XqBCYtkw.js +139 -0
  348. package/web/dist/assets/index-zpf3OSKC.css +1 -0
  349. package/web/dist/index.html +2 -2
  350. package/dist/domain/scheduling/jobs/failed-dispatch-reconciliation.d.ts +0 -1
  351. package/dist/domain/scheduling/jobs/failed-dispatch-reconciliation.js +0 -78
  352. package/web/dist/assets/index-B19jLgji.js +0 -138
  353. package/web/dist/assets/index-BuFyPyRW.css +0 -1
@@ -0,0 +1,35 @@
1
+ import { type ChildProcess, type StdioOptions } from 'node:child_process';
2
+ export declare const PINNED_RUNTIME_PATH: string;
3
+ export declare const PINNED_ENV_KEYS: readonly ["CLAUDE_CONFIG_DIR", "CORTEX_HOME", "CORTEX_PROJECTS_DIR", "HOME", "TEMP", "TMP", "TMPDIR", "XDG_CACHE_HOME", "XDG_CONFIG_HOME"];
4
+ export interface PinnedTrialPaths {
5
+ root: string;
6
+ home: string;
7
+ cortexHome: string;
8
+ projectsDir: string;
9
+ xdgConfigHome: string;
10
+ xdgCacheHome: string;
11
+ claudeConfigDir: string;
12
+ tempDir: string;
13
+ logsDir: string;
14
+ }
15
+ export interface PinnedNodeLaunchOptions {
16
+ trialRoot: string;
17
+ workspaceCwd: string;
18
+ entry: string;
19
+ args?: string[];
20
+ nodeArgs?: string[];
21
+ parentEnv?: NodeJS.ProcessEnv;
22
+ passthroughEnv?: string[];
23
+ stdio?: StdioOptions;
24
+ }
25
+ export interface PinnedNodeLaunchSpec {
26
+ command: string;
27
+ args: string[];
28
+ cwd: string;
29
+ env: NodeJS.ProcessEnv;
30
+ stdio: StdioOptions;
31
+ paths: PinnedTrialPaths;
32
+ }
33
+ export declare function preparePinnedTrialPaths(trialRoot: string): PinnedTrialPaths;
34
+ export declare function preparePinnedNodeLaunch(options: PinnedNodeLaunchOptions): PinnedNodeLaunchSpec;
35
+ export declare function spawnPinnedNode(options: PinnedNodeLaunchOptions): ChildProcess;
@@ -0,0 +1,206 @@
1
+ // input: trial root, Node entry, allowlisted parent runtime env
2
+ // output: canonical trial paths, exact child env and process spec
3
+ // pos: Fresh-process boundary for benchmark Node entries
4
+ // >>> If I am updated, update my header and folder CORTEX.md <<<
5
+ import { spawn } from 'node:child_process';
6
+ import fs from 'node:fs';
7
+ import os from 'node:os';
8
+ import path from 'node:path';
9
+ import { fileURLToPath } from 'node:url';
10
+ export const PINNED_RUNTIME_PATH = [
11
+ path.dirname(process.execPath),
12
+ '/usr/local/bin',
13
+ '/usr/bin',
14
+ '/bin',
15
+ ].filter((value, index, values) => values.indexOf(value) === index).join(path.delimiter);
16
+ export const PINNED_ENV_KEYS = [
17
+ 'CLAUDE_CONFIG_DIR',
18
+ 'CORTEX_HOME',
19
+ 'CORTEX_PROJECTS_DIR',
20
+ 'HOME',
21
+ 'TEMP',
22
+ 'TMP',
23
+ 'TMPDIR',
24
+ 'XDG_CACHE_HOME',
25
+ 'XDG_CONFIG_HOME',
26
+ ];
27
+ const INHERITED_ENV_KEYS = new Set(['LANG', 'TZ', 'TERM', 'NODE_ENV']);
28
+ const NEVER_INHERIT = new Set(['NODE_OPTIONS', 'NODE_PATH', 'NODE_EXTRA_CA_CERTS']);
29
+ const ENV_KEY = /^[A-Za-z_][A-Za-z0-9_]*$/;
30
+ function isInheritedRuntimeKey(key) {
31
+ return INHERITED_ENV_KEYS.has(key) || key.startsWith('LC_');
32
+ }
33
+ function splitPathValues(part) {
34
+ const token = part.includes('=') ? part.slice(part.lastIndexOf('=') + 1) : part;
35
+ if (token.includes('://'))
36
+ return [token];
37
+ return token.split(path.delimiter);
38
+ }
39
+ function tokenPath(token, cwd) {
40
+ const unquoted = token.replace(/^["']|["']$/g, '');
41
+ if (unquoted.startsWith('file://')) {
42
+ try {
43
+ return fileURLToPath(unquoted);
44
+ }
45
+ catch {
46
+ return null;
47
+ }
48
+ }
49
+ if (!unquoted.includes('/') || unquoted.includes('://'))
50
+ return null;
51
+ return path.isAbsolute(unquoted) ? path.resolve(unquoted) : path.resolve(cwd, unquoted);
52
+ }
53
+ function pathCandidates(value, cwd) {
54
+ return value.split(/[\s,;]+/).flatMap(splitPathValues)
55
+ .map(token => tokenPath(token, cwd)).filter((item) => item !== null);
56
+ }
57
+ function physicalPath(value, depth = 0) {
58
+ const absolute = path.resolve(value);
59
+ if (depth >= 40)
60
+ return absolute;
61
+ let cursor = absolute;
62
+ const suffix = [];
63
+ while (true) {
64
+ try {
65
+ return path.join(fs.realpathSync(cursor), ...suffix);
66
+ }
67
+ catch { }
68
+ try {
69
+ if (fs.lstatSync(cursor).isSymbolicLink()) {
70
+ const target = fs.readlinkSync(cursor);
71
+ const resolved = path.isAbsolute(target) ? target : path.resolve(path.dirname(cursor), target);
72
+ return physicalPath(path.join(resolved, ...suffix), depth + 1);
73
+ }
74
+ }
75
+ catch { }
76
+ const parent = path.dirname(cursor);
77
+ if (parent === cursor)
78
+ return absolute;
79
+ suffix.unshift(path.basename(cursor));
80
+ cursor = parent;
81
+ }
82
+ }
83
+ function isWithin(candidate, root) {
84
+ const relative = path.relative(path.resolve(root), path.resolve(candidate));
85
+ return relative === '' || (!relative.startsWith(`..${path.sep}`) && relative !== '..'
86
+ && !path.isAbsolute(relative));
87
+ }
88
+ function referencesForbiddenRoot(value, cwd, paths, parentEnv) {
89
+ const roots = [os.homedir(), parentEnv.CORTEX_HOME].filter((root) => typeof root === 'string' && root.length > 0);
90
+ const trialRoot = physicalPath(paths.root);
91
+ return pathCandidates(value, cwd).some((candidate) => {
92
+ const physical = physicalPath(candidate);
93
+ return !isWithin(physical, trialRoot)
94
+ && roots.some(root => isWithin(physical, physicalPath(root)));
95
+ });
96
+ }
97
+ function assertPassthrough(key, value, cwd, paths, parentEnv) {
98
+ if (!ENV_KEY.test(key))
99
+ throw new Error(`Invalid passthrough environment key: ${key}`);
100
+ if (PINNED_ENV_KEYS.includes(key)) {
101
+ throw new Error(`Cannot passthrough pinned environment key: ${key}`);
102
+ }
103
+ if (NEVER_INHERIT.has(key) || key.startsWith('NODE_REPL_')) {
104
+ throw new Error(`Unsafe Node environment key cannot be inherited: ${key}`);
105
+ }
106
+ if (referencesForbiddenRoot(value, cwd, paths, parentEnv)) {
107
+ throw new Error(`Passthrough ${key} references a forbidden host root`);
108
+ }
109
+ }
110
+ function passthroughEnvironment(names, parentEnv, paths, cwd) {
111
+ const result = {};
112
+ for (const name of names) {
113
+ const value = parentEnv[name];
114
+ if (value === undefined)
115
+ continue;
116
+ assertPassthrough(name, value, cwd, paths, parentEnv);
117
+ result[name] = value;
118
+ }
119
+ return result;
120
+ }
121
+ function inheritedEnvironment(parentEnv, paths, passthrough, cwd) {
122
+ const inherited = Object.fromEntries(Object.entries(parentEnv).filter((entry) => entry[1] !== undefined && isInheritedRuntimeKey(entry[0])));
123
+ return {
124
+ ...inherited,
125
+ ...passthroughEnvironment(passthrough, parentEnv, paths, cwd),
126
+ PATH: PINNED_RUNTIME_PATH,
127
+ };
128
+ }
129
+ function pinnedEnvironment(paths) {
130
+ return {
131
+ HOME: paths.home,
132
+ CORTEX_HOME: paths.cortexHome,
133
+ CORTEX_PROJECTS_DIR: paths.projectsDir,
134
+ XDG_CONFIG_HOME: paths.xdgConfigHome,
135
+ XDG_CACHE_HOME: paths.xdgCacheHome,
136
+ CLAUDE_CONFIG_DIR: paths.claudeConfigDir,
137
+ TMPDIR: paths.tempDir,
138
+ TMP: paths.tempDir,
139
+ TEMP: paths.tempDir,
140
+ };
141
+ }
142
+ function assertEmptyProjectsDir(projectsDir) {
143
+ if (fs.existsSync(projectsDir) && fs.readdirSync(projectsDir).length > 0) {
144
+ throw new Error(`CORTEX_PROJECTS_DIR must be empty: ${projectsDir}`);
145
+ }
146
+ fs.mkdirSync(projectsDir, { recursive: true });
147
+ }
148
+ export function preparePinnedTrialPaths(trialRoot) {
149
+ const requestedRoot = path.resolve(trialRoot);
150
+ fs.mkdirSync(requestedRoot, { recursive: true });
151
+ const root = fs.realpathSync(requestedRoot);
152
+ const paths = {
153
+ root,
154
+ home: path.join(root, 'home'),
155
+ cortexHome: path.join(root, 'cortex-home'),
156
+ projectsDir: path.join(root, 'projects'),
157
+ xdgConfigHome: path.join(root, 'xdg-config'),
158
+ xdgCacheHome: path.join(root, 'xdg-cache'),
159
+ claudeConfigDir: path.join(root, 'claude-config'),
160
+ tempDir: path.join(root, 'tmp'),
161
+ logsDir: path.join(root, 'logs'),
162
+ };
163
+ assertEmptyProjectsDir(paths.projectsDir);
164
+ for (const value of Object.values(paths).slice(1))
165
+ fs.mkdirSync(value, { recursive: true });
166
+ return paths;
167
+ }
168
+ function resolveDirectory(directory, label) {
169
+ try {
170
+ const resolved = fs.realpathSync(directory);
171
+ if (fs.statSync(resolved).isDirectory())
172
+ return resolved;
173
+ }
174
+ catch { }
175
+ throw new Error(`${label} must be an existing directory: ${directory}`);
176
+ }
177
+ export function preparePinnedNodeLaunch(options) {
178
+ const paths = preparePinnedTrialPaths(options.trialRoot);
179
+ const parentEnv = options.parentEnv ?? process.env;
180
+ const cwd = resolveDirectory(options.workspaceCwd, 'workspaceCwd');
181
+ return {
182
+ command: process.execPath,
183
+ args: [
184
+ '--no-global-search-paths',
185
+ ...(options.nodeArgs ?? []),
186
+ path.resolve(options.entry),
187
+ ...(options.args ?? []),
188
+ ],
189
+ cwd,
190
+ env: {
191
+ ...inheritedEnvironment(parentEnv, paths, options.passthroughEnv ?? [], cwd),
192
+ ...pinnedEnvironment(paths),
193
+ },
194
+ stdio: options.stdio ?? 'inherit',
195
+ paths,
196
+ };
197
+ }
198
+ export function spawnPinnedNode(options) {
199
+ const launch = preparePinnedNodeLaunch(options);
200
+ return spawn(launch.command, launch.args, {
201
+ cwd: launch.cwd,
202
+ env: launch.env,
203
+ stdio: launch.stdio,
204
+ shell: false,
205
+ });
206
+ }
@@ -0,0 +1,4 @@
1
+ import type { AgentSpawnConfig } from '../../agent-adapter/types.js';
2
+ import { type RoleToolSurfaceInput } from './identity.js';
3
+ export declare function directoryContentSha256(directory: string): string;
4
+ export declare function roleSurfaceFromSpawnConfig(config: AgentSpawnConfig, directive?: string): RoleToolSurfaceInput;
@@ -0,0 +1,99 @@
1
+ // input: resolved AgentSpawnConfig and plugin directory trees
2
+ // output: content-addressed role/tool identity surface
3
+ // pos: Anti-divergence identity projection for one-shot spawns
4
+ // >>> If I am updated, update my header and folder CORTEX.md <<<
5
+ import { createHash } from 'node:crypto';
6
+ import fs from 'node:fs';
7
+ import path from 'node:path';
8
+ import { DEFAULT_TOOLS } from '../../agent-adapter/claude/defaults.js';
9
+ import { buildHooksSettings } from '../../agent-adapter/claude/hooks-builder.js';
10
+ import { canonicalJsonSha256, } from './identity.js';
11
+ function sha256(value) {
12
+ return createHash('sha256').update(value).digest('hex');
13
+ }
14
+ function contentEntries(root, directory = root) {
15
+ const result = [];
16
+ for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
17
+ const absolute = path.join(directory, entry.name);
18
+ if (entry.isDirectory())
19
+ result.push(...contentEntries(root, absolute));
20
+ if (entry.isFile()) {
21
+ result.push({ path: path.relative(root, absolute), type: 'file', sha256: sha256(fs.readFileSync(absolute)) });
22
+ }
23
+ if (entry.isSymbolicLink()) {
24
+ result.push({ path: path.relative(root, absolute), type: 'symlink', target: fs.readlinkSync(absolute) });
25
+ }
26
+ }
27
+ return result;
28
+ }
29
+ function compareText(left, right) {
30
+ if (left < right)
31
+ return -1;
32
+ if (left > right)
33
+ return 1;
34
+ return 0;
35
+ }
36
+ function comparePath(a, b) {
37
+ if (a.path < b.path)
38
+ return -1;
39
+ if (a.path > b.path)
40
+ return 1;
41
+ return 0;
42
+ }
43
+ export function directoryContentSha256(directory) {
44
+ if (!fs.statSync(directory).isDirectory()) {
45
+ throw new Error(`Plugin path is not a directory: ${directory}`);
46
+ }
47
+ return canonicalJsonSha256(contentEntries(directory).sort(comparePath));
48
+ }
49
+ function pluginIdentities(pluginDirs) {
50
+ return pluginDirs.map(directory => ({
51
+ path: directory,
52
+ content_sha256: directoryContentSha256(directory),
53
+ })).sort((left, right) => compareText(left.path, right.path));
54
+ }
55
+ function pluginSkills(pluginDir) {
56
+ const root = path.join(pluginDir, 'skills');
57
+ if (!fs.existsSync(root))
58
+ return [];
59
+ return fs.readdirSync(root, { withFileTypes: true })
60
+ .filter(entry => entry.isDirectory())
61
+ .map(entry => ({
62
+ name: entry.name,
63
+ content_sha256: directoryContentSha256(path.join(root, entry.name)),
64
+ }));
65
+ }
66
+ function discoveredSkills(pluginDirs) {
67
+ const skills = pluginDirs.flatMap(pluginSkills);
68
+ const names = new Set();
69
+ for (const skill of skills) {
70
+ if (names.has(skill.name))
71
+ throw new Error(`Duplicate plugin skill name: ${skill.name}`);
72
+ names.add(skill.name);
73
+ }
74
+ return skills.sort((left, right) => compareText(left.name, right.name));
75
+ }
76
+ function spawnedTools(config) {
77
+ if (config.rawTools !== undefined) {
78
+ return (config.rawTools || DEFAULT_TOOLS).split(',');
79
+ }
80
+ return config.tools?.length ? config.tools : DEFAULT_TOOLS.split(',');
81
+ }
82
+ function hookPolicy(config) {
83
+ if (config.disableHooks === true)
84
+ return {};
85
+ const tools = spawnedTools(config).join(',');
86
+ return buildHooksSettings(tools);
87
+ }
88
+ export function roleSurfaceFromSpawnConfig(config, directive = '') {
89
+ const pluginDirs = config.pluginDirs ?? [];
90
+ return {
91
+ systemPromptSha256: sha256(config.systemPrompt ?? ''),
92
+ directiveSha256: sha256(directive),
93
+ tools: spawnedTools(config),
94
+ pluginDirs: pluginIdentities(pluginDirs),
95
+ skills: discoveredSkills(pluginDirs),
96
+ mcpComposition: config.mcpComposition ?? 'direct',
97
+ hookPolicy: hookPolicy(config),
98
+ };
99
+ }
@@ -0,0 +1,22 @@
1
+ import type { McpComposition } from '../../agent-adapter/types.js';
2
+ import type { ResolvedProfileConfig } from '../agents/profile-manager.js';
3
+ import type { FrozenIdentityInput, IdentityJsonValue } from './identity.js';
4
+ export { resolvedRouteHost } from './identity.js';
5
+ export interface ResolvedAgentRunRole {
6
+ systemPrompt: string;
7
+ tools: string[];
8
+ pluginDirs: string[];
9
+ mcpComposition: McpComposition;
10
+ mcpConfigPaths: string[];
11
+ disableHooks: boolean;
12
+ }
13
+ export interface ResolvedAgentRunConfig {
14
+ modelExecution: FrozenIdentityInput['modelExecution'];
15
+ role: ResolvedAgentRunRole;
16
+ runConfig: IdentityJsonValue;
17
+ limits: IdentityJsonValue;
18
+ adapterHashes: IdentityJsonValue;
19
+ harnessHashes: IdentityJsonValue;
20
+ }
21
+ export declare function loadAgentRunConfig(file?: string): ResolvedAgentRunConfig;
22
+ export declare function validateResolvedExecution(profile: ResolvedProfileConfig, _config: ResolvedAgentRunConfig): void;
@@ -0,0 +1,135 @@
1
+ // input: file/stdin run-config JSON, resolved profile, defaults
2
+ // output: argv-closed frozen inputs and one non-empty spawn role
3
+ // pos: Configuration boundary for daemon-free one-shot runs
4
+ // >>> If I am updated, update my header and folder CORTEX.md <<<
5
+ import fs from 'node:fs';
6
+ import path from 'node:path';
7
+ import { z } from 'zod';
8
+ import { DEFAULT_TOOLS } from '../../agent-adapter/claude/defaults.js';
9
+ import { readStdinSync } from '../../core/cli-utils.js';
10
+ import { DEFAULTS_DIR } from '../../core/paths.js';
11
+ export { resolvedRouteHost } from './identity.js';
12
+ const roleSchema = z.object({
13
+ system_prompt: z.string(),
14
+ tools: z.array(z.string().min(1).refine(value => !value.includes(','), 'tool names may not contain commas')).min(1, 'role tools must contain at least one tool'),
15
+ plugin_dirs: z.array(z.string()),
16
+ mcp_composition: z.enum(['direct', 'thread-control', 'none', 'benchmark-thread-run']),
17
+ mcp_config_paths: z.array(z.string().min(1)),
18
+ disable_hooks: z.literal(true),
19
+ }).strict();
20
+ const runConfigSchema = z.object({
21
+ schema_version: z.literal('cortex-agent-run-config/1'),
22
+ model_execution: z.object({ model_alias_policy: z.unknown() }).strict(),
23
+ role: roleSchema,
24
+ bundle: z.object({
25
+ run_config: z.unknown(),
26
+ limits: z.unknown(),
27
+ adapter_hashes: z.unknown(),
28
+ harness_hashes: z.unknown(),
29
+ }).strict(),
30
+ }).strict();
31
+ function parseJson(text, label) {
32
+ try {
33
+ return JSON.parse(text);
34
+ }
35
+ catch (error) {
36
+ throw new Error(`Failed to parse JSON from '${label}': ${error.message}`);
37
+ }
38
+ }
39
+ function readJson(file) {
40
+ try {
41
+ return parseJson(fs.readFileSync(file, 'utf8'), file);
42
+ }
43
+ catch (error) {
44
+ if (error.message.startsWith('Failed to parse'))
45
+ throw error;
46
+ throw new Error(`Failed to read JSON file '${file}': ${error.message}`);
47
+ }
48
+ }
49
+ function resolveConfigPaths(base, values) {
50
+ return values.map(value => path.resolve(base, value));
51
+ }
52
+ function declaredMcpServers(files) {
53
+ const servers = files.flatMap((file) => {
54
+ const value = readJson(file);
55
+ if (!value || typeof value.mcpServers !== 'object' || value.mcpServers === null) {
56
+ throw new Error(`Invalid MCP config: ${file}`);
57
+ }
58
+ return Object.keys(value.mcpServers);
59
+ });
60
+ return [...new Set(servers)].sort();
61
+ }
62
+ function validateRestrictedMcp(role) {
63
+ if (role.mcpComposition !== 'none' && role.mcpComposition !== 'benchmark-thread-run')
64
+ return;
65
+ const servers = declaredMcpServers(role.mcpConfigPaths);
66
+ if (role.mcpComposition === 'none' && servers.length !== 0) {
67
+ throw new Error('none composition must expose zero MCP servers');
68
+ }
69
+ if (role.mcpComposition === 'benchmark-thread-run'
70
+ && JSON.stringify(servers) !== JSON.stringify(['cortex-benchmark-thread'])) {
71
+ throw new Error('benchmark-thread-run composition must expose only cortex-benchmark-thread');
72
+ }
73
+ }
74
+ function roleConfig(base, role) {
75
+ const resolved = {
76
+ systemPrompt: role.system_prompt,
77
+ tools: role.tools,
78
+ pluginDirs: resolveConfigPaths(base, role.plugin_dirs),
79
+ mcpComposition: role.mcp_composition,
80
+ mcpConfigPaths: resolveConfigPaths(base, role.mcp_config_paths),
81
+ disableHooks: role.disable_hooks,
82
+ };
83
+ validateRestrictedMcp(resolved);
84
+ return resolved;
85
+ }
86
+ function defaultConfig() {
87
+ const role = {
88
+ systemPrompt: '',
89
+ tools: DEFAULT_TOOLS.split(','),
90
+ pluginDirs: [],
91
+ mcpComposition: 'none',
92
+ mcpConfigPaths: [path.join(DEFAULTS_DIR, 'config', 'mcp-config-empty.json')],
93
+ disableHooks: true,
94
+ };
95
+ validateRestrictedMcp(role);
96
+ return {
97
+ modelExecution: {
98
+ modelAliasPolicy: null,
99
+ configuredRouteBaseHost: null,
100
+ claudeCliVersion: null,
101
+ },
102
+ role,
103
+ runConfig: null,
104
+ limits: null,
105
+ adapterHashes: null,
106
+ harnessHashes: null,
107
+ };
108
+ }
109
+ function resolvedRunConfig(value, base) {
110
+ const parsed = runConfigSchema.parse(value);
111
+ return {
112
+ modelExecution: {
113
+ modelAliasPolicy: parsed.model_execution.model_alias_policy,
114
+ configuredRouteBaseHost: null,
115
+ claudeCliVersion: null,
116
+ },
117
+ role: roleConfig(base, parsed.role),
118
+ runConfig: parsed.bundle.run_config,
119
+ limits: parsed.bundle.limits,
120
+ adapterHashes: parsed.bundle.adapter_hashes,
121
+ harnessHashes: parsed.bundle.harness_hashes,
122
+ };
123
+ }
124
+ export function loadAgentRunConfig(file) {
125
+ if (file === undefined)
126
+ return defaultConfig();
127
+ if (file === '-')
128
+ return resolvedRunConfig(parseJson(readStdinSync(), 'stdin'), process.cwd());
129
+ return resolvedRunConfig(readJson(file), path.dirname(file));
130
+ }
131
+ export function validateResolvedExecution(profile, _config) {
132
+ const extra = Object.keys(profile.extraOption)[0];
133
+ if (extra)
134
+ throw new Error(`agent-run does not support profile extraOption ${extra}`);
135
+ }
@@ -0,0 +1,7 @@
1
+ import type { Writable } from 'node:stream';
2
+ import type { AgentRunCliOptions } from './agent-run-cli.js';
3
+ export interface AgentRunIo {
4
+ stdout: Pick<Writable, 'write'> & Partial<Pick<Writable, 'on'>>;
5
+ stderr: Pick<Writable, 'write'>;
6
+ }
7
+ export declare function runOneShotAgent(options: AgentRunCliOptions, io: AgentRunIo): Promise<number>;