@wrongstack/tools 0.281.3 → 0.282.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/pack.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { spawn, execFileSync } from 'node:child_process';
2
2
  import * as Core from '@wrongstack/core';
3
- import { buildChildEnv, getDesignKitLoader, isDesignStack, loadActiveKit, applyTokenOverrides, setActiveKit, recordKitChoice, recordOverrides, setDesignOverrides, materializeTokens, runDesignVerify, ToolValidationError, detectNewlineStyle, normalizeToLf, toStyle, atomicWrite, unifiedDiff, ToolError, FetchError, isPrivateIPv4, isPrivateIPv6, assessCommitSafety, compileGlob, expectDefined, recordPackageAction, detectPackageEcosystem, deepMerge, mutatePlan, clearPlan, getPlanTemplate, addPlanItem, deriveTodosFromPlanItem, removePlanItem, setPlanItemStatus, mutateTasks, formatTaskList, formatPlan, FsError, toErrorMessage as toErrorMessage$2, computeTaskItemProgress, loadPlan, savePlan, loadTasks, saveTasks, wstackGlobalRoot, resolveWstackPaths, truncate } from '@wrongstack/core';
3
+ import { buildChildEnv, getDesignKitLoader, isDesignStack, loadActiveKit, applyTokenOverrides, setActiveKit, recordKitChoice, recordOverrides, setDesignOverrides, materializeTokens, runDesignVerify, ToolValidationError, detectNewlineStyle, normalizeToLf, toStyle, atomicWrite, unifiedDiff, ToolError, FetchError, isPrivateIPv4, isPrivateIPv6, assessCommitSafety, compileGlob, expectDefined, recordPackageAction, detectPackageEcosystem, deepMerge, addLinkToTask, addNoteToTask, updateCheckOnTask, addCheckToTask, updateGoalMetricOnTask, addGoalMetricToTask, addDependency, updateTaskAssignment, assignTask, releaseTaskClaim, claimReadyTask, getTaskChain, setTaskChain, removeTask, moveTask, updateTask, getTask, transferTaskToBoard, copyTaskToBoard, mergeTasks, splitTask, addTask, removeColumn, updateColumn, addColumn, getKanbanOrchestrationSnapshot, listReadyTasks, searchKanban, deserializeTaskGraph, syncBoardFromTaskGraph, exportBoardToTaskGraph, serializeTaskGraph, exportBoardAsMarkdown, generateBoardFromDescription, createBoard, parseLinesIntoTasks, getBoard, removeBoard, duplicateBoard, updateBoard, listBoards, mutatePlan, clearPlan, getPlanTemplate, addPlanItem, deriveTodosFromPlanItem, removePlanItem, setPlanItemStatus, mutateTasks, formatTaskList, formatPlan, FsError, toErrorMessage as toErrorMessage$2, computeTaskItemProgress, loadPlan, savePlan, loadTasks, saveTasks, wstackGlobalRoot, resolveWstackPaths, truncate } from '@wrongstack/core';
4
4
  import * as fs from 'node:fs';
5
5
  import { statSync, mkdirSync, createWriteStream } from 'node:fs';
6
6
  import * as fs2 from 'node:fs/promises';
@@ -345,14 +345,34 @@ function redactCommand(cmd) {
345
345
  return result;
346
346
  }
347
347
  var DEFAULT_GRACE_MS = 2e3;
348
- function killWin32Tree(pid) {
348
+ var WIN32_TASKKILL_TIMEOUT_MS = 5e3;
349
+ function killWin32Tree(pid, opts = {}) {
349
350
  try {
350
351
  const child = spawn("taskkill", ["/pid", String(pid), "/T", "/F"], {
351
352
  stdio: "ignore",
352
353
  windowsHide: true
353
354
  });
354
- child.on("error", () => {
355
- });
355
+ let settled = false;
356
+ let timeout;
357
+ const settle = () => {
358
+ if (settled) return;
359
+ settled = true;
360
+ if (timeout) clearTimeout(timeout);
361
+ try {
362
+ opts.onSettled?.();
363
+ } catch {
364
+ }
365
+ };
366
+ child.on("error", settle);
367
+ child.on("close", settle);
368
+ timeout = setTimeout(() => {
369
+ try {
370
+ child.kill();
371
+ } catch {
372
+ }
373
+ settle();
374
+ }, Math.max(1, opts.timeoutMs ?? WIN32_TASKKILL_TIMEOUT_MS));
375
+ timeout.unref?.();
356
376
  child.unref();
357
377
  return true;
358
378
  } catch {
@@ -582,17 +602,18 @@ var ProcessRegistryImpl = class {
582
602
  const isWin4 = os2.platform() === "win32";
583
603
  if (isWin4) {
584
604
  const liveRealChild = p.child.exitCode === null && typeof p.child.pid === "number";
585
- if (liveRealChild && killWin32Tree(pid)) {
586
- const fallback = setTimeout(() => {
587
- if (p.child.exitCode === null) {
588
- try {
589
- p.child.kill("SIGKILL");
590
- } catch {
591
- }
605
+ const directFallback = () => {
606
+ if (p.child.exitCode === null) {
607
+ try {
608
+ p.child.kill("SIGKILL");
609
+ } catch {
592
610
  }
593
- }, graceMs);
594
- fallback.unref?.();
595
- } else {
611
+ }
612
+ };
613
+ if (liveRealChild && killWin32Tree(pid, {
614
+ timeoutMs: Math.max(graceMs, WIN32_TASKKILL_TIMEOUT_MS),
615
+ onSettled: directFallback
616
+ })) ; else {
596
617
  try {
597
618
  p.child.kill(force ? "SIGKILL" : "SIGTERM");
598
619
  } catch {
@@ -2088,17 +2109,14 @@ var bashTool = {
2088
2109
  const spool = createOutputSpool({ tool: "bash", thresholdBytes: MAX_OUTPUT });
2089
2110
  function killWithTimeout(child2, timeoutMs2) {
2090
2111
  if (isWin4) {
2091
- if (typeof child2.pid === "number" && child2.exitCode === null && killWin32Tree(child2.pid)) {
2092
- const fallback = setTimeout(() => {
2093
- if (child2.exitCode === null) {
2094
- try {
2095
- child2.kill();
2096
- } catch {
2097
- }
2112
+ if (typeof child2.pid === "number" && child2.exitCode === null) {
2113
+ const attempted = registry.kill(child2.pid, { force: true, graceMs: timeoutMs2 });
2114
+ if (!attempted) {
2115
+ try {
2116
+ child2.kill();
2117
+ } catch {
2098
2118
  }
2099
- }, 2e3);
2100
- timers.push(fallback);
2101
- fallback.unref?.();
2119
+ }
2102
2120
  } else {
2103
2121
  try {
2104
2122
  child2.kill();
@@ -3475,11 +3493,70 @@ function detectLang(file) {
3475
3493
  async function parseSymbols2(opts) {
3476
3494
  const { file, content, lang } = opts;
3477
3495
  try {
3478
- return await syncGoParse(file, content, lang);
3496
+ const parsed = await syncGoParse(file, content, lang);
3497
+ if (parsed.symbols.length > 0) {
3498
+ return parsed;
3499
+ }
3500
+ return fallbackParse(file, content, lang);
3479
3501
  } catch {
3480
- return { file, lang, symbols: [], mtimeMs: Date.now() };
3502
+ return fallbackParse(file, content, lang);
3481
3503
  }
3482
3504
  }
3505
+ function fallbackParse(filePath, content, lang) {
3506
+ if (!/^\s*package\s+[A-Za-z_]\w*/m.test(content) || hasUnbalancedDelimiters(content)) {
3507
+ return { file: filePath, lang, symbols: [], mtimeMs: Date.now() };
3508
+ }
3509
+ const symbols = [];
3510
+ const packageName = content.match(/^\s*package\s+([A-Za-z_]\w*)/m)?.[1] ?? "";
3511
+ const lines = content.split(/\r?\n/);
3512
+ for (const [idx, line] of lines.entries()) {
3513
+ const trimmed = line.trimStart();
3514
+ const col = line.length - trimmed.length + 1;
3515
+ const fn = /^func\s+(?:\([^)]*\)\s*)?([A-Za-z_]\w*)\s*\(/.exec(trimmed);
3516
+ if (fn?.[1]) {
3517
+ addFallbackSymbol(symbols, { filePath, lang, kind: trimmed.startsWith("func (") ? "method" : "function", name: fn[1], line: idx + 1, col, signature: trimmed, scope: packageName ? `${packageName}.${fn[1]}` : fn[1] });
3518
+ continue;
3519
+ }
3520
+ const typeDecl = /^type\s+([A-Za-z_]\w*)\b/.exec(trimmed);
3521
+ if (typeDecl?.[1]) {
3522
+ addFallbackSymbol(symbols, { filePath, lang, kind: "type", name: typeDecl[1], line: idx + 1, col, signature: trimmed, scope: packageName });
3523
+ continue;
3524
+ }
3525
+ const valueDecl = /^(const|var)\s+([A-Za-z_]\w*)\b/.exec(trimmed);
3526
+ if (valueDecl?.[1] && valueDecl[2]) {
3527
+ addFallbackSymbol(symbols, { filePath, lang, kind: valueDecl[1], name: valueDecl[2], line: idx + 1, col, signature: trimmed, scope: packageName });
3528
+ }
3529
+ }
3530
+ return { file: filePath, lang, symbols, mtimeMs: Date.now() };
3531
+ }
3532
+ function addFallbackSymbol(symbols, opts) {
3533
+ symbols.push({
3534
+ id: 0,
3535
+ lang: opts.lang,
3536
+ kind: opts.kind,
3537
+ name: opts.name,
3538
+ file: opts.filePath,
3539
+ line: opts.line,
3540
+ col: opts.col,
3541
+ signature: opts.signature,
3542
+ docComment: "",
3543
+ scope: opts.scope,
3544
+ text: `${opts.name} ${opts.signature}`.trim()
3545
+ });
3546
+ }
3547
+ function hasUnbalancedDelimiters(content) {
3548
+ const pairs = { "(": ")", "[": "]", "{": "}" };
3549
+ const closers = new Set(Object.values(pairs));
3550
+ const stack = [];
3551
+ for (const ch of content) {
3552
+ if (pairs[ch]) {
3553
+ stack.push(pairs[ch]);
3554
+ } else if (closers.has(ch) && stack.pop() !== ch) {
3555
+ return true;
3556
+ }
3557
+ }
3558
+ return stack.length > 0;
3559
+ }
3483
3560
  var GO_PARSE_SCRIPT = `
3484
3561
  package main
3485
3562
 
@@ -9206,6 +9283,700 @@ function toYaml(data, indent = 0) {
9206
9283
  }
9207
9284
  return String(data) + "\n";
9208
9285
  }
9286
+ var kanbanTool = {
9287
+ name: "kanban",
9288
+ category: "Project",
9289
+ description: "Manage project-scoped multi-kanban boards stored under .wrongstack/kanbans. Supports board/task/column CRUD, ready-task queues, dependency chains, split/merge, assignment metadata, provider/model/fallback routing hints, goal metrics, success checks, notes, links, and run status updates.",
9290
+ usageHint: "Use this for durable project kanban state. Agents should call snapshot/ready_tasks, then claim_task before working. Use set_chain for ordered work, split_task/merge_tasks when task scope changes, assign_task with provider/model/fallback hints before spawning, mark_assignment when starting or finishing, and release_task if the claim cannot be worked.",
9291
+ permission: "confirm",
9292
+ mutating: true,
9293
+ capabilities: ["fs.write"],
9294
+ icon: "task",
9295
+ timeoutMs: 5e3,
9296
+ inputSchema: {
9297
+ type: "object",
9298
+ properties: {
9299
+ action: {
9300
+ type: "string",
9301
+ enum: [
9302
+ "list_boards",
9303
+ "get_board",
9304
+ "create_board",
9305
+ "duplicate_board",
9306
+ "update_board",
9307
+ "delete_board",
9308
+ "generate_board",
9309
+ "export_markdown",
9310
+ "export_task_graph",
9311
+ "sync_task_graph",
9312
+ "search_tasks",
9313
+ "ready_tasks",
9314
+ "snapshot",
9315
+ "add_column",
9316
+ "update_column",
9317
+ "delete_column",
9318
+ "add_task",
9319
+ "split_task",
9320
+ "merge_tasks",
9321
+ "copy_task",
9322
+ "transfer_task",
9323
+ "get_task",
9324
+ "update_task",
9325
+ "move_task",
9326
+ "delete_task",
9327
+ "set_chain",
9328
+ "get_chain",
9329
+ "claim_task",
9330
+ "release_task",
9331
+ "assign_task",
9332
+ "mark_assignment",
9333
+ "add_dependency",
9334
+ "add_goal_metric",
9335
+ "update_goal_metric",
9336
+ "add_check",
9337
+ "update_check",
9338
+ "add_note",
9339
+ "add_link"
9340
+ ]
9341
+ },
9342
+ boardId: { type: "string" },
9343
+ taskId: { type: "string" },
9344
+ taskIds: { type: "array", items: { type: "string" } },
9345
+ chainId: { type: "string" },
9346
+ columnId: { type: "string" },
9347
+ targetBoardId: { type: "string" },
9348
+ targetColumnId: { type: "string" },
9349
+ title: { type: "string" },
9350
+ description: { type: "string" },
9351
+ tags: { type: "array", items: { type: "string" } },
9352
+ labels: { type: "array", items: { type: "string" } },
9353
+ priority: { type: "string", enum: ["critical", "high", "medium", "low"] },
9354
+ status: {
9355
+ type: "string",
9356
+ enum: [
9357
+ "pending",
9358
+ "ready",
9359
+ "in_progress",
9360
+ "blocked",
9361
+ "review",
9362
+ "completed",
9363
+ "failed",
9364
+ "archived"
9365
+ ]
9366
+ },
9367
+ order: { type: "number" },
9368
+ query: { type: "string" },
9369
+ limit: { type: "number" },
9370
+ agentId: { type: "string" },
9371
+ name: { type: "string" },
9372
+ role: { type: "string" },
9373
+ provider: { type: "string" },
9374
+ model: { type: "string" },
9375
+ fallbackProfile: { type: "string" },
9376
+ fallbackModels: { type: "array", items: { type: "string" } },
9377
+ tools: { type: "array", items: { type: "string" } },
9378
+ allowedCapabilities: { type: "array", items: { type: "string" } },
9379
+ subagentId: { type: "string" },
9380
+ runTaskId: { type: "string" },
9381
+ lastResult: { type: "string" },
9382
+ error: { type: "string" },
9383
+ assignmentStatus: {
9384
+ type: "string",
9385
+ enum: ["assigned", "queued", "running", "completed", "failed", "cancelled"]
9386
+ },
9387
+ releaseStatus: { type: "string", enum: ["pending", "ready", "blocked"] },
9388
+ releaseReason: { type: "string" },
9389
+ clearAssignee: { type: "boolean" },
9390
+ taskGraph: { type: "object" },
9391
+ graphId: { type: "string" },
9392
+ specId: { type: "string" },
9393
+ sourceSystem: { type: "string" },
9394
+ phaseId: { type: "string" },
9395
+ preserveOriginTaskIds: { type: "boolean" },
9396
+ includeArchived: { type: "boolean" },
9397
+ archiveMissingTasks: { type: "boolean" },
9398
+ preserveManualDependencies: { type: "boolean" },
9399
+ dependencyTaskId: { type: "string" },
9400
+ enforceDependencies: { type: "boolean" },
9401
+ childTitles: { type: "array", items: { type: "string" } },
9402
+ inheritAssignment: { type: "boolean" },
9403
+ inheritLabels: { type: "boolean" },
9404
+ inheritSuccessCriteria: { type: "boolean" },
9405
+ inheritGoalMetrics: { type: "boolean" },
9406
+ inheritDependencies: { type: "boolean" },
9407
+ chainChildren: { type: "boolean" },
9408
+ rewireDependents: { type: "boolean" },
9409
+ closeSourceTasks: { type: "boolean" },
9410
+ metricId: { type: "string" },
9411
+ metricName: { type: "string" },
9412
+ metricTarget: { oneOf: [{ type: "string" }, { type: "number" }] },
9413
+ metricCurrent: { oneOf: [{ type: "string" }, { type: "number" }] },
9414
+ metricUnit: { type: "string" },
9415
+ metricStatus: { type: "string", enum: ["pending", "met", "missed", "waived"] },
9416
+ metricNotes: { type: "string" },
9417
+ checkId: { type: "string" },
9418
+ checkDescription: { type: "string" },
9419
+ checkStatus: { type: "string", enum: ["pending", "passed", "failed", "skipped"] },
9420
+ note: { type: "string" },
9421
+ author: { type: "string" },
9422
+ url: { type: "string" },
9423
+ linkTitle: { type: "string" },
9424
+ linkType: {
9425
+ type: "string",
9426
+ enum: ["issue", "pr", "doc", "commit", "design", "file", "url", "other"]
9427
+ },
9428
+ context: { type: "string" },
9429
+ columns: { type: "array", items: { type: "string" } },
9430
+ generatedBy: { type: "string" },
9431
+ includeTasks: { type: "boolean" },
9432
+ includeCompletedTasks: { type: "boolean" },
9433
+ preserveAssignment: { type: "boolean" },
9434
+ preserveDependencies: { type: "boolean" },
9435
+ moveTasksToColumnId: { type: "string" }
9436
+ },
9437
+ required: ["action"]
9438
+ },
9439
+ async execute(input, ctx) {
9440
+ const projectRoot = ctx.projectRoot;
9441
+ if (!projectRoot) return fail("No project root is available.");
9442
+ try {
9443
+ switch (input.action) {
9444
+ case "list_boards": {
9445
+ const boards = await listBoards(projectRoot);
9446
+ return { ok: true, message: `${boards.length} board(s).`, boards };
9447
+ }
9448
+ case "get_board": {
9449
+ const board = await requireBoard(projectRoot, input.boardId);
9450
+ return board ? okBoard(board) : fail("Board not found.");
9451
+ }
9452
+ case "create_board": {
9453
+ if (!input.title) return fail("create_board requires title.");
9454
+ const board = await createBoard(projectRoot, {
9455
+ title: input.title,
9456
+ ...input.description !== void 0 ? { description: input.description } : {},
9457
+ ...input.tags !== void 0 ? { tags: input.tags } : {},
9458
+ ...input.generatedBy !== void 0 ? { generatedBy: input.generatedBy } : {}
9459
+ });
9460
+ return { ok: true, message: `Board created: ${board.title}`, board };
9461
+ }
9462
+ case "update_board": {
9463
+ if (!input.boardId) return fail("update_board requires boardId.");
9464
+ const board = await updateBoard(projectRoot, input.boardId, {
9465
+ ...input.title !== void 0 ? { title: input.title } : {},
9466
+ ...input.description !== void 0 ? { description: input.description } : {},
9467
+ ...input.tags !== void 0 ? { tags: input.tags } : {}
9468
+ });
9469
+ return board ? okBoard(board, "Board updated.") : fail("Board not found.");
9470
+ }
9471
+ case "duplicate_board": {
9472
+ if (!input.boardId) return fail("duplicate_board requires boardId.");
9473
+ const board = await duplicateBoard(projectRoot, input.boardId, {
9474
+ ...input.title !== void 0 ? { title: input.title } : {},
9475
+ ...input.generatedBy !== void 0 ? { generatedBy: input.generatedBy } : {},
9476
+ ...input.includeTasks !== void 0 ? { includeTasks: input.includeTasks } : {},
9477
+ ...input.includeCompletedTasks !== void 0 ? { includeCompletedTasks: input.includeCompletedTasks } : {},
9478
+ ...input.preserveAssignment !== void 0 ? { preserveAssignment: input.preserveAssignment } : {}
9479
+ });
9480
+ return board ? okBoard(board, "Board duplicated.") : fail("Board not found.");
9481
+ }
9482
+ case "delete_board": {
9483
+ if (!input.boardId) return fail("delete_board requires boardId.");
9484
+ const removed = await removeBoard(projectRoot, input.boardId);
9485
+ return { ok: removed, message: removed ? "Board deleted." : "Board not found." };
9486
+ }
9487
+ case "generate_board": {
9488
+ if (!input.description) return fail("generate_board requires description.");
9489
+ const boardInput = generateBoardFromDescription({
9490
+ description: input.description,
9491
+ ...input.title !== void 0 ? { title: input.title } : {},
9492
+ ...input.context !== void 0 ? { context: input.context } : {},
9493
+ ...input.columns !== void 0 ? { columns: input.columns } : {}
9494
+ });
9495
+ const board = await createBoard(projectRoot, boardInput);
9496
+ for (const taskInput2 of parseLinesIntoTasks(
9497
+ input.description,
9498
+ board.columns[0]?.id ?? "backlog"
9499
+ )) {
9500
+ await addTask(projectRoot, board.id, taskInput2);
9501
+ }
9502
+ return okBoard(await getBoard(projectRoot, board.id) ?? board, "Board generated.");
9503
+ }
9504
+ case "export_markdown": {
9505
+ const board = await requireBoard(projectRoot, input.boardId);
9506
+ if (!board) return fail("Board not found.");
9507
+ return {
9508
+ ok: true,
9509
+ message: "Board exported.",
9510
+ board,
9511
+ markdown: exportBoardAsMarkdown(board)
9512
+ };
9513
+ }
9514
+ case "export_task_graph": {
9515
+ if (!input.boardId) return fail("export_task_graph requires boardId.");
9516
+ const exported = await exportBoardToTaskGraph(projectRoot, input.boardId, {
9517
+ ...input.graphId !== void 0 ? { graphId: input.graphId } : {},
9518
+ ...input.specId !== void 0 ? { specId: input.specId } : {},
9519
+ ...input.title !== void 0 ? { title: input.title } : {},
9520
+ ...input.preserveOriginTaskIds !== void 0 ? { preserveOriginTaskIds: input.preserveOriginTaskIds } : {},
9521
+ ...input.includeArchived !== void 0 ? { includeArchived: input.includeArchived } : {}
9522
+ });
9523
+ if (!exported) return fail("Board not found.");
9524
+ return {
9525
+ ok: true,
9526
+ message: `Task graph exported with ${exported.graph.nodes.size} node(s).`,
9527
+ board: exported.board,
9528
+ taskGraph: serializeTaskGraph(exported.graph)
9529
+ };
9530
+ }
9531
+ case "sync_task_graph": {
9532
+ if (!input.boardId || !input.taskGraph) {
9533
+ return fail("sync_task_graph requires boardId and taskGraph.");
9534
+ }
9535
+ const graph = deserializeTaskGraph(input.taskGraph);
9536
+ const result = await syncBoardFromTaskGraph(projectRoot, input.boardId, graph, {
9537
+ ...input.title !== void 0 ? { title: input.title } : {},
9538
+ ...input.description !== void 0 ? { description: input.description } : {},
9539
+ ...input.tags !== void 0 ? { tags: input.tags } : {},
9540
+ ...input.generatedBy !== void 0 ? { generatedBy: input.generatedBy } : {},
9541
+ ...input.sourceSystem !== void 0 ? { sourceSystem: input.sourceSystem } : {},
9542
+ ...input.phaseId !== void 0 ? { phaseId: input.phaseId } : {},
9543
+ ...input.includeCompletedTasks !== void 0 ? { includeCompletedTasks: input.includeCompletedTasks } : {},
9544
+ ...input.archiveMissingTasks !== void 0 ? { archiveMissingTasks: input.archiveMissingTasks } : {},
9545
+ ...input.preserveManualDependencies !== void 0 ? { preserveManualDependencies: input.preserveManualDependencies } : {}
9546
+ });
9547
+ return result ? {
9548
+ ok: true,
9549
+ message: `Task graph synced: ${result.createdTaskIds.length} created, ${result.updatedTaskIds.length} updated, ${result.archivedTaskIds.length} archived.`,
9550
+ board: result.board
9551
+ } : fail("Board not found.");
9552
+ }
9553
+ case "search_tasks": {
9554
+ const tasks = await searchKanban(projectRoot, {
9555
+ query: input.query,
9556
+ boardId: input.boardId,
9557
+ assignedAgent: input.agentId,
9558
+ status: input.status,
9559
+ priority: input.priority,
9560
+ label: input.labels?.[0],
9561
+ chainId: input.chainId
9562
+ });
9563
+ return { ok: true, message: `${tasks.length} task(s) matched.`, tasks };
9564
+ }
9565
+ case "ready_tasks": {
9566
+ const tasks = await listReadyTasks(projectRoot, {
9567
+ query: input.query,
9568
+ boardId: input.boardId,
9569
+ assignedAgent: input.agentId,
9570
+ priority: input.priority,
9571
+ label: input.labels?.[0],
9572
+ chainId: input.chainId,
9573
+ limit: input.limit
9574
+ });
9575
+ return { ok: true, message: `${tasks.length} ready task(s).`, tasks };
9576
+ }
9577
+ case "snapshot": {
9578
+ const snapshot = await getKanbanOrchestrationSnapshot(projectRoot, {
9579
+ query: input.query,
9580
+ boardId: input.boardId,
9581
+ assignedAgent: input.agentId,
9582
+ status: input.status,
9583
+ priority: input.priority,
9584
+ label: input.labels?.[0],
9585
+ chainId: input.chainId
9586
+ });
9587
+ return {
9588
+ ok: true,
9589
+ message: `${snapshot.ready.length} ready, ${snapshot.running.length} running, ${snapshot.blocked.length} blocked.`,
9590
+ snapshot
9591
+ };
9592
+ }
9593
+ case "add_column": {
9594
+ if (!input.boardId || !input.title) return fail("add_column requires boardId and title.");
9595
+ const result = await addColumn(projectRoot, input.boardId, {
9596
+ title: input.title,
9597
+ ...input.description !== void 0 ? { description: input.description } : {}
9598
+ });
9599
+ return result ? okBoard(result.board, "Column added.") : fail("Board not found.");
9600
+ }
9601
+ case "update_column": {
9602
+ if (!input.boardId || !input.columnId)
9603
+ return fail("update_column requires boardId and columnId.");
9604
+ const board = await updateColumn(projectRoot, input.boardId, input.columnId, {
9605
+ ...input.title !== void 0 ? { title: input.title } : {},
9606
+ ...input.description !== void 0 ? { description: input.description } : {},
9607
+ ...input.order !== void 0 ? { order: input.order } : {}
9608
+ });
9609
+ return board ? okBoard(board, "Column updated.") : fail("Column not found.");
9610
+ }
9611
+ case "delete_column": {
9612
+ if (!input.boardId || !input.columnId)
9613
+ return fail("delete_column requires boardId and columnId.");
9614
+ const board = await removeColumn(projectRoot, input.boardId, input.columnId, {
9615
+ moveTasksToColumnId: input.moveTasksToColumnId
9616
+ });
9617
+ return board ? okBoard(board, "Column deleted.") : fail("Column not found.");
9618
+ }
9619
+ case "add_task": {
9620
+ if (!input.boardId || !input.title) return fail("add_task requires boardId and title.");
9621
+ const result = await addTask(projectRoot, input.boardId, taskInput(input));
9622
+ return result ? okTask(result.board, result.task, "Task added.") : fail("Board not found.");
9623
+ }
9624
+ case "split_task": {
9625
+ if (!input.boardId || !input.taskId || !input.childTitles?.length) {
9626
+ return fail("split_task requires boardId, taskId, and childTitles.");
9627
+ }
9628
+ const result = await splitTask(projectRoot, input.boardId, input.taskId, {
9629
+ titles: input.childTitles,
9630
+ ...input.targetColumnId !== void 0 ? { columnId: input.targetColumnId } : {},
9631
+ ...input.inheritAssignment !== void 0 ? { inheritAssignment: input.inheritAssignment } : {},
9632
+ ...input.inheritLabels !== void 0 ? { inheritLabels: input.inheritLabels } : {},
9633
+ ...input.inheritSuccessCriteria !== void 0 ? { inheritSuccessCriteria: input.inheritSuccessCriteria } : {},
9634
+ ...input.inheritGoalMetrics !== void 0 ? { inheritGoalMetrics: input.inheritGoalMetrics } : {},
9635
+ ...input.inheritDependencies !== void 0 ? { inheritDependencies: input.inheritDependencies } : {},
9636
+ ...input.chainChildren !== void 0 ? { chainChildren: input.chainChildren } : {},
9637
+ ...input.rewireDependents !== void 0 ? { rewireDependents: input.rewireDependents } : {}
9638
+ });
9639
+ return result ? {
9640
+ ok: true,
9641
+ message: `${result.children.length} child task(s) created.`,
9642
+ board: result.board,
9643
+ task: result.parent,
9644
+ children: result.children
9645
+ } : fail("Task not found.");
9646
+ }
9647
+ case "merge_tasks": {
9648
+ if (!input.boardId || !input.taskIds?.length || !input.title) {
9649
+ return fail("merge_tasks requires boardId, taskIds, and title.");
9650
+ }
9651
+ const result = await mergeTasks(projectRoot, input.boardId, {
9652
+ taskIds: input.taskIds,
9653
+ title: input.title,
9654
+ ...input.description !== void 0 ? { description: input.description } : {},
9655
+ ...input.targetColumnId !== void 0 ? { targetColumnId: input.targetColumnId } : {},
9656
+ ...input.preserveAssignment !== void 0 ? { preserveAssignment: input.preserveAssignment } : {},
9657
+ ...input.closeSourceTasks !== void 0 ? { closeSourceTasks: input.closeSourceTasks } : {}
9658
+ });
9659
+ return result ? okTask(result.board, result.task, "Tasks merged.") : fail("Board or task not found.");
9660
+ }
9661
+ case "copy_task": {
9662
+ if (!input.boardId || !input.taskId || !input.targetBoardId) {
9663
+ return fail("copy_task requires boardId, taskId, and targetBoardId.");
9664
+ }
9665
+ const result = await copyTaskToBoard(
9666
+ projectRoot,
9667
+ input.boardId,
9668
+ input.taskId,
9669
+ input.targetBoardId,
9670
+ {
9671
+ ...input.targetColumnId !== void 0 ? { targetColumnId: input.targetColumnId } : {},
9672
+ ...input.order !== void 0 ? { targetOrder: input.order } : {},
9673
+ ...input.preserveAssignment !== void 0 ? { preserveAssignment: input.preserveAssignment } : {},
9674
+ ...input.preserveDependencies !== void 0 ? { preserveDependencies: input.preserveDependencies } : {}
9675
+ }
9676
+ );
9677
+ return result ? okTask(result.targetBoard, result.task, "Task copied to target board.") : fail("Board or task not found.");
9678
+ }
9679
+ case "transfer_task": {
9680
+ if (!input.boardId || !input.taskId || !input.targetBoardId) {
9681
+ return fail("transfer_task requires boardId, taskId, and targetBoardId.");
9682
+ }
9683
+ const result = await transferTaskToBoard(
9684
+ projectRoot,
9685
+ input.boardId,
9686
+ input.taskId,
9687
+ input.targetBoardId,
9688
+ {
9689
+ ...input.targetColumnId !== void 0 ? { targetColumnId: input.targetColumnId } : {},
9690
+ ...input.order !== void 0 ? { targetOrder: input.order } : {},
9691
+ ...input.preserveAssignment !== void 0 ? { preserveAssignment: input.preserveAssignment } : {},
9692
+ ...input.preserveDependencies !== void 0 ? { preserveDependencies: input.preserveDependencies } : {}
9693
+ }
9694
+ );
9695
+ return result ? okTask(result.targetBoard, result.task, "Task transferred to target board.") : fail("Board or task not found.");
9696
+ }
9697
+ case "get_task": {
9698
+ if (!input.boardId || !input.taskId) return fail("get_task requires boardId and taskId.");
9699
+ const task = await getTask(projectRoot, input.boardId, input.taskId);
9700
+ return task ? { ok: true, message: "Task loaded.", task } : fail("Task not found.");
9701
+ }
9702
+ case "update_task": {
9703
+ if (!input.boardId || !input.taskId)
9704
+ return fail("update_task requires boardId and taskId.");
9705
+ const board = await updateTask(
9706
+ projectRoot,
9707
+ input.boardId,
9708
+ input.taskId,
9709
+ taskPatch(input)
9710
+ );
9711
+ return board ? okBoard(board, "Task updated.") : fail("Task not found.");
9712
+ }
9713
+ case "move_task": {
9714
+ if (!input.boardId || !input.taskId || !input.targetColumnId) {
9715
+ return fail("move_task requires boardId, taskId, and targetColumnId.");
9716
+ }
9717
+ const board = await moveTask(
9718
+ projectRoot,
9719
+ input.boardId,
9720
+ input.taskId,
9721
+ input.targetColumnId,
9722
+ input.order
9723
+ );
9724
+ return board ? okBoard(board, "Task moved.") : fail("Move failed.");
9725
+ }
9726
+ case "delete_task": {
9727
+ if (!input.boardId || !input.taskId)
9728
+ return fail("delete_task requires boardId and taskId.");
9729
+ const board = await removeTask(projectRoot, input.boardId, input.taskId);
9730
+ return board ? okBoard(board, "Task deleted.") : fail("Task not found.");
9731
+ }
9732
+ case "set_chain": {
9733
+ if (!input.boardId || !input.taskIds?.length) {
9734
+ return fail("set_chain requires boardId and taskIds.");
9735
+ }
9736
+ const result = await setTaskChain(projectRoot, input.boardId, {
9737
+ taskIds: input.taskIds,
9738
+ ...input.chainId !== void 0 ? { chainId: input.chainId } : {},
9739
+ ...input.enforceDependencies !== void 0 ? { enforceDependencies: input.enforceDependencies } : {}
9740
+ });
9741
+ return result ? {
9742
+ ok: true,
9743
+ message: `Chain set: ${result.chainId}`,
9744
+ board: result.board,
9745
+ chain: result.tasks
9746
+ } : fail("Board or task not found.");
9747
+ }
9748
+ case "get_chain": {
9749
+ if (!input.boardId || !(input.taskId || input.chainId)) {
9750
+ return fail("get_chain requires boardId and taskId or chainId.");
9751
+ }
9752
+ const result = await getTaskChain(
9753
+ projectRoot,
9754
+ input.boardId,
9755
+ input.taskId ?? input.chainId ?? ""
9756
+ );
9757
+ return result ? {
9758
+ ok: true,
9759
+ message: `Chain loaded: ${result.chainId}`,
9760
+ board: result.board,
9761
+ chain: result.tasks
9762
+ } : fail("Chain not found.");
9763
+ }
9764
+ case "claim_task": {
9765
+ const result = await claimReadyTask(projectRoot, {
9766
+ ...input.boardId !== void 0 ? { boardId: input.boardId } : {},
9767
+ ...input.taskId !== void 0 ? { taskId: input.taskId } : {},
9768
+ ...assignmentInput(input),
9769
+ status: input.assignmentStatus ?? "queued"
9770
+ });
9771
+ return result ? okTask(result.board, result.task, "Task claimed.") : fail("No ready kanban task matched the claim.");
9772
+ }
9773
+ case "release_task": {
9774
+ if (!input.boardId || !input.taskId) {
9775
+ return fail("release_task requires boardId and taskId.");
9776
+ }
9777
+ const board = await releaseTaskClaim(projectRoot, input.boardId, input.taskId, {
9778
+ ...input.releaseStatus !== void 0 ? { status: input.releaseStatus } : {},
9779
+ ...input.releaseReason !== void 0 ? { reason: input.releaseReason } : {},
9780
+ ...input.clearAssignee !== void 0 ? { clearAssignee: input.clearAssignee } : {}
9781
+ });
9782
+ return board ? okBoard(board, "Task claim released.") : fail("Task not found.");
9783
+ }
9784
+ case "assign_task": {
9785
+ if (!input.boardId || !input.taskId)
9786
+ return fail("assign_task requires boardId and taskId.");
9787
+ const board = await assignTask(
9788
+ projectRoot,
9789
+ input.boardId,
9790
+ input.taskId,
9791
+ assignmentInput(input)
9792
+ );
9793
+ return board ? okBoard(board, "Task assigned.") : fail("Task not found.");
9794
+ }
9795
+ case "mark_assignment": {
9796
+ if (!input.boardId || !input.taskId)
9797
+ return fail("mark_assignment requires boardId and taskId.");
9798
+ const assignmentStatus = input.assignmentStatus ?? (input.status === "completed" ? "completed" : input.error ? "failed" : void 0);
9799
+ const board = await updateTaskAssignment(projectRoot, input.boardId, input.taskId, {
9800
+ ...assignmentStatus !== void 0 ? { status: assignmentStatus } : {},
9801
+ ...input.subagentId !== void 0 ? { subagentId: input.subagentId } : {},
9802
+ ...input.runTaskId !== void 0 ? { runTaskId: input.runTaskId } : {},
9803
+ ...input.lastResult !== void 0 ? { lastResult: input.lastResult } : {},
9804
+ ...input.error !== void 0 ? { error: input.error } : {},
9805
+ ...input.agentId !== void 0 ? { agentId: input.agentId } : {}
9806
+ });
9807
+ return board ? okBoard(board, "Assignment updated.") : fail("Task not found.");
9808
+ }
9809
+ case "add_dependency": {
9810
+ if (!input.boardId || !input.taskId || !input.dependencyTaskId) {
9811
+ return fail("add_dependency requires boardId, taskId, and dependencyTaskId.");
9812
+ }
9813
+ const board = await addDependency(
9814
+ projectRoot,
9815
+ input.boardId,
9816
+ input.taskId,
9817
+ input.dependencyTaskId
9818
+ );
9819
+ return board ? okBoard(board, "Dependency added.") : fail("Task not found.");
9820
+ }
9821
+ case "add_goal_metric": {
9822
+ if (!input.boardId || !input.taskId || !input.metricName) {
9823
+ return fail("add_goal_metric requires boardId, taskId, and metricName.");
9824
+ }
9825
+ const board = await addGoalMetricToTask(projectRoot, input.boardId, input.taskId, {
9826
+ name: input.metricName,
9827
+ ...input.metricStatus !== void 0 ? { status: input.metricStatus } : {},
9828
+ ...input.metricTarget !== void 0 ? { target: input.metricTarget } : {},
9829
+ ...input.metricCurrent !== void 0 ? { current: input.metricCurrent } : {},
9830
+ ...input.metricUnit !== void 0 ? { unit: input.metricUnit } : {},
9831
+ ...input.metricNotes !== void 0 ? { notes: input.metricNotes } : {}
9832
+ });
9833
+ return board ? okBoard(board, "Goal metric added.") : fail("Task not found.");
9834
+ }
9835
+ case "update_goal_metric": {
9836
+ if (!input.boardId || !input.taskId || !input.metricId) {
9837
+ return fail("update_goal_metric requires boardId, taskId, and metricId.");
9838
+ }
9839
+ const board = await updateGoalMetricOnTask(
9840
+ projectRoot,
9841
+ input.boardId,
9842
+ input.taskId,
9843
+ input.metricId,
9844
+ {
9845
+ ...input.metricName !== void 0 ? { name: input.metricName } : {},
9846
+ ...input.metricStatus !== void 0 ? { status: input.metricStatus } : {},
9847
+ ...input.metricTarget !== void 0 ? { target: input.metricTarget } : {},
9848
+ ...input.metricCurrent !== void 0 ? { current: input.metricCurrent } : {},
9849
+ ...input.metricUnit !== void 0 ? { unit: input.metricUnit } : {},
9850
+ ...input.metricNotes !== void 0 ? { notes: input.metricNotes } : {}
9851
+ }
9852
+ );
9853
+ return board ? okBoard(board, "Goal metric updated.") : fail("Metric not found.");
9854
+ }
9855
+ case "add_check": {
9856
+ if (!input.boardId || !input.taskId || !input.checkDescription) {
9857
+ return fail("add_check requires boardId, taskId, and checkDescription.");
9858
+ }
9859
+ const board = await addCheckToTask(projectRoot, input.boardId, input.taskId, {
9860
+ description: input.checkDescription,
9861
+ type: "manual",
9862
+ status: input.checkStatus
9863
+ });
9864
+ return board ? okBoard(board, "Check added.") : fail("Task not found.");
9865
+ }
9866
+ case "update_check": {
9867
+ if (!input.boardId || !input.taskId || !input.checkId) {
9868
+ return fail("update_check requires boardId, taskId, and checkId.");
9869
+ }
9870
+ const board = await updateCheckOnTask(
9871
+ projectRoot,
9872
+ input.boardId,
9873
+ input.taskId,
9874
+ input.checkId,
9875
+ {
9876
+ ...input.checkDescription !== void 0 ? { description: input.checkDescription } : {},
9877
+ ...input.checkStatus !== void 0 ? { status: input.checkStatus } : {}
9878
+ }
9879
+ );
9880
+ return board ? okBoard(board, "Check updated.") : fail("Check not found.");
9881
+ }
9882
+ case "add_note": {
9883
+ if (!input.boardId || !input.taskId || !input.note)
9884
+ return fail("add_note requires boardId, taskId, and note.");
9885
+ const board = await addNoteToTask(projectRoot, input.boardId, input.taskId, {
9886
+ author: input.author ?? "agent",
9887
+ content: input.note
9888
+ });
9889
+ return board ? okBoard(board, "Note added.") : fail("Task not found.");
9890
+ }
9891
+ case "add_link": {
9892
+ if (!input.boardId || !input.taskId || !input.url)
9893
+ return fail("add_link requires boardId, taskId, and url.");
9894
+ const board = await addLinkToTask(projectRoot, input.boardId, input.taskId, {
9895
+ url: input.url,
9896
+ type: input.linkType ?? "url",
9897
+ ...input.linkTitle !== void 0 ? { title: input.linkTitle } : {}
9898
+ });
9899
+ return board ? okBoard(board, "Link added.") : fail("Task not found.");
9900
+ }
9901
+ default:
9902
+ return fail(`Unknown kanban action: ${input.action}`);
9903
+ }
9904
+ } catch (err) {
9905
+ return fail(err instanceof Error ? err.message : String(err));
9906
+ }
9907
+ }
9908
+ };
9909
+ function fail(message) {
9910
+ return { ok: false, message };
9911
+ }
9912
+ function okBoard(board, message = "Board loaded.") {
9913
+ return { ok: true, message, board };
9914
+ }
9915
+ function okTask(board, task, message) {
9916
+ return { ok: true, message, board, task };
9917
+ }
9918
+ async function requireBoard(projectRoot, boardId) {
9919
+ return boardId ? getBoard(projectRoot, boardId) : null;
9920
+ }
9921
+ function taskInput(input) {
9922
+ const assignment = hasAssignmentInput(input) ? assignmentForTaskCreate(input) : void 0;
9923
+ return {
9924
+ title: input.title ?? "",
9925
+ columnId: input.columnId,
9926
+ description: input.description,
9927
+ priority: input.priority,
9928
+ status: input.status,
9929
+ labels: input.labels,
9930
+ ...assignment?.agentId ?? assignment?.role ?? assignment?.name ? { assignedAgent: assignment.agentId ?? assignment.role ?? assignment.name } : {},
9931
+ ...input.assignee ?? assignment?.name ?? assignment?.agentId ? { assignee: input.assignee ?? assignment?.name ?? assignment?.agentId } : {},
9932
+ ...input.dependencyTaskId !== void 0 ? { dependsOn: [input.dependencyTaskId] } : {},
9933
+ ...assignment ? { assignment } : {}
9934
+ };
9935
+ }
9936
+ function taskPatch(input) {
9937
+ return {
9938
+ title: input.title,
9939
+ description: input.description,
9940
+ columnId: input.columnId,
9941
+ order: input.order,
9942
+ priority: input.priority,
9943
+ status: input.status,
9944
+ labels: input.labels,
9945
+ assignedAgent: input.agentId,
9946
+ ...input.dependencyTaskId !== void 0 ? { dependsOn: [input.dependencyTaskId] } : {}
9947
+ };
9948
+ }
9949
+ function assignmentInput(input) {
9950
+ return {
9951
+ agentId: input.agentId,
9952
+ name: input.name,
9953
+ role: input.role,
9954
+ provider: input.provider,
9955
+ model: input.model,
9956
+ fallbackProfile: input.fallbackProfile,
9957
+ fallbackModels: input.fallbackModels,
9958
+ tools: input.tools,
9959
+ allowedCapabilities: input.allowedCapabilities,
9960
+ assignee: input.assignee
9961
+ };
9962
+ }
9963
+ function hasAssignmentInput(input) {
9964
+ 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.assignmentStatus !== void 0;
9965
+ }
9966
+ function assignmentForTaskCreate(input) {
9967
+ return {
9968
+ status: input.assignmentStatus ?? "assigned",
9969
+ ...input.agentId !== void 0 ? { agentId: input.agentId } : {},
9970
+ ...input.name !== void 0 ? { name: input.name } : {},
9971
+ ...input.role !== void 0 ? { role: input.role } : {},
9972
+ ...input.provider !== void 0 ? { provider: input.provider } : {},
9973
+ ...input.model !== void 0 ? { model: input.model } : {},
9974
+ ...input.fallbackProfile !== void 0 ? { fallbackProfile: input.fallbackProfile } : {},
9975
+ ...input.fallbackModels !== void 0 ? { fallbackModels: input.fallbackModels } : {},
9976
+ ...input.tools !== void 0 ? { tools: input.tools } : {},
9977
+ ...input.allowedCapabilities !== void 0 ? { allowedCapabilities: input.allowedCapabilities } : {}
9978
+ };
9979
+ }
9209
9980
 
9210
9981
  // src/lint.ts
9211
9982
  var lintTool = {
@@ -12229,56 +13000,75 @@ var writeTool = {
12229
13000
  required: ["path", "content"]
12230
13001
  },
12231
13002
  async execute(input, ctx) {
12232
- if (!input?.path) {
12233
- throw new ToolValidationError({
12234
- message: "write: path is required",
12235
- field: "path"
12236
- });
12237
- }
12238
- if (input.content === void 0) {
12239
- throw new ToolValidationError({
12240
- message: "write: content is required",
12241
- field: "content"
12242
- });
12243
- }
12244
- const absPath = await safeResolveReal(input.path, ctx);
12245
- let existed = false;
12246
- let prev = "";
12247
- try {
12248
- const stat12 = await fs2.stat(absPath);
12249
- existed = stat12.isFile();
12250
- if (existed) {
12251
- if (!ctx.hasRead(absPath)) {
12252
- prev = await fs2.readFile(absPath, "utf8");
12253
- ctx.recordRead(absPath, stat12.mtimeMs, "write");
12254
- } else {
12255
- prev = await fs2.readFile(absPath, "utf8");
12256
- }
12257
- }
12258
- } catch (err) {
12259
- if (err.code !== "ENOENT") {
12260
- throw err;
13003
+ return writeFile7(input, ctx);
13004
+ },
13005
+ async *executeStream(input, ctx) {
13006
+ const prepared = await prepareWrite(input, ctx);
13007
+ if (!prepared.existed) {
13008
+ for (const line of input.content.split("\n")) {
13009
+ yield { type: "partial_output", text: `${line}
13010
+ `, data: { livePreview: true } };
12261
13011
  }
12262
13012
  }
12263
- await atomicWrite(absPath, input.content);
12264
- const diff = existed ? unifiedDiff(prev, input.content, { fromFile: input.path, toFile: input.path }) : `+++ ${input.path}
12265
- + (new file, ${input.content.split("\n").length} lines)`;
12266
- const stat11 = await fs2.stat(absPath);
12267
- ctx.recordRead(absPath, stat11.mtimeMs, "write");
12268
- ctx.session.recordFileChange({
12269
- path: absPath,
12270
- action: existed ? "modified" : "created",
12271
- before: existed ? prev : null,
12272
- after: input.content
12273
- });
12274
- return {
12275
- path: absPath,
12276
- bytes_written: Buffer.byteLength(input.content, "utf8"),
12277
- created: !existed,
12278
- diff
12279
- };
13013
+ yield { type: "final", output: await finishWrite(input, ctx, prepared) };
12280
13014
  }
12281
13015
  };
13016
+ async function writeFile7(input, ctx) {
13017
+ return finishWrite(input, ctx, await prepareWrite(input, ctx));
13018
+ }
13019
+ async function prepareWrite(input, ctx) {
13020
+ if (!input?.path) {
13021
+ throw new ToolValidationError({
13022
+ message: "write: path is required",
13023
+ field: "path"
13024
+ });
13025
+ }
13026
+ if (input.content === void 0) {
13027
+ throw new ToolValidationError({
13028
+ message: "write: content is required",
13029
+ field: "content"
13030
+ });
13031
+ }
13032
+ const absPath = await safeResolveReal(input.path, ctx);
13033
+ let existed = false;
13034
+ let prev = "";
13035
+ try {
13036
+ const stat11 = await fs2.stat(absPath);
13037
+ existed = stat11.isFile();
13038
+ if (existed) {
13039
+ if (!ctx.hasRead(absPath)) {
13040
+ prev = await fs2.readFile(absPath, "utf8");
13041
+ ctx.recordRead(absPath, stat11.mtimeMs, "write");
13042
+ } else {
13043
+ prev = await fs2.readFile(absPath, "utf8");
13044
+ }
13045
+ }
13046
+ } catch (err) {
13047
+ if (err.code !== "ENOENT") {
13048
+ throw err;
13049
+ }
13050
+ }
13051
+ return { absPath, existed, prev };
13052
+ }
13053
+ async function finishWrite(input, ctx, prepared) {
13054
+ await atomicWrite(prepared.absPath, input.content);
13055
+ const diff = prepared.existed ? unifiedDiff(prepared.prev, input.content, { fromFile: input.path, toFile: input.path }) : `+++ ${input.path}
13056
+ + (new file, ${input.content.split("\n").length} lines)`;
13057
+ const stat11 = await fs2.stat(prepared.absPath);
13058
+ ctx.recordRead(prepared.absPath, stat11.mtimeMs, "write");
13059
+ ctx.session.recordFileChange({
13060
+ path: prepared.absPath,
13061
+ action: prepared.existed ? "modified" : "created",
13062
+ before: prepared.existed ? prepared.prev : null,
13063
+ after: input.content
13064
+ });
13065
+ return {
13066
+ path: prepared.absPath,
13067
+ bytes_written: Buffer.byteLength(input.content, "utf8"),
13068
+ created: !prepared.existed,
13069
+ diff
13070
+ };
13071
+ }
12282
13072
 
12283
13073
  // src/builtin.ts
12284
13074
  var builtinTools = [
@@ -12294,6 +13084,7 @@ var builtinTools = [
12294
13084
  searchTool,
12295
13085
  todoTool,
12296
13086
  planTool,
13087
+ kanbanTool,
12297
13088
  taskTool,
12298
13089
  gitTool,
12299
13090
  patchTool,