@moldea.ai/cli 13.0.4 → 14.0.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.
@@ -0,0 +1,3114 @@
1
+ import { d as e, f as t, m as n, n as r, u as i } from "./chunk-2cc3bf5c.mjs";
2
+ import { a, c as o, d as s, f as c, g as l, h as u, i as d, l as f, o as p, p as m, r as h, s as g, t as _, u as v } from "./chunk-8f198616.mjs";
3
+ import { a as y, c as b, i as x, l as S, n as C, s as w, u as T } from "./chunk-98d84174.mjs";
4
+ //#region ../../node_modules/.pnpm/jg-utilities@1.7.2/node_modules/jg-utilities/dist/utils/marked-region.js
5
+ var ee = "", E = (n) => {
6
+ throw new t(n, { code: e.INVALID_MARKED_REGION });
7
+ }, te = ({ start: e, end: t }) => {
8
+ for (let n of [e, t]) (typeof n != "string" || n === "" || /[\r\n]/.test(n)) && E("Each region marker must be a non-empty single line.");
9
+ (e.includes(t) || t.includes(e)) && E("Neither region marker may contain the other.");
10
+ }, ne = (e, t) => {
11
+ te(t);
12
+ let n, r, i = 0;
13
+ for (; i < e.length;) {
14
+ let a = e.indexOf("\n", i), o = a === -1 ? e.length : a + 1, s = a > i && e[a - 1] === "\r", c = a === -1 ? e.length : a - +!!s, l = i === 0 && e.startsWith(ee) ? 1 : i, u = e.slice(l, c);
15
+ for (let e of ["start", "end"]) u.includes(t[e]) && (u !== t[e] && E(`The ${e} marker must fill its whole line.`), e === "start" ? ((n !== void 0 || r !== void 0) && E("The document must hold one start marker, before one end marker."), n = {
16
+ offset: l,
17
+ lineEnding: s ? "\r\n" : "\n"
18
+ }) : (r !== void 0 && E("The document must hold one end marker."), r = o));
19
+ i = o;
20
+ }
21
+ return n === void 0 && r === void 0 ? null : n === void 0 || r === void 0 ? E("The document must hold both region markers, or neither.") : {
22
+ start: n.offset,
23
+ end: r,
24
+ lineEnding: n.lineEnding
25
+ };
26
+ }, re = /^[a-z0-9]+(?:-[a-z0-9]+)*$/u, ie = /^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])$/u, ae = [
27
+ "\n",
28
+ "\r",
29
+ "…",
30
+ "\u2028",
31
+ "\u2029"
32
+ ], oe = /[!?[\]{}]/u, se = (e) => ae.some((t) => e.includes(t)), D = (e) => e >= 9 && e <= 13 || e === 32 || e === 133 || e === 160 || e === 5760 || e >= 8192 && e <= 8202 || e === 8232 || e === 8233 || e === 8239 || e === 8287 || e === 12288, O = (e) => {
33
+ let t = e[Symbol.iterator](), n = 0;
34
+ for (; t.next().done !== !0;) n += 1;
35
+ return n;
36
+ }, k = (e) => {
37
+ for (let t of e) if (!D(t.codePointAt(0) ?? 0)) return !0;
38
+ return !1;
39
+ }, ce = (e) => {
40
+ let t = e.codePointAt(0), n = e.codePointAt(e.length - 1);
41
+ return t !== void 0 && D(t) || n !== void 0 && D(n);
42
+ }, le = (e) => {
43
+ let t = 0, n = e.length;
44
+ for (; t < n;) {
45
+ let n = e.codePointAt(t);
46
+ if (n === void 0 || !D(n)) break;
47
+ t += n > 65535 ? 2 : 1;
48
+ }
49
+ for (; n > t;) {
50
+ let t = e.codePointAt(n - 1);
51
+ if (t === void 0 || !D(t)) break;
52
+ --n;
53
+ }
54
+ return e.slice(t, n);
55
+ }, ue = (e) => e.length > 0 && !se(e), de = (e) => e.length <= 64 && re.test(e), fe = (e) => ie.test(e), pe = (e) => {
56
+ let t = O(e);
57
+ return t >= 1 && t <= 1e3 && !ce(e) && !se(e) && !e.includes("\0");
58
+ }, A = (e) => e !== "/" && b(e) ? S(e) : null, me = (e) => e === "/moldea/moldea.yaml", j = (e) => {
59
+ let t = /^\/moldea\/decisions\/(\d{13})-([a-z0-9]+(?:-[a-z0-9]+)*)\.md$/u.exec(e), n = t?.[1], r = t?.[2];
60
+ return n !== void 0 && r !== void 0 && de(r) ? n : null;
61
+ }, he = (e, t) => t && e === "/moldea/project.md" ? !0 : e.startsWith("/moldea/context/") && e.endsWith(".md"), ge = (e) => j(e) !== null, _e = (e) => e !== "/moldea" && !e.startsWith("/moldea/"), ve = (e) => oe.test(e), ye = (e) => ve(e) || e.includes("***") || e.slice(1).split("/").some((e) => e.includes("**") && e !== "**") ? !1 : e.includes("*") && b(e.replaceAll("*", "x")), be = (e) => ue(e) && !e.includes("\0"), xe = (e) => e === "/moldea" || e.startsWith("/moldea/"), Se = new TextEncoder(), Ce = new TextDecoder("utf-8", {
62
+ fatal: !0,
63
+ ignoreBOM: !0
64
+ }), we = (e, t, n) => {
65
+ let r = 1, i = 1, a = 0;
66
+ for (let o of e) o === "\0" && n.add({
67
+ code: "MOLDEA_TEXT_NUL_FORBIDDEN",
68
+ path: t,
69
+ range: {
70
+ end: {
71
+ column: r + 1,
72
+ line: i,
73
+ offset: a + 1
74
+ },
75
+ start: {
76
+ column: r,
77
+ line: i,
78
+ offset: a
79
+ }
80
+ }
81
+ }), o === "\n" ? (r = 1, i += 1) : r += 1, a += 1;
82
+ }, Te = (e) => {
83
+ throw new r({
84
+ code: "INVALID_ARGUMENT",
85
+ operation: e
86
+ });
87
+ }, Ee = (e, t, n, i) => {
88
+ if (!(e <= t[i])) throw new r({
89
+ code: "RESOURCE_LIMIT_EXCEEDED",
90
+ limit: i,
91
+ limitMaximum: t[i],
92
+ nextAction: "reduce-input-or-increase-limit",
93
+ observedUsage: e,
94
+ operation: n
95
+ });
96
+ }, De = (e) => m({
97
+ diagnostics: [...e],
98
+ text: null,
99
+ valid: !1
100
+ }), Oe = (e, t, n, r, a) => {
101
+ if (!i(e, !0)) return Te(n);
102
+ let o = e.path, s = e.content;
103
+ if (typeof o != "string" || typeof s != "string" && !(s instanceof Uint8Array)) return Te(n);
104
+ let c = S(o);
105
+ if (typeof s == "string") return Ee(l(s, t[r]), t, n, r), s.isWellFormed() ? {
106
+ path: c,
107
+ value: s
108
+ } : (a.add({
109
+ code: "MOLDEA_TEXT_INVALID_UNICODE",
110
+ path: c
111
+ }), De(a.finalize()));
112
+ Ee(s.byteLength, t, n, r);
113
+ let u = new Uint8Array(s);
114
+ try {
115
+ return {
116
+ path: c,
117
+ value: Ce.decode(u)
118
+ };
119
+ } catch {
120
+ return a.add({
121
+ code: "MOLDEA_TEXT_INVALID_UTF8",
122
+ path: c
123
+ }), De(a.finalize());
124
+ }
125
+ }, M = (e, t, n, r = "maxFileBytes") => {
126
+ let i = d(t, n), a = Oe(e, t, n, r, i);
127
+ if ("valid" in a) return a;
128
+ let o = (a.value.startsWith("") ? a.value.slice(1) : a.value).replace(/\r\n?/gu, "\n");
129
+ if (we(o, a.path, i), i.size > 0) return De(i.finalize());
130
+ let s = m({
131
+ scalarLength: O(o),
132
+ utf8ByteLength: l(o),
133
+ value: o
134
+ });
135
+ return m({
136
+ diagnostics: [],
137
+ text: s,
138
+ valid: !0
139
+ });
140
+ }, ke = (e) => {
141
+ let t = "";
142
+ for (let n of e) t += n.toString(16).padStart(2, "0");
143
+ return t;
144
+ }, N = async (e) => {
145
+ let t = Se.encode(e.value);
146
+ return `sha256:${ke(new Uint8Array(await globalThis.crypto.subtle.digest("SHA-256", t)))}`;
147
+ }, Ae = async (e, t) => {
148
+ let n = M(e, t, "calculate-content-digest");
149
+ if (!n.valid || n.text === null) return m({
150
+ diagnostics: n.diagnostics,
151
+ digest: null,
152
+ text: null,
153
+ valid: !1
154
+ });
155
+ let r = await N(n.text);
156
+ return m({
157
+ diagnostics: [],
158
+ digest: r,
159
+ text: n.text,
160
+ valid: !0
161
+ });
162
+ }, je = (e, t) => {
163
+ let n = 0, r = 0, i = -1, a = -1;
164
+ for (; r < t.length;) {
165
+ if (e[n] === t[r]) {
166
+ n += 1, r += 1;
167
+ continue;
168
+ }
169
+ if (e[n] === "*") {
170
+ i = n, a = r, n += 1;
171
+ continue;
172
+ }
173
+ if (i === -1) return !1;
174
+ n = i + 1, a += 1, r = a;
175
+ }
176
+ for (; e[n] === "*";) n += 1;
177
+ return n === e.length;
178
+ }, Me = (e, t) => {
179
+ let n = t.slice(1).split("/"), r = new Uint8Array(n.length + 1);
180
+ r[0] = 1;
181
+ for (let t of e) {
182
+ let e = new Uint8Array(n.length + 1);
183
+ if (t === "**") {
184
+ let t = !1;
185
+ for (let n = 0; n < r.length; n += 1) t ||= r[n] === 1, e[n] = +!!t;
186
+ } else for (let i = 0; i < n.length; i += 1) r[i] === 1 && je(t, n[i] ?? "") && (e[i + 1] = 1);
187
+ r = e;
188
+ }
189
+ return r[n.length] === 1;
190
+ }, P = (e, t) => `${e}/${g(t)}`, Ne = (e, t, n = null) => ({
191
+ agentId: n,
192
+ id: t,
193
+ kind: e
194
+ }), Pe = (e, t) => u(e.kind, t.kind) || u(e.agentId ?? "", t.agentId ?? "") || u(e.id, t.id), Fe = (e) => e.kind === "exact" ? e.path : e.pattern, Ie = (e, t) => Pe(e.owner, t.owner) || u(e.field, t.field) || u(Fe(e.declaration), Fe(t.declaration)) || u(e.pointer, t.pointer), F = (e, t, n, r, i) => {
195
+ e.push({
196
+ declaration: typeof i == "string" ? {
197
+ kind: "exact",
198
+ path: i,
199
+ symbol: null
200
+ } : {
201
+ kind: "exact",
202
+ path: i.path,
203
+ symbol: i.symbol ?? null
204
+ },
205
+ field: n,
206
+ owner: t,
207
+ pointer: r
208
+ });
209
+ }, Le = (e, t, n, r, i) => {
210
+ for (let [a, o] of (t ?? []).entries()) F(e, n, r, P(i, String(a)), o);
211
+ }, Re = (e, t, n, r) => {
212
+ for (let [i, a] of (t ?? []).entries()) e.push({
213
+ declaration: a.includes("*") ? {
214
+ kind: "glob",
215
+ pattern: a
216
+ } : {
217
+ kind: "exact",
218
+ path: a,
219
+ symbol: null
220
+ },
221
+ field: "affectedBy",
222
+ owner: n,
223
+ pointer: P(r, String(i))
224
+ });
225
+ }, ze = (e, t, n, r, i) => {
226
+ let a = Ne(n.kind, t, r);
227
+ if (F(e, a, "implementation", P(i, "implementation"), n.value.implementation), n.value.registration !== void 0 && F(e, a, "registration", P(i, "registration"), n.value.registration), n.kind === "tool") for (let t of ["inputSchema", "outputSchema"]) {
228
+ let r = n.value[t];
229
+ r !== void 0 && F(e, a, t, P(i, t), r);
230
+ }
231
+ Re(e, n.value.affectedBy, a, P(i, "affectedBy"));
232
+ }, Be = (e, t, n) => {
233
+ let r = P("/agents", t), i = Ne("agent", t, t), a = P(r, "bindings");
234
+ for (let t of [
235
+ "runtimeAgent",
236
+ "inputSchema",
237
+ "outputSchema",
238
+ "instructionLoader"
239
+ ]) {
240
+ let r = n.bindings?.[t];
241
+ r !== void 0 && F(e, i, t, P(a, t), r);
242
+ }
243
+ Re(e, n.affectedBy, i, P(r, "affectedBy"));
244
+ for (let i of Object.keys(n.tools ?? {}).sort(u)) {
245
+ let a = n.tools?.[i];
246
+ a !== void 0 && ze(e, i, {
247
+ kind: "tool",
248
+ value: a
249
+ }, t, P(P(r, "tools"), i));
250
+ }
251
+ for (let i of Object.keys(n.skills ?? {}).sort(u)) {
252
+ let a = n.skills?.[i];
253
+ a !== void 0 && ze(e, i, {
254
+ kind: "skill",
255
+ value: a
256
+ }, t, P(P(r, "skills"), i));
257
+ }
258
+ for (let [t, a] of (n.mirrors ?? []).entries()) F(e, i, "mirrors", P(P(r, "mirrors"), String(t)), a);
259
+ }, Ve = (e) => {
260
+ let t = [];
261
+ for (let n of ["context", "decision"]) {
262
+ let r = n === "context" ? e.context : e.decisions;
263
+ for (let e of Object.keys(r ?? {}).sort(u)) {
264
+ let i = r?.[e];
265
+ if (i === void 0) continue;
266
+ let a = Ne(n, e), o = P(n === "context" ? "/context" : "/decisions", e);
267
+ Le(t, i.bindings, a, "bindings", P(o, "bindings")), Re(t, i.affectedBy, a, P(o, "affectedBy"));
268
+ }
269
+ }
270
+ for (let n of Object.keys(e.agents ?? {}).sort(u)) {
271
+ let r = e.agents?.[n];
272
+ r !== void 0 && Be(t, n, r);
273
+ }
274
+ return t.sort(Ie);
275
+ }, He = (e, t) => {
276
+ let n = Ve(e);
277
+ if (n.length > t.maxEntries) throw new r({
278
+ code: "RESOURCE_LIMIT_EXCEEDED",
279
+ limit: "maxEntries",
280
+ limitMaximum: t.maxEntries,
281
+ nextAction: "reduce-input-or-increase-limit",
282
+ observedUsage: n.length,
283
+ operation: "match-manifest-scope"
284
+ });
285
+ let i = new Map(), a = [], o = new Map();
286
+ for (let e of n) {
287
+ if (e.declaration.kind === "exact") {
288
+ let t = i.get(e.declaration.path) ?? [];
289
+ t.push(e), i.set(e.declaration.path, t);
290
+ continue;
291
+ }
292
+ let t = e.declaration.pattern.slice(1).split("/"), n = {
293
+ declaration: e,
294
+ segments: t
295
+ }, r = t[0] ?? "";
296
+ if (r === "**" || r.includes("*")) a.push(n);
297
+ else {
298
+ let e = o.get(r) ?? [];
299
+ e.push(n), o.set(r, e);
300
+ }
301
+ }
302
+ return {
303
+ declarations: n,
304
+ exact: i,
305
+ globalGlobs: a,
306
+ globsByFirstSegment: o
307
+ };
308
+ }, Ue = (e, t) => Pe(e.owner, t.owner) || u(e.field, t.field) || u(Fe(e.declaration), Fe(t.declaration)) || u(e.inputPath, t.inputPath) || u(e.pointer, t.pointer), We = (e, t) => ({
309
+ declaration: t.declaration,
310
+ field: t.field,
311
+ inputPath: e,
312
+ owner: t.owner,
313
+ pointer: t.pointer
314
+ }), Ge = (e, t, n, i) => {
315
+ if (e.length >= i.maxEntries) throw new r({
316
+ code: "RESOURCE_LIMIT_EXCEEDED",
317
+ limit: "maxEntries",
318
+ limitMaximum: i.maxEntries,
319
+ nextAction: "reduce-input-or-increase-limit",
320
+ observedUsage: e.length + 1,
321
+ operation: "match-manifest-scope"
322
+ });
323
+ e.push(We(t, n));
324
+ }, Ke = (e, t, n, r) => {
325
+ for (let i of n) Me(i.segments, t) && Ge(e, t, i.declaration, r);
326
+ }, qe = async (e) => {
327
+ let t = e.join("\0");
328
+ return N({
329
+ scalarLength: O(t),
330
+ utf8ByteLength: l(t),
331
+ value: t
332
+ });
333
+ }, Je = (e, t, n) => {
334
+ let r = He(e, n), i = [], a = new Set(), o = new Set();
335
+ for (let e of t) {
336
+ let t = e.slice(1).split("/", 1)[0] ?? "", a = r.exact.get(e) ?? [];
337
+ for (let t of a) Ge(i, e, t, n);
338
+ Ke(i, e, r.globalGlobs, n), Ke(i, e, r.globsByFirstSegment.get(t) ?? [], n);
339
+ }
340
+ i.sort(Ue);
341
+ for (let e of i) a.add(`${e.owner.kind}\0${e.owner.agentId ?? ""}\0${e.owner.id}`), o.add(e.inputPath);
342
+ return m({
343
+ counts: {
344
+ declarations: r.declarations.length,
345
+ inputPaths: t.length,
346
+ matchedOwners: a.size,
347
+ matchedPaths: o.size,
348
+ matches: i.length
349
+ },
350
+ matches: i
351
+ });
352
+ }, I = (e, t) => `${e}/${g(t)}`, L = (e, t, n, r, i = null) => {
353
+ e.diagnostics.add({
354
+ code: "MOLDEA_MANIFEST_VALUE_INVALID",
355
+ details: { reason: r },
356
+ entity: i,
357
+ path: e.path,
358
+ pointer: t,
359
+ range: n
360
+ });
361
+ }, R = (e, t, n, r, i = null) => {
362
+ if (e.kind !== "mapping") return L(r, t, e.range, "mapping-required", i), null;
363
+ let a = new Map();
364
+ for (let o of e.entries) {
365
+ if (o.key.kind !== "scalar" || typeof o.key.value != "string") {
366
+ L(r, t, o.key.range, "string-key-required", i);
367
+ continue;
368
+ }
369
+ let e = o.key.value;
370
+ if (n !== null && !n.has(e)) {
371
+ r.diagnostics.add({
372
+ code: "MOLDEA_MANIFEST_PROPERTY_UNKNOWN",
373
+ entity: i,
374
+ path: r.path,
375
+ pointer: I(t, e),
376
+ range: o.key.range
377
+ });
378
+ continue;
379
+ }
380
+ a.set(e, {
381
+ key: o.key,
382
+ value: o.value
383
+ });
384
+ }
385
+ return a;
386
+ }, Ye = (e, t, n, r = {}) => {
387
+ if (e === void 0) return r.required === !0 && L(n, t, null, "required", r.entity ?? null), null;
388
+ if (e.value.kind !== "scalar" || typeof e.value.value != "string") return L(n, t, e.value.range, "string-required", r.entity ?? null), null;
389
+ let i = e.value.value;
390
+ return !k(i) || r.singleLine === !0 && !ue(i) ? (L(n, t, e.value.range, "string-invalid", r.entity ?? null), null) : i;
391
+ }, Xe = (e, t, n, r, i = null) => de(e) ? !fe(e) || (r.diagnostics.add({
392
+ code: "MOLDEA_ID_RESERVED",
393
+ entity: i,
394
+ path: r.path,
395
+ pointer: n,
396
+ range: t
397
+ }), !1) : (r.diagnostics.add({
398
+ code: "MOLDEA_ID_INVALID",
399
+ entity: i,
400
+ path: r.path,
401
+ pointer: n,
402
+ range: t
403
+ }), !1), Ze = (e, t, n, r = null) => {
404
+ let i = R(e, t, new Set(["path", "symbol"]), n, r);
405
+ if (i === null) return null;
406
+ let a = i.get("path");
407
+ if (a?.value.kind !== "scalar" || typeof a.value.value != "string") return n.diagnostics.add({
408
+ code: "MOLDEA_PATH_INVALID",
409
+ details: { reason: a === void 0 ? "missing" : "type" },
410
+ entity: r,
411
+ path: n.path,
412
+ pointer: I(t, "path"),
413
+ range: a?.value.range ?? null
414
+ }), null;
415
+ let o = A(a.value.value);
416
+ if (o === null) return n.diagnostics.add({
417
+ code: "MOLDEA_PATH_INVALID",
418
+ entity: r,
419
+ path: n.path,
420
+ pointer: I(t, "path"),
421
+ range: a.value.range
422
+ }), null;
423
+ let s = i.get("symbol");
424
+ return s === void 0 ? { path: o } : s.value.kind !== "scalar" || typeof s.value.value != "string" || !be(s.value.value) ? (n.diagnostics.add({
425
+ code: "MOLDEA_SYMBOL_INVALID",
426
+ entity: r,
427
+ path: n.path,
428
+ pointer: I(t, "symbol"),
429
+ range: s.value.range
430
+ }), null) : xe(o) ? (n.diagnostics.add({
431
+ code: "MOLDEA_SYMBOL_FORBIDDEN",
432
+ entity: r,
433
+ path: n.path,
434
+ pointer: I(t, "symbol"),
435
+ range: s.value.range
436
+ }), null) : {
437
+ path: o,
438
+ symbol: s.value.value
439
+ };
440
+ }, Qe = (e, t, n, r = null) => {
441
+ if (e.kind !== "sequence" || e.items.length === 0) return L(n, t, e.range, "non-empty-sequence-required", r), [];
442
+ let i = [], a = new Set();
443
+ return e.items.forEach((e, o) => {
444
+ let s = Ze(e, I(t, String(o)), n, r);
445
+ if (s === null) return;
446
+ let c = `${s.path}\0${s.symbol ?? ""}`;
447
+ if (a.has(c)) {
448
+ n.diagnostics.add({
449
+ code: "MOLDEA_PATH_DUPLICATE",
450
+ entity: r,
451
+ path: n.path,
452
+ pointer: I(t, String(o)),
453
+ range: e.range
454
+ });
455
+ return;
456
+ }
457
+ a.add(c), i.push(s);
458
+ }), i;
459
+ }, $e = (e, t, n, r = null) => {
460
+ if (e.kind !== "sequence" || e.items.length === 0) return L(n, t, e.range, "non-empty-sequence-required", r), [];
461
+ let i = [], a = new Set();
462
+ return e.items.forEach((e, o) => {
463
+ let s = I(t, String(o));
464
+ if (e.kind !== "scalar" || typeof e.value != "string") {
465
+ L(n, s, e.range, "string-required", r);
466
+ return;
467
+ }
468
+ let c = e.value.includes("*") || ve(e.value);
469
+ if (!(c ? ye(e.value) : A(e.value) !== null)) {
470
+ n.diagnostics.add({
471
+ code: c ? "MOLDEA_GLOB_INVALID" : "MOLDEA_PATH_INVALID",
472
+ entity: r,
473
+ path: n.path,
474
+ pointer: s,
475
+ range: e.range
476
+ });
477
+ return;
478
+ }
479
+ if (a.has(e.value)) {
480
+ n.diagnostics.add({
481
+ code: c ? "MOLDEA_PATTERN_DUPLICATE" : "MOLDEA_PATH_DUPLICATE",
482
+ entity: r,
483
+ path: n.path,
484
+ pointer: s,
485
+ range: e.range
486
+ });
487
+ return;
488
+ }
489
+ a.add(e.value), i.push(e.value);
490
+ }), i;
491
+ }, et = (e, t, n) => {
492
+ let r = R(e, t, new Set(["affectedBy", "bindings"]), n);
493
+ if (r === null) return null;
494
+ let i = r.get("bindings"), a = r.get("affectedBy");
495
+ return i === void 0 && a === void 0 && n.diagnostics.add({
496
+ code: "MOLDEA_CONTEXT_RELATIONSHIP_EMPTY",
497
+ path: n.path,
498
+ pointer: t,
499
+ range: e.range
500
+ }), {
501
+ ...i === void 0 ? {} : { bindings: Qe(i.value, I(t, "bindings"), n) },
502
+ ...a === void 0 ? {} : { affectedBy: $e(a.value, I(t, "affectedBy"), n) }
503
+ };
504
+ }, tt = (e, t, n, r) => {
505
+ let i = R(e, t, null, r);
506
+ if (i === null) return null;
507
+ let a = [];
508
+ for (let [e, o] of [...i].sort(([e], [t]) => u(e, t))) {
509
+ let i = A(e);
510
+ if (!(i !== null && (n === "context" ? he(i, !0) : ge(i)))) {
511
+ r.diagnostics.add({
512
+ code: n === "context" ? "MOLDEA_CONTEXT_PATH_INVALID" : "MOLDEA_DECISION_FILENAME_INVALID",
513
+ path: r.path,
514
+ pointer: I(t, e),
515
+ range: o.key.range
516
+ });
517
+ continue;
518
+ }
519
+ let s = et(o.value, I(t, e), r);
520
+ s !== null && a.push([e, s]);
521
+ }
522
+ return p(a);
523
+ }, nt = (e, t, n, r, i) => {
524
+ if (e.kind !== "sequence") return L(r, t, e.range, "sequence-required", i), [];
525
+ let a = [], o = new Set();
526
+ return e.items.forEach((e, s) => {
527
+ let c = I(t, String(s));
528
+ if (e.kind !== "scalar" || typeof e.value != "string") {
529
+ L(r, c, e.range, "string-required", i);
530
+ return;
531
+ }
532
+ let l = A(e.value);
533
+ if (!(l !== null && (n === "context" ? he(l, !1) : n === "decision" ? ge(l) : _e(l))) || l === null) {
534
+ let t = n === "context" ? "MOLDEA_CONTEXT_PATH_INVALID" : n === "decision" ? "MOLDEA_DECISION_FILENAME_INVALID" : l !== null && !_e(l) ? "MOLDEA_MIRROR_PATH_INSIDE_MOLDEA" : "MOLDEA_MIRROR_PATH_INVALID";
535
+ r.diagnostics.add({
536
+ code: t,
537
+ entity: i,
538
+ path: r.path,
539
+ pointer: c,
540
+ range: e.range
541
+ });
542
+ return;
543
+ }
544
+ if (o.has(l)) {
545
+ r.diagnostics.add({
546
+ code: n === "mirror" ? "MOLDEA_MIRROR_PATH_DUPLICATE" : "MOLDEA_PATH_DUPLICATE",
547
+ entity: i,
548
+ path: r.path,
549
+ pointer: c,
550
+ range: e.range
551
+ });
552
+ return;
553
+ }
554
+ if (n === "mirror" && r.mirrorPaths.has(l)) {
555
+ r.diagnostics.add({
556
+ code: "MOLDEA_MIRROR_PATH_DUPLICATE",
557
+ entity: i,
558
+ path: r.path,
559
+ pointer: c,
560
+ range: e.range
561
+ });
562
+ return;
563
+ }
564
+ o.add(l), n === "mirror" && r.mirrorPaths.add(l), a.push(l);
565
+ }), a;
566
+ }, rt = (e, t, n, r) => {
567
+ let i = { agentId: r }, a = R(e, t, new Set([
568
+ "inputSchema",
569
+ "instructionLoader",
570
+ "outputSchema",
571
+ "runtimeAgent"
572
+ ]), n, i);
573
+ if (a === null) return null;
574
+ let o = (e) => {
575
+ let r = a.get(e);
576
+ return r === void 0 ? null : Ze(r.value, I(t, e), n, i);
577
+ }, s = o("inputSchema"), c = o("instructionLoader"), l = o("outputSchema"), u = o("runtimeAgent");
578
+ return {
579
+ ...u === null ? {} : { runtimeAgent: u },
580
+ ...s === null ? {} : { inputSchema: s },
581
+ ...l === null ? {} : { outputSchema: l },
582
+ ...c === null ? {} : { instructionLoader: c }
583
+ };
584
+ }, it = (e, t, n, r, i, a) => {
585
+ let o = {
586
+ agentId: r,
587
+ capabilityId: i,
588
+ capabilityKind: a
589
+ }, s = R(e, t, a === "tool" ? new Set([
590
+ "affectedBy",
591
+ "description",
592
+ "implementation",
593
+ "inputSchema",
594
+ "name",
595
+ "outputSchema",
596
+ "registration"
597
+ ]) : new Set([
598
+ "affectedBy",
599
+ "description",
600
+ "implementation",
601
+ "name",
602
+ "registration"
603
+ ]), n, o);
604
+ if (s === null) return null;
605
+ let c = Ye(s.get("name"), I(t, "name"), n, {
606
+ entity: o,
607
+ required: !0,
608
+ singleLine: !0
609
+ }), l = s.get("description"), u = null;
610
+ l === void 0 ? n.diagnostics.add({
611
+ code: "MOLDEA_CAPABILITY_DESCRIPTION_MISSING",
612
+ entity: o,
613
+ path: n.path,
614
+ pointer: I(t, "description")
615
+ }) : l.value.kind !== "scalar" || typeof l.value.value != "string" || !pe(l.value.value) ? n.diagnostics.add({
616
+ code: "MOLDEA_CAPABILITY_DESCRIPTION_INVALID",
617
+ entity: o,
618
+ path: n.path,
619
+ pointer: I(t, "description"),
620
+ range: l.value.range
621
+ }) : u = l.value.value;
622
+ let d = s.get("implementation"), f = null;
623
+ d === void 0 ? n.diagnostics.add({
624
+ code: a === "tool" ? "MOLDEA_TOOL_IMPLEMENTATION_MISSING" : "MOLDEA_SKILL_IMPLEMENTATION_MISSING",
625
+ entity: o,
626
+ path: n.path,
627
+ pointer: I(t, "implementation")
628
+ }) : f = Ze(d.value, I(t, "implementation"), n, o);
629
+ let p = (e) => {
630
+ let r = s.get(e);
631
+ return r === void 0 ? null : Ze(r.value, I(t, e), n, o);
632
+ }, m = p("registration"), h = a === "tool" ? p("inputSchema") : null, g = a === "tool" ? p("outputSchema") : null, _ = s.get("affectedBy"), v = _ === void 0 ? null : $e(_.value, I(t, "affectedBy"), n, o);
633
+ return c === null || u === null || f === null ? null : {
634
+ name: c,
635
+ description: u,
636
+ implementation: f,
637
+ ...m === null ? {} : { registration: m },
638
+ ...h === null ? {} : { inputSchema: h },
639
+ ...g === null ? {} : { outputSchema: g },
640
+ ...v === null ? {} : { affectedBy: v }
641
+ };
642
+ }, at = (e, t, n, r, i) => {
643
+ let a = R(e, t, null, n, { agentId: r });
644
+ if (a === null) return null;
645
+ let o = [];
646
+ for (let [e, s] of [...a].sort(([e], [t]) => u(e, t))) {
647
+ let a = {
648
+ agentId: r,
649
+ capabilityId: e,
650
+ capabilityKind: i
651
+ }, c = I(t, e);
652
+ Xe(e, s.key.range, c, n, a);
653
+ let l = it(s.value, c, n, r, e, i);
654
+ l !== null && o.push([e, l]);
655
+ }
656
+ return p(o);
657
+ }, ot = (e, t) => {
658
+ if (e.kind !== "mapping") return null;
659
+ for (let n of e.entries) if (n.key.kind === "scalar" && n.key.value === t) return n.value;
660
+ return null;
661
+ }, st = (e) => {
662
+ if (e.kind !== "mapping") return null;
663
+ let t = ot(e, "version");
664
+ return t?.kind === "scalar" && t.value === 1n ? 1 : null;
665
+ }, ct = (e, t, n, r) => {
666
+ let i = new Set();
667
+ for (let a of ["tools", "skills"]) {
668
+ let o = ot(e, a);
669
+ if (o?.kind === "mapping") for (let e of o.entries) e.key.kind === "scalar" && typeof e.key.value == "string" && (i.has(e.key.value) && n.diagnostics.add({
670
+ code: "MOLDEA_ID_DUPLICATE",
671
+ entity: { agentId: r },
672
+ path: n.path,
673
+ pointer: I(I(t, a), e.key.value),
674
+ range: e.key.range
675
+ }), i.add(e.key.value));
676
+ }
677
+ }, lt = (e, t, n, r) => {
678
+ let i = { agentId: r }, a = R(e, t, new Set([
679
+ "affectedBy",
680
+ "bindings",
681
+ "context",
682
+ "decisions",
683
+ "mirrors",
684
+ "skills",
685
+ "tools"
686
+ ]), n, i);
687
+ if (a === null) return null;
688
+ ct(e, t, n, r);
689
+ let o = a.get("bindings"), s = o === void 0 ? null : rt(o.value, I(t, "bindings"), n, r), c = a.get("context"), l = c === void 0 ? null : nt(c.value, I(t, "context"), "context", n, i), u = a.get("decisions"), d = u === void 0 ? null : nt(u.value, I(t, "decisions"), "decision", n, i), f = a.get("tools"), p = f === void 0 ? null : at(f.value, I(t, "tools"), n, r, "tool"), m = a.get("skills"), h = m === void 0 ? null : at(m.value, I(t, "skills"), n, r, "skill"), g = a.get("affectedBy"), _ = g === void 0 ? null : $e(g.value, I(t, "affectedBy"), n, i), v = a.get("mirrors"), y = v === void 0 ? null : nt(v.value, I(t, "mirrors"), "mirror", n, i);
690
+ return {
691
+ ...l === null ? {} : { context: l },
692
+ ...d === null ? {} : { decisions: d },
693
+ ...s === null ? {} : { bindings: s },
694
+ ...p === null ? {} : { tools: p },
695
+ ...h === null ? {} : { skills: h },
696
+ ..._ === null ? {} : { affectedBy: _ },
697
+ ...y === null ? {} : { mirrors: y }
698
+ };
699
+ }, ut = (e, t, n) => {
700
+ let r = R(e, t, null, n);
701
+ if (r === null) return null;
702
+ let i = [];
703
+ for (let [e, a] of [...r].sort(([e], [t]) => u(e, t))) {
704
+ let r = I(t, e);
705
+ Xe(e, a.key.range, r, n, { agentId: e });
706
+ let o = lt(a.value, r, n, e);
707
+ o !== null && i.push([e, o]);
708
+ }
709
+ return p(i);
710
+ }, dt = (e, t) => {
711
+ let n = (e, n, r, i) => {
712
+ t.diagnostics.add({
713
+ code: "MOLDEA_MANIFEST_VALUE_INVALID",
714
+ path: t.path,
715
+ pointer: e === null ? "/acceptedWarnings" : `/acceptedWarnings/${e}/${g(n)}`,
716
+ range: r,
717
+ details: {
718
+ entry: e,
719
+ field: n,
720
+ reason: i
721
+ }
722
+ });
723
+ };
724
+ if (e.kind !== "sequence") return n(null, "acceptedWarnings", e.range, "sequence-required"), null;
725
+ if (e.items.length > t.limits.maxAcceptedWarnings) throw new r({
726
+ code: "RESOURCE_LIMIT_EXCEEDED",
727
+ operation: t.operation,
728
+ limit: "maxAcceptedWarnings",
729
+ limitMaximum: t.limits.maxAcceptedWarnings,
730
+ observedUsage: e.items.length,
731
+ nextAction: "reduce-input-or-increase-limit"
732
+ });
733
+ let i = [], a = new Set();
734
+ for (let [t, r] of e.items.entries()) {
735
+ if (r.kind !== "mapping") {
736
+ n(t, "entry", r.range, "mapping-required");
737
+ continue;
738
+ }
739
+ let e = new Map(), o = !0;
740
+ for (let i of r.entries) i.key.kind !== "scalar" || typeof i.key.value != "string" || ![
741
+ "code",
742
+ "subject",
743
+ "qualifier",
744
+ "reason"
745
+ ].includes(i.key.value) ? (n(t, i.key.kind === "scalar" && typeof i.key.value == "string" ? i.key.value : "key", i.key.range, "unknown-field"), o = !1) : e.set(i.key.value, i.value);
746
+ let s = (i) => {
747
+ let a = e.get(i);
748
+ return a?.kind !== "scalar" || typeof a.value != "string" || !k(a.value) ? (n(t, i, a?.range ?? r.range, a === void 0 ? "required" : "non-empty-string-required"), o = !1, null) : a.value;
749
+ }, c = s("code"), l = s("subject"), u = s("reason"), d = l === null ? null : A(l), f = e.get("qualifier"), p = null;
750
+ f !== void 0 && (f.kind !== "scalar" || f.value !== null) && (p = s("qualifier"), p !== null && !ue(p) && (n(t, "qualifier", f.range, "single-line-required"), o = !1));
751
+ let m = _.find((e) => e === c);
752
+ if (c !== null && m === void 0 && (n(t, "code", e.get("code").range, "code-not-acceptable"), o = !1), l !== null && d === null && (n(t, "subject", e.get("subject").range, "repository-path-required"), o = !1), u !== null && O(u) > 256 && (n(t, "reason", e.get("reason").range, "maximum-256-characters"), o = !1), !o || m === void 0 || d === null || u === null) continue;
753
+ let h = JSON.stringify([
754
+ m,
755
+ d,
756
+ p
757
+ ]);
758
+ if (a.has(h)) {
759
+ n(t, "code", e.get("code").range, "duplicate-identity");
760
+ continue;
761
+ }
762
+ a.add(h), i.push({
763
+ code: m,
764
+ subject: d,
765
+ ...f === void 0 ? {} : { qualifier: p },
766
+ reason: u
767
+ });
768
+ }
769
+ return i;
770
+ }, ft = (e, t, n, r, i) => {
771
+ let a = {
772
+ diagnostics: n,
773
+ operation: i,
774
+ limits: r,
775
+ mirrorPaths: new Set(),
776
+ path: t
777
+ };
778
+ if (e.kind !== "mapping") return n.add({
779
+ code: "MOLDEA_MANIFEST_ROOT_INVALID",
780
+ path: t,
781
+ range: e.range
782
+ }), null;
783
+ let o = ot(e, "version");
784
+ if (o === null) return n.add({
785
+ code: "MOLDEA_MANIFEST_VERSION_MISSING",
786
+ path: t,
787
+ pointer: "/version"
788
+ }), null;
789
+ if (o.kind !== "scalar" || typeof o.value != "bigint" || o.kind !== "scalar" || o.value <= 0n) return n.add({
790
+ code: "MOLDEA_MANIFEST_VERSION_INVALID",
791
+ path: t,
792
+ pointer: "/version",
793
+ range: o.range
794
+ }), null;
795
+ if (o.value !== 1n) return n.add({
796
+ code: "MOLDEA_MANIFEST_VERSION_UNSUPPORTED",
797
+ path: t,
798
+ pointer: "/version",
799
+ range: o.range
800
+ }), null;
801
+ let s = R(e, "", new Set([
802
+ "acceptedWarnings",
803
+ "agents",
804
+ "context",
805
+ "decisions",
806
+ "version"
807
+ ]), a);
808
+ if (s === null) return null;
809
+ let c = s.get("acceptedWarnings"), l = c === void 0 ? null : dt(c.value, a), u = s.get("context"), d = u === void 0 ? null : tt(u.value, "/context", "context", a), f = s.get("decisions"), p = f === void 0 ? null : tt(f.value, "/decisions", "decision", a), m = s.get("agents"), h = m === void 0 ? null : ut(m.value, "/agents", a);
810
+ return {
811
+ version: 1,
812
+ ...l === null ? {} : { acceptedWarnings: l },
813
+ ...d === null ? {} : { context: d },
814
+ ...p === null ? {} : { decisions: p },
815
+ ...h === null ? {} : { agents: h }
816
+ };
817
+ }, pt = (e, t) => {
818
+ let n = 0, r = e.length - 1;
819
+ for (; n < r;) {
820
+ let i = Math.ceil((n + r) / 2);
821
+ (e[i] ?? 0) <= t ? n = i : r = i - 1;
822
+ }
823
+ return n;
824
+ }, mt = (e) => {
825
+ let t = new Uint32Array(e.length + 1), n = [0], r = 0;
826
+ for (let i = 0; i < e.length;) {
827
+ let a = e.codePointAt(i), o = a !== void 0 && a > 65535 ? 2 : 1;
828
+ t[i] = r;
829
+ for (let e = 1; e < o; e += 1) t[i + e] = r;
830
+ i += o, r += 1, t[i] = r, a === 10 && n.push(i);
831
+ }
832
+ let i = (r) => {
833
+ let i = Math.max(0, Math.min(e.length, r)), a = pt(n, i), o = n[a] ?? 0, s = t[i] ?? 0;
834
+ return {
835
+ column: s - (t[o] ?? 0) + 1,
836
+ line: a + 1,
837
+ offset: s
838
+ };
839
+ };
840
+ return Object.freeze({ locateRange: (e, t) => ({
841
+ end: i(t),
842
+ start: i(e)
843
+ }) });
844
+ }, ht = async (e, t, n = "parse-manifest") => {
845
+ t = a(t);
846
+ let r = M(e, t.limits, n, "maxManifestBytes"), i = S(e.path), s = d(t.limits, n);
847
+ me(i) || s.add({
848
+ code: "MOLDEA_MANIFEST_PATH_INVALID",
849
+ path: i
850
+ });
851
+ for (let e of r.diagnostics) s.merge(e);
852
+ if (!r.valid || r.text === null) return m({
853
+ asset: null,
854
+ diagnostics: s.finalize(),
855
+ formatVersion: null,
856
+ manifest: null,
857
+ valid: !1,
858
+ yamlRoot: null
859
+ });
860
+ let l = mt(r.text.value), u = c(r.text.value, i, l, s), f = u.value === null ? null : st(u.value), p = u.valid && u.value !== null ? ft(u.value, i, s, t.limits, n) : null, h = o(s.finalize(), new Map(u.value === null ? [] : [[i, u.value]]));
861
+ if (p === null || s.size > 0) return m({
862
+ asset: null,
863
+ diagnostics: h,
864
+ formatVersion: f,
865
+ manifest: null,
866
+ valid: !1,
867
+ yamlRoot: u.value
868
+ });
869
+ let g = await N(r.text), _ = {
870
+ content: r.text.value,
871
+ digest: g,
872
+ path: i,
873
+ scalarLength: r.text.scalarLength,
874
+ utf8ByteLength: r.text.utf8ByteLength
875
+ };
876
+ return m({
877
+ asset: _,
878
+ diagnostics: h,
879
+ formatVersion: f,
880
+ manifest: p,
881
+ valid: !0,
882
+ yamlRoot: u.value
883
+ });
884
+ }, gt = async (e, t, n = "parse-manifest") => {
885
+ let r = await ht(e, t, n);
886
+ return m({
887
+ asset: r.asset,
888
+ diagnostics: r.diagnostics,
889
+ manifest: r.manifest,
890
+ valid: r.valid
891
+ });
892
+ }, _t = () => {
893
+ throw new r({
894
+ code: "INVALID_ARGUMENT",
895
+ operation: "match-manifest-scope"
896
+ });
897
+ }, vt = (e, t, n) => {
898
+ throw new r({
899
+ code: "RESOURCE_LIMIT_EXCEEDED",
900
+ limit: e,
901
+ limitMaximum: t,
902
+ nextAction: "reduce-input-or-increase-limit",
903
+ observedUsage: n,
904
+ operation: "match-manifest-scope"
905
+ });
906
+ }, yt = (e, t) => {
907
+ if (!i(e, !0)) return _t();
908
+ let n = e.manifest, r = e.paths;
909
+ if (!i(n, !0) || !Array.isArray(r)) return _t();
910
+ if (r.length > t.maxEntries) return vt("maxEntries", t.maxEntries, r.length);
911
+ let a = new Set(), o = 0;
912
+ for (let [e, n] of r.entries()) {
913
+ if (typeof n != "string") return _t();
914
+ let r = S(n);
915
+ if (o += l(r) + (e === 0 ? 0 : 1), o > t.maxTotalBytesRead) return vt("maxTotalBytesRead", t.maxTotalBytesRead, o);
916
+ a.add(r);
917
+ }
918
+ return {
919
+ manifest: n,
920
+ paths: [...a].sort(u)
921
+ };
922
+ }, bt = async (e, t) => {
923
+ let n = yt(e, t.limits), r = await qe(n.paths), i = await gt(n.manifest, t, "match-manifest-scope");
924
+ if (!i.valid || i.asset === null || i.manifest === null) return m({
925
+ counts: {
926
+ declarations: 0,
927
+ inputPaths: n.paths.length,
928
+ matchedOwners: 0,
929
+ matchedPaths: 0,
930
+ matches: 0
931
+ },
932
+ diagnostics: i.diagnostics,
933
+ inputDigest: r,
934
+ manifestDigest: null,
935
+ matches: [],
936
+ relevant: !1,
937
+ valid: !1
938
+ });
939
+ let a = Je(i.manifest, n.paths, t.limits);
940
+ return m({
941
+ counts: a.counts,
942
+ diagnostics: [],
943
+ inputDigest: r,
944
+ manifestDigest: i.asset.digest,
945
+ matches: a.matches,
946
+ relevant: a.matches.length > 0,
947
+ valid: !0
948
+ });
949
+ }, xt = Object.defineProperty, St = (e, t) => {
950
+ let n = {};
951
+ for (var r in e) xt(n, r, {
952
+ get: e[r],
953
+ enumerable: !0
954
+ });
955
+ return t || xt(n, Symbol.toStringTag, { value: "Module" }), n;
956
+ }, Ct = new TextDecoder("utf-8", {
957
+ fatal: !0,
958
+ ignoreBOM: !0
959
+ }), z = () => {
960
+ throw new r({
961
+ code: "INVALID_ARGUMENT",
962
+ operation: "read-canonical-content-page"
963
+ });
964
+ }, wt = () => {
965
+ throw new r({
966
+ code: "CONTENT_INVALID",
967
+ operation: "read-canonical-content-page"
968
+ });
969
+ }, Tt = (e) => typeof e == "object" && !!e && typeof e.getEntry == "function" && typeof e.readFilePage == "function", Et = async (e, t, n, r, i) => {
970
+ let a = [], o = 0, s = n, c = null, l = null;
971
+ for (; o < r;) {
972
+ let n = await e.readFilePage(t, {
973
+ maxBytes: r - o,
974
+ offset: s,
975
+ ...i === void 0 ? {} : { signal: i }
976
+ });
977
+ if (n.snapshot.id !== e.snapshot.id || n.offset !== s || n.bytes.byteLength > r - o || n.totalBytes < n.offset + n.bytes.byteLength || l !== null && n.totalBytes !== l || n.bytes.byteLength === 0 && !n.isComplete) throw new x({
978
+ code: "INVALID_SOURCE_DATA",
979
+ operation: "read-file-page",
980
+ path: t,
981
+ retryable: !1
982
+ });
983
+ if (a.push(n.bytes), o += n.bytes.byteLength, l = n.totalBytes, c = n, n.isComplete || o === r) break;
984
+ if (n.nextOffset !== n.offset + n.bytes.byteLength) throw new x({
985
+ code: "INVALID_SOURCE_DATA",
986
+ operation: "read-file-page",
987
+ path: t,
988
+ retryable: !1
989
+ });
990
+ s = n.nextOffset;
991
+ }
992
+ if (c === null) return z();
993
+ let u = new Uint8Array(o), d = 0;
994
+ for (let e of a) u.set(e, d), d += e.byteLength;
995
+ return {
996
+ bytes: u,
997
+ lastPage: c
998
+ };
999
+ }, Dt = (e, t) => {
1000
+ let n = Math.max(0, t - 3);
1001
+ for (let r = t; r >= n; --r) try {
1002
+ let t = Ct.decode(e.subarray(0, r));
1003
+ if (r === 0 && e.byteLength > 0) continue;
1004
+ return [t, r];
1005
+ } catch {}
1006
+ return wt();
1007
+ }, Ot = async (e, t) => {
1008
+ if (typeof e != "object" || !e || Reflect.ownKeys(e).some((e) => e !== "maxBytes" && e !== "offset" && e !== "path" && e !== "repository" && e !== "signal") || !Tt(e.repository) || !Number.isSafeInteger(e.maxBytes) || e.maxBytes < 1 || e.maxBytes > t.limits.maxFileBytes || !Number.isSafeInteger(e.offset) || e.offset < 0) return z();
1009
+ let n = S(e.path);
1010
+ if (!n.startsWith("/moldea/")) return z();
1011
+ let i = e.signal === void 0 ? void 0 : { signal: e.signal }, a = await e.repository.getEntry(n, i);
1012
+ if (a === null) throw new x({
1013
+ code: "ENTRY_NOT_FOUND",
1014
+ operation: "read-file-page",
1015
+ path: n,
1016
+ retryable: !1
1017
+ });
1018
+ if (a.type !== "file" || a.byteLength === null) throw new x({
1019
+ code: "ENTRY_NOT_FILE",
1020
+ operation: "read-file-page",
1021
+ path: n,
1022
+ retryable: !1
1023
+ });
1024
+ if (a.byteLength > t.limits.maxFileBytes) throw new r({
1025
+ code: "RESOURCE_LIMIT_EXCEEDED",
1026
+ limit: "maxFileBytes",
1027
+ limitMaximum: t.limits.maxFileBytes,
1028
+ nextAction: "reduce-input-or-increase-limit",
1029
+ observedUsage: a.byteLength,
1030
+ operation: "read-canonical-content-page"
1031
+ });
1032
+ if (e.offset > a.byteLength) return z();
1033
+ if (e.offset === a.byteLength) return m({
1034
+ byteEnd: e.offset,
1035
+ byteStart: e.offset,
1036
+ content: "",
1037
+ contentIdentity: a.contentIdentity,
1038
+ isComplete: !0,
1039
+ nextOffset: null,
1040
+ path: n,
1041
+ source: e.repository.snapshot,
1042
+ totalBytes: a.byteLength
1043
+ });
1044
+ let o = Math.min(a.byteLength - e.offset, e.maxBytes + 3), { bytes: s, lastPage: c } = await Et(e.repository, n, e.offset, o, e.signal);
1045
+ if (c.totalBytes !== a.byteLength || (s[0] & 192) == 128) return z();
1046
+ let [l, u] = Dt(s, Math.min(e.maxBytes, s.byteLength)), d = e.offset + u, f = d === a.byteLength;
1047
+ return m({
1048
+ byteEnd: d,
1049
+ byteStart: e.offset,
1050
+ content: l,
1051
+ contentIdentity: a.contentIdentity,
1052
+ isComplete: f,
1053
+ nextOffset: f ? null : d,
1054
+ path: n,
1055
+ source: e.repository.snapshot,
1056
+ totalBytes: a.byteLength
1057
+ });
1058
+ }, kt = new Set([
1059
+ "accepted",
1060
+ "proposed",
1061
+ "rejected",
1062
+ "superseded"
1063
+ ]), At = /^\d{13}$/u, jt = /^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])T(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d\.\d{3}Z$/u, B = (e) => e === null ? null : { decisionId: e }, Mt = (e, t, n, r = null) => {
1064
+ e.diagnostics.add({
1065
+ code: "MOLDEA_DECISION_FRONTMATTER_INVALID",
1066
+ details: { reason: n },
1067
+ entity: B(e.decisionId),
1068
+ path: e.path,
1069
+ pointer: r,
1070
+ range: t
1071
+ });
1072
+ }, Nt = (e) => {
1073
+ if (!jt.test(e)) return !1;
1074
+ let t = Date.parse(e);
1075
+ return Number.isFinite(t) && new Date(t).toISOString() === e;
1076
+ }, Pt = (e, t) => {
1077
+ if (e.kind !== "mapping") return Mt(t, e.range, "mapping-required"), null;
1078
+ let n = new Map();
1079
+ for (let r of e.entries) {
1080
+ if (r.key.kind !== "scalar" || typeof r.key.value != "string") {
1081
+ Mt(t, r.key.range, "string-key-required");
1082
+ continue;
1083
+ }
1084
+ let e = r.key.value;
1085
+ if (e !== "status" && e !== "createdAt" && e !== "supersedes") {
1086
+ t.diagnostics.add({
1087
+ code: "MOLDEA_DECISION_PROPERTY_UNKNOWN",
1088
+ entity: B(t.decisionId),
1089
+ path: t.path,
1090
+ pointer: `/${g(e)}`,
1091
+ range: r.key.range
1092
+ });
1093
+ continue;
1094
+ }
1095
+ n.set(e, r.value);
1096
+ }
1097
+ return n;
1098
+ }, Ft = (e, t) => e?.kind !== "scalar" || typeof e.value != "string" || !kt.has(e.value) ? (t.diagnostics.add({
1099
+ code: "MOLDEA_DECISION_STATUS_INVALID",
1100
+ entity: B(t.decisionId),
1101
+ path: t.path,
1102
+ pointer: "/status",
1103
+ range: e?.range ?? null
1104
+ }), null) : e.value, It = (e, t) => e?.kind !== "scalar" || typeof e.value != "string" || !Nt(e.value) ? (t.diagnostics.add({
1105
+ code: "MOLDEA_DECISION_CREATED_AT_INVALID",
1106
+ entity: B(t.decisionId),
1107
+ path: t.path,
1108
+ pointer: "/createdAt",
1109
+ range: e?.range ?? null
1110
+ }), null) : (t.decisionId !== null && Date.parse(e.value) !== Number(t.decisionId) && t.diagnostics.add({
1111
+ code: "MOLDEA_DECISION_TIMESTAMP_MISMATCH",
1112
+ entity: B(t.decisionId),
1113
+ path: t.path,
1114
+ pointer: "/createdAt",
1115
+ range: e.range
1116
+ }), e.value), Lt = (e, t) => {
1117
+ if (e === void 0) return [];
1118
+ if (e.kind !== "sequence" || e.items.length === 0) return Mt(t, e.range, "non-empty-supersedes-sequence-required", "/supersedes"), null;
1119
+ let n = [], r = new Set();
1120
+ return e.items.forEach((e, i) => {
1121
+ let a = `/supersedes/${i}`;
1122
+ if (e.kind !== "scalar" || typeof e.value != "string" || !At.test(e.value)) {
1123
+ Mt(t, e.range, "decision-id-string-required", a);
1124
+ return;
1125
+ }
1126
+ if (r.has(e.value)) {
1127
+ t.diagnostics.add({
1128
+ code: "MOLDEA_ID_DUPLICATE",
1129
+ entity: B(t.decisionId),
1130
+ path: t.path,
1131
+ pointer: a,
1132
+ range: e.range
1133
+ });
1134
+ return;
1135
+ }
1136
+ r.add(e.value), n.push(e.value), e.value === t.decisionId && t.diagnostics.add({
1137
+ code: "MOLDEA_DECISION_SELF_SUPERSESSION",
1138
+ entity: B(t.decisionId),
1139
+ path: t.path,
1140
+ pointer: a,
1141
+ range: e.range
1142
+ });
1143
+ }), n.sort(u);
1144
+ }, Rt = (e, t, n) => {
1145
+ let r = e.indexOf("\n"), i = r === -1 ? e.length : r;
1146
+ if (e.slice(0, i) !== "---") return n.diagnostics.add({
1147
+ code: "MOLDEA_DECISION_FRONTMATTER_MISSING",
1148
+ entity: B(n.decisionId),
1149
+ path: n.path,
1150
+ range: t.locateRange(0, i)
1151
+ }), null;
1152
+ let a = r === -1 ? e.length : r + 1;
1153
+ for (; a <= e.length;) {
1154
+ let n = e.indexOf("\n", a), r = n === -1 ? e.length : n;
1155
+ if (e.slice(a, r) === "---") {
1156
+ let i = n === -1 ? r : n + 1;
1157
+ return {
1158
+ body: e.slice(i),
1159
+ bodyRange: t.locateRange(i, e.length),
1160
+ yaml: e.slice(0, a)
1161
+ };
1162
+ }
1163
+ if (n === -1) break;
1164
+ a = n + 1;
1165
+ }
1166
+ return n.diagnostics.add({
1167
+ code: "MOLDEA_DECISION_FRONTMATTER_MISSING",
1168
+ entity: B(n.decisionId),
1169
+ path: n.path,
1170
+ range: t.locateRange(e.length, e.length)
1171
+ }), null;
1172
+ }, zt = (e, t) => {
1173
+ let n = t.diagnostics.size, r = Pt(e, t);
1174
+ if (r === null) return null;
1175
+ let i = Ft(r.get("status"), t), a = It(r.get("createdAt"), t), o = Lt(r.get("supersedes"), t);
1176
+ return i === null || a === null || o === null || t.diagnostics.size > n ? null : {
1177
+ createdAt: a,
1178
+ status: i,
1179
+ supersedes: o
1180
+ };
1181
+ }, Bt = (e, t, n) => k(e) ? !0 : (n.diagnostics.add({
1182
+ code: "MOLDEA_DECISION_BODY_EMPTY",
1183
+ entity: B(n.decisionId),
1184
+ path: n.path,
1185
+ range: t
1186
+ }), !1), Vt = async (e, t, n = "parse-decision") => {
1187
+ t = a(t);
1188
+ let r = M(e, t.limits, n), i = S(e.path), s = d(t.limits, n), l = j(i);
1189
+ l === null && s.add({
1190
+ code: "MOLDEA_DECISION_FILENAME_INVALID",
1191
+ path: i
1192
+ });
1193
+ for (let e of r.diagnostics) s.merge(e);
1194
+ if (!r.valid || r.text === null) return m({
1195
+ decision: null,
1196
+ diagnostics: s.finalize(),
1197
+ valid: !1,
1198
+ yamlRoot: null
1199
+ });
1200
+ let u = {
1201
+ decisionId: l,
1202
+ diagnostics: s,
1203
+ path: i
1204
+ }, f = mt(r.text.value), p = Rt(r.text.value, f, u), h = null, g = null;
1205
+ if (p !== null) {
1206
+ Bt(p.body, p.bodyRange, u);
1207
+ let e = c(p.yaml, i, f, s);
1208
+ g = e.value, e.valid && e.value !== null && (h = zt(e.value, u));
1209
+ }
1210
+ let _ = o(s.finalize(), new Map(g === null ? [] : [[i, g]]));
1211
+ if (l === null || p === null || h === null || s.size > 0) return m({
1212
+ decision: null,
1213
+ diagnostics: _,
1214
+ valid: !1,
1215
+ yamlRoot: g
1216
+ });
1217
+ let v = await N(r.text), y = {
1218
+ content: r.text.value,
1219
+ digest: v,
1220
+ path: i,
1221
+ scalarLength: r.text.scalarLength,
1222
+ utf8ByteLength: r.text.utf8ByteLength
1223
+ };
1224
+ return m({
1225
+ decision: {
1226
+ asset: y,
1227
+ body: p.body,
1228
+ createdAt: h.createdAt,
1229
+ id: l,
1230
+ path: i,
1231
+ status: h.status,
1232
+ supersedes: h.supersedes
1233
+ },
1234
+ diagnostics: _,
1235
+ valid: !0,
1236
+ yamlRoot: g
1237
+ });
1238
+ }, Ht = async (e, t, n = "parse-decision") => {
1239
+ let r = await Vt(e, t, n);
1240
+ return m({
1241
+ decision: r.decision,
1242
+ diagnostics: r.diagnostics,
1243
+ valid: r.valid
1244
+ });
1245
+ }, Ut = function* (e) {
1246
+ for (let t of e.agents) yield { agentId: t.id };
1247
+ }, V = (e, t, n = null, r = null) => ({
1248
+ agentId: n,
1249
+ byteLength: e.utf8ByteLength,
1250
+ canonicalDigest: null,
1251
+ decisionId: r,
1252
+ digest: e.digest,
1253
+ kind: t,
1254
+ path: e.path,
1255
+ scalarLength: e.scalarLength
1256
+ }), Wt = function* (e) {
1257
+ yield V(e.manifest.asset, "manifest"), yield V(e.project, "project");
1258
+ for (let t of e.context) yield V(t.asset, "context");
1259
+ for (let { decision: t } of e.decisions) yield V(t.asset, "decision", null, t.id);
1260
+ for (let t of e.agents) {
1261
+ yield V(t.description.asset, "agent-description", t.id), yield V(t.instruction, "agent-instruction", t.id);
1262
+ for (let e of t.mirrors) yield {
1263
+ agentId: t.id,
1264
+ byteLength: e.byteLength,
1265
+ canonicalDigest: e.canonicalDigest,
1266
+ decisionId: null,
1267
+ digest: e.digest,
1268
+ kind: "mirror",
1269
+ path: e.path,
1270
+ scalarLength: e.scalarLength
1271
+ };
1272
+ }
1273
+ }, Gt = (e) => ({
1274
+ counts: {
1275
+ agents: e.agents.length,
1276
+ context: e.context.length,
1277
+ decisions: e.decisions.length,
1278
+ mirrors: e.agents.reduce((e, t) => e + t.mirrors.length, 0)
1279
+ },
1280
+ manifestDigest: e.manifest.asset.digest,
1281
+ manifestPath: e.manifest.asset.path,
1282
+ projectDigest: e.project.digest,
1283
+ projectPath: e.project.path
1284
+ }), Kt = (e) => ({
1285
+ bindings: e.length,
1286
+ exportsPassed: e.filter((e) => e.exportCheck === "passed").length,
1287
+ exportsFailed: e.filter((e) => e.exportCheck === "failed").length,
1288
+ exportsNotChecked: e.filter((e) => e.exportCheck === "not-checked").length
1289
+ }), qt = new WeakMap(), Jt = (e, t) => {
1290
+ if (qt.has(e)) throw TypeError("The inspection reader is already registered.");
1291
+ qt.set(e, t);
1292
+ }, Yt = (e) => {
1293
+ let t = qt.get(e);
1294
+ if (t === void 0) throw TypeError("The inspection reader has no retained-memory ledger.");
1295
+ return t;
1296
+ }, Xt = (e, t) => {
1297
+ qt.get(e)?.reserve(t);
1298
+ }, Zt = S("/moldea/moldea.yaml"), Qt = new Set([
1299
+ "/AGENTS.md",
1300
+ "/CLAUDE.md",
1301
+ "/.claude/CLAUDE.md",
1302
+ "/CLAUDE.local.md"
1303
+ ].map((e) => S(e))), $t = 256, en = 65536, tn = 4, nn = 64, rn = 2, an = new TextEncoder(), H = (e, t) => {
1304
+ throw new x({
1305
+ code: "INVALID_SOURCE_DATA",
1306
+ operation: e,
1307
+ path: t,
1308
+ retryable: !1
1309
+ });
1310
+ }, on = (e, t, n, r) => {
1311
+ if (typeof e != "object" || !e) return H(t, n);
1312
+ let i = e, a = i.path, o = i.type, s = i.byteLength, c = i.contentIdentity;
1313
+ if (typeof a != "string" || !b(a)) return H(t, n);
1314
+ let l = S(a);
1315
+ return r !== void 0 && l !== r || o !== "file" && o !== "directory" && o !== "symlink" || (o === "file" ? !Number.isSafeInteger(s) || s < 0 || c !== null && typeof c != "string" : s !== null || c !== null) ? H(t, l) : {
1316
+ byteLength: s,
1317
+ contentIdentity: c,
1318
+ path: l,
1319
+ type: o
1320
+ };
1321
+ }, sn = (e, t) => {
1322
+ if (e === t) return !1;
1323
+ let n = t === C ? C : `${t}/`;
1324
+ return e.startsWith(n);
1325
+ }, U = (e, t, n) => {
1326
+ throw new r({
1327
+ code: "RESOURCE_LIMIT_EXCEEDED",
1328
+ limit: e,
1329
+ limitMaximum: t,
1330
+ nextAction: "reduce-input-or-increase-limit",
1331
+ observedUsage: n,
1332
+ operation: "validate-project"
1333
+ });
1334
+ }, W = (e, t) => {
1335
+ let n = e === void 0 ? t : t === void 0 || t === e ? e : AbortSignal.any([e, t]);
1336
+ return n === void 0 ? void 0 : { signal: n };
1337
+ }, cn = (e, t, n, i) => {
1338
+ let a = new Set(), o = 0, s = 0, c = 0, l = 0, u = (e) => new r({
1339
+ cause: e.reason,
1340
+ code: "ABORTED",
1341
+ operation: "validate-project"
1342
+ }), d = (e) => {
1343
+ if (!Number.isSafeInteger(e) || e < 0 || e > t.maxRetainedBytes - c) return U("maxRetainedBytes", t.maxRetainedBytes, c + e);
1344
+ c += e, s = Math.max(s, c);
1345
+ }, f = (e) => {
1346
+ if (!Number.isSafeInteger(e) || e < 0 || e > t.maxRetainedBytes - c) return U("maxRetainedBytes", t.maxRetainedBytes, c + e);
1347
+ s = Math.max(s, c + e);
1348
+ }, p = (e) => {
1349
+ if (!(e === C || a.has(e))) {
1350
+ if (a.size >= t.maxEntries) return U("maxEntries", t.maxEntries, a.size + 1);
1351
+ d(nn + an.encode(e).byteLength * rn), a.add(e);
1352
+ }
1353
+ }, m = (e) => {
1354
+ let t = n?.aborted ? n : e?.aborted ? e : null;
1355
+ if (t !== null) throw u(t);
1356
+ };
1357
+ m();
1358
+ let h = (e) => {
1359
+ if (e > t.maxTotalBytesRead - l) return U("maxTotalBytesRead", t.maxTotalBytesRead, l + e);
1360
+ l += e;
1361
+ }, g = {
1362
+ readPage: (t, n) => e.readFilePage(t, n),
1363
+ snapshotId: e.snapshot.id
1364
+ }, _ = async (e, t, r) => {
1365
+ let i = S(t);
1366
+ m(r?.signal), p(i);
1367
+ let a = await e.getEntry(i, W(n, r?.signal));
1368
+ return m(r?.signal), a === null ? null : on(a, "get-entry", i, i);
1369
+ }, v = (t, n) => _(e, t, n), b = (r) => {
1370
+ let i = r?.prefix === void 0 ? C : S(r.prefix);
1371
+ return { async *[Symbol.asyncIterator]() {
1372
+ p(i);
1373
+ let a = new Set(), o, s = null;
1374
+ do {
1375
+ m(r?.signal);
1376
+ let c = await e.listEntriesPage({
1377
+ ...o === void 0 ? {} : { cursor: o },
1378
+ maxEntries: Math.min($t, t.maxEntries),
1379
+ prefix: i,
1380
+ ...W(n, r?.signal) ?? {}
1381
+ });
1382
+ if (c.snapshot.id !== e.snapshot.id || c.entries.length === 0 && !c.isComplete) return H("list-entries-page", i);
1383
+ for (let e of c.entries) {
1384
+ m(r?.signal);
1385
+ let t = on(e, "list-entries-page", i);
1386
+ if (!sn(t.path, i) || a.has(t.path) || s !== null && y(s, t.path) >= 0) return H("list-entries-page", t.path);
1387
+ a.add(t.path), s = t.path, p(t.path), yield t;
1388
+ }
1389
+ if (c.isComplete) return c.nextCursor === null ? void 0 : H("list-entries-page", i);
1390
+ if (c.nextCursor === null || c.nextCursor === o) return H("list-entries-page", i);
1391
+ o = c.nextCursor;
1392
+ } while (!0);
1393
+ } };
1394
+ }, w = async (e, r, i = !1, a = g) => {
1395
+ let s = i ? 1 : tn, l = e === Zt ? "maxManifestBytes" : "maxFileBytes", u = t.maxRetainedBytes - c;
1396
+ if (u < 1) return U("maxRetainedBytes", t.maxRetainedBytes, c + 1);
1397
+ let p = Math.min(en, Math.max(1, t[l]), u);
1398
+ f(p);
1399
+ let _ = await a.readPage(e, {
1400
+ maxBytes: p,
1401
+ offset: 0,
1402
+ ...W(n, r) ?? {}
1403
+ });
1404
+ if (m(r), _.snapshot.id !== a.snapshotId || _.offset !== 0 || !(_.bytes instanceof Uint8Array) || !Number.isSafeInteger(_.totalBytes) || _.totalBytes < 0 || _.bytes.byteLength > en || _.bytes.byteLength > _.totalBytes || _.bytes.byteLength === 0 && !_.isComplete) return H("read-file-page", e);
1405
+ if (_.totalBytes > t[l]) return U(l, t[l], _.totalBytes);
1406
+ let v = _.bytes.byteLength, y = t.maxRetainedBytes - c - v;
1407
+ if (y < 0 || _.totalBytes > Math.floor(y / s)) {
1408
+ let e = c + v + _.totalBytes * s;
1409
+ return U("maxRetainedBytes", t.maxRetainedBytes, Number.isSafeInteger(e) ? e : 2 ** 53 - 1);
1410
+ }
1411
+ h(_.totalBytes);
1412
+ let b = _.totalBytes * s;
1413
+ f(b + v), d(b), i || (o += _.totalBytes);
1414
+ let x = new Uint8Array(_.totalBytes), S = 0, C = _, w = !0;
1415
+ for (; w || S < x.byteLength;) {
1416
+ if (w = !1, C.snapshot.id !== a.snapshotId || C.offset !== S || C.totalBytes !== x.byteLength || !(C.bytes instanceof Uint8Array) || C.bytes.byteLength > en || C.bytes.byteLength > x.byteLength - S || C.bytes.byteLength === 0 && !C.isComplete) return H("read-file-page", e);
1417
+ if (x.set(C.bytes, S), S += C.bytes.byteLength, C.isComplete) {
1418
+ if (C.nextOffset !== null || S !== x.byteLength) return H("read-file-page", e);
1419
+ break;
1420
+ }
1421
+ if (C.nextOffset !== S) return H("read-file-page", e);
1422
+ C = await a.readPage(e, {
1423
+ maxBytes: Math.min(en, Math.max(1, x.byteLength - S)),
1424
+ offset: S,
1425
+ ...W(n, r) ?? {}
1426
+ }), m(r);
1427
+ }
1428
+ return x;
1429
+ }, T = async (e, t) => {
1430
+ let r = W(n, t)?.signal;
1431
+ return r === void 0 ? e : new Promise((t, n) => {
1432
+ let i = () => r.removeEventListener("abort", a), a = () => {
1433
+ i(), n(u(r));
1434
+ };
1435
+ r.aborted ? a() : r.addEventListener("abort", a, { once: !0 }), e.then((e) => {
1436
+ i(), t(e);
1437
+ }, (e) => {
1438
+ i(), n(e instanceof Error ? e : new x({
1439
+ cause: e,
1440
+ code: "INVALID_SOURCE_DATA",
1441
+ operation: "read-file-page",
1442
+ path: null,
1443
+ retryable: !1
1444
+ }));
1445
+ });
1446
+ });
1447
+ }, ee = async (e, t) => {
1448
+ let n = S(e);
1449
+ m(t?.signal), p(n);
1450
+ let r = await T(w(n, t?.signal), t?.signal);
1451
+ return m(t?.signal), r.slice();
1452
+ }, E = async (e, t) => {
1453
+ m(), p(e);
1454
+ let n = await T(w(e, void 0, !0, t));
1455
+ m();
1456
+ let r = !1;
1457
+ return {
1458
+ bytes: n,
1459
+ release: () => {
1460
+ r || (c -= n.byteLength), r = !0;
1461
+ }
1462
+ };
1463
+ }, te = (t) => i !== void 0 && Qt.has(t) ? i : e, ne = (t) => {
1464
+ let n = te(t);
1465
+ return n === e ? g : {
1466
+ readPage: (e, t) => n.readFilePage(e, t),
1467
+ snapshotId: n.snapshot.id
1468
+ };
1469
+ }, re = Object.freeze({
1470
+ getEntry: (e, t) => {
1471
+ let n = S(e);
1472
+ return _(te(n), n, t);
1473
+ },
1474
+ readLinkText: async (e, t) => {
1475
+ let r = S(e);
1476
+ m(t?.signal), p(r);
1477
+ let i = await T(te(r).readLinkText(r, W(n, t?.signal)), t?.signal);
1478
+ return m(t?.signal), i !== null && (typeof i != "string" || an.encode(i).byteLength > 4096) ? H("read-link-text", r) : i;
1479
+ },
1480
+ readSourceFile: (e) => {
1481
+ let t = S(e);
1482
+ return E(t, ne(t));
1483
+ }
1484
+ }), ie = Object.freeze({
1485
+ getEntry: v,
1486
+ iterateEntries: b,
1487
+ readCompleteFile: ee
1488
+ });
1489
+ return Jt(ie, {
1490
+ reserve: d,
1491
+ tryReserve: (e) => !Number.isSafeInteger(e) || e < 0 || e > t.maxRetainedBytes - c ? !1 : (d(e), !0),
1492
+ release: (e) => {
1493
+ if (!Number.isSafeInteger(e) || e < 0 || e > c) throw TypeError("The retained-memory release is invalid.");
1494
+ c -= e;
1495
+ },
1496
+ readSourceFile: (e) => E(e, g)
1497
+ }), Object.freeze({
1498
+ getResourceUsage: () => Object.freeze({
1499
+ canonicalBytes: o,
1500
+ peakRetainedBytes: s,
1501
+ retainedBytes: c,
1502
+ totalBytesRead: l
1503
+ }),
1504
+ instructions: re,
1505
+ reader: ie,
1506
+ throwIfAborted: m
1507
+ });
1508
+ }, ln = /^#{1,6} /u, un = (e, t) => {
1509
+ for (let n = t; n < e.length; n += 1) {
1510
+ let t = e[n];
1511
+ if (t !== void 0 && k(t)) return n;
1512
+ }
1513
+ return null;
1514
+ }, dn = (e, t, n) => {
1515
+ let r = d(n, "validate-project"), i = le(e.content), a = O(i);
1516
+ a === 0 && r.add({
1517
+ code: "MOLDEA_AGENT_DESCRIPTION_INVALID",
1518
+ details: { reason: "empty" },
1519
+ entity: { agentId: t },
1520
+ path: e.path
1521
+ }), a > 1e3 && r.add({
1522
+ code: "MOLDEA_AGENT_DESCRIPTION_INVALID",
1523
+ details: { reason: "too-long" },
1524
+ entity: { agentId: t },
1525
+ path: e.path
1526
+ });
1527
+ let o = r.finalize();
1528
+ return m({
1529
+ description: o.length === 0 ? {
1530
+ asset: e,
1531
+ scalarLength: a,
1532
+ value: i
1533
+ } : null,
1534
+ diagnostics: o,
1535
+ valid: o.length === 0
1536
+ });
1537
+ }, fn = (e, t, n) => {
1538
+ let r = d(n, "validate-project");
1539
+ if (!k(e.content)) return r.add({
1540
+ code: "MOLDEA_AGENT_INSTRUCTION_EMPTY",
1541
+ entity: { agentId: t },
1542
+ path: e.path
1543
+ }), m({
1544
+ diagnostics: r.finalize(),
1545
+ instruction: null,
1546
+ valid: !1
1547
+ });
1548
+ let i = `\`${t}\``, a = e.content.split("\n"), o = un(a, 0), s = o;
1549
+ o !== null && ln.test(a[o] ?? "") && (s = un(a, o + 1)), (s === null || !(a[s] ?? "").includes(i)) && r.add({
1550
+ code: "MOLDEA_AGENT_IDENTITY_INVALID",
1551
+ details: { reason: e.content.includes(i) ? "misplaced" : "missing" },
1552
+ entity: { agentId: t },
1553
+ path: e.path
1554
+ });
1555
+ let c = r.finalize();
1556
+ return m({
1557
+ diagnostics: c,
1558
+ instruction: e,
1559
+ valid: c.length === 0
1560
+ });
1561
+ }, pn = (e) => {
1562
+ throw new x({
1563
+ code: "INVALID_SOURCE_DATA",
1564
+ operation: "read-file-page",
1565
+ path: e,
1566
+ retryable: !1
1567
+ });
1568
+ }, G = async (e, t, n, r) => {
1569
+ let i = await e.readCompleteFile(t, r === void 0 ? void 0 : { signal: r });
1570
+ if (!(i instanceof Uint8Array)) return pn(t);
1571
+ let a = M({
1572
+ content: i,
1573
+ path: t
1574
+ }, n, "validate-project");
1575
+ if (!a.valid || a.text === null) return m({
1576
+ asset: null,
1577
+ diagnostics: a.diagnostics,
1578
+ valid: !1
1579
+ });
1580
+ let o = {
1581
+ content: a.text.value,
1582
+ digest: await N(a.text),
1583
+ path: t,
1584
+ scalarLength: a.text.scalarLength,
1585
+ utf8ByteLength: a.text.utf8ByteLength
1586
+ };
1587
+ return m({
1588
+ asset: o,
1589
+ diagnostics: [],
1590
+ valid: !0
1591
+ });
1592
+ }, mn = (e, t) => {
1593
+ for (let n of t) e.merge(n);
1594
+ }, hn = (e, t) => {
1595
+ let n = e;
1596
+ for (; n.length > 0;) {
1597
+ if (t.has(n)) return !0;
1598
+ let e = n.lastIndexOf("/");
1599
+ if (e <= 0) return !1;
1600
+ n = n.slice(0, e);
1601
+ }
1602
+ return !1;
1603
+ }, gn = async (e, t, n, r, i, a) => {
1604
+ let o = await G(e, t, r.limits, a);
1605
+ if (mn(i, o.diagnostics), o.asset === null) return null;
1606
+ let s = dn(o.asset, n, r.limits);
1607
+ return mn(i, s.diagnostics), s.description;
1608
+ }, _n = async (e, t, n, r, i, a) => {
1609
+ let o = await G(e, t, r.limits, a);
1610
+ if (mn(i, o.diagnostics), o.asset === null) return null;
1611
+ let s = fn(o.asset, n, r.limits);
1612
+ return mn(i, s.diagnostics), s.instruction;
1613
+ }, vn = async (e, t, n, r, i) => {
1614
+ r = a(r);
1615
+ let o = d(r.limits, "validate-project"), s = [], c = t.agents ?? {}, l = new Set(Object.keys(c)), f = new Map(n.inventory.agents.map((e) => [e.id, e])), p = new Set(n.diagnostics.flatMap((e) => e.path === null ? [] : [e.path]));
1616
+ for (let e of n.inventory.agents) l.has(e.id) || o.add({
1617
+ code: "MOLDEA_AGENT_DIRECTORY_UNREGISTERED",
1618
+ entity: { agentId: e.id },
1619
+ path: e.path
1620
+ });
1621
+ for (let t of [...l].sort(u)) {
1622
+ let n = c[t];
1623
+ if (n === void 0) continue;
1624
+ let a = f.get(t);
1625
+ if (a === void 0) {
1626
+ let e = S(`/moldea/agents/${t}`);
1627
+ hn(e, p) || o.add({
1628
+ code: "MOLDEA_AGENT_DIRECTORY_MISSING",
1629
+ entity: { agentId: t },
1630
+ path: e
1631
+ }), s.push({
1632
+ declaration: n,
1633
+ description: null,
1634
+ id: t,
1635
+ instruction: null
1636
+ });
1637
+ continue;
1638
+ }
1639
+ let l = null, u = null;
1640
+ if (a.description === null) {
1641
+ let e = S(`${a.path}/description.md`);
1642
+ hn(e, p) || o.add({
1643
+ code: "MOLDEA_AGENT_DESCRIPTION_MISSING",
1644
+ entity: { agentId: t },
1645
+ path: e
1646
+ });
1647
+ } else l = await gn(e, a.description, t, r, o, i);
1648
+ if (a.instruction === null) {
1649
+ let e = S(`${a.path}/instruction.md`);
1650
+ hn(e, p) || o.add({
1651
+ code: "MOLDEA_AGENT_INSTRUCTION_MISSING",
1652
+ entity: { agentId: t },
1653
+ path: e
1654
+ });
1655
+ } else u = await _n(e, a.instruction, t, r, o, i);
1656
+ s.push({
1657
+ declaration: n,
1658
+ description: l,
1659
+ id: t,
1660
+ instruction: u
1661
+ });
1662
+ }
1663
+ let h = o.finalize();
1664
+ return m({
1665
+ agents: s,
1666
+ diagnostics: h,
1667
+ valid: h.length === 0
1668
+ });
1669
+ }, yn = /^\/moldea\/agents\/([^/]+)\/(description|instruction)\.md$/u, bn = /^\/moldea\/agents\/([^/]+)$/u, xn = /^\/moldea\/decisions\/[^/]+\.md$/u, Sn = (e) => {
1670
+ if (e === "/moldea/moldea.yaml") return {
1671
+ agentId: null,
1672
+ fileKind: "manifest",
1673
+ kind: "canonical-file"
1674
+ };
1675
+ if (e === "/moldea/project.md") return {
1676
+ agentId: null,
1677
+ fileKind: "project",
1678
+ kind: "canonical-file"
1679
+ };
1680
+ if (he(e, !1)) return {
1681
+ agentId: null,
1682
+ fileKind: "context",
1683
+ kind: "canonical-file"
1684
+ };
1685
+ if (xn.test(e)) return {
1686
+ agentId: null,
1687
+ fileKind: "decision",
1688
+ kind: "canonical-file"
1689
+ };
1690
+ let t = yn.exec(e);
1691
+ if (t === null) return null;
1692
+ let n = t[1], r = t[2];
1693
+ return n === void 0 || r === void 0 ? null : {
1694
+ agentId: n,
1695
+ fileKind: r === "description" ? "agent-description" : "agent-instruction",
1696
+ kind: "canonical-file"
1697
+ };
1698
+ }, Cn = (e) => bn.exec(e)?.[1] ?? null, wn = (e) => e === "/moldea" || e === "/moldea/context" || e === "/moldea/decisions" || e === "/moldea/agents", Tn = (e) => wn(e) || e.startsWith("/moldea/context/"), En = (e) => {
1699
+ let t = Sn(e.path);
1700
+ if (t !== null) return e.type === "file" ? t : e.type === "symlink" ? { kind: "canonical-asset-symlink" } : {
1701
+ expectedType: "file",
1702
+ kind: "entry-type-invalid"
1703
+ };
1704
+ let n = Cn(e.path);
1705
+ return n === null ? wn(e.path) ? e.type === "directory" ? { kind: "structural-directory" } : {
1706
+ expectedType: "directory",
1707
+ kind: "entry-type-invalid"
1708
+ } : e.type === "directory" ? Tn(e.path) ? { kind: "structural-directory" } : { kind: "ignored-directory" } : { kind: "unrecognized" } : e.type === "directory" ? {
1709
+ agentId: n,
1710
+ kind: "agent-directory"
1711
+ } : {
1712
+ expectedType: "directory",
1713
+ kind: "entry-type-invalid"
1714
+ };
1715
+ }, Dn = S("/moldea"), K = S("/moldea/moldea.yaml"), q = S("/moldea/project.md"), On = () => ({
1716
+ agents: new Map(),
1717
+ context: new Set(),
1718
+ decisions: new Set(),
1719
+ manifest: null,
1720
+ project: null
1721
+ }), J = (e, t) => {
1722
+ throw new x({
1723
+ code: "INVALID_SOURCE_DATA",
1724
+ operation: e,
1725
+ path: t,
1726
+ retryable: !1
1727
+ });
1728
+ }, kn = (e, t, n) => {
1729
+ if (typeof e != "object" || !e) return J(t, n ?? null);
1730
+ let r = e, i = r.path, a = r.type, o = r.byteLength, s = r.contentIdentity;
1731
+ if (typeof i != "string" || !b(i)) return J(t, n ?? null);
1732
+ let c = S(i);
1733
+ return n !== void 0 && c !== n || a !== "file" && a !== "directory" && a !== "symlink" || (a === "file" ? !Number.isSafeInteger(o) || o < 0 || s !== null && typeof s != "string" : o !== null || s !== null) ? J(t, c) : {
1734
+ byteLength: o,
1735
+ contentIdentity: s,
1736
+ path: c,
1737
+ type: a
1738
+ };
1739
+ }, An = async (e, t, n) => {
1740
+ let r = await e.getEntry(t, n === void 0 ? void 0 : { signal: n });
1741
+ return r === null ? null : kn(r, "get-entry", t);
1742
+ }, jn = (e, t, n) => {
1743
+ e.add({
1744
+ code: "MOLDEA_ENTRY_TYPE_INVALID",
1745
+ details: {
1746
+ actualType: t.type,
1747
+ expectedType: n
1748
+ },
1749
+ path: t.path
1750
+ });
1751
+ }, Mn = (e, t) => {
1752
+ let n = e.get(t);
1753
+ if (n !== void 0) return n;
1754
+ let r = {
1755
+ description: null,
1756
+ id: t,
1757
+ instruction: null,
1758
+ path: S(`/moldea/agents/${t}`)
1759
+ };
1760
+ return e.set(t, r), r;
1761
+ }, Nn = (e, t, n, r) => {
1762
+ switch (n) {
1763
+ case "manifest":
1764
+ e.manifest = t;
1765
+ return;
1766
+ case "project":
1767
+ e.project = t;
1768
+ return;
1769
+ case "context":
1770
+ e.context.add(t);
1771
+ return;
1772
+ case "decision":
1773
+ e.decisions.add(t);
1774
+ return;
1775
+ }
1776
+ if (r === null) return J("list-entries-page", t);
1777
+ let i = Mn(e.agents, r);
1778
+ n === "agent-description" ? i.description = t : i.instruction = t;
1779
+ }, Pn = (e) => {
1780
+ let t = (e) => [...e].sort(u), n = [...e.agents.values()].sort((e, t) => u(e.id, t.id)).map((e) => m({ ...e }));
1781
+ return m({
1782
+ agents: n,
1783
+ context: t(e.context),
1784
+ decisions: t(e.decisions),
1785
+ manifest: e.manifest,
1786
+ project: e.project
1787
+ });
1788
+ }, Fn = (e, t) => {
1789
+ let n = t.finalize();
1790
+ return m({
1791
+ diagnostics: n,
1792
+ inventory: Pn(e),
1793
+ valid: n.length === 0
1794
+ });
1795
+ }, In = (e, t, n, r, i) => {
1796
+ if (e === null) {
1797
+ i.add({
1798
+ code: n,
1799
+ path: t
1800
+ });
1801
+ return;
1802
+ }
1803
+ if (e.type === "file") {
1804
+ t === K ? r.manifest = t : r.project = t;
1805
+ return;
1806
+ }
1807
+ if (e.type === "symlink") {
1808
+ i.add({
1809
+ code: "MOLDEA_CANONICAL_ASSET_SYMLINK",
1810
+ path: t
1811
+ });
1812
+ return;
1813
+ }
1814
+ jn(i, e, "file");
1815
+ }, Ln = (e, t) => {
1816
+ if (t === null || t.type !== e.type) return J("list-entries-page", e.path);
1817
+ }, Rn = async (e, t, n, r) => {
1818
+ let i = d(t, "validate-project"), a = On(), o = r === void 0 ? await An(e, Dn, n) : r.moldeaRoot;
1819
+ if (o === null) return i.add({
1820
+ code: "MOLDEA_MANIFEST_MISSING",
1821
+ path: K
1822
+ }), i.add({
1823
+ code: "MOLDEA_PROJECT_FILE_MISSING",
1824
+ path: q
1825
+ }), Fn(a, i);
1826
+ if (o.type !== "directory") return jn(i, o, "directory"), Fn(a, i);
1827
+ let s = r === void 0 ? await An(e, K, n) : r.manifest, c = r === void 0 ? await An(e, q, n) : r.project;
1828
+ In(s, K, "MOLDEA_MANIFEST_MISSING", a, i), In(c, q, "MOLDEA_PROJECT_FILE_MISSING", a, i);
1829
+ let l = new Set(), u = !1, f = !1, p = n === void 0 ? { prefix: Dn } : {
1830
+ prefix: Dn,
1831
+ signal: n
1832
+ };
1833
+ for await (let t of e.iterateEntries(p)) {
1834
+ let e = kn(t, "list-entries-page");
1835
+ if (!e.path.startsWith("/moldea/") || l.has(e.path)) return J("list-entries-page", e.path);
1836
+ if (l.add(e.path), e.path === K) {
1837
+ Ln(e, s), u = !0;
1838
+ continue;
1839
+ }
1840
+ if (e.path === q) {
1841
+ Ln(e, c), f = !0;
1842
+ continue;
1843
+ }
1844
+ let n = En(e);
1845
+ switch (n.kind) {
1846
+ case "canonical-file":
1847
+ Nn(a, e.path, n.fileKind, n.agentId);
1848
+ break;
1849
+ case "agent-directory":
1850
+ Mn(a.agents, n.agentId);
1851
+ break;
1852
+ case "canonical-asset-symlink":
1853
+ i.add({
1854
+ code: "MOLDEA_CANONICAL_ASSET_SYMLINK",
1855
+ path: e.path
1856
+ });
1857
+ break;
1858
+ case "entry-type-invalid":
1859
+ jn(i, e, n.expectedType);
1860
+ break;
1861
+ case "unrecognized": i.add({
1862
+ code: "MOLDEA_CANONICAL_PATH_UNRECOGNIZED",
1863
+ details: { entryType: e.type },
1864
+ path: e.path
1865
+ });
1866
+ }
1867
+ }
1868
+ return s !== null === u ? c !== null === f ? Fn(a, i) : J("list-entries-page", q) : J("list-entries-page", K);
1869
+ }, zn = (e) => [...e].sort((e, t) => u(e.path, t.path)), Bn = (e) => {
1870
+ let t = new Map();
1871
+ for (let n of zn(e)) {
1872
+ if (n.id === null) continue;
1873
+ let e = t.get(n.id) ?? [];
1874
+ e.push(n), t.set(n.id, e);
1875
+ }
1876
+ let n = new Map(), r = new Map();
1877
+ for (let e of [...t.keys()].sort(u)) {
1878
+ let i = t.get(e) ?? [];
1879
+ if (n.set(e, i), i.length === 1 && i[0]?.decision !== null) {
1880
+ let t = i[0]?.decision;
1881
+ t !== void 0 && r.set(e, t);
1882
+ }
1883
+ }
1884
+ let i = new Map();
1885
+ for (let [e, t] of r) {
1886
+ let r = t.supersedes.filter((e) => {
1887
+ let t = n.get(e);
1888
+ return t?.length === 1 && t[0]?.decision !== null;
1889
+ });
1890
+ i.set(e, r);
1891
+ }
1892
+ return {
1893
+ candidateGroups: n,
1894
+ edges: i,
1895
+ nodes: r
1896
+ };
1897
+ }, Vn = (e, t) => {
1898
+ for (let [n, r] of e.candidateGroups) if (!(r.length < 2)) for (let e of r) t.add({
1899
+ code: "MOLDEA_DECISION_ID_DUPLICATE",
1900
+ details: { occurrences: r.length },
1901
+ entity: { decisionId: n },
1902
+ path: e.path
1903
+ });
1904
+ }, Hn = (e, t) => {
1905
+ for (let n of e.nodes.values()) for (let r of n.supersedes) e.candidateGroups.has(r) || t.add({
1906
+ code: "MOLDEA_DECISION_REFERENCE_MISSING",
1907
+ details: { referencedDecisionId: r },
1908
+ entity: { decisionId: n.id },
1909
+ path: n.path,
1910
+ pointer: "/supersedes"
1911
+ });
1912
+ }, Un = (e, t) => {
1913
+ let n = new Set();
1914
+ for (let r of e.nodes.values()) if (r.status === "accepted" || r.status === "superseded") for (let i of e.edges.get(r.id) ?? []) {
1915
+ let a = e.nodes.get(i);
1916
+ if (a !== void 0) {
1917
+ if (a.status === "superseded") {
1918
+ n.add(i);
1919
+ continue;
1920
+ }
1921
+ t.add({
1922
+ code: "MOLDEA_DECISION_SUPERSESSION_STATUS_INVALID",
1923
+ details: {
1924
+ referencedDecisionId: i,
1925
+ sourceStatus: r.status,
1926
+ targetStatus: a.status
1927
+ },
1928
+ entity: { decisionId: r.id },
1929
+ path: r.path,
1930
+ pointer: "/supersedes"
1931
+ });
1932
+ }
1933
+ }
1934
+ return n;
1935
+ }, Wn = (e, t, n) => {
1936
+ for (let r of e.nodes.values()) r.status === "superseded" && !t.has(r.id) && n.add({
1937
+ code: "MOLDEA_DECISION_SUPERSEDED_ORPHAN",
1938
+ entity: { decisionId: r.id },
1939
+ path: r.path
1940
+ });
1941
+ }, Gn = (e) => {
1942
+ let t = new Set(), n = [];
1943
+ for (let r of e.nodes.keys()) {
1944
+ if (t.has(r)) continue;
1945
+ let i = [{
1946
+ id: r,
1947
+ nextNeighbor: 0
1948
+ }];
1949
+ for (t.add(r); i.length > 0;) {
1950
+ let r = i.at(-1);
1951
+ if (r === void 0) break;
1952
+ let a = (e.edges.get(r.id) ?? [])[r.nextNeighbor];
1953
+ if (a === void 0) {
1954
+ n.push(r.id), i.pop();
1955
+ continue;
1956
+ }
1957
+ r.nextNeighbor += 1, t.has(a) || (t.add(a), i.push({
1958
+ id: a,
1959
+ nextNeighbor: 0
1960
+ }));
1961
+ }
1962
+ }
1963
+ return n;
1964
+ }, Kn = (e) => {
1965
+ let t = new Map();
1966
+ for (let n of e.nodes.keys()) t.set(n, []);
1967
+ for (let [n, r] of e.edges) for (let e of r) t.get(e)?.push(n);
1968
+ for (let e of t.values()) e.sort(u);
1969
+ return t;
1970
+ }, qn = (e) => {
1971
+ let t = Kn(e), n = new Set(), r = [];
1972
+ for (let i of [...Gn(e)].reverse()) {
1973
+ if (n.has(i)) continue;
1974
+ let e = [], a = [i];
1975
+ for (n.add(i); a.length > 0;) {
1976
+ let r = a.pop();
1977
+ if (r === void 0) break;
1978
+ e.push(r);
1979
+ for (let e of [...t.get(r) ?? []].reverse()) n.has(e) || (n.add(e), a.push(e));
1980
+ }
1981
+ r.push(e.sort(u));
1982
+ }
1983
+ return r.sort((e, t) => u(e[0] ?? "", t[0] ?? ""));
1984
+ }, Jn = (e, t) => {
1985
+ for (let n of qn(e)) {
1986
+ if (n.length < 2) continue;
1987
+ let r = n[0];
1988
+ if (r !== void 0) for (let i of n) {
1989
+ let a = e.nodes.get(i);
1990
+ a !== void 0 && t.add({
1991
+ code: "MOLDEA_DECISION_SUPERSESSION_CYCLE",
1992
+ details: {
1993
+ cycleRepresentativeDecisionId: r,
1994
+ cycleSize: n.length
1995
+ },
1996
+ entity: { decisionId: i },
1997
+ path: a.path,
1998
+ pointer: "/supersedes"
1999
+ });
2000
+ }
2001
+ }
2002
+ }, Yn = (e, t) => {
2003
+ let n = d(t, "validate-project"), r = Bn(e);
2004
+ return Vn(r, n), Hn(r, n), Jn(r, n), Wn(r, Un(r, n), n), n.finalize();
2005
+ }, Xn = (e) => {
2006
+ throw new x({
2007
+ code: "INVALID_SOURCE_DATA",
2008
+ operation: "read-file-page",
2009
+ path: e,
2010
+ retryable: !1
2011
+ });
2012
+ }, Zn = (e) => [...e].sort((e, t) => u(e.id, t.id) || u(e.path, t.path)), Qn = async (e, t, n, r, i) => {
2013
+ n = a(n);
2014
+ let o = d(n.limits, "validate-project"), s = [], c = [], l = r === void 0 ? void 0 : { signal: r };
2015
+ for (let r of [...t].sort(u)) {
2016
+ let t = await e.readCompleteFile(r, l);
2017
+ if (!(t instanceof Uint8Array)) return Xn(r);
2018
+ let a = await Vt({
2019
+ content: t.slice(),
2020
+ path: r
2021
+ }, n, "validate-project");
2022
+ a.decision !== null && a.yamlRoot !== null && i?.(r, a.yamlRoot);
2023
+ for (let e of a.diagnostics) o.merge(e);
2024
+ s.push({
2025
+ decision: a.decision,
2026
+ id: j(r),
2027
+ path: r
2028
+ }), a.decision !== null && c.push(a.decision);
2029
+ }
2030
+ for (let e of Yn(s, n.limits)) o.merge(e);
2031
+ let f = o.finalize();
2032
+ return m({
2033
+ decisions: Zn(c),
2034
+ diagnostics: f,
2035
+ valid: f.length === 0
2036
+ });
2037
+ }, $n = (e, t) => {
2038
+ let n = j(e);
2039
+ return {
2040
+ ...t === void 0 ? {} : { agentId: t },
2041
+ ...n === null ? {} : { decisionId: n }
2042
+ };
2043
+ }, er = (e, t, n, r, i) => {
2044
+ n.has(e) || r.blockedPaths.has(e) || r.collector.add({
2045
+ code: "MOLDEA_REFERENCE_MISSING",
2046
+ details: { referencedPath: e },
2047
+ entity: i === void 0 ? null : { agentId: i },
2048
+ path: r.manifestPath,
2049
+ pointer: t
2050
+ });
2051
+ }, tr = (e, t, n, r) => {
2052
+ if (!n.discoveredDecisionPaths.has(e)) {
2053
+ if (n.blockedPaths.has(e)) return;
2054
+ n.collector.add({
2055
+ code: "MOLDEA_DECISION_REFERENCE_MISSING",
2056
+ details: { referencedPath: e },
2057
+ entity: $n(e, r),
2058
+ path: n.manifestPath,
2059
+ pointer: t
2060
+ });
2061
+ return;
2062
+ }
2063
+ let i = n.parsedDecisionsByPath.get(e);
2064
+ i !== void 0 && i.status !== "accepted" && n.collector.add({
2065
+ code: "MOLDEA_DECISION_RELATIONSHIP_INACTIVE",
2066
+ details: {
2067
+ referencedPath: e,
2068
+ targetStatus: i.status
2069
+ },
2070
+ entity: $n(e, r),
2071
+ path: n.manifestPath,
2072
+ pointer: t
2073
+ });
2074
+ }, nr = (e, t, n, r, i) => {
2075
+ let a = d(i, "validate-project"), o = new Set(n.inventory.context), s = new Set(o);
2076
+ n.inventory.project !== null && s.add(n.inventory.project);
2077
+ let c = {
2078
+ blockedPaths: new Set(n.diagnostics.flatMap((e) => e.path === null ? [] : [e.path])),
2079
+ collector: a,
2080
+ discoveredDecisionPaths: new Set(n.inventory.decisions),
2081
+ manifestPath: e,
2082
+ parsedDecisionsByPath: new Map(r.map((e) => [e.path, e])),
2083
+ validAgentContextPaths: o,
2084
+ validTopLevelContextPaths: s
2085
+ };
2086
+ for (let e of Object.keys(t.context ?? {}).sort(u)) er(S(e), `/context/${g(e)}`, c.validTopLevelContextPaths, c);
2087
+ for (let e of Object.keys(t.decisions ?? {}).sort(u)) tr(S(e), `/decisions/${g(e)}`, c);
2088
+ for (let e of Object.keys(t.agents ?? {}).sort(u)) {
2089
+ let n = t.agents?.[e];
2090
+ if (n === void 0) continue;
2091
+ let r = g(e);
2092
+ for (let [t, i] of (n.context ?? []).entries()) er(i, `/agents/${r}/context/${t}`, c.validAgentContextPaths, c, e);
2093
+ for (let [t, i] of (n.decisions ?? []).entries()) tr(i, `/agents/${r}/decisions/${t}`, c, e);
2094
+ }
2095
+ return a.finalize();
2096
+ }, Y = {
2097
+ start: "<!-- moldea:start -->",
2098
+ end: "<!-- moldea:end -->"
2099
+ }, rr = (t) => {
2100
+ try {
2101
+ let e = ne(t.replace(/(<!-- moldea:(?:start|end) -->)[ \t]+(?=\r?$)/gmu, "$1"), Y);
2102
+ if (e === null) return "block-missing";
2103
+ let n = t.indexOf(Y.start), r = t.indexOf("\n", t.indexOf(Y.end));
2104
+ return {
2105
+ start: n,
2106
+ end: r === -1 ? t.length : r + 1,
2107
+ lineEnding: e.lineEnding
2108
+ };
2109
+ } catch (t) {
2110
+ if (n(t, e.INVALID_MARKED_REGION)) return "block-invalid";
2111
+ throw t;
2112
+ }
2113
+ }, ir = (e) => {
2114
+ let t = e.replaceAll("\r\n", "\n").replace(/(<!-- moldea:(?:start|end) -->)[ \t]+(?=\n|$)/gu, "$1");
2115
+ if (!t.startsWith(`${Y.start}\n`) || !(t.endsWith(Y.end) || t.endsWith(`${Y.end}\n`))) return t;
2116
+ let n = Y.start.length, r = t.lastIndexOf(Y.end);
2117
+ for (; n < r && t[n] === "\n";) n++;
2118
+ for (; r > n && t[r - 1] === "\n";) r--;
2119
+ return `${Y.start}\n${t.slice(n, r)}\n${Y.end}`;
2120
+ }, ar = (e) => {
2121
+ let t = rr(e);
2122
+ if (typeof t == "string") return {
2123
+ kind: "missing",
2124
+ reason: t
2125
+ };
2126
+ let n = e.slice(t.start, t.end).matchAll(/^node "<repo-root>\/([^"\r\n]+)\/scripts\/relevance-gate\.mjs"(?=[ \t\r]|$)([^\r\n]*)/gm), r = new Map();
2127
+ for (let e of n) {
2128
+ let t = e[1], n = /(?:^|[ \t])--adoption-only(?:[ \t]|$)/u.test(e[2] ?? "") ? "adoption" : "paths";
2129
+ if (t === void 0 || r.has(n)) return {
2130
+ kind: "missing",
2131
+ reason: "skill-path-missing"
2132
+ };
2133
+ r.set(n, t);
2134
+ }
2135
+ let i = r.get("paths") ?? r.get("adoption");
2136
+ return r.size === 0 || r.size === 2 && r.get("adoption") !== i ? {
2137
+ kind: "missing",
2138
+ reason: "skill-path-missing"
2139
+ } : i === void 0 || !/^[A-Za-z0-9._/-]+$/.test(i) || i.startsWith("/") || i.endsWith("/") || i.includes("//") || /(?:^|\/)\.{1,2}(?:\/|$)/.test(i) ? {
2140
+ kind: "missing",
2141
+ reason: "skill-path-invalid"
2142
+ } : {
2143
+ kind: "found",
2144
+ skillPath: i
2145
+ };
2146
+ }, or = new Set(["@AGENTS.md", "@./AGENTS.md"]), sr = new Set(["@../AGENTS.md"]), cr = (e, t) => {
2147
+ let n = t ? sr : or, r = null;
2148
+ for (let t of e.replace(/^\uFEFF/u, "").split(/\r\n|\n|\r/u)) {
2149
+ let e = t.replace(/^[ \t]+|[ \t]+$/gu, ""), i = /^(`{3,}|~{3,})/u.exec(e)?.[1];
2150
+ if (r !== null) i !== void 0 && i[0] === r[0] && i.length >= r.length && (r = null);
2151
+ else if (i !== void 0) r = i;
2152
+ else if (n.has(e)) return !0;
2153
+ }
2154
+ return !1;
2155
+ }, lr = async (e, t) => {
2156
+ let n = await t(), r = n.bytes.byteLength * 8, i = !1;
2157
+ try {
2158
+ e.reserve(r), i = !0;
2159
+ let t;
2160
+ try {
2161
+ t = new TextDecoder("utf-8", { fatal: !0 }).decode(n.bytes);
2162
+ } catch {
2163
+ t = null;
2164
+ }
2165
+ return {
2166
+ text: t,
2167
+ release: () => e.release(r)
2168
+ };
2169
+ } catch (t) {
2170
+ throw i && e.release(r), t;
2171
+ } finally {
2172
+ n.release();
2173
+ }
2174
+ }, ur = (e) => e instanceof x ? e.code === "ENTRY_NOT_FOUND" ? "missing" : e.code === "ENTRY_NOT_FILE" ? "non-regular" : null : null, dr = S("/AGENTS.md"), fr = (e, t) => e("MOLDEA_INTEGRATION_LINK_UNRESOLVED", {
2175
+ entryKind: "symlink",
2176
+ reason: t
2177
+ }, t), pr = async (e, t, n, r) => {
2178
+ let { ledger: i, reader: a, signal: o } = e, s;
2179
+ try {
2180
+ s = await lr(i, n);
2181
+ } catch (e) {
2182
+ let n = ur(e);
2183
+ if (n === null) throw e;
2184
+ return r.entryKind === "symlink" ? fr(t, n === "missing" ? "missing" : "not-file") : t("MOLDEA_INTEGRATION_BLOCK_MISSING", { entryKind: n });
2185
+ }
2186
+ try {
2187
+ if (s.text === null) return t("MOLDEA_INTEGRATION_BLOCK_MISSING", {
2188
+ ...r,
2189
+ reason: "invalid-utf8"
2190
+ });
2191
+ let e = ar(s.text);
2192
+ if (e.kind === "missing") return t(e.reason.startsWith("block-") ? "MOLDEA_INTEGRATION_BLOCK_MISSING" : "MOLDEA_INTEGRATION_SKILL_MISSING", {
2193
+ ...r,
2194
+ reason: e.reason
2195
+ });
2196
+ let { skillPath: n } = e;
2197
+ for (let e of ["SKILL.md", "scripts/relevance-gate.mjs"]) {
2198
+ let r = S(`/${n}/${e}`), i = await a.getEntry(r, o === void 0 ? void 0 : { signal: o });
2199
+ if (i?.type !== "file") return t("MOLDEA_INTEGRATION_SKILL_MISSING", {
2200
+ referencedPath: `/${n}`,
2201
+ missingFile: r,
2202
+ entryKind: i?.type ?? "missing"
2203
+ });
2204
+ }
2205
+ let c = S(`/${n}/assets/managed-agents-block.md`), l;
2206
+ try {
2207
+ l = await lr(i, () => i.readSourceFile(c));
2208
+ } catch (e) {
2209
+ let r = ur(e);
2210
+ if (r !== null) return t("MOLDEA_INTEGRATION_SKILL_MISSING", {
2211
+ referencedPath: `/${n}`,
2212
+ missingFile: c,
2213
+ entryKind: r
2214
+ });
2215
+ throw e;
2216
+ }
2217
+ try {
2218
+ if (l.text === null) return t("MOLDEA_INTEGRATION_BLOCK_STALE", {
2219
+ referencedPath: `/${n}`,
2220
+ reason: "invalid-utf8-asset"
2221
+ });
2222
+ let e = rr(s.text), r = 0, a = 0;
2223
+ for (; (a = l.text.indexOf("{{skill-path}}", a)) !== -1;) r++, a += 14;
2224
+ let o = (l.text.length + r * n.length) * 8;
2225
+ i.reserve(o);
2226
+ try {
2227
+ let r = ir(l.text.replaceAll("{{skill-path}}", n).replace(/\r\n?/gu, "\n"));
2228
+ if (ir(s.text.slice(e.start, e.end)) !== r) return t("MOLDEA_INTEGRATION_BLOCK_STALE", { referencedPath: `/${n}` });
2229
+ } finally {
2230
+ i.release(o);
2231
+ }
2232
+ } finally {
2233
+ l.release();
2234
+ }
2235
+ } finally {
2236
+ s.release();
2237
+ }
2238
+ }, mr = async (e) => {
2239
+ let { instructions: t } = e, n = (t, n, r) => e.report(t, dr, n, r), r = await t.getEntry(dr);
2240
+ if (r === null) return n("MOLDEA_INTEGRATION_BLOCK_MISSING", { entryKind: "missing" }), { kind: "missing" };
2241
+ if (r.type === "directory") return n("MOLDEA_INTEGRATION_BLOCK_MISSING", { entryKind: "directory" }), { kind: "directory" };
2242
+ if (r.type === "file") return await pr(e, n, () => t.readSourceFile(dr), { entryKind: "file" }), { kind: "file" };
2243
+ let i = await T(t, dr);
2244
+ if (i.state === "file") {
2245
+ let { targetPath: r } = i;
2246
+ await pr(e, n, () => t.readSourceFile(r), { entryKind: "symlink" });
2247
+ } else fr(n, i.state);
2248
+ return {
2249
+ kind: "link",
2250
+ resolution: i
2251
+ };
2252
+ }, hr = S("/AGENTS.md"), gr = S("/CLAUDE.md"), _r = S("/.claude/CLAUDE.md"), vr = S("/CLAUDE.local.md"), yr = (e) => e.kind === "file" ? hr : e.kind === "link" && e.resolution.state === "file" ? e.resolution.targetPath : null, br = (e, t, n) => {
2253
+ let r = yr(n);
2254
+ return n.kind === "link" && r === e || t?.state === "file" && t.targetPath === r;
2255
+ }, xr = async (e, t, n) => {
2256
+ let { instructions: r, ledger: i } = e, a = await r.getEntry(t);
2257
+ if (a === null) return { kind: "absent" };
2258
+ if (br(t, null, n)) return { kind: "loads" };
2259
+ if (a.type === "directory") return {
2260
+ entryKind: "directory",
2261
+ kind: "not-loading"
2262
+ };
2263
+ let o = () => r.readSourceFile(t);
2264
+ if (a.type === "symlink") {
2265
+ let e = await T(r, t);
2266
+ if (br(t, e, n)) return { kind: "loads" };
2267
+ if (e.state !== "file") return {
2268
+ kind: "unresolved",
2269
+ reason: e.state
2270
+ };
2271
+ let { targetPath: i } = e;
2272
+ o = () => r.readSourceFile(i);
2273
+ }
2274
+ let s;
2275
+ try {
2276
+ s = await lr(i, o);
2277
+ } catch (e) {
2278
+ let t = ur(e);
2279
+ if (t === null) throw e;
2280
+ return a.type === "symlink" ? {
2281
+ kind: "unresolved",
2282
+ reason: t === "missing" ? "missing" : "not-file"
2283
+ } : { kind: "absent" };
2284
+ }
2285
+ try {
2286
+ return s.text !== null && cr(s.text, t === _r) ? { kind: "loads" } : {
2287
+ entryKind: a.type,
2288
+ kind: "not-loading"
2289
+ };
2290
+ } finally {
2291
+ s.release();
2292
+ }
2293
+ }, Sr = async (e, t) => {
2294
+ let n = [];
2295
+ for (let r of [gr, _r]) {
2296
+ let i = await xr(e, r, t);
2297
+ if (i.kind === "loads") return;
2298
+ i.kind !== "absent" && n.push({
2299
+ assessment: i,
2300
+ path: r
2301
+ });
2302
+ }
2303
+ if (n.length === 0) {
2304
+ let r = await xr(e, vr, t);
2305
+ if (r.kind === "absent" || r.kind === "loads") return;
2306
+ n.push({
2307
+ assessment: r,
2308
+ path: vr
2309
+ });
2310
+ }
2311
+ let r = n.find(({ assessment: e }) => e.kind === "unresolved");
2312
+ if (r?.assessment.kind === "unresolved") {
2313
+ let { reason: t } = r.assessment;
2314
+ e.report("MOLDEA_INTEGRATION_LINK_UNRESOLVED", r.path, {
2315
+ entryKind: "symlink",
2316
+ reason: t
2317
+ }, t);
2318
+ return;
2319
+ }
2320
+ let i = n[0];
2321
+ i?.assessment.kind === "not-loading" && e.report("MOLDEA_INTEGRATION_CLAUDE_IMPORT_MISSING", i.path, { entryKind: i.assessment.entryKind });
2322
+ }, Cr = async (e, t, n, r) => {
2323
+ let i = d(n, "validate-project"), a = {
2324
+ instructions: t,
2325
+ ledger: Yt(e),
2326
+ reader: e,
2327
+ report: (e, t, n, r) => {
2328
+ i.add({
2329
+ code: e,
2330
+ path: t,
2331
+ subject: t,
2332
+ qualifier: r ?? null,
2333
+ entity: { integrationPath: t },
2334
+ details: n
2335
+ });
2336
+ },
2337
+ ...r === void 0 ? {} : { signal: r }
2338
+ };
2339
+ return await Sr(a, await mr(a)), i.finalize();
2340
+ }, wr = (e) => {
2341
+ if (e.kind === "context") return {
2342
+ subject: S(e.id),
2343
+ entity: { contextPath: S(e.id) }
2344
+ };
2345
+ if (e.kind === "decision") return {
2346
+ subject: S(e.id),
2347
+ entity: { decisionId: j(S(e.id)) ?? e.id }
2348
+ };
2349
+ let t = e.agentId ?? e.id;
2350
+ return {
2351
+ subject: S(`/moldea/agents/${t}/instruction.md`),
2352
+ entity: {
2353
+ agentId: t,
2354
+ ...e.kind === "tool" || e.kind === "skill" ? {
2355
+ capabilityId: e.id,
2356
+ capabilityKind: e.kind
2357
+ } : {}
2358
+ }
2359
+ };
2360
+ }, Tr = (e) => {
2361
+ let t = new Map();
2362
+ for (let n of Ve(e)) {
2363
+ if (n.field !== "affectedBy" || n.declaration.kind !== "glob") continue;
2364
+ let e = n.declaration.pattern, r = e.slice(1).split("/"), i = r.findIndex((e) => e.includes("*")), a = S("/" + r.slice(0, i).join("/")), o = t.get(a) ?? [];
2365
+ o.push({
2366
+ declaration: n,
2367
+ pattern: e,
2368
+ segments: r
2369
+ }), t.set(a, o);
2370
+ }
2371
+ return t;
2372
+ }, Er = async (e, t, n, i) => {
2373
+ let a = [];
2374
+ try {
2375
+ for (let [n, r] of Tr(t)) {
2376
+ let t = new Set(r);
2377
+ if ((await e.getEntry(n, i === void 0 ? void 0 : { signal: i }))?.type === "directory") {
2378
+ for await (let r of e.iterateEntries({
2379
+ prefix: n,
2380
+ ...i === void 0 ? {} : { signal: i }
2381
+ })) if (r.type === "file") {
2382
+ for (let e of t) Me(e.segments, r.path) && t.delete(e);
2383
+ if (t.size === 0) break;
2384
+ }
2385
+ }
2386
+ a.push(...t);
2387
+ }
2388
+ } catch (e) {
2389
+ if (e instanceof r && e.code === "RESOURCE_LIMIT_EXCEEDED" || e instanceof x && e.code === "RESOURCE_LIMIT_EXCEEDED") return {
2390
+ completed: !1,
2391
+ diagnostics: []
2392
+ };
2393
+ throw e;
2394
+ }
2395
+ let o = d(n, "validate-project");
2396
+ for (let { declaration: e, pattern: t } of a) {
2397
+ let { subject: n, entity: r } = wr(e.owner);
2398
+ o.add({
2399
+ code: "MOLDEA_IMPACT_PATTERN_UNMATCHED",
2400
+ path: S("/moldea/moldea.yaml"),
2401
+ pointer: e.pointer,
2402
+ subject: n,
2403
+ qualifier: t,
2404
+ entity: r,
2405
+ details: {
2406
+ pattern: t,
2407
+ owner: n
2408
+ }
2409
+ });
2410
+ }
2411
+ return {
2412
+ completed: !0,
2413
+ diagnostics: o.finalize()
2414
+ };
2415
+ }, Dr = (e) => JSON.stringify([
2416
+ e.code,
2417
+ e.subject,
2418
+ e.qualifier ?? null
2419
+ ]), Or = (e, t, n, r) => {
2420
+ let i = new Map(t.map((e, t) => [Dr(e), {
2421
+ entry: e,
2422
+ index: t
2423
+ }])), a = new Set(), o = e.map((e) => {
2424
+ if (e.severity !== "warning" || !e.acceptable || !n.has(e.code)) return e;
2425
+ let t = Dr(e), r = i.get(t);
2426
+ return r === void 0 ? e : (a.add(t), m({
2427
+ ...e,
2428
+ accepted: !0,
2429
+ reason: r.entry.reason
2430
+ }));
2431
+ }), c = d(r, "validate-project");
2432
+ for (let [e, { entry: t, index: r }] of i) {
2433
+ if (a.has(e) || !n.has(t.code)) continue;
2434
+ let i = `/acceptedWarnings/${r}`;
2435
+ c.add({
2436
+ code: "MOLDEA_ACCEPTANCE_UNMATCHED",
2437
+ path: S("/moldea/moldea.yaml"),
2438
+ pointer: i,
2439
+ subject: S("/moldea/moldea.yaml"),
2440
+ qualifier: i,
2441
+ details: {
2442
+ code: t.code,
2443
+ subject: t.subject,
2444
+ qualifier: t.qualifier ?? null
2445
+ }
2446
+ });
2447
+ }
2448
+ return s([...o, ...c.finalize()]);
2449
+ }, kr = (e, t) => {
2450
+ for (let n of t) e.merge(n);
2451
+ }, Ar = (e, t, n, r, i, a, o) => {
2452
+ e.add({
2453
+ code: t,
2454
+ details: {
2455
+ ...o === void 0 ? {} : { actualType: o.type },
2456
+ mirrorPath: r
2457
+ },
2458
+ entity: { agentId: a },
2459
+ path: n,
2460
+ pointer: i
2461
+ });
2462
+ }, jr = async (e, t, n, r, i, a, o, s, c, l) => {
2463
+ let u = await e.getEntry(r, c);
2464
+ if (u === null) return Ar(s, "MOLDEA_MIRROR_MISSING", t, r, i, a), null;
2465
+ if (u.type === "symlink") return Ar(s, "MOLDEA_MIRROR_SYMLINK", t, r, i, a, u), null;
2466
+ if (u.type !== "file") return Ar(s, "MOLDEA_MIRROR_NOT_FILE", t, r, i, a, u), null;
2467
+ let d = await G(e, r, o.limits, l);
2468
+ return kr(s, d.diagnostics), d.asset === null ? null : d.asset.content === n.content ? {
2469
+ byteLength: d.asset.utf8ByteLength,
2470
+ canonicalDigest: n.digest,
2471
+ digest: d.asset.digest,
2472
+ path: r,
2473
+ scalarLength: d.asset.scalarLength
2474
+ } : (Ar(s, "MOLDEA_MIRROR_STALE", t, r, i, a), null);
2475
+ }, Mr = async (e, t, n, r, i) => {
2476
+ r = a(r);
2477
+ let o = d(r.limits, "validate-project"), s = [], c = i === void 0 ? void 0 : { signal: i };
2478
+ for (let a of [...n].sort((e, t) => u(e.id, t.id))) {
2479
+ let n = [];
2480
+ if (a.instruction !== null) {
2481
+ let s = a.declaration.mirrors ?? [];
2482
+ for (let [l, u] of s.entries()) {
2483
+ let s = await jr(e, t, a.instruction, u, `/agents/${g(a.id)}/mirrors/${l}`, a.id, r, o, c, i);
2484
+ s !== null && n.push(s);
2485
+ }
2486
+ }
2487
+ s.push({
2488
+ id: a.id,
2489
+ mirrors: n
2490
+ });
2491
+ }
2492
+ let l = o.finalize();
2493
+ return m({
2494
+ agentMirrors: s,
2495
+ diagnostics: l,
2496
+ valid: l.length === 0
2497
+ });
2498
+ }, Nr = (e, t) => {
2499
+ for (let n of t) e.merge(n);
2500
+ }, Pr = async (e, t, n, r) => {
2501
+ n = a(n);
2502
+ let i = d(n.limits, "validate-project"), o = null;
2503
+ if (t !== null) {
2504
+ let a = await G(e, t, n.limits, r);
2505
+ Nr(i, a.diagnostics), a.asset !== null && (k(a.asset.content) ? o = a.asset : i.add({
2506
+ code: "MOLDEA_PROJECT_FILE_EMPTY",
2507
+ path: a.asset.path
2508
+ }));
2509
+ }
2510
+ let s = i.finalize();
2511
+ return m({
2512
+ diagnostics: s,
2513
+ project: o,
2514
+ valid: s.length === 0
2515
+ });
2516
+ }, Fr = async (e, t, n, r, i, o) => {
2517
+ r = a(r);
2518
+ let s = d(r.limits, "validate-project"), c = [], l = o ?? await Pr(e, n.inventory.project, r, i);
2519
+ Nr(s, l.diagnostics);
2520
+ for (let a of [...n.inventory.context].sort(u)) {
2521
+ let n = await G(e, a, r.limits, i);
2522
+ if (Nr(s, n.diagnostics), n.asset !== null) {
2523
+ if (!k(n.asset.content)) {
2524
+ s.add({
2525
+ code: "MOLDEA_CONTEXT_FILE_EMPTY",
2526
+ path: a
2527
+ });
2528
+ continue;
2529
+ }
2530
+ c.push({
2531
+ asset: n.asset,
2532
+ relationships: t?.context?.[a] ?? null
2533
+ });
2534
+ }
2535
+ }
2536
+ let f = s.finalize();
2537
+ return m({
2538
+ context: c,
2539
+ diagnostics: f,
2540
+ project: l.project,
2541
+ valid: f.length === 0
2542
+ });
2543
+ }, Ir = (e, t) => [...e].sort((e, t) => u(e.id, t.id) || u(e.path, t.path)).map((e) => ({
2544
+ decision: e,
2545
+ relationships: t.value.decisions?.[e.path] ?? null
2546
+ })), Lr = (e, t) => {
2547
+ let n = new Map(t.map((e) => [e.id, e.mirrors])), r = [];
2548
+ if (n.size !== e.length) return null;
2549
+ for (let t of [...e].sort((e, t) => u(e.id, t.id))) {
2550
+ let e = n.get(t.id);
2551
+ if (t.description === null || t.instruction === null || e === void 0) return null;
2552
+ r.push({
2553
+ context: [...t.declaration.context ?? []].sort(u),
2554
+ decisions: [...t.declaration.decisions ?? []].sort(u),
2555
+ declaration: t.declaration,
2556
+ description: t.description,
2557
+ id: t.id,
2558
+ instruction: t.instruction,
2559
+ mirrors: [...e].sort((e, t) => u(e.path, t.path))
2560
+ });
2561
+ }
2562
+ return r;
2563
+ }, Rr = (e) => {
2564
+ let t = Lr(e.agents, e.agentMirrors);
2565
+ return t === null ? null : m({
2566
+ agents: t,
2567
+ context: [...e.context].sort((e, t) => u(e.asset.path, t.asset.path)),
2568
+ decisions: Ir(e.decisions, e.manifest),
2569
+ formatVersion: 1,
2570
+ manifest: e.manifest,
2571
+ project: e.project
2572
+ });
2573
+ }, zr = (e) => !/\.d\.(?:ts|tsx|mts|cts)$/.test(e) && /\.(?:ts|tsx|mts|cts|js|mjs|jsx)$/.test(e), Br = async (e, t, n, r) => {
2574
+ if (!zr(t)) return {
2575
+ kind: "not-checked",
2576
+ reason: "unsupported-file-type"
2577
+ };
2578
+ let i = Yt(e), a = 65536 + n * 520, o = Math.max(1, n + Math.min(65536, n));
2579
+ if (n > r || !i.tryReserve(a + o)) return {
2580
+ kind: "not-checked",
2581
+ reason: "resource-limit"
2582
+ };
2583
+ i.release(o);
2584
+ try {
2585
+ let e = await i.readSourceFile(t);
2586
+ try {
2587
+ if (e.bytes.byteLength !== n) throw new x({
2588
+ code: "INVALID_SOURCE_DATA",
2589
+ operation: "read-file-page",
2590
+ path: t,
2591
+ retryable: !1
2592
+ });
2593
+ let { inventoryExports: r } = await import("./chunk-936e5d09.mjs"), a = r(t, e.bytes);
2594
+ if (a.kind === "parsed") {
2595
+ let e = 64;
2596
+ for (let t of a.names) e += 64 + t.length * 2;
2597
+ i.reserve(e);
2598
+ }
2599
+ return a;
2600
+ } finally {
2601
+ e.release();
2602
+ }
2603
+ } finally {
2604
+ i.release(a);
2605
+ }
2606
+ }, X = (e, t) => `${e}/${g(t)}`, Vr = (e, t, n, r, i) => {
2607
+ for (let [a, o] of (t ?? []).entries()) e.push({
2608
+ entity: r,
2609
+ kind: "reference",
2610
+ path: o.path,
2611
+ pointer: X(n, String(a)),
2612
+ ...i === void 0 ? {} : { relationship: i },
2613
+ ...o.symbol === void 0 ? {} : { symbol: o.symbol }
2614
+ });
2615
+ }, Hr = (e, t, n, r) => {
2616
+ for (let [i, a] of (t ?? []).entries()) a.includes("*") || e.push({
2617
+ entity: r,
2618
+ kind: "impact",
2619
+ path: S(a),
2620
+ pointer: X(n, String(i))
2621
+ });
2622
+ }, Ur = (e, t, n, r) => {
2623
+ Vr(e, t.bindings, X(n, "bindings"), r, n.startsWith("/context/") ? "context-binding" : "decision-binding"), Hr(e, t.affectedBy, X(n, "affectedBy"), r);
2624
+ }, Wr = (e, t, n, r, i, a, o = []) => {
2625
+ let s = X(a, r), c = {
2626
+ agentId: i,
2627
+ capabilityId: r,
2628
+ capabilityKind: n
2629
+ };
2630
+ e.push({
2631
+ entity: c,
2632
+ kind: `${n}-implementation`,
2633
+ relationship: `${n}-implementation`,
2634
+ ...t.implementation.symbol === void 0 ? {} : { symbol: t.implementation.symbol },
2635
+ path: t.implementation.path,
2636
+ pointer: X(s, "implementation")
2637
+ });
2638
+ for (let [r, i] of [["registration", t.registration], ...o]) i !== void 0 && e.push({
2639
+ entity: c,
2640
+ kind: "reference",
2641
+ path: i.path,
2642
+ pointer: X(s, r),
2643
+ relationship: `${n}-${r === "inputSchema" ? "input-schema" : r === "outputSchema" ? "output-schema" : "registration"}`,
2644
+ ...i.symbol === void 0 ? {} : { symbol: i.symbol }
2645
+ });
2646
+ Hr(e, t.affectedBy, X(s, "affectedBy"), c);
2647
+ }, Gr = (e, t, n) => {
2648
+ let r = `/agents/${g(t)}`, i = { agentId: t }, a = X(r, "bindings"), o = n.bindings;
2649
+ for (let t of [
2650
+ "runtimeAgent",
2651
+ "inputSchema",
2652
+ "outputSchema",
2653
+ "instructionLoader"
2654
+ ]) {
2655
+ let n = o?.[t];
2656
+ n !== void 0 && e.push({
2657
+ entity: i,
2658
+ kind: "reference",
2659
+ path: n.path,
2660
+ pointer: X(a, t),
2661
+ relationship: {
2662
+ runtimeAgent: "runtime-agent",
2663
+ inputSchema: "agent-input-schema",
2664
+ outputSchema: "agent-output-schema",
2665
+ instructionLoader: "instruction-loader"
2666
+ }[t],
2667
+ ...n.symbol === void 0 ? {} : { symbol: n.symbol }
2668
+ });
2669
+ }
2670
+ Hr(e, n.affectedBy, X(r, "affectedBy"), i);
2671
+ let s = X(r, "tools");
2672
+ for (let r of Object.keys(n.tools ?? {}).sort(u)) {
2673
+ let i = n.tools?.[r];
2674
+ i !== void 0 && Wr(e, i, "tool", r, t, s, [["inputSchema", i.inputSchema], ["outputSchema", i.outputSchema]]);
2675
+ }
2676
+ let c = X(r, "skills");
2677
+ for (let r of Object.keys(n.skills ?? {}).sort(u)) {
2678
+ let i = n.skills?.[r];
2679
+ i !== void 0 && Wr(e, i, "skill", r, t, c);
2680
+ }
2681
+ }, Kr = (e) => {
2682
+ let t = [];
2683
+ for (let n of ["context", "decisions"]) {
2684
+ let r = e[n];
2685
+ for (let e of Object.keys(r ?? {}).sort(u)) {
2686
+ let i = r?.[e];
2687
+ if (i === void 0) continue;
2688
+ let a = X(`/${n}`, e), o = n === "decisions" ? j(S(e)) : null;
2689
+ Ur(t, i, a, o === null ? { contextPath: S(e) } : { decisionId: o });
2690
+ }
2691
+ }
2692
+ for (let n of Object.keys(e.agents ?? {}).sort(u)) {
2693
+ let r = e.agents?.[n];
2694
+ r !== void 0 && Gr(t, n, r);
2695
+ }
2696
+ return t.sort((e, t) => u(e.pointer, t.pointer));
2697
+ }, qr = (e, t) => {
2698
+ let n = e;
2699
+ for (; n.length > 0;) {
2700
+ if (t.has(n)) return !0;
2701
+ let e = n.lastIndexOf("/");
2702
+ if (e <= 0) return !1;
2703
+ n = n.slice(0, e);
2704
+ }
2705
+ return !1;
2706
+ }, Jr = (e, t) => {
2707
+ let n = { [e.kind === "impact" ? "impactPath" : "referencedPath"]: e.path };
2708
+ return t !== null && (n.actualType = t.type), (e.kind === "tool-implementation" || e.kind === "skill-implementation") && (n.reason = t === null ? "missing" : t.type === "symlink" ? "symlink" : "not-file"), n;
2709
+ }, Yr = (e, t) => t?.type === "file" ? null : e.kind === "tool-implementation" ? "MOLDEA_TOOL_IMPLEMENTATION_MISSING" : e.kind === "skill-implementation" ? "MOLDEA_SKILL_IMPLEMENTATION_MISSING" : e.kind === "impact" ? t === null ? "MOLDEA_IMPACT_PATH_MISSING" : "MOLDEA_IMPACT_PATH_NOT_FILE" : t === null ? "MOLDEA_REFERENCE_MISSING" : t.type === "symlink" ? "MOLDEA_REFERENCE_SYMLINK" : "MOLDEA_REFERENCE_NOT_FILE", Xr = (e, t, n, r) => {
2710
+ let i = Yr(e, t);
2711
+ i !== null && r.add({
2712
+ code: i,
2713
+ details: Jr(e, t),
2714
+ entity: e.entity,
2715
+ path: n,
2716
+ pointer: e.pointer
2717
+ });
2718
+ }, Zr = async (e, t, n, i, a, o, s = []) => {
2719
+ let c = d(a, "validate-project"), l = new Set(i.diagnostics.flatMap((e) => e.path === null ? [] : [e.path])), u = new Map(), f = new Map(), p = o === void 0 ? void 0 : { signal: o };
2720
+ for (let i of Kr(n)) {
2721
+ if (qr(i.path, l)) continue;
2722
+ let n = f.get(i.path);
2723
+ n === void 0 && (n = e.getEntry(i.path, p), f.set(i.path, n));
2724
+ let o = await n;
2725
+ if (Xr(i, o, t, c), o?.type !== "file" || i.relationship === void 0) continue;
2726
+ if (o.byteLength === null) throw TypeError("A repository file entry must declare its byte length.");
2727
+ if (s.length >= a.maxCoverage) throw new r({
2728
+ code: "RESOURCE_LIMIT_EXCEEDED",
2729
+ operation: "validate-project",
2730
+ limit: "maxCoverage",
2731
+ limitMaximum: a.maxCoverage,
2732
+ observedUsage: s.length + 1,
2733
+ nextAction: "reduce-input-or-increase-limit"
2734
+ });
2735
+ let d = {
2736
+ entity: i.entity ?? {},
2737
+ relationship: i.relationship,
2738
+ path: i.path,
2739
+ symbol: i.symbol ?? null,
2740
+ fileCheck: "passed"
2741
+ }, m;
2742
+ if (i.symbol === void 0) m = {
2743
+ ...d,
2744
+ exportCheck: "not-checked",
2745
+ exportNotCheckedReason: "no-symbol"
2746
+ };
2747
+ else {
2748
+ let n = u.get(i.path);
2749
+ n === void 0 && (n = await Br(e, i.path, o.byteLength, a.maxFileBytes), u.set(i.path, n)), n.kind === "not-checked" ? m = {
2750
+ ...d,
2751
+ exportCheck: "not-checked",
2752
+ exportNotCheckedReason: n.reason
2753
+ } : n.complete ? n.names.has(i.symbol) ? m = {
2754
+ ...d,
2755
+ exportCheck: "passed"
2756
+ } : (m = {
2757
+ ...d,
2758
+ exportCheck: "failed"
2759
+ }, c.add({
2760
+ code: "MOLDEA_REFERENCE_EXPORT_MISSING",
2761
+ entity: i.entity,
2762
+ path: t,
2763
+ pointer: i.pointer,
2764
+ details: {
2765
+ referencedPath: i.path,
2766
+ symbol: i.symbol,
2767
+ relationship: i.relationship
2768
+ }
2769
+ })) : m = {
2770
+ ...d,
2771
+ exportCheck: "not-checked",
2772
+ exportNotCheckedReason: "unresolved-exports"
2773
+ };
2774
+ }
2775
+ Xt(e, 512 + JSON.stringify(m).length * 2), s.push(m);
2776
+ }
2777
+ return c.finalize();
2778
+ }, Qr = S("/moldea"), $r = S("/moldea/moldea.yaml"), ei = S("/moldea/project.md"), Z = (e, t) => {
2779
+ for (let n of t) e.merge(n);
2780
+ }, ti = async (e, t) => {
2781
+ t = a(t);
2782
+ let { session: n, signal: r } = e, i = [], s = d(t.limits, "validate-project"), c = r === void 0 ? void 0 : { signal: r }, l = new Map(), u = Yt(n.reader), p = 0, h = (e, t) => {
2783
+ let n = f(t);
2784
+ u.reserve(n), p += n, l.set(e, t);
2785
+ };
2786
+ try {
2787
+ let e = await n.reader.getEntry(Qr, c), a = null, u = null, d = null, f = null;
2788
+ if (e?.type === "directory") {
2789
+ if (a = await n.reader.getEntry($r, c), a?.type === "file") {
2790
+ let e = await ht({
2791
+ content: await n.reader.readCompleteFile($r, c),
2792
+ path: $r
2793
+ }, t, "validate-project");
2794
+ e.manifest !== null && e.yamlRoot !== null && h($r, e.yamlRoot), f = e.formatVersion, Z(s, e.diagnostics), e.asset !== null && e.manifest !== null && (d = {
2795
+ asset: e.asset,
2796
+ value: e.manifest
2797
+ });
2798
+ }
2799
+ u = await n.reader.getEntry(ei, c);
2800
+ }
2801
+ let p = await Pr(n.reader, u?.type === "file" ? ei : null, t, r);
2802
+ Z(s, p.diagnostics);
2803
+ let g = await Rn(n.reader, t.limits, r, {
2804
+ manifest: a,
2805
+ moldeaRoot: e,
2806
+ project: u
2807
+ });
2808
+ Z(s, g.diagnostics), n.throwIfAborted();
2809
+ let _ = await Fr(n.reader, d?.value ?? null, g, t, r, p);
2810
+ Z(s, _.diagnostics);
2811
+ let v = await Qn(n.reader, g.inventory.decisions, t, r, h);
2812
+ Z(s, v.diagnostics);
2813
+ let y = [], b = [];
2814
+ if (d !== null) {
2815
+ let e = d.asset.path, a = await vn(n.reader, d.value, g, t, r);
2816
+ y = a.agents, Z(s, a.diagnostics), Z(s, nr(e, d.value, g, v.decisions, t.limits)), Z(s, await Zr(n.reader, e, d.value, g, t.limits, r, i));
2817
+ let o = await Mr(n.reader, e, y, t, r);
2818
+ b = o.agentMirrors, Z(s, o.diagnostics);
2819
+ }
2820
+ n.throwIfAborted(), Z(s, await Cr(n.reader, n.instructions, t.limits, r));
2821
+ let x = d === null ? {
2822
+ completed: !1,
2823
+ diagnostics: []
2824
+ } : await Er(n.reader, d.value, t.limits, r);
2825
+ n.throwIfAborted(), Z(s, x.diagnostics);
2826
+ let S = o(Or(s.finalize(), d?.value.acceptedWarnings ?? [], new Set([
2827
+ "MOLDEA_INTEGRATION_BLOCK_MISSING",
2828
+ "MOLDEA_INTEGRATION_SKILL_MISSING",
2829
+ "MOLDEA_INTEGRATION_BLOCK_STALE",
2830
+ "MOLDEA_INTEGRATION_LINK_UNRESOLVED",
2831
+ "MOLDEA_INTEGRATION_CLAUDE_IMPORT_MISSING",
2832
+ ...x.completed ? ["MOLDEA_IMPACT_PATTERN_UNMATCHED"] : []
2833
+ ]), t.limits), l), C = !S.some((e) => e.severity === "error") && d !== null && _.project !== null ? Rr({
2834
+ agentMirrors: b,
2835
+ agents: y,
2836
+ context: _.context,
2837
+ decisions: v.decisions,
2838
+ manifest: d,
2839
+ project: _.project
2840
+ }) : null;
2841
+ return m({
2842
+ diagnostics: S,
2843
+ coverage: i,
2844
+ formatVersion: f,
2845
+ project: C
2846
+ });
2847
+ } finally {
2848
+ l.clear(), u.release(p);
2849
+ }
2850
+ }, ni = () => {
2851
+ throw new r({
2852
+ code: "INVALID_ARGUMENT",
2853
+ operation: "validate-project"
2854
+ });
2855
+ }, ri = (e) => i(e, !0) && i(e.snapshot, !0) && typeof e.snapshot.id == "string" && typeof e.snapshot.sourceKind == "string" && typeof e.compare == "function" && typeof e.getEntry == "function" && typeof e.listEntriesPage == "function" && typeof e.readFilePage == "function" && typeof e.readLinkText == "function", ii = (e) => i(e, !0) && typeof e.aborted == "boolean" && typeof e.addEventListener == "function" && typeof e.removeEventListener == "function", ai = (e) => {
2856
+ try {
2857
+ if (!i(e, !0)) return ni();
2858
+ let t = e.repository, n = e.instructions, r = e.signal;
2859
+ return Reflect.ownKeys(e).some((e) => e !== "repository" && e !== "instructions" && e !== "signal") || !ri(t) || n !== void 0 && !ri(n) || r !== void 0 && !ii(r) ? ni() : {
2860
+ ...n === void 0 ? {} : { instructions: n },
2861
+ repository: t,
2862
+ ...r === void 0 ? {} : { signal: r }
2863
+ };
2864
+ } catch (e) {
2865
+ if (e instanceof r) throw e;
2866
+ return ni();
2867
+ }
2868
+ }, oi = async (e, t) => {
2869
+ let n = ai(e), r = a(t), i = cn(n.repository, r.limits, n.signal, n.instructions), o = await ti({
2870
+ session: i,
2871
+ ...n.signal === void 0 ? {} : { signal: n.signal }
2872
+ }, r);
2873
+ i.throwIfAborted();
2874
+ let s = h(o.diagnostics);
2875
+ return m({
2876
+ project: o.project,
2877
+ resourceUsage: i.getResourceUsage(),
2878
+ result: {
2879
+ diagnostics: o.diagnostics,
2880
+ ...s,
2881
+ coverage: o.coverage,
2882
+ coverageCounts: Kt(o.coverage),
2883
+ formatVersion: o.formatVersion,
2884
+ source: n.repository.snapshot,
2885
+ summary: o.project === null ? null : Gt(o.project),
2886
+ valid: s.errorCount === 0
2887
+ }
2888
+ });
2889
+ }, si = async (e, t) => (await oi(e, t)).result, ci = "core7", li = 512, ui = 64, di = 2, fi = 8, pi = new TextEncoder(), Q = () => {
2890
+ throw new r({
2891
+ code: "INVALID_ARGUMENT",
2892
+ operation: "create-project-inspection"
2893
+ });
2894
+ }, mi = (e, t) => {
2895
+ throw new r({
2896
+ code: "RESOURCE_LIMIT_EXCEEDED",
2897
+ limit: "maxRetainedBytes",
2898
+ limitMaximum: e,
2899
+ nextAction: "reduce-input-or-increase-limit",
2900
+ observedUsage: t,
2901
+ operation: "create-project-inspection"
2902
+ });
2903
+ }, $ = (e) => {
2904
+ if (typeof e != "object" || !e) {
2905
+ let t = JSON.stringify(e);
2906
+ return t === void 0 ? "null" : t;
2907
+ }
2908
+ return Array.isArray(e) ? `[${e.map((e) => $(e)).join(",")}]` : `{${Object.entries(e).filter(([, e]) => e !== void 0).sort(([e], [t]) => e < t ? -1 : +(e > t)).map(([e, t]) => `${JSON.stringify(e)}:${$(t)}`).join(",")}}`;
2909
+ }, hi = (e) => w((function* () {
2910
+ for (let t of e) yield pi.encode(t);
2911
+ })()), gi = (e) => e.kind === "agent" ? ["3", e.agent.agentId].join("\0") : e.kind === "metadata" ? [
2912
+ "0",
2913
+ e.metadata.path,
2914
+ e.metadata.kind,
2915
+ e.metadata.agentId ?? "",
2916
+ e.metadata.decisionId ?? "",
2917
+ e.metadata.digest
2918
+ ].join(":") : e.kind === "diagnostic" ? [
2919
+ "1",
2920
+ e.diagnostic.source,
2921
+ e.diagnostic.code,
2922
+ e.diagnostic.path ?? "",
2923
+ hi([$(e.diagnostic)])
2924
+ ].join(":") : [
2925
+ "2",
2926
+ e.coverage.path,
2927
+ e.coverage.relationship,
2928
+ e.coverage.entity.agentId ?? "",
2929
+ hi([$(e.coverage)])
2930
+ ].join(":"), _i = (e) => {
2931
+ let t = Array.from(e, (e) => ({
2932
+ item: e,
2933
+ key: gi(e)
2934
+ })).sort((e, t) => e.key < t.key ? -1 : +(e.key > t.key)), n = null, r = 0;
2935
+ for (let e of t) {
2936
+ let t = e.key;
2937
+ r = t === n ? r + 1 : 0, n = t, e.key = `${t}:${String(r).padStart(10, "0")}`;
2938
+ }
2939
+ return t;
2940
+ }, vi = (e, t, n) => hi([
2941
+ ci,
2942
+ e,
2943
+ t,
2944
+ n
2945
+ ]), yi = (e, t, n) => [
2946
+ ci,
2947
+ t,
2948
+ encodeURIComponent(n),
2949
+ e,
2950
+ vi(e, n, t)
2951
+ ].join(":"), bi = (e, t, n) => {
2952
+ if (e === void 0) return null;
2953
+ let r = /^core7:(all|diagnostics|coverage|metadata):([^:]+):(sha256:[0-9a-f]{64}):(sha256:[0-9a-f]{64})$/u.exec(e);
2954
+ if (r === null || r[1] !== n || r[3] !== t) return Q();
2955
+ let i;
2956
+ try {
2957
+ i = decodeURIComponent(r[2]);
2958
+ } catch {
2959
+ return Q();
2960
+ }
2961
+ return i.length === 0 || r[4] !== vi(t, i, n) ? Q() : i;
2962
+ }, xi = (e) => m({
2963
+ all: e,
2964
+ diagnostics: e.filter(({ item: e }) => e.kind === "diagnostic"),
2965
+ coverage: e.filter(({ item: e }) => e.kind === "coverage"),
2966
+ metadata: e.filter(({ item: e }) => e.kind === "metadata" || e.kind === "agent")
2967
+ }), Si = (e, t, n, r) => {
2968
+ let i = n + e + t;
2969
+ return !Number.isSafeInteger(t) || t < 0 || !Number.isSafeInteger(i) || i > r ? mi(r, Number.isSafeInteger(i) ? i : 2 ** 53 - 1) : e + t;
2970
+ }, Ci = function* (e) {
2971
+ if (e.project !== null) for (let t of Wt(e.project)) yield {
2972
+ kind: "metadata",
2973
+ metadata: t
2974
+ };
2975
+ for (let t of e.result.diagnostics) yield {
2976
+ diagnostic: t,
2977
+ kind: "diagnostic"
2978
+ };
2979
+ for (let t of e.result.coverage) yield {
2980
+ coverage: t,
2981
+ kind: "coverage"
2982
+ };
2983
+ if (e.project !== null) for (let t of Ut(e.project)) yield {
2984
+ agent: t,
2985
+ kind: "agent"
2986
+ };
2987
+ }, wi = (e, t, n) => {
2988
+ let r = e.resourceUsage.retainedBytes, i = Si(0, li, r, n), a = 0;
2989
+ for (let t of Ci(e)) {
2990
+ let e = `${gi(t)}:0000000000`, o = pi.encode(e).byteLength + pi.encode($(t)).byteLength;
2991
+ i = Si(i, ui + o * di + fi, r, n), t.kind === "metadata" && (a += 1);
2992
+ }
2993
+ let o = {
2994
+ agents: t.agents,
2995
+ context: t.context,
2996
+ decisions: t.decisions,
2997
+ diagnostics: t.diagnostics,
2998
+ errors: t.errors,
2999
+ coverage: t.coverage,
3000
+ metadata: a,
3001
+ mirrors: t.mirrors,
3002
+ warnings: t.warnings,
3003
+ acceptedWarnings: t.acceptedWarnings
3004
+ };
3005
+ return i = Si(i, pi.encode($({
3006
+ counts: o,
3007
+ formatVersion: e.result.formatVersion,
3008
+ inspectionDigest: "sha256:0000000000000000000000000000000000000000000000000000000000000000",
3009
+ source: e.result.source,
3010
+ summary: e.result.summary,
3011
+ valid: e.result.valid
3012
+ })).byteLength * di, r, n), {
3013
+ counts: o,
3014
+ preparedBytes: i
3015
+ };
3016
+ }, Ti = (e, t, n, r, i, a) => hi((function* () {
3017
+ yield "core7-prepared-inspection", yield $({
3018
+ counts: e,
3019
+ coverageCounts: t,
3020
+ formatVersion: n,
3021
+ summary: i,
3022
+ valid: a
3023
+ });
3024
+ for (let { key: e } of r) yield e;
3025
+ })()), Ei = (e, t) => {
3026
+ if (t === null) return 0;
3027
+ let n = 0, r = e.length - 1;
3028
+ for (; n <= r;) {
3029
+ let i = n + Math.floor((r - n) / 2), a = e[i];
3030
+ if (a === void 0) return Q();
3031
+ if (a.key === t) return i + 1;
3032
+ a.key < t ? n = i + 1 : r = i - 1;
3033
+ }
3034
+ return Q();
3035
+ }, Di = (e) => {
3036
+ let { counts: t, coverageCounts: n, formatVersion: r, items: i, maxEntries: a, preparedBytes: o, resourceUsage: s, source: c, summary: l, valid: u } = e, d = xi(i), f = Ti(t, n, r, i, l, u), p = m({
3037
+ canonicalBytes: s.canonicalBytes,
3038
+ peakRetainedBytes: Math.max(s.peakRetainedBytes, s.retainedBytes + o),
3039
+ preparedBytes: o,
3040
+ retainedBytes: o,
3041
+ totalBytesRead: s.totalBytesRead
3042
+ });
3043
+ return m({
3044
+ counts: t,
3045
+ coverageCounts: n,
3046
+ formatVersion: r,
3047
+ inspectionDigest: f,
3048
+ readPage: (e) => {
3049
+ if (typeof e != "object" || !e || Reflect.ownKeys(e).some((e) => e !== "cursor" && e !== "maxItems" && e !== "view") || !Number.isSafeInteger(e.maxItems) || e.maxItems < 1 || e.maxItems > a || e.cursor !== void 0 && typeof e.cursor != "string" || e.view !== "all" && e.view !== "diagnostics" && e.view !== "coverage" && e.view !== "metadata") return Q();
3050
+ let i = d[e.view], o = Ei(i, bi(e.cursor, f, e.view)), s = i.slice(o, o + e.maxItems).map(({ item: t, key: n }, r) => ({
3051
+ item: t,
3052
+ nextCursor: o + r + 1 >= i.length ? null : yi(f, e.view, n)
3053
+ })), p = s.at(-1)?.nextCursor ?? null;
3054
+ return m({
3055
+ counts: t,
3056
+ coverageCounts: n,
3057
+ formatVersion: r,
3058
+ inspectionDigest: f,
3059
+ page: {
3060
+ isComplete: p === null,
3061
+ nextCursor: p,
3062
+ records: s,
3063
+ totalItems: i.length
3064
+ },
3065
+ source: c,
3066
+ summary: l,
3067
+ valid: u,
3068
+ view: e.view
3069
+ });
3070
+ },
3071
+ resourceUsage: p,
3072
+ source: c,
3073
+ summary: l,
3074
+ valid: u
3075
+ });
3076
+ }, Oi = async (e, t) => {
3077
+ let n = await oi(e, t), r = wi(n, {
3078
+ agents: n.result.summary?.counts.agents ?? 0,
3079
+ context: n.result.summary?.counts.context ?? 0,
3080
+ decisions: n.result.summary?.counts.decisions ?? 0,
3081
+ diagnostics: n.result.diagnostics.length,
3082
+ errors: n.result.errorCount,
3083
+ coverage: n.result.coverage.length,
3084
+ mirrors: n.result.summary?.counts.mirrors ?? 0,
3085
+ warnings: n.result.warningCount,
3086
+ acceptedWarnings: n.result.acceptedWarningCount
3087
+ }, t.limits.maxRetainedBytes), i = m(r.counts), a = m(_i(Ci(n)));
3088
+ return Di({
3089
+ counts: i,
3090
+ coverageCounts: n.result.coverageCounts,
3091
+ formatVersion: n.result.formatVersion,
3092
+ items: a,
3093
+ maxEntries: t.limits.maxEntries,
3094
+ preparedBytes: r.preparedBytes,
3095
+ resourceUsage: n.resourceUsage,
3096
+ source: n.result.source,
3097
+ summary: n.result.summary,
3098
+ valid: n.result.valid
3099
+ });
3100
+ }, ki = St({ createCore: () => Ai }), Ai = (e) => {
3101
+ let t = v(e);
3102
+ return m({
3103
+ calculateContentDigest: (e) => Ae(e, a(t).limits),
3104
+ createProjectInspection: (e) => Oi(e, a(t)),
3105
+ validateProject: (e) => si(e, a(t)),
3106
+ matchManifestScope: (e) => bt(e, a(t)),
3107
+ normalizeText: (e) => M(e, a(t).limits, "normalize-text"),
3108
+ parseDecision: (e) => Ht(e, a(t)),
3109
+ parseManifest: (e) => gt(e, a(t)),
3110
+ readCanonicalContentPage: (e) => Ot(e, a(t))
3111
+ });
3112
+ };
3113
+ //#endregion
3114
+ export { ar as i, Ai as n, zr as r, ki as t };