@moldea.ai/core 8.0.0 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/README.md +2 -2
  2. package/dist/agent-asset-validation/index.d.ts.map +1 -1
  3. package/dist/agent-assets/index.d.ts.map +1 -1
  4. package/dist/analysis-worker.js +5 -5
  5. package/dist/canonical-content-page/index.d.ts.map +1 -1
  6. package/dist/canonical-discovery/index.d.ts.map +1 -1
  7. package/dist/chunks/{core-BCMf-ig9.js → core-CFmT3SRC.js} +90 -94
  8. package/dist/chunks/core-CFmT3SRC.js.map +1 -0
  9. package/dist/chunks/{errors-CvWn6gr2.js → errors-Uvb-9X1u.js} +27 -67
  10. package/dist/chunks/errors-Uvb-9X1u.js.map +1 -0
  11. package/dist/chunks/{exceptions-CYf1pCKf.js → exceptions-AT654xUL.js} +10 -15
  12. package/dist/chunks/exceptions-AT654xUL.js.map +1 -0
  13. package/dist/chunks/{lifecycle-DwuevNoO.js → lifecycle-DuAHgnYH.js} +2 -2
  14. package/dist/chunks/{lifecycle-DwuevNoO.js.map → lifecycle-DuAHgnYH.js.map} +1 -1
  15. package/dist/chunks/{options-l3kVfA-K.js → options-C5360E_N.js} +20 -171
  16. package/dist/chunks/options-C5360E_N.js.map +1 -0
  17. package/dist/chunks/{repository-rpc-DgYwMaGv.js → repository-rpc-B9YaeLba.js} +31 -25
  18. package/dist/chunks/repository-rpc-B9YaeLba.js.map +1 -0
  19. package/dist/chunks/{scope-D9BYchNI.js → scope-CNg6Gnpi.js} +214 -151
  20. package/dist/chunks/scope-CNg6Gnpi.js.map +1 -0
  21. package/dist/core/index.d.ts.map +1 -1
  22. package/dist/decision/index.d.ts.map +1 -1
  23. package/dist/decision-graph/index.d.ts.map +1 -1
  24. package/dist/decision-graph-validation/index.d.ts.map +1 -1
  25. package/dist/decision-validation/index.d.ts.map +1 -1
  26. package/dist/diagnostic-utilities/index.d.ts.map +1 -1
  27. package/dist/exceptions/index.d.ts +1 -1
  28. package/dist/exceptions/index.d.ts.map +1 -1
  29. package/dist/format-validation/index.d.ts +0 -4
  30. package/dist/format-validation/index.d.ts.map +1 -1
  31. package/dist/immutable/index.d.ts +0 -6
  32. package/dist/immutable/index.d.ts.map +1 -1
  33. package/dist/index.js +3 -3
  34. package/dist/integration-validation/agents-inspection.d.ts.map +1 -1
  35. package/dist/integration-validation/parser.d.ts +9 -3
  36. package/dist/integration-validation/parser.d.ts.map +1 -1
  37. package/dist/integration-validation/types.d.ts +0 -5
  38. package/dist/integration-validation/types.d.ts.map +1 -1
  39. package/dist/manifest/index.d.ts.map +1 -1
  40. package/dist/manifest-relationship-validation/index.d.ts.map +1 -1
  41. package/dist/manifest-validation/index.d.ts.map +1 -1
  42. package/dist/mirrors/index.d.ts.map +1 -1
  43. package/dist/node-inspection/client.d.ts.map +1 -1
  44. package/dist/node-inspection/protocol.d.ts.map +1 -1
  45. package/dist/node-inspection/repository-rpc.d.ts.map +1 -1
  46. package/dist/node-runner.js +3 -3
  47. package/dist/node.js +13 -22
  48. package/dist/node.js.map +1 -1
  49. package/dist/options/index.d.ts.map +1 -1
  50. package/dist/project-assets/index.d.ts.map +1 -1
  51. package/dist/project-index/index.d.ts.map +1 -1
  52. package/dist/project-inspection/index.d.ts.map +1 -1
  53. package/dist/project-validation/index.d.ts.map +1 -1
  54. package/dist/repository-reference-validation/index.d.ts.map +1 -1
  55. package/dist/repository-text/index.d.ts.map +1 -1
  56. package/dist/runtime-guidance/index.d.ts.map +1 -1
  57. package/dist/runtime-placeholder-validation/index.d.ts.map +1 -1
  58. package/dist/scope-matching/matching.d.ts.map +1 -1
  59. package/dist/scope-matching/scope.d.ts.map +1 -1
  60. package/dist/scope-matching/validations.d.ts +0 -2
  61. package/dist/scope-matching/validations.d.ts.map +1 -1
  62. package/dist/scope.js +2 -2
  63. package/dist/text/index.d.ts.map +1 -1
  64. package/dist/universal-project-inspection/index.d.ts.map +1 -1
  65. package/dist/warning-acceptance/acceptance.d.ts.map +1 -1
  66. package/dist/yaml/index.d.ts.map +1 -1
  67. package/package.json +4 -3
  68. package/dist/chunks/core-BCMf-ig9.js.map +0 -1
  69. package/dist/chunks/errors-CvWn6gr2.js.map +0 -1
  70. package/dist/chunks/exceptions-CYf1pCKf.js.map +0 -1
  71. package/dist/chunks/options-l3kVfA-K.js.map +0 -1
  72. package/dist/chunks/repository-rpc-DgYwMaGv.js.map +0 -1
  73. package/dist/chunks/scope-D9BYchNI.js.map +0 -1
@@ -1,50 +1,137 @@
1
- import { C as isSimpleGlob, D as parseManifestPath, S as isRuntimeGuidancePath, T as isVariableId, _ as isDecisionPath, a as escapeJsonPointerSegment, b as isRepositorySymbol, c as freezeRecursively, d as hasNonWhitespace, f as hasUnsupportedGlobMetacharacter, g as isContextPath, h as isCapabilityDescription, i as createCoreDiagnosticCollector, j as RECOGNIZED_RUNTIME_IDS, k as ACCEPTABLE_WARNING_CODES, l as compareExactStrings, m as isCanonicalMoldeaPath, p as isCanonicalManifestPath, s as createNullPrototypeRecord, t as createCoreOperationOptionsSnapshot, u as countUnicodeScalars$1, v as isMirrorPath, w as isStableId, x as isReservedId, y as isNonEmptySingleLine } from "./options-l3kVfA-K.js";
2
- import { n as CoreOperationException } from "./exceptions-CYf1pCKf.js";
3
- import { parseRepositoryPath } from "@moldea.ai/repository";
1
+ import { a as escapeJsonPointerSegment, c as ACCEPTABLE_WARNING_CODES, i as createCoreDiagnosticCollector, s as createNullPrototypeRecord, t as createCoreOperationOptionsSnapshot, u as RECOGNIZED_RUNTIME_IDS } from "./options-C5360E_N.js";
2
+ import { n as CoreOperationException } from "./exceptions-AT654xUL.js";
3
+ import { compareCodePoints, countUtf8Bytes, deepFreeze, isObjectValid } from "jg-utilities";
4
+ import { isRepositoryPath, parseRepositoryPath } from "@moldea.ai/repository";
4
5
  import { Parser, isAlias, isMap, isScalar, isSeq, parseAllDocuments } from "yaml";
6
+ //#region src/format-validation/index.ts
7
+ var STABLE_ID_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/u;
8
+ var VARIABLE_ID_PATTERN = /^[A-Z][A-Z0-9_]*$/u;
9
+ var WINDOWS_RESERVED_ID_PATTERN = /^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])$/u;
10
+ var LINE_BREAK_CHARACTERS = [
11
+ "\n",
12
+ "\r",
13
+ "…",
14
+ "\u2028",
15
+ "\u2029"
16
+ ];
17
+ var UNSUPPORTED_GLOB_PATTERN = /[!?[\]{}]/u;
18
+ var hasLineBreak = (value) => {
19
+ return LINE_BREAK_CHARACTERS.some((lineBreak) => value.includes(lineBreak));
20
+ };
21
+ /** Determines whether a code point belongs to the Repository Format version 1 whitespace set. */
22
+ var isRepositoryFormatWhitespace = (codePoint) => {
23
+ return codePoint >= 9 && codePoint <= 13 || codePoint === 32 || codePoint === 133 || codePoint === 160 || codePoint === 5760 || codePoint >= 8192 && codePoint <= 8202 || codePoint === 8232 || codePoint === 8233 || codePoint === 8239 || codePoint === 8287 || codePoint === 12288;
24
+ };
25
+ /** Counts Unicode scalar values in valid JavaScript text. */
26
+ var countUnicodeScalars = (value) => {
27
+ const scalars = value[Symbol.iterator]();
28
+ let count = 0;
29
+ while (scalars.next().done !== true) count += 1;
30
+ return count;
31
+ };
32
+ /** Determines whether a value contains at least one non-whitespace scalar. */
33
+ var hasNonWhitespace = (value) => {
34
+ for (const scalar of value) if (!isRepositoryFormatWhitespace(scalar.codePointAt(0) ?? 0)) return true;
35
+ return false;
36
+ };
37
+ /** Determines whether a value begins or ends with version 1 whitespace. */
38
+ var hasSurroundingWhitespace = (value) => {
39
+ const firstCodePoint = value.codePointAt(0);
40
+ const lastCodePoint = value.codePointAt(value.length - 1);
41
+ return firstCodePoint !== void 0 && isRepositoryFormatWhitespace(firstCodePoint) || lastCodePoint !== void 0 && isRepositoryFormatWhitespace(lastCodePoint);
42
+ };
43
+ /** Removes only Repository Format version 1 whitespace from both edges. */
44
+ var trimRepositoryFormatWhitespace = (value) => {
45
+ let start = 0;
46
+ let end = value.length;
47
+ while (start < end) {
48
+ const codePoint = value.codePointAt(start);
49
+ if (codePoint === void 0 || !isRepositoryFormatWhitespace(codePoint)) break;
50
+ start += codePoint > 65535 ? 2 : 1;
51
+ }
52
+ while (end > start) {
53
+ const codePoint = value.codePointAt(end - 1);
54
+ if (codePoint === void 0 || !isRepositoryFormatWhitespace(codePoint)) break;
55
+ end -= 1;
56
+ }
57
+ return value.slice(start, end);
58
+ };
59
+ /** Determines whether a string is non-empty and contains no line break. */
60
+ var isNonEmptySingleLine = (value) => {
61
+ return value.length > 0 && !hasLineBreak(value);
62
+ };
63
+ /** Determines whether a value satisfies stable moldea ID syntax. */
64
+ var isStableId = (value) => {
65
+ return value.length <= 64 && STABLE_ID_PATTERN.test(value);
66
+ };
67
+ /** Determines whether an otherwise valid stable ID is filesystem-reserved. */
68
+ var isReservedId = (value) => WINDOWS_RESERVED_ID_PATTERN.test(value);
69
+ /** Determines whether a value satisfies runtime-variable ID syntax. */
70
+ var isVariableId = (value) => {
71
+ return value.length <= 64 && VARIABLE_ID_PATTERN.test(value);
72
+ };
73
+ /** Determines whether a parsed capability description satisfies version 1 limits. */
74
+ var isCapabilityDescription = (value) => {
75
+ const scalarLength = countUnicodeScalars(value);
76
+ return scalarLength >= 1 && scalarLength <= 1e3 && !hasSurroundingWhitespace(value) && !hasLineBreak(value) && !value.includes("\0") && !value.includes("{{") && !value.includes("}}");
77
+ };
78
+ /** Parses a non-root repository-format logical path without throwing. */
79
+ var parseManifestPath = (value) => {
80
+ return value !== "/" && isRepositoryPath(value) ? parseRepositoryPath(value) : null;
81
+ };
82
+ /** Determines whether a path is the canonical manifest path. */
83
+ var isCanonicalManifestPath = (path) => {
84
+ return path === "/moldea/moldea.yaml";
85
+ };
86
+ /** Extracts the stable millisecond ID from one canonical immediate decision path. */
87
+ var parseDecisionIdFromPath = (path) => {
88
+ const match = /^\/moldea\/decisions\/(\d{13})-([a-z0-9]+(?:-[a-z0-9]+)*)\.md$/u.exec(path);
89
+ const id = match?.[1];
90
+ const slug = match?.[2];
91
+ return id !== void 0 && slug !== void 0 && isStableId(slug) ? id : null;
92
+ };
93
+ /** Determines whether a path is an allowed focused-context relationship key. */
94
+ var isContextPath = (path, allowProject) => {
95
+ if (allowProject && path === "/moldea/project.md") return true;
96
+ return path.startsWith("/moldea/context/") && path.endsWith(".md");
97
+ };
98
+ /** Determines whether a path has the canonical immediate decision filename shape. */
99
+ var isDecisionPath = (path) => {
100
+ return parseDecisionIdFromPath(path) !== null;
101
+ };
102
+ /** Determines whether a path is canonical runtime guidance. */
103
+ var isRuntimeGuidancePath = (path) => {
104
+ return path.startsWith("/moldea/runtimes/") && path.endsWith(".md");
105
+ };
106
+ /** Determines whether a mirror path is outside canonical moldea content. */
107
+ var isMirrorPath = (path) => {
108
+ return path !== "/moldea" && !path.startsWith("/moldea/");
109
+ };
110
+ /** Determines whether an impact path contains prohibited glob metacharacters. */
111
+ var hasUnsupportedGlobMetacharacter = (value) => {
112
+ return UNSUPPORTED_GLOB_PATTERN.test(value);
113
+ };
114
+ /** Determines whether a string satisfies the version 1 simple-glob grammar. */
115
+ var isSimpleGlob = (value) => {
116
+ if (hasUnsupportedGlobMetacharacter(value) || value.includes("***")) return false;
117
+ if (value.slice(1).split("/").some((segment) => segment.includes("**") && segment !== "**")) return false;
118
+ return value.includes("*") && isRepositoryPath(value.replaceAll("*", "x"));
119
+ };
120
+ /** Determines whether a repository-reference symbol has the common safe shape. */
121
+ var isRepositorySymbol = (value) => {
122
+ return isNonEmptySingleLine(value) && !value.includes("\0");
123
+ };
124
+ /** Determines whether a canonical moldea reference incorrectly carries a symbol. */
125
+ var isCanonicalMoldeaPath = (path) => {
126
+ return path === "/moldea" || path.startsWith("/moldea/");
127
+ };
128
+ //#endregion
5
129
  //#region src/text/index.ts
6
130
  var encoder = new TextEncoder();
7
131
  var decoder = new TextDecoder("utf-8", {
8
132
  fatal: true,
9
133
  ignoreBOM: true
10
134
  });
11
- var isRecord$1 = (value) => {
12
- return typeof value === "object" && value !== null && !Array.isArray(value);
13
- };
14
- /**
15
- * Measures valid scalar UTF-8 bytes and stops once the operation budget is exceeded.
16
- * @param value The decoded string to measure without lossy replacement.
17
- * @param maximumByteLength The threshold after which measurement may stop early.
18
- * @returns The measured bytes, a value above the threshold, or `null` for invalid Unicode.
19
- */
20
- var measureScalarUtf8ByteLength = (value, maximumByteLength) => {
21
- let byteLength = 0;
22
- for (let index = 0; index < value.length; index += 1) {
23
- const codeUnit = value.charCodeAt(index);
24
- if (codeUnit >= 55296 && codeUnit <= 56319) {
25
- if (index + 1 >= value.length) return null;
26
- const nextCodeUnit = value.charCodeAt(index + 1);
27
- if (nextCodeUnit < 56320 || nextCodeUnit > 57343) return null;
28
- byteLength += 4;
29
- if (byteLength > maximumByteLength) return byteLength;
30
- index += 1;
31
- continue;
32
- }
33
- if (codeUnit >= 56320 && codeUnit <= 57343) return null;
34
- byteLength += codeUnit <= 127 ? 1 : codeUnit <= 2047 ? 2 : 3;
35
- if (byteLength > maximumByteLength) return byteLength;
36
- }
37
- return byteLength;
38
- };
39
- var countUnicodeScalars = (value) => {
40
- let count = 0;
41
- for (let index = 0; index < value.length; count += 1) {
42
- const codePoint = value.codePointAt(index);
43
- if (codePoint === void 0) break;
44
- index += codePoint > 65535 ? 2 : 1;
45
- }
46
- return count;
47
- };
48
135
  /**
49
136
  * Collects every normalized NUL location or rejects when the diagnostic budget is exhausted.
50
137
  * @param value The normalized scalar text to inspect.
@@ -99,7 +186,7 @@ var enforceFileLimit = (byteLength, limits, operation, limit) => {
99
186
  });
100
187
  };
101
188
  var invalidResult = (diagnostics) => {
102
- return freezeRecursively({
189
+ return deepFreeze({
103
190
  diagnostics: [...diagnostics],
104
191
  text: null,
105
192
  valid: false
@@ -119,21 +206,20 @@ var invalidResult = (diagnostics) => {
119
206
  * - RESOURCE_LIMIT_EXCEEDED: A Core resource limit was exceeded.
120
207
  */
121
208
  var readInput = (input, limits, operation, limit, diagnostics) => {
122
- if (!isRecord$1(input)) return invalidArgument$1(operation);
209
+ if (!isObjectValid(input, true)) return invalidArgument$1(operation);
123
210
  const pathCandidate = input["path"];
124
211
  const content = input["content"];
125
212
  if (typeof pathCandidate !== "string" || typeof content !== "string" && !(content instanceof Uint8Array)) return invalidArgument$1(operation);
126
213
  const path = parseRepositoryPath(pathCandidate);
127
214
  if (typeof content === "string") {
128
- const byteLength = measureScalarUtf8ByteLength(content, limits[limit]);
129
- if (byteLength === null) {
215
+ enforceFileLimit(countUtf8Bytes(content, limits[limit]), limits, operation, limit);
216
+ if (!content.isWellFormed()) {
130
217
  diagnostics.add({
131
218
  code: "MOLDEA_TEXT_INVALID_UNICODE",
132
219
  path
133
220
  });
134
221
  return invalidResult(diagnostics.finalize());
135
222
  }
136
- enforceFileLimit(byteLength, limits, operation, limit);
137
223
  return {
138
224
  path,
139
225
  value: content
@@ -173,12 +259,12 @@ var normalizeTextDocument = (input, limits, operation, limit = "maxFileBytes") =
173
259
  const value = (decoded.value.startsWith("") ? decoded.value.slice(1) : decoded.value).replace(/\r\n?/gu, "\n");
174
260
  collectNulDiagnostics(value, decoded.path, diagnostics);
175
261
  if (diagnostics.size > 0) return invalidResult(diagnostics.finalize());
176
- const text = freezeRecursively({
262
+ const text = deepFreeze({
177
263
  scalarLength: countUnicodeScalars(value),
178
- utf8ByteLength: encoder.encode(value).byteLength,
264
+ utf8ByteLength: countUtf8Bytes(value),
179
265
  value
180
266
  });
181
- return freezeRecursively({
267
+ return deepFreeze({
182
268
  diagnostics: [],
183
269
  text,
184
270
  valid: true
@@ -210,14 +296,14 @@ var calculateNormalizedTextDigest = async (text) => {
210
296
  */
211
297
  var calculateContentDigest = async (input, limits) => {
212
298
  const normalized = normalizeTextDocument(input, limits, "calculate-content-digest");
213
- if (!normalized.valid || normalized.text === null) return freezeRecursively({
299
+ if (!normalized.valid || normalized.text === null) return deepFreeze({
214
300
  diagnostics: normalized.diagnostics,
215
301
  digest: null,
216
302
  text: null,
217
303
  valid: false
218
304
  });
219
305
  const digest = await calculateNormalizedTextDigest(normalized.text);
220
- return freezeRecursively({
306
+ return deepFreeze({
221
307
  diagnostics: [],
222
308
  digest,
223
309
  text: normalized.text,
@@ -225,68 +311,6 @@ var calculateContentDigest = async (input, limits) => {
225
311
  });
226
312
  };
227
313
  //#endregion
228
- //#region src/scope-matching/validations.ts
229
- var isRecord = (value) => {
230
- return typeof value === "object" && value !== null && !Array.isArray(value);
231
- };
232
- /** Throws the stable invalid-argument failure for malformed scope input. */
233
- var invalidArgument = () => {
234
- throw new CoreOperationException({
235
- code: "INVALID_ARGUMENT",
236
- operation: "match-manifest-scope"
237
- });
238
- };
239
- /** Throws the stable resource failure for an exhausted scope-input budget. */
240
- var resourceLimitExceeded = (limit, limitMaximum, observedUsage) => {
241
- throw new CoreOperationException({
242
- code: "RESOURCE_LIMIT_EXCEEDED",
243
- limit,
244
- limitMaximum,
245
- nextAction: "reduce-input-or-increase-limit",
246
- observedUsage,
247
- operation: "match-manifest-scope"
248
- });
249
- };
250
- /** Measures scalar UTF-8 bytes without allocating an encoded copy. */
251
- var measureUtf8ByteLength = (value) => {
252
- let byteLength = 0;
253
- for (const scalar of value) {
254
- const codePoint = scalar.codePointAt(0) ?? 0;
255
- byteLength += codePoint <= 127 ? 1 : codePoint <= 2047 ? 2 : codePoint <= 65535 ? 3 : 4;
256
- }
257
- return byteLength;
258
- };
259
- /**
260
- * Validates and snapshots one public manifest-scope input.
261
- * @param input The untrusted manifest document and changed logical paths.
262
- * @param limits The immutable Core resource limits.
263
- * @returns The detached manifest input and sorted unique repository paths.
264
- * @throws
265
- * - INVALID_REPOSITORY_PATH: A changed repository path is invalid.
266
- * - INVALID_ARGUMENT: The scope operation received an invalid argument.
267
- * - RESOURCE_LIMIT_EXCEEDED: The changed-path count or byte budget was exceeded.
268
- */
269
- var normalizeManifestScopeInput = (input, limits) => {
270
- if (!isRecord(input)) return invalidArgument();
271
- const manifest = input["manifest"];
272
- const pathCandidates = input["paths"];
273
- if (!isRecord(manifest) || !Array.isArray(pathCandidates)) return invalidArgument();
274
- if (pathCandidates.length > limits.maxEntries) return resourceLimitExceeded("maxEntries", limits.maxEntries, pathCandidates.length);
275
- const uniquePaths = /* @__PURE__ */ new Set();
276
- let totalBytes = 0;
277
- for (const [index, candidate] of pathCandidates.entries()) {
278
- if (typeof candidate !== "string") return invalidArgument();
279
- const path = parseRepositoryPath(candidate);
280
- totalBytes += measureUtf8ByteLength(path) + (index === 0 ? 0 : 1);
281
- if (totalBytes > limits.maxTotalBytesRead) return resourceLimitExceeded("maxTotalBytesRead", limits.maxTotalBytesRead, totalBytes);
282
- uniquePaths.add(path);
283
- }
284
- return {
285
- manifest,
286
- paths: [...uniquePaths].sort(compareExactStrings)
287
- };
288
- };
289
- //#endregion
290
314
  //#region src/scope-matching/patterns.ts
291
315
  /** Tests a single-segment wildcard without regular-expression interpretation. */
292
316
  var matchesSegment = (pattern, value) => {
@@ -343,13 +367,13 @@ var createOwner = (kind, id, agentId = null) => ({
343
367
  kind
344
368
  });
345
369
  var compareOwners = (left, right) => {
346
- return compareExactStrings(left.kind, right.kind) || compareExactStrings(left.agentId ?? "", right.agentId ?? "") || compareExactStrings(left.id, right.id);
370
+ return compareCodePoints(left.kind, right.kind) || compareCodePoints(left.agentId ?? "", right.agentId ?? "") || compareCodePoints(left.id, right.id);
347
371
  };
348
372
  var getDeclarationValue = (declaration) => {
349
373
  return declaration.kind === "exact" ? declaration.path : declaration.pattern;
350
374
  };
351
375
  var compareDeclarations = (left, right) => {
352
- return compareOwners(left.owner, right.owner) || compareExactStrings(left.field, right.field) || compareExactStrings(getDeclarationValue(left.declaration), getDeclarationValue(right.declaration)) || compareExactStrings(left.pointer, right.pointer);
376
+ return compareOwners(left.owner, right.owner) || compareCodePoints(left.field, right.field) || compareCodePoints(getDeclarationValue(left.declaration), getDeclarationValue(right.declaration)) || compareCodePoints(left.pointer, right.pointer);
353
377
  };
354
378
  /** Adds one exact repository relationship to the normalized declaration collection. */
355
379
  var addExactDeclaration = (declarations, owner, field, pointer, reference) => {
@@ -390,7 +414,7 @@ var addAffectedByDeclarations = (declarations, affectedBy, owner, pointer) => {
390
414
  };
391
415
  /** Adds project-level or agent-level unresolved requirement references. */
392
416
  var addUnresolvedDeclarations = (declarations, requirements, pointer, agentId) => {
393
- for (const requirementId of Object.keys(requirements ?? {}).sort(compareExactStrings)) {
417
+ for (const requirementId of Object.keys(requirements ?? {}).sort(compareCodePoints)) {
394
418
  const requirement = requirements?.[requirementId];
395
419
  if (requirement === void 0) continue;
396
420
  const owner = createOwner("unresolved", requirementId, agentId);
@@ -422,19 +446,19 @@ var addAgentDeclarations = (declarations, agentId, agent) => {
422
446
  const reference = agent.bindings?.[field];
423
447
  if (reference !== void 0) addExactDeclaration(declarations, owner, field, childPointer$1(bindingsPointer, field), reference);
424
448
  }
425
- for (const variableId of Object.keys(agent.bindings?.variableProviders ?? {}).sort(compareExactStrings)) {
449
+ for (const variableId of Object.keys(agent.bindings?.variableProviders ?? {}).sort(compareCodePoints)) {
426
450
  const reference = agent.bindings?.variableProviders?.[variableId];
427
451
  if (reference !== void 0) addExactDeclaration(declarations, owner, "variableProvider", childPointer$1(childPointer$1(bindingsPointer, "variableProviders"), variableId), reference);
428
452
  }
429
453
  addAffectedByDeclarations(declarations, agent.affectedBy, owner, childPointer$1(pointer, "affectedBy"));
430
- for (const capabilityId of Object.keys(agent.tools ?? {}).sort(compareExactStrings)) {
454
+ for (const capabilityId of Object.keys(agent.tools ?? {}).sort(compareCodePoints)) {
431
455
  const tool = agent.tools?.[capabilityId];
432
456
  if (tool !== void 0) addCapabilityDeclarations(declarations, capabilityId, {
433
457
  kind: "tool",
434
458
  value: tool
435
459
  }, agentId, childPointer$1(childPointer$1(pointer, "tools"), capabilityId));
436
460
  }
437
- for (const capabilityId of Object.keys(agent.skills ?? {}).sort(compareExactStrings)) {
461
+ for (const capabilityId of Object.keys(agent.skills ?? {}).sort(compareCodePoints)) {
438
462
  const skill = agent.skills?.[capabilityId];
439
463
  if (skill !== void 0) addCapabilityDeclarations(declarations, capabilityId, {
440
464
  kind: "skill",
@@ -449,7 +473,7 @@ var collectManifestScopeDeclarations = (manifest) => {
449
473
  const declarations = [];
450
474
  for (const kind of ["context", "decision"]) {
451
475
  const relationships = kind === "context" ? manifest.context : manifest.decisions;
452
- for (const ownerId of Object.keys(relationships ?? {}).sort(compareExactStrings)) {
476
+ for (const ownerId of Object.keys(relationships ?? {}).sort(compareCodePoints)) {
453
477
  const relationship = relationships?.[ownerId];
454
478
  if (relationship === void 0) continue;
455
479
  const owner = createOwner(kind, ownerId);
@@ -459,7 +483,7 @@ var collectManifestScopeDeclarations = (manifest) => {
459
483
  }
460
484
  }
461
485
  addUnresolvedDeclarations(declarations, manifest.unresolved, "/unresolved", null);
462
- for (const agentId of Object.keys(manifest.agents ?? {}).sort(compareExactStrings)) {
486
+ for (const agentId of Object.keys(manifest.agents ?? {}).sort(compareCodePoints)) {
463
487
  const agent = manifest.agents?.[agentId];
464
488
  if (agent !== void 0) addAgentDeclarations(declarations, agentId, agent);
465
489
  }
@@ -507,7 +531,7 @@ var compileManifestScope = (manifest, limits) => {
507
531
  };
508
532
  };
509
533
  var compareMatches = (left, right) => {
510
- return compareOwners(left.owner, right.owner) || compareExactStrings(left.field, right.field) || compareExactStrings(getDeclarationValue(left.declaration), getDeclarationValue(right.declaration)) || compareExactStrings(left.inputPath, right.inputPath) || compareExactStrings(left.pointer, right.pointer);
534
+ return compareOwners(left.owner, right.owner) || compareCodePoints(left.field, right.field) || compareCodePoints(getDeclarationValue(left.declaration), getDeclarationValue(right.declaration)) || compareCodePoints(left.inputPath, right.inputPath) || compareCodePoints(left.pointer, right.pointer);
511
535
  };
512
536
  var createMatch = (inputPath, relationship) => ({
513
537
  declaration: relationship.declaration,
@@ -536,8 +560,8 @@ var addGlobMatches = (matches, inputPath, declarations, limits) => {
536
560
  var calculateManifestScopeInputDigest = async (paths) => {
537
561
  const value = paths.join("\0");
538
562
  return calculateNormalizedTextDigest({
539
- scalarLength: countUnicodeScalars$1(value),
540
- utf8ByteLength: measureUtf8ByteLength(value),
563
+ scalarLength: countUnicodeScalars(value),
564
+ utf8ByteLength: countUtf8Bytes(value),
541
565
  value
542
566
  });
543
567
  };
@@ -567,7 +591,7 @@ var matchParsedManifestScope = (manifest, paths, limits) => {
567
591
  matchedOwners.add(`${match.owner.kind}\0${match.owner.agentId ?? ""}\0${match.owner.id}`);
568
592
  matchedPaths.add(match.inputPath);
569
593
  }
570
- return freezeRecursively({
594
+ return deepFreeze({
571
595
  counts: {
572
596
  declarations: compiled.declarations.length,
573
597
  inputPaths: paths.length,
@@ -799,7 +823,7 @@ var readRelationshipRecord = (node, pointer, kind, context) => {
799
823
  const entries = readMapping(node, pointer, null, context);
800
824
  if (entries === null) return null;
801
825
  const normalized = [];
802
- for (const [key, entry] of [...entries].sort(([left], [right]) => compareExactStrings(left, right))) {
826
+ for (const [key, entry] of [...entries].sort(([left], [right]) => compareCodePoints(left, right))) {
803
827
  const path = parseManifestPath(key);
804
828
  if (!(path !== null && (kind === "context" ? isContextPath(path, true) : isDecisionPath(path)))) {
805
829
  context.diagnostics.add({
@@ -921,7 +945,7 @@ var readVariables = (node, pointer, context, agentId) => {
921
945
  const entries = readMapping(node, pointer, null, context, { agentId });
922
946
  if (entries === null) return null;
923
947
  const normalized = [];
924
- for (const [variableId, entry] of [...entries].sort(([left], [right]) => compareExactStrings(left, right))) {
948
+ for (const [variableId, entry] of [...entries].sort(([left], [right]) => compareCodePoints(left, right))) {
925
949
  const entity = {
926
950
  agentId,
927
951
  variableId
@@ -968,7 +992,7 @@ var readBindings = (node, pointer, context, agentId, declaredVariables) => {
968
992
  const providers = readMapping(providersEntry.value, childPointer(pointer, "variableProviders"), null, context, entity);
969
993
  if (providers !== null) {
970
994
  const normalized = [];
971
- for (const [variableId, providerEntry] of [...providers].sort(([left], [right]) => compareExactStrings(left, right))) {
995
+ for (const [variableId, providerEntry] of [...providers].sort(([left], [right]) => compareCodePoints(left, right))) {
972
996
  const variableEntity = {
973
997
  agentId,
974
998
  variableId
@@ -1078,7 +1102,7 @@ var readCapabilities = (node, pointer, context, agentId, kind) => {
1078
1102
  const entries = readMapping(node, pointer, null, context, { agentId });
1079
1103
  if (entries === null) return null;
1080
1104
  const normalized = [];
1081
- for (const [capabilityId, entry] of [...entries].sort(([left], [right]) => compareExactStrings(left, right))) {
1105
+ for (const [capabilityId, entry] of [...entries].sort(([left], [right]) => compareCodePoints(left, right))) {
1082
1106
  const entity = {
1083
1107
  agentId,
1084
1108
  capabilityId,
@@ -1095,7 +1119,7 @@ var readUnresolved = (node, pointer, context, agentId) => {
1095
1119
  const entries = readMapping(node, pointer, null, context, agentId === void 0 ? null : { agentId });
1096
1120
  if (entries === null) return null;
1097
1121
  const normalized = [];
1098
- for (const [requirementId, entry] of [...entries].sort(([left], [right]) => compareExactStrings(left, right))) {
1122
+ for (const [requirementId, entry] of [...entries].sort(([left], [right]) => compareCodePoints(left, right))) {
1099
1123
  const entity = agentId === void 0 ? null : { agentId };
1100
1124
  const requirementPointer = childPointer(pointer, requirementId);
1101
1125
  validateStableId(requirementId, entry.key.range, requirementPointer, context, entity);
@@ -1242,7 +1266,7 @@ var readAgents = (node, pointer, context) => {
1242
1266
  const entries = readMapping(node, pointer, null, context);
1243
1267
  if (entries === null) return null;
1244
1268
  const normalized = [];
1245
- for (const [agentId, entry] of [...entries].sort(([left], [right]) => compareExactStrings(left, right))) {
1269
+ for (const [agentId, entry] of [...entries].sort(([left], [right]) => compareCodePoints(left, right))) {
1246
1270
  const agentPointer = childPointer(pointer, agentId);
1247
1271
  validateStableId(agentId, entry.key.range, agentPointer, context, { agentId });
1248
1272
  const agent = readAgent(entry.value, agentPointer, context, agentId);
@@ -1331,7 +1355,7 @@ var readAcceptedWarnings = (node, context) => {
1331
1355
  report(index, "subject", fields.get("subject").range, "repository-path-required");
1332
1356
  isValid = false;
1333
1357
  }
1334
- if (reason !== null && countUnicodeScalars$1(reason) > 256) {
1358
+ if (reason !== null && countUnicodeScalars(reason) > 256) {
1335
1359
  report(index, "reason", fields.get("reason").range, "maximum-256-characters");
1336
1360
  isValid = false;
1337
1361
  }
@@ -1506,17 +1530,6 @@ var addUnsupportedFeature = (diagnostics, path, range, reason) => {
1506
1530
  range
1507
1531
  });
1508
1532
  };
1509
- var isUnicodeScalarString = (value) => {
1510
- for (let index = 0; index < value.length; index += 1) {
1511
- const codeUnit = value.charCodeAt(index);
1512
- if (codeUnit >= 55296 && codeUnit <= 56319) {
1513
- const nextCodeUnit = value.charCodeAt(index + 1);
1514
- if (!(nextCodeUnit >= 56320 && nextCodeUnit <= 57343)) return false;
1515
- index += 1;
1516
- } else if (codeUnit >= 56320 && codeUnit <= 57343) return false;
1517
- }
1518
- return true;
1519
- };
1520
1533
  var isCoreTagCompatible = (node) => {
1521
1534
  switch (node.tag) {
1522
1535
  case "tag:yaml.org,2002:bool": return isScalar(node) && typeof node.value === "boolean";
@@ -1562,7 +1575,7 @@ var convertNode = (node, path, locator, diagnostics) => {
1562
1575
  });
1563
1576
  return null;
1564
1577
  }
1565
- if (typeof value === "string" && !isUnicodeScalarString(value)) {
1578
+ if (typeof value === "string" && !value.isWellFormed()) {
1566
1579
  diagnostics.add({
1567
1580
  code: "MOLDEA_YAML_MALFORMED",
1568
1581
  details: { reason: "invalid-unicode" },
@@ -1726,7 +1739,7 @@ var inspectManifestDocument = async (input, options, operation = "parse-manifest
1726
1739
  path
1727
1740
  });
1728
1741
  for (const diagnostic of normalized.diagnostics) diagnostics.merge(diagnostic);
1729
- if (!normalized.valid || normalized.text === null) return freezeRecursively({
1742
+ if (!normalized.valid || normalized.text === null) return deepFreeze({
1730
1743
  asset: null,
1731
1744
  diagnostics: diagnostics.finalize(),
1732
1745
  formatVersion: null,
@@ -1737,7 +1750,7 @@ var inspectManifestDocument = async (input, options, operation = "parse-manifest
1737
1750
  const parsed = parseStrictYaml(normalized.text.value, path, locator, diagnostics);
1738
1751
  const formatVersion = parsed.value === null ? null : detectSupportedManifestVersion(parsed.value);
1739
1752
  const manifest = parsed.valid && parsed.value !== null ? validateManifest(parsed.value, path, diagnostics, options.limits, operation) : null;
1740
- if (manifest === null || diagnostics.size > 0) return freezeRecursively({
1753
+ if (manifest === null || diagnostics.size > 0) return deepFreeze({
1741
1754
  asset: null,
1742
1755
  diagnostics: diagnostics.finalize(),
1743
1756
  formatVersion,
@@ -1752,7 +1765,7 @@ var inspectManifestDocument = async (input, options, operation = "parse-manifest
1752
1765
  scalarLength: normalized.text.scalarLength,
1753
1766
  utf8ByteLength: normalized.text.utf8ByteLength
1754
1767
  };
1755
- return freezeRecursively({
1768
+ return deepFreeze({
1756
1769
  asset,
1757
1770
  diagnostics: diagnostics.finalize(),
1758
1771
  formatVersion,
@@ -1772,7 +1785,7 @@ var inspectManifestDocument = async (input, options, operation = "parse-manifest
1772
1785
  */
1773
1786
  var parseManifestDocument = async (input, options, operation = "parse-manifest") => {
1774
1787
  const inspection = await inspectManifestDocument(input, options, operation);
1775
- return freezeRecursively({
1788
+ return deepFreeze({
1776
1789
  asset: inspection.asset,
1777
1790
  diagnostics: inspection.diagnostics,
1778
1791
  manifest: inspection.manifest,
@@ -1780,6 +1793,56 @@ var parseManifestDocument = async (input, options, operation = "parse-manifest")
1780
1793
  });
1781
1794
  };
1782
1795
  //#endregion
1796
+ //#region src/scope-matching/validations.ts
1797
+ /** Throws the stable invalid-argument failure for malformed scope input. */
1798
+ var invalidArgument = () => {
1799
+ throw new CoreOperationException({
1800
+ code: "INVALID_ARGUMENT",
1801
+ operation: "match-manifest-scope"
1802
+ });
1803
+ };
1804
+ /** Throws the stable resource failure for an exhausted scope-input budget. */
1805
+ var resourceLimitExceeded = (limit, limitMaximum, observedUsage) => {
1806
+ throw new CoreOperationException({
1807
+ code: "RESOURCE_LIMIT_EXCEEDED",
1808
+ limit,
1809
+ limitMaximum,
1810
+ nextAction: "reduce-input-or-increase-limit",
1811
+ observedUsage,
1812
+ operation: "match-manifest-scope"
1813
+ });
1814
+ };
1815
+ /**
1816
+ * Validates and snapshots one public manifest-scope input.
1817
+ * @param input The untrusted manifest document and changed logical paths.
1818
+ * @param limits The immutable Core resource limits.
1819
+ * @returns The detached manifest input and sorted unique repository paths.
1820
+ * @throws
1821
+ * - INVALID_REPOSITORY_PATH: A changed repository path is invalid.
1822
+ * - INVALID_ARGUMENT: The scope operation received an invalid argument.
1823
+ * - RESOURCE_LIMIT_EXCEEDED: The changed-path count or byte budget was exceeded.
1824
+ */
1825
+ var normalizeManifestScopeInput = (input, limits) => {
1826
+ if (!isObjectValid(input, true)) return invalidArgument();
1827
+ const manifest = input["manifest"];
1828
+ const pathCandidates = input["paths"];
1829
+ if (!isObjectValid(manifest, true) || !Array.isArray(pathCandidates)) return invalidArgument();
1830
+ if (pathCandidates.length > limits.maxEntries) return resourceLimitExceeded("maxEntries", limits.maxEntries, pathCandidates.length);
1831
+ const uniquePaths = /* @__PURE__ */ new Set();
1832
+ let totalBytes = 0;
1833
+ for (const [index, candidate] of pathCandidates.entries()) {
1834
+ if (typeof candidate !== "string") return invalidArgument();
1835
+ const path = parseRepositoryPath(candidate);
1836
+ totalBytes += countUtf8Bytes(path) + (index === 0 ? 0 : 1);
1837
+ if (totalBytes > limits.maxTotalBytesRead) return resourceLimitExceeded("maxTotalBytesRead", limits.maxTotalBytesRead, totalBytes);
1838
+ uniquePaths.add(path);
1839
+ }
1840
+ return {
1841
+ manifest,
1842
+ paths: [...uniquePaths].sort(compareCodePoints)
1843
+ };
1844
+ };
1845
+ //#endregion
1783
1846
  //#region src/scope-matching/scope.ts
1784
1847
  /**
1785
1848
  * Parses a manifest and matches its repository relationships against changed logical paths.
@@ -1795,7 +1858,7 @@ var matchManifestScope = async (input, options) => {
1795
1858
  const normalized = normalizeManifestScopeInput(input, options.limits);
1796
1859
  const inputDigest = await calculateManifestScopeInputDigest(normalized.paths);
1797
1860
  const parsed = await parseManifestDocument(normalized.manifest, options, "match-manifest-scope");
1798
- if (!parsed.valid || parsed.asset === null || parsed.manifest === null) return freezeRecursively({
1861
+ if (!parsed.valid || parsed.asset === null || parsed.manifest === null) return deepFreeze({
1799
1862
  counts: {
1800
1863
  declarations: 0,
1801
1864
  inputPaths: normalized.paths.length,
@@ -1811,7 +1874,7 @@ var matchManifestScope = async (input, options) => {
1811
1874
  valid: false
1812
1875
  });
1813
1876
  const matched = matchParsedManifestScope(parsed.manifest, normalized.paths, options.limits);
1814
- return freezeRecursively({
1877
+ return deepFreeze({
1815
1878
  counts: matched.counts,
1816
1879
  diagnostics: [],
1817
1880
  inputDigest,
@@ -1822,6 +1885,6 @@ var matchManifestScope = async (input, options) => {
1822
1885
  });
1823
1886
  };
1824
1887
  //#endregion
1825
- export { createSourceLocator as a, calculateContentDigest as c, parseStrictYaml as i, calculateNormalizedTextDigest as l, inspectManifestDocument as n, collectManifestScopeDeclarations as o, parseManifestDocument as r, matchesRepositoryGlob as s, matchManifestScope as t, normalizeTextDocument as u };
1888
+ export { trimRepositoryFormatWhitespace as _, createSourceLocator as a, calculateContentDigest as c, countUnicodeScalars as d, hasNonWhitespace as f, parseDecisionIdFromPath as g, isVariableId as h, parseStrictYaml as i, calculateNormalizedTextDigest as l, isRuntimeGuidancePath as m, inspectManifestDocument as n, collectManifestScopeDeclarations as o, isContextPath as p, parseManifestDocument as r, matchesRepositoryGlob as s, matchManifestScope as t, normalizeTextDocument as u };
1826
1889
 
1827
- //# sourceMappingURL=scope-D9BYchNI.js.map
1890
+ //# sourceMappingURL=scope-CNg6Gnpi.js.map