@wrongstack/core 0.313.0 → 0.313.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (182) hide show
  1. package/dist/chronicle/index.js +84 -6391
  2. package/dist/chronicle/project-server.js +84 -4868
  3. package/dist/chunk-2BUUIMQB.js +225 -0
  4. package/dist/chunk-2FK4WTFF.js +207 -0
  5. package/dist/chunk-2FQL4PDC.js +292 -0
  6. package/dist/chunk-2KKODIQU.js +2256 -0
  7. package/dist/chunk-2YU4WVBW.js +134 -0
  8. package/dist/chunk-3E244UDA.js +356 -0
  9. package/dist/chunk-3XPVB7BA.js +135 -0
  10. package/dist/chunk-4LJJYBAU.js +388 -0
  11. package/dist/chunk-4VWO3ZXL.js +342 -0
  12. package/dist/chunk-4XV6IR37.js +187 -0
  13. package/dist/chunk-4ZHTKJHM.js +183 -0
  14. package/dist/chunk-52RTVH4M.js +361 -0
  15. package/dist/chunk-57GEWK5X.js +26 -0
  16. package/dist/chunk-5DSMEVA4.js +931 -0
  17. package/dist/chunk-5RP3QTRL.js +1223 -0
  18. package/dist/chunk-5S437PRC.js +50 -0
  19. package/dist/chunk-5XDUGTKN.js +511 -0
  20. package/dist/chunk-62V2AFVG.js +422 -0
  21. package/dist/chunk-65RDIOR2.js +2470 -0
  22. package/dist/chunk-6AKOTGLM.js +597 -0
  23. package/dist/chunk-7ZHZE5EO.js +28 -0
  24. package/dist/chunk-A455ATZB.js +140 -0
  25. package/dist/chunk-AD7ZFZCS.js +46 -0
  26. package/dist/chunk-AI4LLQ2U.js +856 -0
  27. package/dist/chunk-ASX6AW36.js +789 -0
  28. package/dist/chunk-AT4V4XGI.js +3522 -0
  29. package/dist/chunk-AWNQ6ED6.js +311 -0
  30. package/dist/chunk-B4AMLZPB.js +9 -0
  31. package/dist/chunk-BAKVJLEV.js +417 -0
  32. package/dist/chunk-BJHVULHO.js +55 -0
  33. package/dist/chunk-CB2HFKTP.js +9 -0
  34. package/dist/chunk-CE4ZOCOI.js +1640 -0
  35. package/dist/chunk-CQQL4ZOQ.js +151 -0
  36. package/dist/chunk-DEIQMBD2.js +65 -0
  37. package/dist/chunk-E6I5RXVK.js +58 -0
  38. package/dist/chunk-EFEHDQGY.js +1589 -0
  39. package/dist/chunk-EODDVJBM.js +82 -0
  40. package/dist/chunk-EPC3GZD4.js +308 -0
  41. package/dist/chunk-FAYRX2AD.js +13 -0
  42. package/dist/chunk-FFSX2QDQ.js +362 -0
  43. package/dist/chunk-FHAMQS7Q.js +5856 -0
  44. package/dist/chunk-FIV4IJL7.js +2263 -0
  45. package/dist/chunk-FNXVT7HF.js +52 -0
  46. package/dist/chunk-FSWCWSTS.js +395 -0
  47. package/dist/chunk-FW5LDDMJ.js +16464 -0
  48. package/dist/chunk-FXQLIX3K.js +211 -0
  49. package/dist/chunk-G5AAKEEZ.js +228 -0
  50. package/dist/chunk-G5S3S5ZN.js +38 -0
  51. package/dist/chunk-GAZEWQEZ.js +231 -0
  52. package/dist/chunk-GFJOMSHG.js +125 -0
  53. package/dist/chunk-GFXZTHNI.js +158 -0
  54. package/dist/chunk-GM54GJBU.js +960 -0
  55. package/dist/chunk-GPQ3NJPR.js +900 -0
  56. package/dist/chunk-GTCU6DZ3.js +1 -0
  57. package/dist/chunk-H5E77KUJ.js +15 -0
  58. package/dist/chunk-H72H4XDU.js +1023 -0
  59. package/dist/chunk-HA4ZYA6T.js +178 -0
  60. package/dist/chunk-I45KAW2N.js +5020 -0
  61. package/dist/chunk-IQ35HMQL.js +1396 -0
  62. package/dist/chunk-IYFBFX34.js +86 -0
  63. package/dist/chunk-JJPMWPB6.js +109 -0
  64. package/dist/chunk-JTHKOYWU.js +663 -0
  65. package/dist/chunk-JVGPR3TS.js +365 -0
  66. package/dist/chunk-JVKB2TBL.js +48 -0
  67. package/dist/chunk-JX7VBZDK.js +31 -0
  68. package/dist/chunk-K3G6JBUC.js +5232 -0
  69. package/dist/chunk-K4YUNKU7.js +589 -0
  70. package/dist/chunk-KBZGE6LN.js +710 -0
  71. package/dist/chunk-KDQJCT2J.js +45 -0
  72. package/dist/chunk-KI4L2DUL.js +560 -0
  73. package/dist/chunk-KJ2ZTQSL.js +47 -0
  74. package/dist/chunk-KSJ5UTP7.js +154 -0
  75. package/dist/chunk-LHOA5DWA.js +28 -0
  76. package/dist/chunk-LX5QWLBL.js +27 -0
  77. package/dist/chunk-LZDDLNCZ.js +279 -0
  78. package/dist/chunk-M2WF6AXG.js +115 -0
  79. package/dist/chunk-M7BS2K6U.js +1 -0
  80. package/dist/chunk-NDBIPFNY.js +102 -0
  81. package/dist/chunk-NEMIWEXC.js +1199 -0
  82. package/dist/chunk-NFAYHPRH.js +323 -0
  83. package/dist/chunk-O37BQ65S.js +21 -0
  84. package/dist/chunk-O74MJHXU.js +187 -0
  85. package/dist/chunk-OJZEX73F.js +112 -0
  86. package/dist/chunk-PAAWLLZX.js +74 -0
  87. package/dist/chunk-PFXFQQRT.js +339 -0
  88. package/dist/chunk-PFZO3C6H.js +14 -0
  89. package/dist/chunk-PHH7LD45.js +113 -0
  90. package/dist/chunk-QRTG4XTI.js +188 -0
  91. package/dist/chunk-QVOVMXJR.js +1351 -0
  92. package/dist/chunk-RCQYT2I4.js +757 -0
  93. package/dist/chunk-RD6DEE36.js +1178 -0
  94. package/dist/chunk-RJIZEJ42.js +30 -0
  95. package/dist/chunk-RPOA7IAE.js +150 -0
  96. package/dist/chunk-SN2DQRL6.js +1172 -0
  97. package/dist/chunk-SQJVFEBV.js +41 -0
  98. package/dist/chunk-SQP64RCS.js +5391 -0
  99. package/dist/chunk-SVT4RNTR.js +49 -0
  100. package/dist/chunk-SWUFN7XM.js +43 -0
  101. package/dist/chunk-SXMVYC5H.js +174 -0
  102. package/dist/chunk-SZ6AYUIZ.js +23 -0
  103. package/dist/chunk-T3KGZBU5.js +3171 -0
  104. package/dist/chunk-TBRL2RCC.js +9 -0
  105. package/dist/chunk-TRT2HRWZ.js +18 -0
  106. package/dist/chunk-TYW2GI5I.js +1077 -0
  107. package/dist/chunk-UIWONWVG.js +4959 -0
  108. package/dist/chunk-VB3H5WWB.js +151 -0
  109. package/dist/chunk-W4A6QA3D.js +258 -0
  110. package/dist/chunk-WBPVKEEE.js +227 -0
  111. package/dist/chunk-WEBMSQP2.js +123 -0
  112. package/dist/chunk-WOEZV3Q4.js +333 -0
  113. package/dist/chunk-WQQON3SV.js +473 -0
  114. package/dist/chunk-WQTOVMGV.js +119 -0
  115. package/dist/chunk-WZO23AWO.js +2779 -0
  116. package/dist/chunk-XBDP4QPW.js +7 -0
  117. package/dist/chunk-XEBHSJLT.js +103 -0
  118. package/dist/chunk-XQ2ECNK3.js +1 -0
  119. package/dist/chunk-XQ2XGIBF.js +2086 -0
  120. package/dist/chunk-Y2GE5TSI.js +355 -0
  121. package/dist/chunk-YBUJCZ57.js +351 -0
  122. package/dist/chunk-YNCVSFGF.js +149 -0
  123. package/dist/chunk-YUPMXOGP.js +282 -0
  124. package/dist/chunk-YY6APYUM.js +49 -0
  125. package/dist/chunk-Z2IJUO45.js +691 -0
  126. package/dist/chunk-ZEHUCJHY.js +129 -0
  127. package/dist/chunk-ZYU2YOJ6.js +1496 -0
  128. package/dist/chunk-ZZ4V3WIZ.js +163 -0
  129. package/dist/coordination/agents/index.js +145 -6260
  130. package/dist/coordination/index.js +365 -34324
  131. package/dist/coordination/mailbox-project-server.js +48 -3276
  132. package/dist/coordination/provider-status-tracker.d.ts +4 -0
  133. package/dist/core/agent.d.ts +14 -1
  134. package/dist/core/index.js +267 -12480
  135. package/dist/core/model-ref.js +5 -23
  136. package/dist/core/provider-runner.d.ts +36 -1
  137. package/dist/design/index.js +50 -1087
  138. package/dist/execution/index.d.ts +1 -1
  139. package/dist/execution/index.js +1599 -21888
  140. package/dist/execution/prompt-enhancer.js +16 -535
  141. package/dist/execution/retry-policy.d.ts +31 -1
  142. package/dist/extension/index.js +7 -311
  143. package/dist/goal/index.js +33 -3435
  144. package/dist/hooks/index.js +14 -1138
  145. package/dist/hq/index.js +112 -5139
  146. package/dist/hq/protocol.js +21 -668
  147. package/dist/index.js +1410 -92656
  148. package/dist/infrastructure/index.js +64 -4811
  149. package/dist/kernel/events/provider-events.d.ts +15 -0
  150. package/dist/kernel/index.js +14 -992
  151. package/dist/models/index.js +40 -1117
  152. package/dist/notifications/index.js +3 -108
  153. package/dist/observability/index.js +17 -279
  154. package/dist/plugin/index.js +584 -14835
  155. package/dist/prompts/index.js +14 -948
  156. package/dist/registry/index.js +9 -822
  157. package/dist/registry-R23UBE7H.js +14 -0
  158. package/dist/replay/index.js +6 -84
  159. package/dist/review-finding-store-DKAV3AS6.js +21 -0
  160. package/dist/review-report-store-OWY3EC3N.js +19 -0
  161. package/dist/security/index.js +114 -2202
  162. package/dist/session-catalog/index.js +36 -2103
  163. package/dist/session-catalog/project-server.js +42 -1435
  164. package/dist/skills/index.js +35 -1578
  165. package/dist/storage/index.js +182 -15600
  166. package/dist/tasking/index.js +10 -676
  167. package/dist/tools/index.js +52 -9590
  168. package/dist/types/config/autonomy.d.ts +5 -0
  169. package/dist/types/config/ui.d.ts +1 -1
  170. package/dist/types/errors.d.ts +18 -0
  171. package/dist/types/index.js +121 -1342
  172. package/dist/types/provider-runner.d.ts +8 -0
  173. package/dist/types/session-markers.js +8 -144
  174. package/dist/utils/error.js +3 -4
  175. package/dist/utils/expect-defined.js +3 -9
  176. package/dist/utils/heap-watchdog.js +6 -706
  177. package/dist/utils/index.js +269 -5685
  178. package/dist/utils/sage-output-block.js +5 -42
  179. package/dist/wiring/proxy-rewrite.d.ts +18 -0
  180. package/dist/wiring/proxy-rewrite.js +18 -121
  181. package/dist/worktree/index.js +6 -887
  182. package/package.json +4 -4
@@ -1,679 +1,13 @@
1
- // src/tasking/task-store.ts
2
- var DefaultTaskStore = class {
3
- graphs = /* @__PURE__ */ new Map();
4
- async saveGraph(graph) {
5
- this.graphs.set(graph.id, this.cloneGraph(graph));
6
- }
7
- async loadGraph(id) {
8
- const graph = this.graphs.get(id);
9
- return graph ? this.cloneGraph(graph) : null;
10
- }
11
- async listGraphs() {
12
- return Array.from(this.graphs.values()).map((graph) => ({
13
- id: graph.id,
14
- title: graph.title,
15
- updatedAt: graph.updatedAt
16
- }));
17
- }
18
- async deleteGraph(id) {
19
- this.graphs.delete(id);
20
- }
21
- cloneGraph(graph) {
22
- return {
23
- ...graph,
24
- nodes: new Map(graph.nodes),
25
- edges: [...graph.edges],
26
- rootNodes: [...graph.rootNodes]
27
- };
28
- }
29
- };
30
-
31
- // src/utils/error.ts
32
- function toErrorMessage(err) {
33
- return err instanceof Error ? err.message : String(err);
34
- }
35
-
36
- // src/types/errors.ts
37
- var ERROR_CODES = {
38
- // Provider
39
- PROVIDER_RATE_LIMITED: "PROVIDER_RATE_LIMITED",
40
- PROVIDER_AUTH_FAILED: "PROVIDER_AUTH_FAILED",
41
- PROVIDER_OVERLOADED: "PROVIDER_OVERLOADED",
42
- PROVIDER_INVALID_REQUEST: "PROVIDER_INVALID_REQUEST",
43
- PROVIDER_SERVER_ERROR: "PROVIDER_SERVER_ERROR",
44
- PROVIDER_NETWORK_ERROR: "PROVIDER_NETWORK_ERROR",
45
- PROVIDER_CONTEXT_OVERFLOW: "PROVIDER_CONTEXT_OVERFLOW",
46
- // Tool
47
- TOOL_NOT_FOUND: "TOOL_NOT_FOUND",
48
- TOOL_PERMISSION_DENIED: "TOOL_PERMISSION_DENIED",
49
- TOOL_EXECUTION_FAILED: "TOOL_EXECUTION_FAILED",
50
- TOOL_TIMEOUT: "TOOL_TIMEOUT",
51
- TOOL_INPUT_INVALID: "TOOL_INPUT_INVALID",
52
- // Config
53
- CONFIG_INVALID: "CONFIG_INVALID",
54
- CONFIG_NOT_FOUND: "CONFIG_NOT_FOUND",
55
- CONFIG_PARSE_FAILED: "CONFIG_PARSE_FAILED",
56
- CONFIG_MIGRATION_NEEDED: "CONFIG_MIGRATION_NEEDED",
57
- // Plugin
58
- PLUGIN_LOAD_FAILED: "PLUGIN_LOAD_FAILED",
59
- PLUGIN_API_MISMATCH: "PLUGIN_API_MISMATCH",
60
- PLUGIN_MISSING_DEPENDENCY: "PLUGIN_MISSING_DEPENDENCY",
61
- // Agent
62
- AGENT_ITERATION_LIMIT: "AGENT_ITERATION_LIMIT",
63
- AGENT_CONTEXT_OVERFLOW: "AGENT_CONTEXT_OVERFLOW",
64
- AGENT_ABORTED: "AGENT_ABORTED",
65
- AGENT_RUN_FAILED: "AGENT_RUN_FAILED",
66
- // Session
67
- SESSION_NOT_FOUND: "SESSION_NOT_FOUND",
68
- SESSION_CORRUPTED: "SESSION_CORRUPTED",
69
- SESSION_WRITE_FAILED: "SESSION_WRITE_FAILED",
70
- // Container / Registry
71
- CONTAINER_TOKEN_ALREADY_BOUND: "CONTAINER_TOKEN_ALREADY_BOUND",
72
- CONTAINER_TOKEN_NOT_BOUND: "CONTAINER_TOKEN_NOT_BOUND",
73
- CONTAINER_CIRCULAR_DEPENDENCY: "CONTAINER_CIRCULAR_DEPENDENCY",
74
- REGISTRY_DUPLICATE: "REGISTRY_DUPLICATE",
75
- REGISTRY_NOT_FOUND: "REGISTRY_NOT_FOUND",
76
- REGISTRY_INVALID: "REGISTRY_INVALID",
77
- // File system
78
- FS_READ_FAILED: "FS_READ_FAILED",
79
- FS_WRITE_FAILED: "FS_WRITE_FAILED",
80
- FS_MKDIR_FAILED: "FS_MKDIR_FAILED",
81
- FS_DELETE_FAILED: "FS_DELETE_FAILED",
82
- FS_ATOMIC_WRITE_FAILED: "FS_ATOMIC_WRITE_FAILED",
83
- // SDD (Spec-Driven Development)
84
- SDD_VALIDATION_FAILED: "SDD_VALIDATION_FAILED",
85
- SDD_PARSE_FAILED: "SDD_PARSE_FAILED",
86
- SDD_INVALID_STATE: "SDD_INVALID_STATE",
87
- SDD_NOT_READY: "SDD_NOT_READY",
88
- // General
89
- VALIDATION_ERROR: "VALIDATION_ERROR",
90
- PARSE_FAILED: "PARSE_FAILED",
91
- UNKNOWN: "UNKNOWN"
92
- };
93
- var WrongStackError = class extends Error {
94
- code;
95
- subsystem;
96
- severity;
97
- recoverable;
98
- context;
99
- constructor(opts) {
100
- super(opts.message, { cause: opts.cause });
101
- this.name = "WrongStackError";
102
- this.code = opts.code;
103
- this.subsystem = opts.subsystem;
104
- this.severity = opts.severity ?? "error";
105
- this.recoverable = opts.recoverable ?? false;
106
- this.context = opts.context;
107
- }
108
- /**
109
- * Render a one-line user-facing description.
110
- * Subclasses should override for domain-specific formatting.
111
- */
112
- describe() {
113
- const ctx = this.context ? ` ${formatContext(this.context)}` : "";
114
- return `${this.code}: ${this.message}${ctx}`;
115
- }
116
- };
117
- function formatContext(ctx) {
118
- const parts = Object.entries(ctx).filter(([, v]) => v !== void 0).slice(0, 3).map(([k, v]) => `${k}=${String(v)}`);
119
- return parts.length > 0 ? `[${parts.join(" ")}]` : "";
120
- }
121
- var SddError = class extends WrongStackError {
122
- constructor(opts) {
123
- super({
124
- message: opts.message,
125
- code: opts.code,
126
- subsystem: "sdd",
127
- severity: opts.code === ERROR_CODES.SDD_PARSE_FAILED ? "warning" : "error",
128
- recoverable: opts.code === ERROR_CODES.SDD_NOT_READY,
129
- context: opts.context,
130
- cause: opts.cause
131
- });
132
- this.name = "SddError";
133
- }
134
- };
135
-
136
- // src/types/task-graph.ts
137
- function computeTaskProgress(graph) {
138
- let completed = 0;
139
- let pending = 0;
140
- let inProgress = 0;
141
- let blocked = 0;
142
- let failed = 0;
143
- let review = 0;
144
- let estimatedHours = 0;
145
- let actualHours = 0;
146
- for (const n of graph.nodes.values()) {
147
- switch (n.status) {
148
- case "completed":
149
- completed++;
150
- break;
151
- case "pending":
152
- pending++;
153
- break;
154
- case "in_progress":
155
- inProgress++;
156
- break;
157
- case "blocked":
158
- blocked++;
159
- break;
160
- case "failed":
161
- failed++;
162
- break;
163
- case "review":
164
- review++;
165
- break;
166
- }
167
- estimatedHours += n.estimateHours ?? 0;
168
- actualHours += n.actualHours ?? 0;
169
- }
170
- const total = graph.nodes.size;
171
- return {
172
- total,
173
- pending,
174
- inProgress,
175
- blocked,
176
- failed,
177
- review,
178
- completed,
179
- percentComplete: total > 0 ? Math.round(completed / total * 100) : 0,
180
- estimatedHours,
181
- actualHours
182
- };
183
- }
184
- function topologicalSort(graph) {
185
- const visited = /* @__PURE__ */ new Set();
186
- const inStack = /* @__PURE__ */ new Set();
187
- const result = [];
188
- function visit(id) {
189
- if (inStack.has(id)) return;
190
- if (visited.has(id)) return;
191
- if (!graph.nodes.has(id)) return;
192
- visited.add(id);
193
- inStack.add(id);
194
- for (const edge of graph.edges) {
195
- if (edge.from === id) visit(edge.to);
196
- }
197
- inStack.delete(id);
198
- result.push(id);
199
- }
200
- for (const rootId of graph.rootNodes) {
201
- visit(rootId);
202
- }
203
- return result;
204
- }
205
- function serializeTaskGraph(graph) {
206
- return {
207
- ...graph,
208
- nodes: Array.from(graph.nodes.values())
209
- };
210
- }
211
- function deserializeTaskGraph(input) {
212
- const nodes = /* @__PURE__ */ new Map();
213
- if (Array.isArray(input.nodes)) {
214
- for (const entry of input.nodes) {
215
- if (Array.isArray(entry)) nodes.set(entry[0], { ...entry[1], id: entry[1].id || entry[0] });
216
- else nodes.set(entry.id, entry);
217
- }
218
- } else {
219
- for (const [id, node] of Object.entries(input.nodes)) {
220
- nodes.set(id, { ...node, id: node.id || id });
221
- }
222
- }
223
- return { ...input, nodes };
224
- }
225
-
226
- // src/tasking/task-tracker.ts
227
- var TaskTracker = class _TaskTracker {
228
- constructor(opts) {
229
- this.opts = opts;
230
- }
231
- opts;
232
- graph = null;
233
- transitions = [];
234
- listeners = [];
235
- /**
236
- * Re-entrancy guard for status cascades: true while an auto-block /
237
- * auto-unblock cascade is running. Listener-driven mutations during a
238
- * cascade still record their own primary transition — only their
239
- * cascading is skipped (prevents unbounded recursion).
240
- */
241
- cascading = false;
242
- static MAX_TRANSITIONS = 1e4;
243
- /**
244
- * Subscribe to live task mutations (add / update / status change). Returns an
245
- * unsubscribe fn. This is the hook the board projector uses to stream a live
246
- * snapshot — the tracker was previously fire-and-forget with no observability.
247
- */
248
- subscribe(listener) {
249
- this.listeners.push(listener);
250
- return () => {
251
- const i = this.listeners.indexOf(listener);
252
- if (i >= 0) this.listeners.splice(i, 1);
253
- };
254
- }
255
- notifyChange(change) {
256
- for (const l of this.listeners) {
257
- try {
258
- l(change);
259
- } catch {
260
- }
261
- }
262
- }
263
- /**
264
- * Attach an existing graph (used by PhaseOrchestrator to associate a tracker
265
- * with a phase's pre-built task graph without re-creating it).
266
- */
267
- setGraph(graph) {
268
- this.graph = graph;
269
- }
270
- async createGraph(specId, title) {
271
- this.graph = {
272
- id: crypto.randomUUID(),
273
- specId,
274
- title,
275
- nodes: /* @__PURE__ */ new Map(),
276
- edges: [],
277
- rootNodes: [],
278
- createdAt: Date.now(),
279
- updatedAt: Date.now()
280
- };
281
- await this.opts.store.saveGraph(this.graph);
282
- return this.graph;
283
- }
284
- async loadGraph(id) {
285
- this.graph = await this.opts.store.loadGraph(id);
286
- return this.graph;
287
- }
288
- addNode(node) {
289
- if (!this.graph)
290
- throw new SddError({
291
- message: "No graph loaded",
292
- code: ERROR_CODES.SDD_INVALID_STATE
293
- });
294
- const now = Date.now();
295
- const newNode = {
296
- ...node,
297
- id: crypto.randomUUID(),
298
- status: node.status ?? "pending",
299
- createdAt: now,
300
- updatedAt: now
301
- };
302
- this.graph.nodes.set(newNode.id, newNode);
303
- if (!node.parentId) {
304
- this.graph.rootNodes.push(newNode.id);
305
- }
306
- this.graph.updatedAt = now;
307
- this.persist();
308
- this.notifyChange({ type: "node_added", nodeId: newNode.id, node: newNode });
309
- return newNode;
310
- }
311
- addEdge(from, to, type = "depends_on") {
312
- if (!this.graph)
313
- throw new SddError({
314
- message: "No graph loaded",
315
- code: ERROR_CODES.SDD_INVALID_STATE
316
- });
317
- if (!this.graph.nodes.has(from) || !this.graph.nodes.has(to)) {
318
- throw new SddError({
319
- message: `Cannot add ${type} edge ${from} -> ${to}: endpoint task is not in the graph`,
320
- code: ERROR_CODES.SDD_NOT_READY,
321
- context: { from, to, type }
322
- });
323
- }
324
- if (from === to) {
325
- throw new SddError({
326
- message: `Cannot add ${type} edge: self-loop on task ${from}`,
327
- code: ERROR_CODES.SDD_INVALID_STATE,
328
- context: { nodeId: from, type }
329
- });
330
- }
331
- if (this.graph.edges.some((e) => e.from === from && e.to === to && e.type === type)) return;
332
- if (type === "depends_on" && this.dependsOnTransitively(from, to, /* @__PURE__ */ new Set())) {
333
- throw new SddError({
334
- message: `Cannot add depends_on edge ${from} -> ${to}: it would create a dependency cycle`,
335
- code: ERROR_CODES.SDD_INVALID_STATE,
336
- context: { from, to }
337
- });
338
- }
339
- this.graph.edges.push({
340
- id: crypto.randomUUID(),
341
- from,
342
- to,
343
- type
344
- });
345
- this.graph.updatedAt = Date.now();
346
- this.persist();
347
- }
348
- /**
349
- * Declare that `taskId` depends on `depId` (a `depends_on` edge `depId → taskId`),
350
- * guarding against self-loops, duplicates, missing nodes, and cycles. Returns
351
- * true if the dependency now holds (added or already present), false if it was
352
- * rejected (would create a cycle / unknown node). This is the safe entry point
353
- * for wiring agent-declared `dependsOn` references into the graph.
354
- */
355
- addDependency(depId, taskId) {
356
- if (!this.graph) return false;
357
- if (depId === taskId) return false;
358
- if (!this.graph.nodes.has(depId) || !this.graph.nodes.has(taskId)) return false;
359
- if (this.getBlockers(taskId).includes(depId)) return true;
360
- if (this.dependsOnTransitively(depId, taskId, /* @__PURE__ */ new Set())) return false;
361
- this.addEdge(depId, taskId, "depends_on");
362
- return true;
363
- }
364
- /** True when `taskId` transitively depends on `targetId` (follows depends_on blockers). */
365
- dependsOnTransitively(taskId, targetId, seen) {
366
- if (taskId === targetId) return true;
367
- if (seen.has(taskId)) return false;
368
- seen.add(taskId);
369
- for (const blocker of this.getBlockers(taskId)) {
370
- if (this.dependsOnTransitively(blocker, targetId, seen)) return true;
371
- }
372
- return false;
373
- }
374
- /**
375
- * Merge `patch` into a node's `metadata` (used for per-task model/provider/
376
- * fallback assignment and the cancel marker). Persists + notifies as a node
377
- * update. No-op if the node is missing.
378
- */
379
- patchMetadata(id, patch) {
380
- if (!this.graph) return;
381
- const node = this.graph.nodes.get(id);
382
- if (!node) return;
383
- node.metadata = { ...node.metadata, ...patch };
384
- node.updatedAt = Date.now();
385
- this.graph.updatedAt = node.updatedAt;
386
- this.persist();
387
- this.notifyChange({ type: "node_updated", nodeId: id, node });
388
- }
389
- /**
390
- * Remove a node and every edge touching it. Intended for deleting a task that
391
- * has not started yet — callers must gate on status (do not remove a running
392
- * task). Dependents simply lose this blocker (re-evaluated by `canStart`).
393
- * Returns true if a node was removed.
394
- */
395
- removeNode(id) {
396
- if (!this.graph) return false;
397
- const node = this.graph.nodes.get(id);
398
- if (!node) return false;
399
- if (node.specRequirementId && this.graph.requiredRequirementIds?.includes(node.specRequirementId) && !Array.from(this.graph.nodes.values()).some(
400
- (candidate) => candidate.id !== id && candidate.specRequirementId === node.specRequirementId
401
- )) {
402
- return false;
403
- }
404
- this.graph.nodes.delete(id);
405
- this.graph.edges = this.graph.edges.filter((e) => e.from !== id && e.to !== id);
406
- this.graph.rootNodes = this.graph.rootNodes.filter((r) => r !== id);
407
- for (const n of this.graph.nodes.values()) {
408
- if (n.children?.includes(id)) n.children = n.children.filter((c) => c !== id);
409
- }
410
- this.graph.updatedAt = Date.now();
411
- this.persist();
412
- this.notifyChange({ type: "node_removed", nodeId: id, node });
413
- return true;
414
- }
415
- updateNodeStatus(id, status, reason) {
416
- if (!this.graph)
417
- throw new SddError({
418
- message: "No graph loaded",
419
- code: ERROR_CODES.SDD_INVALID_STATE
420
- });
421
- const node = this.graph.nodes.get(id);
422
- if (!node)
423
- throw new SddError({
424
- message: `Node ${id} not found`,
425
- code: ERROR_CODES.SDD_NOT_READY,
426
- context: { nodeId: id }
427
- });
428
- const from = node.status;
429
- const now = Date.now();
430
- node.status = status;
431
- node.updatedAt = now;
432
- if (status === "completed") {
433
- node.completedAt = now;
434
- node.startedAt = node.startedAt ?? now;
435
- }
436
- if (status === "in_progress") {
437
- node.startedAt = now;
438
- }
439
- this.transitions.push({ nodeId: id, from, to: status, timestamp: now, reason });
440
- if (this.transitions.length > _TaskTracker.MAX_TRANSITIONS) {
441
- this.transitions.splice(0, this.transitions.length - _TaskTracker.MAX_TRANSITIONS);
442
- }
443
- if (status === "completed") {
444
- this.unblockDependents(id);
445
- }
446
- if (status === "in_progress") {
447
- this.checkAndBlockIfNeeded(id);
448
- }
449
- this.graph.updatedAt = now;
450
- this.persist();
451
- this.notifyChange({
452
- type: "status_changed",
453
- nodeId: id,
454
- node,
455
- transition: { nodeId: id, from, to: status, timestamp: now, reason }
456
- });
457
- }
458
- updateNode(id, patch) {
459
- if (!this.graph)
460
- throw new SddError({
461
- message: "No graph loaded",
462
- code: ERROR_CODES.SDD_INVALID_STATE
463
- });
464
- const node = this.graph.nodes.get(id);
465
- if (!node)
466
- throw new SddError({
467
- message: `Node ${id} not found`,
468
- code: ERROR_CODES.SDD_NOT_READY,
469
- context: { nodeId: id }
470
- });
471
- if (patch.title !== void 0) node.title = patch.title;
472
- if (patch.description !== void 0) node.description = patch.description;
473
- if (patch.priority !== void 0) node.priority = patch.priority;
474
- if (patch.estimateHours !== void 0) node.estimateHours = patch.estimateHours;
475
- if (patch.tags !== void 0) node.tags = patch.tags;
476
- if (patch.assignee !== void 0) node.assignee = patch.assignee;
477
- node.updatedAt = Date.now();
478
- this.graph.updatedAt = node.updatedAt;
479
- this.persist();
480
- this.notifyChange({ type: "node_updated", nodeId: id, node });
481
- }
482
- getNode(id) {
483
- return this.graph?.nodes.get(id);
484
- }
485
- getAllNodes(filter, sort) {
486
- if (!this.graph) return [];
487
- let nodes = Array.from(this.graph.nodes.values());
488
- if (filter) {
489
- nodes = nodes.filter((n) => {
490
- if (filter.status?.length && !filter.status.includes(n.status)) return false;
491
- if (filter.priority?.length && !filter.priority.includes(n.priority)) return false;
492
- if (filter.type?.length && !filter.type.includes(n.type)) return false;
493
- if (filter.assignee?.length && n.assignee && !filter.assignee.includes(n.assignee))
494
- return false;
495
- if (filter.tags?.length && n.tags && !n.tags.some((t) => filter.tags?.includes(t)))
496
- return false;
497
- if (filter.specRequirementId && n.specRequirementId !== filter.specRequirementId)
498
- return false;
499
- return true;
500
- });
501
- }
502
- if (sort) {
503
- nodes.sort((a, b) => {
504
- const cmp = compareByField(a, b, sort.field);
505
- return sort.direction === "asc" ? cmp : -cmp;
506
- });
507
- }
508
- return nodes;
509
- }
510
- getChildren(parentId) {
511
- if (!this.graph) return [];
512
- return Array.from(this.graph.nodes.values()).filter((n) => n.parentId === parentId);
513
- }
514
- getDependents(taskId) {
515
- if (!this.graph) return [];
516
- return this.graph.edges.filter((e) => e.from === taskId && e.type === "depends_on").map((e) => e.to);
517
- }
518
- getBlockers(taskId) {
519
- if (!this.graph) return [];
520
- return this.graph.edges.filter((e) => e.to === taskId && e.type === "depends_on").map((e) => e.from);
521
- }
522
- canStart(taskId) {
523
- const blockers = this.getBlockers(taskId);
524
- return blockers.every((id) => {
525
- const node = this.graph?.nodes.get(id);
526
- return node?.status === "completed" || node?.status === "failed";
527
- });
528
- }
529
- getProgress() {
530
- if (!this.graph) {
531
- return {
532
- total: 0,
533
- pending: 0,
534
- inProgress: 0,
535
- blocked: 0,
536
- failed: 0,
537
- review: 0,
538
- completed: 0,
539
- percentComplete: 0,
540
- estimatedHours: 0,
541
- actualHours: 0
542
- };
543
- }
544
- return computeTaskProgress(this.graph);
545
- }
546
- /**
547
- * Recorded transitions in insertion order (oldest first — the array is
548
- * trimmed from the front). With `taskId`, only that task's transitions are
549
- * returned, still oldest-first; a consumer wanting newest-first reverses
550
- * the result. Per-task filtering is possible because every TaskTransition
551
- * carries `nodeId` (BIZ-005).
552
- */
553
- getTransitions(taskId) {
554
- return taskId === void 0 ? [...this.transitions] : this.transitions.filter((t) => t.nodeId === taskId);
555
- }
556
- /**
557
- * Record a cascade-driven status change (BIZ-003): mutate the node, push a
558
- * TaskTransition, persist, and notify subscribers — the same effects an
559
- * explicit updateNodeStatus produces — so the board projector's live
560
- * snapshot and the transition log observe auto-block/auto-unblock.
561
- */
562
- recordCascadeStatusChange(nodeId, node, to, reason) {
563
- const from = node.status;
564
- if (from === to) return;
565
- const now = Date.now();
566
- node.status = to;
567
- node.updatedAt = now;
568
- if (this.graph) this.graph.updatedAt = now;
569
- this.transitions.push({ nodeId, from, to, timestamp: now, reason });
570
- if (this.transitions.length > _TaskTracker.MAX_TRANSITIONS) {
571
- this.transitions.splice(0, this.transitions.length - _TaskTracker.MAX_TRANSITIONS);
572
- }
573
- this.persist();
574
- this.notifyChange({
575
- type: "status_changed",
576
- nodeId,
577
- node,
578
- transition: { nodeId, from, to, timestamp: now, reason }
579
- });
580
- }
581
- unblockDependents(completedId) {
582
- if (!this.graph || this.cascading) return;
583
- this.cascading = true;
584
- try {
585
- const dependents = this.getDependents(completedId);
586
- for (const depId of dependents) {
587
- const dep = this.graph.nodes.get(depId);
588
- if (dep?.status !== "blocked") continue;
589
- const remainingBlockers = this.getBlockers(depId);
590
- const allUnblocked = remainingBlockers.every((id) => {
591
- const blocker = this.graph?.nodes.get(id);
592
- return blocker?.status === "completed" || blocker?.status === "failed";
593
- });
594
- if (allUnblocked) {
595
- this.recordCascadeStatusChange(
596
- depId,
597
- dep,
598
- "pending",
599
- `auto-unblocked: blocker ${completedId} reached a terminal state`
600
- );
601
- }
602
- }
603
- } finally {
604
- this.cascading = false;
605
- }
606
- }
607
- checkAndBlockIfNeeded(taskId) {
608
- if (!this.graph || this.cascading) return;
609
- this.cascading = true;
610
- try {
611
- const blockers = this.getBlockers(taskId);
612
- const incomplete = blockers.filter((id) => {
613
- const blocker = this.graph?.nodes.get(id);
614
- return blocker?.status !== "completed" && blocker?.status !== "failed";
615
- });
616
- if (incomplete.length > 0) {
617
- const node = this.graph.nodes.get(taskId);
618
- if (node) {
619
- this.recordCascadeStatusChange(
620
- taskId,
621
- node,
622
- "blocked",
623
- `auto-blocked: incomplete blocker(s) ${incomplete.join(", ")}`
624
- );
625
- }
626
- }
627
- } finally {
628
- this.cascading = false;
629
- }
630
- }
631
- /**
632
- * Fire-and-forget persistence with attached error handler.
633
- * Synchronous mutators (addNode/addEdge/updateNodeStatus) use this to
634
- * avoid forcing an async cascade through every caller; if the store
635
- * is missing or throwing, the error is surfaced via onPersistError.
636
- */
637
- persist() {
638
- if (!this.graph) return;
639
- this.opts.store.saveGraph(this.graph).catch((err) => {
640
- this.opts.onPersistError ? this.opts.onPersistError(err) : console.warn(
641
- JSON.stringify({
642
- level: "warn",
643
- event: "task_tracker.save_graph_failed",
644
- message: toErrorMessage(err),
645
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
646
- })
647
- );
648
- });
649
- }
650
- };
651
- var PRIORITY_RANK = {
652
- critical: 0,
653
- high: 1,
654
- medium: 2,
655
- low: 3
656
- };
657
- var STATUS_RANK = {
658
- in_progress: 0,
659
- pending: 1,
660
- review: 2,
661
- blocked: 3,
662
- failed: 4,
663
- completed: 5
664
- };
665
- function compareByField(a, b, field) {
666
- switch (field) {
667
- case "priority":
668
- return PRIORITY_RANK[a.priority] - PRIORITY_RANK[b.priority];
669
- case "status":
670
- return STATUS_RANK[a.status] - STATUS_RANK[b.status];
671
- case "createdAt":
672
- return a.createdAt - b.createdAt;
673
- case "updatedAt":
674
- return a.updatedAt - b.updatedAt;
675
- }
676
- }
1
+ import {
2
+ DefaultTaskStore,
3
+ TaskTracker,
4
+ computeTaskProgress,
5
+ deserializeTaskGraph,
6
+ serializeTaskGraph,
7
+ topologicalSort
8
+ } from "../chunk-K4YUNKU7.js";
9
+ import "../chunk-WOEZV3Q4.js";
10
+ import "../chunk-TBRL2RCC.js";
677
11
  export {
678
12
  DefaultTaskStore,
679
13
  TaskTracker,