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