@wrongstack/tools 0.302.2 → 0.305.0
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.
- package/dist/builtin.d.ts +6 -0
- package/dist/builtin.js +3213 -686
- package/dist/codebase-index/binary-frame.d.ts +43 -0
- package/dist/codebase-index/codebase-incoming-calls-tool.d.ts +1 -0
- package/dist/codebase-index/codebase-index-tool.d.ts +6 -0
- package/dist/codebase-index/codebase-outgoing-calls-tool.d.ts +1 -0
- package/dist/codebase-index/content-hash.d.ts +66 -0
- package/dist/codebase-index/index.js +1597 -153
- package/dist/codebase-index/indexer.d.ts +6 -0
- package/dist/codebase-index/parser-worker-pool.d.ts +63 -0
- package/dist/codebase-index/parser-worker-script.d.ts +42 -0
- package/dist/codebase-index/project-server-protocol.d.ts +2 -0
- package/dist/codebase-index/project-server.js +1483 -104
- package/dist/codebase-index/schema.d.ts +18 -0
- package/dist/codebase-index/tree-sitter/queries.d.ts +48 -0
- package/dist/codebase-index/tree-sitter/util.d.ts +31 -0
- package/dist/codebase-index/tree-sitter/visitor.d.ts +47 -0
- package/dist/codebase-index/tree-sitter-parser.d.ts +58 -0
- package/dist/codebase-index/vector-search.d.ts +62 -0
- package/dist/codebase-index/worker-protocol.d.ts +2 -0
- package/dist/codebase-index/worker.js +1452 -73
- package/dist/codebase-index/writer-bulk-insert.d.ts +5 -0
- package/dist/codebase-index/writer-graph-reader.d.ts +39 -0
- package/dist/codebase-index/writer-schema.d.ts +9 -2
- package/dist/codebase-index/writer.d.ts +36 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.js +3258 -727
- package/dist/kanban-contract-actions.d.ts +7 -0
- package/dist/kanban-task-inputs.d.ts +16 -2
- package/dist/kanban-tool-schema.d.ts +2 -2
- package/dist/kanban-tool-types.d.ts +39 -2
- package/dist/kanban.js +580 -193
- package/dist/pack.js +3212 -686
- package/dist/plan.d.ts +4 -1
- package/dist/plan.js +2701 -18
- package/dist/read.js +1559 -103
- package/dist/session-kanban.d.ts +94 -1
- package/dist/session-kanban.js +308 -44
- package/dist/task.d.ts +5 -4
- package/dist/task.js +2825 -138
- package/dist/todo.d.ts +10 -1
- package/dist/todo.js +2474 -30
- package/dist/tool-tier.js +3212 -686
- package/package.json +8 -4
package/dist/todo.js
CHANGED
|
@@ -1,5 +1,1054 @@
|
|
|
1
1
|
// src/todo.ts
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
loadPlan as loadPlan2,
|
|
4
|
+
loadTasks as loadTasks3,
|
|
5
|
+
savePlan,
|
|
6
|
+
saveTasks,
|
|
7
|
+
setPlanItemStatus
|
|
8
|
+
} from "@wrongstack/core/storage";
|
|
9
|
+
import { addTask as addTask2, getBoard as getBoard4 } from "@wrongstack/kanban";
|
|
10
|
+
|
|
11
|
+
// src/kanban.ts
|
|
12
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
13
|
+
import { loadTasks as loadTasks2 } from "@wrongstack/core/storage";
|
|
14
|
+
import { deserializeTaskGraph as deserializeTaskGraph2, serializeTaskGraph } from "@wrongstack/core/tasking";
|
|
15
|
+
import {
|
|
16
|
+
addTask,
|
|
17
|
+
adoptManagedLifecycle,
|
|
18
|
+
assignTask,
|
|
19
|
+
claimReadyTask,
|
|
20
|
+
copyTaskToBoard,
|
|
21
|
+
createBoard as createBoard2,
|
|
22
|
+
createBoardFromTaskGraph,
|
|
23
|
+
createBoardFromText,
|
|
24
|
+
duplicateBoard,
|
|
25
|
+
evaluateContractGraphReadiness,
|
|
26
|
+
exportBoardAsMarkdown,
|
|
27
|
+
exportBoardToTaskGraph,
|
|
28
|
+
finalizeTaskCompletion,
|
|
29
|
+
getBoard as getBoard3,
|
|
30
|
+
getKanbanOrchestrationSnapshot as getKanbanOrchestrationSnapshot2,
|
|
31
|
+
getKanbanQueueHealth,
|
|
32
|
+
getTask,
|
|
33
|
+
getTaskChain,
|
|
34
|
+
heartbeatTaskAssignment,
|
|
35
|
+
listBoards as listBoards2,
|
|
36
|
+
listKanbanEvents,
|
|
37
|
+
listReadyTasks,
|
|
38
|
+
mergeTasks,
|
|
39
|
+
moveTask,
|
|
40
|
+
parseLinesIntoTasks,
|
|
41
|
+
recoverStaleTaskAssignments,
|
|
42
|
+
releaseTaskClaim,
|
|
43
|
+
removeBoard as removeBoard2,
|
|
44
|
+
removeTask,
|
|
45
|
+
repairManagedTaskProjection,
|
|
46
|
+
resolveAutoAccept,
|
|
47
|
+
searchKanban,
|
|
48
|
+
setTaskChain,
|
|
49
|
+
stripLifecycleIssues,
|
|
50
|
+
syncBoardFromTaskGraph as syncBoardFromTaskGraph2,
|
|
51
|
+
transferTaskToBoard,
|
|
52
|
+
transitionTask,
|
|
53
|
+
updateBoard as updateBoard2,
|
|
54
|
+
updateTask as updateTask2,
|
|
55
|
+
updateTaskAssignment,
|
|
56
|
+
verifyTaskCompletion as verifyTaskCompletion2
|
|
57
|
+
} from "@wrongstack/kanban";
|
|
58
|
+
|
|
59
|
+
// src/kanban-board-inputs.ts
|
|
60
|
+
function agentSettableGate(enforcement) {
|
|
61
|
+
if (enforcement === void 0 || enforcement === "off") return {};
|
|
62
|
+
return { completionGate: { enforcement } };
|
|
63
|
+
}
|
|
64
|
+
function boardCreateInput(input, title) {
|
|
65
|
+
return {
|
|
66
|
+
title,
|
|
67
|
+
...input.description !== void 0 ? { description: input.description } : {},
|
|
68
|
+
...input.tags !== void 0 ? { tags: input.tags } : {},
|
|
69
|
+
...input.generatedBy !== void 0 ? { generatedBy: input.generatedBy } : {},
|
|
70
|
+
...input.atomicityMode !== void 0 ? {
|
|
71
|
+
atomicity: {
|
|
72
|
+
mode: input.atomicityMode,
|
|
73
|
+
decomposition: input.atomicityDecomposition ?? "propose"
|
|
74
|
+
}
|
|
75
|
+
} : {},
|
|
76
|
+
...agentSettableGate(input.gateEnforcement)
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function boardUpdatePatch(input) {
|
|
80
|
+
return {
|
|
81
|
+
...input.title !== void 0 ? { title: input.title } : {},
|
|
82
|
+
...input.description !== void 0 ? { description: input.description } : {},
|
|
83
|
+
...input.tags !== void 0 ? { tags: input.tags } : {},
|
|
84
|
+
...input.atomicityMode !== void 0 ? {
|
|
85
|
+
atomicity: {
|
|
86
|
+
mode: input.atomicityMode,
|
|
87
|
+
decomposition: input.atomicityDecomposition ?? "propose"
|
|
88
|
+
}
|
|
89
|
+
} : {},
|
|
90
|
+
...agentSettableGate(input.gateEnforcement)
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function duplicateBoardOptions(input) {
|
|
94
|
+
return {
|
|
95
|
+
...input.title !== void 0 ? { title: input.title } : {},
|
|
96
|
+
...input.generatedBy !== void 0 ? { generatedBy: input.generatedBy } : {},
|
|
97
|
+
...input.includeTasks !== void 0 ? { includeTasks: input.includeTasks } : {},
|
|
98
|
+
...input.includeCompletedTasks !== void 0 ? { includeCompletedTasks: input.includeCompletedTasks } : {},
|
|
99
|
+
...input.preserveAssignment !== void 0 ? { preserveAssignment: input.preserveAssignment } : {}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// src/kanban-contract-actions.ts
|
|
104
|
+
import {
|
|
105
|
+
addContractEdge,
|
|
106
|
+
configureContractGraph,
|
|
107
|
+
evaluateTaskContractGraph,
|
|
108
|
+
getContractGraph,
|
|
109
|
+
removeContractEdge,
|
|
110
|
+
removeContractNode,
|
|
111
|
+
upsertContractNode
|
|
112
|
+
} from "@wrongstack/kanban";
|
|
113
|
+
|
|
114
|
+
// src/kanban-tool-results.ts
|
|
115
|
+
function atomicityNudge(task) {
|
|
116
|
+
if (task.atomicityAssessment?.verdict !== "needs_decomposition") return "";
|
|
117
|
+
const reasons = task.atomicityAssessment.criteria.filter((entry) => entry.score < 1).map((entry) => entry.reason).join(" | ");
|
|
118
|
+
return ` Atomicity: needs_decomposition (score ${task.atomicityAssessment.score}) \u2014 call propose_decomposition with 2+ subtasks before dispatch. Reasons: ${reasons}`;
|
|
119
|
+
}
|
|
120
|
+
function readEnvGateEnforcement() {
|
|
121
|
+
const raw = process.env["WRONGSTACK_KANBAN_GATE"]?.trim().toLowerCase();
|
|
122
|
+
return raw === "strict" || raw === "soft" || raw === "off" ? raw : void 0;
|
|
123
|
+
}
|
|
124
|
+
function fail(message) {
|
|
125
|
+
return { ok: false, message };
|
|
126
|
+
}
|
|
127
|
+
function okBoard(board, message = "Board loaded.") {
|
|
128
|
+
return { ok: true, message, board };
|
|
129
|
+
}
|
|
130
|
+
function okTask(board, task, message) {
|
|
131
|
+
return { ok: true, message, board, task };
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// src/kanban-contract-actions.ts
|
|
135
|
+
async function handleKanbanContractAction(projectRoot, input, actor) {
|
|
136
|
+
switch (input.action) {
|
|
137
|
+
case "get_contract_graph": {
|
|
138
|
+
if (!input.boardId) return fail("get_contract_graph requires boardId.");
|
|
139
|
+
const found = await getContractGraph(projectRoot, input.boardId);
|
|
140
|
+
if (!found) return fail("Board not found.");
|
|
141
|
+
const evaluated = input.taskId ? await evaluateTaskContractGraph(projectRoot, input.boardId, input.taskId) : null;
|
|
142
|
+
if (input.taskId && !evaluated) return fail("Task not found on this board.");
|
|
143
|
+
return {
|
|
144
|
+
ok: true,
|
|
145
|
+
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.",
|
|
146
|
+
board: found.board,
|
|
147
|
+
contractGraph: found.graph,
|
|
148
|
+
...evaluated ? { contractEvaluation: evaluated.evaluation } : {}
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
case "configure_contract_graph": {
|
|
152
|
+
if (!input.boardId) return fail("configure_contract_graph requires boardId.");
|
|
153
|
+
const enforcement = input.contractEnforcement ?? "advisory";
|
|
154
|
+
const board = await configureContractGraph(projectRoot, input.boardId, enforcement);
|
|
155
|
+
return board ? okBoard(board, `Contract map enforcement set to ${enforcement}.`) : fail("Board not found.");
|
|
156
|
+
}
|
|
157
|
+
case "upsert_contract_node": {
|
|
158
|
+
if (!input.boardId || !input.taskId) {
|
|
159
|
+
return fail("upsert_contract_node requires boardId and taskId.");
|
|
160
|
+
}
|
|
161
|
+
if (!input.contractNodeKind || !input.contractNodeTitle) {
|
|
162
|
+
return fail("upsert_contract_node requires contractNodeKind and contractNodeTitle.");
|
|
163
|
+
}
|
|
164
|
+
const waiver = input.contractNodeState === "waived" ? {
|
|
165
|
+
actor: actor ?? "agent",
|
|
166
|
+
reason: input.contractWaiverReason ?? "",
|
|
167
|
+
at: (/* @__PURE__ */ new Date()).toISOString()
|
|
168
|
+
} : void 0;
|
|
169
|
+
if (waiver && !waiver.reason.trim()) {
|
|
170
|
+
return fail("A waived contract node requires contractWaiverReason.");
|
|
171
|
+
}
|
|
172
|
+
const result = await upsertContractNode(projectRoot, input.boardId, {
|
|
173
|
+
taskId: input.taskId,
|
|
174
|
+
kind: input.contractNodeKind,
|
|
175
|
+
title: input.contractNodeTitle,
|
|
176
|
+
...input.contractNodeId !== void 0 ? { id: input.contractNodeId } : {},
|
|
177
|
+
...input.contractNodeDescription !== void 0 ? { description: input.contractNodeDescription } : {},
|
|
178
|
+
...input.contractNodeState !== void 0 ? { state: input.contractNodeState } : {},
|
|
179
|
+
...input.contractNodeEnforcement !== void 0 ? { enforcement: input.contractNodeEnforcement } : {},
|
|
180
|
+
...input.contractCheckId !== void 0 ? { checkId: input.contractCheckId } : {},
|
|
181
|
+
...input.contractMetricId !== void 0 ? { metricId: input.contractMetricId } : {},
|
|
182
|
+
...waiver ? { waiver } : {},
|
|
183
|
+
...actor !== void 0 ? { createdBy: actor } : {}
|
|
184
|
+
});
|
|
185
|
+
if (!result) return fail("Board or task not found.");
|
|
186
|
+
return {
|
|
187
|
+
ok: true,
|
|
188
|
+
message: `Contract node ${result.node.kind} "${result.node.title}" saved (${result.node.id}).`,
|
|
189
|
+
board: result.board,
|
|
190
|
+
contractGraph: result.board.contractGraph ?? null
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
case "remove_contract_node": {
|
|
194
|
+
if (!input.boardId || !input.contractNodeId) {
|
|
195
|
+
return fail("remove_contract_node requires boardId and contractNodeId.");
|
|
196
|
+
}
|
|
197
|
+
const board = await removeContractNode(projectRoot, input.boardId, input.contractNodeId);
|
|
198
|
+
return board ? okBoard(board, "Contract node removed, along with every edge that touched it.") : fail("Contract node not found.");
|
|
199
|
+
}
|
|
200
|
+
case "add_contract_edge": {
|
|
201
|
+
if (!input.boardId || !input.contractEdgeFrom || !input.contractEdgeTo) {
|
|
202
|
+
return fail("add_contract_edge requires boardId, contractEdgeFrom, and contractEdgeTo.");
|
|
203
|
+
}
|
|
204
|
+
if (!input.contractEdgeType) return fail("add_contract_edge requires contractEdgeType.");
|
|
205
|
+
const result = await addContractEdge(projectRoot, input.boardId, {
|
|
206
|
+
from: input.contractEdgeFrom,
|
|
207
|
+
to: input.contractEdgeTo,
|
|
208
|
+
type: input.contractEdgeType,
|
|
209
|
+
...input.contractEdgeId !== void 0 ? { id: input.contractEdgeId } : {},
|
|
210
|
+
...input.contractNodeEnforcement !== void 0 ? { enforcement: input.contractNodeEnforcement } : {},
|
|
211
|
+
...input.contractEdgeRationale !== void 0 ? { rationale: input.contractEdgeRationale } : {},
|
|
212
|
+
...actor !== void 0 ? { createdBy: actor } : {}
|
|
213
|
+
});
|
|
214
|
+
if (!result) return fail("Board not found.");
|
|
215
|
+
return {
|
|
216
|
+
ok: true,
|
|
217
|
+
message: `Contract edge ${result.edge.type}: ${result.edge.from} \u2192 ${result.edge.to}.`,
|
|
218
|
+
board: result.board,
|
|
219
|
+
contractGraph: result.board.contractGraph ?? null
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
case "remove_contract_edge": {
|
|
223
|
+
if (!input.boardId || !input.contractEdgeId) {
|
|
224
|
+
return fail("remove_contract_edge requires boardId and contractEdgeId.");
|
|
225
|
+
}
|
|
226
|
+
const board = await removeContractEdge(projectRoot, input.boardId, input.contractEdgeId);
|
|
227
|
+
return board ? okBoard(board, "Contract edge removed.") : fail("Contract edge not found.");
|
|
228
|
+
}
|
|
229
|
+
default:
|
|
230
|
+
return void 0;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// src/kanban-decomposition-actions.ts
|
|
235
|
+
import {
|
|
236
|
+
assessTaskAtomicity,
|
|
237
|
+
proposeTaskDecomposition,
|
|
238
|
+
updateTask,
|
|
239
|
+
verifyTaskCompletion
|
|
240
|
+
} from "@wrongstack/kanban";
|
|
241
|
+
|
|
242
|
+
// src/kanban-evidence-bridge.ts
|
|
243
|
+
import { recordCompletedWorkEvidence } from "@wrongstack/core/utils";
|
|
244
|
+
function kanbanEvidenceKey(boardId, taskId) {
|
|
245
|
+
return `kanban:${boardId}:${taskId}`;
|
|
246
|
+
}
|
|
247
|
+
function kanbanEvidencePointer(boardId, taskId) {
|
|
248
|
+
return `kanban://${boardId}/${taskId}#verificationReport`;
|
|
249
|
+
}
|
|
250
|
+
function recordKanbanVerificationEvidence(ctx, report) {
|
|
251
|
+
try {
|
|
252
|
+
const passed = report.checks.filter((check) => check.status === "passed").length;
|
|
253
|
+
const completedAt = Date.parse(report.completedAt);
|
|
254
|
+
recordCompletedWorkEvidence(ctx, {
|
|
255
|
+
key: kanbanEvidenceKey(report.boardId, report.taskId),
|
|
256
|
+
source: "verification",
|
|
257
|
+
summary: `${report.taskTitle} \u2014 verification ${report.verdict} (${passed}/${report.checks.length} checks)`,
|
|
258
|
+
...Number.isFinite(completedAt) ? { completedAt } : {},
|
|
259
|
+
evidence: kanbanEvidencePointer(report.boardId, report.taskId)
|
|
260
|
+
});
|
|
261
|
+
} catch {
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// src/kanban-decomposition-actions.ts
|
|
266
|
+
async function handleKanbanDecompositionAction(projectRoot, input, ctx) {
|
|
267
|
+
switch (input.action) {
|
|
268
|
+
case "assess_atomicity": {
|
|
269
|
+
if (!input.boardId || !input.taskId) {
|
|
270
|
+
return fail("assess_atomicity requires boardId and taskId.");
|
|
271
|
+
}
|
|
272
|
+
const result = await assessTaskAtomicity(projectRoot, input.boardId, input.taskId, {
|
|
273
|
+
assessedBy: "agent",
|
|
274
|
+
...ctx.agentId !== void 0 ? { eventContext: { actor: ctx.agentId } } : {}
|
|
275
|
+
});
|
|
276
|
+
if (!result) return fail("Task not found.");
|
|
277
|
+
const failing = result.assessment.criteria.filter((entry) => entry.score < 1).map((entry) => entry.reason);
|
|
278
|
+
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." : "";
|
|
279
|
+
return okTask(
|
|
280
|
+
result.board,
|
|
281
|
+
result.task,
|
|
282
|
+
`Atomicity verdict: ${result.assessment.verdict} (score ${result.assessment.score}).${guidance}`
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
case "propose_decomposition": {
|
|
286
|
+
if (!input.boardId || !input.taskId || !input.subtasks?.length) {
|
|
287
|
+
return fail("propose_decomposition requires boardId, taskId, and subtasks (2+).");
|
|
288
|
+
}
|
|
289
|
+
if (input.subtasks.length < 2) {
|
|
290
|
+
return fail("propose_decomposition requires at least two subtasks.");
|
|
291
|
+
}
|
|
292
|
+
const invalid = input.subtasks.find(
|
|
293
|
+
(subtask) => typeof subtask?.title !== "string" || !subtask.title.trim()
|
|
294
|
+
);
|
|
295
|
+
if (invalid) return fail("Every proposed subtask needs a non-blank title.");
|
|
296
|
+
const result = await proposeTaskDecomposition(
|
|
297
|
+
projectRoot,
|
|
298
|
+
input.boardId,
|
|
299
|
+
input.taskId,
|
|
300
|
+
{
|
|
301
|
+
subtasks: input.subtasks,
|
|
302
|
+
...input.note !== void 0 ? { rationale: input.note } : {},
|
|
303
|
+
...ctx.agentId !== void 0 ? { proposedBy: ctx.agentId } : {}
|
|
304
|
+
},
|
|
305
|
+
ctx.agentId !== void 0 ? { actor: ctx.agentId } : {}
|
|
306
|
+
);
|
|
307
|
+
if (!result) return fail("Task not found.");
|
|
308
|
+
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.';
|
|
309
|
+
return okTask(result.board, result.task, message);
|
|
310
|
+
}
|
|
311
|
+
case "verify_completion": {
|
|
312
|
+
if (!input.boardId || !input.taskId) {
|
|
313
|
+
return fail("verify_completion requires boardId and taskId.");
|
|
314
|
+
}
|
|
315
|
+
const verResult = await verifyTaskCompletion(projectRoot, input.boardId, input.taskId);
|
|
316
|
+
const persistedBoard = await updateTask(projectRoot, input.boardId, input.taskId, {
|
|
317
|
+
verificationReport: verResult.report,
|
|
318
|
+
successCriteria: verResult.task.successCriteria
|
|
319
|
+
});
|
|
320
|
+
if (!persistedBoard) {
|
|
321
|
+
return {
|
|
322
|
+
ok: false,
|
|
323
|
+
verdict: verResult.report.verdict,
|
|
324
|
+
message: `Verification succeeded but persist failed: ${verResult.report.markdownSummary}. Board may be stale \u2014 re-run verify_completion.`,
|
|
325
|
+
board: verResult.board
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
recordKanbanVerificationEvidence(ctx, verResult.report);
|
|
329
|
+
const freshTask = persistedBoard.tasks?.find((t) => t.id === input.taskId);
|
|
330
|
+
const deterministicVerdicts = ["passed", "failed", "needs_human", "incomplete"];
|
|
331
|
+
return {
|
|
332
|
+
ok: deterministicVerdicts.includes(
|
|
333
|
+
verResult.report.verdict
|
|
334
|
+
),
|
|
335
|
+
verdict: verResult.report.verdict,
|
|
336
|
+
message: verResult.report.markdownSummary,
|
|
337
|
+
board: persistedBoard,
|
|
338
|
+
task: freshTask ?? verResult.task
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
default:
|
|
342
|
+
return void 0;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// src/kanban-detail-actions.ts
|
|
347
|
+
import {
|
|
348
|
+
addCheckToTask,
|
|
349
|
+
addDependency,
|
|
350
|
+
addGoalMetricToTask,
|
|
351
|
+
addLinkToTask,
|
|
352
|
+
addNoteToTask,
|
|
353
|
+
getKanbanWorkbench,
|
|
354
|
+
removeCheckFromTask,
|
|
355
|
+
updateCheckOnTask,
|
|
356
|
+
updateGoalMetricOnTask
|
|
357
|
+
} from "@wrongstack/kanban";
|
|
358
|
+
|
|
359
|
+
// src/kanban-split-task-handler.ts
|
|
360
|
+
import { getBoard, splitTask } from "@wrongstack/kanban";
|
|
361
|
+
async function handleSplitTask(projectRoot, input, extraSplitOptions) {
|
|
362
|
+
const boardId = input.boardId;
|
|
363
|
+
const taskId = input.taskId;
|
|
364
|
+
const childTitles = input.childTitles;
|
|
365
|
+
if (!boardId || !taskId || !childTitles?.length) {
|
|
366
|
+
return fail("split requires boardId, taskId, and at least one childTitles.");
|
|
367
|
+
}
|
|
368
|
+
const {
|
|
369
|
+
targetColumnId,
|
|
370
|
+
inheritAssignment,
|
|
371
|
+
inheritLabels,
|
|
372
|
+
inheritSuccessCriteria,
|
|
373
|
+
inheritGoalMetrics,
|
|
374
|
+
inheritDependencies,
|
|
375
|
+
chainChildren,
|
|
376
|
+
rewireDependents
|
|
377
|
+
} = input;
|
|
378
|
+
const result = await splitTask(projectRoot, boardId, taskId, {
|
|
379
|
+
titles: childTitles,
|
|
380
|
+
...extraSplitOptions,
|
|
381
|
+
...targetColumnId !== void 0 ? { columnId: targetColumnId } : {},
|
|
382
|
+
...inheritAssignment !== void 0 ? { inheritAssignment } : {},
|
|
383
|
+
...inheritLabels !== void 0 ? { inheritLabels } : {},
|
|
384
|
+
...inheritSuccessCriteria !== void 0 ? { inheritSuccessCriteria } : {},
|
|
385
|
+
...inheritGoalMetrics !== void 0 ? { inheritGoalMetrics } : {},
|
|
386
|
+
...inheritDependencies !== void 0 ? { inheritDependencies } : {},
|
|
387
|
+
...chainChildren !== void 0 ? { chainChildren } : {},
|
|
388
|
+
...rewireDependents !== void 0 ? { rewireDependents } : {}
|
|
389
|
+
});
|
|
390
|
+
if (!result) return fail("Task not found.");
|
|
391
|
+
const freshParent = result.board.tasks?.find((t) => t.id === taskId);
|
|
392
|
+
if (!freshParent) {
|
|
393
|
+
return fail(
|
|
394
|
+
`Split succeeded but parent ${taskId} not found in returned board. Children: [${result.children.map((c) => c.id).join(", ")}].`
|
|
395
|
+
);
|
|
396
|
+
}
|
|
397
|
+
return {
|
|
398
|
+
ok: true,
|
|
399
|
+
message: `${result.children.length} child task(s) created.`,
|
|
400
|
+
board: result.board,
|
|
401
|
+
task: freshParent,
|
|
402
|
+
children: result.children
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
async function requireBoard(projectRoot, boardId) {
|
|
406
|
+
return boardId ? getBoard(projectRoot, boardId) : null;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// src/kanban-detail-actions.ts
|
|
410
|
+
async function handleKanbanDetailAction(projectRoot, input) {
|
|
411
|
+
switch (input.action) {
|
|
412
|
+
case "workbench": {
|
|
413
|
+
const workbench = await getKanbanWorkbench(projectRoot, {
|
|
414
|
+
...input.limit !== void 0 ? { limitPerLane: input.limit, alertLimit: input.limit } : {}
|
|
415
|
+
});
|
|
416
|
+
return {
|
|
417
|
+
ok: true,
|
|
418
|
+
message: `${workbench.totals.now} now, ${workbench.totals.next} next, ${workbench.totals.blocked} blocked, ${workbench.totals.review} review; ${workbench.alertTotal} alert(s).`,
|
|
419
|
+
workbench
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
case "add_dependency": {
|
|
423
|
+
if (!input.boardId || !input.taskId || !input.dependencyTaskId) {
|
|
424
|
+
return fail("add_dependency requires boardId, taskId, and dependencyTaskId.");
|
|
425
|
+
}
|
|
426
|
+
const board = await addDependency(
|
|
427
|
+
projectRoot,
|
|
428
|
+
input.boardId,
|
|
429
|
+
input.taskId,
|
|
430
|
+
input.dependencyTaskId
|
|
431
|
+
);
|
|
432
|
+
return board ? okBoard(board, "Dependency added.") : fail("Task not found.");
|
|
433
|
+
}
|
|
434
|
+
case "add_goal_metric": {
|
|
435
|
+
if (!input.boardId || !input.taskId || !input.metricName) {
|
|
436
|
+
return fail("add_goal_metric requires boardId, taskId, and metricName.");
|
|
437
|
+
}
|
|
438
|
+
const board = await addGoalMetricToTask(projectRoot, input.boardId, input.taskId, {
|
|
439
|
+
name: input.metricName,
|
|
440
|
+
...input.metricStatus !== void 0 ? { status: input.metricStatus } : {},
|
|
441
|
+
...input.metricTarget !== void 0 ? { target: input.metricTarget } : {},
|
|
442
|
+
...input.metricCurrent !== void 0 ? { current: input.metricCurrent } : {},
|
|
443
|
+
...input.metricUnit !== void 0 ? { unit: input.metricUnit } : {},
|
|
444
|
+
...input.metricNotes !== void 0 ? { notes: input.metricNotes } : {}
|
|
445
|
+
});
|
|
446
|
+
return board ? okBoard(board, "Goal metric added.") : fail("Task not found.");
|
|
447
|
+
}
|
|
448
|
+
case "update_goal_metric": {
|
|
449
|
+
if (!input.boardId || !input.taskId || !input.metricId) {
|
|
450
|
+
return fail("update_goal_metric requires boardId, taskId, and metricId.");
|
|
451
|
+
}
|
|
452
|
+
const board = await updateGoalMetricOnTask(
|
|
453
|
+
projectRoot,
|
|
454
|
+
input.boardId,
|
|
455
|
+
input.taskId,
|
|
456
|
+
input.metricId,
|
|
457
|
+
{
|
|
458
|
+
...input.metricName !== void 0 ? { name: input.metricName } : {},
|
|
459
|
+
...input.metricStatus !== void 0 ? { status: input.metricStatus } : {},
|
|
460
|
+
...input.metricTarget !== void 0 ? { target: input.metricTarget } : {},
|
|
461
|
+
...input.metricCurrent !== void 0 ? { current: input.metricCurrent } : {},
|
|
462
|
+
...input.metricUnit !== void 0 ? { unit: input.metricUnit } : {},
|
|
463
|
+
...input.metricNotes !== void 0 ? { notes: input.metricNotes } : {}
|
|
464
|
+
}
|
|
465
|
+
);
|
|
466
|
+
return board ? okBoard(board, "Goal metric updated.") : fail("Metric not found.");
|
|
467
|
+
}
|
|
468
|
+
case "add_check": {
|
|
469
|
+
if (!input.boardId || !input.taskId || !input.checkDescription) {
|
|
470
|
+
return fail("add_check requires boardId, taskId, and checkDescription.");
|
|
471
|
+
}
|
|
472
|
+
const board = await addCheckToTask(projectRoot, input.boardId, input.taskId, {
|
|
473
|
+
description: input.checkDescription,
|
|
474
|
+
type: input.checkType ?? "manual",
|
|
475
|
+
status: input.checkStatus,
|
|
476
|
+
...input.checkNotes !== void 0 ? { notes: input.checkNotes } : {}
|
|
477
|
+
});
|
|
478
|
+
return board ? okBoard(board, "Check added.") : fail("Task not found.");
|
|
479
|
+
}
|
|
480
|
+
case "update_check": {
|
|
481
|
+
if (!input.boardId || !input.taskId || !input.checkId) {
|
|
482
|
+
return fail("update_check requires boardId, taskId, and checkId.");
|
|
483
|
+
}
|
|
484
|
+
const board = await updateCheckOnTask(
|
|
485
|
+
projectRoot,
|
|
486
|
+
input.boardId,
|
|
487
|
+
input.taskId,
|
|
488
|
+
input.checkId,
|
|
489
|
+
{
|
|
490
|
+
...input.checkDescription !== void 0 ? { description: input.checkDescription } : {},
|
|
491
|
+
...input.checkStatus !== void 0 ? { status: input.checkStatus } : {},
|
|
492
|
+
// Promoting an existing manual criterion to an executable one is the
|
|
493
|
+
// common repair: the card was written before anyone knew the command.
|
|
494
|
+
...input.checkType !== void 0 ? { type: input.checkType } : {},
|
|
495
|
+
...input.checkNotes !== void 0 ? { notes: input.checkNotes } : {}
|
|
496
|
+
}
|
|
497
|
+
);
|
|
498
|
+
return board ? okBoard(board, "Check updated.") : fail("Check not found.");
|
|
499
|
+
}
|
|
500
|
+
case "remove_check": {
|
|
501
|
+
if (!input.boardId || !input.taskId || !input.checkId) {
|
|
502
|
+
return fail("remove_check requires boardId, taskId, and checkId.");
|
|
503
|
+
}
|
|
504
|
+
const board = await removeCheckFromTask(
|
|
505
|
+
projectRoot,
|
|
506
|
+
input.boardId,
|
|
507
|
+
input.taskId,
|
|
508
|
+
input.checkId
|
|
509
|
+
);
|
|
510
|
+
return board ? okBoard(board, "Acceptance criterion removed.") : fail("Check not found on this task.");
|
|
511
|
+
}
|
|
512
|
+
case "add_note": {
|
|
513
|
+
if (!input.boardId || !input.taskId || !input.note)
|
|
514
|
+
return fail("add_note requires boardId, taskId, and note.");
|
|
515
|
+
const board = await addNoteToTask(projectRoot, input.boardId, input.taskId, {
|
|
516
|
+
author: input.author ?? "agent",
|
|
517
|
+
content: input.note
|
|
518
|
+
});
|
|
519
|
+
return board ? okBoard(board, "Note added.") : fail("Task not found.");
|
|
520
|
+
}
|
|
521
|
+
case "add_link": {
|
|
522
|
+
if (!input.boardId || !input.taskId || !input.url)
|
|
523
|
+
return fail("add_link requires boardId, taskId, and url.");
|
|
524
|
+
const board = await addLinkToTask(projectRoot, input.boardId, input.taskId, {
|
|
525
|
+
url: input.url,
|
|
526
|
+
type: input.linkType ?? "url",
|
|
527
|
+
...input.linkTitle !== void 0 ? { title: input.linkTitle } : {}
|
|
528
|
+
});
|
|
529
|
+
return board ? okBoard(board, "Link added.") : fail("Task not found.");
|
|
530
|
+
}
|
|
531
|
+
case "split_atomic": {
|
|
532
|
+
if (!input.boardId || !input.taskId || !input.childTitles?.length) {
|
|
533
|
+
return fail("split_atomic requires boardId, taskId, and childTitles (at least one).");
|
|
534
|
+
}
|
|
535
|
+
return handleSplitTask(projectRoot, input, { atomic: true });
|
|
536
|
+
}
|
|
537
|
+
default:
|
|
538
|
+
return void 0;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
// src/kanban-presence.ts
|
|
543
|
+
import { touchKanbanPresence } from "@wrongstack/kanban";
|
|
544
|
+
function createKanbanPresenceWrapper(projectRoot, input, ctx) {
|
|
545
|
+
return async (result) => {
|
|
546
|
+
const boardId = result.board?.id ?? input.boardId;
|
|
547
|
+
if (!result.ok || !boardId || !ctx.session?.id || !ctx.agentId) return result;
|
|
548
|
+
try {
|
|
549
|
+
const board = await touchKanbanPresence(projectRoot, boardId, {
|
|
550
|
+
sessionId: ctx.session.id,
|
|
551
|
+
agentId: ctx.agentId,
|
|
552
|
+
agentName: ctx.agentName,
|
|
553
|
+
taskId: input.taskId ?? result.task?.id,
|
|
554
|
+
runTaskId: input.runTaskId
|
|
555
|
+
});
|
|
556
|
+
return board ? { ...result, board } : result;
|
|
557
|
+
} catch {
|
|
558
|
+
return result;
|
|
559
|
+
}
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
// src/kanban-task-inputs.ts
|
|
564
|
+
import { randomUUID } from "node:crypto";
|
|
565
|
+
import { clampSubagentCapabilities } from "@wrongstack/core/security";
|
|
566
|
+
function taskInput(input) {
|
|
567
|
+
const assignment = hasAssignmentInput(input) ? assignmentForTaskCreate(input) : void 0;
|
|
568
|
+
return {
|
|
569
|
+
title: input.title ?? "",
|
|
570
|
+
columnId: input.columnId,
|
|
571
|
+
description: input.description,
|
|
572
|
+
dueDate: input.dueDate,
|
|
573
|
+
priority: input.priority,
|
|
574
|
+
...input.taskType !== void 0 ? { type: input.taskType } : {},
|
|
575
|
+
status: input.status,
|
|
576
|
+
labels: input.labels,
|
|
577
|
+
...assignment?.agentId ?? assignment?.role ?? assignment?.name ? { assignedAgent: assignment.agentId ?? assignment.role ?? assignment.name } : {},
|
|
578
|
+
...input.assignee ?? assignment?.name ?? assignment?.agentId ? { assignee: input.assignee ?? assignment?.name ?? assignment?.agentId } : {},
|
|
579
|
+
...mergedDependsOn(input) ? { dependsOn: mergedDependsOn(input) } : {},
|
|
580
|
+
...input.estimatedHours !== void 0 ? { estimatedHours: input.estimatedHours } : {},
|
|
581
|
+
...input.actualHours !== void 0 ? { actualHours: input.actualHours } : {},
|
|
582
|
+
...assignment ? { assignment } : {},
|
|
583
|
+
...input.order !== void 0 ? { order: input.order } : {},
|
|
584
|
+
...input.retryPolicy !== void 0 ? { retryPolicy: input.retryPolicy } : {},
|
|
585
|
+
...input.costCeilingUsd !== void 0 ? { costCeilingUsd: input.costCeilingUsd } : {},
|
|
586
|
+
// The system prompt has always told the model it may "set atomic: true"
|
|
587
|
+
// when creating a composite parent. It could not: the field reached
|
|
588
|
+
// neither the create input nor the patch, so the instruction described a
|
|
589
|
+
// capability that did not exist and the attempt was silently dropped.
|
|
590
|
+
...input.atomic !== void 0 ? { atomic: input.atomic } : {},
|
|
591
|
+
...input.childTitles !== void 0 ? { childTaskIds: input.childTitles } : {},
|
|
592
|
+
...input.checkDescription !== void 0 ? {
|
|
593
|
+
successCriteria: [
|
|
594
|
+
{
|
|
595
|
+
id: randomUUID(),
|
|
596
|
+
description: input.checkDescription,
|
|
597
|
+
// `manual` only as the fallback. Hard-coding it here meant every
|
|
598
|
+
// agent-authored criterion was unverifiable by construction: the
|
|
599
|
+
// deterministic plugins never matched, the registry passed the
|
|
600
|
+
// hand-set status straight through, and "verified" collapsed into
|
|
601
|
+
// "the author ticked its own box".
|
|
602
|
+
type: input.checkType ?? "manual",
|
|
603
|
+
status: input.checkStatus ?? "pending",
|
|
604
|
+
...input.checkNotes !== void 0 ? { notes: input.checkNotes } : {}
|
|
605
|
+
}
|
|
606
|
+
]
|
|
607
|
+
} : {},
|
|
608
|
+
...input.metricName !== void 0 ? {
|
|
609
|
+
goalMetrics: [
|
|
610
|
+
{
|
|
611
|
+
id: randomUUID(),
|
|
612
|
+
name: input.metricName,
|
|
613
|
+
status: input.metricStatus ?? "pending",
|
|
614
|
+
...input.metricTarget !== void 0 ? { target: input.metricTarget } : {},
|
|
615
|
+
...input.metricCurrent !== void 0 ? { current: input.metricCurrent } : {},
|
|
616
|
+
...input.metricUnit !== void 0 ? { unit: input.metricUnit } : {},
|
|
617
|
+
...input.metricNotes !== void 0 ? { notes: input.metricNotes } : {}
|
|
618
|
+
}
|
|
619
|
+
]
|
|
620
|
+
} : {},
|
|
621
|
+
...input.url !== void 0 ? {
|
|
622
|
+
links: [
|
|
623
|
+
{
|
|
624
|
+
url: input.url,
|
|
625
|
+
type: input.linkType ?? "url",
|
|
626
|
+
...input.linkTitle !== void 0 ? { title: input.linkTitle } : {}
|
|
627
|
+
}
|
|
628
|
+
]
|
|
629
|
+
} : {},
|
|
630
|
+
...input.note !== void 0 ? {
|
|
631
|
+
notes: [
|
|
632
|
+
{
|
|
633
|
+
id: randomUUID(),
|
|
634
|
+
author: input.author ?? "agent",
|
|
635
|
+
content: input.note,
|
|
636
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
637
|
+
}
|
|
638
|
+
]
|
|
639
|
+
} : {},
|
|
640
|
+
...[input.graphId, input.specId, input.specRequirementId].some((value) => value !== void 0) ? {
|
|
641
|
+
origin: {
|
|
642
|
+
system: input.sourceSystem ?? "kanban-tool",
|
|
643
|
+
...input.graphId !== void 0 ? { graphId: input.graphId } : {},
|
|
644
|
+
...input.specId !== void 0 ? { specId: input.specId } : {},
|
|
645
|
+
...input.specRequirementId !== void 0 ? { specRequirementId: input.specRequirementId } : {},
|
|
646
|
+
...input.phaseId !== void 0 ? { phaseId: input.phaseId } : {}
|
|
647
|
+
}
|
|
648
|
+
} : {}
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
function mergedDependsOn(input) {
|
|
652
|
+
if (input.dependsOn === void 0 && input.dependencyTaskId === void 0) return void 0;
|
|
653
|
+
return [
|
|
654
|
+
...input.dependsOn ?? [],
|
|
655
|
+
...input.dependencyTaskId !== void 0 ? [input.dependencyTaskId] : []
|
|
656
|
+
].filter((id, i, arr) => id && arr.indexOf(id) === i);
|
|
657
|
+
}
|
|
658
|
+
function taskPatch(input) {
|
|
659
|
+
return {
|
|
660
|
+
title: input.title,
|
|
661
|
+
description: input.description,
|
|
662
|
+
dueDate: input.dueDate,
|
|
663
|
+
columnId: input.columnId,
|
|
664
|
+
order: input.order,
|
|
665
|
+
priority: input.priority,
|
|
666
|
+
...input.taskType !== void 0 ? { type: input.taskType } : {},
|
|
667
|
+
status: input.status,
|
|
668
|
+
labels: input.labels,
|
|
669
|
+
assignedAgent: input.agentId,
|
|
670
|
+
...mergedDependsOn(input) !== void 0 ? { dependsOn: mergedDependsOn(input) } : {},
|
|
671
|
+
// `atomic` and `childTaskIds` are the composite-parent contract, and the
|
|
672
|
+
// managed gate reads both: an `atomic` parent may not move forward without
|
|
673
|
+
// children, and may not reach Done until every child is completed. The
|
|
674
|
+
// manager has always accepted both on a patch; only this surface withheld
|
|
675
|
+
// them, so `split_atomic` was a one-way door — delete the children and the
|
|
676
|
+
// parent was stranded with no way to declare itself a leaf again.
|
|
677
|
+
...input.atomic !== void 0 ? { atomic: input.atomic } : {},
|
|
678
|
+
...input.childTaskIds !== void 0 ? { childTaskIds: input.childTaskIds } : {},
|
|
679
|
+
...input.estimatedHours !== void 0 ? { estimatedHours: input.estimatedHours } : {},
|
|
680
|
+
...input.actualHours !== void 0 ? { actualHours: input.actualHours } : {}
|
|
681
|
+
};
|
|
682
|
+
}
|
|
683
|
+
function clampRequestedCapabilities(requested) {
|
|
684
|
+
if (requested === void 0) return void 0;
|
|
685
|
+
return clampSubagentCapabilities(requested).granted;
|
|
686
|
+
}
|
|
687
|
+
function assignmentInput(input) {
|
|
688
|
+
return {
|
|
689
|
+
agentId: input.agentId,
|
|
690
|
+
name: input.name,
|
|
691
|
+
role: input.role,
|
|
692
|
+
provider: input.provider,
|
|
693
|
+
model: input.model,
|
|
694
|
+
fallbackProfile: input.fallbackProfile,
|
|
695
|
+
fallbackModels: input.fallbackModels,
|
|
696
|
+
tools: input.tools,
|
|
697
|
+
allowedCapabilities: clampRequestedCapabilities(input.allowedCapabilities),
|
|
698
|
+
assignee: input.assignee,
|
|
699
|
+
leaseId: input.leaseId,
|
|
700
|
+
claimedAt: input.claimedAt,
|
|
701
|
+
heartbeatAt: input.heartbeatAt,
|
|
702
|
+
leaseExpiresAt: input.leaseExpiresAt,
|
|
703
|
+
attempt: input.attempt,
|
|
704
|
+
maxAttempts: input.maxAttempts,
|
|
705
|
+
costCeilingUsd: input.costCeilingUsd,
|
|
706
|
+
retryPolicy: input.retryPolicy,
|
|
707
|
+
lastFailureKind: input.lastFailureKind
|
|
708
|
+
};
|
|
709
|
+
}
|
|
710
|
+
function hasAssignmentInput(input) {
|
|
711
|
+
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;
|
|
712
|
+
}
|
|
713
|
+
function assignmentForTaskCreate(input) {
|
|
714
|
+
return {
|
|
715
|
+
status: input.assignmentStatus ?? "assigned",
|
|
716
|
+
...input.agentId !== void 0 ? { agentId: input.agentId } : {},
|
|
717
|
+
...input.name !== void 0 ? { name: input.name } : {},
|
|
718
|
+
...input.role !== void 0 ? { role: input.role } : {},
|
|
719
|
+
...input.provider !== void 0 ? { provider: input.provider } : {},
|
|
720
|
+
...input.model !== void 0 ? { model: input.model } : {},
|
|
721
|
+
...input.fallbackProfile !== void 0 ? { fallbackProfile: input.fallbackProfile } : {},
|
|
722
|
+
...input.fallbackModels !== void 0 ? { fallbackModels: input.fallbackModels } : {},
|
|
723
|
+
...input.tools !== void 0 ? { tools: input.tools } : {},
|
|
724
|
+
...input.allowedCapabilities !== void 0 ? { allowedCapabilities: clampRequestedCapabilities(input.allowedCapabilities) } : {},
|
|
725
|
+
...input.leaseId !== void 0 ? { leaseId: input.leaseId } : {},
|
|
726
|
+
...input.claimedAt !== void 0 ? { claimedAt: input.claimedAt } : {},
|
|
727
|
+
...input.heartbeatAt !== void 0 ? { heartbeatAt: input.heartbeatAt } : {},
|
|
728
|
+
...input.leaseExpiresAt !== void 0 ? { leaseExpiresAt: input.leaseExpiresAt } : {},
|
|
729
|
+
...input.attempt !== void 0 ? { attempt: input.attempt } : {},
|
|
730
|
+
...input.maxAttempts !== void 0 ? { maxAttempts: input.maxAttempts } : {},
|
|
731
|
+
...input.costCeilingUsd !== void 0 ? { costCeilingUsd: input.costCeilingUsd } : {},
|
|
732
|
+
...input.retryPolicy !== void 0 ? { retryPolicy: input.retryPolicy } : {},
|
|
733
|
+
...input.lastFailureKind !== void 0 ? { lastFailureKind: input.lastFailureKind } : {}
|
|
734
|
+
};
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
// src/kanban-tool-schema.ts
|
|
738
|
+
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.";
|
|
739
|
+
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.';
|
|
740
|
+
var KANBAN_INPUT_SCHEMA = {
|
|
741
|
+
type: "object",
|
|
742
|
+
properties: {
|
|
743
|
+
action: {
|
|
744
|
+
type: "string",
|
|
745
|
+
enum: [
|
|
746
|
+
"list_boards",
|
|
747
|
+
"get_board",
|
|
748
|
+
"create_board",
|
|
749
|
+
"duplicate_board",
|
|
750
|
+
"update_board",
|
|
751
|
+
"adopt_managed_lifecycle",
|
|
752
|
+
"release_managed_lifecycle",
|
|
753
|
+
"delete_board",
|
|
754
|
+
"generate_board",
|
|
755
|
+
"export_markdown",
|
|
756
|
+
"export_task_graph",
|
|
757
|
+
"sync_task_graph",
|
|
758
|
+
"create_from_graph",
|
|
759
|
+
"import_session_tasks",
|
|
760
|
+
"search_tasks",
|
|
761
|
+
"ready_tasks",
|
|
762
|
+
"snapshot",
|
|
763
|
+
"workbench",
|
|
764
|
+
"add_task",
|
|
765
|
+
"split_task",
|
|
766
|
+
"merge_tasks",
|
|
767
|
+
"copy_task",
|
|
768
|
+
"transfer_task",
|
|
769
|
+
"get_task",
|
|
770
|
+
"start_task",
|
|
771
|
+
"update_task",
|
|
772
|
+
"transition_task",
|
|
773
|
+
"repair_managed_projection",
|
|
774
|
+
"move_task",
|
|
775
|
+
"delete_task",
|
|
776
|
+
"set_chain",
|
|
777
|
+
"get_chain",
|
|
778
|
+
"claim_task",
|
|
779
|
+
"release_task",
|
|
780
|
+
"assign_task",
|
|
781
|
+
"mark_assignment",
|
|
782
|
+
"heartbeat_assignment",
|
|
783
|
+
"recover_stale",
|
|
784
|
+
"events",
|
|
785
|
+
"queue_health",
|
|
786
|
+
"add_dependency",
|
|
787
|
+
"add_goal_metric",
|
|
788
|
+
"update_goal_metric",
|
|
789
|
+
"add_check",
|
|
790
|
+
"update_check",
|
|
791
|
+
"remove_check",
|
|
792
|
+
"add_note",
|
|
793
|
+
"add_link",
|
|
794
|
+
"verify_completion",
|
|
795
|
+
"split_atomic",
|
|
796
|
+
"assess_atomicity",
|
|
797
|
+
"propose_decomposition",
|
|
798
|
+
"get_contract_graph",
|
|
799
|
+
"configure_contract_graph",
|
|
800
|
+
"upsert_contract_node",
|
|
801
|
+
"remove_contract_node",
|
|
802
|
+
"add_contract_edge",
|
|
803
|
+
"remove_contract_edge"
|
|
804
|
+
]
|
|
805
|
+
},
|
|
806
|
+
boardId: { type: "string" },
|
|
807
|
+
taskId: { type: "string" },
|
|
808
|
+
taskIds: { type: "array", items: { type: "string" } },
|
|
809
|
+
chainId: { type: "string" },
|
|
810
|
+
fromNodeId: { type: "string" },
|
|
811
|
+
toNodeId: { type: "string" },
|
|
812
|
+
baseline: { oneOf: [{ type: "string" }, { type: "number" }] },
|
|
813
|
+
threshold: { oneOf: [{ type: "string" }, { type: "number" }] },
|
|
814
|
+
columnId: { type: "string" },
|
|
815
|
+
targetBoardId: { type: "string" },
|
|
816
|
+
targetColumnId: { type: "string" },
|
|
817
|
+
title: { type: "string" },
|
|
818
|
+
description: { type: "string" },
|
|
819
|
+
dueDate: { type: "string" },
|
|
820
|
+
tags: { type: "array", items: { type: "string" } },
|
|
821
|
+
labels: { type: "array", items: { type: "string" } },
|
|
822
|
+
priority: { type: "string", enum: ["critical", "high", "medium", "low"] },
|
|
823
|
+
taskType: {
|
|
824
|
+
type: "string",
|
|
825
|
+
enum: ["feature", "bugfix", "refactor", "docs", "test", "chore"]
|
|
826
|
+
},
|
|
827
|
+
status: {
|
|
828
|
+
type: "string",
|
|
829
|
+
enum: [
|
|
830
|
+
"pending",
|
|
831
|
+
"ready",
|
|
832
|
+
"in_progress",
|
|
833
|
+
"blocked",
|
|
834
|
+
"review",
|
|
835
|
+
"completed",
|
|
836
|
+
"failed",
|
|
837
|
+
"archived"
|
|
838
|
+
]
|
|
839
|
+
},
|
|
840
|
+
order: { type: "number" },
|
|
841
|
+
query: { type: "string" },
|
|
842
|
+
limit: { type: "number" },
|
|
843
|
+
agentId: { type: "string" },
|
|
844
|
+
name: { type: "string" },
|
|
845
|
+
role: { type: "string" },
|
|
846
|
+
provider: { type: "string" },
|
|
847
|
+
model: { type: "string" },
|
|
848
|
+
fallbackProfile: { type: "string" },
|
|
849
|
+
fallbackModels: { type: "array", items: { type: "string" } },
|
|
850
|
+
tools: { type: "array", items: { type: "string" } },
|
|
851
|
+
allowedCapabilities: { type: "array", items: { type: "string" } },
|
|
852
|
+
leaseId: { type: "string" },
|
|
853
|
+
claimedAt: { type: "string" },
|
|
854
|
+
heartbeatAt: { type: "string" },
|
|
855
|
+
leaseExpiresAt: { type: "string" },
|
|
856
|
+
attempt: { type: "number" },
|
|
857
|
+
maxAttempts: { type: "number" },
|
|
858
|
+
subagentId: { type: "string" },
|
|
859
|
+
runTaskId: { type: "string" },
|
|
860
|
+
lastResult: { type: "string" },
|
|
861
|
+
error: { type: "string" },
|
|
862
|
+
expectedLeaseId: { type: "string" },
|
|
863
|
+
assignmentStatus: {
|
|
864
|
+
type: "string",
|
|
865
|
+
enum: ["assigned", "queued", "running", "completed", "failed", "cancelled"]
|
|
866
|
+
},
|
|
867
|
+
lifecycleStage: {
|
|
868
|
+
type: "string",
|
|
869
|
+
enum: ["backlog", "todo", "running", "review", "done"]
|
|
870
|
+
},
|
|
871
|
+
transitionAction: { type: "string" },
|
|
872
|
+
transitionComment: { type: "string" },
|
|
873
|
+
attachmentUrl: { type: "string" },
|
|
874
|
+
attachmentTitle: { type: "string" },
|
|
875
|
+
attachmentType: {
|
|
876
|
+
type: "string",
|
|
877
|
+
enum: ["issue", "pr", "doc", "commit", "design", "file", "url", "other"]
|
|
878
|
+
},
|
|
879
|
+
releaseStatus: { type: "string", enum: ["pending", "ready", "blocked"] },
|
|
880
|
+
releaseReason: { type: "string" },
|
|
881
|
+
clearAssignee: { type: "boolean" },
|
|
882
|
+
recoveryMode: { type: "string", enum: ["auto", "release", "retry", "fail"] },
|
|
883
|
+
recoveryNow: { type: "string" },
|
|
884
|
+
recoveryPolicyFailOnCostCeiling: { type: "boolean" },
|
|
885
|
+
recoveryPolicyReleaseOnFailureKinds: { type: "array", items: { type: "string" } },
|
|
886
|
+
recoveryPolicyReleaseOnHeartbeatDue: { type: "boolean" },
|
|
887
|
+
recoveryPolicyRetryPolicyOverride: {
|
|
888
|
+
type: "string",
|
|
889
|
+
enum: ["off", "incremental", "exponential"]
|
|
890
|
+
},
|
|
891
|
+
assignee: { type: "string" },
|
|
892
|
+
costCeilingUsd: { type: "number" },
|
|
893
|
+
retryPolicy: { type: "string", enum: ["off", "incremental", "exponential"] },
|
|
894
|
+
lastFailureKind: { type: "string" },
|
|
895
|
+
dependsOn: {
|
|
896
|
+
type: "array",
|
|
897
|
+
items: { type: "string" },
|
|
898
|
+
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."
|
|
899
|
+
},
|
|
900
|
+
atomic: {
|
|
901
|
+
type: "boolean",
|
|
902
|
+
description: "Composite parent (true) or executable leaf (false). Set false to make a stranded parent a leaf again after its children were dropped."
|
|
903
|
+
},
|
|
904
|
+
childTaskIds: {
|
|
905
|
+
type: "array",
|
|
906
|
+
items: { type: "string" },
|
|
907
|
+
description: "Children of a composite parent. On update_task an explicit empty array detaches them all."
|
|
908
|
+
},
|
|
909
|
+
estimatedHours: { type: "number" },
|
|
910
|
+
actualHours: { type: "number" },
|
|
911
|
+
taskGraph: { type: "object" },
|
|
912
|
+
graphId: { type: "string" },
|
|
913
|
+
specId: { type: "string" },
|
|
914
|
+
specRequirementId: { type: "string" },
|
|
915
|
+
sourceSystem: { type: "string" },
|
|
916
|
+
phaseId: { type: "string" },
|
|
917
|
+
preserveOriginTaskIds: { type: "boolean" },
|
|
918
|
+
includeArchived: { type: "boolean" },
|
|
919
|
+
archiveMissingTasks: { type: "boolean" },
|
|
920
|
+
preserveManualDependencies: { type: "boolean" },
|
|
921
|
+
dependencyTaskId: { type: "string" },
|
|
922
|
+
enforceDependencies: { type: "boolean" },
|
|
923
|
+
childTitles: { type: "array", items: { type: "string" } },
|
|
924
|
+
inheritAssignment: { type: "boolean" },
|
|
925
|
+
inheritLabels: { type: "boolean" },
|
|
926
|
+
inheritSuccessCriteria: { type: "boolean" },
|
|
927
|
+
inheritGoalMetrics: { type: "boolean" },
|
|
928
|
+
inheritDependencies: { type: "boolean" },
|
|
929
|
+
chainChildren: { type: "boolean" },
|
|
930
|
+
rewireDependents: { type: "boolean" },
|
|
931
|
+
closeSourceTasks: { type: "boolean" },
|
|
932
|
+
metricId: { type: "string" },
|
|
933
|
+
metricName: { type: "string" },
|
|
934
|
+
metricTarget: { oneOf: [{ type: "string" }, { type: "number" }] },
|
|
935
|
+
metricCurrent: { oneOf: [{ type: "string" }, { type: "number" }] },
|
|
936
|
+
metricUnit: { type: "string" },
|
|
937
|
+
metricStatus: { type: "string", enum: ["pending", "met", "missed", "waived"] },
|
|
938
|
+
metricNotes: { type: "string" },
|
|
939
|
+
checkId: { type: "string" },
|
|
940
|
+
checkDescription: { type: "string" },
|
|
941
|
+
checkStatus: { type: "string", enum: ["pending", "passed", "failed", "skipped"] },
|
|
942
|
+
checkType: {
|
|
943
|
+
type: "string",
|
|
944
|
+
// Only types a verifier can actually execute. `manual` is the default and
|
|
945
|
+
// means a human or agent asserts the status by hand. The rest are run by
|
|
946
|
+
// `verify_completion` against the default deterministic registry. Types
|
|
947
|
+
// with no plugin in that registry (`auto`, `review`, `agent`, `council`)
|
|
948
|
+
// are deliberately omitted: offering them would produce criteria that
|
|
949
|
+
// silently report `skipped — no verifier plugin registered`.
|
|
950
|
+
enum: ["manual", "command", "test", "file_exists", "file_matches", "git_diff", "metric"],
|
|
951
|
+
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.'
|
|
952
|
+
},
|
|
953
|
+
checkNotes: {
|
|
954
|
+
type: "string",
|
|
955
|
+
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"}.'
|
|
956
|
+
},
|
|
957
|
+
// ── Contract map ───────────────────────────────────────────────────
|
|
958
|
+
// The card contract: what this work targets, what it must not break, what
|
|
959
|
+
// it risks, and what verifies it. Advisory by default — the readiness gate
|
|
960
|
+
// deliberately does not require map structure, so a map is an operator
|
|
961
|
+
// review aid, not work the model must complete before implementing.
|
|
962
|
+
contractEnforcement: {
|
|
963
|
+
type: "string",
|
|
964
|
+
enum: ["off", "advisory", "strict"],
|
|
965
|
+
description: "Board-level contract map enforcement. Default when first configured: advisory."
|
|
966
|
+
},
|
|
967
|
+
contractNodeId: { type: "string" },
|
|
968
|
+
contractNodeKind: {
|
|
969
|
+
type: "string",
|
|
970
|
+
enum: ["objective", "guardrail", "risk", "component", "artifact", "verification"],
|
|
971
|
+
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."
|
|
972
|
+
},
|
|
973
|
+
contractNodeTitle: { type: "string" },
|
|
974
|
+
contractNodeDescription: { type: "string" },
|
|
975
|
+
contractNodeState: {
|
|
976
|
+
type: "string",
|
|
977
|
+
enum: ["unknown", "active", "satisfied", "violated", "waived", "resolved"]
|
|
978
|
+
},
|
|
979
|
+
contractNodeEnforcement: {
|
|
980
|
+
type: "string",
|
|
981
|
+
enum: ["blocking", "advisory", "informational"]
|
|
982
|
+
},
|
|
983
|
+
/** Bind a node to an acceptance criterion or goal metric already on the task. */
|
|
984
|
+
contractCheckId: { type: "string" },
|
|
985
|
+
contractMetricId: { type: "string" },
|
|
986
|
+
contractWaiverReason: {
|
|
987
|
+
type: "string",
|
|
988
|
+
description: 'Required, with an actor, when contractNodeState is "waived".'
|
|
989
|
+
},
|
|
990
|
+
contractEdgeId: { type: "string" },
|
|
991
|
+
contractEdgeFrom: {
|
|
992
|
+
type: "string",
|
|
993
|
+
description: 'A contract node id, or a task id (bare or "task:<id>") for the card endpoint.'
|
|
994
|
+
},
|
|
995
|
+
contractEdgeTo: { type: "string" },
|
|
996
|
+
contractEdgeType: {
|
|
997
|
+
type: "string",
|
|
998
|
+
enum: [
|
|
999
|
+
"targets",
|
|
1000
|
+
"affects",
|
|
1001
|
+
"must_preserve",
|
|
1002
|
+
"exposes",
|
|
1003
|
+
"verified_by",
|
|
1004
|
+
"conflicts_with",
|
|
1005
|
+
"derived_from",
|
|
1006
|
+
"relates_to"
|
|
1007
|
+
]
|
|
1008
|
+
},
|
|
1009
|
+
contractEdgeRationale: { type: "string" },
|
|
1010
|
+
note: { type: "string" },
|
|
1011
|
+
author: { type: "string" },
|
|
1012
|
+
url: { type: "string" },
|
|
1013
|
+
linkTitle: { type: "string" },
|
|
1014
|
+
linkType: {
|
|
1015
|
+
type: "string",
|
|
1016
|
+
enum: ["issue", "pr", "doc", "commit", "design", "file", "url", "other"]
|
|
1017
|
+
},
|
|
1018
|
+
context: { type: "string" },
|
|
1019
|
+
columns: { type: "array", items: { type: "string" } },
|
|
1020
|
+
generatedBy: { type: "string" },
|
|
1021
|
+
includeTasks: { type: "boolean" },
|
|
1022
|
+
includeCompletedTasks: { type: "boolean" },
|
|
1023
|
+
preserveAssignment: { type: "boolean" },
|
|
1024
|
+
preserveDependencies: { type: "boolean" },
|
|
1025
|
+
moveTasksToColumnId: { type: "string" },
|
|
1026
|
+
atomicityMode: { type: "string", enum: ["off", "assess", "enforce"] },
|
|
1027
|
+
atomicityDecomposition: { type: "string", enum: ["auto", "propose"] },
|
|
1028
|
+
gateEnforcement: {
|
|
1029
|
+
type: "string",
|
|
1030
|
+
// WS-023: `'off'` is deliberately absent. The agent whose work this gate
|
|
1031
|
+
// checks must not be able to switch it off; it may only tighten. Turning
|
|
1032
|
+
// a gate off stays a human decision, made through board config.
|
|
1033
|
+
enum: ["strict", "soft"]
|
|
1034
|
+
},
|
|
1035
|
+
subtasks: {
|
|
1036
|
+
type: "array",
|
|
1037
|
+
minItems: 2,
|
|
1038
|
+
items: {
|
|
1039
|
+
type: "object",
|
|
1040
|
+
properties: {
|
|
1041
|
+
title: { type: "string" },
|
|
1042
|
+
description: { type: "string" },
|
|
1043
|
+
successCriteria: { type: "array", items: { type: "string" } },
|
|
1044
|
+
dependsOnIndex: { type: "array", items: { type: "number" } }
|
|
1045
|
+
},
|
|
1046
|
+
required: ["title"]
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
},
|
|
1050
|
+
required: ["action"]
|
|
1051
|
+
};
|
|
3
1052
|
|
|
4
1053
|
// src/session-kanban.ts
|
|
5
1054
|
import { getSharedProjectMailbox } from "@wrongstack/core/coordination";
|
|
@@ -10,35 +1059,66 @@ import {
|
|
|
10
1059
|
mutateTasks
|
|
11
1060
|
} from "@wrongstack/core/storage";
|
|
12
1061
|
import { deserializeTaskGraph } from "@wrongstack/core/tasking";
|
|
13
|
-
import { resolveWstackPaths } from "@wrongstack/core/utils";
|
|
1062
|
+
import { formatTodosForModel, resolveWstackPaths } from "@wrongstack/core/utils";
|
|
14
1063
|
import {
|
|
15
1064
|
bridgeKanbanSupervisor,
|
|
1065
|
+
compactSessionMirrorBoard,
|
|
16
1066
|
createBoard,
|
|
17
|
-
|
|
1067
|
+
DEFAULT_COLUMNS,
|
|
1068
|
+
getBoard as getBoard2,
|
|
1069
|
+
getDependencyReadinessIssues,
|
|
1070
|
+
getKanbanOrchestrationSnapshot,
|
|
18
1071
|
listBoards,
|
|
1072
|
+
pruneSessionBoards,
|
|
19
1073
|
removeBoard,
|
|
20
1074
|
syncBoardFromTaskGraph,
|
|
21
|
-
touchKanbanPresence,
|
|
1075
|
+
touchKanbanPresence as touchKanbanPresence2,
|
|
22
1076
|
updateBoard
|
|
23
1077
|
} from "@wrongstack/kanban";
|
|
24
1078
|
var SESSION_BOARD_TAG = "session-work";
|
|
25
1079
|
var MIRROR_DISABLED_ENV = "WRONGSTACK_KANBAN_TASK_MIRROR";
|
|
26
|
-
var SESSION_KANBAN_COLUMNS =
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
{ id: "review", title: "Preview", order: 2, wipLimit: 0, color: "#7c3aed" },
|
|
30
|
-
{ id: "done", title: "Done", order: 3, wipLimit: 0, color: "#16a34a" }
|
|
31
|
-
];
|
|
1080
|
+
var SESSION_KANBAN_COLUMNS = DEFAULT_COLUMNS.map((column) => ({
|
|
1081
|
+
...column
|
|
1082
|
+
}));
|
|
32
1083
|
var boardQueue = /* @__PURE__ */ new Map();
|
|
33
1084
|
var boardEnsures = /* @__PURE__ */ new Map();
|
|
34
1085
|
var pendingMirrors = /* @__PURE__ */ new Map();
|
|
35
1086
|
var activeMirrors = /* @__PURE__ */ new Set();
|
|
1087
|
+
var mirrorFailures = /* @__PURE__ */ new Map();
|
|
1088
|
+
var suppressedTodoMirrors = /* @__PURE__ */ new WeakSet();
|
|
36
1089
|
function boardKey(projectRoot, sessionId) {
|
|
37
1090
|
return `${projectRoot}\0${sessionId}`;
|
|
38
1091
|
}
|
|
39
1092
|
function mirrorKey(projectRoot, sessionId, sourceSystem) {
|
|
40
1093
|
return `${boardKey(projectRoot, sessionId)}\0${sourceSystem}`;
|
|
41
1094
|
}
|
|
1095
|
+
function completedReconciliationGraph(latest, candidates) {
|
|
1096
|
+
const latestNodeIds = new Set(latest.nodes.map((node) => node.id));
|
|
1097
|
+
const carriedNodeIds = /* @__PURE__ */ new Set();
|
|
1098
|
+
const completedNodes = candidates.flatMap(
|
|
1099
|
+
(candidate) => candidate.nodes.filter((node) => {
|
|
1100
|
+
if (node.status !== "completed" || latestNodeIds.has(node.id) || carriedNodeIds.has(node.id)) {
|
|
1101
|
+
return false;
|
|
1102
|
+
}
|
|
1103
|
+
carriedNodeIds.add(node.id);
|
|
1104
|
+
return true;
|
|
1105
|
+
})
|
|
1106
|
+
);
|
|
1107
|
+
if (completedNodes.length === 0) return void 0;
|
|
1108
|
+
const carriedRequirements = completedNodes.flatMap(
|
|
1109
|
+
(node) => node.specRequirementId ? [node.specRequirementId] : []
|
|
1110
|
+
);
|
|
1111
|
+
return {
|
|
1112
|
+
...latest,
|
|
1113
|
+
nodes: [...latest.nodes, ...completedNodes],
|
|
1114
|
+
rootNodes: [.../* @__PURE__ */ new Set([...latest.rootNodes, ...completedNodes.map((node) => node.id)])],
|
|
1115
|
+
...latest.requiredRequirementIds ? {
|
|
1116
|
+
requiredRequirementIds: [
|
|
1117
|
+
.../* @__PURE__ */ new Set([...latest.requiredRequirementIds, ...carriedRequirements])
|
|
1118
|
+
]
|
|
1119
|
+
} : {}
|
|
1120
|
+
};
|
|
1121
|
+
}
|
|
42
1122
|
function sessionTag(sessionId) {
|
|
43
1123
|
return `session:${sessionId}`;
|
|
44
1124
|
}
|
|
@@ -61,7 +1141,7 @@ async function ensureSessionKanbanBoard(projectRoot, sessionId) {
|
|
|
61
1141
|
const summary = (await listBoards(projectRoot)).find(
|
|
62
1142
|
(board2) => board2.tags?.includes(sessionTag(sessionId))
|
|
63
1143
|
);
|
|
64
|
-
let board = summary ? await
|
|
1144
|
+
let board = summary ? await getBoard2(projectRoot, summary.id) : null;
|
|
65
1145
|
if (!board) {
|
|
66
1146
|
return createBoard(projectRoot, {
|
|
67
1147
|
title: sessionBoardTitle(sessionId),
|
|
@@ -117,16 +1197,44 @@ async function projectGraph(projectRoot, sessionId, graph, sourceSystem) {
|
|
|
117
1197
|
sourceSystem,
|
|
118
1198
|
tags: [.../* @__PURE__ */ new Set([...board.tags ?? [], ...sessionBoardTags(sessionId)])],
|
|
119
1199
|
archiveMissingTasks: true,
|
|
120
|
-
includeCompletedTasks: true
|
|
1200
|
+
includeCompletedTasks: true,
|
|
1201
|
+
// The scope ledger stays declared and accurate, but it may not veto a
|
|
1202
|
+
// projection. A session mirror reflects a tactical list that shrinks by
|
|
1203
|
+
// design, and refusing the sync never protected the removed row — it
|
|
1204
|
+
// froze the entire board, permanently, because the stored scope then
|
|
1205
|
+
// outlived every later snapshot (`session-kanban.mirror-failed`).
|
|
1206
|
+
// Nothing is lost by shrinking here: `archiveMissingTasks` keeps the
|
|
1207
|
+
// removed card on the board as `archived`, the reconciliation pass
|
|
1208
|
+
// first walks vanished completed rows to Done, and the session journal
|
|
1209
|
+
// remains the durable record.
|
|
1210
|
+
allowRequirementScopeShrink: true
|
|
121
1211
|
}
|
|
122
1212
|
);
|
|
123
|
-
|
|
1213
|
+
if (!result) return null;
|
|
1214
|
+
const compacted = await compactSessionMirrorBoard(projectRoot, board.id);
|
|
1215
|
+
if (compacted?.removedTaskIds.length) {
|
|
1216
|
+
return await getBoard2(projectRoot, board.id) ?? result.board;
|
|
1217
|
+
}
|
|
1218
|
+
return result.board;
|
|
124
1219
|
});
|
|
125
1220
|
}
|
|
126
1221
|
function queueLatestMirror(projectRoot, sessionId, graph, sourceSystem) {
|
|
127
1222
|
if (!projectRoot || !sessionId || process.env[MIRROR_DISABLED_ENV] === "0") return;
|
|
128
1223
|
const key = mirrorKey(projectRoot, sessionId, sourceSystem);
|
|
129
|
-
pendingMirrors.
|
|
1224
|
+
const previous = pendingMirrors.get(key);
|
|
1225
|
+
const reconciliationGraph = previous ? completedReconciliationGraph(
|
|
1226
|
+
graph,
|
|
1227
|
+
[previous.reconciliationGraph, previous.graph].filter(
|
|
1228
|
+
(candidate) => candidate !== void 0
|
|
1229
|
+
)
|
|
1230
|
+
) : void 0;
|
|
1231
|
+
pendingMirrors.set(key, {
|
|
1232
|
+
projectRoot,
|
|
1233
|
+
sessionId,
|
|
1234
|
+
graph,
|
|
1235
|
+
...reconciliationGraph ? { reconciliationGraph } : {},
|
|
1236
|
+
sourceSystem
|
|
1237
|
+
});
|
|
130
1238
|
if (activeMirrors.has(key)) return;
|
|
131
1239
|
activeMirrors.add(key);
|
|
132
1240
|
void (async () => {
|
|
@@ -136,13 +1244,37 @@ function queueLatestMirror(projectRoot, sessionId, graph, sourceSystem) {
|
|
|
136
1244
|
if (!pending) break;
|
|
137
1245
|
pendingMirrors.delete(key);
|
|
138
1246
|
try {
|
|
1247
|
+
if (pending.reconciliationGraph) {
|
|
1248
|
+
await projectGraph(
|
|
1249
|
+
pending.projectRoot,
|
|
1250
|
+
pending.sessionId,
|
|
1251
|
+
pending.reconciliationGraph,
|
|
1252
|
+
pending.sourceSystem
|
|
1253
|
+
);
|
|
1254
|
+
}
|
|
139
1255
|
await projectGraph(
|
|
140
1256
|
pending.projectRoot,
|
|
141
1257
|
pending.sessionId,
|
|
142
1258
|
pending.graph,
|
|
143
1259
|
pending.sourceSystem
|
|
144
1260
|
);
|
|
145
|
-
|
|
1261
|
+
mirrorFailures.delete(boardKey(pending.projectRoot, pending.sessionId));
|
|
1262
|
+
} catch (error) {
|
|
1263
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1264
|
+
mirrorFailures.set(boardKey(pending.projectRoot, pending.sessionId), {
|
|
1265
|
+
message,
|
|
1266
|
+
sourceSystem: pending.sourceSystem
|
|
1267
|
+
});
|
|
1268
|
+
console.warn(
|
|
1269
|
+
JSON.stringify({
|
|
1270
|
+
level: "warn",
|
|
1271
|
+
event: "session-kanban.mirror-failed",
|
|
1272
|
+
sessionId: pending.sessionId,
|
|
1273
|
+
sourceSystem: pending.sourceSystem,
|
|
1274
|
+
message,
|
|
1275
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
1276
|
+
})
|
|
1277
|
+
);
|
|
146
1278
|
}
|
|
147
1279
|
}
|
|
148
1280
|
} finally {
|
|
@@ -160,7 +1292,16 @@ function queueLatestMirror(projectRoot, sessionId, graph, sourceSystem) {
|
|
|
160
1292
|
}
|
|
161
1293
|
})();
|
|
162
1294
|
}
|
|
1295
|
+
function takeSessionMirrorFailure(projectRoot, sessionId) {
|
|
1296
|
+
if (!projectRoot || !sessionId) return void 0;
|
|
1297
|
+
const key = boardKey(projectRoot, sessionId);
|
|
1298
|
+
const failure = mirrorFailures.get(key);
|
|
1299
|
+
if (!failure) return void 0;
|
|
1300
|
+
mirrorFailures.delete(key);
|
|
1301
|
+
return `Kanban mirror (${failure.sourceSystem}) failed and the board may be stale: ${failure.message}`;
|
|
1302
|
+
}
|
|
163
1303
|
function todoListToSerializedGraph(todos, sessionId) {
|
|
1304
|
+
const graphId = `todo:${sessionId}`;
|
|
164
1305
|
const nodes = todos.map((todo, index) => ({
|
|
165
1306
|
id: todo.id,
|
|
166
1307
|
title: todo.content,
|
|
@@ -168,12 +1309,14 @@ function todoListToSerializedGraph(todos, sessionId) {
|
|
|
168
1309
|
type: "chore",
|
|
169
1310
|
priority: "medium",
|
|
170
1311
|
status: todo.status,
|
|
1312
|
+
specRequirementId: `${graphId}:${todo.id}`,
|
|
171
1313
|
createdAt: index,
|
|
172
1314
|
updatedAt: index
|
|
173
1315
|
}));
|
|
174
1316
|
return {
|
|
175
|
-
id:
|
|
176
|
-
specId:
|
|
1317
|
+
id: graphId,
|
|
1318
|
+
specId: graphId,
|
|
1319
|
+
requiredRequirementIds: nodes.map((node) => node.specRequirementId),
|
|
177
1320
|
title: "Session todos",
|
|
178
1321
|
nodes,
|
|
179
1322
|
edges: [],
|
|
@@ -182,6 +1325,87 @@ function todoListToSerializedGraph(todos, sessionId) {
|
|
|
182
1325
|
updatedAt: 0
|
|
183
1326
|
};
|
|
184
1327
|
}
|
|
1328
|
+
function taskFileToSerializedGraph(tasks, sessionId) {
|
|
1329
|
+
const graphId = `session:${sessionId}`;
|
|
1330
|
+
const ids = new Set(tasks.map((task) => task.id));
|
|
1331
|
+
const nodes = tasks.map((task, index) => ({
|
|
1332
|
+
id: task.id,
|
|
1333
|
+
title: task.title,
|
|
1334
|
+
description: task.description ?? "",
|
|
1335
|
+
type: task.type,
|
|
1336
|
+
priority: task.priority,
|
|
1337
|
+
status: task.status,
|
|
1338
|
+
specRequirementId: `${graphId}:${task.id}`,
|
|
1339
|
+
...task.assignee ? { assignee: task.assignee } : {},
|
|
1340
|
+
...task.estimateHours !== void 0 ? { estimateHours: task.estimateHours } : {},
|
|
1341
|
+
createdAt: index,
|
|
1342
|
+
updatedAt: index
|
|
1343
|
+
}));
|
|
1344
|
+
const edges = tasks.flatMap(
|
|
1345
|
+
(task) => (task.dependsOn ?? []).filter((dependency) => ids.has(dependency)).map((dependency) => ({
|
|
1346
|
+
id: `${dependency}->${task.id}`,
|
|
1347
|
+
from: dependency,
|
|
1348
|
+
to: task.id,
|
|
1349
|
+
type: "depends_on"
|
|
1350
|
+
}))
|
|
1351
|
+
);
|
|
1352
|
+
const hasIncoming = new Set(edges.map((edge) => edge.to));
|
|
1353
|
+
const rootNodes = nodes.filter((node) => !hasIncoming.has(node.id)).map((node) => node.id);
|
|
1354
|
+
return {
|
|
1355
|
+
// Keep the historical graph id so existing mirrored task cards are reused.
|
|
1356
|
+
id: graphId,
|
|
1357
|
+
specId: graphId,
|
|
1358
|
+
requiredRequirementIds: nodes.map((node) => node.specRequirementId),
|
|
1359
|
+
title: "Session tasks",
|
|
1360
|
+
nodes,
|
|
1361
|
+
edges,
|
|
1362
|
+
rootNodes: rootNodes.length ? rootNodes : nodes[0] ? [nodes[0].id] : [],
|
|
1363
|
+
createdAt: 0,
|
|
1364
|
+
updatedAt: 0
|
|
1365
|
+
};
|
|
1366
|
+
}
|
|
1367
|
+
function broadcastTodoUpdate(context, todos) {
|
|
1368
|
+
const sessionId = context.session?.id ?? "";
|
|
1369
|
+
if (!context.agentId || !sessionId) return;
|
|
1370
|
+
const statusCounts = { pending: 0, inProgress: 0, completed: 0 };
|
|
1371
|
+
for (const todo of todos) {
|
|
1372
|
+
if (todo.status === "completed") statusCounts.completed++;
|
|
1373
|
+
else if (todo.status === "in_progress") statusCounts.inProgress++;
|
|
1374
|
+
else statusCounts.pending++;
|
|
1375
|
+
}
|
|
1376
|
+
const projectDir = resolveWstackPaths({ projectRoot: context.projectRoot }).projectDir;
|
|
1377
|
+
const mailbox = getSharedProjectMailbox(projectDir);
|
|
1378
|
+
void mailbox.send({
|
|
1379
|
+
from: context.agentId,
|
|
1380
|
+
to: "*",
|
|
1381
|
+
type: "status",
|
|
1382
|
+
subject: `Kanban todo list updated (${todos.length} item${todos.length === 1 ? "" : "s"})`,
|
|
1383
|
+
body: JSON.stringify({
|
|
1384
|
+
kind: "kanban.todos.updated",
|
|
1385
|
+
sessionId,
|
|
1386
|
+
revision: context.state.revision,
|
|
1387
|
+
todoCount: todos.length,
|
|
1388
|
+
statusCounts
|
|
1389
|
+
}),
|
|
1390
|
+
priority: "normal",
|
|
1391
|
+
senderSessionId: sessionId
|
|
1392
|
+
}).catch(() => {
|
|
1393
|
+
});
|
|
1394
|
+
}
|
|
1395
|
+
function notifyTodoUpdate(context, todos) {
|
|
1396
|
+
const summary = formatTodosForModel(todos);
|
|
1397
|
+
const text = `[KANBAN TODO UPDATE]
|
|
1398
|
+
Another Kanban agent reassessed the shared board. The canonical todo list is now:
|
|
1399
|
+
${summary}
|
|
1400
|
+
Reassess your current plan before continuing; do not rely on the initial todo snapshot. Preserve each row's <kanban board/task> binding verbatim on your next \`todo\` call \u2014 a row that loses it stops advancing its card.`;
|
|
1401
|
+
const state = context.state;
|
|
1402
|
+
if (typeof state.appendBlockToLastUserMessage === "function") {
|
|
1403
|
+
if (state.appendBlockToLastUserMessage({ type: "text", text })) return;
|
|
1404
|
+
}
|
|
1405
|
+
if (typeof state.appendMessage === "function") {
|
|
1406
|
+
state.appendMessage({ role: "user", content: [{ type: "text", text }] });
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
185
1409
|
function mirrorSessionTodosToKanban(projectRoot, todos, sessionId) {
|
|
186
1410
|
queueLatestMirror(
|
|
187
1411
|
projectRoot,
|
|
@@ -190,18 +1414,1160 @@ function mirrorSessionTodosToKanban(projectRoot, todos, sessionId) {
|
|
|
190
1414
|
"session-todo"
|
|
191
1415
|
);
|
|
192
1416
|
}
|
|
1417
|
+
function sourceStatus(task) {
|
|
1418
|
+
if (task.status === "completed") return "completed";
|
|
1419
|
+
if (task.status === "in_progress") return "in_progress";
|
|
1420
|
+
if (task.status === "review") return "review";
|
|
1421
|
+
if (task.status === "blocked") return "blocked";
|
|
1422
|
+
if (task.status === "failed") return "failed";
|
|
1423
|
+
return "pending";
|
|
1424
|
+
}
|
|
1425
|
+
function todoStatus(task) {
|
|
1426
|
+
const status = sourceStatus(task);
|
|
1427
|
+
if (status === "completed") return "completed";
|
|
1428
|
+
if (status === "in_progress" || status === "review") return "in_progress";
|
|
1429
|
+
return "pending";
|
|
1430
|
+
}
|
|
1431
|
+
function sessionTodoFromTask(task, board) {
|
|
1432
|
+
const blockedBy = board ? blockingTitles(board, task) : [];
|
|
1433
|
+
return {
|
|
1434
|
+
id: task.origin?.taskId ?? task.id,
|
|
1435
|
+
content: task.title,
|
|
1436
|
+
status: todoStatus(task),
|
|
1437
|
+
...task.description ? { activeForm: task.description } : {},
|
|
1438
|
+
...blockedBy.length ? { blockedBy } : {}
|
|
1439
|
+
};
|
|
1440
|
+
}
|
|
1441
|
+
function managedTodoFromTask(task, board) {
|
|
1442
|
+
return {
|
|
1443
|
+
...sessionTodoFromTask(task, board),
|
|
1444
|
+
kanbanBoardId: board.id,
|
|
1445
|
+
kanbanTaskId: task.id
|
|
1446
|
+
};
|
|
1447
|
+
}
|
|
1448
|
+
function blockingTitles(board, task) {
|
|
1449
|
+
return getDependencyReadinessIssues(board, task).map((issue) => {
|
|
1450
|
+
const dependency = board.tasks.find((candidate) => candidate.id === issue.dependencyId);
|
|
1451
|
+
if (!dependency) return `${issue.dependencyId} (missing)`;
|
|
1452
|
+
return dependency.title;
|
|
1453
|
+
});
|
|
1454
|
+
}
|
|
1455
|
+
var PRIORITY_ORDER = {
|
|
1456
|
+
critical: 0,
|
|
1457
|
+
high: 1,
|
|
1458
|
+
medium: 2,
|
|
1459
|
+
low: 3
|
|
1460
|
+
};
|
|
1461
|
+
function orderTasksForTodos(board, tasks) {
|
|
1462
|
+
const columnOrder = new Map(board.columns.map((column) => [column.id, column.order]));
|
|
1463
|
+
const baseline = [...tasks].sort(
|
|
1464
|
+
(left, right) => (columnOrder.get(left.columnId) ?? 0) - (columnOrder.get(right.columnId) ?? 0) || (PRIORITY_ORDER[left.priority] ?? 2) - (PRIORITY_ORDER[right.priority] ?? 2) || left.order - right.order || left.createdAt.localeCompare(right.createdAt) || left.id.localeCompare(right.id)
|
|
1465
|
+
);
|
|
1466
|
+
const included = new Set(baseline.map((task) => task.id));
|
|
1467
|
+
const remaining = new Map(baseline.map((task) => [task.id, task]));
|
|
1468
|
+
const emitted = [];
|
|
1469
|
+
const done = /* @__PURE__ */ new Set();
|
|
1470
|
+
while (remaining.size > 0) {
|
|
1471
|
+
const ready = baseline.filter(
|
|
1472
|
+
(task) => remaining.has(task.id) && (task.dependsOn ?? []).every(
|
|
1473
|
+
(dependencyId) => !included.has(dependencyId) || done.has(dependencyId)
|
|
1474
|
+
)
|
|
1475
|
+
);
|
|
1476
|
+
if (ready.length === 0) break;
|
|
1477
|
+
for (const task of ready) {
|
|
1478
|
+
remaining.delete(task.id);
|
|
1479
|
+
done.add(task.id);
|
|
1480
|
+
emitted.push(task);
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
for (const task of baseline) if (remaining.has(task.id)) emitted.push(task);
|
|
1484
|
+
return emitted;
|
|
1485
|
+
}
|
|
1486
|
+
function sameTodos(left, right) {
|
|
1487
|
+
return left.length === right.length && left.every((todo, index) => {
|
|
1488
|
+
const candidate = right[index];
|
|
1489
|
+
return candidate?.id === todo.id && candidate.content === todo.content && candidate.status === todo.status && candidate.activeForm === todo.activeForm && candidate.promotedFromPlan === todo.promotedFromPlan && candidate.promotedFromTask === todo.promotedFromTask && candidate.kanbanBoardId === todo.kanbanBoardId && candidate.kanbanTaskId === todo.kanbanTaskId && // Readiness is part of the projection: when a dependency completes,
|
|
1490
|
+
// the rows are otherwise identical and the unblocking would never
|
|
1491
|
+
// reach the model.
|
|
1492
|
+
(candidate.blockedBy ?? []).join("\0") === (todo.blockedBy ?? []).join("\0");
|
|
1493
|
+
});
|
|
1494
|
+
}
|
|
1495
|
+
function applyManagedKanbanBoardToTodos(context, board) {
|
|
1496
|
+
const metaKanban = context.meta["kanban"];
|
|
1497
|
+
const metaBoardId = metaKanban && typeof metaKanban === "object" ? metaKanban["boardId"] : void 0;
|
|
1498
|
+
const activeBoardId2 = context.currentKanbanBoardId ?? (typeof metaBoardId === "string" ? metaBoardId : void 0);
|
|
1499
|
+
if (!activeBoardId2 || board.id !== activeBoardId2 || board.lifecycle?.mode !== "managed") {
|
|
1500
|
+
return [...context.todos];
|
|
1501
|
+
}
|
|
1502
|
+
const projectedTodos = orderTasksForTodos(
|
|
1503
|
+
board,
|
|
1504
|
+
board.tasks.filter(
|
|
1505
|
+
(task) => task.status !== "archived" && task.mergedIntoTaskId === void 0 && (!task.childTaskIds || task.childTaskIds.length === 0)
|
|
1506
|
+
)
|
|
1507
|
+
).map((task) => managedTodoFromTask(task, board));
|
|
1508
|
+
if (sameTodos(context.todos, projectedTodos)) return [...context.todos];
|
|
1509
|
+
suppressedTodoMirrors.add(context);
|
|
1510
|
+
try {
|
|
1511
|
+
context.state.replaceTodos(projectedTodos);
|
|
1512
|
+
} finally {
|
|
1513
|
+
suppressedTodoMirrors.delete(context);
|
|
1514
|
+
}
|
|
1515
|
+
notifyTodoUpdate(context, context.todos);
|
|
1516
|
+
broadcastTodoUpdate(context, context.todos);
|
|
1517
|
+
return [...context.todos];
|
|
1518
|
+
}
|
|
1519
|
+
|
|
1520
|
+
// src/kanban.ts
|
|
1521
|
+
var kanbanTool = {
|
|
1522
|
+
name: "kanban",
|
|
1523
|
+
category: "Project",
|
|
1524
|
+
description: KANBAN_TOOL_DESCRIPTION,
|
|
1525
|
+
usageHint: KANBAN_TOOL_USAGE_HINT,
|
|
1526
|
+
permission: "confirm",
|
|
1527
|
+
mutating: true,
|
|
1528
|
+
capabilities: ["fs.write"],
|
|
1529
|
+
icon: "task",
|
|
1530
|
+
timeoutMs: 3e4,
|
|
1531
|
+
inputSchema: KANBAN_INPUT_SCHEMA,
|
|
1532
|
+
async execute(input, ctx) {
|
|
1533
|
+
const projectRoot = ctx.projectRoot;
|
|
1534
|
+
if (!projectRoot) return fail("No project root is available.");
|
|
1535
|
+
const withPresence = createKanbanPresenceWrapper(projectRoot, input, ctx);
|
|
1536
|
+
try {
|
|
1537
|
+
const result = await (async () => {
|
|
1538
|
+
const decompositionResult = await handleKanbanDecompositionAction(projectRoot, input, ctx);
|
|
1539
|
+
if (decompositionResult !== void 0) return decompositionResult;
|
|
1540
|
+
switch (input.action) {
|
|
1541
|
+
case "list_boards": {
|
|
1542
|
+
const boards = await listBoards2(projectRoot);
|
|
1543
|
+
return { ok: true, message: `${boards.length} board(s).`, boards };
|
|
1544
|
+
}
|
|
1545
|
+
case "get_board": {
|
|
1546
|
+
const board = await requireBoard(projectRoot, input.boardId);
|
|
1547
|
+
return board ? okBoard(board) : fail("Board not found.");
|
|
1548
|
+
}
|
|
1549
|
+
case "create_board": {
|
|
1550
|
+
if (!input.title) return fail("create_board requires title.");
|
|
1551
|
+
const existing = (await listBoards2(projectRoot)).filter(
|
|
1552
|
+
(candidate) => (candidate.kind ?? "project") === "project"
|
|
1553
|
+
);
|
|
1554
|
+
const board = await createBoard2(projectRoot, boardCreateInput(input, input.title));
|
|
1555
|
+
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(
|
|
1556
|
+
", "
|
|
1557
|
+
)}${existing.length > 3 ? ", \u2026" : ""}. If this work belongs to one of them, add_task there instead and delete this board.` : "";
|
|
1558
|
+
return { ok: true, message: `Board created: ${board.title}.${note}`, board };
|
|
1559
|
+
}
|
|
1560
|
+
case "update_board": {
|
|
1561
|
+
if (!input.boardId) return fail("update_board requires boardId.");
|
|
1562
|
+
const board = await updateBoard2(projectRoot, input.boardId, boardUpdatePatch(input));
|
|
1563
|
+
return board ? okBoard(board, "Board updated.") : fail("Board not found.");
|
|
1564
|
+
}
|
|
1565
|
+
case "adopt_managed_lifecycle": {
|
|
1566
|
+
if (!input.boardId || !input.author || !input.transitionComment) {
|
|
1567
|
+
return fail(
|
|
1568
|
+
"adopt_managed_lifecycle requires boardId, author, transitionComment, and five ordered columns."
|
|
1569
|
+
);
|
|
1570
|
+
}
|
|
1571
|
+
if (input.columns?.length !== 5) {
|
|
1572
|
+
return fail(
|
|
1573
|
+
"adopt_managed_lifecycle columns must be ordered as backlog, todo, running, review, done."
|
|
1574
|
+
);
|
|
1575
|
+
}
|
|
1576
|
+
const [backlog, todo, running, review, done] = input.columns;
|
|
1577
|
+
if (!backlog || !todo || !running || !review || !done) {
|
|
1578
|
+
return fail("adopt_managed_lifecycle columns must contain five nonblank ids.");
|
|
1579
|
+
}
|
|
1580
|
+
const board = await adoptManagedLifecycle(projectRoot, input.boardId, {
|
|
1581
|
+
columns: { backlog, todo, running, review, done },
|
|
1582
|
+
actor: input.author,
|
|
1583
|
+
comment: input.transitionComment
|
|
1584
|
+
});
|
|
1585
|
+
return board ? okBoard(board, "Managed lifecycle adopted without moving existing cards.") : fail("Board not found.");
|
|
1586
|
+
}
|
|
1587
|
+
// Adoption used to be a one-way door: the strict lifecycle carries
|
|
1588
|
+
// acceptance-criteria, verification-report, review-evidence and
|
|
1589
|
+
// one-stage-at-a-time gates, and nothing on the tool surface could
|
|
1590
|
+
// undo it, so a board adopted once kept its ceremony forever. The
|
|
1591
|
+
// gates are worth having where a fleet is supervised; they are not
|
|
1592
|
+
// worth being unable to leave. Cards and columns are untouched.
|
|
1593
|
+
case "release_managed_lifecycle": {
|
|
1594
|
+
if (!input.boardId) return fail("release_managed_lifecycle requires boardId.");
|
|
1595
|
+
const board = await updateBoard2(projectRoot, input.boardId, { lifecycle: null });
|
|
1596
|
+
return board ? okBoard(
|
|
1597
|
+
board,
|
|
1598
|
+
"Managed lifecycle released; the board now tracks work without strict gates."
|
|
1599
|
+
) : fail("Board not found.");
|
|
1600
|
+
}
|
|
1601
|
+
case "duplicate_board": {
|
|
1602
|
+
if (!input.boardId) return fail("duplicate_board requires boardId.");
|
|
1603
|
+
const board = await duplicateBoard(
|
|
1604
|
+
projectRoot,
|
|
1605
|
+
input.boardId,
|
|
1606
|
+
duplicateBoardOptions(input)
|
|
1607
|
+
);
|
|
1608
|
+
return board ? okBoard(board, "Board duplicated.") : fail("Board not found.");
|
|
1609
|
+
}
|
|
1610
|
+
case "delete_board": {
|
|
1611
|
+
if (!input.boardId) return fail("delete_board requires boardId.");
|
|
1612
|
+
const removed = await removeBoard2(projectRoot, input.boardId);
|
|
1613
|
+
return { ok: removed, message: removed ? "Board deleted." : "Board not found." };
|
|
1614
|
+
}
|
|
1615
|
+
case "generate_board": {
|
|
1616
|
+
if (!input.description) return fail("generate_board requires description.");
|
|
1617
|
+
const boardInput = createBoardFromText({
|
|
1618
|
+
description: input.description,
|
|
1619
|
+
...input.title !== void 0 ? { title: input.title } : {},
|
|
1620
|
+
...input.context !== void 0 ? { context: input.context } : {}
|
|
1621
|
+
});
|
|
1622
|
+
const board = await createBoard2(projectRoot, boardInput);
|
|
1623
|
+
for (const taskInput2 of parseLinesIntoTasks(
|
|
1624
|
+
input.description,
|
|
1625
|
+
board.columns[0]?.id ?? "backlog"
|
|
1626
|
+
)) {
|
|
1627
|
+
await addTask(projectRoot, board.id, taskInput2);
|
|
1628
|
+
}
|
|
1629
|
+
return okBoard(await getBoard3(projectRoot, board.id) ?? board, "Board generated.");
|
|
1630
|
+
}
|
|
1631
|
+
case "export_markdown": {
|
|
1632
|
+
const board = await requireBoard(projectRoot, input.boardId);
|
|
1633
|
+
if (!board) return fail("Board not found.");
|
|
1634
|
+
return {
|
|
1635
|
+
ok: true,
|
|
1636
|
+
message: "Board exported.",
|
|
1637
|
+
board,
|
|
1638
|
+
markdown: exportBoardAsMarkdown(board)
|
|
1639
|
+
};
|
|
1640
|
+
}
|
|
1641
|
+
case "export_task_graph": {
|
|
1642
|
+
if (!input.boardId) return fail("export_task_graph requires boardId.");
|
|
1643
|
+
const exported = await exportBoardToTaskGraph(projectRoot, input.boardId, {
|
|
1644
|
+
...input.graphId !== void 0 ? { graphId: input.graphId } : {},
|
|
1645
|
+
...input.specId !== void 0 ? { specId: input.specId } : {},
|
|
1646
|
+
...input.title !== void 0 ? { title: input.title } : {},
|
|
1647
|
+
...input.preserveOriginTaskIds !== void 0 ? { preserveOriginTaskIds: input.preserveOriginTaskIds } : {},
|
|
1648
|
+
...input.includeArchived !== void 0 ? { includeArchived: input.includeArchived } : {}
|
|
1649
|
+
});
|
|
1650
|
+
if (!exported) return fail("Board not found.");
|
|
1651
|
+
return {
|
|
1652
|
+
ok: true,
|
|
1653
|
+
message: `Task graph exported with ${exported.graph.nodes.size} node(s).`,
|
|
1654
|
+
board: exported.board,
|
|
1655
|
+
taskGraph: serializeTaskGraph(exported.graph)
|
|
1656
|
+
};
|
|
1657
|
+
}
|
|
1658
|
+
case "sync_task_graph": {
|
|
1659
|
+
if (!input.boardId || !input.taskGraph) {
|
|
1660
|
+
return fail("sync_task_graph requires boardId and taskGraph.");
|
|
1661
|
+
}
|
|
1662
|
+
const graph = deserializeTaskGraph2(input.taskGraph);
|
|
1663
|
+
const result2 = await syncBoardFromTaskGraph2(projectRoot, input.boardId, graph, {
|
|
1664
|
+
...input.title !== void 0 ? { title: input.title } : {},
|
|
1665
|
+
...input.description !== void 0 ? { description: input.description } : {},
|
|
1666
|
+
...input.tags !== void 0 ? { tags: input.tags } : {},
|
|
1667
|
+
...input.generatedBy !== void 0 ? { generatedBy: input.generatedBy } : {},
|
|
1668
|
+
...input.sourceSystem !== void 0 ? { sourceSystem: input.sourceSystem } : {},
|
|
1669
|
+
...input.phaseId !== void 0 ? { phaseId: input.phaseId } : {},
|
|
1670
|
+
...input.includeCompletedTasks !== void 0 ? { includeCompletedTasks: input.includeCompletedTasks } : {},
|
|
1671
|
+
...input.archiveMissingTasks !== void 0 ? { archiveMissingTasks: input.archiveMissingTasks } : {},
|
|
1672
|
+
...input.preserveManualDependencies !== void 0 ? { preserveManualDependencies: input.preserveManualDependencies } : {}
|
|
1673
|
+
});
|
|
1674
|
+
return result2 ? {
|
|
1675
|
+
ok: true,
|
|
1676
|
+
message: `Task graph synced: ${result2.createdTaskIds.length} created, ${result2.updatedTaskIds.length} updated, ${result2.archivedTaskIds.length} archived.`,
|
|
1677
|
+
board: result2.board
|
|
1678
|
+
} : fail("Board not found.");
|
|
1679
|
+
}
|
|
1680
|
+
case "create_from_graph": {
|
|
1681
|
+
if (!input.taskGraph) return fail("create_from_graph requires taskGraph.");
|
|
1682
|
+
const graph = deserializeTaskGraph2(input.taskGraph);
|
|
1683
|
+
const { board } = await createBoardFromTaskGraph(projectRoot, graph, {
|
|
1684
|
+
...input.title !== void 0 ? { title: input.title } : {},
|
|
1685
|
+
...input.description !== void 0 ? { description: input.description } : {},
|
|
1686
|
+
...input.tags !== void 0 ? { tags: input.tags } : {},
|
|
1687
|
+
...input.generatedBy !== void 0 ? { generatedBy: input.generatedBy } : {},
|
|
1688
|
+
...input.sourceSystem !== void 0 ? { sourceSystem: input.sourceSystem } : {},
|
|
1689
|
+
...input.phaseId !== void 0 ? { phaseId: input.phaseId } : {},
|
|
1690
|
+
...input.includeCompletedTasks !== void 0 ? { includeCompletedTasks: input.includeCompletedTasks } : {}
|
|
1691
|
+
});
|
|
1692
|
+
return {
|
|
1693
|
+
ok: true,
|
|
1694
|
+
message: `Created board "${board.title}" from task graph with ${board.tasks.length} tasks.`,
|
|
1695
|
+
board
|
|
1696
|
+
};
|
|
1697
|
+
}
|
|
1698
|
+
case "import_session_tasks": {
|
|
1699
|
+
const taskPath = ctx.meta?.["task.path"];
|
|
1700
|
+
if (!taskPath) return fail("No session task file for this session.");
|
|
1701
|
+
const file = await loadTasks2(taskPath);
|
|
1702
|
+
if (!file || file.tasks.length === 0) return fail("No session tasks to import.");
|
|
1703
|
+
const sessionId = ctx.session?.id ?? file.sessionId ?? "session";
|
|
1704
|
+
const graph = deserializeTaskGraph2(taskFileToSerializedGraph(file.tasks, sessionId));
|
|
1705
|
+
const tags = ["session", `session:${sessionId}`];
|
|
1706
|
+
const existing = (await listBoards2(projectRoot)).find(
|
|
1707
|
+
(b) => b.tags?.includes(`session:${sessionId}`)
|
|
1708
|
+
);
|
|
1709
|
+
if (existing) {
|
|
1710
|
+
const result2 = await syncBoardFromTaskGraph2(projectRoot, existing.id, graph, {
|
|
1711
|
+
sourceSystem: "session",
|
|
1712
|
+
tags,
|
|
1713
|
+
archiveMissingTasks: true,
|
|
1714
|
+
includeCompletedTasks: true
|
|
1715
|
+
});
|
|
1716
|
+
return result2 ? {
|
|
1717
|
+
ok: true,
|
|
1718
|
+
message: `Synced ${file.tasks.length} session tasks into board "${result2.board.title}".`,
|
|
1719
|
+
board: result2.board
|
|
1720
|
+
} : fail("Session board vanished mid-sync.");
|
|
1721
|
+
}
|
|
1722
|
+
const { board } = await createBoardFromTaskGraph(projectRoot, graph, {
|
|
1723
|
+
title: `Session tasks (${sessionId.slice(0, 8)})`,
|
|
1724
|
+
sourceSystem: "session",
|
|
1725
|
+
tags
|
|
1726
|
+
});
|
|
1727
|
+
return {
|
|
1728
|
+
ok: true,
|
|
1729
|
+
message: `Imported ${file.tasks.length} session tasks into new board "${board.title}".`,
|
|
1730
|
+
board
|
|
1731
|
+
};
|
|
1732
|
+
}
|
|
1733
|
+
case "search_tasks": {
|
|
1734
|
+
const tasks = await searchKanban(projectRoot, {
|
|
1735
|
+
query: input.query,
|
|
1736
|
+
boardId: input.boardId,
|
|
1737
|
+
assignedAgent: input.agentId,
|
|
1738
|
+
status: input.status,
|
|
1739
|
+
priority: input.priority,
|
|
1740
|
+
label: input.labels?.[0],
|
|
1741
|
+
chainId: input.chainId
|
|
1742
|
+
});
|
|
1743
|
+
return { ok: true, message: `${tasks.length} task(s) matched.`, tasks };
|
|
1744
|
+
}
|
|
1745
|
+
case "ready_tasks": {
|
|
1746
|
+
const tasks = await listReadyTasks(projectRoot, {
|
|
1747
|
+
query: input.query,
|
|
1748
|
+
boardId: input.boardId,
|
|
1749
|
+
assignedAgent: input.agentId,
|
|
1750
|
+
priority: input.priority,
|
|
1751
|
+
label: input.labels?.[0],
|
|
1752
|
+
chainId: input.chainId,
|
|
1753
|
+
limit: input.limit
|
|
1754
|
+
});
|
|
1755
|
+
return { ok: true, message: `${tasks.length} ready task(s).`, tasks };
|
|
1756
|
+
}
|
|
1757
|
+
case "snapshot": {
|
|
1758
|
+
const snapshot = await getKanbanOrchestrationSnapshot2(projectRoot, {
|
|
1759
|
+
query: input.query,
|
|
1760
|
+
boardId: input.boardId,
|
|
1761
|
+
assignedAgent: input.agentId,
|
|
1762
|
+
status: input.status,
|
|
1763
|
+
priority: input.priority,
|
|
1764
|
+
label: input.labels?.[0],
|
|
1765
|
+
chainId: input.chainId
|
|
1766
|
+
});
|
|
1767
|
+
return {
|
|
1768
|
+
ok: true,
|
|
1769
|
+
message: `${snapshot.ready.length} ready, ${snapshot.running.length} running, ${snapshot.blocked.length} blocked.`,
|
|
1770
|
+
snapshot
|
|
1771
|
+
};
|
|
1772
|
+
}
|
|
1773
|
+
case "add_task": {
|
|
1774
|
+
if (!input.boardId || !input.title) return fail("add_task requires boardId and title.");
|
|
1775
|
+
const result2 = await addTask(projectRoot, input.boardId, taskInput(input));
|
|
1776
|
+
if (!result2) return fail("Board not found.");
|
|
1777
|
+
return okTask(result2.board, result2.task, `Task added.${atomicityNudge(result2.task)}`);
|
|
1778
|
+
}
|
|
1779
|
+
case "split_task": {
|
|
1780
|
+
if (!input.boardId || !input.taskId || !input.childTitles?.length) {
|
|
1781
|
+
return fail("split_task requires boardId, taskId, and childTitles.");
|
|
1782
|
+
}
|
|
1783
|
+
return handleSplitTask(projectRoot, input, {});
|
|
1784
|
+
}
|
|
1785
|
+
case "merge_tasks": {
|
|
1786
|
+
if (!input.boardId || !input.taskIds?.length || !input.title) {
|
|
1787
|
+
return fail("merge_tasks requires boardId, taskIds, and title.");
|
|
1788
|
+
}
|
|
1789
|
+
const result2 = await mergeTasks(projectRoot, input.boardId, {
|
|
1790
|
+
taskIds: input.taskIds,
|
|
1791
|
+
title: input.title,
|
|
1792
|
+
...input.description !== void 0 ? { description: input.description } : {},
|
|
1793
|
+
...input.targetColumnId !== void 0 ? { targetColumnId: input.targetColumnId } : {},
|
|
1794
|
+
...input.preserveAssignment !== void 0 ? { preserveAssignment: input.preserveAssignment } : {},
|
|
1795
|
+
...input.closeSourceTasks !== void 0 ? { closeSourceTasks: input.closeSourceTasks } : {}
|
|
1796
|
+
});
|
|
1797
|
+
return result2 ? okTask(result2.board, result2.task, "Tasks merged.") : fail("Board or task not found.");
|
|
1798
|
+
}
|
|
1799
|
+
case "copy_task": {
|
|
1800
|
+
if (!input.boardId || !input.taskId || !input.targetBoardId) {
|
|
1801
|
+
return fail("copy_task requires boardId, taskId, and targetBoardId.");
|
|
1802
|
+
}
|
|
1803
|
+
const result2 = await copyTaskToBoard(
|
|
1804
|
+
projectRoot,
|
|
1805
|
+
input.boardId,
|
|
1806
|
+
input.taskId,
|
|
1807
|
+
input.targetBoardId,
|
|
1808
|
+
{
|
|
1809
|
+
...input.targetColumnId !== void 0 ? { targetColumnId: input.targetColumnId } : {},
|
|
1810
|
+
...input.order !== void 0 ? { targetOrder: input.order } : {},
|
|
1811
|
+
...input.preserveAssignment !== void 0 ? { preserveAssignment: input.preserveAssignment } : {},
|
|
1812
|
+
...input.preserveDependencies !== void 0 ? { preserveDependencies: input.preserveDependencies } : {}
|
|
1813
|
+
}
|
|
1814
|
+
);
|
|
1815
|
+
return result2 ? okTask(result2.targetBoard, result2.task, "Task copied to target board.") : fail("Board or task not found.");
|
|
1816
|
+
}
|
|
1817
|
+
case "transfer_task": {
|
|
1818
|
+
if (!input.boardId || !input.taskId || !input.targetBoardId) {
|
|
1819
|
+
return fail("transfer_task requires boardId, taskId, and targetBoardId.");
|
|
1820
|
+
}
|
|
1821
|
+
const result2 = await transferTaskToBoard(
|
|
1822
|
+
projectRoot,
|
|
1823
|
+
input.boardId,
|
|
1824
|
+
input.taskId,
|
|
1825
|
+
input.targetBoardId,
|
|
1826
|
+
{
|
|
1827
|
+
...input.targetColumnId !== void 0 ? { targetColumnId: input.targetColumnId } : {},
|
|
1828
|
+
...input.order !== void 0 ? { targetOrder: input.order } : {},
|
|
1829
|
+
...input.preserveAssignment !== void 0 ? { preserveAssignment: input.preserveAssignment } : {},
|
|
1830
|
+
...input.preserveDependencies !== void 0 ? { preserveDependencies: input.preserveDependencies } : {}
|
|
1831
|
+
}
|
|
1832
|
+
);
|
|
1833
|
+
return result2 ? okTask(result2.targetBoard, result2.task, "Task transferred to target board.") : fail("Board or task not found.");
|
|
1834
|
+
}
|
|
1835
|
+
case "get_task": {
|
|
1836
|
+
if (!input.boardId || !input.taskId)
|
|
1837
|
+
return fail("get_task requires boardId and taskId.");
|
|
1838
|
+
const task = await getTask(projectRoot, input.boardId, input.taskId);
|
|
1839
|
+
return task ? { ok: true, message: "Task loaded.", task } : fail("Task not found.");
|
|
1840
|
+
}
|
|
1841
|
+
case "start_task": {
|
|
1842
|
+
if (!input.boardId || !input.taskId || !input.author || !input.transitionComment) {
|
|
1843
|
+
return fail("start_task requires boardId, taskId, author, and transitionComment.");
|
|
1844
|
+
}
|
|
1845
|
+
let board = await getBoard3(projectRoot, input.boardId);
|
|
1846
|
+
let task = board?.tasks.find((candidate) => candidate.id === input.taskId);
|
|
1847
|
+
if (!board || !task) return fail("Board or task not found.");
|
|
1848
|
+
const readiness = evaluateContractGraphReadiness(board, task.id);
|
|
1849
|
+
if (!readiness.ready) {
|
|
1850
|
+
return fail(
|
|
1851
|
+
`Task is not implementation-ready: ${readiness.issues.map((issue) => issue.message).join(" | ")}`
|
|
1852
|
+
);
|
|
1853
|
+
}
|
|
1854
|
+
if (board.lifecycle?.mode !== "managed") {
|
|
1855
|
+
const now = /* @__PURE__ */ new Date();
|
|
1856
|
+
const assigned = await updateTaskAssignment(projectRoot, board.id, task.id, {
|
|
1857
|
+
status: "running",
|
|
1858
|
+
agentId: input.agentId ?? input.author,
|
|
1859
|
+
leaseId: input.leaseId ?? randomUUID2(),
|
|
1860
|
+
claimedAt: input.claimedAt ?? now.toISOString(),
|
|
1861
|
+
heartbeatAt: input.heartbeatAt ?? now.toISOString(),
|
|
1862
|
+
leaseExpiresAt: input.leaseExpiresAt ?? new Date(now.getTime() + 15 * 6e4).toISOString(),
|
|
1863
|
+
attempt: input.attempt ?? 1,
|
|
1864
|
+
maxAttempts: input.maxAttempts ?? 3
|
|
1865
|
+
});
|
|
1866
|
+
if (!assigned) return fail("Task assignment could not be started.");
|
|
1867
|
+
const started = await updateTask2(projectRoot, board.id, task.id, {
|
|
1868
|
+
status: "in_progress"
|
|
1869
|
+
});
|
|
1870
|
+
const current = started ?? assigned;
|
|
1871
|
+
const claimed = task;
|
|
1872
|
+
const currentTask = current.tasks.find((candidate) => candidate.id === claimed.id) ?? claimed;
|
|
1873
|
+
ctx.setCurrentKanbanTask?.(currentTask.id, current.id);
|
|
1874
|
+
return okTask(
|
|
1875
|
+
current,
|
|
1876
|
+
currentTask,
|
|
1877
|
+
"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."
|
|
1878
|
+
);
|
|
1879
|
+
}
|
|
1880
|
+
let stage = task.lifecycle?.currentStage;
|
|
1881
|
+
if (stage === "backlog") {
|
|
1882
|
+
const moved = await transitionTask(projectRoot, board.id, task.id, {
|
|
1883
|
+
to: "todo",
|
|
1884
|
+
actor: input.author,
|
|
1885
|
+
comment: input.transitionComment
|
|
1886
|
+
});
|
|
1887
|
+
if (!moved) return fail("Task could not enter Todo.");
|
|
1888
|
+
board = moved.board;
|
|
1889
|
+
task = moved.task;
|
|
1890
|
+
stage = task.lifecycle?.currentStage;
|
|
1891
|
+
}
|
|
1892
|
+
if (stage === "todo" || stage === "review") {
|
|
1893
|
+
const now = /* @__PURE__ */ new Date();
|
|
1894
|
+
const leaseId = input.leaseId ?? randomUUID2();
|
|
1895
|
+
const assigned = await updateTaskAssignment(projectRoot, board.id, task.id, {
|
|
1896
|
+
status: "running",
|
|
1897
|
+
agentId: input.agentId ?? input.author,
|
|
1898
|
+
leaseId,
|
|
1899
|
+
claimedAt: input.claimedAt ?? now.toISOString(),
|
|
1900
|
+
heartbeatAt: input.heartbeatAt ?? now.toISOString(),
|
|
1901
|
+
leaseExpiresAt: input.leaseExpiresAt ?? new Date(now.getTime() + 15 * 6e4).toISOString(),
|
|
1902
|
+
attempt: input.attempt ?? 1,
|
|
1903
|
+
maxAttempts: input.maxAttempts ?? 3
|
|
1904
|
+
});
|
|
1905
|
+
if (!assigned) return fail("Task assignment could not be started.");
|
|
1906
|
+
const moved = await transitionTask(projectRoot, board.id, task.id, {
|
|
1907
|
+
to: "running",
|
|
1908
|
+
actor: input.author,
|
|
1909
|
+
comment: input.transitionComment
|
|
1910
|
+
});
|
|
1911
|
+
if (!moved) return fail("Task could not enter Running.");
|
|
1912
|
+
board = moved.board;
|
|
1913
|
+
task = moved.task;
|
|
1914
|
+
stage = task.lifecycle?.currentStage;
|
|
1915
|
+
}
|
|
1916
|
+
if (stage !== "running" || task.assignment?.status !== "running") {
|
|
1917
|
+
return fail(
|
|
1918
|
+
`start_task only accepts Backlog, Todo, Review repair, or live Running cards (current: ${stage ?? "unknown"}).`
|
|
1919
|
+
);
|
|
1920
|
+
}
|
|
1921
|
+
ctx.setCurrentKanbanTask(task.id, board.id);
|
|
1922
|
+
return okTask(
|
|
1923
|
+
board,
|
|
1924
|
+
task,
|
|
1925
|
+
"Task is active; runtime Kanban governance is now bound to this run."
|
|
1926
|
+
);
|
|
1927
|
+
}
|
|
1928
|
+
case "update_task": {
|
|
1929
|
+
if (!input.boardId || !input.taskId)
|
|
1930
|
+
return fail("update_task requires boardId and taskId.");
|
|
1931
|
+
const board = await updateTask2(
|
|
1932
|
+
projectRoot,
|
|
1933
|
+
input.boardId,
|
|
1934
|
+
input.taskId,
|
|
1935
|
+
taskPatch(input)
|
|
1936
|
+
);
|
|
1937
|
+
return board ? okBoard(board, "Task updated.") : fail("Task not found.");
|
|
1938
|
+
}
|
|
1939
|
+
case "transition_task": {
|
|
1940
|
+
if (!input.boardId || !input.taskId || !input.lifecycleStage || !input.author || !input.transitionComment) {
|
|
1941
|
+
return fail(
|
|
1942
|
+
"transition_task requires boardId, taskId, lifecycleStage, author, and transitionComment."
|
|
1943
|
+
);
|
|
1944
|
+
}
|
|
1945
|
+
if (input.lifecycleStage === "done") {
|
|
1946
|
+
const boardBefore = await getBoard3(projectRoot, input.boardId);
|
|
1947
|
+
const taskBefore = boardBefore ? await getTask(projectRoot, input.boardId, input.taskId) : null;
|
|
1948
|
+
if (boardBefore && taskBefore && !taskBefore.verificationReport && (taskBefore.atomic || Boolean(taskBefore.successCriteria?.length))) {
|
|
1949
|
+
const preGate = await verifyTaskCompletion2(
|
|
1950
|
+
projectRoot,
|
|
1951
|
+
input.boardId,
|
|
1952
|
+
taskBefore.id,
|
|
1953
|
+
{
|
|
1954
|
+
persist: false
|
|
1955
|
+
}
|
|
1956
|
+
);
|
|
1957
|
+
await updateTask2(projectRoot, input.boardId, taskBefore.id, {
|
|
1958
|
+
verificationReport: preGate.report,
|
|
1959
|
+
successCriteria: preGate.task.successCriteria
|
|
1960
|
+
});
|
|
1961
|
+
}
|
|
1962
|
+
}
|
|
1963
|
+
const result2 = await transitionTask(projectRoot, input.boardId, input.taskId, {
|
|
1964
|
+
to: input.lifecycleStage,
|
|
1965
|
+
actor: input.author,
|
|
1966
|
+
comment: input.transitionComment,
|
|
1967
|
+
...input.transitionAction !== void 0 ? { action: input.transitionAction } : {},
|
|
1968
|
+
...input.attachmentUrl !== void 0 ? {
|
|
1969
|
+
attachment: {
|
|
1970
|
+
url: input.attachmentUrl,
|
|
1971
|
+
type: input.attachmentType ?? "url",
|
|
1972
|
+
...input.attachmentTitle !== void 0 ? { title: input.attachmentTitle } : {}
|
|
1973
|
+
}
|
|
1974
|
+
} : {},
|
|
1975
|
+
patch: taskPatch(input)
|
|
1976
|
+
});
|
|
1977
|
+
if (result2 && input.lifecycleStage === "done" && result2.task.verificationReport) {
|
|
1978
|
+
recordKanbanVerificationEvidence(ctx, result2.task.verificationReport);
|
|
1979
|
+
}
|
|
1980
|
+
return result2 ? okTask(result2.board, result2.task, `Task advanced to ${result2.transition.to}.`) : fail("Board or task not found.");
|
|
1981
|
+
}
|
|
1982
|
+
case "repair_managed_projection": {
|
|
1983
|
+
if (!input.boardId || !input.taskId || !input.author || !input.transitionComment) {
|
|
1984
|
+
return fail(
|
|
1985
|
+
"repair_managed_projection requires boardId, taskId, author, and transitionComment."
|
|
1986
|
+
);
|
|
1987
|
+
}
|
|
1988
|
+
const result2 = await repairManagedTaskProjection(
|
|
1989
|
+
projectRoot,
|
|
1990
|
+
input.boardId,
|
|
1991
|
+
input.taskId,
|
|
1992
|
+
{
|
|
1993
|
+
actor: input.author,
|
|
1994
|
+
comment: input.transitionComment
|
|
1995
|
+
}
|
|
1996
|
+
);
|
|
1997
|
+
return result2 ? okTask(
|
|
1998
|
+
result2.board,
|
|
1999
|
+
result2.task,
|
|
2000
|
+
"Managed card projection repaired from lifecycle history."
|
|
2001
|
+
) : fail("Board or task not found.");
|
|
2002
|
+
}
|
|
2003
|
+
case "move_task": {
|
|
2004
|
+
if (!input.boardId || !input.taskId || !input.targetColumnId) {
|
|
2005
|
+
return fail("move_task requires boardId, taskId, and targetColumnId.");
|
|
2006
|
+
}
|
|
2007
|
+
const board = await moveTask(
|
|
2008
|
+
projectRoot,
|
|
2009
|
+
input.boardId,
|
|
2010
|
+
input.taskId,
|
|
2011
|
+
input.targetColumnId,
|
|
2012
|
+
input.order
|
|
2013
|
+
);
|
|
2014
|
+
return board ? okBoard(board, "Task moved.") : fail("Move failed.");
|
|
2015
|
+
}
|
|
2016
|
+
case "delete_task": {
|
|
2017
|
+
if (!input.boardId || !input.taskId)
|
|
2018
|
+
return fail("delete_task requires boardId and taskId.");
|
|
2019
|
+
const board = await removeTask(projectRoot, input.boardId, input.taskId);
|
|
2020
|
+
if (board && ctx.currentKanbanTaskId === input.taskId) {
|
|
2021
|
+
ctx.setCurrentKanbanTask?.(void 0, ctx.currentKanbanBoardId);
|
|
2022
|
+
}
|
|
2023
|
+
return board ? okBoard(board, "Task deleted.") : fail("Task not found.");
|
|
2024
|
+
}
|
|
2025
|
+
case "set_chain": {
|
|
2026
|
+
if (!input.boardId || !input.taskIds?.length) {
|
|
2027
|
+
return fail("set_chain requires boardId and taskIds.");
|
|
2028
|
+
}
|
|
2029
|
+
const result2 = await setTaskChain(projectRoot, input.boardId, {
|
|
2030
|
+
taskIds: input.taskIds,
|
|
2031
|
+
...input.chainId !== void 0 ? { chainId: input.chainId } : {},
|
|
2032
|
+
...input.enforceDependencies !== void 0 ? { enforceDependencies: input.enforceDependencies } : {}
|
|
2033
|
+
});
|
|
2034
|
+
return result2 ? {
|
|
2035
|
+
ok: true,
|
|
2036
|
+
message: `Chain set: ${result2.chainId}`,
|
|
2037
|
+
board: result2.board,
|
|
2038
|
+
chain: result2.tasks
|
|
2039
|
+
} : fail("Board or task not found.");
|
|
2040
|
+
}
|
|
2041
|
+
case "get_chain": {
|
|
2042
|
+
if (!input.boardId || !(input.taskId || input.chainId)) {
|
|
2043
|
+
return fail("get_chain requires boardId and taskId or chainId.");
|
|
2044
|
+
}
|
|
2045
|
+
const result2 = await getTaskChain(
|
|
2046
|
+
projectRoot,
|
|
2047
|
+
input.boardId,
|
|
2048
|
+
input.taskId ?? input.chainId ?? ""
|
|
2049
|
+
);
|
|
2050
|
+
return result2 ? {
|
|
2051
|
+
ok: true,
|
|
2052
|
+
message: `Chain loaded: ${result2.chainId}`,
|
|
2053
|
+
board: result2.board,
|
|
2054
|
+
chain: result2.tasks
|
|
2055
|
+
} : fail("Chain not found.");
|
|
2056
|
+
}
|
|
2057
|
+
case "claim_task": {
|
|
2058
|
+
const result2 = await claimReadyTask(projectRoot, {
|
|
2059
|
+
...input.boardId !== void 0 ? { boardId: input.boardId } : {},
|
|
2060
|
+
...input.taskId !== void 0 ? { taskId: input.taskId } : {},
|
|
2061
|
+
...assignmentInput(input),
|
|
2062
|
+
status: input.assignmentStatus ?? "queued"
|
|
2063
|
+
});
|
|
2064
|
+
return result2 ? okTask(result2.board, result2.task, "Task claimed.") : fail("No ready kanban task matched the claim.");
|
|
2065
|
+
}
|
|
2066
|
+
case "release_task": {
|
|
2067
|
+
if (!input.boardId || !input.taskId) {
|
|
2068
|
+
return fail("release_task requires boardId and taskId.");
|
|
2069
|
+
}
|
|
2070
|
+
const board = await releaseTaskClaim(projectRoot, input.boardId, input.taskId, {
|
|
2071
|
+
...input.releaseStatus !== void 0 ? { status: input.releaseStatus } : {},
|
|
2072
|
+
...input.releaseReason !== void 0 ? { reason: input.releaseReason } : {},
|
|
2073
|
+
...input.clearAssignee !== void 0 ? { clearAssignee: input.clearAssignee } : {}
|
|
2074
|
+
});
|
|
2075
|
+
return board ? okBoard(board, "Task claim released.") : fail("Task not found.");
|
|
2076
|
+
}
|
|
2077
|
+
case "assign_task": {
|
|
2078
|
+
if (!input.boardId || !input.taskId)
|
|
2079
|
+
return fail("assign_task requires boardId and taskId.");
|
|
2080
|
+
const board = await assignTask(
|
|
2081
|
+
projectRoot,
|
|
2082
|
+
input.boardId,
|
|
2083
|
+
input.taskId,
|
|
2084
|
+
assignmentInput(input)
|
|
2085
|
+
);
|
|
2086
|
+
return board ? okBoard(board, "Task assigned.") : fail("Task not found.");
|
|
2087
|
+
}
|
|
2088
|
+
case "mark_assignment": {
|
|
2089
|
+
if (!input.boardId || !input.taskId)
|
|
2090
|
+
return fail("mark_assignment requires boardId and taskId.");
|
|
2091
|
+
const assignmentStatus = input.assignmentStatus ?? (input.status === "completed" ? "completed" : input.error ? "failed" : void 0);
|
|
2092
|
+
const board = await updateTaskAssignment(
|
|
2093
|
+
projectRoot,
|
|
2094
|
+
input.boardId,
|
|
2095
|
+
input.taskId,
|
|
2096
|
+
{
|
|
2097
|
+
...assignmentStatus !== void 0 ? { status: assignmentStatus } : {},
|
|
2098
|
+
...input.subagentId !== void 0 ? { subagentId: input.subagentId } : {},
|
|
2099
|
+
...input.runTaskId !== void 0 ? { runTaskId: input.runTaskId } : {},
|
|
2100
|
+
...input.lastResult !== void 0 ? { lastResult: input.lastResult } : {},
|
|
2101
|
+
...input.error !== void 0 ? { error: input.error } : {},
|
|
2102
|
+
...input.agentId !== void 0 ? { agentId: input.agentId } : {},
|
|
2103
|
+
...input.leaseId !== void 0 ? { leaseId: input.leaseId } : {},
|
|
2104
|
+
...input.claimedAt !== void 0 ? { claimedAt: input.claimedAt } : {},
|
|
2105
|
+
...input.heartbeatAt !== void 0 ? { heartbeatAt: input.heartbeatAt } : {},
|
|
2106
|
+
...input.leaseExpiresAt !== void 0 ? { leaseExpiresAt: input.leaseExpiresAt } : {},
|
|
2107
|
+
...input.attempt !== void 0 ? { attempt: input.attempt } : {},
|
|
2108
|
+
...input.maxAttempts !== void 0 ? { maxAttempts: input.maxAttempts } : {}
|
|
2109
|
+
},
|
|
2110
|
+
// Ownership fence: when expectedLeaseId is supplied, the write is
|
|
2111
|
+
// applied only if the current assignment still holds this lease.
|
|
2112
|
+
// This prevents a recovered+reassigned stale worker's terminal
|
|
2113
|
+
// mark_assignment from overwriting the successor's state. The check
|
|
2114
|
+
// is atomic inside updateTaskAssignment's mutateBoard lock.
|
|
2115
|
+
input.expectedLeaseId !== void 0 ? { expectedLeaseId: input.expectedLeaseId } : {}
|
|
2116
|
+
);
|
|
2117
|
+
if (!board) return fail("Task not found.");
|
|
2118
|
+
if (assignmentStatus === "completed" && board.lifecycle?.mode !== "managed") {
|
|
2119
|
+
const envGate = readEnvGateEnforcement();
|
|
2120
|
+
const finalized = await finalizeTaskCompletion(projectRoot, board.id, input.taskId, {
|
|
2121
|
+
...board.completionGate === void 0 && envGate !== void 0 ? { enforcement: envGate } : {},
|
|
2122
|
+
...ctx.agentId !== void 0 ? { eventContext: { actor: ctx.agentId } } : {}
|
|
2123
|
+
});
|
|
2124
|
+
if (finalized) {
|
|
2125
|
+
if (finalized.gate.report) {
|
|
2126
|
+
recordKanbanVerificationEvidence(ctx, finalized.gate.report);
|
|
2127
|
+
}
|
|
2128
|
+
const gateSummary = {
|
|
2129
|
+
enforcement: finalized.gate.enforcement,
|
|
2130
|
+
allowed: finalized.gate.allowed,
|
|
2131
|
+
verdict: finalized.gate.verdict,
|
|
2132
|
+
issues: finalized.gate.issues.map((issue) => issue.message)
|
|
2133
|
+
};
|
|
2134
|
+
const gateMessage = finalized.gate.allowed ? `Completion gate ${finalized.gate.verdict === "skipped" ? "skipped" : "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(" | ")}`;
|
|
2135
|
+
return {
|
|
2136
|
+
...okTask(finalized.board, finalized.task, `Assignment updated. ${gateMessage}`),
|
|
2137
|
+
gate: gateSummary
|
|
2138
|
+
};
|
|
2139
|
+
}
|
|
2140
|
+
} else if (board.lifecycle?.mode === "managed") {
|
|
2141
|
+
const managedTask = board.tasks.find((candidate) => candidate.id === input.taskId);
|
|
2142
|
+
const stage = managedTask?.lifecycle?.currentStage;
|
|
2143
|
+
const actor = ctx.agentId ?? "kanban-agent";
|
|
2144
|
+
let transitionResult = null;
|
|
2145
|
+
const lifecycleWarnings = [];
|
|
2146
|
+
if (assignmentStatus === "running" && stage === "todo") {
|
|
2147
|
+
try {
|
|
2148
|
+
transitionResult = await transitionTask(projectRoot, board.id, input.taskId, {
|
|
2149
|
+
to: "running",
|
|
2150
|
+
actor,
|
|
2151
|
+
comment: "Work started."
|
|
2152
|
+
});
|
|
2153
|
+
} catch (err) {
|
|
2154
|
+
lifecycleWarnings.push(
|
|
2155
|
+
`Lifecycle transition to Running deferred: ${stripLifecycleIssues(err instanceof Error ? err.message : String(err))}`
|
|
2156
|
+
);
|
|
2157
|
+
}
|
|
2158
|
+
}
|
|
2159
|
+
if (assignmentStatus === "completed" && stage === "running") {
|
|
2160
|
+
const comment = typeof input.lastResult === "string" && input.lastResult.trim().length > 0 ? input.lastResult.trim().slice(0, 1e3) : "Work completed.";
|
|
2161
|
+
try {
|
|
2162
|
+
transitionResult = await transitionTask(projectRoot, board.id, input.taskId, {
|
|
2163
|
+
to: "review",
|
|
2164
|
+
actor,
|
|
2165
|
+
comment,
|
|
2166
|
+
attachment: {
|
|
2167
|
+
url: `kanban://task/${input.taskId}/result`,
|
|
2168
|
+
title: "Worker completion result",
|
|
2169
|
+
type: "file"
|
|
2170
|
+
},
|
|
2171
|
+
patch: {
|
|
2172
|
+
// Only patch non-description fields so the
|
|
2173
|
+
// original card description is preserved.
|
|
2174
|
+
...input.agentId !== void 0 ? { assignedAgent: input.agentId } : {}
|
|
2175
|
+
}
|
|
2176
|
+
});
|
|
2177
|
+
} catch (err) {
|
|
2178
|
+
lifecycleWarnings.push(
|
|
2179
|
+
`Lifecycle transition to Review failed: ${stripLifecycleIssues(err instanceof Error ? err.message : String(err))}`
|
|
2180
|
+
);
|
|
2181
|
+
}
|
|
2182
|
+
if (transitionResult) {
|
|
2183
|
+
const hasCriteria = (transitionResult.task.successCriteria?.length ?? 0) > 0 || transitionResult.task.atomic === true;
|
|
2184
|
+
if (hasCriteria) {
|
|
2185
|
+
try {
|
|
2186
|
+
const verResult = await verifyTaskCompletion2(
|
|
2187
|
+
projectRoot,
|
|
2188
|
+
board.id,
|
|
2189
|
+
input.taskId
|
|
2190
|
+
);
|
|
2191
|
+
if (verResult.report) {
|
|
2192
|
+
recordKanbanVerificationEvidence(ctx, verResult.report);
|
|
2193
|
+
}
|
|
2194
|
+
await updateTask2(projectRoot, board.id, input.taskId, {
|
|
2195
|
+
verificationReport: verResult.report,
|
|
2196
|
+
successCriteria: verResult.task.successCriteria
|
|
2197
|
+
});
|
|
2198
|
+
const verdict = verResult.report.verdict;
|
|
2199
|
+
if (verdict === "passed" && !resolveAutoAccept(board)) {
|
|
2200
|
+
lifecycleWarnings.push(
|
|
2201
|
+
"Verification passed, but this board does not auto-accept. The card is in Review awaiting an explicit transition_task to done."
|
|
2202
|
+
);
|
|
2203
|
+
} else if (verdict === "passed") {
|
|
2204
|
+
try {
|
|
2205
|
+
const doneResult = await transitionTask(
|
|
2206
|
+
projectRoot,
|
|
2207
|
+
board.id,
|
|
2208
|
+
input.taskId,
|
|
2209
|
+
{
|
|
2210
|
+
to: "done",
|
|
2211
|
+
actor,
|
|
2212
|
+
action: "Automated acceptance after verification",
|
|
2213
|
+
comment: "Auto-accepted: verification passed.",
|
|
2214
|
+
attachment: {
|
|
2215
|
+
url: `kanban://task/${input.taskId}/verification`,
|
|
2216
|
+
title: "Auto-verification result",
|
|
2217
|
+
type: "file"
|
|
2218
|
+
}
|
|
2219
|
+
}
|
|
2220
|
+
);
|
|
2221
|
+
transitionResult = doneResult;
|
|
2222
|
+
} catch (acceptErr) {
|
|
2223
|
+
lifecycleWarnings.push(
|
|
2224
|
+
`Auto-accept to Done deferred: ${acceptErr instanceof Error ? acceptErr.message : String(acceptErr)}`
|
|
2225
|
+
);
|
|
2226
|
+
}
|
|
2227
|
+
} else {
|
|
2228
|
+
lifecycleWarnings.push(
|
|
2229
|
+
`Verification verdict: ${verdict} \u2014 card left in Review for manual acceptance.`
|
|
2230
|
+
);
|
|
2231
|
+
}
|
|
2232
|
+
} catch (verifyErr) {
|
|
2233
|
+
lifecycleWarnings.push(
|
|
2234
|
+
`Auto-verification error: ${verifyErr instanceof Error ? verifyErr.message : String(verifyErr)}`
|
|
2235
|
+
);
|
|
2236
|
+
}
|
|
2237
|
+
} else {
|
|
2238
|
+
lifecycleWarnings.push(
|
|
2239
|
+
"No automatic success criteria \u2014 card left in Review for manual verification."
|
|
2240
|
+
);
|
|
2241
|
+
}
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
const responseBoard = transitionResult?.board ?? board;
|
|
2245
|
+
const responseTask = transitionResult?.task ?? managedTask;
|
|
2246
|
+
const msgParts = ["Assignment updated."];
|
|
2247
|
+
if (transitionResult) {
|
|
2248
|
+
msgParts.push(`Card advanced to ${transitionResult.transition.to}.`);
|
|
2249
|
+
}
|
|
2250
|
+
for (const w of lifecycleWarnings) msgParts.push(`Warning: ${w}`);
|
|
2251
|
+
return okTask(responseBoard, responseTask, msgParts.join(" "));
|
|
2252
|
+
}
|
|
2253
|
+
return okBoard(board, "Assignment updated.");
|
|
2254
|
+
}
|
|
2255
|
+
case "heartbeat_assignment": {
|
|
2256
|
+
if (!input.boardId || !input.taskId) {
|
|
2257
|
+
return fail("heartbeat_assignment requires boardId and taskId.");
|
|
2258
|
+
}
|
|
2259
|
+
const board = await heartbeatTaskAssignment(projectRoot, input.boardId, input.taskId, {
|
|
2260
|
+
...input.heartbeatAt !== void 0 ? { heartbeatAt: input.heartbeatAt } : {},
|
|
2261
|
+
...input.leaseExpiresAt !== void 0 ? { leaseExpiresAt: input.leaseExpiresAt } : {},
|
|
2262
|
+
// Ownership fence: when expectedLeaseId is supplied, the renewal
|
|
2263
|
+
// is applied only if the current assignment still holds this lease.
|
|
2264
|
+
// This prevents a recovered+reassigned stale worker's heartbeat
|
|
2265
|
+
// from renewing the successor's lease. The check is atomic inside
|
|
2266
|
+
// heartbeatTaskAssignment's mutateBoard lock.
|
|
2267
|
+
...input.expectedLeaseId !== void 0 ? { expectedLeaseId: input.expectedLeaseId } : {}
|
|
2268
|
+
});
|
|
2269
|
+
return board ? okBoard(board, "Assignment heartbeat updated.") : fail("Task assignment not found.");
|
|
2270
|
+
}
|
|
2271
|
+
case "recover_stale": {
|
|
2272
|
+
if (!input.boardId) return fail("recover_stale requires boardId.");
|
|
2273
|
+
const policyFields = [
|
|
2274
|
+
input.recoveryPolicyFailOnCostCeiling !== void 0,
|
|
2275
|
+
input.recoveryPolicyReleaseOnFailureKinds !== void 0,
|
|
2276
|
+
input.recoveryPolicyReleaseOnHeartbeatDue !== void 0,
|
|
2277
|
+
input.recoveryPolicyRetryPolicyOverride !== void 0
|
|
2278
|
+
].some(Boolean);
|
|
2279
|
+
const result2 = await recoverStaleTaskAssignments(projectRoot, input.boardId, {
|
|
2280
|
+
...input.recoveryMode !== void 0 ? { mode: input.recoveryMode } : {},
|
|
2281
|
+
...input.recoveryNow !== void 0 ? { now: input.recoveryNow } : {},
|
|
2282
|
+
...input.releaseReason !== void 0 ? { reason: input.releaseReason } : {},
|
|
2283
|
+
...input.clearAssignee !== void 0 ? { clearAssignee: input.clearAssignee } : {},
|
|
2284
|
+
...policyFields ? {
|
|
2285
|
+
policy: {
|
|
2286
|
+
...input.recoveryPolicyFailOnCostCeiling !== void 0 ? { failWhenCostCeilingSet: input.recoveryPolicyFailOnCostCeiling } : {},
|
|
2287
|
+
...input.recoveryPolicyReleaseOnFailureKinds !== void 0 ? {
|
|
2288
|
+
releaseOnFailureKinds: input.recoveryPolicyReleaseOnFailureKinds
|
|
2289
|
+
} : {},
|
|
2290
|
+
...input.recoveryPolicyReleaseOnHeartbeatDue !== void 0 ? {
|
|
2291
|
+
releaseOnHeartbeatDue: input.recoveryPolicyReleaseOnHeartbeatDue
|
|
2292
|
+
} : {},
|
|
2293
|
+
...input.recoveryPolicyRetryPolicyOverride !== void 0 ? {
|
|
2294
|
+
retryPolicyOverride: input.recoveryPolicyRetryPolicyOverride
|
|
2295
|
+
} : {}
|
|
2296
|
+
}
|
|
2297
|
+
} : {}
|
|
2298
|
+
});
|
|
2299
|
+
return result2 ? {
|
|
2300
|
+
ok: true,
|
|
2301
|
+
message: `Recovered ${result2.tasks.length} stale assignment(s).`,
|
|
2302
|
+
board: result2.board,
|
|
2303
|
+
recoveredTasks: result2.tasks
|
|
2304
|
+
} : { ok: true, message: "No stale assignment matched.", recoveredTasks: [] };
|
|
2305
|
+
}
|
|
2306
|
+
case "events": {
|
|
2307
|
+
if (!input.boardId) return fail("events requires boardId.");
|
|
2308
|
+
const eventList = await listKanbanEvents(projectRoot, input.boardId);
|
|
2309
|
+
return {
|
|
2310
|
+
ok: true,
|
|
2311
|
+
message: `${eventList.length} event(s).`,
|
|
2312
|
+
events: eventList
|
|
2313
|
+
};
|
|
2314
|
+
}
|
|
2315
|
+
case "queue_health": {
|
|
2316
|
+
const health = await getKanbanQueueHealth(projectRoot, {
|
|
2317
|
+
...input.boardId !== void 0 ? { boardId: input.boardId } : {}
|
|
2318
|
+
});
|
|
2319
|
+
return {
|
|
2320
|
+
ok: true,
|
|
2321
|
+
message: `Counts: startable=${health.counts.startable}, running=${health.counts.running}, stale=${health.staleAssignments.count}.`,
|
|
2322
|
+
queueHealth: health
|
|
2323
|
+
};
|
|
2324
|
+
}
|
|
2325
|
+
// Not every action is handled above. These are dispatched from here,
|
|
2326
|
+
// and the split has already cost real time: an agent that read this
|
|
2327
|
+
// file concluded `add_check` / `update_check` did not exist, wrote
|
|
2328
|
+
// that on a card, and spent a session trying to satisfy a gate it
|
|
2329
|
+
// already had the tool to clear. Keep this index in step with the
|
|
2330
|
+
// handlers.
|
|
2331
|
+
//
|
|
2332
|
+
// kanban-detail-actions.ts workbench · add_dependency ·
|
|
2333
|
+
// add_goal_metric · update_goal_metric · add_check ·
|
|
2334
|
+
// update_check · add_note · add_link · split_atomic
|
|
2335
|
+
// kanban-decomposition-actions.ts verify_completion ·
|
|
2336
|
+
// assess_atomicity · propose_decomposition
|
|
2337
|
+
// kanban-contract-actions.ts get_contract_graph ·
|
|
2338
|
+
// configure_contract_graph · upsert_contract_node ·
|
|
2339
|
+
// remove_contract_node · add_contract_edge · remove_contract_edge
|
|
2340
|
+
default:
|
|
2341
|
+
{
|
|
2342
|
+
const contractResult = await handleKanbanContractAction(
|
|
2343
|
+
projectRoot,
|
|
2344
|
+
input,
|
|
2345
|
+
input.author ?? input.agentId
|
|
2346
|
+
);
|
|
2347
|
+
if (contractResult !== void 0) return contractResult;
|
|
2348
|
+
}
|
|
2349
|
+
{
|
|
2350
|
+
const detailResult = await handleKanbanDetailAction(projectRoot, input);
|
|
2351
|
+
if (detailResult !== void 0) return detailResult;
|
|
2352
|
+
}
|
|
2353
|
+
return fail(`Unknown kanban action: ${input.action}`);
|
|
2354
|
+
}
|
|
2355
|
+
})();
|
|
2356
|
+
return withPresence(result);
|
|
2357
|
+
} catch (err) {
|
|
2358
|
+
return fail(stripLifecycleIssues(err instanceof Error ? err.message : String(err)));
|
|
2359
|
+
}
|
|
2360
|
+
}
|
|
2361
|
+
};
|
|
193
2362
|
|
|
194
2363
|
// src/todo.ts
|
|
2364
|
+
function normalizedTitle(value) {
|
|
2365
|
+
return value.trim().toLocaleLowerCase().replace(/\s+/g, " ");
|
|
2366
|
+
}
|
|
2367
|
+
function activeBoardId(items, ctx) {
|
|
2368
|
+
const metaKanban = ctx.meta?.["kanban"];
|
|
2369
|
+
const metaBoardId = metaKanban && typeof metaKanban === "object" ? metaKanban["boardId"] : void 0;
|
|
2370
|
+
return ctx.currentKanbanBoardId ?? (typeof metaBoardId === "string" ? metaBoardId : void 0) ?? items.find((item) => item.kanbanBoardId)?.kanbanBoardId ?? "";
|
|
2371
|
+
}
|
|
2372
|
+
function bindTodosToBoard(items, previous, board) {
|
|
2373
|
+
const previousById = new Map(previous.map((item) => [item.id, item]));
|
|
2374
|
+
const available = board.tasks.filter(
|
|
2375
|
+
(task) => task.status !== "archived" && task.mergedIntoTaskId === void 0 && (!task.childTaskIds || task.childTaskIds.length === 0)
|
|
2376
|
+
).sort(
|
|
2377
|
+
(left, right) => left.createdAt.localeCompare(right.createdAt) || left.order - right.order
|
|
2378
|
+
);
|
|
2379
|
+
const used = /* @__PURE__ */ new Set();
|
|
2380
|
+
return items.map((item) => {
|
|
2381
|
+
const previousItem = previousById.get(item.id);
|
|
2382
|
+
const requestedTaskId = item.kanbanBoardId === board.id ? item.kanbanTaskId : previousItem?.kanbanBoardId === board.id ? previousItem.kanbanTaskId : void 0;
|
|
2383
|
+
const title = normalizedTitle(item.content);
|
|
2384
|
+
const candidates = [
|
|
2385
|
+
requestedTaskId ? board.tasks.find((task2) => task2.id === requestedTaskId) : void 0,
|
|
2386
|
+
board.tasks.find((task2) => task2.id === item.id),
|
|
2387
|
+
board.tasks.find((task2) => task2.origin?.taskId === item.id),
|
|
2388
|
+
available.find((task2) => !used.has(task2.id) && normalizedTitle(task2.title) === title)
|
|
2389
|
+
];
|
|
2390
|
+
const task = candidates.find((candidate) => candidate && !used.has(candidate.id));
|
|
2391
|
+
if (!task) {
|
|
2392
|
+
const { blockedBy: _discarded, ...rest } = item;
|
|
2393
|
+
return { ...rest };
|
|
2394
|
+
}
|
|
2395
|
+
used.add(task.id);
|
|
2396
|
+
const blockedBy = blockingTitles(board, task);
|
|
2397
|
+
return {
|
|
2398
|
+
...item,
|
|
2399
|
+
kanbanBoardId: board.id,
|
|
2400
|
+
kanbanTaskId: task.id,
|
|
2401
|
+
...blockedBy.length ? { blockedBy } : { blockedBy: void 0 }
|
|
2402
|
+
};
|
|
2403
|
+
});
|
|
2404
|
+
}
|
|
2405
|
+
function demoteBlockedInProgress(items, warnings) {
|
|
2406
|
+
return items.map((item) => {
|
|
2407
|
+
if (item.status !== "in_progress" || !item.blockedBy?.length) return item;
|
|
2408
|
+
warnings.push(
|
|
2409
|
+
`"${item.content}" cannot start yet \u2014 it waits on: ${item.blockedBy.join("; ")}. Kept as pending; complete the blocking work first.`
|
|
2410
|
+
);
|
|
2411
|
+
return { ...item, status: "pending" };
|
|
2412
|
+
});
|
|
2413
|
+
}
|
|
2414
|
+
async function createMissingManagedCards(items, board, ctx, warnings) {
|
|
2415
|
+
const created = /* @__PURE__ */ new Map();
|
|
2416
|
+
for (const item of items) {
|
|
2417
|
+
if (item.kanbanBoardId === board.id && item.kanbanTaskId) continue;
|
|
2418
|
+
try {
|
|
2419
|
+
const result = await addTask2(ctx.projectRoot, board.id, {
|
|
2420
|
+
title: item.content,
|
|
2421
|
+
description: item.activeForm?.trim() || `Added from the session todo list: ${item.content}`
|
|
2422
|
+
});
|
|
2423
|
+
if (!result) {
|
|
2424
|
+
warnings.push(`Could not open a Kanban card for "${item.content}": board not found.`);
|
|
2425
|
+
continue;
|
|
2426
|
+
}
|
|
2427
|
+
created.set(item.id, result.task.id);
|
|
2428
|
+
} catch (error) {
|
|
2429
|
+
warnings.push(
|
|
2430
|
+
`Could not open a Kanban card for "${item.content}": ${error instanceof Error ? error.message : String(error)}`
|
|
2431
|
+
);
|
|
2432
|
+
}
|
|
2433
|
+
}
|
|
2434
|
+
return created;
|
|
2435
|
+
}
|
|
2436
|
+
async function synchronizeManagedKanban(items, board, ctx, signal) {
|
|
2437
|
+
let synced = 0;
|
|
2438
|
+
const warnings = [];
|
|
2439
|
+
const actor = ctx.agentId?.trim() || ctx.agentName?.trim() || "kanban-agent";
|
|
2440
|
+
const execute = async (input) => {
|
|
2441
|
+
const result = await kanbanTool.execute(input, ctx, { signal });
|
|
2442
|
+
if (!result.ok) warnings.push(result.message);
|
|
2443
|
+
else {
|
|
2444
|
+
synced++;
|
|
2445
|
+
if (result.message.includes("Warning:")) warnings.push(result.message);
|
|
2446
|
+
}
|
|
2447
|
+
return result;
|
|
2448
|
+
};
|
|
2449
|
+
for (const item of items) {
|
|
2450
|
+
if (item.status !== "pending" || item.kanbanBoardId !== board.id || !item.kanbanTaskId) {
|
|
2451
|
+
continue;
|
|
2452
|
+
}
|
|
2453
|
+
const task = board.tasks.find((candidate) => candidate.id === item.kanbanTaskId);
|
|
2454
|
+
if (task?.lifecycle?.currentStage !== "running") continue;
|
|
2455
|
+
const released = await execute({
|
|
2456
|
+
action: "mark_assignment",
|
|
2457
|
+
boardId: board.id,
|
|
2458
|
+
taskId: task.id,
|
|
2459
|
+
assignmentStatus: "assigned",
|
|
2460
|
+
agentId: actor,
|
|
2461
|
+
lastResult: `Todo returned to queue: ${item.content}`
|
|
2462
|
+
});
|
|
2463
|
+
if (!released.ok) continue;
|
|
2464
|
+
await execute({
|
|
2465
|
+
action: "transition_task",
|
|
2466
|
+
boardId: board.id,
|
|
2467
|
+
taskId: task.id,
|
|
2468
|
+
lifecycleStage: "todo",
|
|
2469
|
+
author: actor,
|
|
2470
|
+
transitionComment: `Todo returned to queue: ${item.content}`
|
|
2471
|
+
});
|
|
2472
|
+
}
|
|
2473
|
+
for (const item of items) {
|
|
2474
|
+
if (item.status === "completed" || item.kanbanBoardId !== board.id || !item.kanbanTaskId) {
|
|
2475
|
+
continue;
|
|
2476
|
+
}
|
|
2477
|
+
const task = board.tasks.find((candidate) => candidate.id === item.kanbanTaskId);
|
|
2478
|
+
if (task?.status !== "completed") continue;
|
|
2479
|
+
warnings.push(
|
|
2480
|
+
`"${item.content}" is already Done on the Kanban board and a completed card cannot be reopened; the row stays completed. Create a follow-up card for any remaining work.`
|
|
2481
|
+
);
|
|
2482
|
+
}
|
|
2483
|
+
for (const item of items) {
|
|
2484
|
+
if (item.status !== "completed" || item.kanbanBoardId !== board.id || !item.kanbanTaskId) {
|
|
2485
|
+
continue;
|
|
2486
|
+
}
|
|
2487
|
+
const task = board.tasks.find((candidate) => candidate.id === item.kanbanTaskId);
|
|
2488
|
+
if (!task || task.status === "completed") continue;
|
|
2489
|
+
await execute({
|
|
2490
|
+
action: "mark_assignment",
|
|
2491
|
+
boardId: board.id,
|
|
2492
|
+
taskId: task.id,
|
|
2493
|
+
assignmentStatus: "completed",
|
|
2494
|
+
agentId: actor,
|
|
2495
|
+
lastResult: `Todo completed: ${item.content}`
|
|
2496
|
+
});
|
|
2497
|
+
}
|
|
2498
|
+
const attemptedParents = /* @__PURE__ */ new Set();
|
|
2499
|
+
let afterCompletions = await getBoard4(ctx.projectRoot, board.id);
|
|
2500
|
+
while (afterCompletions) {
|
|
2501
|
+
const parent = afterCompletions.tasks.find(
|
|
2502
|
+
(task) => task.atomic === true && task.status !== "completed" && Boolean(task.childTaskIds?.length) && !attemptedParents.has(task.id) && task.childTaskIds?.every(
|
|
2503
|
+
(childId) => afterCompletions?.tasks.find((candidate) => candidate.id === childId)?.status === "completed"
|
|
2504
|
+
)
|
|
2505
|
+
);
|
|
2506
|
+
if (!parent) break;
|
|
2507
|
+
attemptedParents.add(parent.id);
|
|
2508
|
+
const started = await execute({
|
|
2509
|
+
action: "start_task",
|
|
2510
|
+
boardId: board.id,
|
|
2511
|
+
taskId: parent.id,
|
|
2512
|
+
author: actor,
|
|
2513
|
+
agentId: actor,
|
|
2514
|
+
transitionComment: "All child tasks completed; validating composite parent."
|
|
2515
|
+
});
|
|
2516
|
+
if (started.ok) {
|
|
2517
|
+
await execute({
|
|
2518
|
+
action: "mark_assignment",
|
|
2519
|
+
boardId: board.id,
|
|
2520
|
+
taskId: parent.id,
|
|
2521
|
+
assignmentStatus: "completed",
|
|
2522
|
+
agentId: actor,
|
|
2523
|
+
lastResult: "All child tasks completed; composite result ready for verification."
|
|
2524
|
+
});
|
|
2525
|
+
}
|
|
2526
|
+
afterCompletions = await getBoard4(ctx.projectRoot, board.id);
|
|
2527
|
+
}
|
|
2528
|
+
const completionPending = items.some(
|
|
2529
|
+
(item) => item.status === "completed" && item.kanbanBoardId === board.id && Boolean(item.kanbanTaskId) && afterCompletions?.tasks.find((task) => task.id === item.kanbanTaskId)?.status !== "completed"
|
|
2530
|
+
);
|
|
2531
|
+
const active = items.find(
|
|
2532
|
+
(item) => item.status === "in_progress" && item.kanbanBoardId === board.id && Boolean(item.kanbanTaskId)
|
|
2533
|
+
);
|
|
2534
|
+
const activeStage = active?.kanbanTaskId ? afterCompletions?.tasks.find((task) => task.id === active.kanbanTaskId)?.lifecycle?.currentStage : void 0;
|
|
2535
|
+
if (active?.kanbanTaskId) {
|
|
2536
|
+
if (activeStage === "review" || activeStage === "done") {
|
|
2537
|
+
warnings.push(
|
|
2538
|
+
`"${active.content}" is in ${activeStage === "review" ? "Review" : "Done"} awaiting acceptance; not re-activating it from the todo list. ` + (activeStage === "review" ? "Call kanban start_task explicitly to reopen it as a repair." : "Done is terminal; reopen only by creating a follow-up card.")
|
|
2539
|
+
);
|
|
2540
|
+
} else {
|
|
2541
|
+
await execute({
|
|
2542
|
+
action: "start_task",
|
|
2543
|
+
boardId: board.id,
|
|
2544
|
+
taskId: active.kanbanTaskId,
|
|
2545
|
+
author: actor,
|
|
2546
|
+
agentId: actor,
|
|
2547
|
+
transitionComment: `Todo activated: ${active.content}`
|
|
2548
|
+
});
|
|
2549
|
+
}
|
|
2550
|
+
}
|
|
2551
|
+
if (active?.kanbanTaskId && activeStage === "review") {
|
|
2552
|
+
} else if (active?.kanbanTaskId && completionPending) {
|
|
2553
|
+
warnings.push(
|
|
2554
|
+
"A completed todo is still awaiting acceptance; the next independent Kanban task was started."
|
|
2555
|
+
);
|
|
2556
|
+
} else if (!active && ctx.currentKanbanBoardId === board.id) {
|
|
2557
|
+
ctx.setCurrentKanbanTask(void 0, board.id);
|
|
2558
|
+
}
|
|
2559
|
+
return { synced, warnings };
|
|
2560
|
+
}
|
|
195
2561
|
var todoTool = {
|
|
196
2562
|
name: "todo",
|
|
197
2563
|
category: "Session",
|
|
198
|
-
description: "Manage the
|
|
199
|
-
usageHint: "BEST PRACTICE for complex tasks:\n- At the beginning of a non-trivial task, create a clear todo list with specific, actionable items.\n- Only **one** item should be `in_progress` at any time.\n- Update the list frequently as work progresses (mark items done, add new ones, change status).\n- **Re-order items** to reflect current priorities
|
|
200
|
-
permission: "
|
|
201
|
-
mutating:
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
2564
|
+
description: "Manage the compact active-work list. With a managed Kanban binding, every row resolves to a real card and status changes advance that card; without Kanban it remains session-only state. Each call replaces ordering and supplied fields, but unfinished omitted rows are retained until completed.",
|
|
2565
|
+
usageHint: "BEST PRACTICE for complex tasks:\n- At the beginning of a non-trivial task, create a clear todo list with specific, actionable items.\n- Only **one** item should be `in_progress` at any time.\n- Update the list frequently as work progresses (mark items done, add new ones, change status).\n- **Re-order items** to reflect current priorities. Omission is not cancellation: unfinished rows are retained until completed.\n- When all items are completed the board auto-clears \u2014 you do NOT need to send an empty list.\n- The system and user can see this list, so keep it honest and up-to-date.\nThis tool is extremely valuable for maintaining focus and giving the user visibility into your plan.",
|
|
2566
|
+
permission: "confirm",
|
|
2567
|
+
mutating: true,
|
|
2568
|
+
timeoutMs: 3e4,
|
|
2569
|
+
capabilities: ["session.todo", "fs.write"],
|
|
2570
|
+
subjectKey: "todos",
|
|
205
2571
|
icon: "todo",
|
|
206
2572
|
inputSchema: {
|
|
207
2573
|
type: "object",
|
|
@@ -227,20 +2593,38 @@ var todoTool = {
|
|
|
227
2593
|
activeForm: {
|
|
228
2594
|
type: "string",
|
|
229
2595
|
description: 'Optional present-tense form shown while the task is active (e.g. "Fixing auth bug").'
|
|
2596
|
+
},
|
|
2597
|
+
kanbanBoardId: {
|
|
2598
|
+
type: "string",
|
|
2599
|
+
description: "Kanban board that owns this UI row when Kanban is active."
|
|
2600
|
+
},
|
|
2601
|
+
kanbanTaskId: {
|
|
2602
|
+
type: "string",
|
|
2603
|
+
description: "Real Kanban task represented by this UI row."
|
|
230
2604
|
}
|
|
231
2605
|
},
|
|
232
2606
|
required: ["id", "content", "status"]
|
|
233
2607
|
},
|
|
234
|
-
description: "The
|
|
2608
|
+
description: "The desired todo list. Supplied rows are replaced/reordered; unfinished omitted rows are retained."
|
|
235
2609
|
}
|
|
236
2610
|
},
|
|
237
2611
|
required: ["todos"]
|
|
238
2612
|
},
|
|
239
|
-
async execute(input, ctx) {
|
|
2613
|
+
async execute(input, ctx, call) {
|
|
240
2614
|
if (!Array.isArray(input?.todos)) {
|
|
241
2615
|
throw new Error("todo: todos must be an array");
|
|
242
2616
|
}
|
|
243
2617
|
const items = input.todos.filter((t) => Boolean(t?.id && t.content));
|
|
2618
|
+
const todoIdentity = (item) => item.kanbanBoardId && item.kanbanTaskId ? `kanban:${item.kanbanBoardId}:${item.kanbanTaskId}` : item.promotedFromTask ? `task:${item.promotedFromTask}` : item.promotedFromPlan ? `plan:${item.promotedFromPlan}` : `todo:${item.id}`;
|
|
2619
|
+
const requestedIdentities = new Set(items.map(todoIdentity));
|
|
2620
|
+
for (const previous of ctx.todos ?? []) {
|
|
2621
|
+
const identity = todoIdentity(previous);
|
|
2622
|
+
if (previous.status === "completed" || requestedIdentities.has(identity)) {
|
|
2623
|
+
continue;
|
|
2624
|
+
}
|
|
2625
|
+
items.push({ ...previous });
|
|
2626
|
+
requestedIdentities.add(identity);
|
|
2627
|
+
}
|
|
244
2628
|
const inProgress = items.filter((t) => t.status === "in_progress");
|
|
245
2629
|
if (inProgress.length > 1) {
|
|
246
2630
|
let seenInProgress = false;
|
|
@@ -251,8 +2635,50 @@ var todoTool = {
|
|
|
251
2635
|
}
|
|
252
2636
|
}
|
|
253
2637
|
}
|
|
254
|
-
|
|
255
|
-
|
|
2638
|
+
const boardId = activeBoardId(items, ctx);
|
|
2639
|
+
let board = boardId ? await getBoard4(ctx.projectRoot, boardId) : null;
|
|
2640
|
+
const managed = board?.lifecycle?.mode === "managed";
|
|
2641
|
+
let boundItems = managed && board ? bindTodosToBoard(items, ctx.todos ?? [], board) : items;
|
|
2642
|
+
const creationWarnings = [];
|
|
2643
|
+
if (managed && board) {
|
|
2644
|
+
const managedBoardId = board.id;
|
|
2645
|
+
const created = await createMissingManagedCards(boundItems, board, ctx, creationWarnings);
|
|
2646
|
+
if (created.size > 0) {
|
|
2647
|
+
boundItems = boundItems.map((item) => {
|
|
2648
|
+
const taskId = created.get(item.id);
|
|
2649
|
+
return taskId ? { ...item, kanbanBoardId: managedBoardId, kanbanTaskId: taskId } : item;
|
|
2650
|
+
});
|
|
2651
|
+
board = await getBoard4(ctx.projectRoot, managedBoardId) ?? board;
|
|
2652
|
+
boundItems = bindTodosToBoard(boundItems, ctx.todos ?? [], board);
|
|
2653
|
+
}
|
|
2654
|
+
boundItems = demoteBlockedInProgress(boundItems, creationWarnings);
|
|
2655
|
+
}
|
|
2656
|
+
ctx.state.replaceTodos(boundItems);
|
|
2657
|
+
const kanbanSync = managed && board ? await synchronizeManagedKanban(boundItems, board, ctx, call.signal) : { synced: 0, warnings: [] };
|
|
2658
|
+
kanbanSync.warnings.unshift(...creationWarnings);
|
|
2659
|
+
if (managed && board) {
|
|
2660
|
+
const unresolved = boundItems.filter(
|
|
2661
|
+
(item) => item.kanbanBoardId !== board.id || !item.kanbanTaskId
|
|
2662
|
+
);
|
|
2663
|
+
if (unresolved.length > 0) {
|
|
2664
|
+
kanbanSync.warnings.push(
|
|
2665
|
+
`${unresolved.length} Todo row(s) could not be bound to a Kanban task and were not applied. Preserve kanbanBoardId/kanbanTaskId when updating the projection.`
|
|
2666
|
+
);
|
|
2667
|
+
}
|
|
2668
|
+
}
|
|
2669
|
+
const mirrorFailure = takeSessionMirrorFailure(ctx.projectRoot, ctx.session?.id ?? "");
|
|
2670
|
+
if (mirrorFailure) kanbanSync.warnings.push(mirrorFailure);
|
|
2671
|
+
let projectedBoard = board;
|
|
2672
|
+
if (managed && board) {
|
|
2673
|
+
const refreshed = await getBoard4(ctx.projectRoot, board.id);
|
|
2674
|
+
if (refreshed) {
|
|
2675
|
+
projectedBoard = refreshed;
|
|
2676
|
+
applyManagedKanbanBoardToTodos(ctx, refreshed);
|
|
2677
|
+
}
|
|
2678
|
+
}
|
|
2679
|
+
if (!managed) {
|
|
2680
|
+
mirrorSessionTodosToKanban(ctx.projectRoot, items, ctx.session?.id ?? "session");
|
|
2681
|
+
}
|
|
256
2682
|
const completedPlanIds = /* @__PURE__ */ new Set();
|
|
257
2683
|
const completedTaskIds = /* @__PURE__ */ new Set();
|
|
258
2684
|
const pendingPlanIds = /* @__PURE__ */ new Set();
|
|
@@ -287,7 +2713,7 @@ var todoTool = {
|
|
|
287
2713
|
const taskPath = ctx.meta["task.path"];
|
|
288
2714
|
if (typeof taskPath !== "string" || !taskPath) continue;
|
|
289
2715
|
try {
|
|
290
|
-
const file = await
|
|
2716
|
+
const file = await loadTasks3(taskPath);
|
|
291
2717
|
if (file) {
|
|
292
2718
|
const task = file.tasks.find((t) => t.id === taskId);
|
|
293
2719
|
if (task && task.status !== "completed") {
|
|
@@ -301,7 +2727,25 @@ var todoTool = {
|
|
|
301
2727
|
}
|
|
302
2728
|
return {
|
|
303
2729
|
count: items.length,
|
|
304
|
-
in_progress:
|
|
2730
|
+
in_progress: (ctx.todos ?? boundItems).filter((t) => t.status === "in_progress").length,
|
|
2731
|
+
...kanbanSync.synced > 0 ? { kanban_synced: kanbanSync.synced } : {},
|
|
2732
|
+
...kanbanSync.warnings.length > 0 ? { kanban_warnings: kanbanSync.warnings } : {},
|
|
2733
|
+
...projectedBoard?.lifecycle?.mode === "managed" ? {
|
|
2734
|
+
kanban_bindings: boundItems.flatMap((item) => {
|
|
2735
|
+
if (item.kanbanBoardId !== projectedBoard.id || !item.kanbanTaskId) return [];
|
|
2736
|
+
const task = projectedBoard.tasks.find(
|
|
2737
|
+
(candidate) => candidate.id === item.kanbanTaskId
|
|
2738
|
+
);
|
|
2739
|
+
return task ? [
|
|
2740
|
+
{
|
|
2741
|
+
todoId: item.id,
|
|
2742
|
+
boardId: projectedBoard.id,
|
|
2743
|
+
taskId: task.id,
|
|
2744
|
+
taskStatus: task.status
|
|
2745
|
+
}
|
|
2746
|
+
] : [];
|
|
2747
|
+
})
|
|
2748
|
+
} : {}
|
|
305
2749
|
};
|
|
306
2750
|
}
|
|
307
2751
|
};
|