@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
@@ -5,13 +5,21 @@ paths:
5
5
 
6
6
  # STATUS.md Convention
7
7
 
8
- Snapshot of the project's current state. **Overwrite mode** — only keep the latest state, do not accumulate history.
8
+ The project's **present tense**: the minimal state a fresh session needs to continue working correctly. A register, not a journal.
9
+ It answers exactly four questions: where are we, what is in flight, what is in the way, what comes next.
10
+
11
+ ## Three Admission Tests (apply before every write)
12
+
13
+ 1. **Deletion test**: would removing this line cause a future session to decide wrongly or waste time? If not → do not write it.
14
+ 2. **Grows with state, not with time**: file size may only track state complexity, never project age. Entries that only get added and never removed = the file has degraded into a journal.
15
+ 3. **60-second handoff**: the whole file = what you could tell a new collaborator in 60 seconds. Anything beyond that belongs in its durable home.
9
16
 
10
17
  ## Hard Constraints
11
18
 
12
- - **Length limit: 120 lines**. Must trim if exceeded.
13
- - **Update mode: Overwrite**. Update after each related operation. Do not append historical records.
14
- - **Check line count before each write**: >=80 lines warning, >=120 lines forced trimming.
19
+ - **Update mode: overwrite-rewrite the snapshot**. Every "add a line" must be paired with a check for which existing lines it makes stale — delete those.
20
+ - **Length limit: 80 lines AND 6KB, both hard**. Scan before writing: at >=60 lines or >=4KB, warn and trim proactively; over the limit, trim below it before the write is allowed.
21
+ - **Each bullet <= 2 lines**. If it doesn't fit, the detail belongs elsewhere — keep one sentence + a pointer.
22
+ - **Facts with a durable home appear only as pointers**: task-id / EXP-NNN / K-NNN / DR-NNNN / commit SHA / file path. The only content unique to STATUS is the one-sentence synthesis of the current situation.
15
23
 
16
24
  ## Required Sections (in order)
17
25
 
@@ -20,30 +28,40 @@ Snapshot of the project's current state. **Overwrite mode** — only keep the la
20
28
 
21
29
  Updated: YYYY-MM-DD
22
30
 
23
- ## Current Phase
24
- <One paragraph, stating the current stage and core focus>
31
+ ## Current Situation
32
+ <One paragraph: position on the roadmap + core focus + one-sentence situation call>
25
33
 
26
- ## Recent Progress
27
- <One paragraph or 3-5 bullet points, only changes within this phase>
34
+ ## In Flight & New Variables
35
+ <<=5 items, each <=2 lines + pointer. Only events that changed the situation:
36
+ what got unblocked, what new constraint appeared, why the next step changed.
37
+ Delete an item the moment it stops affecting decisions — its content already
38
+ lives in tasks-archive/git/EXP, nothing to migrate. Write "none" if empty.>
28
39
 
29
- ## Unresolved Issues
30
- <Bullet list, open issues / blockers / pending decisions; write "none" if none>
40
+ ## Blockers & Pending Decisions
41
+ <External blockers, decisions awaiting the user, traps a fresh session would hit. Write "none" if empty.>
31
42
 
32
- ## Next Steps
33
- <Clear next action. Points to task-id in TASKS.yaml or a specific plan file>
43
+ ## Next Step
44
+ <The concrete next action, pointing to a TASKS.yaml task-id or a plan file>
34
45
  ```
35
46
 
47
+ ## Update Triggers
48
+
49
+ Update on state change, not on task completion: phase advance/pause/pivot, a blocker appearing or clearing, the next step changing, in-flight work landing in a way that affects decisions, session end (per the working-record discipline).
50
+
51
+ "A task finished" is not by itself a reason to write. Write only when the completion **changed the situation** (unblocked something / introduced a blocker / changed the next step), and write only the one-line situation change.
52
+
36
53
  ## Prohibited Content
37
54
 
38
- - Historical records of completed items → belongs in `tasks-archive.md`
39
- - Experiment data/conclusions → belongs in `experiments/EXP-NNN.md`
40
- - Settled knowledge/methodology → belongs in `knowledge/K-NNN.md`
41
- - Design decision trade-offs → belongs in `decisions/DR-NNNN.md`
42
- - Superseded old phase descriptions → delete directly (old phase outputs should have been settled into EXP/K/PAT)
55
+ - Task completion reports (test counts, verification steps, commit lists) → TASKS.yaml completion note / tasks-archive / task artifact
56
+ - Experiment data and conclusions → experiments/EXP-NNN.md
57
+ - Settled knowledge / methodology → knowledge/K-NNN.md
58
+ - Design decision trade-offs → decisions/DR-NNNN.md
59
+ - Change history → git log is the changelog; no file may duplicate it
60
+ - Superseded old phase descriptions → delete directly (their outputs should already be settled into EXP/K/PAT)
43
61
 
44
62
  ## Overflow Handling
45
63
 
46
- If exceeding 120 lines before writing:
47
- 1. Move entries from "Recent Progress" that span across current phase out (→ EXP/K or delete directly)
48
- 2. Delete "Completed Items" paragraph (if any)
49
- 3. Still exceeded → delete the entire old phase paragraph, keep only a one-line index pointing to the archive
64
+ When over the limit, trim in this order:
65
+ 1. Delete "In Flight & New Variables" items that no longer affect decisions
66
+ 2. Compress any bullet over 2 lines into one sentence + pointer
67
+ 3. Still over → the state itself is too complex: consider splitting a sub-project or driving the roadmap to converge, and record that call under "Blockers & Pending Decisions"
@@ -1,7 +1,7 @@
1
1
  import type { AgentResult, ContextUsage } from '../core/types/agent-types.js';
2
2
  import type { ContinuationSink } from './types.js';
3
- /** Feature gate: background-task continuation is ON by default. Opt out by setting
4
- * CORTEX_BG_CONTINUATION to a falsy value (0 / false / off / no). */
3
+ import type { NormalizedEvent } from './normalize/event-types.js';
4
+ /** Background-task continuation feature gate. */
5
5
  export declare function isBgContinuationEnabled(): boolean;
6
6
  /** Grace period for work-done-but-unnotified tasks (CORTEX_BG_GRACE_S, default 90s). */
7
7
  export declare function getBgGraceMs(): number;
@@ -12,9 +12,9 @@ export declare function remainingBg(result: {
12
12
  pendingBackgroundTasks?: number;
13
13
  undeliveredBackgroundTasks?: number;
14
14
  } | null | undefined): number;
15
- /** Gate for the facade's inline wait: thread turns only (threadId set — interactive turns are
16
- * held asynchronously by lifecycle instead), claude backend, sink capability, work remaining,
17
- * feature flag on, not rate-limited (that goes to the retry path first). */
15
+ /** Backend and result prerequisites shared by explicit and legacy inline waiting. */
16
+ export declare function canAwaitBgContinuation(backend: string, result: AgentResult | null | undefined, canRegisterSink: boolean): boolean;
17
+ /** Legacy inline policy: settings-enabled thread turns wait; interactive turns do not. */
18
18
  export declare function shouldAwaitBgInline(backend: string, threadId: string | null | undefined, result: AgentResult | null | undefined, canRegisterSink: boolean): boolean;
19
19
  export interface WaitForBgOpts {
20
20
  proc: {
@@ -26,19 +26,17 @@ export interface WaitForBgOpts {
26
26
  onToolUse?: ((name: string, input: any, toolUseId: string) => void) | null;
27
27
  onToolResult?: ((toolUseId: string, content: string, isError: boolean) => void) | null;
28
28
  onContextUsage?: ((usage: ContextUsage) => void | Promise<void>) | null;
29
+ onEvent?: ((event: NormalizedEvent) => void) | null;
29
30
  graceMs?: number;
30
31
  maxWaitMs?: number;
32
+ /** Wait without ambient release timers until continuation completion or supervised stop. */
33
+ completionOnly?: boolean;
34
+ /** Process termination boundary required by completion-only waits. */
35
+ stopPromise?: Promise<unknown>;
31
36
  /** Injectable timers for tests. Production timers are unref'd. */
32
37
  timers?: {
33
38
  set: (fn: () => void, ms: number) => unknown;
34
39
  clear: (h: unknown) => void;
35
40
  };
36
41
  }
37
- /**
38
- * Wait inline for the spontaneous background-task continuation of a turn that ended with
39
- * work remaining. Registers a ContinuationSink on the process and resolves with the merged
40
- * result when the continuation completes (chained continuations keep waiting). Never
41
- * rejects; bounded by the grace watchdog (undelivered-only) or the max-wait cap (running):
42
- * on timeout it resolves with what has accumulated so far.
43
- */
44
42
  export declare function waitForBgContinuation(opts: WaitForBgOpts): Promise<AgentResult>;
@@ -1,24 +1,21 @@
1
- // input: continuation sink, result, tool/context callbacks, timers
2
- // output: bounded inline wait forwarding complete tools and context snapshots
3
- // pos: Thread-session continuation bridge
4
- // >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
1
+ // input: continuation results, exact accounting, wait policy
2
+ // output: cache-inclusive continuation events and bounded results
3
+ // pos: Background continuation wait policy
4
+ // >>> 一旦我被更新,务必更新我的开头注释与所属文件夹 CORTEX.md <<<
5
5
  //
6
6
  // Interactive turns hold their Slack status asynchronously (orchestration/lifecycle +
7
7
  // bg-wait-guard). Thread/dispatch turns have no status message to hold — the step's
8
8
  // RESULT is the deliverable — so they wait INLINE: the facade keeps the turn promise
9
9
  // open until the spontaneous continuation completes, then resolves with the merged
10
- // result. The thread's own busy bracket covers the wait (no extra track here); the
11
- // same grace/cap bounds apply so an undelivered notification or a never-ending task
12
- // cannot hang a thread step forever.
10
+ // result. The thread's own busy bracket covers the wait (no extra track here). Ordinary
11
+ // callers use grace/cap bounds; supervised one-shot runs use completion-only mode and their
12
+ // process-stop boundary so ambient caps cannot publish success while work remains.
13
13
  import { createLogger } from '../core/log.js';
14
+ import { getSettings } from '../core/settings.js';
14
15
  const log = createLogger('bg-wait');
15
- /** Feature gate: background-task continuation is ON by default. Opt out by setting
16
- * CORTEX_BG_CONTINUATION to a falsy value (0 / false / off / no). */
16
+ /** Background-task continuation feature gate. */
17
17
  export function isBgContinuationEnabled() {
18
- const v = process.env.CORTEX_BG_CONTINUATION;
19
- if (v === undefined)
20
- return true;
21
- return !['0', 'false', 'off', 'no'].includes(v.trim().toLowerCase());
18
+ return getSettings().bgContinuation;
22
19
  }
23
20
  const DEFAULT_GRACE_MS = 90_000;
24
21
  const DEFAULT_MAX_WAIT_MS = 1_800_000;
@@ -43,22 +40,20 @@ export function remainingBg(result) {
43
40
  return 0;
44
41
  return (result.pendingBackgroundTasks ?? 0) + (result.undeliveredBackgroundTasks ?? 0);
45
42
  }
46
- /** Gate for the facade's inline wait: thread turns only (threadId set — interactive turns are
47
- * held asynchronously by lifecycle instead), claude backend, sink capability, work remaining,
48
- * feature flag on, not rate-limited (that goes to the retry path first). */
49
- export function shouldAwaitBgInline(backend, threadId, result, canRegisterSink) {
50
- if (!isBgContinuationEnabled())
51
- return false;
52
- if (backend !== 'claude')
53
- return false;
54
- if (!threadId)
55
- return false;
56
- if (!canRegisterSink)
43
+ /** Backend and result prerequisites shared by explicit and legacy inline waiting. */
44
+ export function canAwaitBgContinuation(backend, result, canRegisterSink) {
45
+ if (backend !== 'claude' || !canRegisterSink)
57
46
  return false;
58
47
  if (!result || result.rateLimited)
59
48
  return false;
60
49
  return remainingBg(result) > 0;
61
50
  }
51
+ /** Legacy inline policy: settings-enabled thread turns wait; interactive turns do not. */
52
+ export function shouldAwaitBgInline(backend, threadId, result, canRegisterSink) {
53
+ if (!isBgContinuationEnabled() || !threadId)
54
+ return false;
55
+ return canAwaitBgContinuation(backend, result, canRegisterSink);
56
+ }
62
57
  const realTimers = {
63
58
  set: (fn, ms) => {
64
59
  const h = setTimeout(fn, ms);
@@ -72,8 +67,12 @@ const realTimers = {
72
67
  function mergeContinuation(acc, cont) {
73
68
  const bothCostNull = acc.total_cost_usd == null && cont.total_cost_usd == null;
74
69
  const bothTurnsNull = acc.num_turns == null && cont.num_turns == null;
70
+ const costReported = acc.costReported === undefined && cont.costReported === undefined
71
+ ? undefined
72
+ : acc.costReported === true || cont.costReported === true;
75
73
  return {
76
74
  ...acc,
75
+ costReported,
77
76
  total_cost_usd: bothCostNull ? null : (acc.total_cost_usd ?? 0) + (cont.total_cost_usd ?? 0),
78
77
  num_turns: bothTurnsNull ? null : (acc.num_turns ?? 0) + (cont.num_turns ?? 0),
79
78
  finalOutput: cont.finalOutput || acc.finalOutput,
@@ -83,115 +82,196 @@ function mergeContinuation(acc, cont) {
83
82
  undeliveredBackgroundTasks: cont.undeliveredBackgroundTasks ?? 0,
84
83
  };
85
84
  }
85
+ function continuationCostRecord(result) {
86
+ const accounting = result.reportedAccounting;
87
+ if (result.costReported !== true && accounting?.usageReported !== true)
88
+ return null;
89
+ return {
90
+ type: 'cost_record', provider: 'anthropic', model: accounting?.model ?? 'unknown',
91
+ tokens_in: accounting?.promptTokens ?? null,
92
+ tokens_out: accounting?.outputTokens ?? null,
93
+ prompt_tokens: accounting?.promptTokens ?? null,
94
+ cached_tokens: accounting?.cachedTokens ?? null,
95
+ cost_usd: result.costReported === true ? result.total_cost_usd : null,
96
+ };
97
+ }
86
98
  /**
87
99
  * Wait inline for the spontaneous background-task continuation of a turn that ended with
88
100
  * work remaining. Registers a ContinuationSink on the process and resolves with the merged
89
- * result when the continuation completes (chained continuations keep waiting). Never
90
- * rejects; bounded by the grace watchdog (undelivered-only) or the max-wait cap (running):
91
- * on timeout it resolves with what has accumulated so far.
101
+ * result when the continuation completes (chained continuations keep waiting). Observer failures
102
+ * reject; otherwise the grace watchdog or max-wait cap resolves with the accumulated result.
92
103
  */
93
- export function waitForBgContinuation(opts) {
94
- const timers = opts.timers ?? realTimers;
95
- const graceMs = opts.graceMs ?? getBgGraceMs();
96
- const maxWaitMs = opts.maxWaitMs ?? getBgMaxWaitMs();
97
- return new Promise((resolve) => {
98
- let acc = opts.baseResult;
99
- let settled = false;
100
- let handle = null;
101
- const finish = (result) => {
102
- if (settled)
104
+ class BackgroundContinuationWait {
105
+ opts;
106
+ timers;
107
+ graceMs;
108
+ maxWaitMs;
109
+ completionOnly;
110
+ acc;
111
+ settled = false;
112
+ handle = null;
113
+ resolve;
114
+ reject;
115
+ constructor(opts, timers, graceMs, maxWaitMs, completionOnly) {
116
+ this.opts = opts;
117
+ this.timers = timers;
118
+ this.graceMs = graceMs;
119
+ this.maxWaitMs = maxWaitMs;
120
+ this.completionOnly = completionOnly;
121
+ this.acc = opts.baseResult;
122
+ }
123
+ run() {
124
+ const promise = new Promise((resolve, reject) => {
125
+ this.resolve = resolve;
126
+ this.reject = reject;
127
+ this.opts.proc.setContinuationSink?.(this.sink());
128
+ this.arm(this.opts.baseResult.pendingBackgroundTasks ?? 0, this.opts.baseResult.undeliveredBackgroundTasks ?? 0);
129
+ });
130
+ if (this.opts.stopPromise) {
131
+ void this.opts.stopPromise.then(() => this.stop(), error => this.stop(error));
132
+ }
133
+ return promise;
134
+ }
135
+ settle(complete) {
136
+ if (this.settled)
137
+ return;
138
+ this.settled = true;
139
+ if (this.handle !== null)
140
+ this.timers.clear(this.handle);
141
+ this.handle = null;
142
+ complete();
143
+ }
144
+ finish(result) {
145
+ this.settle(() => this.resolve(result));
146
+ }
147
+ stop(error) {
148
+ const failure = error instanceof Error
149
+ ? error
150
+ : new Error('Agent process stopped before background continuation completed');
151
+ this.settle(() => this.reject(failure));
152
+ }
153
+ emit(event) {
154
+ try {
155
+ this.opts.onEvent?.(event);
156
+ return true;
157
+ }
158
+ catch (error) {
159
+ this.settle(() => this.reject(error));
160
+ return false;
161
+ }
162
+ }
163
+ arm(running, undelivered) {
164
+ if (this.handle !== null)
165
+ this.timers.clear(this.handle);
166
+ this.handle = null;
167
+ if (running > 0) {
168
+ if (this.completionOnly)
103
169
  return;
104
- settled = true;
105
- if (handle !== null) {
106
- timers.clear(handle);
107
- handle = null;
108
- }
109
- resolve(result);
110
- };
111
- const arm = (running, undelivered) => {
112
- if (handle !== null) {
113
- timers.clear(handle);
114
- handle = null;
115
- }
116
- if (running > 0) {
117
- handle = timers.set(() => {
118
- log.info(`bg-wait cap (${maxWaitMs}ms) reached with ${running} task(s) still running — releasing the step`);
119
- finish(acc);
120
- }, maxWaitMs);
121
- }
122
- else if (undelivered > 0) {
123
- handle = timers.set(() => {
124
- log.info(`bg-wait grace (${graceMs}ms) elapsed with no notification — releasing the step`);
125
- finish(acc);
126
- }, graceMs);
127
- }
128
- else {
129
- finish(acc);
130
- }
170
+ this.handle = this.timers.set(() => {
171
+ log.info(`bg-wait cap (${this.maxWaitMs}ms) reached with ${running} task(s) still running — releasing the step`);
172
+ this.finish(this.acc);
173
+ }, this.maxWaitMs);
174
+ return;
175
+ }
176
+ if (undelivered > 0) {
177
+ if (this.completionOnly)
178
+ return;
179
+ this.handle = this.timers.set(() => {
180
+ log.info(`bg-wait grace (${this.graceMs}ms) elapsed with no notification — releasing the step`);
181
+ this.finish(this.acc);
182
+ }, this.graceMs);
183
+ return;
184
+ }
185
+ this.finish(this.acc);
186
+ }
187
+ sink() {
188
+ return {
189
+ onAssistantText: (text, model) => this.assistantText(text, model),
190
+ onToolUse: (name, input, id) => this.toolUse(name, input, id),
191
+ onToolResult: (id, content, isError) => this.toolResult(id, content, isError),
192
+ onContextUsage: (usage) => this.contextUsage(usage),
193
+ onResult: (result) => this.result(result),
131
194
  };
132
- opts.proc.setContinuationSink?.({
133
- onAssistantText: (text) => {
134
- if (settled)
135
- return;
136
- try {
137
- opts.onAssistantText?.(text);
138
- }
139
- catch (e) {
140
- log.warn('bg-wait onAssistantText threw:', e.message);
141
- }
142
- },
143
- onToolUse: (name, input, toolUseId) => {
144
- if (settled)
145
- return;
146
- try {
147
- opts.onToolUse?.(name, input, toolUseId ?? '');
148
- }
149
- catch (e) {
150
- log.warn('bg-wait onToolUse threw:', e.message);
151
- }
152
- },
153
- onToolResult: (toolUseId, content, isError) => {
154
- if (settled)
155
- return;
156
- try {
157
- opts.onToolResult?.(toolUseId, content, isError);
158
- }
159
- catch (e) {
160
- log.warn('bg-wait onToolResult threw:', e.message);
161
- }
162
- },
163
- onContextUsage: (usage) => {
164
- if (settled)
165
- return;
166
- try {
167
- void Promise.resolve(opts.onContextUsage?.(usage)).catch((e) => log.warn('bg-wait onContextUsage rejected:', e.message));
168
- }
169
- catch (e) {
170
- log.warn('bg-wait onContextUsage threw:', e.message);
171
- }
172
- },
173
- onResult: (cont) => {
174
- if (settled)
175
- return;
176
- if (cont.backgroundInterrupted) {
177
- // Process died mid-wait (restart / crash / kill): release the step with what we
178
- // have and surface the interruption to the caller.
179
- finish({ ...acc, backgroundInterrupted: true });
180
- return;
181
- }
182
- acc = mergeContinuation(acc, cont);
183
- if (acc.rateLimited) {
184
- finish(acc);
185
- return;
186
- }
187
- const running = cont.pendingBackgroundTasks ?? 0;
188
- const undelivered = cont.undeliveredBackgroundTasks ?? 0;
189
- if (running + undelivered > 0)
190
- arm(running, undelivered);
191
- else
192
- finish(acc);
193
- },
194
- });
195
- arm(opts.baseResult.pendingBackgroundTasks ?? 0, opts.baseResult.undeliveredBackgroundTasks ?? 0);
196
- });
195
+ }
196
+ assistantText(text, model) {
197
+ if (this.settled || !this.emit({ type: 'assistant_text', text, ...(model != null ? { model } : {}) }))
198
+ return;
199
+ try {
200
+ this.opts.onAssistantText?.(text);
201
+ }
202
+ catch (error) {
203
+ log.warn('bg-wait onAssistantText threw:', error.message);
204
+ }
205
+ }
206
+ toolUse(name, input, toolUseId) {
207
+ const id = toolUseId ?? '';
208
+ if (this.settled || !this.emit({ type: 'tool_use', name, input, toolUseId: id }))
209
+ return;
210
+ try {
211
+ this.opts.onToolUse?.(name, input, id);
212
+ }
213
+ catch (error) {
214
+ log.warn('bg-wait onToolUse threw:', error.message);
215
+ }
216
+ }
217
+ toolResult(toolUseId, content, isError) {
218
+ if (this.settled || !this.emit({ type: 'tool_result', toolUseId, content, ok: !isError }))
219
+ return;
220
+ try {
221
+ this.opts.onToolResult?.(toolUseId, content, isError);
222
+ }
223
+ catch (error) {
224
+ log.warn('bg-wait onToolResult threw:', error.message);
225
+ }
226
+ }
227
+ contextUsage(usage) {
228
+ if (this.settled || !this.emit({ type: 'context_usage', ...usage }))
229
+ return;
230
+ try {
231
+ void Promise.resolve(this.opts.onContextUsage?.(usage))
232
+ .catch((error) => log.warn('bg-wait onContextUsage rejected:', error.message));
233
+ }
234
+ catch (error) {
235
+ log.warn('bg-wait onContextUsage threw:', error.message);
236
+ }
237
+ }
238
+ result(continuation) {
239
+ if (this.settled)
240
+ return;
241
+ if (continuation.backgroundInterrupted) {
242
+ if (this.completionOnly)
243
+ this.stop();
244
+ else
245
+ this.finish({ ...this.acc, backgroundInterrupted: true });
246
+ return;
247
+ }
248
+ const costRecord = continuationCostRecord(continuation);
249
+ if (costRecord && !this.emit(costRecord))
250
+ return;
251
+ const preserveReportedness = continuation.reportedAccounting !== undefined;
252
+ if (!this.emit({
253
+ type: 'turn_complete',
254
+ numTurns: preserveReportedness ? continuation.num_turns : continuation.num_turns ?? 0,
255
+ totalCostUsd: continuation.total_cost_usd ?? null,
256
+ }))
257
+ return;
258
+ this.acc = mergeContinuation(this.acc, continuation);
259
+ if (this.acc.rateLimited) {
260
+ this.finish(this.acc);
261
+ return;
262
+ }
263
+ const running = continuation.pendingBackgroundTasks ?? 0;
264
+ const undelivered = continuation.undeliveredBackgroundTasks ?? 0;
265
+ if (running + undelivered > 0)
266
+ this.arm(running, undelivered);
267
+ else
268
+ this.finish(this.acc);
269
+ }
270
+ }
271
+ export function waitForBgContinuation(opts) {
272
+ const completionOnly = opts.completionOnly === true;
273
+ if (completionOnly && !opts.stopPromise) {
274
+ return Promise.reject(new Error('Completion-only background wait requires a stop promise'));
275
+ }
276
+ return new BackgroundContinuationWait(opts, opts.timers ?? realTimers, completionOnly ? 0 : (opts.graceMs ?? getBgGraceMs()), completionOnly ? 0 : (opts.maxWaitMs ?? getBgMaxWaitMs()), completionOnly).run();
197
277
  }
@@ -2,6 +2,7 @@ import { EventEmitter } from 'node:events';
2
2
  import { TmuxControl } from './tmux-control.js';
3
3
  import { type CortexAgentContext } from './spawn-args.js';
4
4
  import type { NormalizedEvent } from '../normalize/event-types.js';
5
+ import { type McpComposition } from '../types.js';
5
6
  /** Subset of JsonlTail surface the session depends on — lets tests inject a mock. */
6
7
  export interface JsonlTailLike extends EventEmitter {
7
8
  start(): Promise<void>;
@@ -48,7 +49,7 @@ export interface ClaudeTuiSessionConfig {
48
49
  extraOption?: Record<string, string> | null;
49
50
  /** Thinking level from the profile's `thinking` field → `--effort <level>`. Absent → no flag. */
50
51
  thinking?: string | null;
51
- mcpConfigPath?: string;
52
+ mcpComposition?: McpComposition;
52
53
  callbackSource?: string | null;
53
54
  scheduleTaskId?: string | null;
54
55
  anthropicBaseUrl?: string;
@@ -96,6 +97,7 @@ export declare class ClaudeTuiSession {
96
97
  readonly sessionId: string;
97
98
  readonly sessionKey: string;
98
99
  readonly cwd: string;
100
+ readonly mcpComposition: McpComposition;
99
101
  readonly tmuxName: string;
100
102
  readonly jsonlPath: string;
101
103
  private readonly tmux;
@@ -1,7 +1,7 @@
1
- // input: Session config (channel, sessionId, cwd, prompts/tools/model) + TUI deps (TmuxControl, tailFactory)
2
- // output: ClaudeTuiSession — interactive Claude under tmux with jsonl tail; implements turn lifecycle
3
- // pos: DR-0012 Phase 2 — parallel adapter to claude/adapter.ts; selects via spawn-args mode='tui'
4
- // >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
1
+ // input: cwd, composition, prompts, tools, TUI deps
2
+ // output: interactive Claude session with spawn policy
3
+ // pos: Runs Claude TUI sessions under tmux
4
+ // >>> 一旦我被更新,务必更新我的开头注释与所属文件夹 CORTEX.md <<<
5
5
  import { existsSync } from 'node:fs';
6
6
  import * as path from 'path';
7
7
  import { createLogger } from '../../core/log.js';
@@ -9,6 +9,7 @@ import { JsonlTail, JsonlEventNormalizer } from './jsonl-tail.js';
9
9
  import { CancelledError, TUI_TMUX_NAME_PREFIX, TUI_JSONL_BASE, IDLE_SESSION_TIMEOUT, MAX_TIMEOUT, TURN_IDLE_TIMEOUT, JSONL_FIRST_EVENT_TIMEOUT, PASTE_SUBMIT_DELAY_MS, PANE_READY_TIMEOUT, PANE_READY_POLL_MS, PANE_READY_MARKER, } from './defaults.js';
10
10
  import { buildSpawnArgs, buildClaudeEnv } from './spawn-args.js';
11
11
  import { buildPrompt, mergeSubstantialOutput } from './event-parser.js';
12
+ import { resolveMcpComposition } from '../types.js';
12
13
  const log = createLogger('claude-tui');
13
14
  // =====================================================================================
14
15
  // ClaudeTuiSession
@@ -25,6 +26,7 @@ export class ClaudeTuiSession {
25
26
  sessionId;
26
27
  sessionKey;
27
28
  cwd;
29
+ mcpComposition;
28
30
  tmuxName;
29
31
  jsonlPath;
30
32
  tmux;
@@ -49,6 +51,7 @@ export class ClaudeTuiSession {
49
51
  this.sessionId = config.sessionId;
50
52
  this.sessionKey = config.sessionKey;
51
53
  this.cwd = config.cwd;
54
+ this.mcpComposition = resolveMcpComposition(config.mcpComposition, config.context?.useCoreMcp);
52
55
  this.needsResume = config.needsResume;
53
56
  this.tmux = config.deps.tmux;
54
57
  this.tailFactory = config.deps.tailFactory;
@@ -78,7 +81,7 @@ export class ClaudeTuiSession {
78
81
  outputStyle: this.config.outputStyle ?? null,
79
82
  extraOption: this.config.extraOption ?? null,
80
83
  thinking: this.config.thinking ?? null,
81
- mcpConfigPath: this.config.mcpConfigPath,
84
+ mcpComposition: this.mcpComposition,
82
85
  needsResume: this.needsResume,
83
86
  sessionId: this.sessionId,
84
87
  mode: 'tui',