@wrongstack/tools 0.295.1 → 0.296.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/dist/auto-proceed-loop-guard.d.ts +67 -0
  2. package/dist/auto-proceed-loop-guard.d.ts.map +1 -1
  3. package/dist/auto-proceed-loop-guard.js +95 -0
  4. package/dist/auto-proceed-loop-guard.js.map +2 -2
  5. package/dist/bash.js +53 -18
  6. package/dist/bash.js.map +2 -2
  7. package/dist/browser/artifacts.d.ts +2 -0
  8. package/dist/browser/artifacts.d.ts.map +1 -1
  9. package/dist/browser/index.js +58 -7
  10. package/dist/browser/index.js.map +2 -2
  11. package/dist/browser/network-guard-proxy.d.ts.map +1 -1
  12. package/dist/builtin.d.ts +2 -2
  13. package/dist/builtin.d.ts.map +1 -1
  14. package/dist/builtin.js +9516 -7476
  15. package/dist/builtin.js.map +4 -4
  16. package/dist/codebase-index/background-indexer.d.ts +28 -2
  17. package/dist/codebase-index/background-indexer.d.ts.map +1 -1
  18. package/dist/codebase-index/codebase-index-tool.d.ts.map +1 -1
  19. package/dist/codebase-index/dead-code-scan.d.ts +77 -0
  20. package/dist/codebase-index/dead-code-scan.d.ts.map +1 -0
  21. package/dist/codebase-index/index-service.d.ts +4 -3
  22. package/dist/codebase-index/index-service.d.ts.map +1 -1
  23. package/dist/codebase-index/index.d.ts +11 -8
  24. package/dist/codebase-index/index.d.ts.map +1 -1
  25. package/dist/codebase-index/index.js +5217 -3503
  26. package/dist/codebase-index/index.js.map +4 -4
  27. package/dist/codebase-index/indexer.d.ts +2 -0
  28. package/dist/codebase-index/indexer.d.ts.map +1 -1
  29. package/dist/codebase-index/parser-dispatch.d.ts +8 -0
  30. package/dist/codebase-index/parser-dispatch.d.ts.map +1 -0
  31. package/dist/codebase-index/project-server-cache.d.ts +11 -0
  32. package/dist/codebase-index/project-server-cache.d.ts.map +1 -0
  33. package/dist/codebase-index/project-server-client.d.ts +74 -0
  34. package/dist/codebase-index/project-server-client.d.ts.map +1 -0
  35. package/dist/codebase-index/project-server-endpoint.d.ts +24 -0
  36. package/dist/codebase-index/project-server-endpoint.d.ts.map +1 -0
  37. package/dist/codebase-index/project-server-protocol.d.ts +88 -0
  38. package/dist/codebase-index/project-server-protocol.d.ts.map +1 -0
  39. package/dist/codebase-index/project-server.d.ts +11 -0
  40. package/dist/codebase-index/project-server.d.ts.map +1 -0
  41. package/dist/codebase-index/project-server.js +5136 -0
  42. package/dist/codebase-index/project-server.js.map +7 -0
  43. package/dist/codebase-index/refs-extractor.d.ts +1 -0
  44. package/dist/codebase-index/refs-extractor.d.ts.map +1 -1
  45. package/dist/codebase-index/schema.d.ts +11 -0
  46. package/dist/codebase-index/schema.d.ts.map +1 -1
  47. package/dist/codebase-index/sqlite-runtime.d.ts +9 -0
  48. package/dist/codebase-index/sqlite-runtime.d.ts.map +1 -0
  49. package/dist/codebase-index/ts-parser.d.ts +5 -1
  50. package/dist/codebase-index/ts-parser.d.ts.map +1 -1
  51. package/dist/codebase-index/worker-protocol.d.ts +19 -1
  52. package/dist/codebase-index/worker-protocol.d.ts.map +1 -1
  53. package/dist/codebase-index/worker.js +3927 -3413
  54. package/dist/codebase-index/worker.js.map +4 -4
  55. package/dist/codebase-index/writer-admin.d.ts +16 -0
  56. package/dist/codebase-index/writer-admin.d.ts.map +1 -0
  57. package/dist/codebase-index/writer-bulk-insert.d.ts +25 -0
  58. package/dist/codebase-index/writer-bulk-insert.d.ts.map +1 -0
  59. package/dist/codebase-index/writer-graph-helpers.d.ts +52 -0
  60. package/dist/codebase-index/writer-graph-helpers.d.ts.map +1 -0
  61. package/dist/codebase-index/writer-graph-reader.d.ts +11 -0
  62. package/dist/codebase-index/writer-graph-reader.d.ts.map +1 -0
  63. package/dist/codebase-index/writer-helpers.d.ts +15 -0
  64. package/dist/codebase-index/writer-helpers.d.ts.map +1 -0
  65. package/dist/codebase-index/writer-pragmas.d.ts +3 -0
  66. package/dist/codebase-index/writer-pragmas.d.ts.map +1 -0
  67. package/dist/codebase-index/writer-ref-mapper.d.ts +11 -0
  68. package/dist/codebase-index/writer-ref-mapper.d.ts.map +1 -0
  69. package/dist/codebase-index/writer-schema.d.ts +7 -0
  70. package/dist/codebase-index/writer-schema.d.ts.map +1 -0
  71. package/dist/codebase-index/writer-search-helpers.d.ts +28 -0
  72. package/dist/codebase-index/writer-search-helpers.d.ts.map +1 -0
  73. package/dist/codebase-index/writer-store-pool.d.ts +45 -0
  74. package/dist/codebase-index/writer-store-pool.d.ts.map +1 -0
  75. package/dist/codebase-index/writer.d.ts +72 -89
  76. package/dist/codebase-index/writer.d.ts.map +1 -1
  77. package/dist/exec.js +53 -18
  78. package/dist/exec.js.map +2 -2
  79. package/dist/index.d.ts +2 -2
  80. package/dist/index.d.ts.map +1 -1
  81. package/dist/index.js +9860 -7824
  82. package/dist/index.js.map +4 -4
  83. package/dist/kanban-board-inputs.d.ts +34 -0
  84. package/dist/kanban-board-inputs.d.ts.map +1 -0
  85. package/dist/kanban-decomposition-actions.d.ts +4 -0
  86. package/dist/kanban-decomposition-actions.d.ts.map +1 -0
  87. package/dist/kanban-detail-actions.d.ts +3 -0
  88. package/dist/kanban-detail-actions.d.ts.map +1 -0
  89. package/dist/kanban-presence.d.ts +10 -0
  90. package/dist/kanban-presence.d.ts.map +1 -0
  91. package/dist/kanban-split-task-handler.d.ts +6 -0
  92. package/dist/kanban-split-task-handler.d.ts.map +1 -0
  93. package/dist/kanban-task-inputs.d.ts +73 -0
  94. package/dist/kanban-task-inputs.d.ts.map +1 -0
  95. package/dist/kanban-tool-results.d.ts +14 -0
  96. package/dist/kanban-tool-results.d.ts.map +1 -0
  97. package/dist/kanban-tool-schema.d.ts +5 -0
  98. package/dist/kanban-tool-schema.d.ts.map +1 -0
  99. package/dist/kanban-tool-types.d.ts +135 -0
  100. package/dist/kanban-tool-types.d.ts.map +1 -0
  101. package/dist/kanban.d.ts +2 -146
  102. package/dist/kanban.d.ts.map +1 -1
  103. package/dist/kanban.js +1030 -825
  104. package/dist/kanban.js.map +4 -4
  105. package/dist/pack.js +9515 -7476
  106. package/dist/pack.js.map +4 -4
  107. package/dist/plan.js +2 -2
  108. package/dist/plan.js.map +2 -2
  109. package/dist/process-registry-persistent.d.ts +1 -0
  110. package/dist/process-registry-persistent.d.ts.map +1 -1
  111. package/dist/ps-slash.js +53 -18
  112. package/dist/ps-slash.js.map +2 -2
  113. package/dist/read.d.ts +31 -0
  114. package/dist/read.d.ts.map +1 -1
  115. package/dist/read.js +5434 -78
  116. package/dist/read.js.map +4 -4
  117. package/dist/replace.js +8 -0
  118. package/dist/replace.js.map +2 -2
  119. package/dist/session-kanban.d.ts.map +1 -1
  120. package/dist/session-kanban.js +15 -20
  121. package/dist/session-kanban.js.map +2 -2
  122. package/dist/task.d.ts.map +1 -1
  123. package/dist/task.js +48 -6
  124. package/dist/task.js.map +2 -2
  125. package/dist/todo.d.ts.map +1 -1
  126. package/dist/todo.js +47 -5
  127. package/dist/todo.js.map +2 -2
  128. package/dist/tool-tier.js +9517 -7477
  129. package/dist/tool-tier.js.map +4 -4
  130. package/package.json +5 -5
  131. package/dist/shim/node-sqlite.d.ts +0 -3
  132. package/dist/shim/node-sqlite.d.ts.map +0 -1
package/dist/task.js CHANGED
@@ -12,7 +12,7 @@ import {
12
12
  import { randomUUID } from "node:crypto";
13
13
 
14
14
  // src/session-kanban.ts
15
- import { GlobalMailbox } from "@wrongstack/core/coordination";
15
+ import { getSharedProjectMailbox } from "@wrongstack/core/coordination";
16
16
  import {
17
17
  loadPlan,
18
18
  loadTasks,
@@ -22,9 +22,9 @@ import {
22
22
  import { deserializeTaskGraph } from "@wrongstack/core/tasking";
23
23
  import { resolveWstackPaths } from "@wrongstack/core/utils";
24
24
  import {
25
+ bridgeKanbanSupervisor,
25
26
  createBoard,
26
27
  getBoard,
27
- getKanbanDir,
28
28
  listBoards,
29
29
  removeBoard,
30
30
  syncBoardFromTaskGraph,
@@ -41,9 +41,14 @@ var SESSION_KANBAN_COLUMNS = [
41
41
  ];
42
42
  var boardQueue = /* @__PURE__ */ new Map();
43
43
  var boardEnsures = /* @__PURE__ */ new Map();
44
+ var pendingMirrors = /* @__PURE__ */ new Map();
45
+ var activeMirrors = /* @__PURE__ */ new Set();
44
46
  function boardKey(projectRoot, sessionId) {
45
47
  return `${projectRoot}\0${sessionId}`;
46
48
  }
49
+ function mirrorKey(projectRoot, sessionId, sourceSystem) {
50
+ return `${boardKey(projectRoot, sessionId)}\0${sourceSystem}`;
51
+ }
47
52
  function sessionTag(sessionId) {
48
53
  return `session:${sessionId}`;
49
54
  }
@@ -126,6 +131,43 @@ async function projectGraph(projectRoot, sessionId, graph, sourceSystem) {
126
131
  return result?.board ?? null;
127
132
  });
128
133
  }
134
+ function queueLatestMirror(projectRoot, sessionId, graph, sourceSystem) {
135
+ if (!projectRoot || !sessionId || process.env[MIRROR_DISABLED_ENV] === "0") return;
136
+ const key = mirrorKey(projectRoot, sessionId, sourceSystem);
137
+ pendingMirrors.set(key, { projectRoot, sessionId, graph, sourceSystem });
138
+ if (activeMirrors.has(key)) return;
139
+ activeMirrors.add(key);
140
+ void (async () => {
141
+ try {
142
+ for (; ; ) {
143
+ const pending = pendingMirrors.get(key);
144
+ if (!pending) break;
145
+ pendingMirrors.delete(key);
146
+ try {
147
+ await projectGraph(
148
+ pending.projectRoot,
149
+ pending.sessionId,
150
+ pending.graph,
151
+ pending.sourceSystem
152
+ );
153
+ } catch {
154
+ }
155
+ }
156
+ } finally {
157
+ activeMirrors.delete(key);
158
+ const pending = pendingMirrors.get(key);
159
+ if (pending) {
160
+ pendingMirrors.delete(key);
161
+ queueLatestMirror(
162
+ pending.projectRoot,
163
+ pending.sessionId,
164
+ pending.graph,
165
+ pending.sourceSystem
166
+ );
167
+ }
168
+ }
169
+ })();
170
+ }
129
171
  function taskFileToSerializedGraph(tasks, sessionId) {
130
172
  const ids = new Set(tasks.map((task) => task.id));
131
173
  const nodes = tasks.map((task, index) => ({
@@ -162,8 +204,8 @@ function taskFileToSerializedGraph(tasks, sessionId) {
162
204
  updatedAt: 0
163
205
  };
164
206
  }
165
- function projectSessionTasksToKanban(projectRoot, tasks, sessionId) {
166
- return projectGraph(
207
+ function mirrorSessionTasksToKanban(projectRoot, tasks, sessionId) {
208
+ queueLatestMirror(
167
209
  projectRoot,
168
210
  sessionId,
169
211
  taskFileToSerializedGraph(tasks, sessionId),
@@ -192,7 +234,7 @@ var taskTool = {
192
234
  mutating: true,
193
235
  capabilities: ["fs.write"],
194
236
  icon: "task",
195
- timeoutMs: 2e3,
237
+ timeoutMs: 5e3,
196
238
  inputSchema: {
197
239
  type: "object",
198
240
  properties: {
@@ -478,7 +520,7 @@ var taskTool = {
478
520
  };
479
521
  }
480
522
  if (todosToReplace) ctx.state.replaceTodos(todosToReplace);
481
- await projectSessionTasksToKanban(ctx.projectRoot, file.tasks, sessionId);
523
+ mirrorSessionTasksToKanban(ctx.projectRoot, file.tasks, sessionId);
482
524
  if (early) return early;
483
525
  if (didPlanify) {
484
526
  const { title, details } = planifyMeta;
package/dist/task.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/task.ts", "../src/session-kanban.ts"],
4
- "sourcesContent": ["import type { TaskStatus } from '@wrongstack/core/types';\nimport type { TaskFile } from '@wrongstack/core/storage';\nimport {\n computeTaskItemProgress,\n formatTaskList,\n type TaskItem,\n} from '@wrongstack/core/utils';\nimport { mutateTasks } from '@wrongstack/core/storage';\nimport {\n addPlanItem,\n mutatePlan,\n formatPlan,\n} from '@wrongstack/core/storage';\nimport { randomUUID } from 'node:crypto';\nimport type { Tool } from '@wrongstack/core/types';\nimport { projectSessionTasksToKanban } from './session-kanban.js';\n\n// ---------------------------------------------------------------------------\n// Task tool \u2014 structured work items with dependencies, types, and priorities.\n// Unlike `todo` (flat, session-scoped), tasks support:\n// - Dependencies (task can depend on other tasks)\n// - Type classification (feature, bugfix, refactor, docs, test, chore)\n// - Priority ranking (critical, high, medium, low)\n// - Assignment (which agent/subagent)\n// - Estimates (hours)\n//\n// Like `todo`, the list is fully replaced on every call. Session-persistent:\n// stored at `ctx.meta['task.path']` and isolated to this session \u2014 other sessions\n// have their own separate task lists.\n// ---------------------------------------------------------------------------\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\n/** Find a task by 1-based index, exact id, or case-insensitive title substring. */\nfunction findTaskIndex(tasks: TaskItem[], query: string): number {\n const asNum = Number.parseInt(query, 10);\n if (!Number.isNaN(asNum)) {\n const idx = asNum - 1;\n if (tasks[idx]) return idx;\n }\n const byId = tasks.findIndex((t) => t.id === query);\n if (byId >= 0) return byId;\n const lower = query.toLowerCase();\n return tasks.findIndex((t) => t.title.toLowerCase().includes(lower));\n}\n\n// ---------------------------------------------------------------------------\n// Tool\n// ---------------------------------------------------------------------------\n\ninterface TaskInput {\n /** Replace: set new task list. Add: append a task. Status: update task status. Promote: convert a task to todo items. */\n action: 'replace' | 'add' | 'status' | 'show' | 'promote' | 'planify';\n /** Full task list for action=replace. */\n tasks?: TaskItem[] | undefined;\n /** Single task for action=add. id, createdAt, updatedAt are auto-generated. */\n task?: Omit<TaskItem, 'id' | 'createdAt' | 'updatedAt'> | undefined;\n /** Task id for action=status or target for action=promote. */\n id?: string | undefined;\n /** New status for action=status. */\n status?: TaskStatus | undefined;\n /** Target task (id, 1-based index, or title substring) for action=promote. */\n target?: string | undefined;\n /** Optional subtask titles for action=promote. */\n subtasks?: string[] | undefined;\n /**\n * Storage scope. Default (unset): uses the session-scoped path \u2014 isolated to this\n * session, survives resume within the same session.\n * `scope: 'project'`: uses a shared project-level path, visible to all sessions\n * for this project. Useful for a shared backlog that outlasts any single session.\n */\n scope?: 'session' | 'project';\n}\n\ninterface TaskOutput {\n ok: boolean;\n message: string;\n count: number;\n completed: number;\n inProgress: number;\n}\n\nexport const taskTool: Tool<TaskInput, TaskOutput> = {\n name: 'task',\n category: 'Session',\n description:\n 'Manage session-persistent structured work items with dependencies, types, and priorities. ' +\n 'Unlike `todo` (flat, tactical), `task` supports typed work (feature/bugfix/refactor/etc.), ' +\n 'dependencies between items, priority ranking, and agent assignment. ' +\n 'Tasks are written to disk and survive session resumes. By default they are isolated to this session; ' +\n 'use `scope: \"project\"` to store tasks in a shared project-level file visible to all sessions.',\n usageHint:\n 'USE FOR STRUCTURED WORK:\\n' +\n '- `action: \"replace\"` \u2014 set the complete task list (tasks ordered by priority)\\n' +\n '- `action: \"add\"` \u2014 append a single task\\n' +\n '- `action: \"status\"` \u2014 update a task\\'s status (e.g. pending\u2192in_progress, in_progress\u2192completed)\\n' +\n '- `action: \"show\"` \u2014 view current tasks without changing them\\n' +\n '- `action: \"promote\"` \u2014 convert a task into actionable todo items via `target` (id|index|substring)\\n' +\n '- `action: \"planify\"` \u2014 promote a task to a plan item (strategic level) via `target` (id|index|substring)\\n\\n' +\n 'Task fields:\\n' +\n '- `dependsOn`: list of task IDs this one waits for\\n' +\n '- `type`: \"feature\" | \"bugfix\" | \"refactor\" | \"docs\" | \"test\" | \"chore\"\\n' +\n '- `priority`: \"critical\" | \"high\" | \"medium\" | \"low\"\\n' +\n '- `assignee`: agent/subagent name (e.g. \"bug-hunter\", \"refactor-planner\")\\n' +\n '- `estimateHours`: rough time estimate\\n' +\n '- `scope`: \"session\" (default, isolated) or \"project\" (shared across sessions)',\n permission: 'confirm',\n mutating: true,\n capabilities: ['fs.write'],\n icon: 'task',\n timeoutMs: 2_000,\n inputSchema: {\n type: 'object',\n properties: {\n action: {\n type: 'string',\n enum: ['replace', 'add', 'status', 'show', 'promote', 'planify'],\n description: 'replace = set full list, add = append, status = update task status, show = view only, promote = convert task to todos, planify = convert task to plan item.',\n },\n tasks: {\n type: 'array',\n items: {\n type: 'object',\n properties: {\n id: { type: 'string', description: 'Unique id (e.g. \"t1\", \"auth-flow\").' },\n title: { type: 'string', description: 'Short title.' },\n description: { type: 'string', description: 'Optional details.' },\n type: { type: 'string', enum: ['feature', 'bugfix', 'refactor', 'docs', 'test', 'chore'] },\n priority: { type: 'string', enum: ['critical', 'high', 'medium', 'low'] },\n status: { type: 'string', enum: ['pending', 'in_progress', 'blocked', 'failed', 'review', 'completed'] },\n dependsOn: {\n type: 'array',\n items: { type: 'string' },\n description: 'IDs of tasks this one depends on.',\n },\n assignee: { type: 'string', description: 'Agent/subagent assigned.' },\n estimateHours: { type: 'number', description: 'Estimated hours.' },\n tags: { type: 'array', items: { type: 'string' }, description: 'Optional tags.' },\n createdAt: { type: 'string' },\n updatedAt: { type: 'string' },\n },\n required: ['id', 'title', 'type', 'priority', 'status'],\n },\n description: 'Complete task list. Replaces previous list entirely.',\n },\n task: {\n type: 'object',\n properties: {\n title: { type: 'string' },\n description: { type: 'string' },\n type: { type: 'string', enum: ['feature', 'bugfix', 'refactor', 'docs', 'test', 'chore'] },\n priority: { type: 'string', enum: ['critical', 'high', 'medium', 'low'] },\n status: { type: 'string', enum: ['pending', 'in_progress', 'blocked', 'failed', 'review', 'completed'] },\n dependsOn: { type: 'array', items: { type: 'string' } },\n assignee: { type: 'string' },\n estimateHours: { type: 'number' },\n tags: { type: 'array', items: { type: 'string' } },\n },\n required: ['title', 'type', 'priority'],\n description: 'Single task to append (id/createdAt/updatedAt auto-generated).',\n },\n id: { type: 'string', description: 'Task id for action=status or target for action=promote.' },\n status: {\n type: 'string',\n enum: ['pending', 'in_progress', 'blocked', 'failed', 'review', 'completed'],\n description: 'New status for action=status.',\n },\n target: {\n type: 'string',\n description: 'Target task identifier (id, 1-based index, or title substring) for action=promote.',\n },\n subtasks: {\n type: 'array',\n items: { type: 'string' },\n description: 'Optional subtask titles for action=promote. Each becomes a pending todo.',\n },\n scope: {\n type: 'string',\n enum: ['session', 'project'],\n description: 'Storage scope: \"session\" (default, isolated to this session) or \"project\" (shared across all sessions for this project).',\n },\n },\n required: ['action'],\n },\n async execute(input, ctx) {\n const sessionTaskPath = (ctx.meta as Record<string, unknown>)['task.path'] as string | undefined;\n let taskPath: string | undefined;\n\n if (input.scope === 'project') {\n // Project-level: derive from the session path by replacing the filename with\n // 'backlog.tasks.json' so all sessions share the same file.\n if (typeof sessionTaskPath === 'string') {\n // Handle BOTH separators \u2014 a Windows-native path uses '\\\\'; a '/'-only\n // search would miss it and fall back to a bare relative path written\n // into the process CWD instead of the sessions dir.\n const lastSep = Math.max(sessionTaskPath.lastIndexOf('/'), sessionTaskPath.lastIndexOf('\\\\'));\n taskPath = lastSep >= 0\n ? sessionTaskPath.slice(0, lastSep + 1) + 'backlog.tasks.json'\n : 'backlog.tasks.json';\n }\n } else {\n taskPath = sessionTaskPath;\n }\n\n if (typeof taskPath !== 'string' || !taskPath) {\n return { ok: false, message: 'Task storage path not configured.', count: 0, completed: 0, inProgress: 0 };\n }\n const sessionId = ctx.session?.id ?? 'unknown';\n\n // Early-return result for validation errors that happen before or\n // during the critical section. The lock callback sets this instead of\n // mutating the file, and we return it after the lock releases.\n let early: TaskOutput | null = null;\n // Track promote output for the custom message\n const promoteMeta = { count: 0, title: '' };\n // Track planify data \u2014 written to plan file after the task lock releases\n const planifyMeta = { title: '', details: '' };\n let didPlanify = false;\n // collect todos to replace \u2014 called AFTER mutateTasks so rollback is possible\n type TodosReplacement = Array<{ id: string; content: string; status: 'pending' | 'in_progress' | 'completed'; activeForm?: string; promotedFromTask?: string }>;\n let todosToReplace: TodosReplacement | null = null;\n\n let file: TaskFile;\n try {\n file = await mutateTasks(taskPath, sessionId, async (f: TaskFile) => {\n switch (input.action) {\n case 'show':\n // read-only \u2014 no mutation, just return current state\n break;\n\n case 'replace': {\n if (!Array.isArray(input.tasks)) {\n early = { ok: false, message: 'action=replace requires `tasks` array.', count: 0, completed: 0, inProgress: 0 };\n return f;\n }\n // Validate id uniqueness: findTaskIndex / status resolve a task by\n // the FIRST id match, so a duplicate id silently becomes unaddressable.\n const newIds = new Set(input.tasks.map((t) => t.id));\n if (newIds.size !== input.tasks.length) {\n const seen = new Set<string>();\n const dupes = [...new Set(input.tasks.map((t) => t.id).filter((id) => {\n if (seen.has(id)) return true;\n seen.add(id);\n return false;\n }))];\n early = {\n ok: false,\n message: `action=replace has duplicate task IDs: ${dupes.join(', ')}. Each task id must be unique.`,\n count: 0,\n completed: 0,\n inProgress: 0,\n };\n return f;\n }\n // Validate dependsOn references: must point to IDs within the new batch\n for (const t of input.tasks) {\n if (t.dependsOn && t.dependsOn.length > 0) {\n const missing = t.dependsOn.filter((d) => !newIds.has(d));\n if (missing.length > 0) {\n early = {\n ok: false,\n message: `dependsOn validation failed: task \"${t.id}\" references unknown IDs: ${missing.join(', ')}`,\n count: 0,\n completed: 0,\n inProgress: 0,\n };\n return f;\n }\n }\n }\n const now = new Date().toISOString();\n f.tasks = input.tasks.map((t) => ({\n ...t,\n createdAt: t.createdAt || now,\n updatedAt: now,\n }));\n break;\n }\n\n case 'add': {\n const t = input.task;\n if (!t?.title) {\n early = { ok: false, message: 'action=add requires `task` with at least `title`.', count: 0, completed: 0, inProgress: 0 };\n return f;\n }\n // Validate dependsOn: all referenced IDs must exist in the current task list\n if (t.dependsOn && t.dependsOn.length > 0) {\n const existingIds = new Set(f.tasks.map((e: TaskItem) => e.id));\n const missing = t.dependsOn.filter((d) => !existingIds.has(d));\n if (missing.length > 0) {\n early = {\n ok: false,\n message: `dependsOn validation failed: unknown task IDs: ${missing.join(', ')}`,\n count: 0,\n completed: 0,\n inProgress: 0,\n };\n return f;\n }\n }\n const now = new Date().toISOString();\n const newTask: TaskItem = {\n id: `task_${Date.now()}_${randomUUID().slice(0, 8)}`,\n title: t.title,\n description: t.description,\n type: t.type || 'feature',\n priority: t.priority || 'medium',\n status: t.status || 'pending',\n dependsOn: t.dependsOn,\n assignee: t.assignee,\n estimateHours: t.estimateHours,\n tags: t.tags,\n createdAt: now,\n updatedAt: now,\n };\n f.tasks.push(newTask);\n break;\n }\n\n case 'status': {\n if (!input.id || !input.status) {\n early = { ok: false, message: 'action=status requires `id` and `status`.', count: 0, completed: 0, inProgress: 0 };\n return f;\n }\n const task = f.tasks.find((t: TaskItem) => t.id === input.id);\n if (!task) {\n early = { ok: false, message: `Task \"${input.id}\" not found.`, count: 0, completed: 0, inProgress: 0 };\n return f;\n }\n task.status = input.status;\n task.updatedAt = new Date().toISOString();\n break;\n }\n\n case 'promote': {\n const target = input.target?.trim();\n if (!target) {\n early = { ok: false, message: 'action=promote requires `target` (task id, index, or title substring).', count: 0, completed: 0, inProgress: 0 };\n return f;\n }\n const idx = findTaskIndex(f.tasks, target);\n if (idx === -1) {\n early = { ok: false, message: `No task matched \"${target}\".`, count: 0, completed: 0, inProgress: 0 };\n return f;\n }\n const match = f.tasks[idx];\n /* v8 ignore next 4 -- findTaskIndex returned a valid in-range idx, so match is always defined; defensive. */\n if (!match) {\n early = { ok: false, message: `No task matched \"${target}\".`, count: 0, completed: 0, inProgress: 0 };\n return f;\n }\n\n // Mark task in_progress\n if (match.status !== 'completed' && match.status !== 'failed') {\n match.status = 'in_progress';\n match.updatedAt = new Date().toISOString();\n }\n\n // Build todo items\n const todos: Array<{ id: string; content: string; status: 'pending' | 'in_progress' | 'completed'; activeForm?: string; promotedFromTask?: string }> = [];\n const ts = Date.now();\n todos.push({\n id: `todo_${ts}_task`,\n content: match.title,\n status: 'in_progress',\n activeForm: match.title,\n promotedFromTask: match.id,\n });\n\n if (match.description) {\n todos.push({\n id: `todo_${ts}_${randomUUID().slice(0, 6)}`,\n content: match.description.slice(0, 200),\n status: 'pending',\n promotedFromTask: match.id,\n });\n }\n\n if (input.subtasks && input.subtasks.length > 0) {\n for (const st of input.subtasks) {\n todos.push({\n id: `todo_${ts}_${randomUUID().slice(0, 6)}`,\n content: st,\n status: 'pending',\n promotedFromTask: match.id,\n });\n }\n }\n\n todosToReplace = todos;\n promoteMeta.count = todos.length;\n promoteMeta.title = match.title;\n break;\n }\n\n case 'planify': {\n const target = input.target?.trim();\n if (!target) {\n early = { ok: false, message: 'action=planify requires `target` (task id, index, or title substring).', count: 0, completed: 0, inProgress: 0 };\n return f;\n }\n const idx = findTaskIndex(f.tasks, target);\n if (idx === -1) {\n early = { ok: false, message: `No task matched \"${target}\".`, count: 0, completed: 0, inProgress: 0 };\n return f;\n }\n const match = f.tasks[idx];\n /* v8 ignore next 4 -- findTaskIndex returned a valid in-range idx, so match is always defined; defensive. */\n if (!match) {\n early = { ok: false, message: `No task matched \"${target}\".`, count: 0, completed: 0, inProgress: 0 };\n return f;\n }\n // Extract data \u2014 plan write happens after the task lock releases\n planifyMeta.title = match.title;\n planifyMeta.details = match.description ?? '';\n didPlanify = true;\n // Do NOT mutate the task \u2014 just copy to plan\n break;\n }\n\n default:\n early = { ok: false, message: `Unknown action \"${(input as { action: string }).action}\". Use replace | add | status | show | promote | planify.`, count: 0, completed: 0, inProgress: 0 };\n return f;\n }\n\n return f;\n });\n } catch (err) {\n // Persist failed (mutateTasks throws on a failed save) \u2014 report ok:false\n // instead of falsely claiming the tasks were saved.\n return {\n ok: false,\n message: `Task change not saved \u2014 ${err instanceof Error ? err.message : String(err)}`,\n count: 0,\n completed: 0,\n inProgress: 0,\n };\n }\n\n // Apply todo replacements after the task file mutation succeeds so that\n // on error the state is rolled back cleanly.\n if (todosToReplace) ctx.state.replaceTodos(todosToReplace);\n\n // A successful task mutation includes its Kanban projection. Awaiting this\n // keeps the session board authoritative at tool-return time.\n await projectSessionTasksToKanban(ctx.projectRoot, file.tasks, sessionId);\n\n // If the callback set an early-return result, use it\n if (early) return early;\n\n // If planify copied task data, write it to the plan file now\n if (didPlanify) {\n const { title, details } = planifyMeta;\n const planPathRaw = (ctx.meta as Record<string, unknown>)['plan.path'];\n const prog = computeTaskItemProgress(file.tasks);\n if (typeof planPathRaw === 'string' && planPathRaw) {\n let planPath: string = planPathRaw;\n // Honor project scope for the PLAN file too (mirror of plan.ts taskify);\n // handle both separators.\n if (input.scope === 'project') {\n const lastSep = Math.max(planPath.lastIndexOf('/'), planPath.lastIndexOf('\\\\'));\n planPath = lastSep >= 0 ? planPath.slice(0, lastSep + 1) + 'backlog.plan.json' : 'backlog.plan.json';\n }\n // Mutate the cross-file under ITS OWN lock so a concurrent plan tool\n // call in the same batch can't clobber the write.\n let formatted = '';\n try {\n await mutatePlan(planPath, sessionId, (pf) => {\n const { plan: updated } = addPlanItem(pf, title, details || undefined);\n formatted = formatPlan(updated);\n return updated;\n });\n } catch (err) {\n return {\n ok: false,\n message: `planify: plan not saved \u2014 ${err instanceof Error ? err.message : String(err)}`,\n count: file.tasks.length,\n completed: prog.completed,\n inProgress: prog.inProgress,\n };\n }\n return {\n ok: true,\n message: `planify ok \u2014 added \"${title}\" to plan.\\n${formatted}`,\n count: file.tasks.length,\n completed: prog.completed,\n inProgress: prog.inProgress,\n };\n }\n // Plan path missing \u2014 still report the REAL task counts (the task file was\n // loaded and may be non-empty), not zeros.\n return {\n ok: false,\n message: 'Plan storage path not configured \u2014 cannot planify.',\n count: file.tasks.length,\n completed: prog.completed,\n inProgress: prog.inProgress,\n };\n }\n\n const p = computeTaskItemProgress(file.tasks);\n const summary = promoteMeta.count > 0\n ? `promote ok \u2014 ${promoteMeta.count} todo(s) created from \"${promoteMeta.title}\".\\n${formatTaskList(file.tasks)}`\n : file.tasks.length > 0\n ? formatTaskList(file.tasks)\n : 'No tasks.';\n return {\n ok: true,\n message: summary,\n count: file.tasks.length,\n completed: p.completed,\n inProgress: p.inProgress,\n };\n },\n};\n", "import { type FSWatcher, watch } from 'node:fs';\nimport { basename, dirname } from 'node:path';\nimport type { Context, TodoItem } from '@wrongstack/core/agent';\nimport { GlobalMailbox } from '@wrongstack/core/coordination';\nimport {\n loadPlan,\n loadTasks,\n mutatePlan,\n mutateTasks,\n type PlanFile,\n type PlanItem,\n type TaskFile,\n} from '@wrongstack/core/storage';\nimport { deserializeTaskGraph } from '@wrongstack/core/tasking';\nimport type { SerializedTaskGraph, TaskStatus } from '@wrongstack/core/types';\nimport { resolveWstackPaths, type TaskItem } from '@wrongstack/core/utils';\nimport {\n createBoard,\n getBoard,\n getKanbanDir,\n type KanbanBoard,\n type KanbanColumn,\n type KanbanTask,\n listBoards,\n removeBoard,\n syncBoardFromTaskGraph,\n touchKanbanPresence,\n updateBoard,\n} from '@wrongstack/kanban';\n\nconst SESSION_BOARD_TAG = 'session-work';\nconst MIRROR_DISABLED_ENV = 'WRONGSTACK_KANBAN_TASK_MIRROR';\n\n/** The canonical workflow shared by WebUI and TUI session boards. */\nexport const SESSION_KANBAN_COLUMNS: KanbanColumn[] = [\n { id: 'todo', title: 'Todo', order: 0, wipLimit: 0, color: '#2563eb' },\n { id: 'in-progress', title: 'Running', order: 1, wipLimit: 1, color: '#d97706' },\n { id: 'review', title: 'Preview', order: 2, wipLimit: 0, color: '#7c3aed' },\n { id: 'done', title: 'Done', order: 3, wipLimit: 0, color: '#16a34a' },\n];\n\nconst boardQueue = new Map<string, Promise<void>>();\nconst boardEnsures = new Map<string, Promise<KanbanBoard>>();\ntype PendingMirror = {\n projectRoot: string;\n sessionId: string;\n graph: SerializedTaskGraph;\n sourceSystem: 'session-todo' | 'session-task' | 'session-plan';\n};\nconst pendingMirrors = new Map<string, PendingMirror>();\nconst activeMirrors = new Set<string>();\nconst bindings = new WeakMap<Context, () => void>();\nconst suppressedTodoMirrors = new WeakSet<Context>();\nconst activeSessionBoards = new Map<string, number>();\n\nfunction boardKey(projectRoot: string, sessionId: string): string {\n return `${projectRoot}\\0${sessionId}`;\n}\n\nfunction mirrorKey(\n projectRoot: string,\n sessionId: string,\n sourceSystem: PendingMirror['sourceSystem'],\n): string {\n return `${boardKey(projectRoot, sessionId)}\\0${sourceSystem}`;\n}\n\nfunction sessionTag(sessionId: string): string {\n return `session:${sessionId}`;\n}\n\nfunction sessionBoardTitle(sessionId: string): string {\n const leaf = sessionId.split(/[\\\\/]/).filter(Boolean).pop() ?? sessionId;\n return `Session ${leaf.slice(0, 12)}`;\n}\n\nfunction sessionBoardTags(sessionId: string): string[] {\n return ['session', SESSION_BOARD_TAG, sessionTag(sessionId)];\n}\n\nfunction sessionIdFromTags(tags: readonly string[] | undefined): string | null {\n const tag = tags?.find((candidate) => candidate.startsWith('session:'));\n return tag?.slice('session:'.length) || null;\n}\n\nfunction isOwnedSessionBoard(tags: readonly string[] | undefined): boolean {\n return Boolean(tags?.includes(SESSION_BOARD_TAG) && sessionIdFromTags(tags));\n}\n\nfunction retainActiveSessionBoard(projectRoot: string, sessionId: string): void {\n const key = boardKey(projectRoot, sessionId);\n activeSessionBoards.set(key, (activeSessionBoards.get(key) ?? 0) + 1);\n}\n\nfunction releaseActiveSessionBoard(projectRoot: string, sessionId: string): void {\n const key = boardKey(projectRoot, sessionId);\n const remaining = (activeSessionBoards.get(key) ?? 0) - 1;\n if (remaining > 0) activeSessionBoards.set(key, remaining);\n else activeSessionBoards.delete(key);\n}\n\nfunction isSessionBoardActive(projectRoot: string, sessionId: string): boolean {\n return (activeSessionBoards.get(boardKey(projectRoot, sessionId)) ?? 0) > 0;\n}\n\nfunction sameColumns(columns: readonly KanbanColumn[]): boolean {\n return (\n columns.length === SESSION_KANBAN_COLUMNS.length &&\n columns.every((column, index) => column.id === SESSION_KANBAN_COLUMNS[index]?.id)\n );\n}\n\n/** Create (or migrate) the single Kanban board owned by a session. */\nexport async function ensureSessionKanbanBoard(\n projectRoot: string | undefined,\n sessionId: string,\n): Promise<KanbanBoard | null> {\n if (!projectRoot || !sessionId || process.env[MIRROR_DISABLED_ENV] === '0') return null;\n const key = boardKey(projectRoot, sessionId);\n const inFlight = boardEnsures.get(key);\n if (inFlight) return inFlight;\n\n const promise = (async () => {\n const summary = (await listBoards(projectRoot)).find((board) =>\n board.tags?.includes(sessionTag(sessionId)),\n );\n let board = summary ? await getBoard(projectRoot, summary.id) : null;\n if (!board) {\n return createBoard(projectRoot, {\n title: sessionBoardTitle(sessionId),\n description: 'Live session work: todos, tasks, and plan items.',\n tags: sessionBoardTags(sessionId),\n columns: SESSION_KANBAN_COLUMNS,\n generatedBy: `session-kanban:${sessionId}`,\n });\n }\n\n // Boards produced by the older task/plan mirrors used the generic five\n // columns. Migrate only session-owned boards; updateBoard reconciles cards\n // from Backlog into Todo while preserving Running/Preview/Done cards.\n if (!sameColumns(board.columns) || !board.tags?.includes(SESSION_BOARD_TAG)) {\n board =\n (await updateBoard(projectRoot, board.id, {\n title: sessionBoardTitle(sessionId),\n description: 'Live session work: todos, tasks, and plan items.',\n tags: [...new Set([...(board.tags ?? []), ...sessionBoardTags(sessionId)])],\n columns: SESSION_KANBAN_COLUMNS,\n })) ?? board;\n }\n return board;\n })();\n\n boardEnsures.set(key, promise);\n try {\n return await promise;\n } finally {\n boardEnsures.delete(key);\n }\n}\n\nfunction enqueueBoardWork<T>(\n projectRoot: string,\n sessionId: string,\n work: () => Promise<T>,\n): Promise<T> {\n const key = boardKey(projectRoot, sessionId);\n const previous = boardQueue.get(key) ?? Promise.resolve();\n const result = previous.catch(() => undefined).then(work);\n const tail = result.then(\n () => undefined,\n () => undefined,\n );\n boardQueue.set(key, tail);\n void tail.then(() => {\n if (boardQueue.get(key) === tail) boardQueue.delete(key);\n });\n return result;\n}\n\nasync function removeEmptySessionBoard(\n projectRoot: string,\n boardId: string,\n sessionId: string,\n): Promise<string | null> {\n return enqueueBoardWork(projectRoot, sessionId, async () => {\n if (isSessionBoardActive(projectRoot, sessionId)) return null;\n const board = await getBoard(projectRoot, boardId);\n if (!board || board.tasks.length > 0 || !isOwnedSessionBoard(board.tags)) return null;\n if (sessionIdFromTags(board.tags) !== sessionId) return null;\n return (await removeBoard(projectRoot, board.id)) ? board.id : null;\n });\n}\n\n/** Remove a particular inactive session's system-owned board when it has no cards. */\nexport async function cleanupSessionKanbanBoardIfEmpty(\n projectRoot: string | undefined,\n sessionId: string,\n): Promise<string[]> {\n if (!projectRoot || !sessionId || process.env[MIRROR_DISABLED_ENV] === '0') return [];\n if (isSessionBoardActive(projectRoot, sessionId)) return [];\n const candidates = (await listBoards(projectRoot)).filter(\n (board) =>\n board.taskCount === 0 &&\n isOwnedSessionBoard(board.tags) &&\n sessionIdFromTags(board.tags) === sessionId,\n );\n const removed = await Promise.all(\n candidates.map((board) => removeEmptySessionBoard(projectRoot, board.id, sessionId)),\n );\n return removed.filter((boardId): boardId is string => Boolean(boardId));\n}\n\n/** Prune stale empty session boards while preserving manual and live boards. */\nexport async function cleanupEmptySessionKanbanBoards(\n projectRoot: string | undefined,\n activeSessionId = '',\n): Promise<string[]> {\n if (!projectRoot || process.env[MIRROR_DISABLED_ENV] === '0') return [];\n const candidates = (await listBoards(projectRoot)).flatMap((board) => {\n const ownerSessionId = sessionIdFromTags(board.tags);\n return board.taskCount === 0 &&\n isOwnedSessionBoard(board.tags) &&\n ownerSessionId &&\n ownerSessionId !== activeSessionId &&\n !isSessionBoardActive(projectRoot, ownerSessionId)\n ? [{ boardId: board.id, sessionId: ownerSessionId }]\n : [];\n });\n const removed = await Promise.all(\n candidates.map(({ boardId, sessionId }) =>\n removeEmptySessionBoard(projectRoot, boardId, sessionId),\n ),\n );\n return removed.filter((boardId): boardId is string => Boolean(boardId));\n}\n\nasync function projectGraph(\n projectRoot: string | undefined,\n sessionId: string,\n graph: SerializedTaskGraph,\n sourceSystem: 'session-todo' | 'session-task' | 'session-plan',\n): Promise<KanbanBoard | null> {\n if (!projectRoot || !sessionId || process.env[MIRROR_DISABLED_ENV] === '0') return null;\n return enqueueBoardWork(projectRoot, sessionId, async () => {\n const board = await ensureSessionKanbanBoard(projectRoot, sessionId);\n if (!board) return null;\n const result = await syncBoardFromTaskGraph(\n projectRoot,\n board.id,\n deserializeTaskGraph(graph),\n {\n sourceSystem,\n tags: [...new Set([...(board.tags ?? []), ...sessionBoardTags(sessionId)])],\n archiveMissingTasks: true,\n includeCompletedTasks: true,\n },\n );\n return result?.board ?? null;\n });\n}\n\n/**\n * Queue an observational mirror without retaining every intermediate state.\n * Todo/task/plan streams are independent, but within each stream only the\n * newest pending graph matters. This bounds a stalled file lock to one active\n * and one pending projection instead of an arbitrarily long Promise chain.\n */\nfunction queueLatestMirror(\n projectRoot: string | undefined,\n sessionId: string,\n graph: SerializedTaskGraph,\n sourceSystem: PendingMirror['sourceSystem'],\n): void {\n if (!projectRoot || !sessionId || process.env[MIRROR_DISABLED_ENV] === '0') return;\n const key = mirrorKey(projectRoot, sessionId, sourceSystem);\n pendingMirrors.set(key, { projectRoot, sessionId, graph, sourceSystem });\n if (activeMirrors.has(key)) return;\n activeMirrors.add(key);\n void (async () => {\n try {\n for (;;) {\n const pending = pendingMirrors.get(key);\n if (!pending) break;\n pendingMirrors.delete(key);\n try {\n await projectGraph(\n pending.projectRoot,\n pending.sessionId,\n pending.graph,\n pending.sourceSystem,\n );\n } catch {\n // Mirrors are observational. A newer pending snapshot, if present,\n // still gets a chance after a transient lock or filesystem failure.\n }\n }\n } finally {\n activeMirrors.delete(key);\n // A mirror can arrive between the last Map read and deleting the active\n // marker. Re-arm once so that snapshot cannot be stranded.\n const pending = pendingMirrors.get(key);\n if (pending) {\n pendingMirrors.delete(key);\n queueLatestMirror(\n pending.projectRoot,\n pending.sessionId,\n pending.graph,\n pending.sourceSystem,\n );\n }\n }\n })();\n}\n\nexport function todoListToSerializedGraph(\n todos: readonly TodoItem[],\n sessionId: string,\n): SerializedTaskGraph {\n const nodes = todos.map((todo, index) => ({\n id: todo.id,\n title: todo.content,\n description: todo.activeForm ?? '',\n type: 'chore' as const,\n priority: 'medium' as const,\n status: todo.status,\n createdAt: index,\n updatedAt: index,\n }));\n return {\n id: `todo:${sessionId}`,\n specId: `todo:${sessionId}`,\n title: 'Session todos',\n nodes,\n edges: [],\n rootNodes: nodes.map((node) => node.id),\n createdAt: 0,\n updatedAt: 0,\n };\n}\n\nexport function taskFileToSerializedGraph(\n tasks: readonly TaskItem[],\n sessionId: string,\n): SerializedTaskGraph {\n const ids = new Set(tasks.map((task) => task.id));\n const nodes = tasks.map((task, index) => ({\n id: task.id,\n title: task.title,\n description: task.description ?? '',\n type: task.type,\n priority: task.priority,\n status: task.status,\n ...(task.assignee ? { assignee: task.assignee } : {}),\n ...(task.estimateHours !== undefined ? { estimateHours: task.estimateHours } : {}),\n createdAt: index,\n updatedAt: index,\n }));\n const edges = tasks.flatMap((task) =>\n (task.dependsOn ?? [])\n .filter((dependency) => ids.has(dependency))\n .map((dependency) => ({\n id: `${dependency}->${task.id}`,\n from: dependency,\n to: task.id,\n type: 'depends_on' as const,\n })),\n );\n const hasIncoming = new Set(edges.map((edge) => edge.to));\n const rootNodes = nodes.filter((node) => !hasIncoming.has(node.id)).map((node) => node.id);\n return {\n // Keep the historical graph id so existing mirrored task cards are reused.\n id: `session:${sessionId}`,\n specId: `session:${sessionId}`,\n title: 'Session tasks',\n nodes,\n edges,\n rootNodes: rootNodes.length ? rootNodes : nodes[0] ? [nodes[0].id] : [],\n createdAt: 0,\n updatedAt: 0,\n };\n}\n\nconst PLAN_STATUS_TO_TASK: Record<PlanItem['status'], TaskStatus> = {\n open: 'pending',\n in_progress: 'in_progress',\n done: 'completed',\n};\n\nexport function planFileToSerializedGraph(\n items: readonly PlanItem[],\n sessionId: string,\n): SerializedTaskGraph {\n const nodes = items.map((item, index) => ({\n id: item.id,\n title: item.title,\n description: item.details ?? '',\n type: 'chore' as const,\n priority: 'medium' as const,\n status: PLAN_STATUS_TO_TASK[item.status],\n createdAt: index,\n updatedAt: index,\n }));\n return {\n id: `plan:${sessionId}`,\n specId: `plan:${sessionId}`,\n title: 'Session plan',\n nodes,\n edges: [],\n rootNodes: nodes.map((node) => node.id),\n createdAt: 0,\n updatedAt: 0,\n };\n}\n\nexport function projectSessionTodosToKanban(\n projectRoot: string | undefined,\n todos: readonly TodoItem[],\n sessionId: string,\n): Promise<KanbanBoard | null> {\n return projectGraph(\n projectRoot,\n sessionId,\n todoListToSerializedGraph(todos, sessionId),\n 'session-todo',\n );\n}\n\nexport function projectSessionTasksToKanban(\n projectRoot: string | undefined,\n tasks: readonly TaskItem[],\n sessionId: string,\n): Promise<KanbanBoard | null> {\n return projectGraph(\n projectRoot,\n sessionId,\n taskFileToSerializedGraph(tasks, sessionId),\n 'session-task',\n );\n}\n\nexport function projectSessionPlanToKanban(\n projectRoot: string | undefined,\n items: readonly PlanItem[],\n sessionId: string,\n): Promise<KanbanBoard | null> {\n return projectGraph(\n projectRoot,\n sessionId,\n planFileToSerializedGraph(items, sessionId),\n 'session-plan',\n );\n}\n\nfunction fireAndForget(context: string, work: Promise<unknown>): void {\n void work.catch((err: unknown) => {\n const message = err instanceof Error ? err.message : String(err);\n console.warn(JSON.stringify({ level: 'warn', event: 'session-kanban', context, message, timestamp: new Date().toISOString() }));\n });\n}\n\nfunction broadcastTodoUpdate(context: Context, todos: readonly TodoItem[]): void {\n const sessionId = context.session?.id ?? '';\n if (!context.agentId || !sessionId) return;\n const projectDir = resolveWstackPaths({ projectRoot: context.projectRoot }).projectDir;\n const mailbox = new GlobalMailbox(projectDir);\n void mailbox\n .send({\n from: context.agentId,\n to: '*',\n type: 'status',\n subject: `Kanban todo list updated (${todos.length} item${todos.length === 1 ? '' : 's'})`,\n body: JSON.stringify({\n kind: 'kanban.todos.updated',\n sessionId,\n revision: context.state.revision,\n todos,\n }),\n priority: 'normal',\n senderSessionId: sessionId,\n ttlMs: 6 * 60 * 60 * 1000,\n })\n .catch(() => {\n // Mailbox awareness is best-effort; canonical state is already updated.\n });\n}\n\nfunction notifyTodoUpdate(context: Context, todos: readonly TodoItem[]): void {\n const summary = todos.length\n ? todos.map((todo) => `- [${todo.status}] ${todo.content} (${todo.id})`).join('\\n')\n : '- No active todos remain.';\n const text = `[KANBAN TODO UPDATE]\\nAnother Kanban agent reassessed the shared board. The canonical todo list is now:\\n${summary}\\nReassess your current plan before continuing; do not rely on the initial todo snapshot.`;\n const state = context.state as Partial<Context['state']>;\n if (typeof state.appendBlockToLastUserMessage === 'function') {\n if (state.appendBlockToLastUserMessage({ type: 'text', text })) return;\n }\n if (typeof state.appendMessage === 'function') {\n state.appendMessage({ role: 'user', content: [{ type: 'text', text }] });\n }\n}\n\nexport function mirrorSessionTodosToKanban(\n projectRoot: string | undefined,\n todos: readonly TodoItem[],\n sessionId: string,\n): void {\n queueLatestMirror(\n projectRoot,\n sessionId,\n todoListToSerializedGraph(todos, sessionId),\n 'session-todo',\n );\n}\n\nexport function mirrorSessionTasksToKanban(\n projectRoot: string | undefined,\n tasks: readonly TaskItem[],\n sessionId: string,\n): void {\n queueLatestMirror(\n projectRoot,\n sessionId,\n taskFileToSerializedGraph(tasks, sessionId),\n 'session-task',\n );\n}\n\nexport function mirrorSessionPlanToKanban(\n projectRoot: string | undefined,\n items: readonly PlanItem[],\n sessionId: string,\n): void {\n queueLatestMirror(\n projectRoot,\n sessionId,\n planFileToSerializedGraph(items, sessionId),\n 'session-plan',\n );\n}\n\n/**\n * Bind all live session work paths to Kanban. Todo changes are observed from\n * ConversationState; plan/task sidecars are watched so slash commands, WebUI,\n * plugins, and tools all pass through the same board.\n */\nexport function attachSessionKanbanMirror(context: Context): () => void {\n const existing = bindings.get(context);\n if (existing) return existing;\n\n const attachedProjectRoot = context.projectRoot ?? '';\n let registeredSessionId = '';\n const syncActiveSessionRegistration = () => {\n if (!attachedProjectRoot) return;\n const currentSessionId = context.session?.id ?? '';\n if (currentSessionId === registeredSessionId) return;\n if (registeredSessionId) {\n releaseActiveSessionBoard(attachedProjectRoot, registeredSessionId);\n fireAndForget(\n 'cleanup-board',\n cleanupSessionKanbanBoardIfEmpty(attachedProjectRoot, registeredSessionId),\n );\n }\n registeredSessionId = currentSessionId;\n if (registeredSessionId) {\n retainActiveSessionBoard(attachedProjectRoot, registeredSessionId);\n }\n };\n syncActiveSessionRegistration();\n\n let watcher: FSWatcher | null = null;\n let watchedDir = '';\n let timer: NodeJS.Timeout | null = null;\n let boardWatcher: FSWatcher | null = null;\n let watchedBoardId = '';\n let boardTimer: NodeJS.Timeout | null = null;\n let presenceTimer: NodeJS.Timeout | null = null;\n\n const sessionId = () => context.session?.id ?? '';\n const refreshFiles = async () => {\n const id = sessionId();\n if (!id) return;\n const planPath = context.meta['plan.path'];\n if (typeof planPath === 'string' && planPath) {\n const plan = await loadPlan(planPath);\n if (plan) await projectSessionPlanToKanban(context.projectRoot, plan.items, id);\n }\n const taskPath = context.meta['task.path'];\n if (typeof taskPath === 'string' && taskPath) {\n const tasks = await loadTasks(taskPath);\n if (tasks) await projectSessionTasksToKanban(context.projectRoot, tasks.tasks, id);\n }\n };\n\n const refreshBoard = async () => {\n if (!watchedBoardId) return;\n const board = await getBoard(context.projectRoot, watchedBoardId);\n if (board) applySessionKanbanBoardToTodos(context, board);\n };\n\n const configureBoardWatcher = async () => {\n const id = sessionId();\n const board = id ? await ensureSessionKanbanBoard(context.projectRoot, id) : null;\n if (!board || board.id === watchedBoardId) return;\n boardWatcher?.close();\n boardWatcher = null;\n watchedBoardId = board.id;\n try {\n const boardFileName = `${board.id}.json`;\n boardWatcher = watch(\n getKanbanDir(context.projectRoot),\n { persistent: false },\n (_event, filename) => {\n if (filename?.toString() !== boardFileName) return;\n if (boardTimer) clearTimeout(boardTimer);\n boardTimer = setTimeout(() => fireAndForget('refresh-board', refreshBoard()), 60);\n },\n );\n const touchPresence = () =>\n touchKanbanPresence(context.projectRoot, board.id, {\n sessionId: id,\n agentId: context.agentId,\n agentName: context.agentName,\n });\n fireAndForget('touch-presence', touchPresence());\n if (presenceTimer) clearInterval(presenceTimer);\n presenceTimer = setInterval(() => fireAndForget('touch-presence', touchPresence()), 60_000);\n presenceTimer.unref?.();\n boardWatcher.on('error', () => {\n boardWatcher?.close();\n boardWatcher = null;\n watchedBoardId = '';\n });\n } catch {\n boardWatcher = null;\n watchedBoardId = '';\n }\n };\n\n const configureWatcher = () => {\n const planPath = context.meta['plan.path'];\n const taskPath = context.meta['task.path'];\n const candidate =\n typeof planPath === 'string' && planPath\n ? dirname(planPath)\n : typeof taskPath === 'string' && taskPath\n ? dirname(taskPath)\n : '';\n if (!candidate || candidate === watchedDir) return;\n watcher?.close();\n watcher = null;\n watchedDir = candidate;\n try {\n watcher = watch(candidate, { persistent: false }, (_event, filename) => {\n const name = filename?.toString();\n const currentPlanPath = context.meta['plan.path'];\n const currentTaskPath = context.meta['task.path'];\n const planName = typeof currentPlanPath === 'string' ? basename(currentPlanPath) : '';\n const taskName = typeof currentTaskPath === 'string' ? basename(currentTaskPath) : '';\n if (name && name !== planName && name !== taskName) return;\n if (timer) clearTimeout(timer);\n timer = setTimeout(() => fireAndForget('refresh-files', refreshFiles()), 60);\n });\n watcher.on('error', () => watcher?.close());\n } catch {\n // The session directory can briefly disappear during project/session\n // switches; the next meta update re-attempts the binding.\n watcher = null;\n watchedDir = '';\n }\n };\n\n const unsubscribe = context.state.onChange((change) => {\n if (change.kind === 'todos_replaced' && !suppressedTodoMirrors.has(context)) {\n // ConversationState auto-clears an all-done tactical list. Project the\n // pre-clear completion snapshot so every card reaches Done atomically.\n mirrorSessionTodosToKanban(\n context.projectRoot,\n change.completedSnapshot ?? change.todos,\n sessionId(),\n );\n return;\n }\n if (change.kind === 'meta_set' && (change.key === 'plan.path' || change.key === 'task.path')) {\n syncActiveSessionRegistration();\n configureWatcher();\n fireAndForget('ensure-board', ensureSessionKanbanBoard(context.projectRoot, sessionId()));\n fireAndForget('configure-watcher', configureBoardWatcher());\n fireAndForget('refresh-files', refreshFiles());\n }\n });\n\n configureWatcher();\n fireAndForget('configure-watcher', configureBoardWatcher());\n\n const detach = () => {\n unsubscribe();\n if (timer) clearTimeout(timer);\n if (boardTimer) clearTimeout(boardTimer);\n if (presenceTimer) clearInterval(presenceTimer);\n watcher?.close();\n boardWatcher?.close();\n bindings.delete(context);\n if (attachedProjectRoot && registeredSessionId) {\n releaseActiveSessionBoard(attachedProjectRoot, registeredSessionId);\n fireAndForget(\n 'cleanup-board',\n cleanupSessionKanbanBoardIfEmpty(attachedProjectRoot, registeredSessionId),\n );\n registeredSessionId = '';\n }\n };\n bindings.set(context, detach);\n return detach;\n}\n\n/** Fully hydrate a session board before a host announces the session as ready. */\nexport async function hydrateSessionKanban(context: Context): Promise<KanbanBoard | null> {\n const id = context.session?.id ?? '';\n if (!id) return null;\n await cleanupEmptySessionKanbanBoards(context.projectRoot, id);\n let board = await ensureSessionKanbanBoard(context.projectRoot, id);\n if (context.todos.length) {\n board = await projectSessionTodosToKanban(context.projectRoot, context.todos, id);\n }\n const planPath = context.meta['plan.path'];\n if (typeof planPath === 'string' && planPath) {\n const plan = await loadPlan(planPath);\n if (plan) board = await projectSessionPlanToKanban(context.projectRoot, plan.items, id);\n }\n const taskPath = context.meta['task.path'];\n if (typeof taskPath === 'string' && taskPath) {\n const tasks = await loadTasks(taskPath);\n if (tasks) board = await projectSessionTasksToKanban(context.projectRoot, tasks.tasks, id);\n }\n return board;\n}\n\nexport interface SessionKanbanSourceUpdate {\n source: 'todo' | 'task' | 'plan' | null;\n todos?: TodoItem[] | undefined;\n tasks?: TaskFile | undefined;\n plan?: PlanFile | undefined;\n}\n\nfunction sourceStatus(task: KanbanTask): TaskStatus {\n if (task.status === 'completed') return 'completed';\n if (task.status === 'in_progress') return 'in_progress';\n if (task.status === 'review') return 'review';\n if (task.status === 'blocked') return 'blocked';\n if (task.status === 'failed') return 'failed';\n return 'pending';\n}\n\nfunction todoStatus(task: KanbanTask): TodoItem['status'] {\n const status = sourceStatus(task);\n if (status === 'completed') return 'completed';\n if (status === 'in_progress' || status === 'review') return 'in_progress';\n return 'pending';\n}\n\nfunction sessionTodoFromTask(task: KanbanTask): TodoItem {\n return {\n id: task.origin?.taskId ?? task.id,\n content: task.title,\n status: todoStatus(task),\n ...(task.description ? { activeForm: task.description } : {}),\n };\n}\n\nfunction sameTodos(left: readonly TodoItem[], right: readonly TodoItem[]): boolean {\n return (\n left.length === right.length &&\n left.every((todo, index) => {\n const candidate = right[index];\n return (\n candidate?.id === todo.id &&\n candidate.content === todo.content &&\n candidate.status === todo.status &&\n candidate.activeForm === todo.activeForm &&\n candidate.promotedFromPlan === todo.promotedFromPlan &&\n candidate.promotedFromTask === todo.promotedFromTask\n );\n })\n );\n}\n\n/**\n * Replace the tactical todo list from the current cards on a session-owned board.\n *\n * Existing mirrored todo cards retain their stable source ids. New cards created\n * by a Kanban worker become todos under their card ids, so reassessment can add,\n * split, merge, reprioritize, or remove work without being overwritten by the\n * todo list that happened to exist when the run started.\n */\nexport function applySessionKanbanBoardToTodos(context: Context, board: KanbanBoard): TodoItem[] {\n const sessionId = context.session?.id ?? '';\n if (\n !sessionId ||\n sessionIdFromTags(board.tags) !== sessionId ||\n !isOwnedSessionBoard(board.tags)\n ) {\n return [...context.todos];\n }\n\n const projectedTodos = board.tasks\n .filter(\n (task) =>\n task.status !== 'archived' &&\n (!task.origin ||\n task.origin.system === 'session-todo' ||\n (task.origin.graphId ?? '').startsWith('todo:')),\n )\n .sort((left, right) => {\n const leftColumn = board.columns.find((column) => column.id === left.columnId)?.order ?? 0;\n const rightColumn = board.columns.find((column) => column.id === right.columnId)?.order ?? 0;\n return (\n leftColumn - rightColumn ||\n left.order - right.order ||\n left.createdAt.localeCompare(right.createdAt)\n );\n })\n .map(sessionTodoFromTask);\n\n const allCompleted =\n projectedTodos.length > 0 && projectedTodos.every((todo) => todo.status === 'completed');\n const effectiveTodos = allCompleted ? [] : projectedTodos;\n if (sameTodos(context.todos, effectiveTodos)) return [...context.todos];\n suppressedTodoMirrors.add(context);\n try {\n context.state.replaceTodos(projectedTodos);\n } finally {\n suppressedTodoMirrors.delete(context);\n }\n notifyTodoUpdate(context, context.todos);\n broadcastTodoUpdate(context, context.todos);\n return [...context.todos];\n}\n\n/** Reflect a TUI/WebUI Kanban card edit back to its originating work list. */\nexport async function applySessionKanbanTaskToSource(\n context: Context,\n task: KanbanTask,\n options: { remove?: boolean | undefined } = {},\n): Promise<SessionKanbanSourceUpdate> {\n const originId = task.origin?.taskId;\n const graphId = task.origin?.graphId ?? '';\n if (!originId) return { source: null };\n\n if (task.origin?.system === 'session-todo' || graphId.startsWith('todo:')) {\n const next = options.remove\n ? context.todos.filter((todo) => todo.id !== originId)\n : context.todos.map((todo) =>\n todo.id === originId\n ? {\n ...todo,\n content: task.title,\n status:\n sourceStatus(task) === 'completed'\n ? ('completed' as const)\n : sourceStatus(task) === 'in_progress' || sourceStatus(task) === 'review'\n ? ('in_progress' as const)\n : ('pending' as const),\n }\n : todo,\n );\n suppressedTodoMirrors.add(context);\n try {\n context.state.replaceTodos(next);\n } finally {\n suppressedTodoMirrors.delete(context);\n }\n return { source: 'todo', todos: [...context.todos] };\n }\n\n const id = context.session?.id ?? '';\n if (task.origin?.system === 'session-plan' || graphId.startsWith('plan:')) {\n const planPath = context.meta['plan.path'];\n if (typeof planPath !== 'string' || !planPath) return { source: 'plan' };\n const plan = await mutatePlan(planPath, id, (file) => ({\n ...file,\n updatedAt: new Date().toISOString(),\n items: options.remove\n ? file.items.filter((item) => item.id !== originId)\n : file.items.map((item) =>\n item.id === originId\n ? {\n ...item,\n title: task.title,\n details: task.description,\n status:\n task.status === 'completed'\n ? ('done' as const)\n : task.status === 'in_progress' || task.status === 'review'\n ? ('in_progress' as const)\n : ('open' as const),\n updatedAt: new Date().toISOString(),\n }\n : item,\n ),\n }));\n return { source: 'plan', plan };\n }\n\n if (\n task.origin?.system === 'session-task' ||\n task.origin?.system === 'session' ||\n graphId.startsWith('session:')\n ) {\n const taskPath = context.meta['task.path'];\n if (typeof taskPath !== 'string' || !taskPath) return { source: 'task' };\n const tasks = await mutateTasks(taskPath, id, (file) => ({\n ...file,\n tasks: options.remove\n ? file.tasks.filter((item) => item.id !== originId)\n : file.tasks.map((item) =>\n item.id === originId\n ? {\n ...item,\n title: task.title,\n description: task.description,\n status: sourceStatus(task),\n updatedAt: new Date().toISOString(),\n }\n : item,\n ),\n }));\n return { source: 'task', tasks };\n }\n\n return { source: null };\n}\n"],
5
- "mappings": ";AAEA;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AACP,SAAS,eAAAA,oBAAmB;AAC5B;AAAA,EACE;AAAA,EACA,cAAAC;AAAA,EACA;AAAA,OACK;AACP,SAAS,kBAAkB;;;ACV3B,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AACP,SAAS,4BAA4B;AAEr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AAA,QACnB;AAAA,MACF;AAGA,aAAO;AAAA,QACL,IAAI;AAAA,QACJ,SAAS;AAAA,QACT,OAAO,KAAK,MAAM;AAAA,QAClB,WAAW,KAAK;AAAA,QAChB,YAAY,KAAK;AAAA,MACnB;AAAA,IACF;AAEA,UAAM,IAAI,wBAAwB,KAAK,KAAK;AAC5C,UAAM,UAAU,YAAY,QAAQ,IAChC,qBAAgB,YAAY,KAAK,0BAA0B,YAAY,KAAK;AAAA,EAAO,eAAe,KAAK,KAAK,CAAC,KAC7G,KAAK,MAAM,SAAS,IAClB,eAAe,KAAK,KAAK,IACzB;AACN,WAAO;AAAA,MACL,IAAI;AAAA,MACJ,SAAS;AAAA,MACT,OAAO,KAAK,MAAM;AAAA,MAClB,WAAW,EAAE;AAAA,MACb,YAAY,EAAE;AAAA,IAChB;AAAA,EACF;AACF;",
4
+ "sourcesContent": ["import type { TaskStatus } from '@wrongstack/core/types';\nimport type { TaskFile } from '@wrongstack/core/storage';\nimport {\n computeTaskItemProgress,\n formatTaskList,\n type TaskItem,\n} from '@wrongstack/core/utils';\nimport { mutateTasks } from '@wrongstack/core/storage';\nimport {\n addPlanItem,\n mutatePlan,\n formatPlan,\n} from '@wrongstack/core/storage';\nimport { randomUUID } from 'node:crypto';\nimport type { Tool } from '@wrongstack/core/types';\nimport { mirrorSessionTasksToKanban } from './session-kanban.js';\n\n// ---------------------------------------------------------------------------\n// Task tool \u2014 structured work items with dependencies, types, and priorities.\n// Unlike `todo` (flat, session-scoped), tasks support:\n// - Dependencies (task can depend on other tasks)\n// - Type classification (feature, bugfix, refactor, docs, test, chore)\n// - Priority ranking (critical, high, medium, low)\n// - Assignment (which agent/subagent)\n// - Estimates (hours)\n//\n// Like `todo`, the list is fully replaced on every call. Session-persistent:\n// stored at `ctx.meta['task.path']` and isolated to this session \u2014 other sessions\n// have their own separate task lists.\n// ---------------------------------------------------------------------------\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\n/** Find a task by 1-based index, exact id, or case-insensitive title substring. */\nfunction findTaskIndex(tasks: TaskItem[], query: string): number {\n const asNum = Number.parseInt(query, 10);\n if (!Number.isNaN(asNum)) {\n const idx = asNum - 1;\n if (tasks[idx]) return idx;\n }\n const byId = tasks.findIndex((t) => t.id === query);\n if (byId >= 0) return byId;\n const lower = query.toLowerCase();\n return tasks.findIndex((t) => t.title.toLowerCase().includes(lower));\n}\n\n// ---------------------------------------------------------------------------\n// Tool\n// ---------------------------------------------------------------------------\n\ninterface TaskInput {\n /** Replace: set new task list. Add: append a task. Status: update task status. Promote: convert a task to todo items. */\n action: 'replace' | 'add' | 'status' | 'show' | 'promote' | 'planify';\n /** Full task list for action=replace. */\n tasks?: TaskItem[] | undefined;\n /** Single task for action=add. id, createdAt, updatedAt are auto-generated. */\n task?: Omit<TaskItem, 'id' | 'createdAt' | 'updatedAt'> | undefined;\n /** Task id for action=status or target for action=promote. */\n id?: string | undefined;\n /** New status for action=status. */\n status?: TaskStatus | undefined;\n /** Target task (id, 1-based index, or title substring) for action=promote. */\n target?: string | undefined;\n /** Optional subtask titles for action=promote. */\n subtasks?: string[] | undefined;\n /**\n * Storage scope. Default (unset): uses the session-scoped path \u2014 isolated to this\n * session, survives resume within the same session.\n * `scope: 'project'`: uses a shared project-level path, visible to all sessions\n * for this project. Useful for a shared backlog that outlasts any single session.\n */\n scope?: 'session' | 'project';\n}\n\ninterface TaskOutput {\n ok: boolean;\n message: string;\n count: number;\n completed: number;\n inProgress: number;\n}\n\nexport const taskTool: Tool<TaskInput, TaskOutput> = {\n name: 'task',\n category: 'Session',\n description:\n 'Manage session-persistent structured work items with dependencies, types, and priorities. ' +\n 'Unlike `todo` (flat, tactical), `task` supports typed work (feature/bugfix/refactor/etc.), ' +\n 'dependencies between items, priority ranking, and agent assignment. ' +\n 'Tasks are written to disk and survive session resumes. By default they are isolated to this session; ' +\n 'use `scope: \"project\"` to store tasks in a shared project-level file visible to all sessions.',\n usageHint:\n 'USE FOR STRUCTURED WORK:\\n' +\n '- `action: \"replace\"` \u2014 set the complete task list (tasks ordered by priority)\\n' +\n '- `action: \"add\"` \u2014 append a single task\\n' +\n '- `action: \"status\"` \u2014 update a task\\'s status (e.g. pending\u2192in_progress, in_progress\u2192completed)\\n' +\n '- `action: \"show\"` \u2014 view current tasks without changing them\\n' +\n '- `action: \"promote\"` \u2014 convert a task into actionable todo items via `target` (id|index|substring)\\n' +\n '- `action: \"planify\"` \u2014 promote a task to a plan item (strategic level) via `target` (id|index|substring)\\n\\n' +\n 'Task fields:\\n' +\n '- `dependsOn`: list of task IDs this one waits for\\n' +\n '- `type`: \"feature\" | \"bugfix\" | \"refactor\" | \"docs\" | \"test\" | \"chore\"\\n' +\n '- `priority`: \"critical\" | \"high\" | \"medium\" | \"low\"\\n' +\n '- `assignee`: agent/subagent name (e.g. \"bug-hunter\", \"refactor-planner\")\\n' +\n '- `estimateHours`: rough time estimate\\n' +\n '- `scope`: \"session\" (default, isolated) or \"project\" (shared across sessions)',\n permission: 'confirm',\n mutating: true,\n capabilities: ['fs.write'],\n icon: 'task',\n timeoutMs: 5_000,\n inputSchema: {\n type: 'object',\n properties: {\n action: {\n type: 'string',\n enum: ['replace', 'add', 'status', 'show', 'promote', 'planify'],\n description: 'replace = set full list, add = append, status = update task status, show = view only, promote = convert task to todos, planify = convert task to plan item.',\n },\n tasks: {\n type: 'array',\n items: {\n type: 'object',\n properties: {\n id: { type: 'string', description: 'Unique id (e.g. \"t1\", \"auth-flow\").' },\n title: { type: 'string', description: 'Short title.' },\n description: { type: 'string', description: 'Optional details.' },\n type: { type: 'string', enum: ['feature', 'bugfix', 'refactor', 'docs', 'test', 'chore'] },\n priority: { type: 'string', enum: ['critical', 'high', 'medium', 'low'] },\n status: { type: 'string', enum: ['pending', 'in_progress', 'blocked', 'failed', 'review', 'completed'] },\n dependsOn: {\n type: 'array',\n items: { type: 'string' },\n description: 'IDs of tasks this one depends on.',\n },\n assignee: { type: 'string', description: 'Agent/subagent assigned.' },\n estimateHours: { type: 'number', description: 'Estimated hours.' },\n tags: { type: 'array', items: { type: 'string' }, description: 'Optional tags.' },\n createdAt: { type: 'string' },\n updatedAt: { type: 'string' },\n },\n required: ['id', 'title', 'type', 'priority', 'status'],\n },\n description: 'Complete task list. Replaces previous list entirely.',\n },\n task: {\n type: 'object',\n properties: {\n title: { type: 'string' },\n description: { type: 'string' },\n type: { type: 'string', enum: ['feature', 'bugfix', 'refactor', 'docs', 'test', 'chore'] },\n priority: { type: 'string', enum: ['critical', 'high', 'medium', 'low'] },\n status: { type: 'string', enum: ['pending', 'in_progress', 'blocked', 'failed', 'review', 'completed'] },\n dependsOn: { type: 'array', items: { type: 'string' } },\n assignee: { type: 'string' },\n estimateHours: { type: 'number' },\n tags: { type: 'array', items: { type: 'string' } },\n },\n required: ['title', 'type', 'priority'],\n description: 'Single task to append (id/createdAt/updatedAt auto-generated).',\n },\n id: { type: 'string', description: 'Task id for action=status or target for action=promote.' },\n status: {\n type: 'string',\n enum: ['pending', 'in_progress', 'blocked', 'failed', 'review', 'completed'],\n description: 'New status for action=status.',\n },\n target: {\n type: 'string',\n description: 'Target task identifier (id, 1-based index, or title substring) for action=promote.',\n },\n subtasks: {\n type: 'array',\n items: { type: 'string' },\n description: 'Optional subtask titles for action=promote. Each becomes a pending todo.',\n },\n scope: {\n type: 'string',\n enum: ['session', 'project'],\n description: 'Storage scope: \"session\" (default, isolated to this session) or \"project\" (shared across all sessions for this project).',\n },\n },\n required: ['action'],\n },\n async execute(input, ctx) {\n const sessionTaskPath = (ctx.meta as Record<string, unknown>)['task.path'] as string | undefined;\n let taskPath: string | undefined;\n\n if (input.scope === 'project') {\n // Project-level: derive from the session path by replacing the filename with\n // 'backlog.tasks.json' so all sessions share the same file.\n if (typeof sessionTaskPath === 'string') {\n // Handle BOTH separators \u2014 a Windows-native path uses '\\\\'; a '/'-only\n // search would miss it and fall back to a bare relative path written\n // into the process CWD instead of the sessions dir.\n const lastSep = Math.max(sessionTaskPath.lastIndexOf('/'), sessionTaskPath.lastIndexOf('\\\\'));\n taskPath = lastSep >= 0\n ? sessionTaskPath.slice(0, lastSep + 1) + 'backlog.tasks.json'\n : 'backlog.tasks.json';\n }\n } else {\n taskPath = sessionTaskPath;\n }\n\n if (typeof taskPath !== 'string' || !taskPath) {\n return { ok: false, message: 'Task storage path not configured.', count: 0, completed: 0, inProgress: 0 };\n }\n const sessionId = ctx.session?.id ?? 'unknown';\n\n // Early-return result for validation errors that happen before or\n // during the critical section. The lock callback sets this instead of\n // mutating the file, and we return it after the lock releases.\n let early: TaskOutput | null = null;\n // Track promote output for the custom message\n const promoteMeta = { count: 0, title: '' };\n // Track planify data \u2014 written to plan file after the task lock releases\n const planifyMeta = { title: '', details: '' };\n let didPlanify = false;\n // collect todos to replace \u2014 called AFTER mutateTasks so rollback is possible\n type TodosReplacement = Array<{ id: string; content: string; status: 'pending' | 'in_progress' | 'completed'; activeForm?: string; promotedFromTask?: string }>;\n let todosToReplace: TodosReplacement | null = null;\n\n let file: TaskFile;\n try {\n file = await mutateTasks(taskPath, sessionId, async (f: TaskFile) => {\n switch (input.action) {\n case 'show':\n // read-only \u2014 no mutation, just return current state\n break;\n\n case 'replace': {\n if (!Array.isArray(input.tasks)) {\n early = { ok: false, message: 'action=replace requires `tasks` array.', count: 0, completed: 0, inProgress: 0 };\n return f;\n }\n // Validate id uniqueness: findTaskIndex / status resolve a task by\n // the FIRST id match, so a duplicate id silently becomes unaddressable.\n const newIds = new Set(input.tasks.map((t) => t.id));\n if (newIds.size !== input.tasks.length) {\n const seen = new Set<string>();\n const dupes = [...new Set(input.tasks.map((t) => t.id).filter((id) => {\n if (seen.has(id)) return true;\n seen.add(id);\n return false;\n }))];\n early = {\n ok: false,\n message: `action=replace has duplicate task IDs: ${dupes.join(', ')}. Each task id must be unique.`,\n count: 0,\n completed: 0,\n inProgress: 0,\n };\n return f;\n }\n // Validate dependsOn references: must point to IDs within the new batch\n for (const t of input.tasks) {\n if (t.dependsOn && t.dependsOn.length > 0) {\n const missing = t.dependsOn.filter((d) => !newIds.has(d));\n if (missing.length > 0) {\n early = {\n ok: false,\n message: `dependsOn validation failed: task \"${t.id}\" references unknown IDs: ${missing.join(', ')}`,\n count: 0,\n completed: 0,\n inProgress: 0,\n };\n return f;\n }\n }\n }\n const now = new Date().toISOString();\n f.tasks = input.tasks.map((t) => ({\n ...t,\n createdAt: t.createdAt || now,\n updatedAt: now,\n }));\n break;\n }\n\n case 'add': {\n const t = input.task;\n if (!t?.title) {\n early = { ok: false, message: 'action=add requires `task` with at least `title`.', count: 0, completed: 0, inProgress: 0 };\n return f;\n }\n // Validate dependsOn: all referenced IDs must exist in the current task list\n if (t.dependsOn && t.dependsOn.length > 0) {\n const existingIds = new Set(f.tasks.map((e: TaskItem) => e.id));\n const missing = t.dependsOn.filter((d) => !existingIds.has(d));\n if (missing.length > 0) {\n early = {\n ok: false,\n message: `dependsOn validation failed: unknown task IDs: ${missing.join(', ')}`,\n count: 0,\n completed: 0,\n inProgress: 0,\n };\n return f;\n }\n }\n const now = new Date().toISOString();\n const newTask: TaskItem = {\n id: `task_${Date.now()}_${randomUUID().slice(0, 8)}`,\n title: t.title,\n description: t.description,\n type: t.type || 'feature',\n priority: t.priority || 'medium',\n status: t.status || 'pending',\n dependsOn: t.dependsOn,\n assignee: t.assignee,\n estimateHours: t.estimateHours,\n tags: t.tags,\n createdAt: now,\n updatedAt: now,\n };\n f.tasks.push(newTask);\n break;\n }\n\n case 'status': {\n if (!input.id || !input.status) {\n early = { ok: false, message: 'action=status requires `id` and `status`.', count: 0, completed: 0, inProgress: 0 };\n return f;\n }\n const task = f.tasks.find((t: TaskItem) => t.id === input.id);\n if (!task) {\n early = { ok: false, message: `Task \"${input.id}\" not found.`, count: 0, completed: 0, inProgress: 0 };\n return f;\n }\n task.status = input.status;\n task.updatedAt = new Date().toISOString();\n break;\n }\n\n case 'promote': {\n const target = input.target?.trim();\n if (!target) {\n early = { ok: false, message: 'action=promote requires `target` (task id, index, or title substring).', count: 0, completed: 0, inProgress: 0 };\n return f;\n }\n const idx = findTaskIndex(f.tasks, target);\n if (idx === -1) {\n early = { ok: false, message: `No task matched \"${target}\".`, count: 0, completed: 0, inProgress: 0 };\n return f;\n }\n const match = f.tasks[idx];\n /* v8 ignore next 4 -- findTaskIndex returned a valid in-range idx, so match is always defined; defensive. */\n if (!match) {\n early = { ok: false, message: `No task matched \"${target}\".`, count: 0, completed: 0, inProgress: 0 };\n return f;\n }\n\n // Mark task in_progress\n if (match.status !== 'completed' && match.status !== 'failed') {\n match.status = 'in_progress';\n match.updatedAt = new Date().toISOString();\n }\n\n // Build todo items\n const todos: Array<{ id: string; content: string; status: 'pending' | 'in_progress' | 'completed'; activeForm?: string; promotedFromTask?: string }> = [];\n const ts = Date.now();\n todos.push({\n id: `todo_${ts}_task`,\n content: match.title,\n status: 'in_progress',\n activeForm: match.title,\n promotedFromTask: match.id,\n });\n\n if (match.description) {\n todos.push({\n id: `todo_${ts}_${randomUUID().slice(0, 6)}`,\n content: match.description.slice(0, 200),\n status: 'pending',\n promotedFromTask: match.id,\n });\n }\n\n if (input.subtasks && input.subtasks.length > 0) {\n for (const st of input.subtasks) {\n todos.push({\n id: `todo_${ts}_${randomUUID().slice(0, 6)}`,\n content: st,\n status: 'pending',\n promotedFromTask: match.id,\n });\n }\n }\n\n todosToReplace = todos;\n promoteMeta.count = todos.length;\n promoteMeta.title = match.title;\n break;\n }\n\n case 'planify': {\n const target = input.target?.trim();\n if (!target) {\n early = { ok: false, message: 'action=planify requires `target` (task id, index, or title substring).', count: 0, completed: 0, inProgress: 0 };\n return f;\n }\n const idx = findTaskIndex(f.tasks, target);\n if (idx === -1) {\n early = { ok: false, message: `No task matched \"${target}\".`, count: 0, completed: 0, inProgress: 0 };\n return f;\n }\n const match = f.tasks[idx];\n /* v8 ignore next 4 -- findTaskIndex returned a valid in-range idx, so match is always defined; defensive. */\n if (!match) {\n early = { ok: false, message: `No task matched \"${target}\".`, count: 0, completed: 0, inProgress: 0 };\n return f;\n }\n // Extract data \u2014 plan write happens after the task lock releases\n planifyMeta.title = match.title;\n planifyMeta.details = match.description ?? '';\n didPlanify = true;\n // Do NOT mutate the task \u2014 just copy to plan\n break;\n }\n\n default:\n early = { ok: false, message: `Unknown action \"${(input as { action: string }).action}\". Use replace | add | status | show | promote | planify.`, count: 0, completed: 0, inProgress: 0 };\n return f;\n }\n\n return f;\n });\n } catch (err) {\n // Persist failed (mutateTasks throws on a failed save) \u2014 report ok:false\n // instead of falsely claiming the tasks were saved.\n return {\n ok: false,\n message: `Task change not saved \u2014 ${err instanceof Error ? err.message : String(err)}`,\n count: 0,\n completed: 0,\n inProgress: 0,\n };\n }\n\n // Apply todo replacements after the task file mutation succeeds so that\n // on error the state is rolled back cleanly.\n if (todosToReplace) ctx.state.replaceTodos(todosToReplace);\n\n // Fire-and-forget kanban projection. The mirror is observational and must\n // not block the tool response (or consume the 2 s timeout budget) waiting\n // on kanban file locks that may be held by other agents.\n mirrorSessionTasksToKanban(ctx.projectRoot, file.tasks, sessionId);\n\n // If the callback set an early-return result, use it\n if (early) return early;\n\n // If planify copied task data, write it to the plan file now\n if (didPlanify) {\n const { title, details } = planifyMeta;\n const planPathRaw = (ctx.meta as Record<string, unknown>)['plan.path'];\n const prog = computeTaskItemProgress(file.tasks);\n if (typeof planPathRaw === 'string' && planPathRaw) {\n let planPath: string = planPathRaw;\n // Honor project scope for the PLAN file too (mirror of plan.ts taskify);\n // handle both separators.\n if (input.scope === 'project') {\n const lastSep = Math.max(planPath.lastIndexOf('/'), planPath.lastIndexOf('\\\\'));\n planPath = lastSep >= 0 ? planPath.slice(0, lastSep + 1) + 'backlog.plan.json' : 'backlog.plan.json';\n }\n // Mutate the cross-file under ITS OWN lock so a concurrent plan tool\n // call in the same batch can't clobber the write.\n let formatted = '';\n try {\n await mutatePlan(planPath, sessionId, (pf) => {\n const { plan: updated } = addPlanItem(pf, title, details || undefined);\n formatted = formatPlan(updated);\n return updated;\n });\n } catch (err) {\n return {\n ok: false,\n message: `planify: plan not saved \u2014 ${err instanceof Error ? err.message : String(err)}`,\n count: file.tasks.length,\n completed: prog.completed,\n inProgress: prog.inProgress,\n };\n }\n return {\n ok: true,\n message: `planify ok \u2014 added \"${title}\" to plan.\\n${formatted}`,\n count: file.tasks.length,\n completed: prog.completed,\n inProgress: prog.inProgress,\n };\n }\n // Plan path missing \u2014 still report the REAL task counts (the task file was\n // loaded and may be non-empty), not zeros.\n return {\n ok: false,\n message: 'Plan storage path not configured \u2014 cannot planify.',\n count: file.tasks.length,\n completed: prog.completed,\n inProgress: prog.inProgress,\n };\n }\n\n const p = computeTaskItemProgress(file.tasks);\n const summary = promoteMeta.count > 0\n ? `promote ok \u2014 ${promoteMeta.count} todo(s) created from \"${promoteMeta.title}\".\\n${formatTaskList(file.tasks)}`\n : file.tasks.length > 0\n ? formatTaskList(file.tasks)\n : 'No tasks.';\n return {\n ok: true,\n message: summary,\n count: file.tasks.length,\n completed: p.completed,\n inProgress: p.inProgress,\n };\n },\n};\n", "import { type FSWatcher, watch } from 'node:fs';\nimport { basename, dirname } from 'node:path';\nimport type { Context, TodoItem } from '@wrongstack/core/agent';\nimport { getSharedProjectMailbox } from '@wrongstack/core/coordination';\nimport {\n loadPlan,\n loadTasks,\n mutatePlan,\n mutateTasks,\n type PlanFile,\n type PlanItem,\n type TaskFile,\n} from '@wrongstack/core/storage';\nimport { deserializeTaskGraph } from '@wrongstack/core/tasking';\nimport type { SerializedTaskGraph, TaskStatus } from '@wrongstack/core/types';\nimport { resolveWstackPaths, type TaskItem } from '@wrongstack/core/utils';\nimport {\n bridgeKanbanSupervisor,\n createBoard,\n getBoard,\n type KanbanBoard,\n type KanbanColumn,\n type KanbanTask,\n listBoards,\n removeBoard,\n syncBoardFromTaskGraph,\n touchKanbanPresence,\n updateBoard,\n} from '@wrongstack/kanban';\n\nconst SESSION_BOARD_TAG = 'session-work';\nconst MIRROR_DISABLED_ENV = 'WRONGSTACK_KANBAN_TASK_MIRROR';\n\n/** The canonical workflow shared by WebUI and TUI session boards. */\nexport const SESSION_KANBAN_COLUMNS: KanbanColumn[] = [\n { id: 'todo', title: 'Todo', order: 0, wipLimit: 0, color: '#2563eb' },\n { id: 'in-progress', title: 'Running', order: 1, wipLimit: 1, color: '#d97706' },\n { id: 'review', title: 'Preview', order: 2, wipLimit: 0, color: '#7c3aed' },\n { id: 'done', title: 'Done', order: 3, wipLimit: 0, color: '#16a34a' },\n];\n\nconst boardQueue = new Map<string, Promise<void>>();\nconst boardEnsures = new Map<string, Promise<KanbanBoard>>();\ntype PendingMirror = {\n projectRoot: string;\n sessionId: string;\n graph: SerializedTaskGraph;\n sourceSystem: 'session-todo' | 'session-task' | 'session-plan';\n};\nconst pendingMirrors = new Map<string, PendingMirror>();\nconst activeMirrors = new Set<string>();\nconst bindings = new WeakMap<Context, () => void>();\nconst suppressedTodoMirrors = new WeakSet<Context>();\nconst activeSessionBoards = new Map<string, number>();\n\nfunction boardKey(projectRoot: string, sessionId: string): string {\n return `${projectRoot}\\0${sessionId}`;\n}\n\nfunction mirrorKey(\n projectRoot: string,\n sessionId: string,\n sourceSystem: PendingMirror['sourceSystem'],\n): string {\n return `${boardKey(projectRoot, sessionId)}\\0${sourceSystem}`;\n}\n\nfunction sessionTag(sessionId: string): string {\n return `session:${sessionId}`;\n}\n\nfunction sessionBoardTitle(sessionId: string): string {\n const leaf = sessionId.split(/[\\\\/]/).filter(Boolean).pop() ?? sessionId;\n return `Session ${leaf.slice(0, 12)}`;\n}\n\nfunction sessionBoardTags(sessionId: string): string[] {\n return ['session', SESSION_BOARD_TAG, sessionTag(sessionId)];\n}\n\nfunction sessionIdFromTags(tags: readonly string[] | undefined): string | null {\n const tag = tags?.find((candidate) => candidate.startsWith('session:'));\n return tag?.slice('session:'.length) || null;\n}\n\nfunction isOwnedSessionBoard(tags: readonly string[] | undefined): boolean {\n return Boolean(tags?.includes(SESSION_BOARD_TAG) && sessionIdFromTags(tags));\n}\n\nfunction retainActiveSessionBoard(projectRoot: string, sessionId: string): void {\n const key = boardKey(projectRoot, sessionId);\n activeSessionBoards.set(key, (activeSessionBoards.get(key) ?? 0) + 1);\n}\n\nfunction releaseActiveSessionBoard(projectRoot: string, sessionId: string): void {\n const key = boardKey(projectRoot, sessionId);\n const remaining = (activeSessionBoards.get(key) ?? 0) - 1;\n if (remaining > 0) activeSessionBoards.set(key, remaining);\n else activeSessionBoards.delete(key);\n}\n\nfunction isSessionBoardActive(projectRoot: string, sessionId: string): boolean {\n return (activeSessionBoards.get(boardKey(projectRoot, sessionId)) ?? 0) > 0;\n}\n\nfunction sameColumns(columns: readonly KanbanColumn[]): boolean {\n return (\n columns.length === SESSION_KANBAN_COLUMNS.length &&\n columns.every((column, index) => column.id === SESSION_KANBAN_COLUMNS[index]?.id)\n );\n}\n\n/** Create (or migrate) the single Kanban board owned by a session. */\nexport async function ensureSessionKanbanBoard(\n projectRoot: string | undefined,\n sessionId: string,\n): Promise<KanbanBoard | null> {\n if (!projectRoot || !sessionId || process.env[MIRROR_DISABLED_ENV] === '0') return null;\n const key = boardKey(projectRoot, sessionId);\n const inFlight = boardEnsures.get(key);\n if (inFlight) return inFlight;\n\n const promise = (async () => {\n const summary = (await listBoards(projectRoot)).find((board) =>\n board.tags?.includes(sessionTag(sessionId)),\n );\n let board = summary ? await getBoard(projectRoot, summary.id) : null;\n if (!board) {\n return createBoard(projectRoot, {\n title: sessionBoardTitle(sessionId),\n description: 'Live session work: todos, tasks, and plan items.',\n tags: sessionBoardTags(sessionId),\n columns: SESSION_KANBAN_COLUMNS,\n generatedBy: `session-kanban:${sessionId}`,\n });\n }\n\n // Boards produced by the older task/plan mirrors used the generic five\n // columns. Migrate only session-owned boards; updateBoard reconciles cards\n // from Backlog into Todo while preserving Running/Preview/Done cards.\n if (!sameColumns(board.columns) || !board.tags?.includes(SESSION_BOARD_TAG)) {\n board =\n (await updateBoard(projectRoot, board.id, {\n title: sessionBoardTitle(sessionId),\n description: 'Live session work: todos, tasks, and plan items.',\n tags: [...new Set([...(board.tags ?? []), ...sessionBoardTags(sessionId)])],\n columns: SESSION_KANBAN_COLUMNS,\n })) ?? board;\n }\n return board;\n })();\n\n boardEnsures.set(key, promise);\n try {\n return await promise;\n } finally {\n boardEnsures.delete(key);\n }\n}\n\nfunction enqueueBoardWork<T>(\n projectRoot: string,\n sessionId: string,\n work: () => Promise<T>,\n): Promise<T> {\n const key = boardKey(projectRoot, sessionId);\n const previous = boardQueue.get(key) ?? Promise.resolve();\n const result = previous.catch(() => undefined).then(work);\n const tail = result.then(\n () => undefined,\n () => undefined,\n );\n boardQueue.set(key, tail);\n void tail.then(() => {\n if (boardQueue.get(key) === tail) boardQueue.delete(key);\n });\n return result;\n}\n\nasync function removeEmptySessionBoard(\n projectRoot: string,\n boardId: string,\n sessionId: string,\n): Promise<string | null> {\n return enqueueBoardWork(projectRoot, sessionId, async () => {\n if (isSessionBoardActive(projectRoot, sessionId)) return null;\n const board = await getBoard(projectRoot, boardId);\n if (!board || board.tasks.length > 0 || !isOwnedSessionBoard(board.tags)) return null;\n if (sessionIdFromTags(board.tags) !== sessionId) return null;\n return (await removeBoard(projectRoot, board.id)) ? board.id : null;\n });\n}\n\n/** Remove a particular inactive session's system-owned board when it has no cards. */\nexport async function cleanupSessionKanbanBoardIfEmpty(\n projectRoot: string | undefined,\n sessionId: string,\n): Promise<string[]> {\n if (!projectRoot || !sessionId || process.env[MIRROR_DISABLED_ENV] === '0') return [];\n if (isSessionBoardActive(projectRoot, sessionId)) return [];\n const candidates = (await listBoards(projectRoot)).filter(\n (board) =>\n board.taskCount === 0 &&\n isOwnedSessionBoard(board.tags) &&\n sessionIdFromTags(board.tags) === sessionId,\n );\n const removed = await Promise.all(\n candidates.map((board) => removeEmptySessionBoard(projectRoot, board.id, sessionId)),\n );\n return removed.filter((boardId): boardId is string => Boolean(boardId));\n}\n\n/** Prune stale empty session boards while preserving manual and live boards. */\nexport async function cleanupEmptySessionKanbanBoards(\n projectRoot: string | undefined,\n activeSessionId = '',\n): Promise<string[]> {\n if (!projectRoot || process.env[MIRROR_DISABLED_ENV] === '0') return [];\n const candidates = (await listBoards(projectRoot)).flatMap((board) => {\n const ownerSessionId = sessionIdFromTags(board.tags);\n return board.taskCount === 0 &&\n isOwnedSessionBoard(board.tags) &&\n ownerSessionId &&\n ownerSessionId !== activeSessionId &&\n !isSessionBoardActive(projectRoot, ownerSessionId)\n ? [{ boardId: board.id, sessionId: ownerSessionId }]\n : [];\n });\n const removed = await Promise.all(\n candidates.map(({ boardId, sessionId }) =>\n removeEmptySessionBoard(projectRoot, boardId, sessionId),\n ),\n );\n return removed.filter((boardId): boardId is string => Boolean(boardId));\n}\n\nasync function projectGraph(\n projectRoot: string | undefined,\n sessionId: string,\n graph: SerializedTaskGraph,\n sourceSystem: 'session-todo' | 'session-task' | 'session-plan',\n): Promise<KanbanBoard | null> {\n if (!projectRoot || !sessionId || process.env[MIRROR_DISABLED_ENV] === '0') return null;\n return enqueueBoardWork(projectRoot, sessionId, async () => {\n const board = await ensureSessionKanbanBoard(projectRoot, sessionId);\n if (!board) return null;\n const result = await syncBoardFromTaskGraph(\n projectRoot,\n board.id,\n deserializeTaskGraph(graph),\n {\n sourceSystem,\n tags: [...new Set([...(board.tags ?? []), ...sessionBoardTags(sessionId)])],\n archiveMissingTasks: true,\n includeCompletedTasks: true,\n },\n );\n return result?.board ?? null;\n });\n}\n\n/**\n * Queue an observational mirror without retaining every intermediate state.\n * Todo/task/plan streams are independent, but within each stream only the\n * newest pending graph matters. This bounds a stalled file lock to one active\n * and one pending projection instead of an arbitrarily long Promise chain.\n */\nfunction queueLatestMirror(\n projectRoot: string | undefined,\n sessionId: string,\n graph: SerializedTaskGraph,\n sourceSystem: PendingMirror['sourceSystem'],\n): void {\n if (!projectRoot || !sessionId || process.env[MIRROR_DISABLED_ENV] === '0') return;\n const key = mirrorKey(projectRoot, sessionId, sourceSystem);\n pendingMirrors.set(key, { projectRoot, sessionId, graph, sourceSystem });\n if (activeMirrors.has(key)) return;\n activeMirrors.add(key);\n void (async () => {\n try {\n for (;;) {\n const pending = pendingMirrors.get(key);\n if (!pending) break;\n pendingMirrors.delete(key);\n try {\n await projectGraph(\n pending.projectRoot,\n pending.sessionId,\n pending.graph,\n pending.sourceSystem,\n );\n } catch {\n // Mirrors are observational. A newer pending snapshot, if present,\n // still gets a chance after a transient lock or filesystem failure.\n }\n }\n } finally {\n activeMirrors.delete(key);\n // A mirror can arrive between the last Map read and deleting the active\n // marker. Re-arm once so that snapshot cannot be stranded.\n const pending = pendingMirrors.get(key);\n if (pending) {\n pendingMirrors.delete(key);\n queueLatestMirror(\n pending.projectRoot,\n pending.sessionId,\n pending.graph,\n pending.sourceSystem,\n );\n }\n }\n })();\n}\n\nexport function todoListToSerializedGraph(\n todos: readonly TodoItem[],\n sessionId: string,\n): SerializedTaskGraph {\n const nodes = todos.map((todo, index) => ({\n id: todo.id,\n title: todo.content,\n description: todo.activeForm ?? '',\n type: 'chore' as const,\n priority: 'medium' as const,\n status: todo.status,\n createdAt: index,\n updatedAt: index,\n }));\n return {\n id: `todo:${sessionId}`,\n specId: `todo:${sessionId}`,\n title: 'Session todos',\n nodes,\n edges: [],\n rootNodes: nodes.map((node) => node.id),\n createdAt: 0,\n updatedAt: 0,\n };\n}\n\nexport function taskFileToSerializedGraph(\n tasks: readonly TaskItem[],\n sessionId: string,\n): SerializedTaskGraph {\n const ids = new Set(tasks.map((task) => task.id));\n const nodes = tasks.map((task, index) => ({\n id: task.id,\n title: task.title,\n description: task.description ?? '',\n type: task.type,\n priority: task.priority,\n status: task.status,\n ...(task.assignee ? { assignee: task.assignee } : {}),\n ...(task.estimateHours !== undefined ? { estimateHours: task.estimateHours } : {}),\n createdAt: index,\n updatedAt: index,\n }));\n const edges = tasks.flatMap((task) =>\n (task.dependsOn ?? [])\n .filter((dependency) => ids.has(dependency))\n .map((dependency) => ({\n id: `${dependency}->${task.id}`,\n from: dependency,\n to: task.id,\n type: 'depends_on' as const,\n })),\n );\n const hasIncoming = new Set(edges.map((edge) => edge.to));\n const rootNodes = nodes.filter((node) => !hasIncoming.has(node.id)).map((node) => node.id);\n return {\n // Keep the historical graph id so existing mirrored task cards are reused.\n id: `session:${sessionId}`,\n specId: `session:${sessionId}`,\n title: 'Session tasks',\n nodes,\n edges,\n rootNodes: rootNodes.length ? rootNodes : nodes[0] ? [nodes[0].id] : [],\n createdAt: 0,\n updatedAt: 0,\n };\n}\n\nconst PLAN_STATUS_TO_TASK: Record<PlanItem['status'], TaskStatus> = {\n open: 'pending',\n in_progress: 'in_progress',\n done: 'completed',\n};\n\nexport function planFileToSerializedGraph(\n items: readonly PlanItem[],\n sessionId: string,\n): SerializedTaskGraph {\n const nodes = items.map((item, index) => ({\n id: item.id,\n title: item.title,\n description: item.details ?? '',\n type: 'chore' as const,\n priority: 'medium' as const,\n status: PLAN_STATUS_TO_TASK[item.status],\n createdAt: index,\n updatedAt: index,\n }));\n return {\n id: `plan:${sessionId}`,\n specId: `plan:${sessionId}`,\n title: 'Session plan',\n nodes,\n edges: [],\n rootNodes: nodes.map((node) => node.id),\n createdAt: 0,\n updatedAt: 0,\n };\n}\n\nexport function projectSessionTodosToKanban(\n projectRoot: string | undefined,\n todos: readonly TodoItem[],\n sessionId: string,\n): Promise<KanbanBoard | null> {\n return projectGraph(\n projectRoot,\n sessionId,\n todoListToSerializedGraph(todos, sessionId),\n 'session-todo',\n );\n}\n\nexport function projectSessionTasksToKanban(\n projectRoot: string | undefined,\n tasks: readonly TaskItem[],\n sessionId: string,\n): Promise<KanbanBoard | null> {\n return projectGraph(\n projectRoot,\n sessionId,\n taskFileToSerializedGraph(tasks, sessionId),\n 'session-task',\n );\n}\n\nexport function projectSessionPlanToKanban(\n projectRoot: string | undefined,\n items: readonly PlanItem[],\n sessionId: string,\n): Promise<KanbanBoard | null> {\n return projectGraph(\n projectRoot,\n sessionId,\n planFileToSerializedGraph(items, sessionId),\n 'session-plan',\n );\n}\n\nfunction fireAndForget(context: string, work: Promise<unknown>): void {\n void work.catch((err: unknown) => {\n const message = err instanceof Error ? err.message : String(err);\n console.warn(JSON.stringify({ level: 'warn', event: 'session-kanban', context, message, timestamp: new Date().toISOString() }));\n });\n}\n\nfunction broadcastTodoUpdate(context: Context, todos: readonly TodoItem[]): void {\n const sessionId = context.session?.id ?? '';\n if (!context.agentId || !sessionId) return;\n const projectDir = resolveWstackPaths({ projectRoot: context.projectRoot }).projectDir;\n const mailbox = getSharedProjectMailbox(projectDir);\n void mailbox\n .send({\n from: context.agentId,\n to: '*',\n type: 'status',\n subject: `Kanban todo list updated (${todos.length} item${todos.length === 1 ? '' : 's'})`,\n body: JSON.stringify({\n kind: 'kanban.todos.updated',\n sessionId,\n revision: context.state.revision,\n todos,\n }),\n priority: 'normal',\n senderSessionId: sessionId,\n ttlMs: 6 * 60 * 60 * 1000,\n })\n .catch(() => {\n // Mailbox awareness is best-effort; canonical state is already updated.\n });\n}\n\nfunction notifyTodoUpdate(context: Context, todos: readonly TodoItem[]): void {\n const summary = todos.length\n ? todos.map((todo) => `- [${todo.status}] ${todo.content} (${todo.id})`).join('\\n')\n : '- No active todos remain.';\n const text = `[KANBAN TODO UPDATE]\\nAnother Kanban agent reassessed the shared board. The canonical todo list is now:\\n${summary}\\nReassess your current plan before continuing; do not rely on the initial todo snapshot.`;\n const state = context.state as Partial<Context['state']>;\n if (typeof state.appendBlockToLastUserMessage === 'function') {\n if (state.appendBlockToLastUserMessage({ type: 'text', text })) return;\n }\n if (typeof state.appendMessage === 'function') {\n state.appendMessage({ role: 'user', content: [{ type: 'text', text }] });\n }\n}\n\nexport function mirrorSessionTodosToKanban(\n projectRoot: string | undefined,\n todos: readonly TodoItem[],\n sessionId: string,\n): void {\n queueLatestMirror(\n projectRoot,\n sessionId,\n todoListToSerializedGraph(todos, sessionId),\n 'session-todo',\n );\n}\n\nexport function mirrorSessionTasksToKanban(\n projectRoot: string | undefined,\n tasks: readonly TaskItem[],\n sessionId: string,\n): void {\n queueLatestMirror(\n projectRoot,\n sessionId,\n taskFileToSerializedGraph(tasks, sessionId),\n 'session-task',\n );\n}\n\nexport function mirrorSessionPlanToKanban(\n projectRoot: string | undefined,\n items: readonly PlanItem[],\n sessionId: string,\n): void {\n queueLatestMirror(\n projectRoot,\n sessionId,\n planFileToSerializedGraph(items, sessionId),\n 'session-plan',\n );\n}\n\n/**\n * Bind all live session work paths to Kanban. Todo changes are observed from\n * ConversationState; plan/task sidecars are watched so slash commands, WebUI,\n * plugins, and tools all pass through the same board.\n */\nexport function attachSessionKanbanMirror(context: Context): () => void {\n const existing = bindings.get(context);\n if (existing) return existing;\n\n const attachedProjectRoot = context.projectRoot ?? '';\n let registeredSessionId = '';\n const syncActiveSessionRegistration = () => {\n if (!attachedProjectRoot) return;\n const currentSessionId = context.session?.id ?? '';\n if (currentSessionId === registeredSessionId) return;\n if (registeredSessionId) {\n releaseActiveSessionBoard(attachedProjectRoot, registeredSessionId);\n fireAndForget(\n 'cleanup-board',\n cleanupSessionKanbanBoardIfEmpty(attachedProjectRoot, registeredSessionId),\n );\n }\n registeredSessionId = currentSessionId;\n if (registeredSessionId) {\n retainActiveSessionBoard(attachedProjectRoot, registeredSessionId);\n }\n };\n syncActiveSessionRegistration();\n\n let watcher: FSWatcher | null = null;\n let watchedDir = '';\n let timer: NodeJS.Timeout | null = null;\n let unsubscribeBoardEvents: (() => void) | null = null;\n let watchedBoardId = '';\n let boardTimer: NodeJS.Timeout | null = null;\n let presenceTimer: NodeJS.Timeout | null = null;\n\n const sessionId = () => context.session?.id ?? '';\n const refreshFiles = async () => {\n const id = sessionId();\n if (!id) return;\n const planPath = context.meta['plan.path'];\n if (typeof planPath === 'string' && planPath) {\n const plan = await loadPlan(planPath);\n if (plan) await projectSessionPlanToKanban(context.projectRoot, plan.items, id);\n }\n const taskPath = context.meta['task.path'];\n if (typeof taskPath === 'string' && taskPath) {\n const tasks = await loadTasks(taskPath);\n if (tasks) await projectSessionTasksToKanban(context.projectRoot, tasks.tasks, id);\n }\n };\n\n const refreshBoard = async () => {\n if (!watchedBoardId) return;\n const board = await getBoard(context.projectRoot, watchedBoardId);\n if (board) applySessionKanbanBoardToTodos(context, board);\n };\n\n const configureBoardWatcher = async () => {\n const id = sessionId();\n const board = id ? await ensureSessionKanbanBoard(context.projectRoot, id) : null;\n if (!board || board.id === watchedBoardId) return;\n unsubscribeBoardEvents?.();\n unsubscribeBoardEvents = null;\n watchedBoardId = board.id;\n try {\n unsubscribeBoardEvents = bridgeKanbanSupervisor(\n context.projectRoot,\n (event) => {\n const data = event.data as { boardId?: string } | undefined;\n if (data?.boardId !== board.id) return;\n if (boardTimer) clearTimeout(boardTimer);\n boardTimer = setTimeout(() => fireAndForget('refresh-board', refreshBoard()), 60);\n },\n { autoReconnect: true, reconnectDelayMs: 1_000 },\n );\n const touchPresence = () =>\n touchKanbanPresence(context.projectRoot, board.id, {\n sessionId: id,\n agentId: context.agentId,\n agentName: context.agentName,\n });\n fireAndForget('touch-presence', touchPresence());\n if (presenceTimer) clearInterval(presenceTimer);\n presenceTimer = setInterval(() => fireAndForget('touch-presence', touchPresence()), 60_000);\n presenceTimer.unref?.();\n } catch {\n unsubscribeBoardEvents = null;\n watchedBoardId = '';\n }\n };\n\n const configureWatcher = () => {\n const planPath = context.meta['plan.path'];\n const taskPath = context.meta['task.path'];\n const candidate =\n typeof planPath === 'string' && planPath\n ? dirname(planPath)\n : typeof taskPath === 'string' && taskPath\n ? dirname(taskPath)\n : '';\n if (!candidate || candidate === watchedDir) return;\n watcher?.close();\n watcher = null;\n watchedDir = candidate;\n try {\n watcher = watch(candidate, { persistent: false }, (_event, filename) => {\n const name = filename?.toString();\n const currentPlanPath = context.meta['plan.path'];\n const currentTaskPath = context.meta['task.path'];\n const planName = typeof currentPlanPath === 'string' ? basename(currentPlanPath) : '';\n const taskName = typeof currentTaskPath === 'string' ? basename(currentTaskPath) : '';\n if (name && name !== planName && name !== taskName) return;\n if (timer) clearTimeout(timer);\n timer = setTimeout(() => fireAndForget('refresh-files', refreshFiles()), 60);\n });\n watcher.on('error', () => watcher?.close());\n } catch {\n // The session directory can briefly disappear during project/session\n // switches; the next meta update re-attempts the binding.\n watcher = null;\n watchedDir = '';\n }\n };\n\n const unsubscribe = context.state.onChange((change) => {\n if (change.kind === 'todos_replaced' && !suppressedTodoMirrors.has(context)) {\n // ConversationState auto-clears an all-done tactical list. Project the\n // pre-clear completion snapshot so every card reaches Done atomically.\n mirrorSessionTodosToKanban(\n context.projectRoot,\n change.completedSnapshot ?? change.todos,\n sessionId(),\n );\n return;\n }\n if (change.kind === 'meta_set' && (change.key === 'plan.path' || change.key === 'task.path')) {\n syncActiveSessionRegistration();\n configureWatcher();\n fireAndForget('ensure-board', ensureSessionKanbanBoard(context.projectRoot, sessionId()));\n fireAndForget('configure-watcher', configureBoardWatcher());\n fireAndForget('refresh-files', refreshFiles());\n }\n });\n\n configureWatcher();\n fireAndForget('configure-watcher', configureBoardWatcher());\n\n const detach = () => {\n unsubscribe();\n if (timer) clearTimeout(timer);\n if (boardTimer) clearTimeout(boardTimer);\n if (presenceTimer) clearInterval(presenceTimer);\n watcher?.close();\n unsubscribeBoardEvents?.();\n bindings.delete(context);\n if (attachedProjectRoot && registeredSessionId) {\n releaseActiveSessionBoard(attachedProjectRoot, registeredSessionId);\n fireAndForget(\n 'cleanup-board',\n cleanupSessionKanbanBoardIfEmpty(attachedProjectRoot, registeredSessionId),\n );\n registeredSessionId = '';\n }\n };\n bindings.set(context, detach);\n return detach;\n}\n\n/** Fully hydrate a session board before a host announces the session as ready. */\nexport async function hydrateSessionKanban(context: Context): Promise<KanbanBoard | null> {\n const id = context.session?.id ?? '';\n if (!id) return null;\n await cleanupEmptySessionKanbanBoards(context.projectRoot, id);\n let board = await ensureSessionKanbanBoard(context.projectRoot, id);\n if (context.todos.length) {\n board = await projectSessionTodosToKanban(context.projectRoot, context.todos, id);\n }\n const planPath = context.meta['plan.path'];\n if (typeof planPath === 'string' && planPath) {\n const plan = await loadPlan(planPath);\n if (plan) board = await projectSessionPlanToKanban(context.projectRoot, plan.items, id);\n }\n const taskPath = context.meta['task.path'];\n if (typeof taskPath === 'string' && taskPath) {\n const tasks = await loadTasks(taskPath);\n if (tasks) board = await projectSessionTasksToKanban(context.projectRoot, tasks.tasks, id);\n }\n return board;\n}\n\nexport interface SessionKanbanSourceUpdate {\n source: 'todo' | 'task' | 'plan' | null;\n todos?: TodoItem[] | undefined;\n tasks?: TaskFile | undefined;\n plan?: PlanFile | undefined;\n}\n\nfunction sourceStatus(task: KanbanTask): TaskStatus {\n if (task.status === 'completed') return 'completed';\n if (task.status === 'in_progress') return 'in_progress';\n if (task.status === 'review') return 'review';\n if (task.status === 'blocked') return 'blocked';\n if (task.status === 'failed') return 'failed';\n return 'pending';\n}\n\nfunction todoStatus(task: KanbanTask): TodoItem['status'] {\n const status = sourceStatus(task);\n if (status === 'completed') return 'completed';\n if (status === 'in_progress' || status === 'review') return 'in_progress';\n return 'pending';\n}\n\nfunction sessionTodoFromTask(task: KanbanTask): TodoItem {\n return {\n id: task.origin?.taskId ?? task.id,\n content: task.title,\n status: todoStatus(task),\n ...(task.description ? { activeForm: task.description } : {}),\n };\n}\n\nfunction sameTodos(left: readonly TodoItem[], right: readonly TodoItem[]): boolean {\n return (\n left.length === right.length &&\n left.every((todo, index) => {\n const candidate = right[index];\n return (\n candidate?.id === todo.id &&\n candidate.content === todo.content &&\n candidate.status === todo.status &&\n candidate.activeForm === todo.activeForm &&\n candidate.promotedFromPlan === todo.promotedFromPlan &&\n candidate.promotedFromTask === todo.promotedFromTask\n );\n })\n );\n}\n\n/**\n * Replace the tactical todo list from the current cards on a session-owned board.\n *\n * Existing mirrored todo cards retain their stable source ids. New cards created\n * by a Kanban worker become todos under their card ids, so reassessment can add,\n * split, merge, reprioritize, or remove work without being overwritten by the\n * todo list that happened to exist when the run started.\n */\nexport function applySessionKanbanBoardToTodos(context: Context, board: KanbanBoard): TodoItem[] {\n const sessionId = context.session?.id ?? '';\n if (\n !sessionId ||\n sessionIdFromTags(board.tags) !== sessionId ||\n !isOwnedSessionBoard(board.tags)\n ) {\n return [...context.todos];\n }\n\n const projectedTodos = board.tasks\n .filter(\n (task) =>\n task.status !== 'archived' &&\n (!task.origin ||\n task.origin.system === 'session-todo' ||\n (task.origin.graphId ?? '').startsWith('todo:')),\n )\n .sort((left, right) => {\n const leftColumn = board.columns.find((column) => column.id === left.columnId)?.order ?? 0;\n const rightColumn = board.columns.find((column) => column.id === right.columnId)?.order ?? 0;\n return (\n leftColumn - rightColumn ||\n left.order - right.order ||\n left.createdAt.localeCompare(right.createdAt)\n );\n })\n .map(sessionTodoFromTask);\n\n const allCompleted =\n projectedTodos.length > 0 && projectedTodos.every((todo) => todo.status === 'completed');\n const effectiveTodos = allCompleted ? [] : projectedTodos;\n if (sameTodos(context.todos, effectiveTodos)) return [...context.todos];\n suppressedTodoMirrors.add(context);\n try {\n context.state.replaceTodos(projectedTodos);\n } finally {\n suppressedTodoMirrors.delete(context);\n }\n notifyTodoUpdate(context, context.todos);\n broadcastTodoUpdate(context, context.todos);\n return [...context.todos];\n}\n\n/** Reflect a TUI/WebUI Kanban card edit back to its originating work list. */\nexport async function applySessionKanbanTaskToSource(\n context: Context,\n task: KanbanTask,\n options: { remove?: boolean | undefined } = {},\n): Promise<SessionKanbanSourceUpdate> {\n const originId = task.origin?.taskId;\n const graphId = task.origin?.graphId ?? '';\n if (!originId) return { source: null };\n\n if (task.origin?.system === 'session-todo' || graphId.startsWith('todo:')) {\n const next = options.remove\n ? context.todos.filter((todo) => todo.id !== originId)\n : context.todos.map((todo) =>\n todo.id === originId\n ? {\n ...todo,\n content: task.title,\n status:\n sourceStatus(task) === 'completed'\n ? ('completed' as const)\n : sourceStatus(task) === 'in_progress' || sourceStatus(task) === 'review'\n ? ('in_progress' as const)\n : ('pending' as const),\n }\n : todo,\n );\n suppressedTodoMirrors.add(context);\n try {\n context.state.replaceTodos(next);\n } finally {\n suppressedTodoMirrors.delete(context);\n }\n return { source: 'todo', todos: [...context.todos] };\n }\n\n const id = context.session?.id ?? '';\n if (task.origin?.system === 'session-plan' || graphId.startsWith('plan:')) {\n const planPath = context.meta['plan.path'];\n if (typeof planPath !== 'string' || !planPath) return { source: 'plan' };\n const plan = await mutatePlan(planPath, id, (file) => ({\n ...file,\n updatedAt: new Date().toISOString(),\n items: options.remove\n ? file.items.filter((item) => item.id !== originId)\n : file.items.map((item) =>\n item.id === originId\n ? {\n ...item,\n title: task.title,\n details: task.description,\n status:\n task.status === 'completed'\n ? ('done' as const)\n : task.status === 'in_progress' || task.status === 'review'\n ? ('in_progress' as const)\n : ('open' as const),\n updatedAt: new Date().toISOString(),\n }\n : item,\n ),\n }));\n return { source: 'plan', plan };\n }\n\n if (\n task.origin?.system === 'session-task' ||\n task.origin?.system === 'session' ||\n graphId.startsWith('session:')\n ) {\n const taskPath = context.meta['task.path'];\n if (typeof taskPath !== 'string' || !taskPath) return { source: 'task' };\n const tasks = await mutateTasks(taskPath, id, (file) => ({\n ...file,\n tasks: options.remove\n ? file.tasks.filter((item) => item.id !== originId)\n : file.tasks.map((item) =>\n item.id === originId\n ? {\n ...item,\n title: task.title,\n description: task.description,\n status: sourceStatus(task),\n updatedAt: new Date().toISOString(),\n }\n : item,\n ),\n }));\n return { source: 'task', tasks };\n }\n\n return { source: null };\n}\n"],
5
+ "mappings": ";AAEA;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AACP,SAAS,eAAAA,oBAAmB;AAC5B;AAAA,EACE;AAAA,EACA,cAAAC;AAAA,EACA;AAAA,OACK;AACP,SAAS,kBAAkB;;;ACV3B,SAAS,+BAA+B;AACxC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AACP,SAAS,4BAA4B;AAErC,SAAS,0BAAyC;AAClD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EAIA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,IAAM,oBAAoB;AAC1B,IAAM,sBAAsB;AAGrB,IAAM,yBAAy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W,EAAE;AAAA,MACb,YAAY,EAAE;AAAA,IAChB;AAAA,EACF;AACF;",
6
6
  "names": ["mutateTasks", "mutatePlan", "board", "mutateTasks", "mutatePlan"]
7
7
  }
@@ -1 +1 @@
1
- {"version":3,"file":"todo.d.ts","sourceRoot":"","sources":["../src/todo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAInD,UAAU,SAAS;IACjB,KAAK,EAAE,QAAQ,EAAE,CAAC;CACnB;AAED,UAAU,UAAU;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,eAAO,MAAM,QAAQ,EAAE,IAAI,CAAC,SAAS,EAAE,UAAU,CA2IhD,CAAC"}
1
+ {"version":3,"file":"todo.d.ts","sourceRoot":"","sources":["../src/todo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAInD,UAAU,SAAS;IACjB,KAAK,EAAE,QAAQ,EAAE,CAAC;CACnB;AAED,UAAU,UAAU;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,eAAO,MAAM,QAAQ,EAAE,IAAI,CAAC,SAAS,EAAE,UAAU,CA8IhD,CAAC"}
package/dist/todo.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import { loadPlan as loadPlan2, loadTasks as loadTasks2, savePlan, saveTasks, setPlanItemStatus } from "@wrongstack/core/storage";
3
3
 
4
4
  // src/session-kanban.ts
5
- import { GlobalMailbox } from "@wrongstack/core/coordination";
5
+ import { getSharedProjectMailbox } from "@wrongstack/core/coordination";
6
6
  import {
7
7
  loadPlan,
8
8
  loadTasks,
@@ -12,9 +12,9 @@ import {
12
12
  import { deserializeTaskGraph } from "@wrongstack/core/tasking";
13
13
  import { resolveWstackPaths } from "@wrongstack/core/utils";
14
14
  import {
15
+ bridgeKanbanSupervisor,
15
16
  createBoard,
16
17
  getBoard,
17
- getKanbanDir,
18
18
  listBoards,
19
19
  removeBoard,
20
20
  syncBoardFromTaskGraph,
@@ -31,9 +31,14 @@ var SESSION_KANBAN_COLUMNS = [
31
31
  ];
32
32
  var boardQueue = /* @__PURE__ */ new Map();
33
33
  var boardEnsures = /* @__PURE__ */ new Map();
34
+ var pendingMirrors = /* @__PURE__ */ new Map();
35
+ var activeMirrors = /* @__PURE__ */ new Set();
34
36
  function boardKey(projectRoot, sessionId) {
35
37
  return `${projectRoot}\0${sessionId}`;
36
38
  }
39
+ function mirrorKey(projectRoot, sessionId, sourceSystem) {
40
+ return `${boardKey(projectRoot, sessionId)}\0${sourceSystem}`;
41
+ }
37
42
  function sessionTag(sessionId) {
38
43
  return `session:${sessionId}`;
39
44
  }
@@ -116,6 +121,43 @@ async function projectGraph(projectRoot, sessionId, graph, sourceSystem) {
116
121
  return result?.board ?? null;
117
122
  });
118
123
  }
124
+ function queueLatestMirror(projectRoot, sessionId, graph, sourceSystem) {
125
+ if (!projectRoot || !sessionId || process.env[MIRROR_DISABLED_ENV] === "0") return;
126
+ const key = mirrorKey(projectRoot, sessionId, sourceSystem);
127
+ pendingMirrors.set(key, { projectRoot, sessionId, graph, sourceSystem });
128
+ if (activeMirrors.has(key)) return;
129
+ activeMirrors.add(key);
130
+ void (async () => {
131
+ try {
132
+ for (; ; ) {
133
+ const pending = pendingMirrors.get(key);
134
+ if (!pending) break;
135
+ pendingMirrors.delete(key);
136
+ try {
137
+ await projectGraph(
138
+ pending.projectRoot,
139
+ pending.sessionId,
140
+ pending.graph,
141
+ pending.sourceSystem
142
+ );
143
+ } catch {
144
+ }
145
+ }
146
+ } finally {
147
+ activeMirrors.delete(key);
148
+ const pending = pendingMirrors.get(key);
149
+ if (pending) {
150
+ pendingMirrors.delete(key);
151
+ queueLatestMirror(
152
+ pending.projectRoot,
153
+ pending.sessionId,
154
+ pending.graph,
155
+ pending.sourceSystem
156
+ );
157
+ }
158
+ }
159
+ })();
160
+ }
119
161
  function todoListToSerializedGraph(todos, sessionId) {
120
162
  const nodes = todos.map((todo, index) => ({
121
163
  id: todo.id,
@@ -138,8 +180,8 @@ function todoListToSerializedGraph(todos, sessionId) {
138
180
  updatedAt: 0
139
181
  };
140
182
  }
141
- function projectSessionTodosToKanban(projectRoot, todos, sessionId) {
142
- return projectGraph(
183
+ function mirrorSessionTodosToKanban(projectRoot, todos, sessionId) {
184
+ queueLatestMirror(
143
185
  projectRoot,
144
186
  sessionId,
145
187
  todoListToSerializedGraph(todos, sessionId),
@@ -208,7 +250,7 @@ var todoTool = {
208
250
  }
209
251
  }
210
252
  ctx.state.replaceTodos(items);
211
- await projectSessionTodosToKanban(ctx.projectRoot, items, ctx.session?.id ?? "session");
253
+ mirrorSessionTodosToKanban(ctx.projectRoot, items, ctx.session?.id ?? "session");
212
254
  const completedPlanIds = /* @__PURE__ */ new Set();
213
255
  const completedTaskIds = /* @__PURE__ */ new Set();
214
256
  const pendingPlanIds = /* @__PURE__ */ new Set();