@cortex-agent/server 2026.10.2 → 2026.10.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 (574) hide show
  1. package/README.md +31 -31
  2. package/defaults/AGENTS.md +3 -3
  3. package/defaults/config/{thread-templates/agents/direct.json → environments/main.json} +2 -2
  4. package/defaults/context/AGENTS.md +0 -2
  5. package/defaults/context/projects/AGENTS.md +0 -2
  6. package/defaults/context/user/AGENTS.md +1 -1
  7. package/defaults/hooks/cortex-hook-api.mjs +1 -3
  8. package/defaults/hooks/new-session-hook.mjs +2 -3
  9. package/defaults/hooks/status-md-guard.mjs +5 -5
  10. package/defaults/plugins/cortex-system/.claude-plugin/plugin.json +2 -2
  11. package/defaults/plugins/cortex-system/plugin.json +2 -2
  12. package/defaults/plugins/cortex-system/skills/project-init/SKILL.md +4 -4
  13. package/defaults/plugins/cortex-system/skills/schedule/SKILL.md +11 -13
  14. package/defaults/plugins/cortex-system/skills/user-learn/SKILL.md +1 -1
  15. package/defaults/prompts/systemPrompts/web-opus-4-6.md +2 -2
  16. package/defaults/prompts/systemPrompts/web-sonnet-4-6.md +2 -2
  17. package/defaults/rules/issues-md.md +2 -2
  18. package/defaults/rules/meta-conventions.md +1 -2
  19. package/defaults/rules/mission-md.md +1 -1
  20. package/defaults/rules/overview-md.md +1 -1
  21. package/defaults/rules/roadmap-md.md +1 -1
  22. package/defaults/rules/status-md.md +4 -4
  23. package/dist/agent-adapter/claude/adapter.d.ts +6 -1
  24. package/dist/agent-adapter/claude/adapter.js +15 -4
  25. package/dist/agent-adapter/claude/compact-window.d.ts +11 -3
  26. package/dist/agent-adapter/claude/compact-window.js +12 -3
  27. package/dist/agent-adapter/claude/defaults.d.ts +0 -1
  28. package/dist/agent-adapter/claude/defaults.js +0 -1
  29. package/dist/agent-adapter/claude/event-translator.d.ts +2 -2
  30. package/dist/agent-adapter/claude/event-translator.js +2 -1
  31. package/dist/agent-adapter/claude/hooks-builder.d.ts +0 -5
  32. package/dist/agent-adapter/claude/hooks-builder.js +0 -13
  33. package/dist/agent-adapter/claude/spawn-args.d.ts +5 -12
  34. package/dist/agent-adapter/claude/spawn-args.js +45 -38
  35. package/dist/agent-adapter/claude/turn-machine.d.ts +2 -2
  36. package/dist/agent-adapter/claude/turn-machine.js +6 -3
  37. package/dist/agent-adapter/continuation-phase.js +2 -1
  38. package/dist/agent-adapter/normalize/event-types.d.ts +4 -1
  39. package/dist/agent-adapter/normalize/tool-result-images.d.ts +11 -0
  40. package/dist/agent-adapter/normalize/tool-result-images.js +32 -0
  41. package/dist/agent-adapter/pi/child-events.js +3 -0
  42. package/dist/agent-adapter/pi/child-runner.d.ts +1 -2
  43. package/dist/agent-adapter/pi/child-runner.js +6 -6
  44. package/dist/agent-adapter/pi/child-session.d.ts +1 -1
  45. package/dist/agent-adapter/pi/event-parser.d.ts +13 -2
  46. package/dist/agent-adapter/pi/event-parser.js +38 -11
  47. package/dist/agent-adapter/pi/mcp-bridge-logic.d.ts +0 -1
  48. package/dist/agent-adapter/pi/mcp-bridge-logic.js +0 -3
  49. package/dist/agent-adapter/pi/mcp-bridge.js +4 -4
  50. package/dist/agent-adapter/pi/pi-session.d.ts +4 -2
  51. package/dist/agent-adapter/pi/pi-session.js +18 -9
  52. package/dist/agent-adapter/pi/runtime-settings.d.ts +7 -0
  53. package/dist/agent-adapter/pi/runtime-settings.js +23 -0
  54. package/dist/agent-adapter/pi/runtime.d.ts +2 -3
  55. package/dist/agent-adapter/pi/session-options.d.ts +4 -1
  56. package/dist/agent-adapter/pi/session-options.js +13 -21
  57. package/dist/agent-adapter/pi/session-support.d.ts +2 -0
  58. package/dist/agent-adapter/run-events.d.ts +3 -1
  59. package/dist/agent-adapter/types.d.ts +6 -12
  60. package/dist/agent-adapter/types.js +2 -4
  61. package/dist/core/agents/roles.d.ts +1 -1
  62. package/dist/core/agents/subagent/attribution.js +1 -0
  63. package/dist/core/agents/subagent/catalog.d.ts +8 -0
  64. package/dist/core/agents/subagent/catalog.js +21 -10
  65. package/dist/core/agents/subagent/types.d.ts +4 -1
  66. package/dist/core/config-generator.d.ts +0 -6
  67. package/dist/core/config-generator.js +1 -35
  68. package/dist/core/icons.d.ts +33 -33
  69. package/dist/core/locales/en.d.ts +863 -1030
  70. package/dist/core/locales/slices/commands.d.ts +282 -349
  71. package/dist/core/locales/slices/commands.js +20 -160
  72. package/dist/core/locales/slices/init.d.ts +152 -152
  73. package/dist/core/locales/slices/interactions.d.ts +44 -45
  74. package/dist/core/locales/slices/interactions.js +0 -4
  75. package/dist/core/locales/slices/lang.d.ts +5 -5
  76. package/dist/core/locales/slices/notices.d.ts +75 -118
  77. package/dist/core/locales/slices/notices.js +13 -99
  78. package/dist/core/locales/slices/scheduling.d.ts +31 -31
  79. package/dist/core/locales/slices/startup.d.ts +5 -5
  80. package/dist/core/locales/slices/status.d.ts +43 -43
  81. package/dist/core/locales/slices/tui.d.ts +91 -114
  82. package/dist/core/locales/slices/tui.js +0 -46
  83. package/dist/core/locales/slices/uiextra.d.ts +41 -61
  84. package/dist/core/locales/slices/uiextra.js +11 -51
  85. package/dist/core/locales/slices/uimsg.d.ts +86 -99
  86. package/dist/core/locales/slices/uimsg.js +6 -32
  87. package/dist/core/mcp-bundles.d.ts +1 -1
  88. package/dist/core/mcp-bundles.js +7 -5
  89. package/dist/core/mcp-tool-gate.js +8 -5
  90. package/dist/core/platform-settings-spec.d.ts +3 -3
  91. package/dist/core/production-benchmark-evidence.d.ts +1 -9
  92. package/dist/core/production-benchmark-evidence.js +0 -22
  93. package/dist/core/rebuild-progress.d.ts +3 -2
  94. package/dist/core/rebuild-progress.js +5 -2
  95. package/dist/core/run-registry.d.ts +7 -28
  96. package/dist/core/run-registry.js +6 -51
  97. package/dist/core/session-retention-liveness.d.ts +0 -2
  98. package/dist/core/session-retention-liveness.js +0 -13
  99. package/dist/core/session-state.d.ts +1 -2
  100. package/dist/core/session-state.js +2 -3
  101. package/dist/core/settings-spec.d.ts +19 -60
  102. package/dist/core/settings-spec.js +30 -60
  103. package/dist/core/status-format.d.ts +0 -14
  104. package/dist/core/status-format.js +2 -24
  105. package/dist/core/types/agent-types.d.ts +26 -9
  106. package/dist/core/types/benchmark-types.d.ts +17 -0
  107. package/dist/core/types/environment-types.d.ts +64 -0
  108. package/dist/core/types/environment-types.js +1 -0
  109. package/dist/core/utils.d.ts +14 -4
  110. package/dist/core/utils.js +32 -6
  111. package/dist/domain/agents/agent-switch.js +2 -4
  112. package/dist/domain/agents/config.js +1 -1
  113. package/dist/domain/agents/environments/entities.d.ts +49 -0
  114. package/dist/domain/agents/environments/entities.js +94 -0
  115. package/dist/domain/agents/environments/file-refs.d.ts +19 -0
  116. package/dist/domain/agents/environments/file-refs.js +48 -0
  117. package/dist/domain/agents/environments/index.d.ts +6 -0
  118. package/dist/domain/agents/environments/index.js +8 -0
  119. package/dist/domain/agents/environments/paths.d.ts +7 -0
  120. package/dist/domain/agents/environments/paths.js +9 -0
  121. package/dist/domain/{threads/template-resolver.js → agents/environments/prompt-includes.js} +2 -2
  122. package/dist/domain/agents/environments/registry.d.ts +17 -0
  123. package/dist/domain/agents/environments/registry.js +159 -0
  124. package/dist/domain/agents/environments/schema.d.ts +68 -0
  125. package/dist/domain/agents/environments/schema.js +111 -0
  126. package/dist/domain/agents/environments/schema.parity.d.ts +1 -0
  127. package/dist/domain/agents/environments/schema.parity.js +7 -0
  128. package/dist/domain/agents/environments/slot-config.d.ts +14 -0
  129. package/dist/domain/agents/environments/slot-config.js +78 -0
  130. package/dist/domain/agents/model-selection.d.ts +3 -0
  131. package/dist/domain/agents/model-selection.js +1 -1
  132. package/dist/domain/agents/subagent/runner.js +3 -2
  133. package/dist/domain/benchmark/accounting-reconciliation.d.ts +1 -1
  134. package/dist/domain/benchmark/atif.d.ts +4 -4
  135. package/dist/domain/benchmark/atif.js +7 -7
  136. package/dist/domain/benchmark/attempt-record.d.ts +16 -55
  137. package/dist/domain/benchmark/attempt-record.js +3 -17
  138. package/dist/domain/benchmark/composite-manifest.d.ts +4 -4
  139. package/dist/domain/benchmark/composite-manifest.js +5 -11
  140. package/dist/domain/benchmark/journal.d.ts +6 -4
  141. package/dist/domain/benchmark/journal.js +6 -4
  142. package/dist/domain/benchmark/manifest-contract.d.ts +1 -1
  143. package/dist/domain/benchmark/production-attempt-identity.d.ts +11 -16
  144. package/dist/domain/benchmark/production-attempt-identity.js +31 -94
  145. package/dist/domain/benchmark/production-attempt-journal.js +14 -7
  146. package/dist/domain/benchmark/production-evidence-journal.js +8 -6
  147. package/dist/domain/benchmark/production-evidence-projection.d.ts +1 -11
  148. package/dist/domain/benchmark/production-evidence-projection.js +32 -143
  149. package/dist/domain/benchmark/session-evidence.d.ts +6 -0
  150. package/dist/domain/benchmark/session-evidence.js +27 -0
  151. package/dist/domain/costs/cost-tracker.d.ts +1 -7
  152. package/dist/domain/costs/cost-tracker.js +0 -4
  153. package/dist/domain/costs/resume-registry.d.ts +9 -20
  154. package/dist/domain/costs/resume-registry.js +24 -39
  155. package/dist/domain/executions/registry.d.ts +3 -18
  156. package/dist/domain/executions/registry.js +4 -158
  157. package/dist/domain/mcp/bundled-server.js +20 -27
  158. package/dist/domain/mcp/tools/commission-tools.js +0 -1
  159. package/dist/domain/mcp/tools/context.d.ts +2 -9
  160. package/dist/domain/mcp/tools/context.js +2 -7
  161. package/dist/domain/mcp/tools/executions.js +6 -19
  162. package/dist/domain/mcp/tools/interaction-ask.js +0 -1
  163. package/dist/domain/mcp/tools/interaction-plan.d.ts +0 -1
  164. package/dist/domain/mcp/tools/interaction-plan.js +0 -2
  165. package/dist/domain/mcp/tools/{task-ops.d.ts → remote-ops.d.ts} +1 -1
  166. package/dist/domain/mcp/tools/{task-ops.js → remote-ops.js} +1 -1
  167. package/dist/domain/mcp/tools/schedule.d.ts +3 -3
  168. package/dist/domain/mcp/tools/schedule.js +10 -32
  169. package/dist/domain/mcp/tools/subagent.d.ts +4 -0
  170. package/dist/domain/mcp/tools/subagent.js +10 -8
  171. package/dist/domain/mcp/tools/ui-view.js +3 -2
  172. package/dist/domain/mcp/tools/waitpoint.js +2 -3
  173. package/dist/domain/mcp/tools/{thread-ops.d.ts → workers.d.ts} +1 -1
  174. package/dist/domain/mcp/tools/workers.js +84 -0
  175. package/dist/domain/memory/user-context.d.ts +2 -3
  176. package/dist/domain/memory/user-context.js +2 -3
  177. package/dist/domain/monitor/gpu-monitor.js +1 -1
  178. package/dist/domain/pi-providers/custom-provider-model.d.ts +1 -1
  179. package/dist/domain/projects/project-store.d.ts +1 -2
  180. package/dist/domain/projects/project-store.js +1 -9
  181. package/dist/domain/remote/client-manager.d.ts +1 -1
  182. package/dist/domain/remote/client-manager.js +1 -1
  183. package/dist/domain/remote/client-remove.d.ts +1 -1
  184. package/dist/domain/remote/machine-registry.d.ts +54 -0
  185. package/dist/domain/{tasks/dispatch-utils.js → remote/machine-registry.js} +1 -61
  186. package/dist/domain/runs/attempt.js +3 -8
  187. package/dist/domain/runs/builders.d.ts +2 -3
  188. package/dist/domain/runs/builders.js +2 -3
  189. package/dist/domain/runs/engine-spec.js +3 -10
  190. package/dist/domain/runs/fallback.d.ts +1 -3
  191. package/dist/domain/runs/fallback.js +1 -3
  192. package/dist/domain/runs/observers/resume-recorder.d.ts +0 -15
  193. package/dist/domain/runs/observers/resume-recorder.js +0 -17
  194. package/dist/domain/runs/prompt.d.ts +23 -8
  195. package/dist/domain/runs/prompt.js +31 -5
  196. package/dist/domain/runs/request.d.ts +6 -15
  197. package/dist/domain/runs/run.js +0 -2
  198. package/dist/domain/runs/service.js +0 -2
  199. package/dist/domain/runs/spec-loader.d.ts +4 -6
  200. package/dist/domain/runs/spec-loader.js +3 -5
  201. package/dist/domain/scheduling/builtin-job-migration.js +3 -3
  202. package/dist/domain/scheduling/builtin-jobs.js +0 -13
  203. package/dist/domain/scheduling/job-registry.d.ts +12 -27
  204. package/dist/domain/scheduling/job-registry.js +2 -3
  205. package/dist/domain/scheduling/jobs/scheduled-task.d.ts +18 -6
  206. package/dist/domain/scheduling/jobs/scheduled-task.js +66 -125
  207. package/dist/domain/scheduling/run-guards.d.ts +6 -0
  208. package/dist/domain/scheduling/run-guards.js +18 -0
  209. package/dist/domain/scheduling/runner.d.ts +0 -1
  210. package/dist/domain/scheduling/runner.js +0 -1
  211. package/dist/domain/scheduling/schedule-cli.js +1 -1
  212. package/dist/domain/scheduling/scheduler.d.ts +0 -4
  213. package/dist/domain/scheduling/scheduler.js +2 -6
  214. package/dist/domain/sessions/session-hooks.d.ts +2 -2
  215. package/dist/domain/sessions/session-lifecycle.d.ts +23 -9
  216. package/dist/domain/sessions/session-lifecycle.js +27 -15
  217. package/dist/domain/sessions/session-retention.d.ts +8 -0
  218. package/dist/domain/sessions/session-retention.js +139 -34
  219. package/dist/domain/sessions/team.d.ts +18 -0
  220. package/dist/domain/sessions/team.js +21 -0
  221. package/dist/domain/system/install-cli.js +5 -5
  222. package/dist/domain/system/rebuild-hold.d.ts +1 -1
  223. package/dist/domain/system/server-update-check.js +2 -1
  224. package/dist/domain/ui-service/app-router.d.ts +41 -154
  225. package/dist/domain/ui-service/app-router.js +9 -30
  226. package/dist/domain/ui-service/input-schemas.d.ts +64 -205
  227. package/dist/domain/ui-service/input-schemas.js +26 -71
  228. package/dist/domain/ui-service/mutate/environments.d.ts +23 -0
  229. package/dist/domain/ui-service/mutate/environments.js +51 -0
  230. package/dist/domain/ui-service/mutate/plugin-packages.js +3 -9
  231. package/dist/domain/ui-service/mutate/plugins.js +7 -109
  232. package/dist/domain/ui-service/mutate/schedules.js +1 -2
  233. package/dist/domain/ui-service/plugins-shared.d.ts +0 -3
  234. package/dist/domain/ui-service/plugins-shared.js +0 -14
  235. package/dist/domain/ui-service/query/config.js +10 -13
  236. package/dist/domain/ui-service/query/environments.d.ts +12 -0
  237. package/dist/domain/ui-service/query/environments.js +72 -0
  238. package/dist/domain/ui-service/query/executions.js +1 -1
  239. package/dist/domain/ui-service/query/hooks.d.ts +1 -1
  240. package/dist/domain/ui-service/query/hooks.js +13 -24
  241. package/dist/domain/ui-service/query/memory.js +1 -1
  242. package/dist/domain/ui-service/query/plugins.js +6 -82
  243. package/dist/domain/ui-service/query/schedules.js +0 -1
  244. package/dist/domain/ui-service/query/sessions.js +23 -5
  245. package/dist/domain/ui-service/query/system.js +0 -1
  246. package/dist/domain/ui-service/query-input-schemas.d.ts +5 -26
  247. package/dist/domain/ui-service/query-input-schemas.js +0 -18
  248. package/dist/domain/ui-service/types.d.ts +68 -330
  249. package/dist/domain/ui-service/ui-service.js +7 -23
  250. package/dist/domain/waitpoints/notices.d.ts +1 -1
  251. package/dist/domain/waitpoints/notices.js +1 -1
  252. package/dist/entry/app.js +70 -146
  253. package/dist/entry/cli-help.js +0 -1
  254. package/dist/entry/cli.js +1 -6
  255. package/dist/entry/daemon.d.ts +27 -23
  256. package/dist/entry/daemon.js +61 -49
  257. package/dist/entry/fast-install.d.ts +13 -2
  258. package/dist/entry/fast-install.js +43 -11
  259. package/dist/entry/hook-cli.d.ts +0 -1
  260. package/dist/entry/hook-cli.js +20 -49
  261. package/dist/entry/init.js +8 -11
  262. package/dist/entry/local-ui.d.ts +1 -1
  263. package/dist/entry/platform-connect.d.ts +23 -0
  264. package/dist/entry/platform-connect.js +94 -0
  265. package/dist/entry/production-evidence-export-cli.js +0 -2
  266. package/dist/events/event-logger.js +1 -0
  267. package/dist/events/event-types.d.ts +13 -62
  268. package/dist/hooks/cortex-hook-api.mjs +1 -3
  269. package/dist/hooks/new-session-hook.mjs +2 -3
  270. package/dist/hooks/status-md-guard.mjs +5 -5
  271. package/dist/orchestration/agent-runner.d.ts +3 -0
  272. package/dist/orchestration/agent-runner.js +21 -19
  273. package/dist/orchestration/agent-view-send.d.ts +7 -0
  274. package/dist/orchestration/agent-view-send.js +12 -0
  275. package/dist/orchestration/benchmark-session-webhook.d.ts +19 -0
  276. package/dist/orchestration/benchmark-session-webhook.js +130 -0
  277. package/dist/orchestration/conversation-request.d.ts +39 -1
  278. package/dist/orchestration/conversation-request.js +71 -15
  279. package/dist/orchestration/interactions/answer-question.d.ts +16 -0
  280. package/dist/orchestration/interactions/answer-question.js +38 -0
  281. package/dist/orchestration/interactions/ask-user-question.d.ts +2 -3
  282. package/dist/orchestration/interactions/ask-user-question.js +1 -3
  283. package/dist/orchestration/interactions/ask-user-resume.d.ts +1 -3
  284. package/dist/orchestration/interactions/ask-user-resume.js +2 -14
  285. package/dist/orchestration/interactions/interaction-handlers.js +6 -35
  286. package/dist/orchestration/interactions/plan-response.d.ts +2 -1
  287. package/dist/orchestration/interactions/plan-response.js +2 -2
  288. package/dist/orchestration/orchestrator.d.ts +1 -7
  289. package/dist/orchestration/orchestrator.js +2 -11
  290. package/dist/orchestration/resume-dispatcher.d.ts +0 -22
  291. package/dist/orchestration/resume-dispatcher.js +8 -72
  292. package/dist/orchestration/routing/commands/cancel.d.ts +1 -7
  293. package/dist/orchestration/routing/commands/cancel.js +17 -37
  294. package/dist/orchestration/routing/commands/channel.js +1 -1
  295. package/dist/orchestration/routing/commands/device.js +1 -1
  296. package/dist/orchestration/routing/commands/index.d.ts +0 -7
  297. package/dist/orchestration/routing/commands/index.js +1 -9
  298. package/dist/orchestration/routing/commands/mode.js +7 -7
  299. package/dist/orchestration/routing/commands/nvtop.js +1 -1
  300. package/dist/orchestration/routing/commands/sendfile.js +1 -1
  301. package/dist/orchestration/routing/commands/status.js +8 -14
  302. package/dist/orchestration/routing/hook-bridge-subscribers.d.ts +4 -1
  303. package/dist/orchestration/routing/hook-bridge-subscribers.js +19 -12
  304. package/dist/orchestration/routing/hook-bridge.d.ts +3 -3
  305. package/dist/orchestration/routing/hook-bridge.js +9 -9
  306. package/dist/orchestration/routing/message-router.js +2 -25
  307. package/dist/orchestration/routing/webhook.js +24 -350
  308. package/dist/orchestration/session-events.d.ts +13 -0
  309. package/dist/orchestration/session-events.js +8 -0
  310. package/dist/orchestration/session-gateway.d.ts +4 -2
  311. package/dist/orchestration/session-gateway.js +17 -12
  312. package/dist/orchestration/session-retention-controller.d.ts +5 -2
  313. package/dist/orchestration/session-retention-controller.js +7 -4
  314. package/dist/orchestration/status-helpers.d.ts +1 -4
  315. package/dist/orchestration/status-helpers.js +3 -5
  316. package/dist/orchestration/team-delivery.d.ts +64 -0
  317. package/dist/orchestration/team-delivery.js +224 -0
  318. package/dist/orchestration/team-state.d.ts +48 -0
  319. package/dist/orchestration/team-state.js +146 -0
  320. package/dist/orchestration/team-webhook.d.ts +48 -0
  321. package/dist/orchestration/team-webhook.js +295 -0
  322. package/dist/orchestration/transcript-sink.d.ts +18 -4
  323. package/dist/orchestration/transcript-sink.js +31 -3
  324. package/dist/orchestration/turn/background-hold.d.ts +2 -2
  325. package/dist/orchestration/turn/background-hold.js +1 -1
  326. package/dist/orchestration/turn/hold-render-platform.d.ts +2 -2
  327. package/dist/orchestration/turn/hold-render-platform.js +2 -2
  328. package/dist/orchestration/turn/hold-render-web.d.ts +3 -3
  329. package/dist/orchestration/turn/hold-render-web.js +2 -2
  330. package/dist/orchestration/turn/terminal.d.ts +5 -2
  331. package/dist/orchestration/turn/terminal.js +11 -10
  332. package/dist/orchestration/turn/turn.d.ts +13 -1
  333. package/dist/orchestration/turn/turn.js +58 -15
  334. package/dist/platform/adapters/composite-adapter.d.ts +2 -0
  335. package/dist/platform/adapters/composite-adapter.js +7 -4
  336. package/dist/platform/adapters/feishu.d.ts +6 -0
  337. package/dist/platform/adapters/feishu.js +50 -4
  338. package/dist/platform/index.d.ts +1 -1
  339. package/dist/platform/index.js +1 -1
  340. package/dist/platform/tui/protocol.d.ts +2 -2
  341. package/dist/platform/types.d.ts +3 -3
  342. package/dist/platform/types.js +3 -3
  343. package/dist/store/conversation-history-reader.js +17 -3
  344. package/dist/store/conversation-history-repo.d.ts +18 -4
  345. package/dist/store/conversation-history-repo.js +14 -5
  346. package/dist/store/conversation-ledger-repo.js +1 -16
  347. package/dist/store/execution-repo.d.ts +17 -40
  348. package/dist/store/execution-repo.js +46 -116
  349. package/dist/store/hook-registry.d.ts +4 -16
  350. package/dist/store/hook-registry.js +5 -65
  351. package/dist/store/plugin-sync.js +4 -0
  352. package/dist/store/profile-repo.js +1 -1
  353. package/dist/store/prompt-migration-replacements.d.ts +0 -1
  354. package/dist/store/prompt-migration-replacements.js +0 -49
  355. package/dist/store/retention-candidate-repo.d.ts +2 -0
  356. package/dist/store/retention-candidate-repo.js +5 -0
  357. package/dist/store/schedule-repo.d.ts +3 -15
  358. package/dist/store/schedule-repo.js +18 -4
  359. package/dist/store/session-registry-journal.d.ts +15 -0
  360. package/dist/store/session-registry-journal.js +68 -10
  361. package/dist/store/session-registry-repo.d.ts +13 -0
  362. package/dist/store/session-registry-repo.js +74 -21
  363. package/dist/store/session-totals.d.ts +3 -3
  364. package/dist/store/session-totals.js +3 -3
  365. package/dist/store/team-outbox-repo.d.ts +20 -0
  366. package/dist/store/team-outbox-repo.js +39 -0
  367. package/dist/store/tool-image-files.d.ts +12 -0
  368. package/dist/store/tool-image-files.js +40 -0
  369. package/dist/store/version-migrations.d.ts +31 -8
  370. package/dist/store/version-migrations.js +307 -87
  371. package/dist/store/waitpoint-repo.d.ts +0 -2
  372. package/dist/tui/App.js +1 -1
  373. package/dist/tui/components/Dashboard.js +0 -8
  374. package/dist/tui/components/InputBox.js +1 -7
  375. package/dist/tui/components/StatusLine.js +1 -1
  376. package/dist/tui/hooks/useDashboardData.d.ts +1 -1
  377. package/dist/tui/hooks/useDashboardData.js +0 -4
  378. package/dist/tui/hooks/useNotifications.d.ts +1 -1
  379. package/dist/tui/slash-commands.js +1 -4
  380. package/package.json +4 -5
  381. package/web/dist/assets/index-BU_kY1rV.js +449 -0
  382. package/web/dist/assets/{index-zvUjPRjt.js → index-CDjsmgsy.js} +1 -1
  383. package/web/dist/assets/index-DzPDbcY1.css +1 -0
  384. package/web/dist/index.html +2 -2
  385. package/defaults/config/hooks/02-tasks-yaml-guard.json +0 -11
  386. package/defaults/config/hooks/11-task-status-check.json +0 -14
  387. package/defaults/config/thread-templates/agents/coder-reviewer.json +0 -17
  388. package/defaults/config/thread-templates/agents/coder.json +0 -17
  389. package/defaults/config/thread-templates/agents/direct-review.json +0 -14
  390. package/defaults/config/thread-templates/agents/direct-web.json +0 -14
  391. package/defaults/config/thread-templates/agents/director.json +0 -11
  392. package/defaults/config/thread-templates/agents/doc-reviewer.json +0 -13
  393. package/defaults/config/thread-templates/agents/doc-writer.json +0 -24
  394. package/defaults/config/thread-templates/agents/executor-reviewer.json +0 -13
  395. package/defaults/config/thread-templates/agents/executor.json +0 -24
  396. package/defaults/config/thread-templates/agents/main.json +0 -14
  397. package/defaults/config/thread-templates/agents/manager.json +0 -14
  398. package/defaults/config/thread-templates/agents/scheduler-main.json +0 -13
  399. package/defaults/config/thread-templates/shells/worker-review.json +0 -12
  400. package/defaults/config/thread-templates/templates/coder-review.json +0 -20
  401. package/defaults/config/thread-templates/templates/default.json +0 -10
  402. package/defaults/config/thread-templates/templates/doc-review.json +0 -6
  403. package/defaults/config/thread-templates/templates/execute-review.json +0 -6
  404. package/defaults/config/thread-templates/templates/manager.json +0 -11
  405. package/defaults/config/thread-templates/templates/scheduler.json +0 -10
  406. package/defaults/hooks/task-status-check.mjs +0 -166
  407. package/defaults/hooks/tasks-yaml-guard.mjs +0 -225
  408. package/defaults/plugins/cortex-system/skills/task/SKILL.md +0 -547
  409. package/defaults/plugins/cortex-system/skills/thread/SKILL.md +0 -505
  410. package/defaults/prompts/directives/coder-reviewer.md +0 -7
  411. package/defaults/prompts/directives/coder.md +0 -7
  412. package/defaults/prompts/directives/director.md +0 -7
  413. package/defaults/prompts/directives/doc-reviewer.md +0 -6
  414. package/defaults/prompts/directives/doc-writer.md +0 -7
  415. package/defaults/prompts/directives/executor-reviewer.md +0 -6
  416. package/defaults/prompts/directives/executor.md +0 -7
  417. package/defaults/prompts/directives/manager.md +0 -24
  418. package/defaults/prompts/systemPrompts/coder.md +0 -10
  419. package/defaults/prompts/systemPrompts/worker.md +0 -10
  420. package/defaults/rules/task-system.md +0 -53
  421. package/dist/core/task-node.d.ts +0 -7
  422. package/dist/core/task-node.js +0 -21
  423. package/dist/core/task-parser.d.ts +0 -86
  424. package/dist/core/task-parser.js +0 -436
  425. package/dist/core/types/thread-types.d.ts +0 -506
  426. package/dist/domain/benchmark/production-evidence-topology.d.ts +0 -14
  427. package/dist/domain/benchmark/production-evidence-topology.js +0 -257
  428. package/dist/domain/mcp/tools/manager-qa.d.ts +0 -4
  429. package/dist/domain/mcp/tools/manager-qa.js +0 -63
  430. package/dist/domain/mcp/tools/task-monitor.d.ts +0 -3
  431. package/dist/domain/mcp/tools/task-monitor.js +0 -92
  432. package/dist/domain/mcp/tools/thread-ops.js +0 -73
  433. package/dist/domain/scheduling/jobs/register-thread-session.d.ts +0 -15
  434. package/dist/domain/scheduling/jobs/register-thread-session.js +0 -32
  435. package/dist/domain/scheduling/jobs/target-dispatch.d.ts +0 -30
  436. package/dist/domain/scheduling/jobs/target-dispatch.js +0 -33
  437. package/dist/domain/scheduling/jobs/task-archive.d.ts +0 -2
  438. package/dist/domain/scheduling/jobs/task-archive.js +0 -16
  439. package/dist/domain/scheduling/jobs/task-dispatch.d.ts +0 -12
  440. package/dist/domain/scheduling/jobs/task-dispatch.js +0 -402
  441. package/dist/domain/tasks/acceptance-ledger.d.ts +0 -39
  442. package/dist/domain/tasks/acceptance-ledger.js +0 -133
  443. package/dist/domain/tasks/archiver.d.ts +0 -10
  444. package/dist/domain/tasks/archiver.js +0 -133
  445. package/dist/domain/tasks/claim-recovery.d.ts +0 -9
  446. package/dist/domain/tasks/claim-recovery.js +0 -54
  447. package/dist/domain/tasks/dispatch-utils.d.ts +0 -117
  448. package/dist/domain/tasks/dispatcher.d.ts +0 -49
  449. package/dist/domain/tasks/dispatcher.js +0 -305
  450. package/dist/domain/tasks/lint.d.ts +0 -12
  451. package/dist/domain/tasks/lint.js +0 -130
  452. package/dist/domain/tasks/mutator.d.ts +0 -39
  453. package/dist/domain/tasks/mutator.js +0 -176
  454. package/dist/domain/tasks/production-topology-ledger.d.ts +0 -106
  455. package/dist/domain/tasks/production-topology-ledger.js +0 -161
  456. package/dist/domain/tasks/system/task-cli.d.ts +0 -7
  457. package/dist/domain/tasks/system/task-cli.js +0 -991
  458. package/dist/domain/tasks/system/task-completion.d.ts +0 -44
  459. package/dist/domain/tasks/system/task-completion.js +0 -262
  460. package/dist/domain/tasks/system/task-file-input.d.ts +0 -10
  461. package/dist/domain/tasks/system/task-file-input.js +0 -53
  462. package/dist/domain/tasks/system/task-id-utils.d.ts +0 -24
  463. package/dist/domain/tasks/system/task-id-utils.js +0 -90
  464. package/dist/domain/tasks/system/task-lifecycle-edit.d.ts +0 -40
  465. package/dist/domain/tasks/system/task-lifecycle-edit.js +0 -419
  466. package/dist/domain/tasks/system/task-lock.d.ts +0 -44
  467. package/dist/domain/tasks/system/task-lock.js +0 -137
  468. package/dist/domain/tasks/system/task-mutations.d.ts +0 -86
  469. package/dist/domain/tasks/system/task-mutations.js +0 -336
  470. package/dist/domain/tasks/system/task-state.d.ts +0 -140
  471. package/dist/domain/tasks/system/task-state.js +0 -287
  472. package/dist/domain/threads/artifact-io.d.ts +0 -4
  473. package/dist/domain/threads/artifact-io.js +0 -57
  474. package/dist/domain/threads/contract.d.ts +0 -17
  475. package/dist/domain/threads/contract.js +0 -54
  476. package/dist/domain/threads/evidence-context.d.ts +0 -2
  477. package/dist/domain/threads/evidence-context.js +0 -40
  478. package/dist/domain/threads/hook-runner.d.ts +0 -7
  479. package/dist/domain/threads/hook-runner.js +0 -237
  480. package/dist/domain/threads/index.d.ts +0 -7
  481. package/dist/domain/threads/index.js +0 -13
  482. package/dist/domain/threads/pending-user-inputs.d.ts +0 -3
  483. package/dist/domain/threads/pending-user-inputs.js +0 -33
  484. package/dist/domain/threads/prompt-builder.d.ts +0 -55
  485. package/dist/domain/threads/prompt-builder.js +0 -245
  486. package/dist/domain/threads/runner.d.ts +0 -150
  487. package/dist/domain/threads/runner.js +0 -832
  488. package/dist/domain/threads/shell-templates.d.ts +0 -9
  489. package/dist/domain/threads/shell-templates.js +0 -108
  490. package/dist/domain/threads/state-machine.d.ts +0 -96
  491. package/dist/domain/threads/state-machine.js +0 -646
  492. package/dist/domain/threads/template-loader.d.ts +0 -37
  493. package/dist/domain/threads/template-loader.js +0 -487
  494. package/dist/domain/threads/template-validate.d.ts +0 -287
  495. package/dist/domain/threads/template-validate.js +0 -575
  496. package/dist/domain/threads/template-validate.parity.d.ts +0 -1
  497. package/dist/domain/threads/template-validate.parity.js +0 -39
  498. package/dist/domain/threads/template-writer.d.ts +0 -57
  499. package/dist/domain/threads/template-writer.js +0 -126
  500. package/dist/domain/threads/thread-transcript.d.ts +0 -60
  501. package/dist/domain/threads/thread-transcript.js +0 -117
  502. package/dist/domain/threads/tree.d.ts +0 -46
  503. package/dist/domain/threads/tree.js +0 -196
  504. package/dist/domain/threads/utils.d.ts +0 -24
  505. package/dist/domain/threads/utils.js +0 -55
  506. package/dist/domain/ui-service/mutate/tasks.d.ts +0 -23
  507. package/dist/domain/ui-service/mutate/tasks.js +0 -58
  508. package/dist/domain/ui-service/mutate/thread-templates.d.ts +0 -4
  509. package/dist/domain/ui-service/mutate/thread-templates.js +0 -46
  510. package/dist/domain/ui-service/mutate/threads.d.ts +0 -4
  511. package/dist/domain/ui-service/mutate/threads.js +0 -19
  512. package/dist/domain/ui-service/query/task-verification.d.ts +0 -2
  513. package/dist/domain/ui-service/query/task-verification.js +0 -58
  514. package/dist/domain/ui-service/query/tasks.d.ts +0 -3
  515. package/dist/domain/ui-service/query/tasks.js +0 -73
  516. package/dist/domain/ui-service/query/thread-template-detail.d.ts +0 -2
  517. package/dist/domain/ui-service/query/thread-template-detail.js +0 -57
  518. package/dist/domain/ui-service/query/thread-templates.d.ts +0 -15
  519. package/dist/domain/ui-service/query/thread-templates.js +0 -79
  520. package/dist/domain/ui-service/query/threads.d.ts +0 -3
  521. package/dist/domain/ui-service/query/threads.js +0 -180
  522. package/dist/hooks/task-status-check.mjs +0 -166
  523. package/dist/hooks/tasks-yaml-guard.mjs +0 -225
  524. package/dist/orchestration/dispatch-reconciler.d.ts +0 -1
  525. package/dist/orchestration/dispatch-reconciler.js +0 -19
  526. package/dist/orchestration/human-answer-backstop.d.ts +0 -36
  527. package/dist/orchestration/human-answer-backstop.js +0 -69
  528. package/dist/orchestration/manager-qa.d.ts +0 -66
  529. package/dist/orchestration/manager-qa.js +0 -356
  530. package/dist/orchestration/routing/commands/dispatch.d.ts +0 -2
  531. package/dist/orchestration/routing/commands/dispatch.js +0 -48
  532. package/dist/orchestration/routing/commands/task.d.ts +0 -4
  533. package/dist/orchestration/routing/commands/task.js +0 -140
  534. package/dist/orchestration/routing/commands/thread-handlers.d.ts +0 -2
  535. package/dist/orchestration/routing/commands/thread-handlers.js +0 -152
  536. package/dist/orchestration/thread-callback.d.ts +0 -107
  537. package/dist/orchestration/thread-callback.js +0 -555
  538. package/dist/orchestration/thread-delivery.d.ts +0 -40
  539. package/dist/orchestration/thread-delivery.js +0 -76
  540. package/dist/orchestration/thread-executor.d.ts +0 -25
  541. package/dist/orchestration/thread-executor.js +0 -180
  542. package/dist/orchestration/thread-input.d.ts +0 -15
  543. package/dist/orchestration/thread-input.js +0 -50
  544. package/dist/orchestration/thread-notices.d.ts +0 -43
  545. package/dist/orchestration/thread-notices.js +0 -195
  546. package/dist/orchestration/thread-run/index.d.ts +0 -3
  547. package/dist/orchestration/thread-run/index.js +0 -2
  548. package/dist/orchestration/thread-run/render-summary.d.ts +0 -57
  549. package/dist/orchestration/thread-run/render-summary.js +0 -109
  550. package/dist/orchestration/thread-run/render-task.d.ts +0 -94
  551. package/dist/orchestration/thread-run/render-task.js +0 -154
  552. package/dist/orchestration/thread-run/settle.d.ts +0 -11
  553. package/dist/orchestration/thread-run/settle.js +0 -18
  554. package/dist/orchestration/thread-run/thread-run.d.ts +0 -114
  555. package/dist/orchestration/thread-run/thread-run.js +0 -181
  556. package/dist/orchestration/thread-run/thread-surface.d.ts +0 -41
  557. package/dist/orchestration/thread-run/thread-surface.js +0 -23
  558. package/dist/orchestration/thread-run/verdict.d.ts +0 -11
  559. package/dist/orchestration/thread-run/verdict.js +0 -20
  560. package/dist/store/plugin-retirement.d.ts +0 -37
  561. package/dist/store/plugin-retirement.js +0 -144
  562. package/dist/store/task-repo.d.ts +0 -43
  563. package/dist/store/task-repo.js +0 -143
  564. package/dist/store/thread-repo.d.ts +0 -65
  565. package/dist/store/thread-repo.js +0 -294
  566. package/dist/tui/components/DashboardTasksTab.d.ts +0 -12
  567. package/dist/tui/components/DashboardTasksTab.js +0 -196
  568. package/dist/tui/components/DashboardThreadsTab.d.ts +0 -11
  569. package/dist/tui/components/DashboardThreadsTab.js +0 -96
  570. package/web/dist/assets/index-C9sEss8T.css +0 -1
  571. package/web/dist/assets/index-fVf_wSMQ.js +0 -447
  572. /package/defaults/config/{thread-templates/agents → environments}/creative.json +0 -0
  573. /package/dist/core/types/{thread-types.js → benchmark-types.js} +0 -0
  574. /package/dist/domain/{threads/template-resolver.d.ts → agents/environments/prompt-includes.d.ts} +0 -0
@@ -1,181 +0,0 @@
1
- import { createLogger } from '../../core/log.js';
2
- import { threadStore } from '../../store/thread-repo.js';
3
- import { continueThread, resumeRateLimitedThread, resumeThread, runThread, } from '../../domain/threads/runner.js';
4
- import { buildInteractiveCallbacks } from '../turn/turn.js';
5
- import { trackPendingTask } from '../busy-tracker.js';
6
- import { createThreadSurface } from './thread-surface.js';
7
- import { openSummaryStatus, renderSummaryOutcome, renderSummaryProgress } from './render-summary.js';
8
- import { makeTaskProgressRenderer, renderTaskOutcome, taskStartText, } from './render-task.js';
9
- import { settleThreadRun } from './settle.js';
10
- import { classifyThreadVerdict } from './verdict.js';
11
- const log = createLogger('thread-run');
12
- /**
13
- * Run one thread on one surface, to completion.
14
- *
15
- * Resolves once the terminal render and the settle hook are done. It does NOT reject for a failure
16
- * inside the run: the failure IS the outcome (`verdict: 'failed' | 'cancelled'`), already rendered
17
- * and logged, and callers — the dispatch path above all — need the verdict to decide what happens
18
- * to the task. Rendering and settle failures are logged too. A status message that cannot be posted
19
- * is tolerated (the run continues with nowhere to draw); only an unexpected failure while opening
20
- * the surface itself escapes.
21
- *
22
- * The daemon busy gate is NOT taken here: `ThreadExecutor.route` already brackets its queued work
23
- * and `resume-dispatcher` brackets its own fire-and-forget resume. `openThreadRunDetached` below is
24
- * the one path that has no bracket of its own and therefore takes it.
25
- */
26
- export async function openThreadRun(input) {
27
- return new ThreadRun(input).run();
28
- }
29
- class ThreadRun {
30
- input;
31
- startTime;
32
- constructor(input) {
33
- this.input = input;
34
- this.startTime = input.startTime ?? Date.now();
35
- }
36
- async run() {
37
- const { adapter, destination, threadAnchorId, render, threadId } = this.input;
38
- if (render.kind === 'task' && !this.input.decide) {
39
- throw new Error('ThreadRun: a task-style render requires `decide`');
40
- }
41
- // 1. Status message: the caller's, or our own two-step post (text first, then the same text
42
- // with the Cancel button once the thread id is known).
43
- const statusMsg = this.input.statusMessage ?? await this.postStatus();
44
- // 2. The platform thread everything hangs off: the caller's anchor, else the status message we
45
- // just posted. Only a claiming caller (`!thread`) makes that message the record's platform
46
- // root — see `claimPlatformThread`.
47
- const anchor = threadAnchorId ?? statusMsg?.messageId ?? null;
48
- if (this.input.claimPlatformThread && !this.input.statusMessage && anchor)
49
- await this.stampPlatformThread(anchor);
50
- const stream = adapter.openOutputStream(destination, { threadId: anchor, anchorRef: statusMsg });
51
- const surface = createThreadSurface({
52
- adapter, statusMsg, threadId, startTime: this.startTime,
53
- renderProgress: render.kind === 'task' ? makeTaskProgressRenderer(render) : renderSummaryProgress,
54
- interactive: this.input.interactive ? buildInteractiveCallbacks(this.input.channel, null) : null,
55
- });
56
- // 3. Run. A throw is a verdict, not an escape — see the class doc.
57
- let result = null;
58
- let error = null;
59
- try {
60
- result = await this.invoke({
61
- channel: this.input.channel, startTime: this.startTime, stream, surface,
62
- ...(this.input.files ? { files: this.input.files } : {}),
63
- ...(this.input.onAbort ? { onAbort: this.input.onAbort } : {}),
64
- });
65
- }
66
- catch (e) {
67
- error = e;
68
- log.error(`thread ${threadId} ${e.cancelled ? 'cancelled' : 'failed'}: ${e.message}`);
69
- }
70
- const verdict = classifyThreadVerdict(result, error);
71
- const outcome = { verdict, result, error, statusMsg };
72
- // 4. Decide (task runs) and render. A delivery failure must not cost the caller its outcome or
73
- // the parent its wake-up, so it is logged and swallowed here (and only here).
74
- try {
75
- if (render.kind === 'task')
76
- await this.decideAndRenderTask(outcome, render);
77
- else {
78
- await renderSummaryOutcome({
79
- adapter, statusMsg, blocks: render.blocks, destination, threadAnchorId,
80
- startTime: this.startTime,
81
- }, { threadId, verdict, thread: threadStore.get(threadId), result, error });
82
- }
83
- }
84
- catch (e) {
85
- log.warn(`render ${verdict} for ${threadId}: ${e.message}`);
86
- }
87
- // 5. Persist the live ref for a run that will be re-entered, then wake whoever is waiting.
88
- await settleThreadRun({ threadId, verdict, statusMsg, settle: this.input.settle });
89
- return outcome;
90
- }
91
- /** The task surface's step 4: the owning job's domain effects first, its verdict rendered
92
- * second. A `decide` that throws becomes the error line and `outcome.error` — never a rejected
93
- * `openThreadRun`, because the job still has a dispatch cycle to close out. */
94
- async decideAndRenderTask(outcome, render) {
95
- let verdict;
96
- try {
97
- verdict = await this.input.decide(outcome);
98
- }
99
- catch (e) {
100
- log.error(`decide for ${this.input.threadId}: ${e.message}`);
101
- outcome.error = e;
102
- verdict = { kind: 'error', message: e.message };
103
- }
104
- await renderTaskOutcome({
105
- adapter: this.input.adapter, statusMsg: outcome.statusMsg,
106
- destination: this.input.destination, startTime: this.startTime, result: outcome.result,
107
- }, render, verdict);
108
- }
109
- async postStatus() {
110
- const { render, adapter, destination, threadAnchorId } = this.input;
111
- try {
112
- if (render.kind === 'task') {
113
- // No action blocks: nobody clicks a background surface.
114
- return await adapter.postMessage(destination, { text: taskStartText(render, this.startTime) });
115
- }
116
- if (!render.startText)
117
- return null;
118
- return await openSummaryStatus(adapter, destination, threadAnchorId, render.startText, render.blocks);
119
- }
120
- catch (e) {
121
- // The webhook's posture, now everyone's: a thread whose status line cannot be posted still
122
- // runs — it just has nowhere to draw.
123
- log.warn(`thread ${this.input.threadId}: status message post failed: ${e.message}`);
124
- return null;
125
- }
126
- }
127
- /** Stamp the platform thread root onto the record when the caller could not know it yet (it is
128
- * the id of the status message we posted a moment ago). `!thread` did this inside createThread. */
129
- async stampPlatformThread(anchor) {
130
- if (threadStore.get(this.input.threadId)?.platformThreadId)
131
- return;
132
- await threadStore.mutate(this.input.threadId, (t) => { t.platformThreadId = anchor; })
133
- .catch((e) => log.warn(`stamp platformThreadId ${this.input.threadId}: ${e.message}`));
134
- }
135
- invoke(opts) {
136
- const { threadId, mode } = this.input;
137
- switch (mode.kind) {
138
- case 'continue': return continueThread(threadId, mode.userMessage, opts);
139
- case 'resume': return resumeThread(threadId, opts);
140
- case 'resume-rate-limited': return resumeRateLimitedThread(threadId, opts);
141
- default: return runThread(threadId, opts);
142
- }
143
- }
144
- }
145
- /**
146
- * Run a thread fire-and-forget while holding the daemon busy gate for the ENTIRE pipeline.
147
- * (Verbatim port of the detached-run helper thread-executor used to own; its doc follows.)
148
- *
149
- * The Slack `!thread` path (ThreadExecutor.route), the scheduled-task path, and the task-dispatch
150
- * path all bracket their run with trackPendingTask(±1). The MCP `thread_start` webhook path did
151
- * not — so a background thread was invisible to the busy/idle gate, and a deploy/restart deferred
152
- * during the orchestrating session's turn would fire on the next idle and SIGTERM app.ts
153
- * mid-thread, stamping it "Interrupted by server restart". This helper closes that gap.
154
- *
155
- * track(+1) is synchronous so the daemon observes `busy` before it can act on any idle. The gate is
156
- * held across the run, the render, the settle AND the `onSettled` callback: settling wakes the
157
- * parent agent for a full LLM turn, and `track(-1)` synchronously emits IPC `idle`. If we released
158
- * the gate first, a deferred restart would fire mid-callback and SIGTERM app.ts, dropping the
159
- * proactive completion notification. So we await `onSettled` first, then release. track(-1) lives
160
- * in an inner `finally` so the gate never leaks. Errors are only logged (the caller already
161
- * returned the threadId to the MCP client, which polls thread_status). `deps` is injectable for
162
- * unit tests.
163
- */
164
- export function openThreadRunDetached(input, onSettled, deps = {}) {
165
- const run = deps.run ?? openThreadRun;
166
- const track = deps.track ?? trackPendingTask;
167
- track(+1);
168
- run(input)
169
- .catch((e) => log.error(`detached thread ${input.threadId} failed: ${e.message}`))
170
- .finally(async () => {
171
- try {
172
- await onSettled?.(input.threadId);
173
- }
174
- catch (e) {
175
- log.error(`detached thread ${input.threadId} onSettled error: ${e.message}`);
176
- }
177
- finally {
178
- track(-1);
179
- }
180
- });
181
- }
@@ -1,41 +0,0 @@
1
- import type { MessageRef, PlatformAdapter } from '../../platform/index.js';
2
- import type { ThreadSurface } from '../../core/types/thread-types.js';
3
- /** What `turn.buildInteractiveCallbacks` returns; null for a surface with no live user. */
4
- export interface InteractiveCapture {
5
- onToolUse?: ((name: string, input: any) => void) | null;
6
- onPlanWritten?: ((event: {
7
- path: string;
8
- content: string;
9
- toolUseId: string;
10
- }) => void) | null;
11
- onAskUserQuestion?: ((event: {
12
- toolUseId: string;
13
- questions: Array<{
14
- question: string;
15
- options?: string[];
16
- multi?: boolean;
17
- }>;
18
- }) => void) | null;
19
- }
20
- /** Renders one step report as a status line, or null to draw nothing for it. `phase` separates
21
- * the two reports a renderer may treat differently: the scheduler's line is only redrawn on
22
- * in-step progress (its step boundary has always drawn nothing), while the multi-agent line is
23
- * redrawn on both. */
24
- export type ProgressRenderer = (info: {
25
- threadId: string;
26
- phase: 'step-started' | 'step-progress';
27
- stepNumber: number;
28
- label: string;
29
- multiAgent: boolean;
30
- numTurns: number | null;
31
- durationMs: number | null;
32
- startTime: number;
33
- }) => string | null;
34
- export declare function createThreadSurface(opts: {
35
- adapter: PlatformAdapter;
36
- statusMsg: MessageRef | null;
37
- threadId: string;
38
- startTime: number;
39
- renderProgress: ProgressRenderer;
40
- interactive: InteractiveCapture | null;
41
- }): ThreadSurface;
@@ -1,23 +0,0 @@
1
- import { writeStatus } from '../status-helpers.js';
2
- export function createThreadSurface(opts) {
3
- const { adapter, statusMsg, threadId, startTime, renderProgress, interactive } = opts;
4
- const text = (phase, stepNumber, label, multiAgent, numTurns, durationMs) => statusMsg ? renderProgress({ threadId, phase, stepNumber, label, multiAgent, numTurns, durationMs, startTime }) : null;
5
- return {
6
- onStepStarted({ stepNumber, label, multiAgent }) {
7
- const line = text('step-started', stepNumber, label, multiAgent, null, null);
8
- if (line === null)
9
- return;
10
- // Returned so the runner keeps its "status line lands before the step starts" ordering.
11
- return writeStatus(adapter, statusMsg, line);
12
- },
13
- onStepProgress({ stepNumber, label, multiAgent, numTurns, durationMs }) {
14
- const line = text('step-progress', stepNumber, label, multiAgent, numTurns, durationMs);
15
- if (line === null)
16
- return;
17
- void writeStatus(adapter, statusMsg, line).catch(() => { });
18
- },
19
- onToolUse: interactive?.onToolUse ?? null,
20
- onPlanWritten: interactive?.onPlanWritten ?? null,
21
- onAskUserQuestion: interactive?.onAskUserQuestion ?? null,
22
- };
23
- }
@@ -1,11 +0,0 @@
1
- import type { ThreadRunResult } from '../../domain/threads/runner.js';
2
- export type ThreadVerdict = 'completed' | 'failed' | 'cancelled' | 'waiting' | 'rate_limited' | 'rate_limited_exhausted';
3
- /** The verdict rule, once:
4
- * - a throw is `cancelled` when it carries `.cancelled` (the Cancel button / `!stop`), else `failed`;
5
- * - a return is read off the PERSISTED status — `waiting` (thread_wait) and `rate_limited`
6
- * (provider pause) are both non-terminal re-entry points, not completions;
7
- * - a run that reports `rateLimited` without the thread being paused exhausted every fallback;
8
- * - everything else — including `aborted` and `split` — is a completion whose summary text
9
- * already spells out which (`buildThreadSummary`).
10
- */
11
- export declare function classifyThreadVerdict(result: ThreadRunResult | null, error: Error | null): ThreadVerdict;
@@ -1,20 +0,0 @@
1
- /** The verdict rule, once:
2
- * - a throw is `cancelled` when it carries `.cancelled` (the Cancel button / `!stop`), else `failed`;
3
- * - a return is read off the PERSISTED status — `waiting` (thread_wait) and `rate_limited`
4
- * (provider pause) are both non-terminal re-entry points, not completions;
5
- * - a run that reports `rateLimited` without the thread being paused exhausted every fallback;
6
- * - everything else — including `aborted` and `split` — is a completion whose summary text
7
- * already spells out which (`buildThreadSummary`).
8
- */
9
- export function classifyThreadVerdict(result, error) {
10
- if (error)
11
- return error.cancelled ? 'cancelled' : 'failed';
12
- const status = result?.thread?.status;
13
- if (status === 'waiting')
14
- return 'waiting';
15
- if (status === 'rate_limited')
16
- return 'rate_limited';
17
- if (result?.lastAgentResult?.rateLimited)
18
- return 'rate_limited_exhausted';
19
- return 'completed';
20
- }
@@ -1,37 +0,0 @@
1
- /** versions.json key guarding this one-shot rewrite. Present → already run; the user is free to
2
- * re-add a retired plugin dir by hand afterwards without us stripping it again on next boot. */
3
- export declare const TEMPLATE_PLUGIN_REFS_KEY = "config/thread-templates/agents";
4
- /** Plugins that no longer ship, with the last version that did.
5
- *
6
- * `lastShippedVersion` is the customization discriminator. A deployed copy at or below it is the
7
- * stock copy we put there, so dropping its reference loses nothing the user wrote. A copy above it
8
- * was re-versioned locally — someone is maintaining that plugin themselves, and its reference is
9
- * left alone. Files on disk are never deleted either way: an unreferenced plugin is inert, and a
10
- * wrongly-deleted one is unrecoverable. */
11
- export declare const RETIRED_TEMPLATE_PLUGINS: ReadonlyArray<{
12
- name: string;
13
- lastShippedVersion: string;
14
- }>;
15
- /** Plugin dirs that started shipping after older installs were created, keyed by the agent files
16
- * whose shipped definition carries them. Deployed templates are never rewritten by an upgrade, so
17
- * without this a newly bundled plugin lands in DATA_DIR/plugins and is never loaded by anything. */
18
- export declare const ADDED_TEMPLATE_PLUGIN_DIRS: ReadonlyArray<{
19
- agents: readonly string[];
20
- dir: string;
21
- }>;
22
- export interface RetirementOptions {
23
- /** Override DATA_DIR. Tests point this at a temp tree; production passes nothing. */
24
- dataDir?: string;
25
- }
26
- /**
27
- * One-shot rewrite of deployed agent templates so they match the plugin set that actually ships.
28
- *
29
- * Drops pluginDirs entries pointing at a retired plugin whose deployed copy is missing (a dead
30
- * pointer) or stock (ours to retire), and adds plugin dirs that began shipping after the install
31
- * was created. Locally customized retired plugins keep their references. Nothing on disk is
32
- * deleted, and agent files the rewrite does not change are not rewritten at all.
33
- *
34
- * Guarded by a versions.json sentinel so it runs exactly once per install: afterwards the user can
35
- * re-add any of these dirs by hand and it stays. Returns the agent file names that changed.
36
- */
37
- export declare function retireTemplatePluginRefs(opts?: RetirementOptions): Promise<string[]>;
@@ -1,144 +0,0 @@
1
- //
2
- // CONVENTION: retiring or moving a plugin takes THREE edits, not one.
3
- // 1. remove it from defaults/plugins/ and from the shipped templates' pluginDirs
4
- // 2. add it to RETIRED_TEMPLATE_PLUGINS here, with the last version you shipped
5
- // 3. if individual skills moved between plugins, add RETIRED_PLUGIN_PATHS entries in
6
- // plugin-sync.ts so the old copy stops competing with the new one
7
- // Step 1 alone is a no-op for every existing install.
8
- import * as fs from 'node:fs/promises';
9
- import * as path from 'node:path';
10
- import { DATA_DIR } from '../core/paths.js';
11
- import { atomicWrite } from '../core/atomic-write.js';
12
- import { CORTEX_VERSION } from '../core/version.js';
13
- import { createLogger } from '../core/log.js';
14
- import { parsePluginVersion } from './plugin-sync.js';
15
- import { compareCalVer, loadVersionsFrom, saveVersionsTo } from './version-migrations.js';
16
- const log = createLogger('plugin-retirement');
17
- /** versions.json key guarding this one-shot rewrite. Present → already run; the user is free to
18
- * re-add a retired plugin dir by hand afterwards without us stripping it again on next boot. */
19
- export const TEMPLATE_PLUGIN_REFS_KEY = 'config/thread-templates/agents';
20
- /** Plugins that no longer ship, with the last version that did.
21
- *
22
- * `lastShippedVersion` is the customization discriminator. A deployed copy at or below it is the
23
- * stock copy we put there, so dropping its reference loses nothing the user wrote. A copy above it
24
- * was re-versioned locally — someone is maintaining that plugin themselves, and its reference is
25
- * left alone. Files on disk are never deleted either way: an unreferenced plugin is inert, and a
26
- * wrongly-deleted one is unrecoverable. */
27
- export const RETIRED_TEMPLATE_PLUGINS = [
28
- // Trimmed from the bundled set in 2026.9.8 (commit e50411c58).
29
- { name: 'cortex-common', lastShippedVersion: '0.1.5' },
30
- { name: 'cortex-coder', lastShippedVersion: '0.1.2' },
31
- { name: 'cortex-stage-gate', lastShippedVersion: '0.1.4' },
32
- ];
33
- /** Plugin dirs that started shipping after older installs were created, keyed by the agent files
34
- * whose shipped definition carries them. Deployed templates are never rewritten by an upgrade, so
35
- * without this a newly bundled plugin lands in DATA_DIR/plugins and is never loaded by anything. */
36
- export const ADDED_TEMPLATE_PLUGIN_DIRS = [
37
- // cortex-commission split out of cortex-system in 2026.9.8; loads only where commissions start.
38
- { agents: ['main', 'direct', 'direct-web'], dir: 'plugins/cortex-commission' },
39
- ];
40
- /** Which retired plugin a pluginDirs entry points at, or null if it points elsewhere.
41
- * Only direct children of DATA_DIR/plugins count — an entry aimed anywhere else is the user's
42
- * own layout and not ours to rewrite. */
43
- function retiredNameOf(entry, dataDir) {
44
- const abs = path.isAbsolute(entry) ? entry : path.resolve(dataDir, entry);
45
- const rel = path.relative(path.join(dataDir, 'plugins'), abs);
46
- if (!rel || rel.startsWith('..') || rel.includes(path.sep))
47
- return null;
48
- return RETIRED_TEMPLATE_PLUGINS.some((p) => p.name === rel) ? rel : null;
49
- }
50
- /** Classify the deployed copy of a retired plugin. A manifest we cannot read counts as customized:
51
- * the safe default when we cannot prove the copy is ours is to leave it wired up. */
52
- async function classifyRetired(pluginsDir, name, lastShippedVersion) {
53
- let manifest;
54
- try {
55
- manifest = await fs.readFile(path.join(pluginsDir, name, '.claude-plugin', 'plugin.json'), 'utf8');
56
- }
57
- catch (e) {
58
- return e.code === 'ENOENT' ? 'absent' : 'customized';
59
- }
60
- const deployed = parsePluginVersion(manifest);
61
- if (!deployed)
62
- return 'customized';
63
- return compareCalVer(deployed, lastShippedVersion) <= 0 ? 'stock' : 'customized';
64
- }
65
- async function listAgentFiles(agentsDir) {
66
- try {
67
- return (await fs.readdir(agentsDir)).filter((f) => f.endsWith('.json')).sort();
68
- }
69
- catch (e) {
70
- if (e.code !== 'ENOENT') {
71
- log.warn(`cannot read ${agentsDir}: ${e.message}`);
72
- }
73
- return [];
74
- }
75
- }
76
- /**
77
- * One-shot rewrite of deployed agent templates so they match the plugin set that actually ships.
78
- *
79
- * Drops pluginDirs entries pointing at a retired plugin whose deployed copy is missing (a dead
80
- * pointer) or stock (ours to retire), and adds plugin dirs that began shipping after the install
81
- * was created. Locally customized retired plugins keep their references. Nothing on disk is
82
- * deleted, and agent files the rewrite does not change are not rewritten at all.
83
- *
84
- * Guarded by a versions.json sentinel so it runs exactly once per install: afterwards the user can
85
- * re-add any of these dirs by hand and it stays. Returns the agent file names that changed.
86
- */
87
- export async function retireTemplatePluginRefs(opts = {}) {
88
- const dataDir = opts.dataDir ?? DATA_DIR;
89
- const pluginsDir = path.join(dataDir, 'plugins');
90
- const storeDir = path.join(dataDir, 'data');
91
- const versionsFile = path.join(storeDir, 'versions.json');
92
- const versions = await loadVersionsFrom(versionsFile);
93
- if (versions[TEMPLATE_PLUGIN_REFS_KEY])
94
- return [];
95
- const agentsDir = path.join(dataDir, 'config', 'thread-templates', 'agents');
96
- const files = await listAgentFiles(agentsDir);
97
- // Classify each retired plugin once, not once per file.
98
- const states = new Map();
99
- for (const { name, lastShippedVersion } of RETIRED_TEMPLATE_PLUGINS) {
100
- states.set(name, await classifyRetired(pluginsDir, name, lastShippedVersion));
101
- }
102
- const changed = [];
103
- for (const file of files) {
104
- const absPath = path.join(agentsDir, file);
105
- let agent;
106
- try {
107
- agent = JSON.parse(await fs.readFile(absPath, 'utf8'));
108
- }
109
- catch (e) {
110
- log.warn(`skipping ${file}: ${e.message}`);
111
- continue;
112
- }
113
- const dirs = agent.pluginDirs;
114
- if (!Array.isArray(dirs) || !dirs.every((d) => typeof d === 'string'))
115
- continue;
116
- const kept = dirs.filter((entry) => {
117
- const name = retiredNameOf(entry, dataDir);
118
- if (!name)
119
- return true;
120
- const state = states.get(name);
121
- if (state === 'customized')
122
- return true;
123
- log.info(`${file}: dropping ${entry} (${state} retired plugin)`);
124
- return false;
125
- });
126
- const agentName = file.replace(/\.json$/, '');
127
- for (const { agents, dir } of ADDED_TEMPLATE_PLUGIN_DIRS) {
128
- if (!agents.includes(agentName) || kept.includes(dir))
129
- continue;
130
- kept.push(dir);
131
- log.info(`${file}: adding ${dir}`);
132
- }
133
- if (kept.length === dirs.length && kept.every((d, i) => d === dirs[i]))
134
- continue;
135
- agent.pluginDirs = kept;
136
- await atomicWrite(absPath, JSON.stringify(agent, null, 2) + '\n');
137
- changed.push(file);
138
- }
139
- versions[TEMPLATE_PLUGIN_REFS_KEY] = CORTEX_VERSION;
140
- await saveVersionsTo(versionsFile, versions);
141
- if (changed.length > 0)
142
- log.info(`rewrote plugin refs in ${changed.length} agent template(s)`);
143
- return changed;
144
- }
@@ -1,43 +0,0 @@
1
- export interface TaskRepoOptions {
2
- /** Skip git-add/commit/push after mutations — for tests. Defaults to false. */
3
- skipGit?: boolean;
4
- }
5
- export declare class TaskRepo {
6
- private tasks;
7
- private taskMutex;
8
- private initialized;
9
- private readonly skipGit;
10
- constructor(opts?: TaskRepoOptions);
11
- /** Load all tasks from TASKS.yaml files into memory */
12
- load(): void;
13
- /** Reload tasks from files (e.g. after external edit or git pull) */
14
- refresh(): void;
15
- /**
16
- * WARNING: this refreshes from disk on every call — `load()` walks every TASKS.yaml.
17
- * task-dispatcher invokes this on every dispatch tick, so this is a
18
- * hot path. If you observe dispatcher latency regression, this is the first
19
- * suspect — consider caching or splitting into a `getActionableCached()` fast-path.
20
- */
21
- getActionable(): any[];
22
- getAll(project?: string): any[];
23
- getById(taskId: string): any | null;
24
- getStats(): any;
25
- getGpuBusyMachines(): Map<string, number>;
26
- runExclusive<T>(fn: () => T | Promise<T>): Promise<T>;
27
- /**
28
- * Wait for any in-flight `runExclusive` / mutation to drain.
29
- * Acquire-release the mutex; FIFO ordering guarantees all preceding
30
- * operations have completed when this resolves.
31
- * Mutations await `commitAndPush` inside the mutex, so git sync is always done by the time
32
- * the mutex releases.
33
- * Known limitation: asyncPush errors may be lost during SIGTERM drain —
34
- * matching current task-store.ts behavior.
35
- */
36
- flush(): Promise<void>;
37
- /** Commit TASKS.yaml changes and push to origin/main.
38
- * Async: git runs on the shared event loop, so the three commands are awaited instead of
39
- * blocking every session/socket in the process (they used to run via execSync). */
40
- commitAndPush(message: string): Promise<void>;
41
- private asyncPush;
42
- }
43
- export declare const taskStore: TaskRepo;
@@ -1,143 +0,0 @@
1
- import * as path from 'path';
2
- import { spawn } from 'child_process';
3
- import { runFile } from '../core/exec-async.js';
4
- import { PROJECTS_DIR, DATA_DIR } from '../core/paths.js';
5
- import { scanAllTasks, scanAvailableTasks, getTaskStatsFromTasks, } from '../core/task-parser.js';
6
- import { createLogger } from '../core/log.js';
7
- import { AsyncMutex } from '../core/async-mutex.js';
8
- const log = createLogger('task-store');
9
- export class TaskRepo {
10
- tasks = [];
11
- taskMutex = new AsyncMutex();
12
- initialized = false;
13
- skipGit;
14
- constructor(opts = {}) {
15
- this.skipGit = opts.skipGit ?? false;
16
- }
17
- /** Load all tasks from TASKS.yaml files into memory */
18
- load() {
19
- try {
20
- this.tasks = scanAllTasks();
21
- this.initialized = true;
22
- log.info(`Loaded ${this.tasks.length} tasks from ${new Set(this.tasks.map(t => t.project)).size} projects`);
23
- }
24
- catch (e) {
25
- log.error(`Failed to load tasks: ${e.message}`);
26
- this.tasks = [];
27
- }
28
- }
29
- /** Reload tasks from files (e.g. after external edit or git pull) */
30
- refresh() {
31
- this.load();
32
- }
33
- // --- Read operations (from memory, no lock needed) ---
34
- /**
35
- * WARNING: this refreshes from disk on every call — `load()` walks every TASKS.yaml.
36
- * task-dispatcher invokes this on every dispatch tick, so this is a
37
- * hot path. If you observe dispatcher latency regression, this is the first
38
- * suspect — consider caching or splitting into a `getActionableCached()` fast-path.
39
- */
40
- getActionable() {
41
- // Always refresh from disk so this.tasks stays in sync with what we return
42
- this.load();
43
- return scanAvailableTasks();
44
- }
45
- getAll(project) {
46
- if (!this.initialized)
47
- this.load();
48
- return project ? this.tasks.filter(t => t.project === project) : [...this.tasks];
49
- }
50
- getById(taskId) {
51
- if (!this.initialized)
52
- this.load();
53
- return this.tasks.find(t => t.id === taskId) || null;
54
- }
55
- getStats() {
56
- if (!this.initialized)
57
- this.load();
58
- return getTaskStatsFromTasks(this.tasks);
59
- }
60
- getGpuBusyMachines() {
61
- if (!this.initialized)
62
- this.load();
63
- const counts = new Map();
64
- for (const t of this.tasks) {
65
- if (t.gpu && t.claimed_by && t.status !== 'done') {
66
- const machine = t.gpu.toLowerCase();
67
- const gpuCount = t.gpu_count || 1;
68
- counts.set(machine, (counts.get(machine) || 0) + gpuCount);
69
- }
70
- }
71
- return counts;
72
- }
73
- // --- External exclusive access (for callers like task-archiver) ---
74
- async runExclusive(fn) {
75
- return this.taskMutex.run(fn);
76
- }
77
- // --- Graceful shutdown ---
78
- /**
79
- * Wait for any in-flight `runExclusive` / mutation to drain.
80
- * Acquire-release the mutex; FIFO ordering guarantees all preceding
81
- * operations have completed when this resolves.
82
- * Mutations await `commitAndPush` inside the mutex, so git sync is always done by the time
83
- * the mutex releases.
84
- * Known limitation: asyncPush errors may be lost during SIGTERM drain —
85
- * matching current task-store.ts behavior.
86
- */
87
- async flush() {
88
- await this.taskMutex.run(async () => { });
89
- }
90
- // --- Git sync ---
91
- /** Commit TASKS.yaml changes and push to origin/main.
92
- * Async: git runs on the shared event loop, so the three commands are awaited instead of
93
- * blocking every session/socket in the process (they used to run via execSync). */
94
- async commitAndPush(message) {
95
- if (this.skipGit)
96
- return;
97
- try {
98
- const rel = path.relative(DATA_DIR, PROJECTS_DIR);
99
- const glob = `${rel}/*/TASKS.yaml`;
100
- const added = await runFile('git', ['add', glob], { cwd: DATA_DIR, timeoutMs: 10000 });
101
- if (!added.ok) {
102
- log.error(`Git add failed: ${(added.stderr || added.stdout || added.error || '').trim()}`);
103
- return;
104
- }
105
- const status = await runFile('git', ['status', '--porcelain', '--', glob], {
106
- cwd: DATA_DIR, timeoutMs: 5000,
107
- });
108
- if (!status.ok) {
109
- log.error(`Git status failed: ${(status.stderr || status.error || '').trim()}`);
110
- return;
111
- }
112
- if (status.stdout.trim()) {
113
- const committed = await runFile('git', ['commit', '-m', message], { cwd: DATA_DIR, timeoutMs: 10000 });
114
- if (!committed.ok) {
115
- log.error(`Git commit failed: ${(committed.stderr || committed.stdout || '').trim()}`);
116
- return;
117
- }
118
- log.info(`Committed: ${message}`);
119
- this.asyncPush();
120
- }
121
- }
122
- catch (e) {
123
- log.error(`Git sync failed: ${e.message}`);
124
- }
125
- }
126
- asyncPush() {
127
- const child = spawn('git', ['push', 'origin', 'main'], {
128
- cwd: DATA_DIR,
129
- stdio: ['ignore', 'ignore', 'pipe'],
130
- detached: true,
131
- });
132
- let stderr = '';
133
- child.stderr.on('data', (d) => { stderr += d; });
134
- child.on('close', (code) => {
135
- if (code !== 0) {
136
- log.error(`Async push failed (exit ${code}): ${stderr.trim()}`);
137
- }
138
- });
139
- child.unref();
140
- }
141
- }
142
- // --- Singleton ---
143
- export const taskStore = new TaskRepo();