@askexenow/exe-os 0.9.264 → 0.9.265

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 (143) hide show
  1. package/dist/backfill-metadata-WM46YQZL.js +597 -0
  2. package/dist/bin/agentic-ontology-backfill.js +1 -1
  3. package/dist/bin/agentic-reflection-backfill.js +1 -1
  4. package/dist/bin/agentic-semantic-label.js +1 -1
  5. package/dist/bin/backfill-conversations.js +1 -1
  6. package/dist/bin/backfill-responses.js +1 -1
  7. package/dist/bin/backfill-vectors.js +2 -2
  8. package/dist/bin/bulk-sync-postgres.js +1 -1
  9. package/dist/bin/cleanup-stale-review-tasks.js +2 -2
  10. package/dist/bin/cli.js +5 -5
  11. package/dist/bin/exe-assign.js +1 -1
  12. package/dist/bin/exe-boot.js +3 -3
  13. package/dist/bin/exe-dispatch.js +2 -2
  14. package/dist/bin/exe-doctor.js +1 -1
  15. package/dist/bin/exe-export-behaviors.js +2 -2
  16. package/dist/bin/exe-forget.js +3 -3
  17. package/dist/bin/exe-gateway.js +5 -5
  18. package/dist/bin/exe-heartbeat.js +3 -3
  19. package/dist/bin/exe-kill.js +3 -3
  20. package/dist/bin/exe-launch-agent.js +3 -3
  21. package/dist/bin/exe-pending-messages.js +3 -3
  22. package/dist/bin/exe-pending-notifications.js +2 -2
  23. package/dist/bin/exe-pending-reviews.js +6 -4
  24. package/dist/bin/exe-review.js +3 -3
  25. package/dist/bin/exe-search.js +2 -2
  26. package/dist/bin/exe-session-cleanup.js +5 -5
  27. package/dist/bin/exe-start-codex.js +1 -1
  28. package/dist/bin/exe-start-opencode.js +1 -1
  29. package/dist/bin/exe-status.js +3 -3
  30. package/dist/bin/exe-team.js +1 -1
  31. package/dist/bin/git-sweep.js +2 -2
  32. package/dist/bin/graph-backfill.js +1 -1
  33. package/dist/bin/graph-export.js +2 -2
  34. package/dist/bin/import-history.js +2 -2
  35. package/dist/bin/intercom-check.js +5 -4
  36. package/dist/bin/mcp-sessions.js +2 -2
  37. package/dist/bin/orchestration-metrics.js +1 -1
  38. package/dist/bin/scan-tasks.js +2 -2
  39. package/dist/bin/shard-migrate.js +1 -1
  40. package/dist/capacity-monitor-FZORNXTA.js +49 -0
  41. package/dist/catchup-brief-PRKHIRWW.js +151 -0
  42. package/dist/chunk-2GU3NYMB.js +813 -0
  43. package/dist/chunk-2VT7Z2E2.js +197 -0
  44. package/dist/chunk-3L6XLN4V.js +1090 -0
  45. package/dist/chunk-3T4PNG5O.js +447 -0
  46. package/dist/chunk-3W324KN7.js +13696 -0
  47. package/dist/chunk-4IATAIAF.js +89 -0
  48. package/dist/chunk-5M4F2FVD.js +204 -0
  49. package/dist/chunk-5TANMPI4.js +377 -0
  50. package/dist/chunk-67E5WIMW.js +333 -0
  51. package/dist/chunk-6NRJIARA.js +346 -0
  52. package/dist/chunk-6O22GTSE.js +1148 -0
  53. package/dist/chunk-7O5CMDP6.js +1345 -0
  54. package/dist/chunk-7P2JKEO3.js +382 -0
  55. package/dist/chunk-A4UY44T7.js +486 -0
  56. package/dist/chunk-AZHPQGSI.js +159 -0
  57. package/dist/chunk-BQAC3GCO.js +127 -0
  58. package/dist/chunk-CIWJRYIC.js +244 -0
  59. package/dist/chunk-CZO2DGGF.js +214 -0
  60. package/dist/chunk-D55SXO3N.js +3951 -0
  61. package/dist/chunk-EPDSRI6O.js +284 -0
  62. package/dist/chunk-EU34R2A3.js +1073 -0
  63. package/dist/chunk-G4KEDLSM.js +488 -0
  64. package/dist/chunk-IODP4JNE.js +551 -0
  65. package/dist/chunk-IZ6LCET7.js +58 -0
  66. package/dist/chunk-LPG3U5UW.js +731 -0
  67. package/dist/chunk-NH6TPXZV.js +13696 -0
  68. package/dist/chunk-O5TZI7OZ.js +50 -0
  69. package/dist/chunk-Q3N4KHLM.js +330 -0
  70. package/dist/chunk-QHQTMWYH.js +54 -0
  71. package/dist/chunk-QNYOPM2L.js +1921 -0
  72. package/dist/chunk-SPOA7EOD.js +81 -0
  73. package/dist/chunk-TK23WXKB.js +128 -0
  74. package/dist/chunk-TOVXER6J.js +76 -0
  75. package/dist/chunk-UIPAZYP7.js +171 -0
  76. package/dist/chunk-WXW4GF6M.js +495 -0
  77. package/dist/{chunk-YGOUKUNX.js → chunk-XLYBSXWS.js} +2 -1
  78. package/dist/core-memory-QXMQ5I7S.js +110 -0
  79. package/dist/crm-webhook-CH5W633Y.js +10 -0
  80. package/dist/cto-delegation-gate-XY3NMGTE.js +206 -0
  81. package/dist/daemon-orchestration-LS62JMTI.js +135 -0
  82. package/dist/dreaming-ZBKE2GFX.js +32 -0
  83. package/dist/exe-export-JNSQRIWI.js +73 -0
  84. package/dist/exe-import-AVGWQZLU.js +76 -0
  85. package/dist/exe-key-WR6QEHYO.js +579 -0
  86. package/dist/exe-snapshot-U6K3J6BD.js +164 -0
  87. package/dist/fast-db-init-ZHRRYI7M.js +7 -0
  88. package/dist/gateway/index.js +6 -6
  89. package/dist/git-task-sweep-64KSWRUI.js +40 -0
  90. package/dist/hooks/bug-report-worker.js +4 -4
  91. package/dist/hooks/codex-stop-task-finalizer.js +4 -4
  92. package/dist/hooks/commit-complete.js +4 -4
  93. package/dist/hooks/error-recall.js +2 -2
  94. package/dist/hooks/ingest.js +2 -2
  95. package/dist/hooks/instructions-loaded.js +1 -1
  96. package/dist/hooks/manifest.json +18 -18
  97. package/dist/hooks/notification.js +1 -1
  98. package/dist/hooks/post-compact.js +2 -2
  99. package/dist/hooks/post-tool-combined.js +2 -2
  100. package/dist/hooks/pre-compact.js +3 -3
  101. package/dist/hooks/pre-tool-use.js +6 -6
  102. package/dist/hooks/prompt-submit.js +15 -10
  103. package/dist/hooks/session-end.js +5 -5
  104. package/dist/hooks/session-start.js +5 -5
  105. package/dist/hooks/stop.js +5 -5
  106. package/dist/hooks/subagent-stop.js +2 -2
  107. package/dist/hooks/summary-worker.js +5 -5
  108. package/dist/index.js +9 -9
  109. package/dist/lib/consolidation.js +2 -2
  110. package/dist/lib/exe-daemon.js +17 -17
  111. package/dist/lib/hybrid-search.js +2 -2
  112. package/dist/lib/messaging.js +2 -2
  113. package/dist/lib/schedules.js +2 -2
  114. package/dist/lib/store.js +1 -1
  115. package/dist/lib/tasks.js +3 -3
  116. package/dist/lib/tmux-routing.js +1 -1
  117. package/dist/mcp/register-tools.js +24 -24
  118. package/dist/mcp/server.js +25 -25
  119. package/dist/mcp/tools/create-task.js +4 -4
  120. package/dist/mcp/tools/list-tasks.js +4 -4
  121. package/dist/mcp/tools/send-message.js +3 -3
  122. package/dist/mcp/tools/update-task.js +4 -4
  123. package/dist/notifications-45QSHDFA.js +45 -0
  124. package/dist/orchestrator-7XBMFK7D.js +33 -0
  125. package/dist/pipeline-router-MQKRNCTR.js +13 -0
  126. package/dist/reranker-CJW3UYE2.js +19 -0
  127. package/dist/review-polling-RL75XLAY.js +124 -0
  128. package/dist/runtime/index.js +3 -3
  129. package/dist/session-events-ZULAN4XL.js +36 -0
  130. package/dist/session-scope-V2RSOTDU.js +86 -0
  131. package/dist/skill-refinement-BSX6Q6IN.js +157 -0
  132. package/dist/task-enforcement-JRTAOYZT.js +333 -0
  133. package/dist/task-scope-GNCB2GAM.js +35 -0
  134. package/dist/tasks-crud-MZIOYF3R.js +77 -0
  135. package/dist/tasks-notify-7KNZ4ULO.js +38 -0
  136. package/dist/tasks-review-U5VEV4Y7.js +47 -0
  137. package/dist/telemetry-upload-BIB5TJA4.js +739 -0
  138. package/dist/tui/App.js +7 -7
  139. package/dist/tui-data-ZSB5DDEY.js +258 -0
  140. package/dist/worker-gate-TXLX33PX.js +21 -0
  141. package/dist/workflow-engine-3PIT3Y56.js +28 -0
  142. package/package.json +1 -1
  143. package/release-notes.json +14 -13
@@ -0,0 +1,447 @@
1
+ import {
2
+ dispatchTaskToEmployee,
3
+ markTaskNotificationsRead,
4
+ notifyTaskDone
5
+ } from "./chunk-CIWJRYIC.js";
6
+ import {
7
+ cleanupReviewFile,
8
+ createTaskCore,
9
+ deleteTaskCore,
10
+ markAsReadByTaskFile,
11
+ sessionScopeFilter,
12
+ updateTaskStatus,
13
+ writeNotification
14
+ } from "./chunk-D55SXO3N.js";
15
+ import {
16
+ orgBus
17
+ } from "./chunk-MP2AFCGL.js";
18
+ import {
19
+ getClient,
20
+ getCoordinatorName,
21
+ isCoordinatorName
22
+ } from "./chunk-QQZMP6QL.js";
23
+ import {
24
+ EXE_AI_DIR
25
+ } from "./chunk-VXIMSRTO.js";
26
+
27
+ // src/lib/tasks.ts
28
+ import path2 from "path";
29
+ import { writeFileSync, mkdirSync, unlinkSync } from "fs";
30
+
31
+ // src/lib/tasks-chain.ts
32
+ import path from "path";
33
+ import { readFile, writeFile } from "fs/promises";
34
+ async function cascadeUnblock(taskId, baseDir, now) {
35
+ const client = getClient();
36
+ const ubScope = sessionScopeFilter();
37
+ const blockedRows = await client.execute({
38
+ sql: `SELECT id, title, assigned_to, priority, task_file, project_name FROM tasks WHERE blocked_by = ? AND status = 'blocked'${ubScope.sql}`,
39
+ args: [taskId, ...ubScope.args]
40
+ });
41
+ if (blockedRows.rows.length === 0) return;
42
+ const ids = blockedRows.rows.map((r) => String(r.id));
43
+ const ph = ids.map(() => "?").join(",");
44
+ await client.execute({
45
+ sql: `UPDATE tasks SET status = 'open', blocked_by = NULL, updated_at = ?
46
+ WHERE id IN (${ph})`,
47
+ args: [now, ...ids]
48
+ });
49
+ const unblockedRows = blockedRows;
50
+ if (baseDir) {
51
+ for (const ur of unblockedRows.rows) {
52
+ try {
53
+ const ubFile = path.join(baseDir, String(ur.task_file));
54
+ let ubContent = await readFile(ubFile, "utf-8");
55
+ ubContent = ubContent.replace(/\*\*Status:\*\* blocked/, "**Status:** open");
56
+ ubContent = ubContent.replace(/\n\*\*Blocked by:\*\*.*\n/, "\n");
57
+ await writeFile(ubFile, ubContent, "utf-8");
58
+ } catch {
59
+ }
60
+ }
61
+ }
62
+ if (unblockedRows.rows.length > 0 && !process.env.VITEST) {
63
+ try {
64
+ const { dispatchTaskToEmployee: dispatchTaskToEmployee2 } = await import("./tasks-notify-7KNZ4ULO.js");
65
+ const dispatched = /* @__PURE__ */ new Set();
66
+ for (const ur of unblockedRows.rows) {
67
+ const assignee = String(ur.assigned_to);
68
+ if (dispatched.has(assignee)) continue;
69
+ dispatched.add(assignee);
70
+ const unblockedId = String(ur.id);
71
+ const title = String(ur.title);
72
+ const priority = String(ur.priority ?? "P2");
73
+ const taskFile = String(ur.task_file ?? "");
74
+ const projectName = ur.project_name != null ? String(ur.project_name) : void 0;
75
+ dispatchTaskToEmployee2({
76
+ assignedTo: assignee,
77
+ taskId: unblockedId,
78
+ title,
79
+ priority,
80
+ taskFile,
81
+ initialStatus: "open",
82
+ projectDir: baseDir,
83
+ projectName
84
+ }).catch(() => {
85
+ });
86
+ }
87
+ } catch {
88
+ try {
89
+ const { queueIntercom } = await import("./intercom-queue-A6UJEFIF.js");
90
+ const dispatched = /* @__PURE__ */ new Set();
91
+ for (const ur of unblockedRows.rows) {
92
+ const assignee = String(ur.assigned_to);
93
+ if (dispatched.has(assignee)) continue;
94
+ dispatched.add(assignee);
95
+ queueIntercom(`${assignee}`, `unblocked: "${String(ur.title)}" is now ready`);
96
+ }
97
+ } catch {
98
+ }
99
+ }
100
+ }
101
+ }
102
+ async function findNextTask(assignedTo) {
103
+ const client = getClient();
104
+ const ntScope = sessionScopeFilter();
105
+ const nextResult = await client.execute({
106
+ sql: `SELECT title, task_file, priority FROM tasks
107
+ WHERE assigned_to = ? AND status = 'open'${ntScope.sql}
108
+ ORDER BY priority ASC, created_at ASC
109
+ LIMIT 1`,
110
+ args: [assignedTo, ...ntScope.args]
111
+ });
112
+ if (nextResult.rows.length === 1) {
113
+ const nr = nextResult.rows[0];
114
+ return {
115
+ title: String(nr.title),
116
+ priority: String(nr.priority),
117
+ taskFile: String(nr.task_file)
118
+ };
119
+ }
120
+ return void 0;
121
+ }
122
+ async function checkSubtaskCompletion(parentTaskId, projectName) {
123
+ const client = getClient();
124
+ const scScope = sessionScopeFilter();
125
+ const remaining = await client.execute({
126
+ sql: `SELECT COUNT(*) as cnt FROM tasks
127
+ WHERE parent_task_id = ? AND status NOT IN ('done', 'needs_review', 'cancelled', 'closed')${scScope.sql}`,
128
+ args: [parentTaskId, ...scScope.args]
129
+ });
130
+ const cnt = Number(remaining.rows[0]?.cnt ?? 1);
131
+ if (cnt === 0) {
132
+ const parentRow = await client.execute({
133
+ sql: `SELECT assigned_to, title, task_file, project_name, session_scope FROM tasks WHERE id = ?`,
134
+ args: [parentTaskId]
135
+ });
136
+ if (parentRow.rows.length === 1) {
137
+ const pr = parentRow.rows[0];
138
+ const parentProject = pr.project_name == null ? projectName : String(pr.project_name);
139
+ await writeNotification({
140
+ agentId: String(pr.assigned_to),
141
+ agentRole: "system",
142
+ event: "subtasks_complete",
143
+ project: parentProject,
144
+ summary: `All subtasks complete for "${String(pr.title)}" \u2014 ready for rollup review`,
145
+ taskFile: String(pr.task_file),
146
+ // Scope the notification to the parent task's coordinator session —
147
+ // prevents subtask-complete notifications from leaking to other coordinator lanes.
148
+ sessionScope: pr.session_scope ? String(pr.session_scope) : void 0
149
+ });
150
+ }
151
+ }
152
+ }
153
+
154
+ // src/lib/tasks.ts
155
+ async function createTask(input) {
156
+ const result = await createTaskCore(input);
157
+ if (!input.skipDispatch && result.status !== "blocked" && !process.env.VITEST) {
158
+ dispatchTaskToEmployee({
159
+ assignedTo: input.assignedTo,
160
+ taskId: result.id,
161
+ title: input.title,
162
+ priority: input.priority,
163
+ taskFile: result.taskFile,
164
+ initialStatus: result.status,
165
+ projectName: input.projectName,
166
+ spawnRuntime: input.spawnRuntime ?? void 0,
167
+ spawnModel: input.spawnModel ?? void 0
168
+ });
169
+ }
170
+ return result;
171
+ }
172
+ async function updateTask(input) {
173
+ const { row, taskFile, now, taskId } = await updateTaskStatus(input);
174
+ try {
175
+ const agent = String(row.assigned_to);
176
+ const cacheDir = path2.join(EXE_AI_DIR, "session-cache");
177
+ const cachePath = path2.join(cacheDir, `current-task-${agent}.json`);
178
+ if (input.status === "in_progress") {
179
+ mkdirSync(cacheDir, { recursive: true });
180
+ writeFileSync(cachePath, JSON.stringify({ taskId, title: String(row.title) }));
181
+ } else if (input.status === "needs_review" || input.status === "done" || input.status === "blocked" || input.status === "cancelled" || input.status === "closed") {
182
+ try {
183
+ unlinkSync(cachePath);
184
+ } catch {
185
+ }
186
+ }
187
+ } catch (e) {
188
+ process.stderr.write(`[tasks] trajectory tagging failed: ${e instanceof Error ? e.message : String(e)}
189
+ `);
190
+ }
191
+ if (input.status === "needs_review" || input.status === "done" || input.status === "closed") {
192
+ await cleanupReviewFile(row, taskFile, input.baseDir);
193
+ }
194
+ if (input.status === "needs_review" || input.status === "done" || input.status === "cancelled" || input.status === "closed") {
195
+ try {
196
+ const client = getClient();
197
+ const taskTitle = String(row.title);
198
+ const escaped = taskTitle.replace(/%/g, "\\%").replace(/_/g, "\\_");
199
+ await client.execute({
200
+ sql: `UPDATE tasks SET status = 'cancelled', updated_at = ?
201
+ WHERE title LIKE ? ESCAPE '\\' AND status IN ('open', 'in_progress')`,
202
+ args: [now, `%left '${escaped}' as in\\_progress%`]
203
+ });
204
+ } catch (e) {
205
+ process.stderr.write(`[tasks] shadow task cleanup failed: ${e instanceof Error ? e.message : String(e)}
206
+ `);
207
+ }
208
+ const assignedAgent = String(row.assigned_to);
209
+ if (!isCoordinatorName(assignedAgent)) {
210
+ try {
211
+ const draftClient = getClient();
212
+ if (input.status === "needs_review" || input.status === "done" || input.status === "closed") {
213
+ await draftClient.execute({
214
+ sql: `UPDATE memories SET draft = 0 WHERE agent_id = ? AND draft = 1`,
215
+ args: [assignedAgent]
216
+ });
217
+ } else if (input.status === "cancelled") {
218
+ const now2 = (/* @__PURE__ */ new Date()).toISOString();
219
+ await draftClient.execute({
220
+ sql: `UPDATE memories SET status = 'deleted', deleted_at = ? WHERE agent_id = ? AND draft = 1`,
221
+ args: [now2, assignedAgent]
222
+ });
223
+ }
224
+ } catch (e) {
225
+ process.stderr.write(`[tasks] draft memory promotion/purge failed: ${e instanceof Error ? e.message : String(e)}
226
+ `);
227
+ }
228
+ }
229
+ try {
230
+ const client = getClient();
231
+ const cascaded = await client.execute({
232
+ sql: `UPDATE tasks SET status = 'closed', updated_at = ?
233
+ WHERE parent_task_id = ? AND status = 'needs_review'`,
234
+ args: [now, taskId]
235
+ });
236
+ if (cascaded.rowsAffected > 0) {
237
+ process.stderr.write(
238
+ `[cascade] Closed ${cascaded.rowsAffected} orphaned review task(s) for parent ${taskId}
239
+ `
240
+ );
241
+ }
242
+ } catch (e) {
243
+ process.stderr.write(`[tasks] review cascade close failed: ${e instanceof Error ? e.message : String(e)}
244
+ `);
245
+ }
246
+ }
247
+ const isCoordinator = isCoordinatorName(String(row.assigned_to));
248
+ if (input.status === "done" && row.reviewer && !isCoordinator) {
249
+ input.status = "needs_review";
250
+ }
251
+ const isTerminal = input.status === "done" || input.status === "needs_review" || input.status === "closed";
252
+ if (isTerminal) {
253
+ if (!isCoordinator) {
254
+ notifyTaskDone();
255
+ }
256
+ if ((input.status === "done" || input.status === "needs_review") && row.reviewer && !isCoordinator) {
257
+ const reviewer = String(row.reviewer);
258
+ const taskTitle = String(row.title);
259
+ let delivered = false;
260
+ try {
261
+ const { sendIntercom, resolveExeSession, employeeSessionName } = await import("./lib/tmux-routing.js");
262
+ const exeSession = row.session_scope ? String(row.session_scope) : resolveExeSession();
263
+ if (exeSession) {
264
+ if (isCoordinatorName(reviewer)) {
265
+ const cooResult = sendIntercom(exeSession, { force: true, reason: "completion" });
266
+ if (cooResult !== "failed") {
267
+ delivered = true;
268
+ process.stderr.write(`[tasks] EVENT: notified coordinator "${reviewer}" for "${taskTitle}" (force)
269
+ `);
270
+ }
271
+ } else {
272
+ const reviewerSession = employeeSessionName(reviewer, exeSession);
273
+ const result = sendIntercom(reviewerSession, { force: true, reason: "completion" });
274
+ if (result !== "failed") {
275
+ delivered = true;
276
+ process.stderr.write(`[tasks] EVENT: notified reviewer "${reviewer}" via tmux for "${taskTitle}"
277
+ `);
278
+ }
279
+ }
280
+ }
281
+ } catch (e) {
282
+ process.stderr.write(`[tasks] EVENT: tmux delivery failed: ${e instanceof Error ? e.message : String(e)}
283
+ `);
284
+ }
285
+ if (!delivered) {
286
+ try {
287
+ process.stderr.write(`[tasks] EVENT: tmux delivery failed for reviewer="${reviewer}". Queueing for daemon delivery.
288
+ `);
289
+ const { queueIntercom } = await import("./intercom-queue-A6UJEFIF.js");
290
+ const { resolveExeSession } = await import("./lib/tmux-routing.js");
291
+ const exeSession = row.session_scope ? String(row.session_scope) : resolveExeSession();
292
+ if (exeSession) {
293
+ const reviewerSession = isCoordinatorName(reviewer) ? exeSession : `${reviewer}-${exeSession}`;
294
+ queueIntercom(
295
+ reviewerSession,
296
+ `Review ready: "${taskTitle}" by ${String(row.assigned_to)}. Run /exe-review.`,
297
+ "completion"
298
+ );
299
+ }
300
+ } catch (e) {
301
+ process.stderr.write(`[tasks] EVENT: intercom queue failed: ${e instanceof Error ? e.message : String(e)}
302
+ `);
303
+ }
304
+ }
305
+ try {
306
+ const { pushNotifyAsync } = await import("./push-notifications-AMHVR6DF.js");
307
+ pushNotifyAsync({
308
+ event: "review_ready",
309
+ title: `Review ready: ${taskTitle.slice(0, 50)}`,
310
+ body: `${String(row.assigned_to)} completed "${taskTitle}". Reviewer: ${reviewer}`,
311
+ priority: "normal"
312
+ });
313
+ } catch {
314
+ }
315
+ }
316
+ if (!isCoordinator) {
317
+ try {
318
+ const { pushNotifyAsync } = await import("./push-notifications-AMHVR6DF.js");
319
+ const event = input.status === "needs_review" ? "review_ready" : "task_complete";
320
+ pushNotifyAsync({
321
+ event,
322
+ title: `${String(row.assigned_to)} completed: ${String(row.title).slice(0, 80)}`,
323
+ body: input.result ? String(input.result).slice(0, 500) : `Task "${String(row.title)}" is ${input.status}.`,
324
+ agent: String(row.assigned_to),
325
+ project: String(row.project_name)
326
+ });
327
+ } catch {
328
+ }
329
+ }
330
+ await markTaskNotificationsRead(taskFile);
331
+ if (input.status === "needs_review" && !isCoordinator && row.reviewer) {
332
+ try {
333
+ const { writeNotification: writeNotification2 } = await import("./notifications-45QSHDFA.js");
334
+ const reviewer = String(row.reviewer);
335
+ await writeNotification2({
336
+ agentId: reviewer,
337
+ agentRole: isCoordinatorName(reviewer) ? "COO" : "manager",
338
+ event: "task_complete",
339
+ project: String(row.project_name),
340
+ summary: `"${String(row.title)}" is ready for review`,
341
+ taskFile,
342
+ sessionScope: row.session_scope ? String(row.session_scope) : void 0
343
+ });
344
+ } catch (e) {
345
+ process.stderr.write(`[tasks] needs_review notification failed: ${e instanceof Error ? e.message : String(e)}
346
+ `);
347
+ }
348
+ }
349
+ if (input.status === "needs_review" || input.status === "done" || input.status === "closed") {
350
+ try {
351
+ await cascadeUnblock(taskId, input.baseDir, now);
352
+ } catch (e) {
353
+ process.stderr.write(`[tasks] cascade unblock failed: ${e instanceof Error ? e.message : String(e)}
354
+ `);
355
+ }
356
+ orgBus.emit({
357
+ type: "task_completed",
358
+ taskId,
359
+ employee: String(row.assigned_to),
360
+ result: input.result ?? "",
361
+ timestamp: now
362
+ });
363
+ if (row.parent_task_id) {
364
+ try {
365
+ await checkSubtaskCompletion(String(row.parent_task_id), String(row.project_name));
366
+ } catch (e) {
367
+ process.stderr.write(`[tasks] subtask completion check failed: ${e instanceof Error ? e.message : String(e)}
368
+ `);
369
+ }
370
+ }
371
+ }
372
+ }
373
+ if (input.status === "cancelled") {
374
+ try {
375
+ await cascadeUnblock(taskId, input.baseDir, now);
376
+ } catch (e) {
377
+ process.stderr.write(`[tasks] cancelled cascade unblock failed: ${e instanceof Error ? e.message : String(e)}
378
+ `);
379
+ }
380
+ }
381
+ if ((input.status === "needs_review" || input.status === "done" || input.status === "closed") && !isCoordinatorName(String(row.assigned_to)) && !process.env.VITEST) {
382
+ import("./lib/skill-learning.js").then(
383
+ ({ captureAndLearn }) => captureAndLearn({
384
+ taskId,
385
+ agentId: String(row.assigned_to),
386
+ projectName: String(row.project_name),
387
+ taskTitle: String(row.title)
388
+ })
389
+ ).catch((err) => {
390
+ process.stderr.write(
391
+ `[updateTask] skill learning failed: ${err instanceof Error ? err.message : String(err)}
392
+ `
393
+ );
394
+ });
395
+ }
396
+ let nextTask;
397
+ if (isTerminal && !isCoordinatorName(String(row.assigned_to))) {
398
+ try {
399
+ nextTask = await findNextTask(String(row.assigned_to));
400
+ } catch (e) {
401
+ process.stderr.write(`[tasks] task chaining failed: ${e instanceof Error ? e.message : String(e)}
402
+ `);
403
+ }
404
+ }
405
+ return {
406
+ id: String(row.id),
407
+ title: String(row.title),
408
+ assignedTo: String(row.assigned_to),
409
+ assignedBy: String(row.assigned_by),
410
+ reviewer: row.reviewer !== void 0 && row.reviewer !== null ? String(row.reviewer) : null,
411
+ projectName: String(row.project_name),
412
+ priority: String(row.priority),
413
+ status: input.status,
414
+ taskFile,
415
+ createdAt: String(row.created_at),
416
+ updatedAt: now,
417
+ budgetTokens: row.budget_tokens !== void 0 && row.budget_tokens !== null ? Number(row.budget_tokens) : null,
418
+ budgetFallbackModel: row.budget_fallback_model !== void 0 && row.budget_fallback_model !== null ? String(row.budget_fallback_model) : null,
419
+ tokensUsed: Number(row.tokens_used ?? 0),
420
+ tokensWarnedAt: row.tokens_warned_at !== void 0 && row.tokens_warned_at !== null ? Number(row.tokens_warned_at) : null,
421
+ spawnRuntime: row.spawn_runtime !== void 0 && row.spawn_runtime !== null ? String(row.spawn_runtime) : null,
422
+ spawnModel: row.spawn_model !== void 0 && row.spawn_model !== null ? String(row.spawn_model) : null,
423
+ sessionScope: row.session_scope !== void 0 && row.session_scope !== null ? String(row.session_scope) : null,
424
+ nextTask
425
+ };
426
+ }
427
+ async function deleteTask(taskId, baseDir) {
428
+ const client = getClient();
429
+ const { taskFile, assignedTo, assignedBy, taskSlug } = await deleteTaskCore(taskId, baseDir);
430
+ const coordinatorName = getCoordinatorName();
431
+ const reviewer = assignedBy || coordinatorName;
432
+ const reviewSlug = `review-${assignedTo}-${taskSlug}`;
433
+ const reviewFile = `exe/${reviewer}/${reviewSlug}.md`;
434
+ const legacyReviewFile = `exe/${coordinatorName}/${reviewSlug}.md`;
435
+ await client.execute({
436
+ sql: "DELETE FROM tasks WHERE task_file = ? OR task_file = ? OR task_file = ?",
437
+ args: [reviewFile, legacyReviewFile, `exe/exe/${reviewSlug}.md`]
438
+ });
439
+ await markAsReadByTaskFile(taskFile);
440
+ await markAsReadByTaskFile(reviewFile);
441
+ }
442
+
443
+ export {
444
+ createTask,
445
+ updateTask,
446
+ deleteTask
447
+ };