@moldea.ai/core 9.1.1 → 9.2.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.
package/README.md CHANGED
@@ -90,12 +90,16 @@ Every diagnostic has `severity`, `group`, and stable `source: 'core'`. The group
90
90
 
91
91
  Managed-block comparison tolerates LF/CRLF differences, an optional final line break, empty lines immediately inside the markers, and spaces or tabs after marker comments. It preserves exact instruction text and internal whitespace; duplicate, reversed, missing, or otherwise malformed markers still produce diagnostics.
92
92
 
93
+ Core 9.2 supplies normalized scalar-based source ranges for pointer-addressed manifest and decision YAML diagnostics, including cross-file findings and unmatched acceptances. Missing members point to their nearest existing ancestor; existing explicit ranges stay unchanged. See [diagnostic locations](docs/diagnostics.md) for member spans and unavailable-source behavior.
94
+
93
95
  ## Resource and trust boundaries
94
96
 
95
97
  Core uses independent limits for distinct entries, total bytes read, per-file bytes, manifest bytes, logical retained bytes, diagnostics, and coverage records. The default logical retained-memory ceiling is 512 MiB. Before reading a supported source for export analysis, Core checks `maxFileBytes`, confirms read-buffer headroom, and reserves `65536 + sourceBytes * (8 + 512)` bytes for text and syntax nodes. An oversized source or reservation miss records `resource-limit` without a source read; a subsequent failed read, cancellation, or operation budget failure rejects the whole operation. Each distinct source is parsed at most once per operation. Source buffers and syntax reservations are released after analysis; only export names remain in the inventory cache. Core executes no repository code, follows instruction links only inside the snapshot, receives no host path or source credential, and returns logical paths only.
96
98
 
97
99
  Logical `RESOURCE_LIMIT_EXCEEDED` exceptions identify the exceeded limit, its configured maximum, the observed or projected usage, and `reduce-input-or-increase-limit`. Verified isolated-worker heap exhaustion uses `review-inspection-capacity` with unknown observed usage. Fixed transport limits have no next action. Core refuses an operation before allocating retained state beyond the applicable ceiling.
98
100
 
101
+ Private manifest and decision YAML trees and their pointer-lookup storage also reserve logical retained memory until final locations are resolved. These reservations are released on success or failure; they do not remain in prepared inspection handles.
102
+
99
103
  ## Development
100
104
 
101
105
  From the monorepo root:
@@ -1,4 +1,4 @@
1
- import { n as normalizeCoreOptions } from "./chunks/options-C5360E_N.js";
1
+ import { n as normalizeCoreOptions } from "./chunks/options-BXKLnSDR.js";
2
2
  import { n as CoreOperationException } from "./chunks/exceptions-AT654xUL.js";
3
3
  import { a as encodeInspectionMessage, d as NODE_INSPECTION_TRANSPORT_BYTES, i as decodeInspectionMessage, n as serializeInspectionFailure, o as NODE_INSPECTION_FILE_PAGE_BYTES, r as createInspectionProcessFailure, t as deserializeInspectionFailure } from "./chunks/errors-Uvb-9X1u.js";
4
4
  import { a as parseRpcLinkText, i as parseRpcFilePage, n as parseRpcEntry, r as parseRpcEntryPage } from "./chunks/repository-rpc-B9YaeLba.js";
@@ -91,7 +91,7 @@ var repository = createProxyReader("repository", start.snapshot);
91
91
  var instructions = start.instructions === null ? null : createProxyReader("instructions", start.instructions.snapshot);
92
92
  /** Prepares the fixed Core implementation after the parent acknowledges the heap. */
93
93
  var prepare = async () => {
94
- const { createCore } = await import("./chunks/core-DuaKbQLI.js").then((n) => n.t);
94
+ const { createCore } = await import("./chunks/core-DOzzzqoB.js").then((n) => n.t);
95
95
  inspection = await createCore(normalizeCoreOptions({ limits: {
96
96
  ...start.limits,
97
97
  maxRetainedBytes: start.limits.maxRetainedBytes - NODE_INSPECTION_TRANSPORT_BYTES
@@ -1,6 +1,6 @@
1
- import { a as escapeJsonPointerSegment, i as createCoreDiagnosticCollector, n as normalizeCoreOptions, o as normalizeDiagnostics, r as countDiagnosticsBySeverity, s as createNullPrototypeRecord, t as createCoreOperationOptionsSnapshot } from "./options-C5360E_N.js";
1
+ import { a as escapeJsonPointerSegment, c as measureYamlRetainedBytes, i as createCoreDiagnosticCollector, l as parseStrictYaml, n as normalizeCoreOptions, o as locateDiagnosticRanges, r as countDiagnosticsBySeverity, s as normalizeDiagnostics, t as createCoreOperationOptionsSnapshot, u as createNullPrototypeRecord } from "./options-BXKLnSDR.js";
2
2
  import { n as CoreOperationException } from "./exceptions-AT654xUL.js";
3
- import { _ as trimRepositoryFormatWhitespace, a as createSourceLocator, c as calculateContentDigest, d as countUnicodeScalars, f as hasNonWhitespace, g as parseDecisionIdFromPath, h as isVariableId, i as parseStrictYaml, l as calculateNormalizedTextDigest, m as isRuntimeGuidancePath, n as inspectManifestDocument, o as collectManifestScopeDeclarations, p as isContextPath, r as parseManifestDocument, s as matchesRepositoryGlob, t as matchManifestScope, u as normalizeTextDocument } from "./scope-CNg6Gnpi.js";
3
+ import { a as collectManifestScopeDeclarations, c as calculateNormalizedTextDigest, d as hasNonWhitespace, f as isContextPath, g as trimRepositoryFormatWhitespace, h as parseDecisionIdFromPath, i as createSourceLocator, l as normalizeTextDocument, m as isVariableId, n as inspectManifestDocument, o as matchesRepositoryGlob, p as isRuntimeGuidancePath, r as parseManifestDocument, s as calculateContentDigest, t as matchManifestScope, u as countUnicodeScalars } from "./scope-COlv6gct.js";
4
4
  import { ERRORS, compareCodePoints, deepFreeze, findMarkedRegion, isObjectValid } from "jg-utilities";
5
5
  import { hasErrorCode } from "jg-exception";
6
6
  import { REPOSITORY_LINK_TEXT_MAX_BYTES, REPOSITORY_ROOT, RepositorySourceException, compareRepositoryPaths, createRepositoryIdentity, isRepositoryPath, parseRepositoryPath, resolveRepositoryLink } from "@moldea.ai/repository";
@@ -352,7 +352,7 @@ var validateDecisionBody = (body, range, context) => {
352
352
  * - INVALID_ARGUMENT: The Core operation received an invalid argument.
353
353
  * - RESOURCE_LIMIT_EXCEEDED: A Core resource limit was exceeded.
354
354
  */
355
- var parseDecisionDocument = async (input, options, operation = "parse-decision") => {
355
+ var inspectDecisionDocument = async (input, options, operation = "parse-decision") => {
356
356
  options = createCoreOperationOptionsSnapshot(options);
357
357
  const normalized = normalizeTextDocument(input, options.limits, operation);
358
358
  const path = parseRepositoryPath(input.path);
@@ -366,7 +366,8 @@ var parseDecisionDocument = async (input, options, operation = "parse-decision")
366
366
  if (!normalized.valid || normalized.text === null) return deepFreeze({
367
367
  decision: null,
368
368
  diagnostics: diagnostics.finalize(),
369
- valid: false
369
+ valid: false,
370
+ yamlRoot: null
370
371
  });
371
372
  const context = {
372
373
  decisionId,
@@ -376,15 +377,19 @@ var parseDecisionDocument = async (input, options, operation = "parse-decision")
376
377
  const locator = createSourceLocator(normalized.text.value);
377
378
  const sections = extractDecisionSections(normalized.text.value, locator, context);
378
379
  let metadata = null;
380
+ let yamlRoot = null;
379
381
  if (sections !== null) {
380
382
  validateDecisionBody(sections.body, sections.bodyRange, context);
381
383
  const parsed = parseStrictYaml(sections.yaml, path, locator, diagnostics);
384
+ yamlRoot = parsed.value;
382
385
  if (parsed.valid && parsed.value !== null) metadata = validateDecisionFrontmatter(parsed.value, context);
383
386
  }
387
+ const locatedDiagnostics = locateDiagnosticRanges(diagnostics.finalize(), new Map(yamlRoot === null ? [] : [[path, yamlRoot]]));
384
388
  if (decisionId === null || sections === null || metadata === null || diagnostics.size > 0) return deepFreeze({
385
389
  decision: null,
386
- diagnostics: diagnostics.finalize(),
387
- valid: false
390
+ diagnostics: locatedDiagnostics,
391
+ valid: false,
392
+ yamlRoot
388
393
  });
389
394
  const digest = await calculateNormalizedTextDigest(normalized.text);
390
395
  const asset = {
@@ -404,8 +409,25 @@ var parseDecisionDocument = async (input, options, operation = "parse-decision")
404
409
  status: metadata.status,
405
410
  supersedes: metadata.supersedes
406
411
  },
407
- diagnostics: diagnostics.finalize(),
408
- valid: true
412
+ diagnostics: locatedDiagnostics,
413
+ valid: true,
414
+ yamlRoot
415
+ });
416
+ };
417
+ /**
418
+ * Parses a decision without exposing private YAML nodes to public callers.
419
+ * @returns The immutable decision parse result.
420
+ * @throws
421
+ * - INVALID_REPOSITORY_PATH: The repository path is invalid.
422
+ * - INVALID_ARGUMENT: The Core operation received an invalid argument.
423
+ * - RESOURCE_LIMIT_EXCEEDED: A Core resource limit was exceeded.
424
+ */
425
+ var parseDecisionDocument = async (input, options, operation = "parse-decision") => {
426
+ const inspection = await inspectDecisionDocument(input, options, operation);
427
+ return deepFreeze({
428
+ decision: inspection.decision,
429
+ diagnostics: inspection.diagnostics,
430
+ valid: inspection.valid
409
431
  });
410
432
  };
411
433
  //#endregion
@@ -1751,6 +1773,7 @@ var sortDecisions = (decisions) => {
1751
1773
  * @param paths The decision candidates retained by canonical discovery.
1752
1774
  * @param options The immutable Core limit snapshot.
1753
1775
  * @param signal Optional cancellation forwarded to every repository read.
1776
+ * @param retainYamlRoot Optional inspection owner that admits private roots to its memory ledger.
1754
1777
  * @returns A deeply immutable internal decision set and its deterministic diagnostics.
1755
1778
  * @throws
1756
1779
  * - ENTRY_NOT_FOUND: The requested repository entry was not found.
@@ -1764,7 +1787,7 @@ var sortDecisions = (decisions) => {
1764
1787
  * - ABORTED: The Core operation was aborted.
1765
1788
  * - ABORTED: The repository operation was aborted.
1766
1789
  */
1767
- var readDecisionGraph = async (repository, paths, options, signal) => {
1790
+ var readDecisionGraph = async (repository, paths, options, signal, retainYamlRoot) => {
1768
1791
  options = createCoreOperationOptionsSnapshot(options);
1769
1792
  const diagnostics = createCoreDiagnosticCollector(options.limits, "validate-project");
1770
1793
  const candidates = [];
@@ -1773,10 +1796,11 @@ var readDecisionGraph = async (repository, paths, options, signal) => {
1773
1796
  for (const path of [...paths].sort(compareCodePoints)) {
1774
1797
  const content = await repository.readCompleteFile(path, readOptions);
1775
1798
  if (!(content instanceof Uint8Array)) return invalidSourceData(path);
1776
- const parsed = await parseDecisionDocument({
1799
+ const parsed = await inspectDecisionDocument({
1777
1800
  content: content.slice(),
1778
1801
  path
1779
1802
  }, options, "validate-project");
1803
+ if (parsed.yamlRoot !== null) retainYamlRoot?.(path, parsed.yamlRoot);
1780
1804
  for (const diagnostic of parsed.diagnostics) diagnostics.merge(diagnostic);
1781
1805
  candidates.push({
1782
1806
  decision: parsed.decision,
@@ -3135,86 +3159,102 @@ var inspectUniversalProject = async (context, options) => {
3135
3159
  const coverage = [];
3136
3160
  const collector = createCoreDiagnosticCollector(options.limits, "validate-project");
3137
3161
  const operationOptions = signal === void 0 ? void 0 : { signal };
3138
- const moldeaRoot = await session.reader.getEntry(MOLDEA_ROOT, operationOptions);
3139
- let manifestEntry = null;
3140
- let projectEntry = null;
3141
- let indexedManifest = null;
3142
- let formatVersion = null;
3143
- if (moldeaRoot?.type === "directory") {
3144
- manifestEntry = await session.reader.getEntry(MANIFEST_PATH, operationOptions);
3145
- if (manifestEntry?.type === "file") {
3146
- const content = await session.reader.readCompleteFile(MANIFEST_PATH, operationOptions);
3147
- const parsedManifest = await inspectManifestDocument({
3148
- content,
3149
- path: MANIFEST_PATH
3150
- }, options, "validate-project");
3151
- formatVersion = parsedManifest.formatVersion;
3152
- addDiagnostics(collector, parsedManifest.diagnostics);
3153
- if (parsedManifest.asset !== null && parsedManifest.manifest !== null) indexedManifest = {
3154
- asset: parsedManifest.asset,
3155
- value: parsedManifest.manifest
3156
- };
3162
+ const yamlRoots = /* @__PURE__ */ new Map();
3163
+ const memory = getRetainedMemory(session.reader);
3164
+ let retainedYamlBytes = 0;
3165
+ /** Reserves each parsed tree until final cross-file and acceptance locations are resolved. */
3166
+ const retainYamlRoot = (path, root) => {
3167
+ const bytes = measureYamlRetainedBytes(root);
3168
+ memory.reserve(bytes);
3169
+ retainedYamlBytes += bytes;
3170
+ yamlRoots.set(path, root);
3171
+ };
3172
+ try {
3173
+ const moldeaRoot = await session.reader.getEntry(MOLDEA_ROOT, operationOptions);
3174
+ let manifestEntry = null;
3175
+ let projectEntry = null;
3176
+ let indexedManifest = null;
3177
+ let formatVersion = null;
3178
+ if (moldeaRoot?.type === "directory") {
3179
+ manifestEntry = await session.reader.getEntry(MANIFEST_PATH, operationOptions);
3180
+ if (manifestEntry?.type === "file") {
3181
+ const content = await session.reader.readCompleteFile(MANIFEST_PATH, operationOptions);
3182
+ const parsedManifest = await inspectManifestDocument({
3183
+ content,
3184
+ path: MANIFEST_PATH
3185
+ }, options, "validate-project");
3186
+ if (parsedManifest.yamlRoot !== null) retainYamlRoot(MANIFEST_PATH, parsedManifest.yamlRoot);
3187
+ formatVersion = parsedManifest.formatVersion;
3188
+ addDiagnostics(collector, parsedManifest.diagnostics);
3189
+ if (parsedManifest.asset !== null && parsedManifest.manifest !== null) indexedManifest = {
3190
+ asset: parsedManifest.asset,
3191
+ value: parsedManifest.manifest
3192
+ };
3193
+ }
3194
+ projectEntry = await session.reader.getEntry(PROJECT_PATH, operationOptions);
3157
3195
  }
3158
- projectEntry = await session.reader.getEntry(PROJECT_PATH, operationOptions);
3159
- }
3160
- const projectFile = await readProjectFile(session.reader, projectEntry?.type === "file" ? PROJECT_PATH : null, options, signal);
3161
- addDiagnostics(collector, projectFile.diagnostics);
3162
- const discovery = await discoverCanonicalAssets(session.reader, options.limits, signal, {
3163
- manifest: manifestEntry,
3164
- moldeaRoot,
3165
- project: projectEntry
3166
- });
3167
- addDiagnostics(collector, discovery.diagnostics);
3168
- session.throwIfAborted();
3169
- const projectAssets = await readProjectAssets(session.reader, indexedManifest?.value ?? null, discovery, options, signal, projectFile);
3170
- addDiagnostics(collector, projectAssets.diagnostics);
3171
- const runtimeGuidance = await readRuntimeGuidance(session.reader, discovery.inventory.manifest ?? MANIFEST_PATH, indexedManifest?.value ?? null, discovery, options, signal);
3172
- addDiagnostics(collector, runtimeGuidance.diagnostics);
3173
- const decisionGraph = await readDecisionGraph(session.reader, discovery.inventory.decisions, options, signal);
3174
- addDiagnostics(collector, decisionGraph.diagnostics);
3175
- let agents = [];
3176
- let agentMirrors = [];
3177
- if (indexedManifest !== null) {
3178
- const manifestPath = indexedManifest.asset.path;
3179
- const agentAssets = await inspectAgentAssets(session.reader, indexedManifest.value, discovery, options, signal);
3180
- agents = agentAssets.agents;
3181
- addDiagnostics(collector, agentAssets.diagnostics);
3182
- addDiagnostics(collector, validateManifestRelationships(manifestPath, indexedManifest.value, discovery, decisionGraph.decisions, options.limits));
3183
- addDiagnostics(collector, await validateRepositoryReferences(session.reader, manifestPath, indexedManifest.value, discovery, options.limits, signal, coverage));
3184
- const mirrorInspection = await inspectMirrors(session.reader, manifestPath, agents, options, signal);
3185
- agentMirrors = mirrorInspection.agentMirrors;
3186
- addDiagnostics(collector, mirrorInspection.diagnostics);
3196
+ const projectFile = await readProjectFile(session.reader, projectEntry?.type === "file" ? PROJECT_PATH : null, options, signal);
3197
+ addDiagnostics(collector, projectFile.diagnostics);
3198
+ const discovery = await discoverCanonicalAssets(session.reader, options.limits, signal, {
3199
+ manifest: manifestEntry,
3200
+ moldeaRoot,
3201
+ project: projectEntry
3202
+ });
3203
+ addDiagnostics(collector, discovery.diagnostics);
3204
+ session.throwIfAborted();
3205
+ const projectAssets = await readProjectAssets(session.reader, indexedManifest?.value ?? null, discovery, options, signal, projectFile);
3206
+ addDiagnostics(collector, projectAssets.diagnostics);
3207
+ const runtimeGuidance = await readRuntimeGuidance(session.reader, discovery.inventory.manifest ?? MANIFEST_PATH, indexedManifest?.value ?? null, discovery, options, signal);
3208
+ addDiagnostics(collector, runtimeGuidance.diagnostics);
3209
+ const decisionGraph = await readDecisionGraph(session.reader, discovery.inventory.decisions, options, signal, retainYamlRoot);
3210
+ addDiagnostics(collector, decisionGraph.diagnostics);
3211
+ let agents = [];
3212
+ let agentMirrors = [];
3213
+ if (indexedManifest !== null) {
3214
+ const manifestPath = indexedManifest.asset.path;
3215
+ const agentAssets = await inspectAgentAssets(session.reader, indexedManifest.value, discovery, options, signal);
3216
+ agents = agentAssets.agents;
3217
+ addDiagnostics(collector, agentAssets.diagnostics);
3218
+ addDiagnostics(collector, validateManifestRelationships(manifestPath, indexedManifest.value, discovery, decisionGraph.decisions, options.limits));
3219
+ addDiagnostics(collector, await validateRepositoryReferences(session.reader, manifestPath, indexedManifest.value, discovery, options.limits, signal, coverage));
3220
+ const mirrorInspection = await inspectMirrors(session.reader, manifestPath, agents, options, signal);
3221
+ agentMirrors = mirrorInspection.agentMirrors;
3222
+ addDiagnostics(collector, mirrorInspection.diagnostics);
3223
+ }
3224
+ session.throwIfAborted();
3225
+ addDiagnostics(collector, await inspectCodingAgentIntegration(session.reader, session.instructions, options.limits, signal));
3226
+ const patterns = indexedManifest === null ? {
3227
+ completed: false,
3228
+ diagnostics: []
3229
+ } : await inspectImpactPatterns(session.reader, indexedManifest.value, options.limits, signal);
3230
+ session.throwIfAborted();
3231
+ addDiagnostics(collector, patterns.diagnostics);
3232
+ const diagnostics = locateDiagnosticRanges(applyWarningAcceptances(collector.finalize(), indexedManifest?.value.acceptedWarnings ?? [], /* @__PURE__ */ new Set([...[
3233
+ "MOLDEA_INTEGRATION_BLOCK_MISSING",
3234
+ "MOLDEA_INTEGRATION_SKILL_MISSING",
3235
+ "MOLDEA_INTEGRATION_BLOCK_STALE",
3236
+ "MOLDEA_INTEGRATION_LINK_UNRESOLVED",
3237
+ "MOLDEA_INTEGRATION_CLAUDE_IMPORT_MISSING"
3238
+ ], ...patterns.completed ? ["MOLDEA_IMPACT_PATTERN_UNMATCHED"] : []]), options.limits), yamlRoots);
3239
+ const project = !diagnostics.some((diagnostic) => diagnostic.severity === "error") && indexedManifest !== null && projectAssets.project !== null ? createProjectIndex({
3240
+ agentMirrors,
3241
+ agents,
3242
+ context: projectAssets.context,
3243
+ decisions: decisionGraph.decisions,
3244
+ manifest: indexedManifest,
3245
+ project: projectAssets.project,
3246
+ runtimes: runtimeGuidance.runtimes
3247
+ }) : null;
3248
+ return deepFreeze({
3249
+ diagnostics,
3250
+ coverage,
3251
+ formatVersion,
3252
+ project
3253
+ });
3254
+ } finally {
3255
+ yamlRoots.clear();
3256
+ memory.release(retainedYamlBytes);
3187
3257
  }
3188
- session.throwIfAborted();
3189
- addDiagnostics(collector, await inspectCodingAgentIntegration(session.reader, session.instructions, options.limits, signal));
3190
- const patterns = indexedManifest === null ? {
3191
- completed: false,
3192
- diagnostics: []
3193
- } : await inspectImpactPatterns(session.reader, indexedManifest.value, options.limits, signal);
3194
- session.throwIfAborted();
3195
- addDiagnostics(collector, patterns.diagnostics);
3196
- const diagnostics = applyWarningAcceptances(collector.finalize(), indexedManifest?.value.acceptedWarnings ?? [], /* @__PURE__ */ new Set([...[
3197
- "MOLDEA_INTEGRATION_BLOCK_MISSING",
3198
- "MOLDEA_INTEGRATION_SKILL_MISSING",
3199
- "MOLDEA_INTEGRATION_BLOCK_STALE",
3200
- "MOLDEA_INTEGRATION_LINK_UNRESOLVED",
3201
- "MOLDEA_INTEGRATION_CLAUDE_IMPORT_MISSING"
3202
- ], ...patterns.completed ? ["MOLDEA_IMPACT_PATTERN_UNMATCHED"] : []]), options.limits);
3203
- const project = !diagnostics.some((diagnostic) => diagnostic.severity === "error") && indexedManifest !== null && projectAssets.project !== null ? createProjectIndex({
3204
- agentMirrors,
3205
- agents,
3206
- context: projectAssets.context,
3207
- decisions: decisionGraph.decisions,
3208
- manifest: indexedManifest,
3209
- project: projectAssets.project,
3210
- runtimes: runtimeGuidance.runtimes
3211
- }) : null;
3212
- return deepFreeze({
3213
- diagnostics,
3214
- coverage,
3215
- formatVersion,
3216
- project
3217
- });
3218
3258
  };
3219
3259
  //#endregion
3220
3260
  //#region src/project-validation/index.ts
@@ -3651,4 +3691,4 @@ var createCore = (options) => {
3651
3691
  //#endregion
3652
3692
  export { createCore as n, parseIntegrationBlock as r, core_exports as t };
3653
3693
 
3654
- //# sourceMappingURL=core-DuaKbQLI.js.map
3694
+ //# sourceMappingURL=core-DOzzzqoB.js.map