@cortex-agent/server 2026.9.15 → 2026.9.25

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 (297) hide show
  1. package/README.md +3 -2
  2. package/defaults/config/hooks/08-agents-md-injector-post-tool.json +10 -0
  3. package/defaults/config/hooks/{10-cortex-md-injector-session-start.json → 10-agents-md-injector-session-start.json} +3 -3
  4. package/defaults/config/hooks/{CORTEX.md → AGENTS.md} +2 -2
  5. package/defaults/config/thread-templates/agents/creative.json +17 -0
  6. package/defaults/hooks/{CORTEX.md → AGENTS.md} +1 -1
  7. package/defaults/hooks/{cortex-md-injector.mjs → agents-md-injector.mjs} +117 -26
  8. package/defaults/hooks/cortex-hook-api.mjs +2 -2
  9. package/defaults/hooks/new-session-hook.mjs +2 -2
  10. package/defaults/hooks/rules-loader.mjs +2 -2
  11. package/defaults/hooks/status-md-guard.mjs +8 -8
  12. package/defaults/hooks/task-status-check.mjs +18 -76
  13. package/defaults/hooks/tasks-yaml-guard.mjs +2 -2
  14. package/defaults/plugins/cortex-feishu/skills/feishu-doc/SKILL.md +1 -1
  15. package/defaults/plugins/cortex-system/skills/client-manage/SKILL.md +2 -2
  16. package/defaults/plugins/cortex-system/skills/project-init/SKILL.md +4 -4
  17. package/defaults/plugins/cortex-system/skills/task/SKILL.md +1 -1
  18. package/defaults/prompts/systemPrompts/creative.md +13 -0
  19. package/defaults/prompts/systemPrompts/direct.md +1 -1
  20. package/defaults/rules/{cortex-md.md → agents-md.md} +4 -4
  21. package/defaults/rules/decision-records.md +1 -1
  22. package/defaults/rules/meta-conventions.md +4 -4
  23. package/defaults/rules/mission-md.md +1 -1
  24. package/dist/agent-adapter/claude/adapter.d.ts +12 -0
  25. package/dist/agent-adapter/claude/adapter.js +19 -1
  26. package/dist/agent-adapter/claude/hooks-builder.js +2 -2
  27. package/dist/agent-adapter/claude/spawn-args.d.ts +7 -0
  28. package/dist/agent-adapter/claude/spawn-args.js +14 -0
  29. package/dist/agent-adapter/claude/turn-machine.d.ts +11 -0
  30. package/dist/agent-adapter/claude/turn-machine.js +46 -5
  31. package/dist/agent-adapter/normalize/prompt-builder.d.ts +16 -1
  32. package/dist/agent-adapter/normalize/prompt-builder.js +24 -6
  33. package/dist/agent-adapter/pi/child-runner.d.ts +4 -2
  34. package/dist/agent-adapter/pi/child-runner.js +5 -1
  35. package/dist/agent-adapter/pi/event-parser.d.ts +3 -2
  36. package/dist/agent-adapter/pi/event-parser.js +46 -2
  37. package/dist/agent-adapter/pi/extensions.d.ts +7 -1
  38. package/dist/agent-adapter/pi/extensions.js +10 -3
  39. package/dist/agent-adapter/pi/mcp-bridge.js +8 -8
  40. package/dist/agent-adapter/pi/pi-session.js +5 -0
  41. package/dist/agent-adapter/pi/runtime.js +3 -0
  42. package/dist/agent-adapter/pi/session-options.js +5 -1
  43. package/dist/agent-adapter/pi/subagent.d.ts +15 -3
  44. package/dist/agent-adapter/pi/subagent.js +18 -0
  45. package/dist/agent-adapter/pi/tool-shims.d.ts +6 -1
  46. package/dist/agent-adapter/pi/tool-shims.js +34 -1
  47. package/dist/agent-adapter/types.d.ts +6 -0
  48. package/dist/core/agents/subagent/types.d.ts +3 -0
  49. package/dist/core/config-generator.js +17 -2
  50. package/dist/core/debug-mode.d.ts +11 -10
  51. package/dist/core/debug-mode.js +12 -18
  52. package/dist/core/exec-async.d.ts +26 -0
  53. package/dist/core/exec-async.js +47 -0
  54. package/dist/core/locales/en.d.ts +14 -1
  55. package/dist/core/locales/slices/commands.d.ts +12 -1
  56. package/dist/core/locales/slices/commands.js +24 -2
  57. package/dist/core/locales/slices/startup.d.ts +2 -0
  58. package/dist/core/locales/slices/startup.js +4 -0
  59. package/dist/core/mcp-tool-gate.js +1 -0
  60. package/dist/core/media-types.d.ts +10 -0
  61. package/dist/core/media-types.js +34 -0
  62. package/dist/core/platform-settings-spec.js +1 -1
  63. package/dist/core/rebuild-progress.d.ts +58 -0
  64. package/dist/core/rebuild-progress.js +103 -0
  65. package/dist/core/resilient-watch.js +5 -3
  66. package/dist/core/run-registry.d.ts +7 -0
  67. package/dist/core/run-registry.js +6 -0
  68. package/dist/core/settings-spec.d.ts +21 -0
  69. package/dist/core/settings-spec.js +28 -1
  70. package/dist/core/types/agent-types.d.ts +3 -1
  71. package/dist/core/types/thread-types.d.ts +23 -4
  72. package/dist/core/utils.d.ts +1 -1
  73. package/dist/core/utils.js +1 -1
  74. package/dist/domain/agents/agent-state.d.ts +7 -0
  75. package/dist/domain/agents/agent-state.js +9 -1
  76. package/dist/domain/agents/agent-switch.d.ts +38 -0
  77. package/dist/domain/agents/agent-switch.js +106 -0
  78. package/dist/domain/agents/config.d.ts +20 -2
  79. package/dist/domain/agents/config.js +58 -4
  80. package/dist/domain/agents/index.d.ts +1 -0
  81. package/dist/domain/agents/index.js +1 -0
  82. package/dist/domain/agents/profile-manager.d.ts +6 -0
  83. package/dist/domain/agents/profile-manager.js +14 -1
  84. package/dist/domain/executions/registry.d.ts +3 -2
  85. package/dist/domain/executions/registry.js +84 -10
  86. package/dist/domain/mcp/bundled-server.js +4 -3
  87. package/dist/domain/mcp/feishu/file.js +37 -18
  88. package/dist/domain/mcp/feishu/types.d.ts +3 -0
  89. package/dist/domain/mcp/feishu-server.js +1 -1
  90. package/dist/domain/mcp/tools/{cortex-md.d.ts → agents-md.d.ts} +6 -6
  91. package/dist/domain/mcp/tools/{cortex-md.js → agents-md.js} +6 -6
  92. package/dist/domain/mcp/tools/remote-file.d.ts +20 -0
  93. package/dist/domain/mcp/tools/remote-file.js +44 -0
  94. package/dist/domain/mcp/tools/slack.d.ts +2 -0
  95. package/dist/domain/mcp/tools/slack.js +22 -7
  96. package/dist/domain/mcp/tools/task-ops.js +5 -13
  97. package/dist/domain/mcp/tools/ui-file.js +23 -10
  98. package/dist/domain/mcp/tools/waitpoint.d.ts +3 -0
  99. package/dist/domain/mcp/tools/waitpoint.js +122 -0
  100. package/dist/domain/memory/agents-md-injector.d.ts +24 -0
  101. package/dist/domain/memory/{cortex-md-injector.js → agents-md-injector.js} +10 -7
  102. package/dist/domain/plugins/runtime.js +1 -1
  103. package/dist/domain/plugins/skill-projection.d.ts +8 -2
  104. package/dist/domain/plugins/skill-projection.js +76 -19
  105. package/dist/domain/projects/project-store.d.ts +1 -1
  106. package/dist/domain/projects/project-store.js +3 -3
  107. package/dist/domain/remote/client-bootstrap.js +1 -1
  108. package/dist/domain/remote/client-hot-reload.d.ts +1 -1
  109. package/dist/domain/remote/client-hot-reload.js +30 -24
  110. package/dist/domain/remote/client-manager.js +39 -119
  111. package/dist/domain/remote/cortex-client-config.d.ts +1 -1
  112. package/dist/domain/remote/cortex-client-config.js +1 -1
  113. package/dist/domain/remote/device-file.d.ts +51 -0
  114. package/dist/domain/remote/device-file.js +193 -0
  115. package/dist/domain/remote/device-port.js +3 -0
  116. package/dist/domain/remote/reverse-stream.d.ts +18 -7
  117. package/dist/domain/remote/reverse-stream.js +19 -6
  118. package/dist/domain/runs/engine-spec.js +4 -0
  119. package/dist/domain/runs/request.d.ts +6 -0
  120. package/dist/domain/runs/run.js +1 -0
  121. package/dist/domain/runs/spec-loader.d.ts +4 -3
  122. package/dist/domain/runs/spec-loader.js +4 -3
  123. package/dist/domain/scheduling/jobs/sync-public.js +6 -6
  124. package/dist/domain/scheduling/scheduler.js +14 -12
  125. package/dist/domain/sessions/session-lifecycle.d.ts +5 -0
  126. package/dist/domain/sessions/session-lifecycle.js +13 -1
  127. package/dist/domain/system/rebuild-hold.d.ts +44 -0
  128. package/dist/domain/system/rebuild-hold.js +91 -0
  129. package/dist/domain/system/server-update-check.d.ts +2 -1
  130. package/dist/domain/system/server-update-check.js +15 -13
  131. package/dist/domain/tasks/archiver.js +21 -13
  132. package/dist/domain/tasks/claim-recovery.js +2 -2
  133. package/dist/domain/tasks/dispatch-utils.d.ts +10 -1
  134. package/dist/domain/tasks/dispatch-utils.js +46 -1
  135. package/dist/domain/tasks/dispatcher.js +4 -5
  136. package/dist/domain/tasks/mutator.d.ts +2 -2
  137. package/dist/domain/tasks/mutator.js +62 -61
  138. package/dist/domain/tasks/system/task-cli.js +2 -2
  139. package/dist/domain/tasks/system/task-completion.d.ts +7 -2
  140. package/dist/domain/tasks/system/task-completion.js +69 -6
  141. package/dist/domain/tasks/system/task-lifecycle-edit.d.ts +6 -1
  142. package/dist/domain/tasks/system/task-lifecycle-edit.js +21 -2
  143. package/dist/domain/tasks/system/task-lock.d.ts +23 -0
  144. package/dist/domain/tasks/system/task-lock.js +29 -1
  145. package/dist/domain/tasks/system/task-mutations.d.ts +14 -1
  146. package/dist/domain/tasks/system/task-mutations.js +25 -2
  147. package/dist/domain/tasks/system/task-state.d.ts +12 -1
  148. package/dist/domain/tasks/system/task-state.js +20 -3
  149. package/dist/domain/threads/prompt-builder.d.ts +9 -6
  150. package/dist/domain/threads/prompt-builder.js +28 -10
  151. package/dist/domain/threads/runner.js +10 -4
  152. package/dist/domain/threads/state-machine.js +15 -11
  153. package/dist/domain/threads/template-loader.js +6 -4
  154. package/dist/domain/threads/template-validate.d.ts +43 -6
  155. package/dist/domain/threads/template-validate.js +12 -0
  156. package/dist/domain/ui-service/app-router.d.ts +34 -3
  157. package/dist/domain/ui-service/app-router.js +9 -14
  158. package/dist/domain/ui-service/input-schemas.d.ts +28 -5
  159. package/dist/domain/ui-service/input-schemas.js +24 -9
  160. package/dist/domain/ui-service/mutate/platform-settings.js +1 -1
  161. package/dist/domain/ui-service/mutate/sessions.d.ts +6 -1
  162. package/dist/domain/ui-service/mutate/sessions.js +54 -0
  163. package/dist/domain/ui-service/mutate/tasks.js +4 -3
  164. package/dist/domain/ui-service/mutate/waitpoints.d.ts +2 -0
  165. package/dist/domain/ui-service/mutate/waitpoints.js +20 -0
  166. package/dist/domain/ui-service/platform-settings.js +1 -1
  167. package/dist/domain/ui-service/plugins-shared.js +1 -1
  168. package/dist/domain/ui-service/query/config.js +20 -2
  169. package/dist/domain/ui-service/query/executions.js +0 -2
  170. package/dist/domain/ui-service/query/machine-detail.js +3 -8
  171. package/dist/domain/ui-service/query/memory.js +29 -35
  172. package/dist/domain/ui-service/query/sessions.js +96 -12
  173. package/dist/domain/ui-service/query/system.js +19 -0
  174. package/dist/domain/ui-service/query/threads.js +1 -54
  175. package/dist/domain/ui-service/query/waitpoints.d.ts +30 -0
  176. package/dist/domain/ui-service/query/waitpoints.js +117 -0
  177. package/dist/domain/ui-service/query-input-schemas.d.ts +4 -0
  178. package/dist/domain/ui-service/query-input-schemas.js +5 -0
  179. package/dist/domain/ui-service/trpc.js +1 -1
  180. package/dist/domain/ui-service/types.d.ts +229 -51
  181. package/dist/domain/ui-service/types.js +1 -1
  182. package/dist/domain/ui-service/ui-service.js +8 -31
  183. package/dist/domain/waitpoints/notices.d.ts +21 -0
  184. package/dist/domain/waitpoints/notices.js +115 -0
  185. package/dist/domain/waitpoints/service.d.ts +91 -0
  186. package/dist/domain/waitpoints/service.js +243 -0
  187. package/dist/entry/app.js +52 -11
  188. package/dist/entry/auth-login-cli.js +1 -1
  189. package/dist/entry/auth-login-terminal.js +1 -1
  190. package/dist/entry/daemon-notice.d.ts +10 -1
  191. package/dist/entry/daemon-notice.js +16 -1
  192. package/dist/entry/daemon.d.ts +43 -2
  193. package/dist/entry/daemon.js +163 -9
  194. package/dist/entry/init-auth.js +1 -1
  195. package/dist/entry/init.js +6 -6
  196. package/dist/entry/signal-cli.d.ts +30 -0
  197. package/dist/entry/signal-cli.js +207 -0
  198. package/dist/entry/start-ui-http.d.ts +1 -1
  199. package/dist/entry/start-ui-http.js +2 -2
  200. package/dist/events/event-types.d.ts +0 -7
  201. package/dist/hooks/{cortex-md-injector.mjs → agents-md-injector.mjs} +117 -26
  202. package/dist/hooks/cortex-hook-api.mjs +2 -2
  203. package/dist/hooks/new-session-hook.mjs +2 -2
  204. package/dist/hooks/rules-loader.mjs +2 -2
  205. package/dist/hooks/status-md-guard.mjs +8 -8
  206. package/dist/hooks/task-status-check.mjs +18 -76
  207. package/dist/hooks/tasks-yaml-guard.mjs +2 -2
  208. package/dist/orchestration/agent-file-send.d.ts +9 -0
  209. package/dist/orchestration/agent-file-send.js +21 -2
  210. package/dist/orchestration/agent-runner.d.ts +3 -2
  211. package/dist/orchestration/agent-runner.js +33 -12
  212. package/dist/orchestration/attachments-store.d.ts +31 -0
  213. package/dist/orchestration/attachments-store.js +184 -0
  214. package/dist/orchestration/conversation-request.d.ts +37 -0
  215. package/dist/orchestration/conversation-request.js +91 -22
  216. package/dist/orchestration/interactions/plan-approvals.js +1 -1
  217. package/dist/orchestration/mid-turn-inject.d.ts +3 -0
  218. package/dist/orchestration/mid-turn-inject.js +9 -4
  219. package/dist/orchestration/outputs-store.d.ts +11 -0
  220. package/dist/orchestration/outputs-store.js +32 -6
  221. package/dist/orchestration/resume-dispatcher.js +4 -2
  222. package/dist/orchestration/routing/commands/mode.js +114 -63
  223. package/dist/orchestration/routing/file-handler.d.ts +23 -2
  224. package/dist/orchestration/routing/file-handler.js +22 -5
  225. package/dist/orchestration/routing/webhook.js +193 -39
  226. package/dist/orchestration/session-gateway.d.ts +1 -1
  227. package/dist/orchestration/session-gateway.js +1 -0
  228. package/dist/orchestration/thread-executor.d.ts +2 -0
  229. package/dist/orchestration/thread-executor.js +24 -1
  230. package/dist/orchestration/thread-input.d.ts +3 -2
  231. package/dist/orchestration/thread-input.js +8 -9
  232. package/dist/orchestration/turn/turn-prep.d.ts +15 -1
  233. package/dist/orchestration/turn/turn-prep.js +19 -8
  234. package/dist/orchestration/turn/turn.js +1 -0
  235. package/dist/orchestration/waitpoint-ingress.d.ts +41 -0
  236. package/dist/orchestration/waitpoint-ingress.js +172 -0
  237. package/dist/orchestration/waitpoint-notifier.d.ts +21 -0
  238. package/dist/orchestration/waitpoint-notifier.js +119 -0
  239. package/dist/orchestration/waitpoint-remote-drain.d.ts +20 -0
  240. package/dist/orchestration/waitpoint-remote-drain.js +147 -0
  241. package/dist/orchestration/waitpoint-sweep.d.ts +42 -0
  242. package/dist/orchestration/waitpoint-sweep.js +87 -0
  243. package/dist/platform/adapters/feishu-image.d.ts +19 -0
  244. package/dist/platform/adapters/feishu-image.js +71 -0
  245. package/dist/platform/adapters/feishu.d.ts +2 -0
  246. package/dist/platform/adapters/feishu.js +26 -16
  247. package/dist/platform/ui-http/listening-ports.d.ts +1 -1
  248. package/dist/platform/ui-http/listening-ports.js +1 -1
  249. package/dist/platform/ui-http/ui-session.js +1 -1
  250. package/dist/store/conversation-display-projection.d.ts +9 -1
  251. package/dist/store/conversation-display-projection.js +13 -6
  252. package/dist/store/conversation-history-reader.d.ts +19 -0
  253. package/dist/store/conversation-history-reader.js +163 -44
  254. package/dist/store/conversation-history-repo.d.ts +37 -10
  255. package/dist/store/conversation-history-repo.js +161 -139
  256. package/dist/store/conversation-ledger-repo.js +1 -1
  257. package/dist/store/execution-repo.d.ts +1 -19
  258. package/dist/store/execution-repo.js +1 -18
  259. package/dist/store/project-notes-repo.js +11 -2
  260. package/dist/store/prompt-migration-replacements.js +1 -1
  261. package/dist/store/session-registry-import.js +1 -1
  262. package/dist/store/session-registry-journal.d.ts +4 -0
  263. package/dist/store/session-registry-journal.js +5 -1
  264. package/dist/store/session-registry-repo.d.ts +2 -1
  265. package/dist/store/session-registry-repo.js +3 -1
  266. package/dist/store/task-repo.d.ts +6 -3
  267. package/dist/store/task-repo.js +26 -10
  268. package/dist/store/version-migrations.d.ts +13 -3
  269. package/dist/store/version-migrations.js +254 -24
  270. package/dist/store/waitpoint-repo.d.ts +108 -0
  271. package/dist/store/waitpoint-repo.js +94 -0
  272. package/package.json +3 -2
  273. package/web/dist/AGENTS.md +10 -0
  274. package/web/dist/assets/index-B1dBi8Za.css +1 -0
  275. package/web/dist/assets/{index-CEZ0DSei.js → index-BAeLybF0.js} +1 -1
  276. package/web/dist/assets/index-BcQI8Fh5.js +445 -0
  277. package/web/dist/index.html +12 -4
  278. package/web/dist/theme.css +211 -40
  279. package/defaults/config/hooks/08-cortex-md-injector-post-tool.json +0 -10
  280. package/dist/domain/executions/log-tailer.d.ts +0 -71
  281. package/dist/domain/executions/log-tailer.js +0 -194
  282. package/dist/domain/memory/cortex-md-injector.d.ts +0 -24
  283. package/dist/domain/memory/cortex-md-scanner.d.ts +0 -10
  284. package/dist/domain/memory/cortex-md-scanner.js +0 -66
  285. package/dist/domain/remote/cortex-client.d.ts +0 -1
  286. package/dist/domain/remote/cortex-client.js +0 -662
  287. package/dist/domain/tasks/system/cortex-run.d.ts +0 -25
  288. package/dist/domain/tasks/system/cortex-run.js +0 -360
  289. package/web/dist/assets/index-CRDJo39X.css +0 -1
  290. package/web/dist/assets/index-DjuPJVZE.js +0 -444
  291. /package/defaults/{CORTEX.md → AGENTS.md} +0 -0
  292. /package/defaults/config/{CORTEX.md → AGENTS.md} +0 -0
  293. /package/defaults/context/{CORTEX.md → AGENTS.md} +0 -0
  294. /package/defaults/context/ideas/{CORTEX.md → AGENTS.md} +0 -0
  295. /package/defaults/context/projects/{CORTEX.md → AGENTS.md} +0 -0
  296. /package/defaults/context/scans/{CORTEX.md → AGENTS.md} +0 -0
  297. /package/defaults/context/user/{CORTEX.md → AGENTS.md} +0 -0
@@ -1,24 +1,25 @@
1
1
  import { taskStore } from '../../store/task-repo.js';
2
2
  import { emitCortexEvent } from '../../core/hook-bus.js';
3
- import { approveTask as lifecycleApproveTask, blockTask as lifecycleBlockTask, claimTask as lifecycleClaimTask, clearApprovalTask as lifecycleClearApprovalTask, pauseTask as lifecyclePauseTask, requestApprovalTask as lifecycleRequestApprovalTask, resumeTask as lifecycleResumeTask, unblockTask as lifecycleUnblockTask, unclaimTask as lifecycleUnclaimTask, } from './system/task-state.js';
4
- import { completeTask as lifecycleCompleteTask, uncompleteTask as lifecycleUncompleteTask, } from './system/task-completion.js';
5
- import { addTask as lifecycleAddTask, batchEdit as lifecycleBatchEdit, decomposeTask as lifecycleDecomposeTask, } from './system/task-mutations.js';
6
- import { editTask as lifecycleEditTask } from './system/task-lifecycle-edit.js';
7
- import { acquireLock, assertLockHeld, getOwnerIdentity, isProjectLocked, releaseLock, } from './system/task-lock.js';
3
+ import { approveTaskAsync as lifecycleApproveTask, blockTaskAsync as lifecycleBlockTask, claimTaskAsync as lifecycleClaimTask, clearApprovalTaskAsync as lifecycleClearApprovalTask, pauseTaskAsync as lifecyclePauseTask, requestApprovalTaskAsync as lifecycleRequestApprovalTask, resumeTaskAsync as lifecycleResumeTask, unblockTaskAsync as lifecycleUnblockTask, unclaimTaskAsync as lifecycleUnclaimTask, } from './system/task-state.js';
4
+ import { completeTaskAsync as lifecycleCompleteTask, uncompleteTaskAsync as lifecycleUncompleteTask, } from './system/task-completion.js';
5
+ import { addTaskAsync as lifecycleAddTask, batchEditAsync as lifecycleBatchEdit, decomposeTaskAsync as lifecycleDecomposeTask, } from './system/task-mutations.js';
6
+ import { editTaskAsync as lifecycleEditTask } from './system/task-lifecycle-edit.js';
7
+ import { acquireLockAsync, assertLockHeld, getOwnerIdentity, isProjectLocked, releaseLockAsync, } from './system/task-lock.js';
8
8
  const SYSTEM_LOCK_RETRY_MS = 50;
9
9
  let systemLockSequence = 0;
10
- function addTaskRecord(request) {
11
- return lifecycleAddTask(request.project, request.text, request.why, request.doneWhen, request.priority, request.template, request.dependsOn, request.plan);
10
+ async function addTaskRecord(request) {
11
+ return await lifecycleAddTask(request.project, request.text, request.why, request.doneWhen, request.priority, request.template, request.dependsOn, request.plan);
12
12
  }
13
13
  async function acquireSystemProjectLock(project) {
14
14
  const owner = `system:${process.pid}:${++systemLockSequence}`;
15
- while (!acquireLock(project, { owner }).acquired) {
15
+ // Async lock: a contended cross-process mutation lock must not park the event loop here.
16
+ while (!(await acquireLockAsync(project, { owner })).acquired) {
16
17
  await new Promise((resolve) => setTimeout(resolve, SYSTEM_LOCK_RETRY_MS));
17
18
  }
18
19
  return owner;
19
20
  }
20
- function releaseSystemProjectLock(project, owner) {
21
- const result = releaseLock(project, owner);
21
+ async function releaseSystemProjectLock(project, owner) {
22
+ const result = await releaseLockAsync(project, owner);
22
23
  if (!result.released)
23
24
  throw new Error(result.message || `Failed to release project lock for ${project}`);
24
25
  }
@@ -39,8 +40,8 @@ export class TaskMutator {
39
40
  this.bus = bus;
40
41
  }
41
42
  /** getById with a one-shot refresh on miss: tasks created out-of-process (CLI, manager
42
- * threads) reach the in-memory cache only on refresh — callers like the cortex-run
43
- * callback may fire before any dispatch cycle has reloaded TASKS.yaml. */
43
+ * threads) reach the in-memory cache only on refresh — a caller may fire before any
44
+ * dispatch cycle has reloaded TASKS.yaml. */
44
45
  getByIdFresh(taskId) {
45
46
  let task = this.store.getById(taskId);
46
47
  if (!task) {
@@ -50,42 +51,42 @@ export class TaskMutator {
50
51
  return task;
51
52
  }
52
53
  async claim(taskId, agent, options = {}) {
53
- return this.store.runExclusive(() => {
54
+ return this.store.runExclusive(async () => {
54
55
  const task = this.store.getById(taskId);
55
56
  if (!task)
56
57
  return { success: false, message: `Task not found: ${taskId}` };
57
- const result = lifecycleClaimTask(task.text, task.project, agent, taskId, options.generation ?? null);
58
+ const result = await lifecycleClaimTask(task.text, task.project, agent, taskId, options.generation ?? null);
58
59
  if (result.success) {
59
60
  this.store.refresh();
60
- this.store.commitAndPush(`task-store: claim ${taskId} by ${agent}`);
61
+ await this.store.commitAndPush(`task-store: claim ${taskId} by ${agent}`);
61
62
  this.bus?.publish({ type: 'task.claimed', taskId, by: agent });
62
63
  }
63
64
  return result;
64
65
  });
65
66
  }
66
67
  async unclaim(taskId, options = {}) {
67
- return this.store.runExclusive(() => {
68
+ return this.store.runExclusive(async () => {
68
69
  const task = this.store.getById(taskId);
69
70
  if (!task)
70
71
  return { success: false, message: `Task not found: ${taskId}` };
71
- const result = lifecycleUnclaimTask(task.text, task.project, taskId, options.ownership);
72
+ const result = await lifecycleUnclaimTask(task.text, task.project, taskId, options.ownership);
72
73
  if (result.success) {
73
74
  this.store.refresh();
74
- this.store.commitAndPush(`task-store: unclaim ${taskId}`);
75
+ await this.store.commitAndPush(`task-store: unclaim ${taskId}`);
75
76
  this.bus?.publish({ type: 'task.unclaimed', taskId });
76
77
  }
77
78
  return result;
78
79
  });
79
80
  }
80
81
  async complete(taskId, note, options = {}) {
81
- return this.store.runExclusive(() => {
82
+ return this.store.runExclusive(async () => {
82
83
  const task = this.getByIdFresh(taskId);
83
84
  if (!task)
84
85
  return { success: false, message: `Task not found: ${taskId}` };
85
- const result = lifecycleCompleteTask(task.text, task.project, note || '', taskId, options.skipVerify ?? false, options.skipVerifyReason ?? null, options.ownership);
86
+ const result = await lifecycleCompleteTask(task.text, task.project, note || '', taskId, options.skipVerify ?? false, options.skipVerifyReason ?? null, options.ownership);
86
87
  if (result.success) {
87
88
  this.store.refresh();
88
- this.store.commitAndPush(`task-store: complete ${taskId}`);
89
+ await this.store.commitAndPush(`task-store: complete ${taskId}`);
89
90
  this.bus?.publish({
90
91
  type: 'task.completed', taskId,
91
92
  ...(options.ownership ? { dispatchGeneration: options.ownership.generation } : {}),
@@ -96,27 +97,27 @@ export class TaskMutator {
96
97
  });
97
98
  }
98
99
  async uncomplete(taskId) {
99
- return this.store.runExclusive(() => {
100
+ return this.store.runExclusive(async () => {
100
101
  const task = this.store.getById(taskId);
101
102
  if (!task)
102
103
  return { success: false, message: `Task not found: ${taskId}` };
103
- const result = lifecycleUncompleteTask(task.text, task.project, taskId);
104
+ const result = await lifecycleUncompleteTask(task.text, task.project, taskId);
104
105
  if (result.success) {
105
106
  this.store.refresh();
106
- this.store.commitAndPush(`task-store: uncomplete ${taskId}`);
107
+ await this.store.commitAndPush(`task-store: uncomplete ${taskId}`);
107
108
  }
108
109
  return result;
109
110
  });
110
111
  }
111
112
  async block(taskId, reason, options = {}) {
112
- return this.store.runExclusive(() => {
113
+ return this.store.runExclusive(async () => {
113
114
  const task = this.getByIdFresh(taskId);
114
115
  if (!task)
115
116
  return { success: false, message: `Task not found: ${taskId}` };
116
- const result = lifecycleBlockTask(task.text, task.project, reason, taskId, options.ownership);
117
+ const result = await lifecycleBlockTask(task.text, task.project, reason, taskId, options.ownership);
117
118
  if (result.success) {
118
119
  this.store.refresh();
119
- this.store.commitAndPush(`task-store: block ${taskId}`);
120
+ await this.store.commitAndPush(`task-store: block ${taskId}`);
120
121
  // DR-0014 §8: a blocked task is a child's escalation — wake its waiting manager.
121
122
  this.bus?.publish({
122
123
  type: 'task.blocked', taskId, reason,
@@ -128,93 +129,93 @@ export class TaskMutator {
128
129
  });
129
130
  }
130
131
  async unblock(taskId) {
131
- return this.store.runExclusive(() => {
132
+ return this.store.runExclusive(async () => {
132
133
  const task = this.store.getById(taskId);
133
134
  if (!task)
134
135
  return { success: false, message: `Task not found: ${taskId}` };
135
- const result = lifecycleUnblockTask(task.text, task.project, taskId);
136
+ const result = await lifecycleUnblockTask(task.text, task.project, taskId);
136
137
  if (result.success) {
137
138
  this.store.refresh();
138
- this.store.commitAndPush(`task-store: unblock ${taskId}`);
139
+ await this.store.commitAndPush(`task-store: unblock ${taskId}`);
139
140
  this.bus?.publish({ type: 'task.unblocked', taskId });
140
141
  }
141
142
  return result;
142
143
  });
143
144
  }
144
145
  async pause(taskId) {
145
- return this.store.runExclusive(() => {
146
+ return this.store.runExclusive(async () => {
146
147
  const task = this.store.getById(taskId);
147
148
  if (!task)
148
149
  return { success: false, message: `Task not found: ${taskId}` };
149
- const result = lifecyclePauseTask(task.text, task.project, taskId);
150
+ const result = await lifecyclePauseTask(task.text, task.project, taskId);
150
151
  if (result.success) {
151
152
  this.store.refresh();
152
- this.store.commitAndPush(`task-store: pause ${taskId}`);
153
+ await this.store.commitAndPush(`task-store: pause ${taskId}`);
153
154
  }
154
155
  return result;
155
156
  });
156
157
  }
157
158
  async resume(taskId) {
158
- return this.store.runExclusive(() => {
159
+ return this.store.runExclusive(async () => {
159
160
  const task = this.store.getById(taskId);
160
161
  if (!task)
161
162
  return { success: false, message: `Task not found: ${taskId}` };
162
- const result = lifecycleResumeTask(task.text, task.project, taskId);
163
+ const result = await lifecycleResumeTask(task.text, task.project, taskId);
163
164
  if (result.success) {
164
165
  this.store.refresh();
165
- this.store.commitAndPush(`task-store: resume ${taskId}`);
166
+ await this.store.commitAndPush(`task-store: resume ${taskId}`);
166
167
  }
167
168
  return result;
168
169
  });
169
170
  }
170
171
  async requestApproval(taskId) {
171
- return this.store.runExclusive(() => {
172
+ return this.store.runExclusive(async () => {
172
173
  const task = this.store.getById(taskId);
173
174
  if (!task)
174
175
  return { success: false, message: `Task not found: ${taskId}` };
175
- const result = lifecycleRequestApprovalTask(task.text, task.project, taskId);
176
+ const result = await lifecycleRequestApprovalTask(task.text, task.project, taskId);
176
177
  if (result.success) {
177
178
  this.store.refresh();
178
- this.store.commitAndPush(`task-store: requestApproval ${taskId}`);
179
+ await this.store.commitAndPush(`task-store: requestApproval ${taskId}`);
179
180
  }
180
181
  return result;
181
182
  });
182
183
  }
183
184
  async approve(taskId) {
184
- return this.store.runExclusive(() => {
185
+ return this.store.runExclusive(async () => {
185
186
  const task = this.store.getById(taskId);
186
187
  if (!task)
187
188
  return { success: false, message: `Task not found: ${taskId}` };
188
- const result = lifecycleApproveTask(task.text, task.project, taskId);
189
+ const result = await lifecycleApproveTask(task.text, task.project, taskId);
189
190
  if (result.success) {
190
191
  this.store.refresh();
191
- this.store.commitAndPush(`task-store: approve ${taskId}`);
192
+ await this.store.commitAndPush(`task-store: approve ${taskId}`);
192
193
  }
193
194
  return result;
194
195
  });
195
196
  }
196
197
  async clearApproval(taskId) {
197
- return this.store.runExclusive(() => {
198
+ return this.store.runExclusive(async () => {
198
199
  const task = this.store.getById(taskId);
199
200
  if (!task)
200
201
  return { success: false, message: `Task not found: ${taskId}` };
201
- const result = lifecycleClearApprovalTask(task.text, task.project, taskId);
202
+ const result = await lifecycleClearApprovalTask(task.text, task.project, taskId);
202
203
  if (result.success) {
203
204
  this.store.refresh();
204
- this.store.commitAndPush(`task-store: clearApproval ${taskId}`);
205
+ await this.store.commitAndPush(`task-store: clearApproval ${taskId}`);
205
206
  }
206
207
  return result;
207
208
  });
208
209
  }
209
210
  async batchEdit(project, taskIds, options) {
210
- return this.store.runExclusive(() => {
211
+ return this.store.runExclusive(async () => {
211
212
  const lockError = assertLockHeld(project, getOwnerIdentity());
212
213
  if (lockError)
213
214
  return { success: false, message: lockError };
214
- const result = lifecycleBatchEdit(project, taskIds, options);
215
+ const result = await lifecycleBatchEdit(project, taskIds, options);
215
216
  if (result.success) {
216
217
  this.store.refresh();
217
- this.store.commitAndPush(`task-store: batch-edit ${taskIds.length} tasks in ${project}`);
218
+ await this.store.commitAndPush(`task-store: batch-edit ${taskIds.length} tasks in ${project}`);
218
219
  }
219
220
  return result;
220
221
  });
@@ -229,60 +230,60 @@ export class TaskMutator {
229
230
  };
230
231
  if (options.system)
231
232
  return this.addSystemTask(request);
232
- return this.store.runExclusive(() => {
233
+ return this.store.runExclusive(async () => {
233
234
  const lockError = assertLockHeld(project, getOwnerIdentity());
234
235
  if (lockError)
235
236
  return { success: false, message: lockError };
236
- const result = addTaskRecord(request);
237
+ const result = await addTaskRecord(request);
237
238
  if (result.success) {
238
239
  this.store.refresh();
239
- this.store.commitAndPush(`task-store: add task to ${project}`);
240
+ await this.store.commitAndPush(`task-store: add task to ${project}`);
240
241
  }
241
242
  return result;
242
243
  });
243
244
  }
244
245
  async addSystemTask(request) {
245
246
  const owner = await acquireSystemProjectLock(request.project);
246
- return this.store.runExclusive(() => {
247
+ return this.store.runExclusive(async () => {
247
248
  let result;
248
249
  try {
249
- result = addTaskRecord(request);
250
+ result = await addTaskRecord(request);
250
251
  }
251
252
  finally {
252
- releaseSystemProjectLock(request.project, owner);
253
+ await releaseSystemProjectLock(request.project, owner);
253
254
  }
254
255
  if (result.success) {
255
256
  this.store.refresh();
256
- this.store.commitAndPush(`task-store: add task to ${request.project}`);
257
+ await this.store.commitAndPush(`task-store: add task to ${request.project}`);
257
258
  }
258
259
  return result;
259
260
  });
260
261
  }
261
262
  async edit(project, options) {
262
- return this.store.runExclusive(() => {
263
+ return this.store.runExclusive(async () => {
263
264
  const lockError = assertLockHeld(project, getOwnerIdentity());
264
265
  if (lockError)
265
266
  return { success: false, message: lockError };
266
- const result = lifecycleEditTask(project, options);
267
+ const result = await lifecycleEditTask(project, options);
267
268
  if (result.success) {
268
269
  this.store.refresh();
269
- this.store.commitAndPush(`task-store: edit task in ${project}`);
270
+ await this.store.commitAndPush(`task-store: edit task in ${project}`);
270
271
  }
271
272
  return result;
272
273
  });
273
274
  }
274
275
  async decompose(project, taskText, subtasks, taskId, options = {}) {
275
- return this.store.runExclusive(() => {
276
+ return this.store.runExclusive(async () => {
276
277
  const lockError = decomposeLockError(project, options);
277
278
  if (lockError)
278
279
  return { success: false, message: lockError };
279
- const result = lifecycleDecomposeTask(project, taskText, subtasks, taskId || null, {
280
+ const result = await lifecycleDecomposeTask(project, taskText, subtasks, taskId || null, {
280
281
  keepParent: options.keepParent,
281
282
  ownership: options.ownership,
282
283
  });
283
284
  if (result.success) {
284
285
  this.store.refresh();
285
- this.store.commitAndPush(`task-store: decompose task in ${project}${options.keepParent ? ' (keep-parent)' : ''}`);
286
+ await this.store.commitAndPush(`task-store: decompose task in ${project}${options.keepParent ? ' (keep-parent)' : ''}`);
286
287
  }
287
288
  return result;
288
289
  });
@@ -108,8 +108,8 @@ const HELP_CONFIG = {
108
108
  { name: 'unclaim', description: 'Remove in-progress status' },
109
109
  { name: 'pause', description: 'Pause' },
110
110
  { name: 'resume', description: 'Resume a paused task' },
111
- { name: 'pending', description: 'Mark pending (waiting for cortex-run)' },
112
- { name: 'reopen', description: 'Restore a stuck pending task back to open (e.g. after a lost cortex-run callback)' },
111
+ { name: 'pending', description: 'Mark pending (waiting on work outside this turn)' },
112
+ { name: 'reopen', description: 'Restore a stuck pending task back to open (e.g. the awaited work never reported)' },
113
113
  { name: 'complete', description: 'Mark complete (--note)' },
114
114
  { name: 'uncomplete', description: 'Reverse a completed task' },
115
115
  ],
@@ -1,5 +1,5 @@
1
1
  import { type TaskGenerationExpectation } from '../../../core/task-parser.js';
2
- declare function completeTaskUnlocked(taskText: string | null, project: string, completionNote?: string, taskId?: string | null, skipVerify?: boolean, skipVerifyReason?: string | null, ownership?: TaskGenerationExpectation): {
2
+ declare function completeTaskUnlocked(taskText: string | null, project: string, completionNote?: string, taskId?: string | null, skipVerify?: boolean, skipVerifyReason?: string | null, ownership?: TaskGenerationExpectation, precomputedEvidence?: boolean | null): {
3
3
  success: boolean;
4
4
  message: string;
5
5
  stale?: undefined;
@@ -36,4 +36,9 @@ declare function uncompleteTaskUnlocked(taskText: string | null, project: string
36
36
  };
37
37
  declare const completeTask: typeof completeTaskUnlocked;
38
38
  declare const uncompleteTask: typeof uncompleteTaskUnlocked;
39
- export { completeTask, uncompleteTask };
39
+ /** Async twin of `completeTask` for the server's completion path: the evidence probes
40
+ * (`git cat-file` / `git log`) run through runFile instead of execFileSync, so completing a task
41
+ * no longer stalls every session in the process. The sync export stays for the CLI and tests. */
42
+ declare function completeTaskAsync(taskText: string | null, project: string, completionNote?: string, taskId?: string | null, skipVerify?: boolean, skipVerifyReason?: string | null, ownership?: TaskGenerationExpectation): Promise<ReturnType<typeof completeTaskUnlocked>>;
43
+ declare function uncompleteTaskAsync(taskText: string | null, project: string, taskId?: string | null, ownership?: TaskGenerationExpectation): Promise<ReturnType<typeof uncompleteTaskUnlocked>>;
44
+ export { completeTask, completeTaskAsync, uncompleteTask, uncompleteTaskAsync };
@@ -2,7 +2,8 @@ import * as fs from 'node:fs';
2
2
  import * as path from 'node:path';
3
3
  import { execFileSync } from 'node:child_process';
4
4
  import { DATA_DIR, INSTALL_ROOT, PROJECTS_DIR, STORE_DIR, WORKSPACE_DIR } from '../../../core/utils.js';
5
- import { clearDependsOnAll, findTask, getTasksPath, readTasks, taskFileProjects, withTaskFileMutationLock, withTaskFileMutationLocks, writeTasks, } from './task-lifecycle-edit.js';
5
+ import { runFile } from '../../../core/exec-async.js';
6
+ import { clearDependsOnAll, findTask, getTasksPath, readTasks, taskFileProjects, withTaskFileMutationLock, withTaskFileMutationLockAsync, withTaskFileMutationLocks, withTaskFileMutationLocksAsync, writeTasks, } from './task-lifecycle-edit.js';
6
7
  const EXPLICIT_SHA = /\b(?:implementation\s+sha|commit(?:\s+sha)?|sha)\s*[:=#]?\s*`?([0-9a-f]{7,40})(?![0-9a-f])`?/gi;
7
8
  function runGit(repo, args, input) {
8
9
  try {
@@ -14,6 +15,14 @@ function runGit(repo, args, input) {
14
15
  return null;
15
16
  }
16
17
  }
18
+ /** Async twin of `runGit`: same argv, same 5s timeout, no event-loop block. The server's
19
+ * completion path uses this; the CLI keeps the synchronous original. */
20
+ async function runGitAsync(repo, args, input) {
21
+ const result = await runFile('git', ['-C', repo, ...args], { timeoutMs: 5000, stdin: input });
22
+ if (!result.ok)
23
+ return null;
24
+ return result.stdout.trim();
25
+ }
17
26
  function extractExplicitShas(note) {
18
27
  const shas = [...note.matchAll(EXPLICIT_SHA)].map((match) => match[1].toLowerCase());
19
28
  return [...new Set(shas)];
@@ -133,13 +142,46 @@ function loadCompletionTask(taskText, project, taskId) {
133
142
  const found = findTask(tasks, taskText, taskId);
134
143
  return 'error' in found ? found : { tasks, task: found.task };
135
144
  }
136
- function completionWarning(project, task, completionNote, skipVerify, skipVerifyReason) {
145
+ function completionWarning(project, task, completionNote, skipVerify, skipVerifyReason, precomputedEvidence = null) {
137
146
  if (skipVerify)
138
147
  return `verify skipped: ${skipVerifyReason ?? 'no reason given'}`;
139
- if (verifyCompletionEvidence(project, task.id, task.done_when, completionNote))
148
+ const verified = precomputedEvidence ?? verifyCompletionEvidence(project, task.id, task.done_when, completionNote);
149
+ if (verified)
140
150
  return null;
141
151
  return 'no evidence of work: no verified implementation SHA, persisted thread artifact, matching git commit, or Done-when artifact. Re-run with --skip-verify to bypass.';
142
152
  }
153
+ /** Async twin of `verifyCompletionEvidence` for callers that must not block on git. Same order and
154
+ * same short-circuiting as the sync version, so both reach the same verdict. */
155
+ async function verifyCompletionEvidenceAsync(project, taskId, doneWhen, completionNote) {
156
+ if (await hasVerifiedImplementationShaAsync(completionNote, project))
157
+ return true;
158
+ if (hasCompletionArtifact(project, taskId))
159
+ return true;
160
+ if (await hasTaskCommitAsync(taskId))
161
+ return true;
162
+ return hasDoneWhenArtifact(doneWhen);
163
+ }
164
+ async function hasVerifiedImplementationShaAsync(note, project) {
165
+ const refs = extractExplicitShas(note).map((sha) => `${sha}^{commit}`);
166
+ if (refs.length === 0)
167
+ return false;
168
+ const repos = [...new Set([process.cwd(), INSTALL_ROOT, DATA_DIR, ...readConfiguredProjectRepos(project)])];
169
+ for (const repo of repos) {
170
+ const out = await runGitAsync(repo, ['cat-file', '--batch-check=%(objecttype)'], `${refs.join('\n')}\n`);
171
+ if (out !== null && out.split('\n').includes('commit'))
172
+ return true;
173
+ }
174
+ return false;
175
+ }
176
+ async function hasTaskCommitAsync(taskId) {
177
+ if (!taskId)
178
+ return false;
179
+ const out = await runGitAsync(DATA_DIR, ['log', '--oneline', `--grep=${taskId}`]);
180
+ if (out === null)
181
+ return false;
182
+ return out.split('\n').filter(Boolean)
183
+ .some((line) => !/task-store:\s+(claim|unclaim)/i.test(line));
184
+ }
143
185
  function markTaskCompleted(task, completionNote, completedAt, ownership) {
144
186
  task.status = 'done';
145
187
  task.claimed_by = null;
@@ -152,7 +194,7 @@ function markTaskCompleted(task, completionNote, completedAt, ownership) {
152
194
  task.completed_at = completedAt;
153
195
  task.completed_note = completionNote || null;
154
196
  }
155
- function completeTaskUnlocked(taskText, project, completionNote = '', taskId = null, skipVerify = false, skipVerifyReason = null, ownership) {
197
+ function completeTaskUnlocked(taskText, project, completionNote = '', taskId = null, skipVerify = false, skipVerifyReason = null, ownership, precomputedEvidence = null) {
156
198
  const loaded = loadCompletionTask(taskText, project, taskId);
157
199
  if ('error' in loaded)
158
200
  return { success: false, message: loaded.error };
@@ -163,7 +205,7 @@ function completeTaskUnlocked(taskText, project, completionNote = '', taskId = n
163
205
  const stateError = completionStateError(task);
164
206
  if (stateError)
165
207
  return { success: false, message: stateError };
166
- const verifyWarning = completionWarning(project, task, completionNote, skipVerify, skipVerifyReason);
208
+ const verifyWarning = completionWarning(project, task, completionNote, skipVerify, skipVerifyReason, precomputedEvidence);
167
209
  const completedAt = new Date().toISOString();
168
210
  const today = completedAt.slice(0, 10);
169
211
  markTaskCompleted(task, completionNote, completedAt, ownership);
@@ -202,4 +244,25 @@ function lockCompletionMutation(mutation) {
202
244
  }
203
245
  const completeTask = ((...args) => withTaskFileMutationLocks([...taskFileProjects(), args[1]], () => completeTaskUnlocked(...args)));
204
246
  const uncompleteTask = lockCompletionMutation(uncompleteTaskUnlocked);
205
- export { completeTask, uncompleteTask };
247
+ /** Async twin of `completeTask` for the server's completion path: the evidence probes
248
+ * (`git cat-file` / `git log`) run through runFile instead of execFileSync, so completing a task
249
+ * no longer stalls every session in the process. The sync export stays for the CLI and tests. */
250
+ async function completeTaskAsync(taskText, project, completionNote = '', taskId = null, skipVerify = false, skipVerifyReason = null, ownership) {
251
+ return withTaskFileMutationLocksAsync([...taskFileProjects(), project], async () => {
252
+ // Probe the (read-only) evidence while holding the mutation lock — same window as the sync
253
+ // path, which runs execFileSync there — but without parking the event loop. A failed pre-read
254
+ // passes null, and completeTaskUnlocked then returns its own load error before verifying.
255
+ let precomputedEvidence = null;
256
+ if (!skipVerify) {
257
+ const loaded = loadCompletionTask(taskText, project, taskId);
258
+ if (!('error' in loaded)) {
259
+ precomputedEvidence = await verifyCompletionEvidenceAsync(project, loaded.task.id, loaded.task.done_when, completionNote);
260
+ }
261
+ }
262
+ return completeTaskUnlocked(taskText, project, completionNote, taskId, skipVerify, skipVerifyReason, ownership, precomputedEvidence);
263
+ });
264
+ }
265
+ async function uncompleteTaskAsync(taskText, project, taskId = null, ownership) {
266
+ return withTaskFileMutationLockAsync(project, async () => uncompleteTaskUnlocked(taskText, project, taskId, ownership));
267
+ }
268
+ export { completeTask, completeTaskAsync, uncompleteTask, uncompleteTaskAsync };
@@ -3,6 +3,9 @@ declare function withTaskFileMutationLock<T>(project: string, mutate: () => T):
3
3
  declare function withTaskFileMutationLocks<T>(projects: string[], mutate: () => T): T;
4
4
  declare function taskFileProjects(): string[];
5
5
  declare function withTaskFileMutationLockAsync<T>(project: string, mutate: () => Promise<T>): Promise<T>;
6
+ /** Multi-project async twin of `withTaskFileMutationLocks`: acquires in sorted order and releases
7
+ * in reverse, so cross-project mutations cannot deadlock against each other. */
8
+ declare function withTaskFileMutationLocksAsync<T>(projects: string[], mutate: () => Promise<T>): Promise<T>;
6
9
  declare function sweepTaskOrphans(tasksPath: string): void;
7
10
  declare const VALID_PRIORITIES: Set<string>;
8
11
  declare function _resetTemplateNameCacheForTests(): void;
@@ -34,5 +37,7 @@ type TaskLineTransformResult = {
34
37
  message: string;
35
38
  };
36
39
  declare const editTask: (project: string, options?: any) => TaskLineTransformResult;
37
- export { VALID_PRIORITIES, _resetTemplateNameCacheForTests, clearDependsOnAll, editTask, findTask, findTaskById, getTasksPath, readTasks, sweepTaskOrphans, taskFileProjects, validateTemplateName, withTaskFileMutationLock, withTaskFileMutationLockAsync, withTaskFileMutationLocks, writeTasks, };
40
+ /** Async twin of `editTask` for the server's per-message edit path. */
41
+ declare const editTaskAsync: (project: string, options?: any) => Promise<TaskLineTransformResult>;
42
+ export { VALID_PRIORITIES, _resetTemplateNameCacheForTests, clearDependsOnAll, editTask, editTaskAsync, findTask, findTaskById, getTasksPath, readTasks, sweepTaskOrphans, taskFileProjects, validateTemplateName, withTaskFileMutationLock, withTaskFileMutationLockAsync, withTaskFileMutationLocks, withTaskFileMutationLocksAsync, writeTasks, };
38
43
  export type { TaskLineTransformResult };
@@ -209,6 +209,23 @@ async function withTaskFileMutationLockAsync(project, mutate) {
209
209
  release();
210
210
  }
211
211
  }
212
+ /** Multi-project async twin of `withTaskFileMutationLocks`: acquires in sorted order and releases
213
+ * in reverse, so cross-project mutations cannot deadlock against each other. */
214
+ async function withTaskFileMutationLocksAsync(projects, mutate) {
215
+ const existing = [...new Set(projects)]
216
+ .filter((project) => fs.existsSync(getTasksPath(project)))
217
+ .sort();
218
+ const releases = [];
219
+ try {
220
+ for (const project of existing)
221
+ releases.push(await acquireTaskFileMutationLockAsync(project));
222
+ return await mutate();
223
+ }
224
+ finally {
225
+ for (const release of releases.reverse())
226
+ release();
227
+ }
228
+ }
212
229
  function sweepTaskOrphans(tasksPath) {
213
230
  try {
214
231
  const dir = path.dirname(tasksPath);
@@ -251,7 +268,7 @@ function _resetTemplateNameCacheForTests() {
251
268
  }
252
269
  function validateTemplateName(name) {
253
270
  if (FORBIDDEN_TEMPLATES.has(name)) {
254
- return `Template '${name}' is forbidden. The 'default' and 'scheduler' templates are single-agent templates with no review pipeline and are not allowed for task dispatch. Use a multi-agent review template instead (e.g. stage-gate, coder-review, analyst-review).`;
271
+ return `Template '${name}' is forbidden. The 'default' and 'scheduler' templates are single-agent templates with no review pipeline and are not allowed for task dispatch. Use a multi-agent review template instead (e.g. stage-gate, coder-review, execute-review).`;
255
272
  }
256
273
  const valid = getValidTemplateNames();
257
274
  if (valid.size === 0)
@@ -400,7 +417,9 @@ function editTaskUnlocked(project, options = {}) {
400
417
  return { success: true, message: 'Task updated', task_id: taskId, updated_fields: updatedFields };
401
418
  }
402
419
  const editTask = (project, options = {}) => withTaskFileMutationLock(project, () => editTaskUnlocked(project, options));
420
+ /** Async twin of `editTask` for the server's per-message edit path. */
421
+ const editTaskAsync = async (project, options = {}) => withTaskFileMutationLockAsync(project, async () => editTaskUnlocked(project, options));
403
422
  // Base of the TASKS.yaml write path: this module owns the file I/O and the line-level primitives;
404
423
  // task-state / task-completion / task-mutations / task-process build on top of it. There is no
405
424
  // barrel for this folder on purpose — task-store.ts and the CLI import each sub-module directly.
406
- export { VALID_PRIORITIES, _resetTemplateNameCacheForTests, clearDependsOnAll, editTask, findTask, findTaskById, getTasksPath, readTasks, sweepTaskOrphans, taskFileProjects, validateTemplateName, withTaskFileMutationLock, withTaskFileMutationLockAsync, withTaskFileMutationLocks, writeTasks, };
425
+ export { VALID_PRIORITIES, _resetTemplateNameCacheForTests, clearDependsOnAll, editTask, editTaskAsync, findTask, findTaskById, getTasksPath, readTasks, sweepTaskOrphans, taskFileProjects, validateTemplateName, withTaskFileMutationLock, withTaskFileMutationLockAsync, withTaskFileMutationLocks, withTaskFileMutationLocksAsync, writeTasks, };
@@ -1,7 +1,11 @@
1
1
  import type { LockState } from '../../../core/task-parser.js';
2
2
  export declare function getOwnerIdentity(): string;
3
3
  export declare function readLock(project: string): LockState | null;
4
+ /** Async twin of `readLock` for callers that must not block the event loop. */
5
+ export declare function readLockAsync(project: string): Promise<LockState | null>;
4
6
  export declare function writeLock(project: string, lock: LockState | null): void;
7
+ /** Async twin of `writeLock`. */
8
+ export declare function writeLockAsync(project: string, lock: LockState | null): Promise<void>;
5
9
  export declare function acquireLock(project: string, opts: {
6
10
  owner: string;
7
11
  force?: boolean;
@@ -11,12 +15,31 @@ export declare function acquireLock(project: string, opts: {
11
15
  lock?: LockState;
12
16
  message?: string;
13
17
  };
18
+ /** Async twin of `acquireLock` — the server takes this path so retrying a contended project lock
19
+ * yields to the event loop instead of sleeping inside `Atomics.wait`. */
20
+ export declare function acquireLockAsync(project: string, opts: {
21
+ owner: string;
22
+ force?: boolean;
23
+ note?: string;
24
+ }): Promise<{
25
+ acquired: boolean;
26
+ lock?: LockState;
27
+ message?: string;
28
+ }>;
14
29
  export declare function releaseLock(project: string, owner: string, opts?: {
15
30
  force?: boolean;
16
31
  }): {
17
32
  released: boolean;
18
33
  message?: string;
19
34
  };
35
+ /** Async twin of `releaseLock` — the server takes this path so a contended cross-process
36
+ * mutation lock never parks the event loop in `Atomics.wait`. */
37
+ export declare function releaseLockAsync(project: string, owner: string, opts?: {
38
+ force?: boolean;
39
+ }): Promise<{
40
+ released: boolean;
41
+ message?: string;
42
+ }>;
20
43
  export declare function assertLockHeld(project: string, owner: string): string | null;
21
44
  export declare function isProjectLocked(project: string, now?: string): {
22
45
  locked: boolean;
@@ -1,10 +1,11 @@
1
1
  import * as fs from 'node:fs';
2
+ import * as fsp from 'node:fs/promises';
2
3
  import * as path from 'node:path';
3
4
  import * as os from 'node:os';
4
5
  import { PROJECTS_DIR } from '../../../core/utils.js';
5
6
  import { createLogger } from '../../../core/log.js';
6
7
  import { parseTasksFileWithLock, serializeTasksFileWithLock } from '../../../core/task-parser.js';
7
- import { withTaskFileMutationLock } from './task-lifecycle-edit.js';
8
+ import { withTaskFileMutationLock, withTaskFileMutationLockAsync } from './task-lifecycle-edit.js';
8
9
  const log = createLogger('task-lock');
9
10
  // ── Atomic write ──
10
11
  function atomicWriteSync(filePath, data) {
@@ -52,6 +53,19 @@ export function readLock(project) {
52
53
  return null;
53
54
  }
54
55
  }
56
+ /** Async twin of `readLock` for callers that must not block the event loop. */
57
+ export async function readLockAsync(project) {
58
+ try {
59
+ const content = await fsp.readFile(tasksYamlPath(project), 'utf8');
60
+ const { lock } = parseTasksFileWithLock(content, project);
61
+ return lock;
62
+ }
63
+ catch (err) {
64
+ if (err?.code !== 'ENOENT')
65
+ log.warn('Failed to read lock for %s: %s', project, err);
66
+ return null;
67
+ }
68
+ }
55
69
  function writeLockUnlocked(project, lock) {
56
70
  const filePath = tasksYamlPath(project);
57
71
  let tasks;
@@ -111,12 +125,26 @@ function releaseLockUnlocked(project, owner, opts) {
111
125
  export function writeLock(project, lock) {
112
126
  withTaskFileMutationLock(project, () => writeLockUnlocked(project, lock));
113
127
  }
128
+ /** Async twin of `writeLock`. */
129
+ export async function writeLockAsync(project, lock) {
130
+ await withTaskFileMutationLockAsync(project, async () => writeLockUnlocked(project, lock));
131
+ }
114
132
  export function acquireLock(project, opts) {
115
133
  return withTaskFileMutationLock(project, () => acquireLockUnlocked(project, opts));
116
134
  }
135
+ /** Async twin of `acquireLock` — the server takes this path so retrying a contended project lock
136
+ * yields to the event loop instead of sleeping inside `Atomics.wait`. */
137
+ export async function acquireLockAsync(project, opts) {
138
+ return withTaskFileMutationLockAsync(project, async () => acquireLockUnlocked(project, opts));
139
+ }
117
140
  export function releaseLock(project, owner, opts) {
118
141
  return withTaskFileMutationLock(project, () => releaseLockUnlocked(project, owner, opts));
119
142
  }
143
+ /** Async twin of `releaseLock` — the server takes this path so a contended cross-process
144
+ * mutation lock never parks the event loop in `Atomics.wait`. */
145
+ export async function releaseLockAsync(project, owner, opts) {
146
+ return withTaskFileMutationLockAsync(project, async () => releaseLockUnlocked(project, owner, opts));
147
+ }
120
148
  export function assertLockHeld(project, owner) {
121
149
  const current = readLock(project);
122
150
  if (!current) {