@adhd/dispatch-base-spec 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.mjs CHANGED
@@ -1,682 +1,473 @@
1
- const z = /* @__PURE__ */ new Set([
2
- "create",
3
- "modify-signature",
4
- "modify-body",
5
- "add-export",
6
- "remove-export",
7
- "rename"
8
- ]), x = {
9
- function: /* @__PURE__ */ new Set([
10
- "add-param",
11
- "remove-param",
12
- "rename-param",
13
- "retype-param",
14
- "change-param-optional",
15
- "reorder-params",
16
- "change-return"
17
- ]),
18
- interface: /* @__PURE__ */ new Set([
19
- "add-field",
20
- "remove-field",
21
- "rename-field",
22
- "retype-field",
23
- "change-field-optional",
24
- "add-generic",
25
- "remove-generic",
26
- "constrain-generic",
27
- "add-extends",
28
- "remove-extends"
29
- ]),
30
- type: /* @__PURE__ */ new Set(["add-field", "remove-field", "retype-field"]),
31
- class: /* @__PURE__ */ new Set([
32
- "add-field",
33
- "remove-field",
34
- "rename-field",
35
- "retype-field",
36
- "change-field-optional",
37
- "add-param",
38
- "add-generic",
39
- "remove-generic",
40
- "constrain-generic",
41
- "add-extends",
42
- "remove-extends"
43
- ]),
44
- enum: /* @__PURE__ */ new Set(["add-field", "remove-field", "rename-field"]),
45
- const: /* @__PURE__ */ new Set([
46
- "add-var",
47
- "remove-var",
48
- "rename-var",
49
- "change-default"
50
- ]),
51
- config: /* @__PURE__ */ new Set([
52
- "set-key",
53
- "remove-key",
54
- "rename-key",
55
- "add-entry",
56
- "remove-entry",
57
- "update-entry",
58
- "bump-version",
59
- "update-checksum"
60
- ]),
61
- env: /* @__PURE__ */ new Set(["set-key", "remove-key", "rename-key"]),
62
- schema: /* @__PURE__ */ new Set([
63
- "add-table",
64
- "remove-table",
65
- "add-column",
66
- "remove-column",
67
- "rename-column",
68
- "retype-column",
69
- "change-nullable",
70
- "add-index",
71
- "remove-index"
72
- ]),
73
- manifest: /* @__PURE__ */ new Set(["add-entry", "remove-entry", "bump-version"]),
74
- doc: /* @__PURE__ */ new Set([
75
- "add-section",
76
- "remove-section",
77
- "rename-section",
78
- "update-section"
79
- ]),
80
- "structured-output": /* @__PURE__ */ new Set([]),
81
- script: /* @__PURE__ */ new Set([
82
- "add-param",
83
- "remove-param",
84
- "rename-param",
85
- "retype-param",
86
- "change-param-optional",
87
- "reorder-params",
88
- "change-return",
89
- "add-field",
90
- "remove-field",
91
- "rename-field",
92
- "retype-field",
93
- "change-field-optional",
94
- "add-generic",
95
- "remove-generic",
96
- "constrain-generic",
97
- "add-extends",
98
- "remove-extends",
99
- "set-key",
100
- "remove-key",
101
- "rename-key",
102
- "add-array-item",
103
- "remove-array-item",
104
- "add-var",
105
- "remove-var",
106
- "rename-var",
107
- "change-default",
108
- "add-section",
109
- "remove-section",
110
- "rename-section",
111
- "update-section",
112
- "add-table",
113
- "remove-table",
114
- "add-column",
115
- "remove-column",
116
- "rename-column",
117
- "retype-column",
118
- "change-nullable",
119
- "add-index",
120
- "remove-index",
121
- "add-entry",
122
- "remove-entry",
123
- "update-entry",
124
- "bump-version",
125
- "update-checksum",
126
- "add-export"
127
- ])
1
+ //#region src/lib/types.ts
2
+ var e = /* @__PURE__ */ new Set([
3
+ "create",
4
+ "modify-signature",
5
+ "modify-body",
6
+ "add-export",
7
+ "remove-export",
8
+ "rename"
9
+ ]), t = {
10
+ function: /* @__PURE__ */ new Set([
11
+ "add-param",
12
+ "remove-param",
13
+ "rename-param",
14
+ "retype-param",
15
+ "change-param-optional",
16
+ "reorder-params",
17
+ "change-return"
18
+ ]),
19
+ interface: /* @__PURE__ */ new Set([
20
+ "add-field",
21
+ "remove-field",
22
+ "rename-field",
23
+ "retype-field",
24
+ "change-field-optional",
25
+ "add-generic",
26
+ "remove-generic",
27
+ "constrain-generic",
28
+ "add-extends",
29
+ "remove-extends"
30
+ ]),
31
+ type: /* @__PURE__ */ new Set([
32
+ "add-field",
33
+ "remove-field",
34
+ "retype-field"
35
+ ]),
36
+ class: /* @__PURE__ */ new Set([
37
+ "add-field",
38
+ "remove-field",
39
+ "rename-field",
40
+ "retype-field",
41
+ "change-field-optional",
42
+ "add-param",
43
+ "add-generic",
44
+ "remove-generic",
45
+ "constrain-generic",
46
+ "add-extends",
47
+ "remove-extends"
48
+ ]),
49
+ enum: /* @__PURE__ */ new Set([
50
+ "add-field",
51
+ "remove-field",
52
+ "rename-field"
53
+ ]),
54
+ const: /* @__PURE__ */ new Set([
55
+ "add-var",
56
+ "remove-var",
57
+ "rename-var",
58
+ "change-default"
59
+ ]),
60
+ config: /* @__PURE__ */ new Set([
61
+ "set-key",
62
+ "remove-key",
63
+ "rename-key",
64
+ "add-entry",
65
+ "remove-entry",
66
+ "update-entry",
67
+ "bump-version",
68
+ "update-checksum"
69
+ ]),
70
+ env: /* @__PURE__ */ new Set([
71
+ "set-key",
72
+ "remove-key",
73
+ "rename-key"
74
+ ]),
75
+ schema: /* @__PURE__ */ new Set([
76
+ "add-table",
77
+ "remove-table",
78
+ "add-column",
79
+ "remove-column",
80
+ "rename-column",
81
+ "retype-column",
82
+ "change-nullable",
83
+ "add-index",
84
+ "remove-index"
85
+ ]),
86
+ manifest: /* @__PURE__ */ new Set([
87
+ "add-entry",
88
+ "remove-entry",
89
+ "bump-version"
90
+ ]),
91
+ doc: /* @__PURE__ */ new Set([
92
+ "add-section",
93
+ "remove-section",
94
+ "rename-section",
95
+ "update-section"
96
+ ]),
97
+ "structured-output": /* @__PURE__ */ new Set([]),
98
+ script: /* @__PURE__ */ new Set(/* @__PURE__ */ "add-param.remove-param.rename-param.retype-param.change-param-optional.reorder-params.change-return.add-field.remove-field.rename-field.retype-field.change-field-optional.add-generic.remove-generic.constrain-generic.add-extends.remove-extends.set-key.remove-key.rename-key.add-array-item.remove-array-item.add-var.remove-var.rename-var.change-default.add-section.remove-section.rename-section.update-section.add-table.remove-table.add-column.remove-column.rename-column.retype-column.change-nullable.add-index.remove-index.add-entry.remove-entry.update-entry.bump-version.update-checksum.add-export".split("."))
128
99
  };
129
- function j(t, e) {
130
- const r = x[t];
131
- return r ? r.has(e) : !1;
100
+ function n(e, n) {
101
+ let r = t[e];
102
+ return r ? r.has(n) : !1;
132
103
  }
133
- const O = /* @__PURE__ */ new Set([
134
- "pending",
135
- "pending-surfaced",
136
- "in_progress",
137
- "complete",
138
- "failed",
139
- "skipped"
140
- ]), I = /* @__PURE__ */ new Set([
141
- "pending",
142
- "in_progress",
143
- "complete",
144
- "failed",
145
- "skipped"
146
- ]), D = /* @__PURE__ */ new Set(["automated", "tool-call", "generative"]), q = /* @__PURE__ */ new Set([
147
- "anthropic",
148
- "openai",
149
- "deepseek",
150
- "google",
151
- "local",
152
- "claudecli",
153
- "teammate"
154
- ]), E = /* @__PURE__ */ new Set([
155
- "function",
156
- "interface",
157
- "type",
158
- "class",
159
- "enum",
160
- "const",
161
- "script",
162
- "config",
163
- "env",
164
- "schema",
165
- "manifest",
166
- "doc",
167
- "structured-output"
104
+ //#endregion
105
+ //#region src/lib/validate.ts
106
+ var r = /* @__PURE__ */ new Set([
107
+ "pending",
108
+ "pending-surfaced",
109
+ "in_progress",
110
+ "complete",
111
+ "failed",
112
+ "skipped"
113
+ ]), i = /* @__PURE__ */ new Set([
114
+ "pending",
115
+ "in_progress",
116
+ "complete",
117
+ "failed",
118
+ "skipped"
119
+ ]), a = /* @__PURE__ */ new Set([
120
+ "automated",
121
+ "tool-call",
122
+ "generative"
123
+ ]), o = /* @__PURE__ */ new Set([
124
+ "anthropic",
125
+ "openai",
126
+ "deepseek",
127
+ "google",
128
+ "local",
129
+ "claudecli",
130
+ "teammate"
131
+ ]), s = /* @__PURE__ */ new Set([
132
+ "function",
133
+ "interface",
134
+ "type",
135
+ "class",
136
+ "enum",
137
+ "const",
138
+ "script",
139
+ "config",
140
+ "env",
141
+ "schema",
142
+ "manifest",
143
+ "doc",
144
+ "structured-output"
168
145
  ]);
169
- function h(t) {
170
- return typeof t == "object" && t !== null && !Array.isArray(t);
146
+ function c(e) {
147
+ return typeof e == "object" && !!e && !Array.isArray(e);
171
148
  }
172
- function l(t) {
173
- return typeof t == "string";
149
+ function l(e) {
150
+ return typeof e == "string";
174
151
  }
175
- function n(t, e, r) {
176
- return { path: t, message: e, value: r };
152
+ function u(e, t, n) {
153
+ return {
154
+ path: e,
155
+ message: t,
156
+ value: n
157
+ };
177
158
  }
178
- function T(t) {
179
- var d, c;
180
- const e = Object.keys(t), r = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map();
181
- for (const o of e)
182
- r.set(o, 0), a.set(o, []);
183
- for (const o of e)
184
- for (const i of ((d = t[o]) == null ? void 0 : d.depends_on) ?? [])
185
- t[i] && ((c = a.get(i)) == null || c.push(o), r.set(o, (r.get(o) ?? 0) + 1));
186
- const p = e.filter((o) => (r.get(o) ?? 0) === 0), m = /* @__PURE__ */ new Set();
187
- for (; p.length > 0; ) {
188
- const o = p.shift();
189
- if (o !== void 0) {
190
- m.add(o);
191
- for (const i of a.get(o) ?? []) {
192
- const u = (r.get(i) ?? 1) - 1;
193
- r.set(i, u), u === 0 && p.push(i);
194
- }
195
- }
196
- }
197
- return m.size !== e.length ? e.filter((o) => !m.has(o)).map((o) => ({ slug: o })) : null;
159
+ function d(e) {
160
+ let t = Object.keys(e), n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map();
161
+ for (let e of t) n.set(e, 0), r.set(e, []);
162
+ for (let i of t) for (let t of e[i]?.depends_on ?? []) e[t] && (r.get(t)?.push(i), n.set(i, (n.get(i) ?? 0) + 1));
163
+ let i = t.filter((e) => (n.get(e) ?? 0) === 0), a = /* @__PURE__ */ new Set();
164
+ for (; i.length > 0;) {
165
+ let e = i.shift();
166
+ if (e !== void 0) {
167
+ a.add(e);
168
+ for (let t of r.get(e) ?? []) {
169
+ let e = (n.get(t) ?? 1) - 1;
170
+ n.set(t, e), e === 0 && i.push(t);
171
+ }
172
+ }
173
+ }
174
+ return a.size === t.length ? null : t.filter((e) => !a.has(e)).map((e) => ({ slug: e }));
198
175
  }
199
- function R(t, e) {
200
- for (const r of t) {
201
- if (!h(r))
202
- continue;
203
- const a = l(r.id) ? r.id : "?", p = r.provider;
204
- (!l(p) || !q.has(p)) && e.push(n(`dispatch_log[${a}].provider`, "invalid provider", p));
205
- const m = r.turns;
206
- if (!Array.isArray(m)) {
207
- e.push(
208
- n(`dispatch_log[${a}].turns`, "must be an array", m)
209
- );
210
- continue;
211
- }
212
- for (let d = 0; d < m.length; d++) {
213
- const c = m[d], o = `dispatch_log[${a}].turns[${d}]`;
214
- if (!h(c)) {
215
- e.push(n(o, "must be an object", c));
216
- continue;
217
- }
218
- (typeof c.turn != "number" || !Number.isInteger(c.turn) || c.turn < 1) && e.push(n(`${o}.turn`, "must be a positive integer", c.turn)), typeof c.input_tokens != "number" && e.push(
219
- n(`${o}.input_tokens`, "must be a number", c.input_tokens)
220
- ), typeof c.output_tokens != "number" && e.push(
221
- n(`${o}.output_tokens`, "must be a number", c.output_tokens)
222
- ), l(c.t) || e.push(n(`${o}.t`, "must be a string", c.t));
223
- const i = c.model_calls;
224
- i != null && typeof i != "number" && e.push(
225
- n(
226
- `${o}.model_calls`,
227
- "must be a number or null if present",
228
- i
229
- )
230
- );
231
- }
232
- }
176
+ function f(e, t) {
177
+ for (let n of e) {
178
+ if (!c(n)) continue;
179
+ let e = l(n.id) ? n.id : "?", r = n.provider;
180
+ (!l(r) || !o.has(r)) && t.push(u(`dispatch_log[${e}].provider`, "invalid provider", r));
181
+ let i = n.turns;
182
+ if (!Array.isArray(i)) {
183
+ t.push(u(`dispatch_log[${e}].turns`, "must be an array", i));
184
+ continue;
185
+ }
186
+ for (let n = 0; n < i.length; n++) {
187
+ let r = i[n], a = `dispatch_log[${e}].turns[${n}]`;
188
+ if (!c(r)) {
189
+ t.push(u(a, "must be an object", r));
190
+ continue;
191
+ }
192
+ (typeof r.turn != "number" || !Number.isInteger(r.turn) || r.turn < 1) && t.push(u(`${a}.turn`, "must be a positive integer", r.turn)), typeof r.input_tokens != "number" && t.push(u(`${a}.input_tokens`, "must be a number", r.input_tokens)), typeof r.output_tokens != "number" && t.push(u(`${a}.output_tokens`, "must be a number", r.output_tokens)), l(r.t) || t.push(u(`${a}.t`, "must be a string", r.t));
193
+ let o = r.model_calls;
194
+ o != null && typeof o != "number" && t.push(u(`${a}.model_calls`, "must be a number or null if present", o));
195
+ }
196
+ }
233
197
  }
234
- function L(t) {
235
- const e = [];
236
- if (!h(t))
237
- return { valid: !1, errors: [n("", "root must be an object")] };
238
- for (const m of ["description", "problem", "approach", "executor"]) {
239
- const d = t[m];
240
- (!l(d) || d.trim() === "") && e.push(n(m, "required string field missing/empty", d));
241
- }
242
- typeof t.schema_version != "number" && e.push(
243
- n("schema_version", "must be a number", t.schema_version)
244
- );
245
- const r = t.plan_kind;
246
- r !== "brownfield" && r !== "greenfield" && e.push(n("plan_kind", 'must be "brownfield" or "greenfield"', r)), Array.isArray(t.phases) ? t.phases.length === 0 && e.push(n("phases", "must have at least one entry")) : e.push(n("phases", "must be an array", t.phases));
247
- const a = t.terminal;
248
- !l(a) && !Array.isArray(a) && e.push(n("terminal", "must be a string or array", a)), Array.isArray(t.dispatch_log) ? R(t.dispatch_log, e) : e.push(n("dispatch_log", "must be an array", t.dispatch_log)), h(t.optimization) || e.push(n("optimization", "must be an object", t.optimization)), h(t.providers) || e.push(n("providers", "must be an object", t.providers)), h(t.effort_max_tokens) || e.push(
249
- n("effort_max_tokens", "must be an object", t.effort_max_tokens)
250
- );
251
- const p = t.milestones;
252
- if (!h(p))
253
- e.push(n("milestones", "must be an object", p));
254
- else {
255
- const m = Object.keys(p);
256
- m.length === 0 && e.push(n("milestones", "must have at least one entry"));
257
- const d = new Set(m);
258
- for (const u of m) {
259
- const s = p[u];
260
- if (!h(s)) {
261
- e.push(n(`milestones.${u}`, "must be an object", s));
262
- continue;
263
- }
264
- if ((!l(s.description) || s.description.trim() === "") && e.push(
265
- n(
266
- `milestones.${u}.description`,
267
- "required string",
268
- s.description
269
- )
270
- ), !Array.isArray(s.depends_on))
271
- e.push(
272
- n(
273
- `milestones.${u}.depends_on`,
274
- "must be an array",
275
- s.depends_on
276
- )
277
- );
278
- else
279
- for (const _ of s.depends_on)
280
- l(_) ? d.has(_) || e.push(
281
- n(`milestones.${u}.depends_on`, `unknown milestone "${_}"`)
282
- ) : e.push(
283
- n(`milestones.${u}.depends_on[]`, "must be a string", _)
284
- );
285
- const b = s.phase;
286
- (!l(b) || b.trim() === "") && e.push(n(`milestones.${u}.phase`, "required string", b)), (!l(s.authored_by) || s.authored_by.trim() === "") && e.push(
287
- n(
288
- `milestones.${u}.authored_by`,
289
- "required string",
290
- s.authored_by
291
- )
292
- );
293
- const f = s.model;
294
- f != null && !["Haiku", "Sonnet", "Opus"].includes(f) && e.push(
295
- n(`milestones.${u}.model`, "invalid model tier", f)
296
- );
297
- const y = s.effort;
298
- y != null && !["low", "medium", "high", "xhigh", "max"].includes(y) && e.push(
299
- n(`milestones.${u}.effort`, "invalid effort tier", y)
300
- ), s.two_stage !== void 0 && typeof s.two_stage != "boolean" && e.push(
301
- n(
302
- `milestones.${u}.two_stage`,
303
- "must be a boolean",
304
- s.two_stage
305
- )
306
- ), Array.isArray(s.read_only) || e.push(
307
- n(
308
- `milestones.${u}.read_only`,
309
- "must be an array",
310
- s.read_only
311
- )
312
- );
313
- }
314
- const c = T(
315
- p
316
- );
317
- if (c)
318
- for (const { slug: u } of c)
319
- e.push(n(`milestones.${u}`, "dependency cycle detected"));
320
- if (l(a) && !d.has(a))
321
- e.push(n("terminal", `unknown milestone "${a}"`));
322
- else if (Array.isArray(a))
323
- for (const u of a)
324
- d.has(u) || e.push(n("terminal[]", `unknown milestone "${u}"`));
325
- const o = t.operations, i = /* @__PURE__ */ new Set();
326
- if (!Array.isArray(o) && !h(o))
327
- e.push(n("operations", "must be an array or object", o));
328
- else {
329
- const u = Array.isArray(o) ? o : Object.values(o);
330
- for (const s of u) {
331
- if (!h(s)) {
332
- e.push(n("operations[]", "must be an object", s));
333
- continue;
334
- }
335
- const b = s.id;
336
- if (!l(b)) {
337
- e.push(n("operations[?]", "missing/invalid id", b));
338
- continue;
339
- }
340
- const f = b;
341
- i.add(f);
342
- const y = s.milestone;
343
- l(y) ? d.has(y) || e.push(
344
- n(`operations[${f}].milestone`, `unknown milestone "${y}"`)
345
- ) : e.push(
346
- n(`operations[${f}].milestone`, "required string", y)
347
- );
348
- const _ = s.type;
349
- l(_) && !D.has(_) && e.push(n(`operations[${f}].type`, "invalid type", _));
350
- const v = s.shape;
351
- if (h(v)) {
352
- const g = v.kind;
353
- g != null && l(g) && !E.has(g) && e.push(
354
- n(`operations[${f}].shape.kind`, "invalid shape kind", g)
355
- );
356
- const $ = v.ops;
357
- if (Array.isArray($) && l(g))
358
- for (let w = 0; w < $.length; w++) {
359
- const A = $[w];
360
- if (!h(A))
361
- continue;
362
- const k = A.op;
363
- l(k) && !j(g, k) && e.push(
364
- n(
365
- `operations[${f}].shape.ops[${w}]`,
366
- `op "${k}" not valid for kind "${g}"`
367
- )
368
- );
369
- }
370
- }
371
- Array.isArray(s.depends_on) || e.push(
372
- n(
373
- `operations[${f}].depends_on`,
374
- "must be an array",
375
- s.depends_on
376
- )
377
- );
378
- }
379
- for (const s of u) {
380
- if (!h(s))
381
- continue;
382
- const b = s.id;
383
- if (!l(b))
384
- continue;
385
- const f = s.depends_on;
386
- if (Array.isArray(f))
387
- for (const y of f)
388
- l(y) && !i.has(y) && e.push(
389
- n(
390
- `operations[${b}].depends_on`,
391
- `unknown operation "${y}"`
392
- )
393
- );
394
- }
395
- }
396
- }
397
- return { valid: e.length === 0, errors: e };
198
+ function p(e) {
199
+ let t = [];
200
+ if (!c(e)) return {
201
+ valid: !1,
202
+ errors: [u("", "root must be an object")]
203
+ };
204
+ for (let n of [
205
+ "description",
206
+ "problem",
207
+ "approach",
208
+ "executor"
209
+ ]) {
210
+ let r = e[n];
211
+ (!l(r) || r.trim() === "") && t.push(u(n, "required string field missing/empty", r));
212
+ }
213
+ typeof e.schema_version != "number" && t.push(u("schema_version", "must be a number", e.schema_version));
214
+ let r = e.plan_kind;
215
+ r !== "brownfield" && r !== "greenfield" && t.push(u("plan_kind", "must be \"brownfield\" or \"greenfield\"", r)), Array.isArray(e.phases) ? e.phases.length === 0 && t.push(u("phases", "must have at least one entry")) : t.push(u("phases", "must be an array", e.phases));
216
+ let i = e.terminal;
217
+ !l(i) && !Array.isArray(i) && t.push(u("terminal", "must be a string or array", i)), Array.isArray(e.dispatch_log) ? f(e.dispatch_log, t) : t.push(u("dispatch_log", "must be an array", e.dispatch_log)), c(e.optimization) || t.push(u("optimization", "must be an object", e.optimization)), c(e.providers) || t.push(u("providers", "must be an object", e.providers)), c(e.effort_max_tokens) || t.push(u("effort_max_tokens", "must be an object", e.effort_max_tokens));
218
+ let o = e.milestones;
219
+ if (!c(o)) t.push(u("milestones", "must be an object", o));
220
+ else {
221
+ let r = Object.keys(o);
222
+ r.length === 0 && t.push(u("milestones", "must have at least one entry"));
223
+ let f = new Set(r);
224
+ for (let e of r) {
225
+ let n = o[e];
226
+ if (!c(n)) {
227
+ t.push(u(`milestones.${e}`, "must be an object", n));
228
+ continue;
229
+ }
230
+ if ((!l(n.description) || n.description.trim() === "") && t.push(u(`milestones.${e}.description`, "required string", n.description)), !Array.isArray(n.depends_on)) t.push(u(`milestones.${e}.depends_on`, "must be an array", n.depends_on));
231
+ else for (let r of n.depends_on) l(r) ? f.has(r) || t.push(u(`milestones.${e}.depends_on`, `unknown milestone "${r}"`)) : t.push(u(`milestones.${e}.depends_on[]`, "must be a string", r));
232
+ let r = n.phase;
233
+ (!l(r) || r.trim() === "") && t.push(u(`milestones.${e}.phase`, "required string", r)), (!l(n.authored_by) || n.authored_by.trim() === "") && t.push(u(`milestones.${e}.authored_by`, "required string", n.authored_by));
234
+ let i = n.model;
235
+ i != null && ![
236
+ "Haiku",
237
+ "Sonnet",
238
+ "Opus"
239
+ ].includes(i) && t.push(u(`milestones.${e}.model`, "invalid model tier", i));
240
+ let a = n.effort;
241
+ a != null && ![
242
+ "low",
243
+ "medium",
244
+ "high",
245
+ "xhigh",
246
+ "max"
247
+ ].includes(a) && t.push(u(`milestones.${e}.effort`, "invalid effort tier", a)), n.two_stage !== void 0 && typeof n.two_stage != "boolean" && t.push(u(`milestones.${e}.two_stage`, "must be a boolean", n.two_stage)), Array.isArray(n.read_only) || t.push(u(`milestones.${e}.read_only`, "must be an array", n.read_only));
248
+ }
249
+ let p = d(o);
250
+ if (p) for (let { slug: e } of p) t.push(u(`milestones.${e}`, "dependency cycle detected"));
251
+ if (l(i) && !f.has(i)) t.push(u("terminal", `unknown milestone "${i}"`));
252
+ else if (Array.isArray(i)) for (let e of i) f.has(e) || t.push(u("terminal[]", `unknown milestone "${e}"`));
253
+ let m = e.operations, h = /* @__PURE__ */ new Set();
254
+ if (!Array.isArray(m) && !c(m)) t.push(u("operations", "must be an array or object", m));
255
+ else {
256
+ let e = Array.isArray(m) ? m : Object.values(m);
257
+ for (let r of e) {
258
+ if (!c(r)) {
259
+ t.push(u("operations[]", "must be an object", r));
260
+ continue;
261
+ }
262
+ let e = r.id;
263
+ if (!l(e)) {
264
+ t.push(u("operations[?]", "missing/invalid id", e));
265
+ continue;
266
+ }
267
+ let i = e;
268
+ h.add(i);
269
+ let o = r.milestone;
270
+ l(o) ? f.has(o) || t.push(u(`operations[${i}].milestone`, `unknown milestone "${o}"`)) : t.push(u(`operations[${i}].milestone`, "required string", o));
271
+ let d = r.type;
272
+ l(d) && !a.has(d) && t.push(u(`operations[${i}].type`, "invalid type", d));
273
+ let p = r.shape;
274
+ if (c(p)) {
275
+ let e = p.kind;
276
+ e != null && l(e) && !s.has(e) && t.push(u(`operations[${i}].shape.kind`, "invalid shape kind", e));
277
+ let r = p.ops;
278
+ if (Array.isArray(r) && l(e)) for (let a = 0; a < r.length; a++) {
279
+ let o = r[a];
280
+ if (!c(o)) continue;
281
+ let s = o.op;
282
+ l(s) && !n(e, s) && t.push(u(`operations[${i}].shape.ops[${a}]`, `op "${s}" not valid for kind "${e}"`));
283
+ }
284
+ }
285
+ Array.isArray(r.depends_on) || t.push(u(`operations[${i}].depends_on`, "must be an array", r.depends_on));
286
+ }
287
+ for (let n of e) {
288
+ if (!c(n)) continue;
289
+ let e = n.id;
290
+ if (!l(e)) continue;
291
+ let r = n.depends_on;
292
+ if (Array.isArray(r)) for (let n of r) l(n) && !h.has(n) && t.push(u(`operations[${e}].depends_on`, `unknown operation "${n}"`));
293
+ }
294
+ }
295
+ }
296
+ return {
297
+ valid: t.length === 0,
298
+ errors: t
299
+ };
398
300
  }
399
- function N(t) {
400
- const e = [];
401
- if (!h(t))
402
- return { valid: !1, errors: [n("", "root must be an object")] };
403
- for (const a of ["snapshot_at", "description"])
404
- l(t[a]) || e.push(n(a, "required string field missing", t[a]));
405
- l(t.plan) || e.push(n("plan", "required string", t.plan));
406
- const r = t.milestones;
407
- if (!h(r))
408
- e.push(n("milestones", "must be an object", r));
409
- else {
410
- const a = Object.keys(r), p = new Set(a);
411
- for (const o of a) {
412
- const i = r[o];
413
- if (!h(i)) {
414
- e.push(n(`milestones.${o}`, "must be an object", i));
415
- continue;
416
- }
417
- const u = i.eligible, s = i.pending;
418
- u === !0 && s !== null && s !== void 0 && e.push(
419
- n(
420
- `milestones.${o}`,
421
- "D-07 violation: eligible=true but pending not null"
422
- )
423
- ), typeof u != "boolean" && e.push(
424
- n(`milestones.${o}.eligible`, "must be boolean", u)
425
- );
426
- const b = i.status;
427
- (!l(b) || !O.has(b)) && e.push(n(`milestones.${o}.status`, "invalid status", b)), u === !0 && b === "complete" && e.push(
428
- n(
429
- `milestones.${o}`,
430
- "D-07 violation: eligible=true but status is complete"
431
- )
432
- );
433
- const f = i.wave;
434
- (typeof f != "number" || !Number.isInteger(f) || f < 0) && e.push(
435
- n(`milestones.${o}.wave`, "must be non-negative integer", f)
436
- );
437
- const y = i.ki_estimate;
438
- y != null && typeof y != "number" && e.push(
439
- n(`milestones.${o}.ki_estimate`, "must be number|null", y)
440
- );
441
- for (const _ of ["tokens_estimated", "tokens_actual"]) {
442
- const v = i[_];
443
- v != null && typeof v != "number" && e.push(n(`milestones.${o}.${_}`, "must be number|null", v));
444
- }
445
- Array.isArray(i.artifacts) || e.push(
446
- n(
447
- `milestones.${o}.artifacts`,
448
- "must be an array",
449
- i.artifacts
450
- )
451
- ), typeof i.si_bytes != "number" && e.push(
452
- n(`milestones.${o}.si_bytes`, "must be a number", i.si_bytes)
453
- );
454
- }
455
- const m = t.operations;
456
- if (!Array.isArray(m))
457
- e.push(n("operations", "must be an array", m));
458
- else
459
- for (const o of m) {
460
- if (!h(o))
461
- continue;
462
- const i = l(o.id) ? o.id : "?", u = o.milestone;
463
- l(u) && !p.has(u) && e.push(
464
- n(
465
- `operations[${i}].milestone`,
466
- `unknown milestone "${u}"`
467
- )
468
- );
469
- const s = o.status;
470
- (!l(s) || !I.has(s)) && e.push(
471
- n(
472
- `operations[${i}].status`,
473
- "invalid operation status",
474
- s
475
- )
476
- ), Array.isArray(o.dispatch_ids) || e.push(
477
- n(
478
- `operations[${i}].dispatch_ids`,
479
- "must be an array",
480
- o.dispatch_ids
481
- )
482
- ), typeof o.attempt_count != "number" && e.push(
483
- n(
484
- `operations[${i}].attempt_count`,
485
- "must be a number",
486
- o.attempt_count
487
- )
488
- ), Array.isArray(o.blast_radius) || e.push(
489
- n(
490
- `operations[${i}].blast_radius`,
491
- "must be an array",
492
- o.blast_radius
493
- )
494
- );
495
- }
496
- const d = t.open_questions;
497
- if (!Array.isArray(d))
498
- e.push(n("open_questions", "must be an array", d));
499
- else
500
- for (const o of d) {
501
- if (!h(o))
502
- continue;
503
- const i = o.blocking;
504
- (!l(i) || !p.has(i)) && e.push(
505
- n("open_questions", `unknown blocking milestone "${i}"`)
506
- ), typeof o.surfaced != "boolean" && e.push(
507
- n(
508
- `open_questions[${o.id}]`,
509
- "surfaced must be boolean",
510
- o.surfaced
511
- )
512
- ), typeof o.answered != "boolean" && e.push(
513
- n(
514
- `open_questions[${o.id}]`,
515
- "answered must be boolean",
516
- o.answered
517
- )
518
- );
519
- }
520
- const c = t.dispatch_units;
521
- if (c !== void 0)
522
- if (!Array.isArray(c))
523
- e.push(
524
- n("dispatch_units", "must be an array if present", c)
525
- );
526
- else
527
- for (const o of c) {
528
- if (!h(o))
529
- continue;
530
- const i = o.fits_context_window;
531
- typeof i != "boolean" && e.push(
532
- n(
533
- `dispatch_units[${o.id}]`,
534
- "fits_context_window must be boolean",
535
- i
536
- )
537
- );
538
- const u = o.milestones;
539
- if (Array.isArray(u))
540
- for (const s of u)
541
- l(s) && !p.has(s) && e.push(
542
- n(
543
- `dispatch_units[${o.id}].milestones`,
544
- `unknown milestone "${s}"`
545
- )
546
- );
547
- }
548
- h(t.pairwise_overlap) || e.push(
549
- n(
550
- "pairwise_overlap",
551
- "must be an object",
552
- t.pairwise_overlap
553
- )
554
- );
555
- }
556
- return { valid: e.length === 0, errors: e };
301
+ function m(e) {
302
+ let t = [];
303
+ if (!c(e)) return {
304
+ valid: !1,
305
+ errors: [u("", "root must be an object")]
306
+ };
307
+ for (let n of ["snapshot_at", "description"]) l(e[n]) || t.push(u(n, "required string field missing", e[n]));
308
+ l(e.plan) || t.push(u("plan", "required string", e.plan));
309
+ let n = e.milestones;
310
+ if (!c(n)) t.push(u("milestones", "must be an object", n));
311
+ else {
312
+ let a = Object.keys(n), o = new Set(a);
313
+ for (let e of a) {
314
+ let i = n[e];
315
+ if (!c(i)) {
316
+ t.push(u(`milestones.${e}`, "must be an object", i));
317
+ continue;
318
+ }
319
+ let a = i.eligible, o = i.pending;
320
+ a === !0 && o != null && t.push(u(`milestones.${e}`, "D-07 violation: eligible=true but pending not null")), typeof a != "boolean" && t.push(u(`milestones.${e}.eligible`, "must be boolean", a));
321
+ let s = i.status;
322
+ (!l(s) || !r.has(s)) && t.push(u(`milestones.${e}.status`, "invalid status", s)), a === !0 && s === "complete" && t.push(u(`milestones.${e}`, "D-07 violation: eligible=true but status is complete"));
323
+ let d = i.wave;
324
+ (typeof d != "number" || !Number.isInteger(d) || d < 0) && t.push(u(`milestones.${e}.wave`, "must be non-negative integer", d));
325
+ let f = i.ki_estimate;
326
+ f != null && typeof f != "number" && t.push(u(`milestones.${e}.ki_estimate`, "must be number|null", f));
327
+ for (let n of ["tokens_estimated", "tokens_actual"]) {
328
+ let r = i[n];
329
+ r != null && typeof r != "number" && t.push(u(`milestones.${e}.${n}`, "must be number|null", r));
330
+ }
331
+ Array.isArray(i.artifacts) || t.push(u(`milestones.${e}.artifacts`, "must be an array", i.artifacts)), typeof i.si_bytes != "number" && t.push(u(`milestones.${e}.si_bytes`, "must be a number", i.si_bytes));
332
+ }
333
+ let s = e.operations;
334
+ if (!Array.isArray(s)) t.push(u("operations", "must be an array", s));
335
+ else for (let e of s) {
336
+ if (!c(e)) continue;
337
+ let n = l(e.id) ? e.id : "?", r = e.milestone;
338
+ l(r) && !o.has(r) && t.push(u(`operations[${n}].milestone`, `unknown milestone "${r}"`));
339
+ let a = e.status;
340
+ (!l(a) || !i.has(a)) && t.push(u(`operations[${n}].status`, "invalid operation status", a)), Array.isArray(e.dispatch_ids) || t.push(u(`operations[${n}].dispatch_ids`, "must be an array", e.dispatch_ids)), typeof e.attempt_count != "number" && t.push(u(`operations[${n}].attempt_count`, "must be a number", e.attempt_count)), Array.isArray(e.blast_radius) || t.push(u(`operations[${n}].blast_radius`, "must be an array", e.blast_radius));
341
+ }
342
+ let d = e.open_questions;
343
+ if (!Array.isArray(d)) t.push(u("open_questions", "must be an array", d));
344
+ else for (let e of d) {
345
+ if (!c(e)) continue;
346
+ let n = e.blocking;
347
+ (!l(n) || !o.has(n)) && t.push(u("open_questions", `unknown blocking milestone "${n}"`)), typeof e.surfaced != "boolean" && t.push(u(`open_questions[${e.id}]`, "surfaced must be boolean", e.surfaced)), typeof e.answered != "boolean" && t.push(u(`open_questions[${e.id}]`, "answered must be boolean", e.answered));
348
+ }
349
+ let f = e.dispatch_units;
350
+ if (f !== void 0) {
351
+ if (!Array.isArray(f)) t.push(u("dispatch_units", "must be an array if present", f));
352
+ else for (let e of f) {
353
+ if (!c(e)) continue;
354
+ let n = e.fits_context_window;
355
+ typeof n != "boolean" && t.push(u(`dispatch_units[${e.id}]`, "fits_context_window must be boolean", n));
356
+ let r = e.milestones;
357
+ if (Array.isArray(r)) for (let n of r) l(n) && !o.has(n) && t.push(u(`dispatch_units[${e.id}].milestones`, `unknown milestone "${n}"`));
358
+ }
359
+ }
360
+ c(e.pairwise_overlap) || t.push(u("pairwise_overlap", "must be an object", e.pairwise_overlap));
361
+ }
362
+ return {
363
+ valid: t.length === 0,
364
+ errors: t
365
+ };
557
366
  }
558
- function P(t) {
559
- const e = L(t);
560
- if (!e.valid)
561
- throw new Error(
562
- `DagJson validation failed:
563
- ${e.errors.map((r) => ` ${r.path}: ${r.message}`).join(`
564
- `)}`
565
- );
367
+ function h(e) {
368
+ let t = p(e);
369
+ if (!t.valid) throw Error(`DagJson validation failed:\n${t.errors.map((e) => ` ${e.path}: ${e.message}`).join("\n")}`);
566
370
  }
567
- function H(t) {
568
- const e = N(t);
569
- if (!e.valid)
570
- throw new Error(
571
- `Snapshot validation failed:
572
- ${e.errors.map((r) => ` ${r.path}: ${r.message}`).join(`
573
- `)}`
574
- );
371
+ function g(e) {
372
+ let t = m(e);
373
+ if (!t.valid) throw Error(`Snapshot validation failed:\n${t.errors.map((e) => ` ${e.path}: ${e.message}`).join("\n")}`);
575
374
  }
576
- const S = [
577
- {
578
- from: 2,
579
- to: 3,
580
- apply: (t) => {
581
- !t.milestones && t.nodes && (t.milestones = t.nodes, delete t.nodes);
582
- const e = t.operations;
583
- e && typeof e == "object" && !Array.isArray(e) && (t.operations = Object.values(e));
584
- }
585
- },
586
- {
587
- from: 3,
588
- to: 4,
589
- apply: (t) => {
590
- (!t.providers || Object.keys(t.providers).length === 0) && (t.providers = {
591
- Haiku: {
592
- type: "claudecli",
593
- model_id: "claude-haiku-4-5",
594
- env_secret: null,
595
- base_url: null,
596
- timeout_ms: 6e4,
597
- retry_config: {
598
- retries: 3,
599
- min_timeout: 1e3,
600
- max_timeout: 3e4,
601
- factor: 2
602
- }
603
- },
604
- Sonnet: {
605
- type: "claudecli",
606
- model_id: "claude-sonnet-4-5",
607
- env_secret: null,
608
- base_url: null,
609
- timeout_ms: 12e4,
610
- retry_config: {
611
- retries: 3,
612
- min_timeout: 1e3,
613
- max_timeout: 3e4,
614
- factor: 2
615
- }
616
- },
617
- Opus: {
618
- type: "claudecli",
619
- model_id: "claude-opus-4-5",
620
- env_secret: null,
621
- base_url: null,
622
- timeout_ms: 3e5,
623
- retry_config: {
624
- retries: 3,
625
- min_timeout: 1e3,
626
- max_timeout: 3e4,
627
- factor: 2
628
- }
629
- }
630
- }), (!t.effort_max_tokens || Object.keys(t.effort_max_tokens).length === 0) && (t.effort_max_tokens = {
631
- low: 1024,
632
- medium: 4096,
633
- high: 8192,
634
- xhigh: 16384,
635
- max: 32768
636
- }), t.optimization || (t.optimization = {
637
- sentinel_fanout: {
638
- enabled: !0,
639
- write_multiplier: 1.25,
640
- read_multiplier: 0.1,
641
- hit_probability: 0.9
642
- },
643
- b_per_tier: { Haiku: 8e3, Sonnet: 15e3, Opus: 27e3 },
644
- context_window_per_tier: { Haiku: 16e3, Sonnet: 16e3, Opus: 32e3 },
645
- context_window_override: null,
646
- b_override: null
647
- });
648
- let e = [];
649
- Array.isArray(t.operations) ? e = t.operations : t.operations && typeof t.operations == "object" && (e = Object.values(t.operations));
650
- for (const r of e)
651
- if (typeof r == "object" && r !== null) {
652
- const a = r;
653
- a.type === void 0 && (a.type = "generative"), a.criteria === void 0 && (a.criteria = []), a.tool === void 0 && (a.tool = null), a.args === void 0 && (a.args = null);
654
- }
655
- }
656
- }
657
- ];
658
- function K(t, e, r) {
659
- if (t === e)
660
- return;
661
- let a = t;
662
- for (const p of [...S].sort((m, d) => m.from - d.from))
663
- if (p.from === a && (p.apply(r), a = p.to, a === e)) {
664
- r.schema_version = e;
665
- return;
666
- }
667
- throw new Error(
668
- `migrateDag: no path from v${t} to v${e}. Available: [${S.map(
669
- (p) => `v${p.from}→v${p.to}`
670
- ).join(", ")}]`
671
- );
375
+ //#endregion
376
+ //#region src/lib/migrate.ts
377
+ var _ = [{
378
+ from: 2,
379
+ to: 3,
380
+ apply: (e) => {
381
+ !e.milestones && e.nodes && (e.milestones = e.nodes, delete e.nodes);
382
+ let t = e.operations;
383
+ t && typeof t == "object" && !Array.isArray(t) && (e.operations = Object.values(t));
384
+ }
385
+ }, {
386
+ from: 3,
387
+ to: 4,
388
+ apply: (e) => {
389
+ (!e.providers || Object.keys(e.providers).length === 0) && (e.providers = {
390
+ Haiku: {
391
+ type: "claudecli",
392
+ model_id: "claude-haiku-4-5",
393
+ env_secret: null,
394
+ base_url: null,
395
+ timeout_ms: 6e4,
396
+ retry_config: {
397
+ retries: 3,
398
+ min_timeout: 1e3,
399
+ max_timeout: 3e4,
400
+ factor: 2
401
+ }
402
+ },
403
+ Sonnet: {
404
+ type: "claudecli",
405
+ model_id: "claude-sonnet-4-5",
406
+ env_secret: null,
407
+ base_url: null,
408
+ timeout_ms: 12e4,
409
+ retry_config: {
410
+ retries: 3,
411
+ min_timeout: 1e3,
412
+ max_timeout: 3e4,
413
+ factor: 2
414
+ }
415
+ },
416
+ Opus: {
417
+ type: "claudecli",
418
+ model_id: "claude-opus-4-5",
419
+ env_secret: null,
420
+ base_url: null,
421
+ timeout_ms: 3e5,
422
+ retry_config: {
423
+ retries: 3,
424
+ min_timeout: 1e3,
425
+ max_timeout: 3e4,
426
+ factor: 2
427
+ }
428
+ }
429
+ }), (!e.effort_max_tokens || Object.keys(e.effort_max_tokens).length === 0) && (e.effort_max_tokens = {
430
+ low: 1024,
431
+ medium: 4096,
432
+ high: 8192,
433
+ xhigh: 16384,
434
+ max: 32768
435
+ }), e.optimization ||= {
436
+ sentinel_fanout: {
437
+ enabled: !0,
438
+ write_multiplier: 1.25,
439
+ read_multiplier: .1,
440
+ hit_probability: .9
441
+ },
442
+ b_per_tier: {
443
+ Haiku: 8e3,
444
+ Sonnet: 15e3,
445
+ Opus: 27e3
446
+ },
447
+ context_window_per_tier: {
448
+ Haiku: 16e3,
449
+ Sonnet: 16e3,
450
+ Opus: 32e3
451
+ },
452
+ context_window_override: null,
453
+ b_override: null
454
+ };
455
+ let t = [];
456
+ Array.isArray(e.operations) ? t = e.operations : e.operations && typeof e.operations == "object" && (t = Object.values(e.operations));
457
+ for (let e of t) if (typeof e == "object" && e) {
458
+ let t = e;
459
+ t.type === void 0 && (t.type = "generative"), t.criteria === void 0 && (t.criteria = []), t.tool === void 0 && (t.tool = null), t.args === void 0 && (t.args = null);
460
+ }
461
+ }
462
+ }];
463
+ function v(e, t, n) {
464
+ if (e === t) return;
465
+ let r = e;
466
+ for (let e of [..._].sort((e, t) => e.from - t.from)) if (e.from === r && (e.apply(n), r = e.to, r === t)) {
467
+ n.schema_version = t;
468
+ return;
469
+ }
470
+ throw Error(`migrateDag: no path from v${e} to v${t}. Available: [${_.map((e) => `v${e.from}→v${e.to}`).join(", ")}]`);
672
471
  }
673
- export {
674
- x as VALID_OPS_BY_KIND,
675
- z as WRITE_CLASS_ACTIONS,
676
- P as assertValidDagJson,
677
- H as assertValidSnapshot,
678
- j as isValidOpForKind,
679
- K as migrateDag,
680
- L as validateDagJson,
681
- N as validateSnapshot
682
- };
472
+ //#endregion
473
+ export { t as VALID_OPS_BY_KIND, e as WRITE_CLASS_ACTIONS, h as assertValidDagJson, g as assertValidSnapshot, n as isValidOpForKind, v as migrateDag, p as validateDagJson, m as validateSnapshot };