@wrongstack/tools 0.313.0 → 0.316.1

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 (182) hide show
  1. package/dist/_edit-match.d.ts +3 -2
  2. package/dist/_output-spool.d.ts +4 -3
  3. package/dist/_shell-pick.d.ts +2 -1
  4. package/dist/_spawn-stream.d.ts +2 -1
  5. package/dist/_syntax-check.d.ts +2 -1
  6. package/dist/audit.js +10 -4055
  7. package/dist/bash-kill-guard.d.ts +3 -6
  8. package/dist/bash.js +9 -2308
  9. package/dist/batch-tool-use.js +2 -187
  10. package/dist/browser/index.js +25 -1339
  11. package/dist/browser/network-guard-proxy.d.ts +2 -1
  12. package/dist/builtin.js +69 -33949
  13. package/dist/chunk-22B7GE5T.js +260 -0
  14. package/dist/chunk-2VSZC6QM.js +113 -0
  15. package/dist/chunk-3PVYQFRQ.js +472 -0
  16. package/dist/chunk-42BHI7TN.js +337 -0
  17. package/dist/chunk-4BHUSMNL.js +104 -0
  18. package/dist/chunk-4I4LWFOO.js +431 -0
  19. package/dist/chunk-4UESMQDP.js +122 -0
  20. package/dist/chunk-553IQUMO.js +478 -0
  21. package/dist/chunk-5H4GSJAI.js +223 -0
  22. package/dist/chunk-6RNIFLG4.js +305 -0
  23. package/dist/chunk-7EY5DCRO.js +434 -0
  24. package/dist/chunk-A6BRWIXN.js +317 -0
  25. package/dist/chunk-AHHDWNXC.js +200 -0
  26. package/dist/chunk-BSLVR56S.js +199 -0
  27. package/dist/chunk-BTSFTGIL.js +7 -0
  28. package/dist/chunk-D33S4RQG.js +222 -0
  29. package/dist/chunk-DA4KNE2H.js +4412 -0
  30. package/dist/chunk-DR7JOQTC.js +520 -0
  31. package/dist/chunk-EEOFQDT6.js +898 -0
  32. package/dist/chunk-EJWSCQ6D.js +137 -0
  33. package/dist/chunk-EMRGN4KM.js +170 -0
  34. package/dist/chunk-FQZOHLG3.js +89 -0
  35. package/dist/chunk-GOIZNNOA.js +221 -0
  36. package/dist/chunk-HFXSNKCV.js +196 -0
  37. package/dist/chunk-HYX2TZ7O.js +1272 -0
  38. package/dist/chunk-I64BS3VC.js +15 -0
  39. package/dist/chunk-IVWV2UM6.js +955 -0
  40. package/dist/chunk-IXMNTNW5.js +238 -0
  41. package/dist/chunk-IYK7XGDZ.js +892 -0
  42. package/dist/chunk-J5SKD6LN.js +235 -0
  43. package/dist/chunk-JNNVRHMV.js +2111 -0
  44. package/dist/chunk-JOHXDF3D.js +295 -0
  45. package/dist/chunk-JRJJX3L5.js +424 -0
  46. package/dist/chunk-K3WNSHUF.js +1371 -0
  47. package/dist/chunk-L25CVUVR.js +2830 -0
  48. package/dist/chunk-LIJQMYYX.js +59 -0
  49. package/dist/chunk-LWKUTMD5.js +197 -0
  50. package/dist/chunk-MQX2KXVW.js +54 -0
  51. package/dist/chunk-MZZN7VCD.js +359 -0
  52. package/dist/chunk-NBDZMMG2.js +169 -0
  53. package/dist/chunk-NKJW5GFO.js +366 -0
  54. package/dist/chunk-NKNOBUBU.js +522 -0
  55. package/dist/chunk-O4MBV4AX.js +134 -0
  56. package/dist/chunk-OUBDL3WH.js +3515 -0
  57. package/dist/chunk-PQKK5JH7.js +101 -0
  58. package/dist/chunk-PY2IOS7C.js +1000 -0
  59. package/dist/chunk-Q5JPPCZC.js +12 -0
  60. package/dist/chunk-QBV725YG.js +128 -0
  61. package/dist/chunk-QZQSPUBF.js +315 -0
  62. package/dist/chunk-RGISBZBD.js +231 -0
  63. package/dist/chunk-RJZQWEMS.js +84 -0
  64. package/dist/chunk-RXISBFR5.js +315 -0
  65. package/dist/chunk-S5CCLZL3.js +99 -0
  66. package/dist/chunk-SDLVH5RZ.js +178 -0
  67. package/dist/chunk-T2F4S7U4.js +1723 -0
  68. package/dist/chunk-TEBQ4VPZ.js +163 -0
  69. package/dist/chunk-U4D5S3VQ.js +21 -0
  70. package/dist/chunk-U4VAATKP.js +193 -0
  71. package/dist/chunk-UCYQTZ7F.js +113 -0
  72. package/dist/chunk-UKU2ZX4C.js +203 -0
  73. package/dist/chunk-UNSKG6DC.js +159 -0
  74. package/dist/chunk-V43EQ6VR.js +68 -0
  75. package/dist/chunk-VB3MJGCV.js +610 -0
  76. package/dist/chunk-VFKPWSOX.js +154 -0
  77. package/dist/chunk-VJNHFZ7J.js +190 -0
  78. package/dist/chunk-VXECAJJ7.js +1091 -0
  79. package/dist/chunk-WHIIIREL.js +223 -0
  80. package/dist/chunk-Z6DAKQ3U.js +1 -0
  81. package/dist/chunk-ZJQ4IGXK.js +474 -0
  82. package/dist/chunk-ZLTFLC25.js +385 -0
  83. package/dist/circuit-breaker.js +3 -191
  84. package/dist/codebase-index/ast-invariant-engine.d.ts +5 -4
  85. package/dist/codebase-index/binary-frame.d.ts +0 -2
  86. package/dist/codebase-index/bm25.d.ts +1 -1
  87. package/dist/codebase-index/circuit-breaker.d.ts +2 -1
  88. package/dist/codebase-index/codebase-ast-replace-tool.d.ts +3 -2
  89. package/dist/codebase-index/codebase-impact-analysis-tool.d.ts +4 -3
  90. package/dist/codebase-index/codebase-invariant-check-tool.d.ts +3 -2
  91. package/dist/codebase-index/codebase-repo-map-tool.d.ts +3 -2
  92. package/dist/codebase-index/codebase-skeleton-tool.d.ts +3 -2
  93. package/dist/codebase-index/codebase-targeted-test-tool.d.ts +3 -2
  94. package/dist/codebase-index/content-hash.d.ts +0 -2
  95. package/dist/codebase-index/import-extractor.d.ts +0 -13
  96. package/dist/codebase-index/index-service.d.ts +1 -1
  97. package/dist/codebase-index/index.js +84 -13688
  98. package/dist/codebase-index/languages.d.ts +2 -1
  99. package/dist/codebase-index/module-roots.d.ts +3 -2
  100. package/dist/codebase-index/parser-batch.d.ts +0 -5
  101. package/dist/codebase-index/parser-dispatch.d.ts +2 -1
  102. package/dist/codebase-index/parser-output.d.ts +4 -3
  103. package/dist/codebase-index/parser-worker-pool.d.ts +0 -2
  104. package/dist/codebase-index/parser-worker-script.d.ts +1 -16
  105. package/dist/codebase-index/parser-worker-script.js +8 -3995
  106. package/dist/codebase-index/project-server-client-state.d.ts +2 -2
  107. package/dist/codebase-index/project-server-endpoint.d.ts +0 -15
  108. package/dist/codebase-index/project-server.js +60 -8548
  109. package/dist/codebase-index/tree-sitter/visitor.d.ts +2 -1
  110. package/dist/codebase-index/tree-sitter-parser.d.ts +0 -2
  111. package/dist/codebase-index/ts-parser.d.ts +1 -1
  112. package/dist/codebase-index/vector-search.d.ts +2 -1
  113. package/dist/codebase-index/wal-maintenance.d.ts +3 -2
  114. package/dist/codebase-index/worker.js +20 -8416
  115. package/dist/codebase-index/writer-admin.d.ts +0 -1
  116. package/dist/codebase-index/writer-search.d.ts +0 -9
  117. package/dist/design.js +2 -299
  118. package/dist/diff.js +4 -256
  119. package/dist/document.js +4 -222
  120. package/dist/e2e.js +5 -476
  121. package/dist/edit.js +14 -10200
  122. package/dist/exec.js +16 -3131
  123. package/dist/fetch.js +8 -398
  124. package/dist/format.js +10 -3750
  125. package/dist/generic-parser-VUXDIAOZ.js +13 -0
  126. package/dist/git.js +4 -380
  127. package/dist/glob.js +6 -280
  128. package/dist/go-parser-JXYKJHRC.js +469 -0
  129. package/dist/grep.js +7 -604
  130. package/dist/index.js +318 -35387
  131. package/dist/install.js +10 -4091
  132. package/dist/json-parser-IBHZ4BZC.js +213 -0
  133. package/dist/json.js +4 -665
  134. package/dist/kanban-contract-actions.d.ts +1 -1
  135. package/dist/kanban-detail-actions.d.ts +2 -1
  136. package/dist/kanban-presence.d.ts +2 -1
  137. package/dist/kanban-serializer.d.ts +0 -8
  138. package/dist/kanban-split-task-handler.d.ts +2 -2
  139. package/dist/kanban-tool-types.d.ts +2 -1
  140. package/dist/kanban.js +3 -2096
  141. package/dist/languages/diagnostics.d.ts +2 -1
  142. package/dist/languages/index.js +23 -4664
  143. package/dist/languages/legacy-bridge.d.ts +3 -2
  144. package/dist/languages/types.d.ts +2 -1
  145. package/dist/legacy-bridge-7M6QLUQN.js +18 -0
  146. package/dist/lint.js +10 -3706
  147. package/dist/logs.js +4 -287
  148. package/dist/memory.js +6 -215
  149. package/dist/mode.js +3 -99
  150. package/dist/outdated.js +4 -5170
  151. package/dist/pack.js +65 -33897
  152. package/dist/parser-dispatch-QH4XPGG6.js +14 -0
  153. package/dist/patch.js +13 -9935
  154. package/dist/plan.js +5 -3286
  155. package/dist/process-registry.js +8 -651
  156. package/dist/ps-slash.js +12 -1439
  157. package/dist/pwsh.d.ts +0 -1
  158. package/dist/py-parser-IS4HKYMF.js +16 -0
  159. package/dist/read.js +13 -9816
  160. package/dist/replace.js +15 -10014
  161. package/dist/rs-parser-XHUUO2KZ.js +81 -0
  162. package/dist/scaffold.js +4 -253
  163. package/dist/search.js +5 -585
  164. package/dist/session-kanban-sync.d.ts +0 -6
  165. package/dist/session-kanban.js +30 -972
  166. package/dist/skill.js +2 -215
  167. package/dist/spawn-background.d.ts +1 -1
  168. package/dist/task.js +5 -3410
  169. package/dist/test.js +10 -3773
  170. package/dist/todo.js +4 -2891
  171. package/dist/tool-help.js +3 -123
  172. package/dist/tool-search.js +3 -79
  173. package/dist/tool-tier.js +68 -33984
  174. package/dist/tool-use.js +2 -93
  175. package/dist/tree-sitter-parser-AIERW3YI.js +15 -0
  176. package/dist/tree.js +4 -288
  177. package/dist/ts-parser-RCTYKSVI.js +232 -0
  178. package/dist/typecheck.js +10 -3753
  179. package/dist/win32.js +6 -60
  180. package/dist/write.js +14 -9882
  181. package/dist/yaml-parser-4SAXV3PL.js +157 -0
  182. package/package.json +5 -5
package/dist/kanban.js CHANGED
@@ -1,2100 +1,7 @@
1
- // src/kanban.ts
2
- import { stripLifecycleIssues as stripLifecycleIssues2 } from "@wrongstack/kanban";
3
-
4
- // src/kanban-board-actions.ts
5
- import { loadTasks as loadTasks2 } from "@wrongstack/core/storage";
6
- import { deserializeTaskGraph as deserializeTaskGraph2, serializeTaskGraph } from "@wrongstack/core/tasking";
7
1
  import {
8
- addTask,
9
- adoptManagedLifecycle,
10
- createBoard as createBoard2,
11
- createBoardFromTaskGraph,
12
- createBoardFromText,
13
- duplicateBoard,
14
- exportBoardAsMarkdown,
15
- exportBoardToTaskGraph,
16
- getBoard as getBoard3,
17
- getKanbanOrchestrationSnapshot as getKanbanOrchestrationSnapshot2,
18
- getKanbanQueueHealth,
19
- listBoards as listBoards2,
20
- listKanbanEvents,
21
- listReadyTasks,
22
- parseLinesIntoTasks,
23
- removeBoard as removeBoard2,
24
- searchKanban,
25
- syncBoardFromTaskGraph as syncBoardFromTaskGraph2,
26
- updateBoard as updateBoard2
27
- } from "@wrongstack/kanban";
28
-
29
- // src/kanban-board-inputs.ts
30
- function agentSettableGate(enforcement) {
31
- if (enforcement === void 0 || enforcement === "off") return {};
32
- return { completionGate: { enforcement } };
33
- }
34
- function boardCreateInput(input, title) {
35
- return {
36
- title,
37
- ...input.description !== void 0 ? { description: input.description } : {},
38
- ...input.tags !== void 0 ? { tags: input.tags } : {},
39
- ...input.generatedBy !== void 0 ? { generatedBy: input.generatedBy } : {},
40
- ...input.atomicityMode !== void 0 ? {
41
- atomicity: {
42
- mode: input.atomicityMode,
43
- decomposition: input.atomicityDecomposition ?? "propose"
44
- }
45
- } : {},
46
- ...agentSettableGate(input.gateEnforcement)
47
- };
48
- }
49
- function boardUpdatePatch(input) {
50
- return {
51
- ...input.title !== void 0 ? { title: input.title } : {},
52
- ...input.description !== void 0 ? { description: input.description } : {},
53
- ...input.tags !== void 0 ? { tags: input.tags } : {},
54
- ...input.atomicityMode !== void 0 ? {
55
- atomicity: {
56
- mode: input.atomicityMode,
57
- decomposition: input.atomicityDecomposition ?? "propose"
58
- }
59
- } : {},
60
- ...agentSettableGate(input.gateEnforcement)
61
- };
62
- }
63
- function duplicateBoardOptions(input) {
64
- return {
65
- ...input.title !== void 0 ? { title: input.title } : {},
66
- ...input.generatedBy !== void 0 ? { generatedBy: input.generatedBy } : {},
67
- ...input.includeTasks !== void 0 ? { includeTasks: input.includeTasks } : {},
68
- ...input.includeCompletedTasks !== void 0 ? { includeCompletedTasks: input.includeCompletedTasks } : {},
69
- ...input.preserveAssignment !== void 0 ? { preserveAssignment: input.preserveAssignment } : {}
70
- };
71
- }
72
-
73
- // src/kanban-split-task-handler.ts
74
- import { getBoard, splitTask } from "@wrongstack/kanban";
75
-
76
- // src/kanban-tool-results.ts
77
- function atomicityNudge(task) {
78
- if (task.atomicityAssessment?.verdict !== "needs_decomposition") return "";
79
- const reasons = task.atomicityAssessment.criteria.filter((entry) => entry.score < 1).map((entry) => entry.reason).join(" | ");
80
- return ` Atomicity: needs_decomposition (score ${task.atomicityAssessment.score}) \u2014 call propose_decomposition with 2+ subtasks before dispatch. Reasons: ${reasons}`;
81
- }
82
- function readEnvGateEnforcement() {
83
- const raw = process.env["WRONGSTACK_KANBAN_GATE"]?.trim().toLowerCase();
84
- return raw === "strict" || raw === "soft" || raw === "off" ? raw : void 0;
85
- }
86
- function fail(message) {
87
- return { ok: false, message };
88
- }
89
- function okBoard(board, message = "Board loaded.") {
90
- return { ok: true, message, board };
91
- }
92
- function okTask(board, task, message) {
93
- return { ok: true, message, board, task };
94
- }
95
-
96
- // src/kanban-split-task-handler.ts
97
- async function handleSplitTask(projectRoot, input, extraSplitOptions) {
98
- const boardId = input.boardId;
99
- const taskId = input.taskId;
100
- const childTitles = input.childTitles;
101
- if (!boardId || !taskId || !childTitles?.length) {
102
- return fail("split requires boardId, taskId, and at least one childTitles.");
103
- }
104
- const {
105
- targetColumnId,
106
- inheritAssignment,
107
- inheritLabels,
108
- inheritSuccessCriteria,
109
- inheritGoalMetrics,
110
- inheritDependencies,
111
- chainChildren,
112
- rewireDependents
113
- } = input;
114
- const result = await splitTask(projectRoot, boardId, taskId, {
115
- titles: childTitles,
116
- ...extraSplitOptions,
117
- ...targetColumnId !== void 0 ? { columnId: targetColumnId } : {},
118
- ...inheritAssignment !== void 0 ? { inheritAssignment } : {},
119
- ...inheritLabels !== void 0 ? { inheritLabels } : {},
120
- ...inheritSuccessCriteria !== void 0 ? { inheritSuccessCriteria } : {},
121
- ...inheritGoalMetrics !== void 0 ? { inheritGoalMetrics } : {},
122
- ...inheritDependencies !== void 0 ? { inheritDependencies } : {},
123
- ...chainChildren !== void 0 ? { chainChildren } : {},
124
- ...rewireDependents !== void 0 ? { rewireDependents } : {}
125
- });
126
- if (!result) return fail("Task not found.");
127
- const freshParent = result.board.tasks?.find((t) => t.id === taskId);
128
- if (!freshParent) {
129
- return fail(
130
- `Split succeeded but parent ${taskId} not found in returned board. Children: [${result.children.map((c) => c.id).join(", ")}].`
131
- );
132
- }
133
- return {
134
- ok: true,
135
- message: `${result.children.length} child task(s) created.`,
136
- board: result.board,
137
- task: freshParent,
138
- children: result.children
139
- };
140
- }
141
- async function requireBoard(projectRoot, boardId) {
142
- return boardId ? getBoard(projectRoot, boardId) : null;
143
- }
144
-
145
- // src/session-kanban.ts
146
- import { loadPlan, loadTasks } from "@wrongstack/core/storage";
147
- import { deserializeTaskGraph } from "@wrongstack/core/tasking";
148
- import {
149
- bridgeKanbanSupervisor,
150
- compactSessionMirrorBoard,
151
- createBoard,
152
- DEFAULT_COLUMNS,
153
- getBoard as getBoard2,
154
- getKanbanOrchestrationSnapshot,
155
- listBoards,
156
- pruneSessionBoards,
157
- removeBoard,
158
- syncBoardFromTaskGraph,
159
- touchKanbanPresence,
160
- updateBoard
161
- } from "@wrongstack/kanban";
162
-
163
- // src/session-kanban-graph.ts
164
- function taskFileToSerializedGraph(tasks, sessionId) {
165
- const graphId = `session:${sessionId}`;
166
- const ids = new Set(tasks.map((task) => task.id));
167
- const nodes = tasks.map((task, index) => ({
168
- id: task.id,
169
- title: task.title,
170
- description: task.description ?? "",
171
- type: task.type,
172
- priority: task.priority,
173
- status: task.status,
174
- specRequirementId: `${graphId}:${task.id}`,
175
- ...task.assignee ? { assignee: task.assignee } : {},
176
- ...task.estimateHours !== void 0 ? { estimateHours: task.estimateHours } : {},
177
- createdAt: index,
178
- updatedAt: index
179
- }));
180
- const edges = tasks.flatMap(
181
- (task) => (task.dependsOn ?? []).filter((dependency) => ids.has(dependency)).map((dependency) => ({
182
- id: `${dependency}->${task.id}`,
183
- from: dependency,
184
- to: task.id,
185
- type: "depends_on"
186
- }))
187
- );
188
- const hasIncoming = new Set(edges.map((edge) => edge.to));
189
- const rootNodes = nodes.filter((node) => !hasIncoming.has(node.id)).map((node) => node.id);
190
- return {
191
- // Keep the historical graph id so existing mirrored task cards are reused.
192
- id: graphId,
193
- specId: graphId,
194
- requiredRequirementIds: nodes.map((node) => node.specRequirementId),
195
- title: "Session tasks",
196
- nodes,
197
- edges,
198
- rootNodes: rootNodes.length ? rootNodes : nodes[0] ? [nodes[0].id] : [],
199
- createdAt: 0,
200
- updatedAt: 0
201
- };
202
- }
203
-
204
- // src/session-kanban-sync.ts
205
- import { getSharedProjectMailbox } from "@wrongstack/core/coordination";
206
- import { mutatePlan, mutateTasks } from "@wrongstack/core/storage";
207
- import { formatTodosForModel, resolveWstackPaths } from "@wrongstack/core/utils";
208
- import {
209
- getDependencyReadinessIssues
210
- } from "@wrongstack/kanban";
211
- function sourceStatus(task) {
212
- if (task.status === "completed") return "completed";
213
- if (task.status === "in_progress") return "in_progress";
214
- if (task.status === "review") return "review";
215
- if (task.status === "blocked") return "blocked";
216
- if (task.status === "failed") return "failed";
217
- return "pending";
218
- }
219
- function todoStatus(task) {
220
- const status = sourceStatus(task);
221
- if (status === "completed") return "completed";
222
- if (status === "review" && task.assignment?.status === "completed") return "completed";
223
- if (status === "in_progress" || status === "review") return "in_progress";
224
- return "pending";
225
- }
226
- async function applySessionKanbanTaskToSource(context, task, suppressedTodoMirrors2, options = {}) {
227
- const originId = task.origin?.taskId;
228
- const graphId = task.origin?.graphId ?? "";
229
- const isTodoOrigin = task.origin?.system === "session-todo" || graphId.startsWith("todo:");
230
- const targetTodo = context.todos?.find(
231
- (todo) => originId !== void 0 && todo.id === originId || todo.kanbanTaskId === task.id || todo.id === task.id && !todo.promotedFromPlan && !todo.promotedFromTask
232
- );
233
- if (isTodoOrigin || targetTodo) {
234
- const matchedId = targetTodo?.id ?? originId;
235
- if (matchedId) {
236
- const mappedStatus = todoStatus(task);
237
- const next = options.remove ? context.todos.filter((todo) => todo.id !== matchedId) : context.todos.map(
238
- (todo) => todo.id === matchedId ? {
239
- ...todo,
240
- content: task.title,
241
- status: mappedStatus,
242
- kanbanTaskId: task.id
243
- } : todo
244
- );
245
- suppressedTodoMirrors2.add(context);
246
- try {
247
- context.state.replaceTodos(next);
248
- } finally {
249
- suppressedTodoMirrors2.delete(context);
250
- }
251
- return { source: "todo", todos: [...context.todos] };
252
- }
253
- }
254
- if (!originId) return { source: null };
255
- const id = context.session?.id ?? "";
256
- if (task.origin?.system === "session-plan" || graphId.startsWith("plan:")) {
257
- const planPath = context.meta["plan.path"];
258
- if (typeof planPath !== "string" || !planPath) {
259
- throw new Error(
260
- "Cannot reflect this Kanban edit back to its plan source: the session has no plan.path configured. The board mutation already succeeded; the plan file is now out of sync."
261
- );
262
- }
263
- const plan = await mutatePlan(planPath, id, (file) => ({
264
- ...file,
265
- updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
266
- items: options.remove ? file.items.filter((item) => item.id !== originId) : file.items.map(
267
- (item) => item.id === originId ? {
268
- ...item,
269
- title: task.title,
270
- details: task.description,
271
- status: task.status === "completed" ? "done" : task.status === "in_progress" || task.status === "review" ? "in_progress" : "open",
272
- updatedAt: (/* @__PURE__ */ new Date()).toISOString()
273
- } : item
274
- )
275
- }));
276
- return { source: "plan", plan };
277
- }
278
- if (task.origin?.system === "session-task" || task.origin?.system === "session" || graphId.startsWith("session:")) {
279
- const taskPath = context.meta["task.path"];
280
- if (typeof taskPath !== "string" || !taskPath) {
281
- throw new Error(
282
- "Cannot reflect this Kanban edit back to its task source: the session has no task.path configured. The board mutation already succeeded; the task file is now out of sync."
283
- );
284
- }
285
- const tasks = await mutateTasks(taskPath, id, (file) => ({
286
- ...file,
287
- tasks: options.remove ? file.tasks.filter((item) => item.id !== originId) : file.tasks.map(
288
- (item) => item.id === originId ? {
289
- ...item,
290
- title: task.title,
291
- description: task.description,
292
- status: sourceStatus(task),
293
- updatedAt: (/* @__PURE__ */ new Date()).toISOString()
294
- } : item
295
- )
296
- }));
297
- return { source: "task", tasks };
298
- }
299
- return { source: null };
300
- }
301
-
302
- // src/session-kanban.ts
303
- var SESSION_KANBAN_COLUMNS = DEFAULT_COLUMNS.map((column) => ({
304
- ...column
305
- }));
306
- var suppressedTodoMirrors = /* @__PURE__ */ new WeakSet();
307
- function applySessionKanbanTaskToSource2(context, task, options = {}) {
308
- return applySessionKanbanTaskToSource(context, task, suppressedTodoMirrors, options);
309
- }
310
-
311
- // src/kanban-board-actions.ts
312
- async function handleKanbanBoardAction(projectRoot, input, ctx) {
313
- switch (input.action) {
314
- case "list_boards": {
315
- const boards = await listBoards2(projectRoot);
316
- return { ok: true, message: `${boards.length} board(s).`, boards };
317
- }
318
- case "get_board": {
319
- const board = await requireBoard(projectRoot, input.boardId);
320
- return board ? okBoard(board) : fail("Board not found.");
321
- }
322
- case "create_board": {
323
- if (!input.title) return fail("create_board requires title.");
324
- const existing = (await listBoards2(projectRoot)).filter(
325
- (candidate) => (candidate.kind ?? "project") === "project"
326
- );
327
- const board = await createBoard2(projectRoot, boardCreateInput(input, input.title));
328
- const note = existing.length ? ` ${existing.length} other project board(s) already exist: ${existing.slice(0, 3).map((candidate) => `"${candidate.title}" (${candidate.taskCount} task(s))`).join(
329
- ", "
330
- )}${existing.length > 3 ? ", \u2026" : ""}. If this work belongs to one of them, add_task there instead and delete this board.` : "";
331
- return { ok: true, message: `Board created: ${board.title}.${note}`, board };
332
- }
333
- case "update_board": {
334
- if (!input.boardId) return fail("update_board requires boardId.");
335
- const board = await updateBoard2(projectRoot, input.boardId, boardUpdatePatch(input));
336
- return board ? okBoard(board, "Board updated.") : fail("Board not found.");
337
- }
338
- case "adopt_managed_lifecycle": {
339
- if (!input.boardId || !input.author || !input.transitionComment) {
340
- return fail(
341
- "adopt_managed_lifecycle requires boardId, author, transitionComment, and five ordered columns."
342
- );
343
- }
344
- if (input.columns?.length !== 5) {
345
- return fail(
346
- "adopt_managed_lifecycle columns must be ordered as backlog, todo, running, review, done."
347
- );
348
- }
349
- const [backlog, todo, running, review, done] = input.columns;
350
- if (!backlog || !todo || !running || !review || !done) {
351
- return fail("adopt_managed_lifecycle columns must contain five nonblank ids.");
352
- }
353
- const board = await adoptManagedLifecycle(projectRoot, input.boardId, {
354
- columns: { backlog, todo, running, review, done },
355
- actor: input.author,
356
- comment: input.transitionComment
357
- });
358
- return board ? okBoard(board, "Managed lifecycle adopted without moving existing cards.") : fail("Board not found.");
359
- }
360
- case "release_managed_lifecycle": {
361
- if (!input.boardId) return fail("release_managed_lifecycle requires boardId.");
362
- const board = await updateBoard2(projectRoot, input.boardId, { lifecycle: null });
363
- return board ? okBoard(
364
- board,
365
- "Managed lifecycle released; the board now tracks work without strict gates."
366
- ) : fail("Board not found.");
367
- }
368
- case "duplicate_board": {
369
- if (!input.boardId) return fail("duplicate_board requires boardId.");
370
- const board = await duplicateBoard(projectRoot, input.boardId, duplicateBoardOptions(input));
371
- return board ? okBoard(board, "Board duplicated.") : fail("Board not found.");
372
- }
373
- case "delete_board": {
374
- if (!input.boardId) return fail("delete_board requires boardId.");
375
- const removed = await removeBoard2(projectRoot, input.boardId);
376
- return { ok: removed, message: removed ? "Board deleted." : "Board not found." };
377
- }
378
- case "generate_board": {
379
- if (!input.description) return fail("generate_board requires description.");
380
- const boardInput = createBoardFromText({
381
- description: input.description,
382
- ...input.title !== void 0 ? { title: input.title } : {},
383
- ...input.context !== void 0 ? { context: input.context } : {}
384
- });
385
- const board = await createBoard2(projectRoot, boardInput);
386
- for (const tInput of parseLinesIntoTasks(
387
- input.description,
388
- board.columns[0]?.id ?? "backlog"
389
- )) {
390
- await addTask(projectRoot, board.id, tInput);
391
- }
392
- return okBoard(await getBoard3(projectRoot, board.id) ?? board, "Board generated.");
393
- }
394
- case "export_markdown": {
395
- const board = await requireBoard(projectRoot, input.boardId);
396
- if (!board) return fail("Board not found.");
397
- return {
398
- ok: true,
399
- message: "Board exported.",
400
- board,
401
- markdown: exportBoardAsMarkdown(board)
402
- };
403
- }
404
- case "export_task_graph": {
405
- if (!input.boardId) return fail("export_task_graph requires boardId.");
406
- const exported = await exportBoardToTaskGraph(projectRoot, input.boardId, {
407
- ...input.graphId !== void 0 ? { graphId: input.graphId } : {},
408
- ...input.specId !== void 0 ? { specId: input.specId } : {},
409
- ...input.title !== void 0 ? { title: input.title } : {},
410
- ...input.preserveOriginTaskIds !== void 0 ? { preserveOriginTaskIds: input.preserveOriginTaskIds } : {},
411
- ...input.includeArchived !== void 0 ? { includeArchived: input.includeArchived } : {}
412
- });
413
- if (!exported) return fail("Board not found.");
414
- return {
415
- ok: true,
416
- message: `Task graph exported with ${exported.graph.nodes.size} node(s).`,
417
- board: exported.board,
418
- taskGraph: serializeTaskGraph(exported.graph)
419
- };
420
- }
421
- case "sync_task_graph": {
422
- if (!input.boardId || !input.taskGraph) {
423
- return fail("sync_task_graph requires boardId and taskGraph.");
424
- }
425
- const graph = deserializeTaskGraph2(input.taskGraph);
426
- const result = await syncBoardFromTaskGraph2(projectRoot, input.boardId, graph, {
427
- ...input.title !== void 0 ? { title: input.title } : {},
428
- ...input.description !== void 0 ? { description: input.description } : {},
429
- ...input.tags !== void 0 ? { tags: input.tags } : {},
430
- ...input.generatedBy !== void 0 ? { generatedBy: input.generatedBy } : {},
431
- ...input.sourceSystem !== void 0 ? { sourceSystem: input.sourceSystem } : {},
432
- ...input.phaseId !== void 0 ? { phaseId: input.phaseId } : {},
433
- ...input.includeCompletedTasks !== void 0 ? { includeCompletedTasks: input.includeCompletedTasks } : {},
434
- ...input.archiveMissingTasks !== void 0 ? { archiveMissingTasks: input.archiveMissingTasks } : {},
435
- ...input.preserveManualDependencies !== void 0 ? { preserveManualDependencies: input.preserveManualDependencies } : {}
436
- });
437
- return result ? {
438
- ok: true,
439
- message: `Task graph synced: ${result.createdTaskIds.length} created, ${result.updatedTaskIds.length} updated, ${result.archivedTaskIds.length} archived.`,
440
- board: result.board
441
- } : fail("Board not found.");
442
- }
443
- case "create_from_graph": {
444
- if (!input.taskGraph) return fail("create_from_graph requires taskGraph.");
445
- const graph = deserializeTaskGraph2(input.taskGraph);
446
- const { board } = await createBoardFromTaskGraph(projectRoot, graph, {
447
- ...input.title !== void 0 ? { title: input.title } : {},
448
- ...input.description !== void 0 ? { description: input.description } : {},
449
- ...input.tags !== void 0 ? { tags: input.tags } : {},
450
- ...input.generatedBy !== void 0 ? { generatedBy: input.generatedBy } : {},
451
- ...input.sourceSystem !== void 0 ? { sourceSystem: input.sourceSystem } : {},
452
- ...input.phaseId !== void 0 ? { phaseId: input.phaseId } : {},
453
- ...input.includeCompletedTasks !== void 0 ? { includeCompletedTasks: input.includeCompletedTasks } : {}
454
- });
455
- return {
456
- ok: true,
457
- message: `Created board "${board.title}" from task graph with ${board.tasks.length} tasks.`,
458
- board
459
- };
460
- }
461
- case "import_session_tasks": {
462
- const taskPath = ctx.meta?.["task.path"];
463
- if (!taskPath) return fail("No session task file for this session.");
464
- const file = await loadTasks2(taskPath);
465
- if (!file || file.tasks.length === 0) return fail("No session tasks to import.");
466
- const sessionId = ctx.session?.id ?? file.sessionId ?? "session";
467
- const graph = deserializeTaskGraph2(taskFileToSerializedGraph(file.tasks, sessionId));
468
- const tags = ["session", `session:${sessionId}`];
469
- const existing = (await listBoards2(projectRoot)).find(
470
- (b) => b.tags?.includes(`session:${sessionId}`)
471
- );
472
- if (existing) {
473
- const result = await syncBoardFromTaskGraph2(projectRoot, existing.id, graph, {
474
- sourceSystem: "session",
475
- tags,
476
- archiveMissingTasks: true,
477
- includeCompletedTasks: true
478
- });
479
- return result ? {
480
- ok: true,
481
- message: `Synced ${file.tasks.length} session tasks into board "${result.board.title}".`,
482
- board: result.board
483
- } : fail("Session board vanished mid-sync.");
484
- }
485
- const { board } = await createBoardFromTaskGraph(projectRoot, graph, {
486
- title: `Session tasks (${sessionId.slice(0, 8)})`,
487
- sourceSystem: "session",
488
- tags
489
- });
490
- return {
491
- ok: true,
492
- message: `Imported ${file.tasks.length} session tasks into new board "${board.title}".`,
493
- board
494
- };
495
- }
496
- case "search_tasks": {
497
- const tasks = await searchKanban(projectRoot, {
498
- query: input.query,
499
- boardId: input.boardId,
500
- assignedAgent: input.agentId,
501
- status: input.status,
502
- priority: input.priority,
503
- label: input.labels?.[0],
504
- chainId: input.chainId
505
- });
506
- return { ok: true, message: `${tasks.length} task(s) matched.`, tasks };
507
- }
508
- case "ready_tasks": {
509
- const tasks = await listReadyTasks(projectRoot, {
510
- query: input.query,
511
- boardId: input.boardId,
512
- assignedAgent: input.agentId,
513
- priority: input.priority,
514
- label: input.labels?.[0],
515
- chainId: input.chainId,
516
- limit: input.limit
517
- });
518
- return { ok: true, message: `${tasks.length} ready task(s).`, tasks };
519
- }
520
- case "snapshot": {
521
- const snapshot = await getKanbanOrchestrationSnapshot2(projectRoot, {
522
- query: input.query,
523
- boardId: input.boardId,
524
- assignedAgent: input.agentId,
525
- status: input.status,
526
- priority: input.priority,
527
- label: input.labels?.[0],
528
- chainId: input.chainId
529
- });
530
- return {
531
- ok: true,
532
- message: `${snapshot.ready.length} ready, ${snapshot.running.length} running, ${snapshot.blocked.length} blocked.`,
533
- snapshot
534
- };
535
- }
536
- case "events": {
537
- if (!input.boardId) return fail("events requires boardId.");
538
- const eventList = await listKanbanEvents(projectRoot, input.boardId);
539
- return {
540
- ok: true,
541
- message: `${eventList.length} event(s).`,
542
- events: eventList
543
- };
544
- }
545
- case "queue_health": {
546
- const health = await getKanbanQueueHealth(projectRoot, {
547
- ...input.boardId !== void 0 ? { boardId: input.boardId } : {}
548
- });
549
- return {
550
- ok: true,
551
- message: `Counts: startable=${health.counts.startable}, running=${health.counts.running}, stale=${health.staleAssignments.count}.`,
552
- queueHealth: health
553
- };
554
- }
555
- default:
556
- return void 0;
557
- }
558
- }
559
-
560
- // src/kanban-contract-actions.ts
561
- import {
562
- addContractEdge,
563
- configureContractGraph,
564
- evaluateTaskContractGraph,
565
- getContractGraph,
566
- removeContractEdge,
567
- removeContractNode,
568
- upsertContractNode
569
- } from "@wrongstack/kanban";
570
- async function handleKanbanContractAction(projectRoot, input, actor) {
571
- switch (input.action) {
572
- case "get_contract_graph": {
573
- if (!input.boardId) return fail("get_contract_graph requires boardId.");
574
- const found = await getContractGraph(projectRoot, input.boardId);
575
- if (!found) return fail("Board not found.");
576
- const evaluated = input.taskId ? await evaluateTaskContractGraph(projectRoot, input.boardId, input.taskId) : null;
577
- if (input.taskId && !evaluated) return fail("Task not found on this board.");
578
- return {
579
- ok: true,
580
- message: found.graph ? `Contract map: ${found.graph.nodes.length} node(s), ${found.graph.edges.length} edge(s), enforcement ${found.graph.enforcement}.` : "No contract map on this board yet. Call configure_contract_graph to start one.",
581
- board: found.board,
582
- contractGraph: found.graph,
583
- ...evaluated ? { contractEvaluation: evaluated.evaluation } : {}
584
- };
585
- }
586
- case "configure_contract_graph": {
587
- if (!input.boardId) return fail("configure_contract_graph requires boardId.");
588
- const enforcement = input.contractEnforcement ?? "advisory";
589
- const board = await configureContractGraph(projectRoot, input.boardId, enforcement);
590
- return board ? okBoard(board, `Contract map enforcement set to ${enforcement}.`) : fail("Board not found.");
591
- }
592
- case "upsert_contract_node": {
593
- if (!input.boardId || !input.taskId) {
594
- return fail("upsert_contract_node requires boardId and taskId.");
595
- }
596
- if (!input.contractNodeKind || !input.contractNodeTitle) {
597
- return fail("upsert_contract_node requires contractNodeKind and contractNodeTitle.");
598
- }
599
- const waiver = input.contractNodeState === "waived" ? {
600
- actor: actor ?? "agent",
601
- reason: input.contractWaiverReason ?? "",
602
- at: (/* @__PURE__ */ new Date()).toISOString()
603
- } : void 0;
604
- if (waiver && !waiver.reason.trim()) {
605
- return fail("A waived contract node requires contractWaiverReason.");
606
- }
607
- const result = await upsertContractNode(projectRoot, input.boardId, {
608
- taskId: input.taskId,
609
- kind: input.contractNodeKind,
610
- title: input.contractNodeTitle,
611
- ...input.contractNodeId !== void 0 ? { id: input.contractNodeId } : {},
612
- ...input.contractNodeDescription !== void 0 ? { description: input.contractNodeDescription } : {},
613
- ...input.contractNodeState !== void 0 ? { state: input.contractNodeState } : {},
614
- ...input.contractNodeEnforcement !== void 0 ? { enforcement: input.contractNodeEnforcement } : {},
615
- ...input.contractCheckId !== void 0 ? { checkId: input.contractCheckId } : {},
616
- ...input.contractMetricId !== void 0 ? { metricId: input.contractMetricId } : {},
617
- ...waiver ? { waiver } : {},
618
- ...actor !== void 0 ? { createdBy: actor } : {}
619
- });
620
- if (!result) return fail("Board or task not found.");
621
- return {
622
- ok: true,
623
- message: `Contract node ${result.node.kind} "${result.node.title}" saved (${result.node.id}).`,
624
- board: result.board,
625
- contractGraph: result.board.contractGraph ?? null
626
- };
627
- }
628
- case "remove_contract_node": {
629
- if (!input.boardId || !input.contractNodeId) {
630
- return fail("remove_contract_node requires boardId and contractNodeId.");
631
- }
632
- const board = await removeContractNode(projectRoot, input.boardId, input.contractNodeId);
633
- return board ? okBoard(board, "Contract node removed, along with every edge that touched it.") : fail("Contract node not found.");
634
- }
635
- case "add_contract_edge": {
636
- if (!input.boardId || !input.contractEdgeFrom || !input.contractEdgeTo) {
637
- return fail("add_contract_edge requires boardId, contractEdgeFrom, and contractEdgeTo.");
638
- }
639
- if (!input.contractEdgeType) return fail("add_contract_edge requires contractEdgeType.");
640
- const result = await addContractEdge(projectRoot, input.boardId, {
641
- from: input.contractEdgeFrom,
642
- to: input.contractEdgeTo,
643
- type: input.contractEdgeType,
644
- ...input.contractEdgeId !== void 0 ? { id: input.contractEdgeId } : {},
645
- ...input.contractNodeEnforcement !== void 0 ? { enforcement: input.contractNodeEnforcement } : {},
646
- ...input.contractEdgeRationale !== void 0 ? { rationale: input.contractEdgeRationale } : {},
647
- ...actor !== void 0 ? { createdBy: actor } : {}
648
- });
649
- if (!result) return fail("Board not found.");
650
- return {
651
- ok: true,
652
- message: `Contract edge ${result.edge.type}: ${result.edge.from} \u2192 ${result.edge.to}.`,
653
- board: result.board,
654
- contractGraph: result.board.contractGraph ?? null
655
- };
656
- }
657
- case "remove_contract_edge": {
658
- if (!input.boardId || !input.contractEdgeId) {
659
- return fail("remove_contract_edge requires boardId and contractEdgeId.");
660
- }
661
- const board = await removeContractEdge(projectRoot, input.boardId, input.contractEdgeId);
662
- return board ? okBoard(board, "Contract edge removed.") : fail("Contract edge not found.");
663
- }
664
- default:
665
- return void 0;
666
- }
667
- }
668
-
669
- // src/kanban-decomposition-actions.ts
670
- import {
671
- assessTaskAtomicity,
672
- proposeTaskDecomposition,
673
- updateTask,
674
- verifyTaskCompletion
675
- } from "@wrongstack/kanban";
676
-
677
- // src/kanban-evidence-bridge.ts
678
- import { recordCompletedWorkEvidence } from "@wrongstack/core/utils";
679
- function kanbanEvidenceKey(boardId, taskId) {
680
- return `kanban:${boardId}:${taskId}`;
681
- }
682
- function kanbanEvidencePointer(boardId, taskId) {
683
- return `kanban://${boardId}/${taskId}#verificationReport`;
684
- }
685
- function recordKanbanVerificationEvidence(ctx, report) {
686
- try {
687
- const passed = report.checks.filter((check) => check.status === "passed").length;
688
- const completedAt = Date.parse(report.completedAt);
689
- recordCompletedWorkEvidence(ctx, {
690
- key: kanbanEvidenceKey(report.boardId, report.taskId),
691
- source: "verification",
692
- summary: `${report.taskTitle} \u2014 verification ${report.verdict} (${passed}/${report.checks.length} checks)`,
693
- ...Number.isFinite(completedAt) ? { completedAt } : {},
694
- evidence: kanbanEvidencePointer(report.boardId, report.taskId)
695
- });
696
- } catch {
697
- }
698
- }
699
-
700
- // src/kanban-decomposition-actions.ts
701
- async function handleKanbanDecompositionAction(projectRoot, input, ctx) {
702
- switch (input.action) {
703
- case "assess_atomicity": {
704
- if (!input.boardId || !input.taskId) {
705
- return fail("assess_atomicity requires boardId and taskId.");
706
- }
707
- const result = await assessTaskAtomicity(projectRoot, input.boardId, input.taskId, {
708
- assessedBy: "agent",
709
- ...ctx.agentId !== void 0 ? { eventContext: { actor: ctx.agentId } } : {}
710
- });
711
- if (!result) return fail("Task not found.");
712
- const failing = result.assessment.criteria.filter((entry) => entry.score < 1).map((entry) => entry.reason);
713
- const guidance = result.assessment.verdict === "needs_decomposition" ? ` This task should be split before dispatch \u2014 call propose_decomposition with 2+ subtasks (each with one verifiable success criterion). Reasons: ${failing.join(" | ")}` : result.assessment.verdict === "composite" ? " Container task: work happens in its children; it is verified via subtask aggregation." : "";
714
- return okTask(
715
- result.board,
716
- result.task,
717
- `Atomicity verdict: ${result.assessment.verdict} (score ${result.assessment.score}).${guidance}`
718
- );
719
- }
720
- case "propose_decomposition": {
721
- if (!input.boardId || !input.taskId || !input.subtasks?.length) {
722
- return fail("propose_decomposition requires boardId, taskId, and subtasks (2+).");
723
- }
724
- if (input.subtasks.length < 2) {
725
- return fail("propose_decomposition requires at least two subtasks.");
726
- }
727
- const invalid = input.subtasks.find(
728
- (subtask) => typeof subtask?.title !== "string" || !subtask.title.trim()
729
- );
730
- if (invalid) return fail("Every proposed subtask needs a non-blank title.");
731
- const result = await proposeTaskDecomposition(
732
- projectRoot,
733
- input.boardId,
734
- input.taskId,
735
- {
736
- subtasks: input.subtasks,
737
- ...input.note !== void 0 ? { rationale: input.note } : {},
738
- ...ctx.agentId !== void 0 ? { proposedBy: ctx.agentId } : {}
739
- },
740
- ctx.agentId !== void 0 ? { actor: ctx.agentId } : {}
741
- );
742
- if (!result) return fail("Task not found.");
743
- const message = result.proposal.status === "applied" ? `Decomposition applied: ${result.proposal.appliedChildTaskIds?.length ?? 0} child tasks created (parent marked atomic).` : 'Decomposition proposal recorded \u2014 awaiting approval (board policy is "propose"). It can be approved from the WebUI or via update_task.';
744
- return okTask(result.board, result.task, message);
745
- }
746
- case "verify_completion": {
747
- if (!input.boardId || !input.taskId) {
748
- return fail("verify_completion requires boardId and taskId.");
749
- }
750
- const verResult = await verifyTaskCompletion(projectRoot, input.boardId, input.taskId);
751
- const persistedBoard = await updateTask(projectRoot, input.boardId, input.taskId, {
752
- verificationReport: verResult.report,
753
- successCriteria: verResult.task.successCriteria
754
- });
755
- if (!persistedBoard) {
756
- return {
757
- ok: false,
758
- verdict: verResult.report.verdict,
759
- message: `Verification succeeded but persist failed: ${verResult.report.markdownSummary}. Board may be stale \u2014 re-run verify_completion.`,
760
- board: verResult.board
761
- };
762
- }
763
- recordKanbanVerificationEvidence(ctx, verResult.report);
764
- const freshTask = persistedBoard.tasks?.find((t) => t.id === input.taskId);
765
- const deterministicVerdicts = ["passed", "failed", "needs_human", "incomplete"];
766
- return {
767
- ok: deterministicVerdicts.includes(
768
- verResult.report.verdict
769
- ),
770
- verdict: verResult.report.verdict,
771
- message: verResult.report.markdownSummary,
772
- board: persistedBoard,
773
- task: freshTask ?? verResult.task
774
- };
775
- }
776
- default:
777
- return void 0;
778
- }
779
- }
780
-
781
- // src/kanban-detail-actions.ts
782
- import {
783
- addCheckToTask,
784
- addDependency,
785
- addGoalMetricToTask,
786
- addLinkToTask,
787
- addNoteToTask,
788
- getKanbanWorkbench,
789
- removeCheckFromTask,
790
- updateCheckOnTask,
791
- updateGoalMetricOnTask
792
- } from "@wrongstack/kanban";
793
- async function handleKanbanDetailAction(projectRoot, input) {
794
- switch (input.action) {
795
- case "workbench": {
796
- const workbench = await getKanbanWorkbench(projectRoot, {
797
- ...input.limit !== void 0 ? { limitPerLane: input.limit, alertLimit: input.limit } : {}
798
- });
799
- return {
800
- ok: true,
801
- message: `${workbench.totals.now} now, ${workbench.totals.next} next, ${workbench.totals.blocked} blocked, ${workbench.totals.review} review; ${workbench.alertTotal} alert(s).`,
802
- workbench
803
- };
804
- }
805
- case "add_dependency": {
806
- if (!input.boardId || !input.taskId || !input.dependencyTaskId) {
807
- return fail("add_dependency requires boardId, taskId, and dependencyTaskId.");
808
- }
809
- const board = await addDependency(
810
- projectRoot,
811
- input.boardId,
812
- input.taskId,
813
- input.dependencyTaskId
814
- );
815
- return board ? okBoard(board, "Dependency added.") : fail("Task not found.");
816
- }
817
- case "add_goal_metric": {
818
- if (!input.boardId || !input.taskId || !input.metricName) {
819
- return fail("add_goal_metric requires boardId, taskId, and metricName.");
820
- }
821
- const board = await addGoalMetricToTask(projectRoot, input.boardId, input.taskId, {
822
- name: input.metricName,
823
- ...input.metricStatus !== void 0 ? { status: input.metricStatus } : {},
824
- ...input.metricTarget !== void 0 ? { target: input.metricTarget } : {},
825
- ...input.metricCurrent !== void 0 ? { current: input.metricCurrent } : {},
826
- ...input.metricDirection !== void 0 ? { direction: input.metricDirection } : {},
827
- ...input.metricUnit !== void 0 ? { unit: input.metricUnit } : {},
828
- ...input.metricNotes !== void 0 ? { notes: input.metricNotes } : {}
829
- });
830
- return board ? okBoard(board, "Goal metric added.") : fail("Task not found.");
831
- }
832
- case "update_goal_metric": {
833
- if (!input.boardId || !input.taskId || !input.metricId) {
834
- return fail("update_goal_metric requires boardId, taskId, and metricId.");
835
- }
836
- const board = await updateGoalMetricOnTask(
837
- projectRoot,
838
- input.boardId,
839
- input.taskId,
840
- input.metricId,
841
- {
842
- ...input.metricName !== void 0 ? { name: input.metricName } : {},
843
- ...input.metricStatus !== void 0 ? { status: input.metricStatus } : {},
844
- ...input.metricTarget !== void 0 ? { target: input.metricTarget } : {},
845
- ...input.metricCurrent !== void 0 ? { current: input.metricCurrent } : {},
846
- ...input.metricDirection !== void 0 ? { direction: input.metricDirection } : {},
847
- ...input.metricUnit !== void 0 ? { unit: input.metricUnit } : {},
848
- ...input.metricNotes !== void 0 ? { notes: input.metricNotes } : {}
849
- }
850
- );
851
- return board ? okBoard(board, "Goal metric updated.") : fail("Metric not found.");
852
- }
853
- case "add_check": {
854
- if (!input.boardId || !input.taskId || !input.checkDescription) {
855
- return fail("add_check requires boardId, taskId, and checkDescription.");
856
- }
857
- const board = await addCheckToTask(projectRoot, input.boardId, input.taskId, {
858
- description: input.checkDescription,
859
- type: input.checkType ?? "manual",
860
- status: input.checkStatus,
861
- ...input.checkNotes !== void 0 ? { notes: input.checkNotes } : {}
862
- });
863
- return board ? okBoard(board, "Check added.") : fail("Task not found.");
864
- }
865
- case "update_check": {
866
- if (!input.boardId || !input.taskId || !input.checkId) {
867
- return fail("update_check requires boardId, taskId, and checkId.");
868
- }
869
- const board = await updateCheckOnTask(
870
- projectRoot,
871
- input.boardId,
872
- input.taskId,
873
- input.checkId,
874
- {
875
- ...input.checkDescription !== void 0 ? { description: input.checkDescription } : {},
876
- ...input.checkStatus !== void 0 ? { status: input.checkStatus } : {},
877
- // Promoting an existing manual criterion to an executable one is the
878
- // common repair: the card was written before anyone knew the command.
879
- ...input.checkType !== void 0 ? { type: input.checkType } : {},
880
- ...input.checkNotes !== void 0 ? { notes: input.checkNotes } : {}
881
- }
882
- );
883
- return board ? okBoard(board, "Check updated.") : fail("Check not found.");
884
- }
885
- case "remove_check": {
886
- if (!input.boardId || !input.taskId || !input.checkId) {
887
- return fail("remove_check requires boardId, taskId, and checkId.");
888
- }
889
- const board = await removeCheckFromTask(
890
- projectRoot,
891
- input.boardId,
892
- input.taskId,
893
- input.checkId
894
- );
895
- return board ? okBoard(board, "Acceptance criterion removed.") : fail("Check not found on this task.");
896
- }
897
- case "add_note": {
898
- if (!input.boardId || !input.taskId || !input.note)
899
- return fail("add_note requires boardId, taskId, and note.");
900
- const board = await addNoteToTask(projectRoot, input.boardId, input.taskId, {
901
- author: input.author ?? "agent",
902
- content: input.note
903
- });
904
- return board ? okBoard(board, "Note added.") : fail("Task not found.");
905
- }
906
- case "add_link": {
907
- if (!input.boardId || !input.taskId || !input.url)
908
- return fail("add_link requires boardId, taskId, and url.");
909
- const board = await addLinkToTask(projectRoot, input.boardId, input.taskId, {
910
- url: input.url,
911
- type: input.linkType ?? "url",
912
- ...input.linkTitle !== void 0 ? { title: input.linkTitle } : {}
913
- });
914
- return board ? okBoard(board, "Link added.") : fail("Task not found.");
915
- }
916
- case "split_atomic": {
917
- if (!input.boardId || !input.taskId || !input.childTitles?.length) {
918
- return fail("split_atomic requires boardId, taskId, and childTitles (at least one).");
919
- }
920
- return handleSplitTask(projectRoot, input, { atomic: true });
921
- }
922
- default:
923
- return void 0;
924
- }
925
- }
926
-
927
- // src/kanban-lifecycle-actions.ts
928
- import { randomUUID as randomUUID2 } from "node:crypto";
929
- import {
930
- addTask as addTask2,
931
- assignTask,
932
- claimReadyTask,
933
- copyTaskToBoard,
934
- evaluateContractGraphReadiness,
935
- finalizeTaskCompletion,
936
- getBoard as getBoard4,
937
- getTask,
938
- getTaskChain,
939
- heartbeatTaskAssignment,
940
- mergeTasks,
941
- moveTask,
942
- recoverStaleTaskAssignments,
943
- releaseTaskClaim,
944
- removeTask,
945
- repairManagedTaskProjection,
946
- resolveAutoAccept,
947
- setTaskChain,
948
- stripLifecycleIssues,
949
- transferTaskToBoard,
950
- transitionTask,
951
- updateTask as updateTask2,
952
- updateTaskAssignment,
953
- verifyTaskCompletion as verifyTaskCompletion2
954
- } from "@wrongstack/kanban";
955
-
956
- // src/kanban-task-inputs.ts
957
- import { randomUUID } from "node:crypto";
958
- import { clampSubagentCapabilities } from "@wrongstack/core/security";
959
- function taskInput(input) {
960
- const assignment = hasAssignmentInput(input) ? assignmentForTaskCreate(input) : void 0;
961
- return {
962
- title: input.title ?? "",
963
- columnId: input.columnId,
964
- description: input.description,
965
- dueDate: input.dueDate,
966
- priority: input.priority,
967
- ...input.taskType !== void 0 ? { type: input.taskType } : {},
968
- status: input.status,
969
- labels: input.labels,
970
- ...assignment?.agentId ?? assignment?.role ?? assignment?.name ? { assignedAgent: assignment.agentId ?? assignment.role ?? assignment.name } : {},
971
- ...input.assignee ?? assignment?.name ?? assignment?.agentId ? { assignee: input.assignee ?? assignment?.name ?? assignment?.agentId } : {},
972
- ...mergedDependsOn(input) ? { dependsOn: mergedDependsOn(input) } : {},
973
- ...input.estimatedHours !== void 0 ? { estimatedHours: input.estimatedHours } : {},
974
- ...input.actualHours !== void 0 ? { actualHours: input.actualHours } : {},
975
- ...assignment ? { assignment } : {},
976
- ...input.order !== void 0 ? { order: input.order } : {},
977
- ...input.retryPolicy !== void 0 ? { retryPolicy: input.retryPolicy } : {},
978
- ...input.costCeilingUsd !== void 0 ? { costCeilingUsd: input.costCeilingUsd } : {},
979
- // The system prompt has always told the model it may "set atomic: true"
980
- // when creating a composite parent. It could not: the field reached
981
- // neither the create input nor the patch, so the instruction described a
982
- // capability that did not exist and the attempt was silently dropped.
983
- ...input.atomic !== void 0 ? { atomic: input.atomic } : {},
984
- ...input.childTitles !== void 0 ? { childTaskIds: input.childTitles } : {},
985
- ...input.checkDescription !== void 0 ? {
986
- successCriteria: [
987
- {
988
- id: randomUUID(),
989
- description: input.checkDescription,
990
- // `manual` only as the fallback. Hard-coding it here meant every
991
- // agent-authored criterion was unverifiable by construction: the
992
- // deterministic plugins never matched, the registry passed the
993
- // hand-set status straight through, and "verified" collapsed into
994
- // "the author ticked its own box".
995
- type: input.checkType ?? "manual",
996
- status: input.checkStatus ?? "pending",
997
- ...input.checkNotes !== void 0 ? { notes: input.checkNotes } : {}
998
- }
999
- ]
1000
- } : {},
1001
- ...input.metricName !== void 0 ? {
1002
- goalMetrics: [
1003
- {
1004
- id: randomUUID(),
1005
- name: input.metricName,
1006
- status: input.metricStatus ?? "pending",
1007
- ...input.metricTarget !== void 0 ? { target: input.metricTarget } : {},
1008
- ...input.metricCurrent !== void 0 ? { current: input.metricCurrent } : {},
1009
- ...input.metricDirection !== void 0 ? { direction: input.metricDirection } : {},
1010
- ...input.metricUnit !== void 0 ? { unit: input.metricUnit } : {},
1011
- ...input.metricNotes !== void 0 ? { notes: input.metricNotes } : {}
1012
- }
1013
- ]
1014
- } : {},
1015
- ...input.url !== void 0 ? {
1016
- links: [
1017
- {
1018
- url: input.url,
1019
- type: input.linkType ?? "url",
1020
- ...input.linkTitle !== void 0 ? { title: input.linkTitle } : {}
1021
- }
1022
- ]
1023
- } : {},
1024
- ...input.note !== void 0 ? {
1025
- notes: [
1026
- {
1027
- id: randomUUID(),
1028
- author: input.author ?? "agent",
1029
- content: input.note,
1030
- createdAt: (/* @__PURE__ */ new Date()).toISOString()
1031
- }
1032
- ]
1033
- } : {},
1034
- ...[input.graphId, input.specId, input.specRequirementId].some((value) => value !== void 0) ? {
1035
- origin: {
1036
- system: input.sourceSystem ?? "kanban-tool",
1037
- ...input.graphId !== void 0 ? { graphId: input.graphId } : {},
1038
- ...input.specId !== void 0 ? { specId: input.specId } : {},
1039
- ...input.specRequirementId !== void 0 ? { specRequirementId: input.specRequirementId } : {},
1040
- ...input.phaseId !== void 0 ? { phaseId: input.phaseId } : {}
1041
- }
1042
- } : {}
1043
- };
1044
- }
1045
- function mergedDependsOn(input) {
1046
- if (input.dependsOn === void 0 && input.dependencyTaskId === void 0) return void 0;
1047
- return [
1048
- ...input.dependsOn ?? [],
1049
- ...input.dependencyTaskId !== void 0 ? [input.dependencyTaskId] : []
1050
- ].filter((id, i, arr) => id && arr.indexOf(id) === i);
1051
- }
1052
- function taskPatch(input) {
1053
- return {
1054
- title: input.title,
1055
- description: input.description,
1056
- dueDate: input.dueDate,
1057
- columnId: input.columnId,
1058
- order: input.order,
1059
- priority: input.priority,
1060
- ...input.taskType !== void 0 ? { type: input.taskType } : {},
1061
- status: input.status,
1062
- labels: input.labels,
1063
- assignedAgent: input.agentId,
1064
- ...mergedDependsOn(input) !== void 0 ? { dependsOn: mergedDependsOn(input) } : {},
1065
- // `atomic` and `childTaskIds` are the composite-parent contract, and the
1066
- // managed gate reads both: an `atomic` parent may not move forward without
1067
- // children, and may not reach Done until every child is completed. The
1068
- // manager has always accepted both on a patch; only this surface withheld
1069
- // them, so `split_atomic` was a one-way door — delete the children and the
1070
- // parent was stranded with no way to declare itself a leaf again.
1071
- ...input.atomic !== void 0 ? { atomic: input.atomic } : {},
1072
- ...input.childTaskIds !== void 0 ? { childTaskIds: input.childTaskIds } : {},
1073
- ...input.estimatedHours !== void 0 ? { estimatedHours: input.estimatedHours } : {},
1074
- ...input.actualHours !== void 0 ? { actualHours: input.actualHours } : {}
1075
- };
1076
- }
1077
- function clampRequestedCapabilities(requested) {
1078
- if (requested === void 0) return void 0;
1079
- return clampSubagentCapabilities(requested).granted;
1080
- }
1081
- function assignmentInput(input) {
1082
- return {
1083
- agentId: input.agentId,
1084
- name: input.name,
1085
- role: input.role,
1086
- provider: input.provider,
1087
- model: input.model,
1088
- fallbackProfile: input.fallbackProfile,
1089
- fallbackModels: input.fallbackModels,
1090
- tools: input.tools,
1091
- allowedCapabilities: clampRequestedCapabilities(input.allowedCapabilities),
1092
- assignee: input.assignee,
1093
- leaseId: input.leaseId,
1094
- claimedAt: input.claimedAt,
1095
- heartbeatAt: input.heartbeatAt,
1096
- leaseExpiresAt: input.leaseExpiresAt,
1097
- attempt: input.attempt,
1098
- maxAttempts: input.maxAttempts,
1099
- costCeilingUsd: input.costCeilingUsd,
1100
- retryPolicy: input.retryPolicy,
1101
- lastFailureKind: input.lastFailureKind
1102
- };
1103
- }
1104
- function hasAssignmentInput(input) {
1105
- return input.agentId !== void 0 || input.name !== void 0 || input.role !== void 0 || input.provider !== void 0 || input.model !== void 0 || input.fallbackProfile !== void 0 || input.fallbackModels !== void 0 || input.tools !== void 0 || input.allowedCapabilities !== void 0 || input.assignee !== void 0 || input.leaseId !== void 0 || input.claimedAt !== void 0 || input.heartbeatAt !== void 0 || input.leaseExpiresAt !== void 0 || input.attempt !== void 0 || input.maxAttempts !== void 0 || input.costCeilingUsd !== void 0 || input.retryPolicy !== void 0 || input.lastFailureKind !== void 0 || input.assignmentStatus !== void 0;
1106
- }
1107
- function assignmentForTaskCreate(input) {
1108
- return {
1109
- status: input.assignmentStatus ?? "assigned",
1110
- ...input.agentId !== void 0 ? { agentId: input.agentId } : {},
1111
- ...input.name !== void 0 ? { name: input.name } : {},
1112
- ...input.role !== void 0 ? { role: input.role } : {},
1113
- ...input.provider !== void 0 ? { provider: input.provider } : {},
1114
- ...input.model !== void 0 ? { model: input.model } : {},
1115
- ...input.fallbackProfile !== void 0 ? { fallbackProfile: input.fallbackProfile } : {},
1116
- ...input.fallbackModels !== void 0 ? { fallbackModels: input.fallbackModels } : {},
1117
- ...input.tools !== void 0 ? { tools: input.tools } : {},
1118
- ...input.allowedCapabilities !== void 0 ? { allowedCapabilities: clampRequestedCapabilities(input.allowedCapabilities) } : {},
1119
- ...input.leaseId !== void 0 ? { leaseId: input.leaseId } : {},
1120
- ...input.claimedAt !== void 0 ? { claimedAt: input.claimedAt } : {},
1121
- ...input.heartbeatAt !== void 0 ? { heartbeatAt: input.heartbeatAt } : {},
1122
- ...input.leaseExpiresAt !== void 0 ? { leaseExpiresAt: input.leaseExpiresAt } : {},
1123
- ...input.attempt !== void 0 ? { attempt: input.attempt } : {},
1124
- ...input.maxAttempts !== void 0 ? { maxAttempts: input.maxAttempts } : {},
1125
- ...input.costCeilingUsd !== void 0 ? { costCeilingUsd: input.costCeilingUsd } : {},
1126
- ...input.retryPolicy !== void 0 ? { retryPolicy: input.retryPolicy } : {},
1127
- ...input.lastFailureKind !== void 0 ? { lastFailureKind: input.lastFailureKind } : {}
1128
- };
1129
- }
1130
-
1131
- // src/kanban-lifecycle-actions.ts
1132
- async function syncContextTask(ctx, task, options = {}) {
1133
- if (!ctx?.state || !task) return;
1134
- try {
1135
- await applySessionKanbanTaskToSource2(ctx, task, options);
1136
- } catch {
1137
- }
1138
- }
1139
- async function handleKanbanLifecycleAction(projectRoot, input, ctx) {
1140
- switch (input.action) {
1141
- case "add_task": {
1142
- if (!input.boardId || !input.title) return fail("add_task requires boardId and title.");
1143
- const result = await addTask2(projectRoot, input.boardId, taskInput(input));
1144
- if (!result) return fail("Board not found.");
1145
- await syncContextTask(ctx, result.task);
1146
- return okTask(result.board, result.task, `Task added.${atomicityNudge(result.task)}`);
1147
- }
1148
- case "split_task": {
1149
- if (!input.boardId || !input.taskId || !input.childTitles?.length) {
1150
- return fail("split_task requires boardId, taskId, and childTitles.");
1151
- }
1152
- return handleSplitTask(projectRoot, input, {});
1153
- }
1154
- case "merge_tasks": {
1155
- if (!input.boardId || !input.taskIds?.length || !input.title) {
1156
- return fail("merge_tasks requires boardId, taskIds, and title.");
1157
- }
1158
- const result = await mergeTasks(projectRoot, input.boardId, {
1159
- taskIds: input.taskIds,
1160
- title: input.title,
1161
- ...input.description !== void 0 ? { description: input.description } : {},
1162
- ...input.targetColumnId !== void 0 ? { targetColumnId: input.targetColumnId } : {},
1163
- ...input.preserveAssignment !== void 0 ? { preserveAssignment: input.preserveAssignment } : {},
1164
- ...input.closeSourceTasks !== void 0 ? { closeSourceTasks: input.closeSourceTasks } : {}
1165
- });
1166
- return result ? okTask(result.board, result.task, "Tasks merged.") : fail("Board or task not found.");
1167
- }
1168
- case "copy_task": {
1169
- if (!input.boardId || !input.taskId || !input.targetBoardId) {
1170
- return fail("copy_task requires boardId, taskId, and targetBoardId.");
1171
- }
1172
- const result = await copyTaskToBoard(
1173
- projectRoot,
1174
- input.boardId,
1175
- input.taskId,
1176
- input.targetBoardId,
1177
- {
1178
- ...input.targetColumnId !== void 0 ? { targetColumnId: input.targetColumnId } : {},
1179
- ...input.order !== void 0 ? { targetOrder: input.order } : {},
1180
- ...input.preserveAssignment !== void 0 ? { preserveAssignment: input.preserveAssignment } : {},
1181
- ...input.preserveDependencies !== void 0 ? { preserveDependencies: input.preserveDependencies } : {}
1182
- }
1183
- );
1184
- return result ? okTask(result.targetBoard, result.task, "Task copied to target board.") : fail("Board or task not found.");
1185
- }
1186
- case "transfer_task": {
1187
- if (!input.boardId || !input.taskId || !input.targetBoardId) {
1188
- return fail("transfer_task requires boardId, taskId, and targetBoardId.");
1189
- }
1190
- const result = await transferTaskToBoard(
1191
- projectRoot,
1192
- input.boardId,
1193
- input.taskId,
1194
- input.targetBoardId,
1195
- {
1196
- ...input.targetColumnId !== void 0 ? { targetColumnId: input.targetColumnId } : {},
1197
- ...input.order !== void 0 ? { targetOrder: input.order } : {},
1198
- ...input.preserveAssignment !== void 0 ? { preserveAssignment: input.preserveAssignment } : {},
1199
- ...input.preserveDependencies !== void 0 ? { preserveDependencies: input.preserveDependencies } : {}
1200
- }
1201
- );
1202
- return result ? okTask(result.targetBoard, result.task, "Task transferred to target board.") : fail("Board or task not found.");
1203
- }
1204
- case "get_task": {
1205
- if (!input.boardId || !input.taskId) return fail("get_task requires boardId and taskId.");
1206
- const task = await getTask(projectRoot, input.boardId, input.taskId);
1207
- return task ? { ok: true, message: "Task loaded.", task } : fail("Task not found.");
1208
- }
1209
- case "start_task": {
1210
- if (!input.boardId || !input.taskId || !input.author || !input.transitionComment) {
1211
- return fail("start_task requires boardId, taskId, author, and transitionComment.");
1212
- }
1213
- let board = await getBoard4(projectRoot, input.boardId);
1214
- let task = board?.tasks.find((candidate) => candidate.id === input.taskId);
1215
- if (!board || !task) return fail("Board or task not found.");
1216
- const readiness = evaluateContractGraphReadiness(board, task.id);
1217
- if (!readiness.ready) {
1218
- return fail(
1219
- `Task is not implementation-ready: ${readiness.issues.map((issue) => issue.message).join(" | ")}`
1220
- );
1221
- }
1222
- if (board.lifecycle?.mode !== "managed") {
1223
- const now = /* @__PURE__ */ new Date();
1224
- const assigned = await updateTaskAssignment(projectRoot, board.id, task.id, {
1225
- status: "running",
1226
- agentId: input.agentId ?? input.author,
1227
- leaseId: input.leaseId ?? randomUUID2(),
1228
- claimedAt: input.claimedAt ?? now.toISOString(),
1229
- heartbeatAt: input.heartbeatAt ?? now.toISOString(),
1230
- leaseExpiresAt: input.leaseExpiresAt ?? new Date(now.getTime() + 15 * 6e4).toISOString(),
1231
- attempt: input.attempt ?? 1,
1232
- maxAttempts: input.maxAttempts ?? 3
1233
- });
1234
- if (!assigned) return fail("Task assignment could not be started.");
1235
- const started = await updateTask2(projectRoot, board.id, task.id, {
1236
- status: "in_progress"
1237
- });
1238
- const current = started ?? assigned;
1239
- const claimed = task;
1240
- const currentTask = current.tasks.find((candidate) => candidate.id === claimed.id) ?? claimed;
1241
- ctx.setCurrentKanbanTask?.(currentTask.id, current.id);
1242
- return okTask(
1243
- current,
1244
- currentTask,
1245
- "Task is active and bound to this run for attribution. This board is not in managed lifecycle mode, so runtime Kanban governance was not bound to it."
1246
- );
1247
- }
1248
- let stage = task.lifecycle?.currentStage;
1249
- if (stage === "backlog") {
1250
- const moved = await transitionTask(projectRoot, board.id, task.id, {
1251
- to: "todo",
1252
- actor: input.author,
1253
- comment: input.transitionComment
1254
- });
1255
- if (!moved) return fail("Task could not enter Todo.");
1256
- board = moved.board;
1257
- task = moved.task;
1258
- stage = task.lifecycle?.currentStage;
1259
- }
1260
- if (stage === "todo" || stage === "review") {
1261
- const now = /* @__PURE__ */ new Date();
1262
- const leaseId = input.leaseId ?? randomUUID2();
1263
- const assigned = await updateTaskAssignment(projectRoot, board.id, task.id, {
1264
- status: "running",
1265
- agentId: input.agentId ?? input.author,
1266
- leaseId,
1267
- claimedAt: input.claimedAt ?? now.toISOString(),
1268
- heartbeatAt: input.heartbeatAt ?? now.toISOString(),
1269
- leaseExpiresAt: input.leaseExpiresAt ?? new Date(now.getTime() + 15 * 6e4).toISOString(),
1270
- attempt: input.attempt ?? 1,
1271
- maxAttempts: input.maxAttempts ?? 3
1272
- });
1273
- if (!assigned) return fail("Task assignment could not be started.");
1274
- const moved = await transitionTask(projectRoot, board.id, task.id, {
1275
- to: "running",
1276
- actor: input.author,
1277
- comment: input.transitionComment
1278
- });
1279
- if (!moved) return fail("Task could not enter Running.");
1280
- board = moved.board;
1281
- task = moved.task;
1282
- stage = task.lifecycle?.currentStage;
1283
- }
1284
- if (stage !== "running" || task.assignment?.status !== "running") {
1285
- return fail(
1286
- `start_task only accepts Backlog, Todo, Review repair, or live Running cards (current: ${stage ?? "unknown"}).`
1287
- );
1288
- }
1289
- ctx.setCurrentKanbanTask(task.id, board.id);
1290
- await syncContextTask(ctx, task);
1291
- return okTask(
1292
- board,
1293
- task,
1294
- "Task is active; runtime Kanban governance is now bound to this run."
1295
- );
1296
- }
1297
- case "update_task": {
1298
- if (!input.boardId || !input.taskId) return fail("update_task requires boardId and taskId.");
1299
- const board = await updateTask2(projectRoot, input.boardId, input.taskId, taskPatch(input));
1300
- if (board) {
1301
- await syncContextTask(ctx, board.tasks.find((t) => t.id === input.taskId));
1302
- }
1303
- return board ? okBoard(board, "Task updated.") : fail("Task not found.");
1304
- }
1305
- case "transition_task": {
1306
- if (!input.boardId || !input.taskId || !input.lifecycleStage || !input.author || !input.transitionComment) {
1307
- return fail(
1308
- "transition_task requires boardId, taskId, lifecycleStage, author, and transitionComment."
1309
- );
1310
- }
1311
- if (input.lifecycleStage === "done") {
1312
- const boardBefore = await getBoard4(projectRoot, input.boardId);
1313
- const taskBefore = boardBefore ? await getTask(projectRoot, input.boardId, input.taskId) : null;
1314
- if (boardBefore && taskBefore && !taskBefore.verificationReport && (taskBefore.atomic || Boolean(taskBefore.successCriteria?.length))) {
1315
- const preGate = await verifyTaskCompletion2(projectRoot, input.boardId, taskBefore.id, {
1316
- persist: false
1317
- });
1318
- await updateTask2(projectRoot, input.boardId, taskBefore.id, {
1319
- verificationReport: preGate.report,
1320
- successCriteria: preGate.task.successCriteria
1321
- });
1322
- }
1323
- }
1324
- const result = await transitionTask(projectRoot, input.boardId, input.taskId, {
1325
- to: input.lifecycleStage,
1326
- actor: input.author,
1327
- comment: input.transitionComment,
1328
- ...input.transitionAction !== void 0 ? { action: input.transitionAction } : {},
1329
- ...input.tickChecks !== void 0 ? { tickChecks: input.tickChecks } : {},
1330
- ...input.attachmentUrl !== void 0 ? {
1331
- attachment: {
1332
- url: input.attachmentUrl,
1333
- type: input.attachmentType ?? "url",
1334
- ...input.attachmentTitle !== void 0 ? { title: input.attachmentTitle } : {}
1335
- }
1336
- } : {},
1337
- patch: taskPatch(input)
1338
- });
1339
- if (result && input.lifecycleStage === "done" && result.task.verificationReport) {
1340
- recordKanbanVerificationEvidence(ctx, result.task.verificationReport);
1341
- }
1342
- if (result?.task) {
1343
- await syncContextTask(ctx, result.task);
1344
- }
1345
- return result ? okTask(result.board, result.task, `Task advanced to ${result.transition.to}.`) : fail("Board or task not found.");
1346
- }
1347
- case "repair_managed_projection": {
1348
- if (!input.boardId || !input.taskId || !input.author || !input.transitionComment) {
1349
- return fail(
1350
- "repair_managed_projection requires boardId, taskId, author, and transitionComment."
1351
- );
1352
- }
1353
- const result = await repairManagedTaskProjection(projectRoot, input.boardId, input.taskId, {
1354
- actor: input.author,
1355
- comment: input.transitionComment
1356
- });
1357
- if (result?.task) {
1358
- await syncContextTask(ctx, result.task);
1359
- }
1360
- return result ? okTask(
1361
- result.board,
1362
- result.task,
1363
- "Managed card projection repaired from lifecycle history."
1364
- ) : fail("Board or task not found.");
1365
- }
1366
- case "move_task": {
1367
- if (!input.boardId || !input.taskId || !input.targetColumnId) {
1368
- return fail("move_task requires boardId, taskId, and targetColumnId.");
1369
- }
1370
- const board = await moveTask(
1371
- projectRoot,
1372
- input.boardId,
1373
- input.taskId,
1374
- input.targetColumnId,
1375
- input.order
1376
- );
1377
- if (board) {
1378
- await syncContextTask(ctx, board.tasks.find((t) => t.id === input.taskId));
1379
- }
1380
- return board ? okBoard(board, "Task moved.") : fail("Move failed.");
1381
- }
1382
- case "delete_task": {
1383
- if (!input.boardId || !input.taskId) return fail("delete_task requires boardId and taskId.");
1384
- const boardBefore = await getBoard4(projectRoot, input.boardId);
1385
- const taskToDelete = boardBefore?.tasks.find((t) => t.id === input.taskId);
1386
- const board = await removeTask(projectRoot, input.boardId, input.taskId);
1387
- if (board && ctx.currentKanbanTaskId === input.taskId) {
1388
- ctx.setCurrentKanbanTask?.(void 0, ctx.currentKanbanBoardId);
1389
- }
1390
- if (board && taskToDelete) {
1391
- await syncContextTask(ctx, taskToDelete, { remove: true });
1392
- }
1393
- return board ? okBoard(board, "Task deleted.") : fail("Task not found.");
1394
- }
1395
- case "set_chain": {
1396
- if (!input.boardId || !input.taskIds?.length) {
1397
- return fail("set_chain requires boardId and taskIds.");
1398
- }
1399
- const result = await setTaskChain(projectRoot, input.boardId, {
1400
- taskIds: input.taskIds,
1401
- ...input.chainId !== void 0 ? { chainId: input.chainId } : {},
1402
- ...input.enforceDependencies !== void 0 ? { enforceDependencies: input.enforceDependencies } : {}
1403
- });
1404
- return result ? {
1405
- ok: true,
1406
- message: `Chain set: ${result.chainId}`,
1407
- board: result.board,
1408
- chain: result.tasks
1409
- } : fail("Board or task not found.");
1410
- }
1411
- case "get_chain": {
1412
- if (!input.boardId || !(input.taskId || input.chainId)) {
1413
- return fail("get_chain requires boardId and taskId or chainId.");
1414
- }
1415
- const result = await getTaskChain(
1416
- projectRoot,
1417
- input.boardId,
1418
- input.taskId ?? input.chainId ?? ""
1419
- );
1420
- return result ? {
1421
- ok: true,
1422
- message: `Chain loaded: ${result.chainId}`,
1423
- board: result.board,
1424
- chain: result.tasks
1425
- } : fail("Chain not found.");
1426
- }
1427
- case "claim_task": {
1428
- const result = await claimReadyTask(projectRoot, {
1429
- ...input.boardId !== void 0 ? { boardId: input.boardId } : {},
1430
- ...input.taskId !== void 0 ? { taskId: input.taskId } : {},
1431
- ...assignmentInput(input),
1432
- status: input.assignmentStatus ?? "queued"
1433
- });
1434
- return result ? okTask(result.board, result.task, "Task claimed.") : fail("No ready kanban task matched the claim.");
1435
- }
1436
- case "release_task": {
1437
- if (!input.boardId || !input.taskId) {
1438
- return fail("release_task requires boardId and taskId.");
1439
- }
1440
- const board = await releaseTaskClaim(projectRoot, input.boardId, input.taskId, {
1441
- ...input.releaseStatus !== void 0 ? { status: input.releaseStatus } : {},
1442
- ...input.releaseReason !== void 0 ? { reason: input.releaseReason } : {},
1443
- ...input.clearAssignee !== void 0 ? { clearAssignee: input.clearAssignee } : {}
1444
- });
1445
- return board ? okBoard(board, "Task claim released.") : fail("Task not found.");
1446
- }
1447
- case "assign_task": {
1448
- if (!input.boardId || !input.taskId) return fail("assign_task requires boardId and taskId.");
1449
- const board = await assignTask(
1450
- projectRoot,
1451
- input.boardId,
1452
- input.taskId,
1453
- assignmentInput(input)
1454
- );
1455
- return board ? okBoard(board, "Task assigned.") : fail("Task not found.");
1456
- }
1457
- case "mark_assignment": {
1458
- if (!input.boardId || !input.taskId)
1459
- return fail("mark_assignment requires boardId and taskId.");
1460
- const assignmentStatus = input.assignmentStatus ?? (input.status === "completed" ? "completed" : input.error ? "failed" : void 0);
1461
- const board = await updateTaskAssignment(
1462
- projectRoot,
1463
- input.boardId,
1464
- input.taskId,
1465
- {
1466
- ...assignmentStatus !== void 0 ? { status: assignmentStatus } : {},
1467
- ...input.subagentId !== void 0 ? { subagentId: input.subagentId } : {},
1468
- ...input.runTaskId !== void 0 ? { runTaskId: input.runTaskId } : {},
1469
- ...input.lastResult !== void 0 ? { lastResult: input.lastResult } : {},
1470
- ...input.error !== void 0 ? { error: input.error } : {},
1471
- ...input.agentId !== void 0 ? { agentId: input.agentId } : {},
1472
- ...input.leaseId !== void 0 ? { leaseId: input.leaseId } : {},
1473
- ...input.claimedAt !== void 0 ? { claimedAt: input.claimedAt } : {},
1474
- ...input.heartbeatAt !== void 0 ? { heartbeatAt: input.heartbeatAt } : {},
1475
- ...input.leaseExpiresAt !== void 0 ? { leaseExpiresAt: input.leaseExpiresAt } : {},
1476
- ...input.attempt !== void 0 ? { attempt: input.attempt } : {},
1477
- ...input.maxAttempts !== void 0 ? { maxAttempts: input.maxAttempts } : {}
1478
- },
1479
- input.expectedLeaseId !== void 0 ? { expectedLeaseId: input.expectedLeaseId } : {}
1480
- );
1481
- if (!board) return fail("Task not found.");
1482
- if (assignmentStatus === "completed" && board.lifecycle?.mode !== "managed") {
1483
- const envGate = readEnvGateEnforcement();
1484
- const finalized = await finalizeTaskCompletion(projectRoot, board.id, input.taskId, {
1485
- ...board.completionGate === void 0 && envGate !== void 0 ? { enforcement: envGate } : {},
1486
- ...ctx.agentId !== void 0 ? { eventContext: { actor: ctx.agentId } } : {}
1487
- });
1488
- if (finalized) {
1489
- if (finalized.gate.report) {
1490
- recordKanbanVerificationEvidence(ctx, finalized.gate.report);
1491
- }
1492
- const gateSummary = {
1493
- enforcement: finalized.gate.enforcement,
1494
- allowed: finalized.gate.allowed,
1495
- verdict: finalized.gate.verdict,
1496
- issues: finalized.gate.issues.map((issue) => issue.message)
1497
- };
1498
- const gateMessage = finalized.gate.allowed ? `Completion gate ${finalized.gate.verdict === "skipped" ? "passed" : "passed"}; task completed.` : finalized.gate.enforcement === "strict" ? `Completion gate BLOCKED (verdict: ${finalized.gate.verdict}); task parked in review. Issues: ${gateSummary.issues.join(" | ")}` : `Completion gate failed softly (verdict: ${finalized.gate.verdict}); task completed with warnings. Issues: ${gateSummary.issues.join(" | ")}`;
1499
- await syncContextTask(ctx, finalized.task);
1500
- return {
1501
- ...okTask(finalized.board, finalized.task, `Assignment updated. ${gateMessage}`),
1502
- gate: gateSummary
1503
- };
1504
- }
1505
- } else if (board.lifecycle?.mode === "managed") {
1506
- const managedTask = board.tasks.find((candidate) => candidate.id === input.taskId);
1507
- const stage = managedTask?.lifecycle?.currentStage;
1508
- const actor = ctx.agentId ?? "kanban-agent";
1509
- let transitionResult = null;
1510
- const lifecycleWarnings = [];
1511
- if (assignmentStatus === "running" && stage === "todo") {
1512
- try {
1513
- transitionResult = await transitionTask(projectRoot, board.id, input.taskId, {
1514
- to: "running",
1515
- actor,
1516
- comment: "Work started."
1517
- });
1518
- } catch (err) {
1519
- lifecycleWarnings.push(
1520
- `Lifecycle transition to Running deferred: ${stripLifecycleIssues(err instanceof Error ? err.message : String(err))}`
1521
- );
1522
- }
1523
- }
1524
- if (assignmentStatus === "completed" && stage === "running") {
1525
- const comment = typeof input.lastResult === "string" && input.lastResult.trim().length > 0 ? input.lastResult.trim().slice(0, 1e3) : "Work completed.";
1526
- try {
1527
- transitionResult = await transitionTask(projectRoot, board.id, input.taskId, {
1528
- to: "review",
1529
- actor,
1530
- comment,
1531
- attachment: {
1532
- url: `kanban://task/${input.taskId}/result`,
1533
- title: "Worker completion result",
1534
- type: "file"
1535
- },
1536
- patch: {
1537
- ...input.agentId !== void 0 ? { assignedAgent: input.agentId } : {}
1538
- }
1539
- });
1540
- } catch (err) {
1541
- lifecycleWarnings.push(
1542
- `Lifecycle transition to Review failed: ${stripLifecycleIssues(err instanceof Error ? err.message : String(err))}`
1543
- );
1544
- }
1545
- if (transitionResult) {
1546
- const hasCriteria = (transitionResult.task.successCriteria?.length ?? 0) > 0 || transitionResult.task.atomic === true;
1547
- if (hasCriteria) {
1548
- try {
1549
- const verResult = await verifyTaskCompletion2(projectRoot, board.id, input.taskId);
1550
- if (verResult.report) {
1551
- recordKanbanVerificationEvidence(ctx, verResult.report);
1552
- }
1553
- await updateTask2(projectRoot, board.id, input.taskId, {
1554
- verificationReport: verResult.report,
1555
- successCriteria: verResult.task.successCriteria
1556
- });
1557
- const verdict = verResult.report.verdict;
1558
- if (verdict === "passed" && !resolveAutoAccept(board)) {
1559
- lifecycleWarnings.push(
1560
- "Verification passed, but this board does not auto-accept. The card is in Review awaiting an explicit transition_task to done."
1561
- );
1562
- } else if (verdict === "passed") {
1563
- try {
1564
- const doneResult = await transitionTask(projectRoot, board.id, input.taskId, {
1565
- to: "done",
1566
- actor,
1567
- action: "Automated acceptance after verification",
1568
- comment: "Auto-accepted: verification passed.",
1569
- attachment: {
1570
- url: `kanban://task/${input.taskId}/verification`,
1571
- title: "Auto-verification result",
1572
- type: "file"
1573
- }
1574
- });
1575
- transitionResult = doneResult;
1576
- } catch (acceptErr) {
1577
- lifecycleWarnings.push(
1578
- `Auto-accept to Done deferred: ${acceptErr instanceof Error ? acceptErr.message : String(acceptErr)}`
1579
- );
1580
- }
1581
- } else {
1582
- lifecycleWarnings.push(
1583
- `Verification verdict: ${verdict} \u2014 card left in Review for manual acceptance.`
1584
- );
1585
- }
1586
- } catch (verifyErr) {
1587
- lifecycleWarnings.push(
1588
- `Auto-verification error: ${verifyErr instanceof Error ? verifyErr.message : String(verifyErr)}`
1589
- );
1590
- }
1591
- } else {
1592
- lifecycleWarnings.push(
1593
- "No automatic success criteria \u2014 card left in Review for manual verification."
1594
- );
1595
- }
1596
- }
1597
- }
1598
- const responseBoard = transitionResult?.board ?? board;
1599
- const responseTask = transitionResult?.task ?? managedTask;
1600
- const msgParts = ["Assignment updated."];
1601
- if (transitionResult) {
1602
- msgParts.push(`Card advanced to ${transitionResult.transition.to}.`);
1603
- }
1604
- for (const w of lifecycleWarnings) msgParts.push(`Warning: ${w}`);
1605
- await syncContextTask(ctx, responseTask);
1606
- return okTask(responseBoard, responseTask, msgParts.join(" "));
1607
- }
1608
- return okBoard(board, "Assignment updated.");
1609
- }
1610
- case "heartbeat_assignment": {
1611
- if (!input.boardId || !input.taskId) {
1612
- return fail("heartbeat_assignment requires boardId and taskId.");
1613
- }
1614
- const board = await heartbeatTaskAssignment(projectRoot, input.boardId, input.taskId, {
1615
- ...input.heartbeatAt !== void 0 ? { heartbeatAt: input.heartbeatAt } : {},
1616
- ...input.leaseExpiresAt !== void 0 ? { leaseExpiresAt: input.leaseExpiresAt } : {},
1617
- ...input.expectedLeaseId !== void 0 ? { expectedLeaseId: input.expectedLeaseId } : {}
1618
- });
1619
- return board ? okBoard(board, "Assignment heartbeat updated.") : fail("Task assignment not found.");
1620
- }
1621
- case "recover_stale": {
1622
- if (!input.boardId) return fail("recover_stale requires boardId.");
1623
- const policyFields = [
1624
- input.recoveryPolicyFailOnCostCeiling !== void 0,
1625
- input.recoveryPolicyReleaseOnFailureKinds !== void 0,
1626
- input.recoveryPolicyReleaseOnHeartbeatDue !== void 0,
1627
- input.recoveryPolicyRetryPolicyOverride !== void 0
1628
- ].some(Boolean);
1629
- const result = await recoverStaleTaskAssignments(projectRoot, input.boardId, {
1630
- ...input.recoveryMode !== void 0 ? { mode: input.recoveryMode } : {},
1631
- ...input.recoveryNow !== void 0 ? { now: input.recoveryNow } : {},
1632
- ...input.releaseReason !== void 0 ? { reason: input.releaseReason } : {},
1633
- ...input.clearAssignee !== void 0 ? { clearAssignee: input.clearAssignee } : {},
1634
- ...policyFields ? {
1635
- policy: {
1636
- ...input.recoveryPolicyFailOnCostCeiling !== void 0 ? { failWhenCostCeilingSet: input.recoveryPolicyFailOnCostCeiling } : {},
1637
- ...input.recoveryPolicyReleaseOnFailureKinds !== void 0 ? {
1638
- releaseOnFailureKinds: input.recoveryPolicyReleaseOnFailureKinds
1639
- } : {},
1640
- ...input.recoveryPolicyReleaseOnHeartbeatDue !== void 0 ? {
1641
- releaseOnHeartbeatDue: input.recoveryPolicyReleaseOnHeartbeatDue
1642
- } : {},
1643
- ...input.recoveryPolicyRetryPolicyOverride !== void 0 ? {
1644
- retryPolicyOverride: input.recoveryPolicyRetryPolicyOverride
1645
- } : {}
1646
- }
1647
- } : {}
1648
- });
1649
- return result ? {
1650
- ok: true,
1651
- message: `Recovered ${result.tasks.length} stale assignment(s).`,
1652
- board: result.board,
1653
- recoveredTasks: result.tasks
1654
- } : { ok: true, message: "No stale assignment matched.", recoveredTasks: [] };
1655
- }
1656
- default:
1657
- return void 0;
1658
- }
1659
- }
1660
-
1661
- // src/kanban-presence.ts
1662
- import { touchKanbanPresence as touchKanbanPresence2 } from "@wrongstack/kanban";
1663
- function createKanbanPresenceWrapper(projectRoot, input, ctx) {
1664
- return async (result) => {
1665
- const boardId = result.board?.id ?? input.boardId;
1666
- if (!result.ok || !boardId || !ctx.session?.id || !ctx.agentId) return result;
1667
- try {
1668
- const board = await touchKanbanPresence2(projectRoot, boardId, {
1669
- sessionId: ctx.session.id,
1670
- agentId: ctx.agentId,
1671
- agentName: ctx.agentName,
1672
- taskId: input.taskId ?? result.task?.id,
1673
- runTaskId: input.runTaskId
1674
- });
1675
- return board ? { ...result, board } : result;
1676
- } catch {
1677
- return result;
1678
- }
1679
- };
1680
- }
1681
-
1682
- // src/kanban-serializer.ts
1683
- var KANBAN_BOARD_TRANSCRIPT_BYTE_CAP = 16384;
1684
- var KANBAN_FULL_BOARD_ACTIONS = /* @__PURE__ */ new Set([
1685
- "get_board",
1686
- "export_markdown",
1687
- "export_task_graph"
1688
- ]);
1689
- function serializeKanbanOutput(output, input) {
1690
- const action = input && typeof input === "object" ? input.action : void 0;
1691
- const board = output.board;
1692
- if (board) {
1693
- const keepFull = typeof action === "string" && KANBAN_FULL_BOARD_ACTIONS.has(action);
1694
- let boardBytes = 0;
1695
- if (!keepFull) {
1696
- try {
1697
- boardBytes = Buffer.byteLength(JSON.stringify(board), "utf8");
1698
- } catch {
1699
- boardBytes = 0;
1700
- }
1701
- }
1702
- if (!keepFull && boardBytes > KANBAN_BOARD_TRANSCRIPT_BYTE_CAP) {
1703
- const columns = {};
1704
- for (const column of board.columns) {
1705
- columns[column.title || column.id] = board.tasks.filter(
1706
- (task) => task.columnId === column.id
1707
- ).length;
1708
- }
1709
- const compact = {
1710
- ...output,
1711
- board: {
1712
- id: board.id,
1713
- title: board.title,
1714
- columns,
1715
- totalTasks: board.tasks.length,
1716
- note: `Full board (${boardBytes} bytes) omitted from the transcript; use get_board to load it.`
1717
- }
1718
- };
1719
- return JSON.stringify(compact, null, 2);
1720
- }
1721
- }
1722
- return JSON.stringify(output, null, 2);
1723
- }
1724
-
1725
- // src/kanban-tool-schema.ts
1726
- var KANBAN_TOOL_DESCRIPTION = "Durable project task boards: create and move cards, record checks, notes, links and assignments. The board is a record of the work, not a permit for it \u2014 nothing here gates other tools. Managed boards additionally enforce ordered Backlog \u2192 Todo \u2192 Running \u2192 Review \u2192 Done transitions; release_managed_lifecycle turns that off.";
1727
- var KANBAN_TOOL_USAGE_HINT = 'Track substantial or multi-step work so it survives the session; a trivial edit or a question needs no card. Work stays on ONE board: call list_boards first and add_task to the board this project already uses. create_board is for a genuinely separate line of work, not for each new piece of it \u2014 a second board splits the same effort in two, and a board holding a single card is the usual sign. Common flow: list_boards or search_tasks to orient, add_task to record work, start_task when you begin, update_check with checkStatus "passed" to tick acceptance criteria (read their ids from get_task), then transition_task. On a managed board a refused transition names the field it wants \u2014 supply it and retry. When the acceptance criterion is something a machine can run, say so: set checkType ("command", "test", "file_exists", "file_matches", "git_diff", "metric") and put the command, pattern or path in checkNotes, then verify_completion executes it and the result is real evidence. Leave checkType off (or "manual") only for criteria that genuinely need a human eye \u2014 a manual check records your assertion, it does not test anything. Goal metrics pass when current >= target by default; when lower is better (error rate, cost ceiling, latency, open-bug count), pass metricDirection "at_most" with add_goal_metric / update_goal_metric so verification compares current <= target instead.';
1728
- var KANBAN_INPUT_SCHEMA = {
1729
- type: "object",
1730
- properties: {
1731
- action: {
1732
- type: "string",
1733
- enum: [
1734
- "list_boards",
1735
- "get_board",
1736
- "create_board",
1737
- "duplicate_board",
1738
- "update_board",
1739
- "adopt_managed_lifecycle",
1740
- "release_managed_lifecycle",
1741
- "delete_board",
1742
- "generate_board",
1743
- "export_markdown",
1744
- "export_task_graph",
1745
- "sync_task_graph",
1746
- "create_from_graph",
1747
- "import_session_tasks",
1748
- "search_tasks",
1749
- "ready_tasks",
1750
- "snapshot",
1751
- "workbench",
1752
- "add_task",
1753
- "split_task",
1754
- "merge_tasks",
1755
- "copy_task",
1756
- "transfer_task",
1757
- "get_task",
1758
- "start_task",
1759
- "update_task",
1760
- "transition_task",
1761
- "repair_managed_projection",
1762
- "move_task",
1763
- "delete_task",
1764
- "set_chain",
1765
- "get_chain",
1766
- "claim_task",
1767
- "release_task",
1768
- "assign_task",
1769
- "mark_assignment",
1770
- "heartbeat_assignment",
1771
- "recover_stale",
1772
- "events",
1773
- "queue_health",
1774
- "add_dependency",
1775
- "add_goal_metric",
1776
- "update_goal_metric",
1777
- "add_check",
1778
- "update_check",
1779
- "remove_check",
1780
- "add_note",
1781
- "add_link",
1782
- "verify_completion",
1783
- "split_atomic",
1784
- "assess_atomicity",
1785
- "propose_decomposition",
1786
- "get_contract_graph",
1787
- "configure_contract_graph",
1788
- "upsert_contract_node",
1789
- "remove_contract_node",
1790
- "add_contract_edge",
1791
- "remove_contract_edge"
1792
- ]
1793
- },
1794
- boardId: { type: "string" },
1795
- taskId: { type: "string" },
1796
- taskIds: { type: "array", items: { type: "string" } },
1797
- chainId: { type: "string" },
1798
- fromNodeId: { type: "string" },
1799
- toNodeId: { type: "string" },
1800
- baseline: { oneOf: [{ type: "string" }, { type: "number" }] },
1801
- threshold: { oneOf: [{ type: "string" }, { type: "number" }] },
1802
- columnId: { type: "string" },
1803
- targetBoardId: { type: "string" },
1804
- targetColumnId: { type: "string" },
1805
- title: { type: "string" },
1806
- description: { type: "string" },
1807
- dueDate: { type: "string" },
1808
- tags: { type: "array", items: { type: "string" } },
1809
- labels: { type: "array", items: { type: "string" } },
1810
- priority: { type: "string", enum: ["critical", "high", "medium", "low"] },
1811
- taskType: {
1812
- type: "string",
1813
- enum: ["feature", "bugfix", "refactor", "docs", "test", "chore"]
1814
- },
1815
- status: {
1816
- type: "string",
1817
- enum: [
1818
- "pending",
1819
- "ready",
1820
- "in_progress",
1821
- "blocked",
1822
- "review",
1823
- "completed",
1824
- "failed",
1825
- "archived"
1826
- ]
1827
- },
1828
- order: { type: "number" },
1829
- query: { type: "string" },
1830
- limit: { type: "number" },
1831
- agentId: { type: "string" },
1832
- name: { type: "string" },
1833
- role: { type: "string" },
1834
- provider: { type: "string" },
1835
- model: { type: "string" },
1836
- fallbackProfile: { type: "string" },
1837
- fallbackModels: { type: "array", items: { type: "string" } },
1838
- tools: { type: "array", items: { type: "string" } },
1839
- allowedCapabilities: { type: "array", items: { type: "string" } },
1840
- leaseId: { type: "string" },
1841
- claimedAt: { type: "string" },
1842
- heartbeatAt: { type: "string" },
1843
- leaseExpiresAt: { type: "string" },
1844
- attempt: { type: "number" },
1845
- maxAttempts: { type: "number" },
1846
- subagentId: { type: "string" },
1847
- runTaskId: { type: "string" },
1848
- lastResult: { type: "string" },
1849
- error: { type: "string" },
1850
- expectedLeaseId: { type: "string" },
1851
- assignmentStatus: {
1852
- type: "string",
1853
- enum: ["assigned", "queued", "running", "completed", "failed", "cancelled"]
1854
- },
1855
- lifecycleStage: {
1856
- type: "string",
1857
- enum: ["backlog", "todo", "running", "review", "done"]
1858
- },
1859
- transitionAction: { type: "string" },
1860
- transitionComment: { type: "string" },
1861
- tickChecks: {
1862
- type: "array",
1863
- items: {
1864
- type: "object",
1865
- properties: {
1866
- checkId: { type: "string" },
1867
- checkStatus: { type: "string", enum: ["passed", "failed", "skipped"] }
1868
- },
1869
- required: ["checkId", "checkStatus"]
1870
- },
1871
- description: "`transition_task` (to=done only): flip one or more manual criteria to `passed` before the gate fires. Read ids from kanban get_task. Non-manual criteria are refused."
1872
- },
1873
- attachmentUrl: { type: "string" },
1874
- attachmentTitle: { type: "string" },
1875
- attachmentType: {
1876
- type: "string",
1877
- enum: ["issue", "pr", "doc", "commit", "design", "file", "url", "other"]
1878
- },
1879
- releaseStatus: { type: "string", enum: ["pending", "ready", "blocked"] },
1880
- releaseReason: { type: "string" },
1881
- clearAssignee: { type: "boolean" },
1882
- recoveryMode: { type: "string", enum: ["auto", "release", "retry", "fail"] },
1883
- recoveryNow: { type: "string" },
1884
- recoveryPolicyFailOnCostCeiling: { type: "boolean" },
1885
- recoveryPolicyReleaseOnFailureKinds: { type: "array", items: { type: "string" } },
1886
- recoveryPolicyReleaseOnHeartbeatDue: { type: "boolean" },
1887
- recoveryPolicyRetryPolicyOverride: {
1888
- type: "string",
1889
- enum: ["off", "incremental", "exponential"]
1890
- },
1891
- assignee: { type: "string" },
1892
- costCeilingUsd: { type: "number" },
1893
- retryPolicy: { type: "string", enum: ["off", "incremental", "exponential"] },
1894
- lastFailureKind: { type: "string" },
1895
- dependsOn: {
1896
- type: "array",
1897
- items: { type: "string" },
1898
- description: "Task ids this card waits on. On update_task an explicit empty array clears them \u2014 use it when a dependency was recorded in error rather than completing work nobody wants."
1899
- },
1900
- atomic: {
1901
- type: "boolean",
1902
- description: "Composite parent (true) or executable leaf (false). Set false to make a stranded parent a leaf again after its children were dropped."
1903
- },
1904
- childTaskIds: {
1905
- type: "array",
1906
- items: { type: "string" },
1907
- description: "Children of a composite parent. On update_task an explicit empty array detaches them all."
1908
- },
1909
- estimatedHours: { type: "number" },
1910
- actualHours: { type: "number" },
1911
- taskGraph: { type: "object" },
1912
- graphId: { type: "string" },
1913
- specId: { type: "string" },
1914
- specRequirementId: { type: "string" },
1915
- sourceSystem: { type: "string" },
1916
- phaseId: { type: "string" },
1917
- preserveOriginTaskIds: { type: "boolean" },
1918
- includeArchived: { type: "boolean" },
1919
- archiveMissingTasks: { type: "boolean" },
1920
- preserveManualDependencies: { type: "boolean" },
1921
- dependencyTaskId: { type: "string" },
1922
- enforceDependencies: { type: "boolean" },
1923
- childTitles: { type: "array", items: { type: "string" } },
1924
- inheritAssignment: { type: "boolean" },
1925
- inheritLabels: { type: "boolean" },
1926
- inheritSuccessCriteria: { type: "boolean" },
1927
- inheritGoalMetrics: { type: "boolean" },
1928
- inheritDependencies: { type: "boolean" },
1929
- chainChildren: { type: "boolean" },
1930
- rewireDependents: { type: "boolean" },
1931
- closeSourceTasks: { type: "boolean" },
1932
- metricId: { type: "string" },
1933
- metricName: { type: "string" },
1934
- metricTarget: { oneOf: [{ type: "string" }, { type: "number" }] },
1935
- metricCurrent: { oneOf: [{ type: "string" }, { type: "number" }] },
1936
- metricDirection: { type: "string", enum: ["at_least", "at_most"] },
1937
- metricUnit: { type: "string" },
1938
- metricStatus: { type: "string", enum: ["pending", "met", "missed", "waived"] },
1939
- metricNotes: { type: "string" },
1940
- checkId: { type: "string" },
1941
- checkDescription: { type: "string" },
1942
- checkStatus: { type: "string", enum: ["pending", "passed", "failed", "skipped"] },
1943
- checkType: {
1944
- type: "string",
1945
- // Only types a verifier can actually execute. `manual` is the default and
1946
- // means a human or agent asserts the status by hand. The rest are run by
1947
- // `verify_completion` against the default deterministic registry. Types
1948
- // with no plugin in that registry (`auto`, `review`, `agent`, `council`)
1949
- // are deliberately omitted: offering them would produce criteria that
1950
- // silently report `skipped — no verifier plugin registered`.
1951
- enum: ["manual", "command", "test", "file_exists", "file_matches", "git_diff", "metric"],
1952
- description: 'How this acceptance criterion is verified. Default "manual" (status set by hand). Any other value makes verify_completion execute it, so the criterion becomes real evidence rather than a self-assertion. Pair with checkNotes.'
1953
- },
1954
- checkNotes: {
1955
- type: "string",
1956
- description: 'The executable body for a non-manual checkType, read in preference to checkDescription. command/test: the shell command or test pattern. file_exists: the path. file_matches: JSON {"file","pattern","flags"}. git_diff: JSON {"expectedFiles","minChanges","maxChanges"}.'
1957
- },
1958
- // ── Contract map ───────────────────────────────────────────────────
1959
- // The card contract: what this work targets, what it must not break, what
1960
- // it risks, and what verifies it. Advisory by default — the readiness gate
1961
- // deliberately does not require map structure, so a map is an operator
1962
- // review aid, not work the model must complete before implementing.
1963
- contractEnforcement: {
1964
- type: "string",
1965
- enum: ["off", "advisory", "strict"],
1966
- description: "Board-level contract map enforcement. Default when first configured: advisory."
1967
- },
1968
- contractNodeId: { type: "string" },
1969
- contractNodeKind: {
1970
- type: "string",
1971
- enum: ["objective", "guardrail", "risk", "component", "artifact", "verification"],
1972
- description: "objective = what this card is for; guardrail = what must keep working; risk = what could go wrong; component/artifact = what it touches; verification = what settles it."
1973
- },
1974
- contractNodeTitle: { type: "string" },
1975
- contractNodeDescription: { type: "string" },
1976
- contractNodeState: {
1977
- type: "string",
1978
- enum: ["unknown", "active", "satisfied", "violated", "waived", "resolved"]
1979
- },
1980
- contractNodeEnforcement: {
1981
- type: "string",
1982
- enum: ["blocking", "advisory", "informational"]
1983
- },
1984
- /** Bind a node to an acceptance criterion or goal metric already on the task. */
1985
- contractCheckId: { type: "string" },
1986
- contractMetricId: { type: "string" },
1987
- contractWaiverReason: {
1988
- type: "string",
1989
- description: 'Required, with an actor, when contractNodeState is "waived".'
1990
- },
1991
- contractEdgeId: { type: "string" },
1992
- contractEdgeFrom: {
1993
- type: "string",
1994
- description: 'A contract node id, or a task id (bare or "task:<id>") for the card endpoint.'
1995
- },
1996
- contractEdgeTo: { type: "string" },
1997
- contractEdgeType: {
1998
- type: "string",
1999
- enum: [
2000
- "targets",
2001
- "affects",
2002
- "must_preserve",
2003
- "exposes",
2004
- "verified_by",
2005
- "conflicts_with",
2006
- "derived_from",
2007
- "relates_to"
2008
- ]
2009
- },
2010
- contractEdgeRationale: { type: "string" },
2011
- note: { type: "string" },
2012
- author: { type: "string" },
2013
- url: { type: "string" },
2014
- linkTitle: { type: "string" },
2015
- linkType: {
2016
- type: "string",
2017
- enum: ["issue", "pr", "doc", "commit", "design", "file", "url", "other"]
2018
- },
2019
- context: { type: "string" },
2020
- columns: { type: "array", items: { type: "string" } },
2021
- generatedBy: { type: "string" },
2022
- includeTasks: { type: "boolean" },
2023
- includeCompletedTasks: { type: "boolean" },
2024
- preserveAssignment: { type: "boolean" },
2025
- preserveDependencies: { type: "boolean" },
2026
- moveTasksToColumnId: { type: "string" },
2027
- atomicityMode: { type: "string", enum: ["off", "assess", "enforce"] },
2028
- atomicityDecomposition: { type: "string", enum: ["auto", "propose"] },
2029
- gateEnforcement: {
2030
- type: "string",
2031
- // WS-023: `'off'` is deliberately absent. The agent whose work this gate
2032
- // checks must not be able to switch it off; it may only tighten. Turning
2033
- // a gate off stays a human decision, made through board config.
2034
- enum: ["strict", "soft"]
2035
- },
2036
- subtasks: {
2037
- type: "array",
2038
- minItems: 2,
2039
- items: {
2040
- type: "object",
2041
- properties: {
2042
- title: { type: "string" },
2043
- description: { type: "string" },
2044
- successCriteria: { type: "array", items: { type: "string" } },
2045
- dependsOnIndex: { type: "array", items: { type: "number" } }
2046
- },
2047
- required: ["title"]
2048
- }
2049
- }
2050
- },
2051
- required: ["action"]
2052
- };
2053
-
2054
- // src/kanban.ts
2055
- var kanbanTool = {
2056
- name: "kanban",
2057
- category: "Project",
2058
- description: KANBAN_TOOL_DESCRIPTION,
2059
- usageHint: KANBAN_TOOL_USAGE_HINT,
2060
- permission: "confirm",
2061
- subjectKey: "action",
2062
- mutating: true,
2063
- capabilities: ["fs.write"],
2064
- icon: "task",
2065
- timeoutMs: 3e4,
2066
- inputSchema: KANBAN_INPUT_SCHEMA,
2067
- async execute(input, ctx) {
2068
- const projectRoot = ctx.projectRoot;
2069
- if (!projectRoot) return fail("No project root is available.");
2070
- const withPresence = createKanbanPresenceWrapper(projectRoot, input, ctx);
2071
- try {
2072
- const result = await (async () => {
2073
- const decompositionResult = await handleKanbanDecompositionAction(projectRoot, input, ctx);
2074
- if (decompositionResult !== void 0) return decompositionResult;
2075
- const boardResult = await handleKanbanBoardAction(projectRoot, input, ctx);
2076
- if (boardResult !== void 0) return boardResult;
2077
- const lifecycleResult = await handleKanbanLifecycleAction(projectRoot, input, ctx);
2078
- if (lifecycleResult !== void 0) return lifecycleResult;
2079
- const contractResult = await handleKanbanContractAction(
2080
- projectRoot,
2081
- input,
2082
- input.author ?? input.agentId
2083
- );
2084
- if (contractResult !== void 0) return contractResult;
2085
- const detailResult = await handleKanbanDetailAction(projectRoot, input);
2086
- if (detailResult !== void 0) return detailResult;
2087
- return fail(`Unknown kanban action: ${input.action}`);
2088
- })();
2089
- return withPresence(result);
2090
- } catch (err) {
2091
- return fail(stripLifecycleIssues2(err instanceof Error ? err.message : String(err)));
2092
- }
2093
- },
2094
- serialize(output, input) {
2095
- return serializeKanbanOutput(output, input);
2096
- }
2097
- };
2
+ kanbanTool
3
+ } from "./chunk-JNNVRHMV.js";
4
+ import "./chunk-PY2IOS7C.js";
2098
5
  export {
2099
6
  kanbanTool
2100
7
  };