@beehexa/hexasync-template-index 2608.20.18 → 2608.20.31

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 (57) hide show
  1. package/dist/checkpoints.d.ts +47 -0
  2. package/dist/checkpoints.d.ts.map +1 -0
  3. package/dist/checkpoints.js +59 -0
  4. package/dist/checkpoints.js.map +1 -0
  5. package/dist/cursorContext.d.ts +204 -0
  6. package/dist/cursorContext.d.ts.map +1 -0
  7. package/dist/cursorContext.js +479 -0
  8. package/dist/cursorContext.js.map +1 -0
  9. package/dist/detectors.d.ts +103 -0
  10. package/dist/detectors.d.ts.map +1 -0
  11. package/dist/detectors.js +104 -0
  12. package/dist/detectors.js.map +1 -0
  13. package/dist/discovery.d.ts +249 -0
  14. package/dist/discovery.d.ts.map +1 -0
  15. package/dist/discovery.js +455 -0
  16. package/dist/discovery.js.map +1 -0
  17. package/dist/effectiveGraph.d.ts +251 -0
  18. package/dist/effectiveGraph.d.ts.map +1 -0
  19. package/dist/effectiveGraph.js +559 -0
  20. package/dist/effectiveGraph.js.map +1 -0
  21. package/dist/failures.d.ts +50 -0
  22. package/dist/failures.d.ts.map +1 -0
  23. package/dist/failures.js +125 -0
  24. package/dist/failures.js.map +1 -0
  25. package/dist/graph.d.ts +47 -0
  26. package/dist/graph.d.ts.map +1 -0
  27. package/dist/graph.js +230 -0
  28. package/dist/graph.js.map +1 -0
  29. package/dist/index.d.ts +21 -0
  30. package/dist/index.d.ts.map +1 -0
  31. package/dist/index.js +38 -0
  32. package/dist/index.js.map +1 -0
  33. package/dist/queries.d.ts +102 -0
  34. package/dist/queries.d.ts.map +1 -0
  35. package/dist/queries.js +469 -0
  36. package/dist/queries.js.map +1 -0
  37. package/dist/ranges.d.ts +104 -0
  38. package/dist/ranges.d.ts.map +1 -0
  39. package/dist/ranges.js +411 -0
  40. package/dist/ranges.js.map +1 -0
  41. package/dist/resolveField.d.ts +125 -0
  42. package/dist/resolveField.d.ts.map +1 -0
  43. package/dist/resolveField.js +234 -0
  44. package/dist/resolveField.js.map +1 -0
  45. package/dist/tier1Service.d.ts +96 -0
  46. package/dist/tier1Service.d.ts.map +1 -0
  47. package/dist/tier1Service.js +194 -0
  48. package/dist/tier1Service.js.map +1 -0
  49. package/dist/tier2Service.d.ts +195 -0
  50. package/dist/tier2Service.d.ts.map +1 -0
  51. package/dist/tier2Service.js +642 -0
  52. package/dist/tier2Service.js.map +1 -0
  53. package/dist/yamlScalar.d.ts +17 -0
  54. package/dist/yamlScalar.d.ts.map +1 -0
  55. package/dist/yamlScalar.js +101 -0
  56. package/dist/yamlScalar.js.map +1 -0
  57. package/package.json +4 -4
@@ -0,0 +1,559 @@
1
+ /**
2
+ * Tier 2 — one project's EFFECTIVE graph: everything it contains, including what it inherits.
3
+ *
4
+ * Tier 1 answers "which project am I in" from 113 `main.yaml` reads. Tier 2 answers "what is in
5
+ * this project" and costs far more, so it is lazy, per project, and bounded: it resolves that
6
+ * project's worklist through the SHARED COMPOSER and parses only those files — a MEASURED median
7
+ * of 99, range 19-213, never the workspace's 7,729 (FR-41, NFR-7).
8
+ *
9
+ * Story 3.1's AC and NFR-5 USED to say "roughly 68 for an average project", and both were amended
10
+ * on 2026-08-02 to the measured median of 99 — along with NFR-5's budget, which had been calibrated
11
+ * against the wrong figure. Recorded here because the correction is the interesting part: the
12
+ * premise was wrong before the result was. Argued in NOTES-epic-3.md §1.
13
+ *
14
+ * Two graphs, never merged (FR-43). The **authored** graph is what this project's own files
15
+ * declare; the **effective** graph is what it actually contains after inheritance and precedence.
16
+ * A caller must say which it wants, because the honest answer to "does this project define X" is
17
+ * different from "does this project have X", and a single ambiguous surface would let a caller
18
+ * silently get the wrong one.
19
+ *
20
+ * Components are keyed in TOKEN FORM — before variable substitution (FR-45). Structural identity
21
+ * has to be substitution-independent: a component whose id is `**Prefix**_Orders` is the same
22
+ * component whatever the pool resolves it to, and keying on the resolved value would make it a
23
+ * different component in every project that inherits it.
24
+ */
25
+ import { parse } from 'yaml';
26
+ import { dirnameUri, joinUri } from '@beehexa/hexasync-template-model';
27
+ import { assembleVariablesWithProvenance, DIRECTIVE_KEYS, mergeToMainValue, normalizeComponentKey, prefetchSources, resolve as resolveWorklist, resumeMerge, } from '@beehexa/hexasync-template-compose';
28
+ import { checkpointPositions, nearestCheckpoint, DEFAULT_MAX_CHECKPOINTS, } from './checkpoints.js';
29
+ /**
30
+ * Collections whose entries are components.
31
+ *
32
+ * Re-exported from the composer rather than re-declared. The two lists were byte-identical, and
33
+ * two answers to "which top-level keys are directives rather than components" is one too many:
34
+ * the day a new directive is added to the merge engine, an independent copy here would start
35
+ * reporting it as authored data in every query and search.
36
+ */
37
+ export { DIRECTIVE_KEYS } from '@beehexa/hexasync-template-compose';
38
+ /**
39
+ * The pool and its per-key provenance, shaped for the graph.
40
+ *
41
+ * One call, so `variables` and `variableProvenance` are always the same computation's two halves.
42
+ */
43
+ function withProvenance(sets) {
44
+ const { pool, provenance } = assembleVariablesWithProvenance(sets);
45
+ return { variables: pool, variableProvenance: provenance };
46
+ }
47
+ /**
48
+ * Serve the host's text for any file it has newer than disk, and fall through for the rest.
49
+ *
50
+ * Exported (Story 2.2 of the extension's Phase 4) because an editor-initiated compose needs exactly
51
+ * this and a second copy would be free to disagree about the one clause that is easy to get wrong:
52
+ * `exists` must be true for a file the overlay holds, or an unsaved file reads as absent.
53
+ */
54
+ export function overlayReader(base, texts) {
55
+ return {
56
+ read: async (uri) => texts.get(uri) ?? base.read(uri),
57
+ exists: async (uri) => texts.has(uri) || base.exists(uri),
58
+ glob: (baseUri, pattern) => base.glob(baseUri, pattern),
59
+ };
60
+ }
61
+ /**
62
+ * Record each file's document version at the moment its text is read.
63
+ *
64
+ * The watermark has to describe the text the build actually folded. Querying the host again once
65
+ * the build has finished asks a different question — "what version is it NOW" — and the two differ
66
+ * for exactly the file the developer is typing in.
67
+ */
68
+ function stampVersions(base, documentVersion, into) {
69
+ const stamp = (uri) => {
70
+ const version = documentVersion(uri);
71
+ if (version !== undefined)
72
+ into.set(uri, version);
73
+ };
74
+ return {
75
+ read: async (uri) => {
76
+ // Stamped BEFORE the read resolves: the version must not be later than the text.
77
+ stamp(uri);
78
+ return base.read(uri);
79
+ },
80
+ exists: (uri) => base.exists(uri),
81
+ glob: (baseUri, pattern) => base.glob(baseUri, pattern),
82
+ };
83
+ }
84
+ /**
85
+ * The host's text, for EVERY read path resolution takes — not just `readFileIfExists`.
86
+ *
87
+ * `searchMain` is the one that mattered and was missed. `projectResolver` reads every ancestor's
88
+ * `main.yaml` through it (`projectResolver.ts:328`) and takes that file's `externals` and inline
89
+ * `variables` from the returned string, so an unsaved edit to an ancestor's `main.yaml` was resolved
90
+ * from DISK while the same file was then re-read through the overlaid reader during prefetch: one
91
+ * build reading one file two ways and getting two answers, with the watermark recording the
92
+ * editor's version. `applyChanges` deliberately routes such an edit down the rebuild path *because*
93
+ * the overlay is supposed to handle it.
94
+ *
95
+ * `globYaml` passes through: the overlay carries text for files that already exist, and a file the
96
+ * host has but disk does not is a create, which `#touches` routes to a rebuild that re-globs anyway.
97
+ */
98
+ function overlayIO(base, texts) {
99
+ return {
100
+ ...base,
101
+ readFileIfExists: async (uri) => texts.get(uri) ?? base.readFileIfExists(uri),
102
+ searchMain: async (folder) => {
103
+ const found = await base.searchMain(folder);
104
+ const overlaid = texts.get(joinUri(found.componentPath, 'main.yaml'));
105
+ return overlaid === undefined ? found : { ...found, mainYml: overlaid };
106
+ },
107
+ };
108
+ }
109
+ /**
110
+ * Pull the components out of one parsed document.
111
+ *
112
+ * A collection is an array of items carrying `id` or `key`; a map collection is keyed by its own
113
+ * keys. Both shapes exist in the corpus and both have to be walked, because a component the
114
+ * graph cannot see is a component no later feature can offer.
115
+ */
116
+ function collectComponents(parsed, provenance) {
117
+ if (!parsed || typeof parsed !== 'object')
118
+ return [];
119
+ const out = [];
120
+ for (const [collection, value] of Object.entries(parsed)) {
121
+ if (DIRECTIVE_KEYS.has(collection))
122
+ continue;
123
+ if (Array.isArray(value)) {
124
+ for (const item of value) {
125
+ if (!item || typeof item !== 'object')
126
+ continue;
127
+ const raw = 'id' in item
128
+ ? item.id
129
+ : 'key' in item
130
+ ? item.key
131
+ : undefined;
132
+ // The merge engine's own normalisation, imported rather than re-derived: it strips a
133
+ // surrounding quote pair and reads a leading `!` as a REMOVAL directive. Taking
134
+ // `String(raw)` verbatim made `- id: '!DROPME'` appear in the authored graph as a component
135
+ // named `!DROPME` that the project does not declare and no real component can ever match,
136
+ // while `effective` correctly omitted it — the two halves disagreeing about what a file says.
137
+ const key = normalizeComponentKey(raw);
138
+ if (!key)
139
+ continue; // `{id: null}` phantoms, and items with no id at all
140
+ // A removal declares nothing. `absent, not present-and-flagged` (Story 3.2 AC 4) has to
141
+ // hold for the authored graph too, which is the surface answering "what does this file say".
142
+ if (key.removes)
143
+ continue;
144
+ out.push({
145
+ collection,
146
+ id: key.id,
147
+ value: item,
148
+ provenance: { ...provenance, overrides: false, redefined: false },
149
+ });
150
+ }
151
+ continue;
152
+ }
153
+ if (value && typeof value === 'object') {
154
+ for (const [key, item] of Object.entries(value)) {
155
+ out.push({
156
+ collection,
157
+ id: key,
158
+ value: item,
159
+ provenance: { ...provenance, overrides: false, redefined: false },
160
+ });
161
+ }
162
+ }
163
+ }
164
+ return out;
165
+ }
166
+ /**
167
+ * A component's identity: collection AND id, joined by a separator no id can contain.
168
+ *
169
+ * Written as the ESCAPE `\u0000`, never as a raw byte. A literal NUL in a `.ts` file makes git
170
+ * treat the whole file as binary, which silently removes it from every textual diff, review and
171
+ * blame — 5.5 KB of source that no reviewer can see. That is exactly how it went unnoticed here.
172
+ */
173
+ const identityOf = (c) => `${c.collection}\u0000${c.id}`;
174
+ /**
175
+ * Build one project's effective graph.
176
+ *
177
+ * Goes through the composer rather than reimplementing merge, so the graph and the artefact
178
+ * `compose` produces cannot drift — NFR-1's rule that the editor invents no semantics the
179
+ * runtime lacks is only true if there is one implementation of them.
180
+ */
181
+ export async function buildEffectiveGraph(projectId, componentPath, mainYml, options) {
182
+ const { documentVersion, overlay } = options;
183
+ const io = overlay?.size ? overlayIO(options.io, overlay) : options.io;
184
+ const overlaid = overlay?.size
185
+ ? overlayReader(options.reader, overlay)
186
+ : options.reader;
187
+ // AD-7a, captured AT READ TIME rather than at the end of the build.
188
+ //
189
+ // Every read here is awaited, so a document can advance between being read and the build
190
+ // finishing. Sampling `documentVersion(path)` in `finishGraph` therefore stamped the version the
191
+ // document had AFTERWARDS onto content read BEFORE — verified certifying v4 for text read at v3,
192
+ // which is the precise false-freshness the watermark exists to make impossible.
193
+ const readVersions = new Map();
194
+ const reader = documentVersion
195
+ ? stampVersions(overlaid, documentVersion, readVersions)
196
+ : overlaid;
197
+ const { worklist, variableSets, unadmittedVariableFiles, libraryVariableSets, } = await resolveWorklist(componentPath, mainYml, io);
198
+ /** Wholesale losses seen by THIS build (Story 1.9). */
199
+ const overwrites = [];
200
+ /**
201
+ * `!md[...]` targets that could not be read by THIS build (2026-08-20).
202
+ *
203
+ * Same shape of problem as `overwrites`: a compose-time fact no rule reading the composed document
204
+ * can see, because the missing file was never inlined and the description is simply empty. The
205
+ * merge no longer throws for it, so without collecting it here the absence would be silent in the
206
+ * report even though it is visible in the artefact.
207
+ */
208
+ const missingIncludes = [];
209
+ const sources = await prefetchSources(worklist, reader, componentPath, mainYml);
210
+ // NO second parse pass. The merge already parses every worklist file, so it hands each
211
+ // parsed value over as it consumes it (`onFileParsed`) and the index reuses them.
212
+ //
213
+ // Measured on a real 99-file project: a separate pass cost 484 ms of a 1,295 ms build,
214
+ // against NFR-5's 500 ms budget — the pass WAS the budget. What remains is the composer's
215
+ // own merge, which is irreducible without reimplementing it, and NFR-1 forbids that.
216
+ const state = newFoldState();
217
+ // The root main.yaml is the merge BASE, so its inline components are written before any
218
+ // worklist file and can be overridden by one. Noted first for exactly that reason: noting it
219
+ // last made a partial's override look as though root main.yaml had won.
220
+ const rootComponents = collectComponents(safeParse(mainYml), {
221
+ project: projectId,
222
+ generation: 0,
223
+ sourceFile: `${componentPath}/main.yaml`,
224
+ });
225
+ state.authored.push(...rootComponents);
226
+ note(state, rootComponents);
227
+ const consume = fileConsumer(state, projectId, worklist);
228
+ const wanted = checkpointSchedule(worklist, options.checkpoints);
229
+ // EFFECTIVE: the composed result. Built by merging, so precedence, `!`-removal and
230
+ // later-wins are the composer's rules rather than a second implementation of them.
231
+ // The merged VALUE, taken directly — and through `mergeToMainValue`, which does not serialize.
232
+ // The stringify/reparse round trip cost 382 ms of a 977 ms build on a real 99-file project; the
233
+ // REPARSE half was removed here first, while `mergeToMain` went on serializing the whole document
234
+ // and sweeping it with a regex for a string this function immediately discarded. Both halves are
235
+ // gone now. `mergeToMain` is still the entry point that produces the artefact.
236
+ let mergedValue = {};
237
+ mergeToMainValue(mainYml, worklist, undefined, componentPath, sources, undefined, {
238
+ onFileParsed: consume,
239
+ onMissingInclude: (missing) => {
240
+ // De-duplicated on the resolved path: inheritance materialises each generation's own
241
+ // descriptions, so one authored directive in a base partial is resolved once per generation
242
+ // that inherits it — the same missing file, reported N times, would bury the finding.
243
+ if (!missingIncludes.some((m) => m.path === missing.path))
244
+ missingIncludes.push(missing);
245
+ },
246
+ onOverwrite: (record) => {
247
+ // Only depth-0 losses of real components. A nested id-less config array being replaced is
248
+ // ordinary customization, and reporting it would bury the real case.
249
+ if (record.depth === 0 && record.hadComponents)
250
+ overwrites.push(record);
251
+ },
252
+ onMerged: (value) => {
253
+ mergedValue = value;
254
+ },
255
+ onCheckpoint: (index, live) => captureCheckpoint(state, wanted, index, live, overwrites),
256
+ });
257
+ return finishGraph({
258
+ projectId,
259
+ componentPath,
260
+ mergedValue,
261
+ state,
262
+ worklist,
263
+ variableSets,
264
+ unadmittedVariableFiles,
265
+ libraryVariableSets,
266
+ overwrites,
267
+ missingIncludes,
268
+ sources,
269
+ readVersions,
270
+ });
271
+ }
272
+ /**
273
+ * Rebuild a graph after an edit, resuming from a retained prefix checkpoint (Story 3.5, FR-46).
274
+ *
275
+ * Returns `undefined` when the change cannot be applied incrementally, rather than guessing.
276
+ * The caller then does a full build — which is always correct, so every case this declines is a
277
+ * case that stays right rather than a case that breaks.
278
+ *
279
+ * `updates` carries the new text of each changed file. Nothing is read here: an incremental
280
+ * re-merge that went back to the filesystem would be reading the very files the editor already
281
+ * holds newer versions of.
282
+ */
283
+ export function resumeEffectiveGraph(graph,
284
+ /**
285
+ * The checkpoints to resume from — passed in rather than read off the graph.
286
+ *
287
+ * They are the heaviest thing the build produces and the only part a holder may want to drop
288
+ * independently of the graph itself (AD-10's last-good snapshot is worth keeping long after
289
+ * its checkpoints are worth their memory). Making the holder name them is what lets the Tier 2
290
+ * service bound them to the project being edited while every hot graph stays whole.
291
+ */
292
+ checkpoints, updates, options = {}) {
293
+ if (updates.size === 0)
294
+ return graph;
295
+ // FIRST index, not last. A path can occupy several worklist positions — a library file pulled in
296
+ // by two ancestors is a duplicate, which ordinary `type: local` declarations produce. `Map.set`
297
+ // in a plain forEach keeps the LAST index, so the resume began AFTER the file's earlier
298
+ // occurrences and folded their stale text: editing such a file gave
299
+ // `{id: SH, name: EDITED, legacy: yes}` where a full recompose gives `{id: SH, name: EDITED}`.
300
+ // Every earlier occurrence has to be replayed, so the earliest position is the one that matters.
301
+ const positionOf = new Map();
302
+ graph.worklist.forEach((item, i) => {
303
+ if (!positionOf.has(item.path))
304
+ positionOf.set(item.path, i);
305
+ });
306
+ let first = Number.POSITIVE_INFINITY;
307
+ for (const path of updates.keys()) {
308
+ const at = positionOf.get(path);
309
+ // Not a worklist file: the merge base (main.yaml), a variables file, an `!md` include, or a
310
+ // file the worklist does not yet know about. Each changes something a prefix checkpoint
311
+ // cannot represent — the base, the variable pool, or the worklist itself.
312
+ if (at === undefined)
313
+ return undefined;
314
+ if (at < first)
315
+ first = at;
316
+ }
317
+ const from = nearestCheckpoint(checkpoints, first - 1);
318
+ // Nothing retained early enough — including the case where the FIRST worklist file changed,
319
+ // which has no prefix to resume from and is simply a full build.
320
+ if (!from)
321
+ return undefined;
322
+ const sources = new Map(graph.sources);
323
+ for (const [path, text] of updates)
324
+ sources.set(path, text);
325
+ const state = {
326
+ authored: graph.authored.slice(0, from.authoredCount),
327
+ winningSource: new Map(from.winningSource),
328
+ // Checkpoints at or after the resume point describe a document that no longer exists.
329
+ checkpoints: checkpoints.filter((cp) => cp.index <= from.index),
330
+ };
331
+ const suffix = graph.worklist.slice(from.index + 1);
332
+ const consume = fileConsumer(state, graph.projectId, graph.worklist);
333
+ const wanted = new Set(checkpointPositions(graph.worklist, options.maxCheckpoints ?? DEFAULT_MAX_CHECKPOINTS).filter((p) => p > from.index));
334
+ // The prefix's losses come from the checkpoint; the suffix's are observed as it re-merges.
335
+ const overwrites = [...from.overwrites];
336
+ /**
337
+ * Seeded from the GRAPH, not the checkpoint (2026-08-20).
338
+ *
339
+ * `GraphCheckpoint` carries `overwrites` for the prefix because a wholesale loss is positional —
340
+ * it belongs to the file that caused it. A missing `!md[...]` target is not: the same absent file
341
+ * is re-reported by every generation that inherits the directive, which is why the collector
342
+ * de-duplicates on the resolved path. Seeding from `graph.missingIncludes` keeps the misses the
343
+ * unchanged prefix already found, so a resume reports the same set a full build would.
344
+ */
345
+ const missingIncludes = [...graph.missingIncludes];
346
+ const mergedValue = resumeMerge(from.merged, suffix, from.index + 1, undefined, sources, undefined, {
347
+ onFileParsed: consume,
348
+ onMissingInclude: (missing) => {
349
+ // De-duplicated on the resolved path: inheritance materialises each generation's own
350
+ // descriptions, so one authored directive in a base partial is resolved once per generation
351
+ // that inherits it — the same missing file, reported N times, would bury the finding.
352
+ if (!missingIncludes.some((m) => m.path === missing.path))
353
+ missingIncludes.push(missing);
354
+ },
355
+ onOverwrite: (record) => {
356
+ // Only depth-0 losses of real components. A nested id-less config array being replaced is
357
+ // ordinary customization, and reporting it would bury the real case.
358
+ if (record.depth === 0 && record.hadComponents)
359
+ overwrites.push(record);
360
+ },
361
+ onCheckpoint: (index, live) => captureCheckpoint(state, wanted, index, live, overwrites),
362
+ });
363
+ return finishGraph({
364
+ projectId: graph.projectId,
365
+ componentPath: graph.componentPath,
366
+ mergedValue,
367
+ state,
368
+ worklist: graph.worklist,
369
+ variableSets: graph.variableSets,
370
+ unadmittedVariableFiles: graph.unadmittedVariableFiles,
371
+ libraryVariableSets: graph.libraryVariableSets,
372
+ overwrites,
373
+ missingIncludes,
374
+ sources,
375
+ readVersions: resumeVersions(graph, updates, options.documentVersion),
376
+ resumedFrom: from.index + 1,
377
+ });
378
+ }
379
+ /**
380
+ * Watermark for a resumed graph: carried forward for untouched files, refreshed for changed ones.
381
+ *
382
+ * A resume reads nothing — it folds `graph.sources` with `updates` applied — so an untouched file's
383
+ * text is exactly what the previous build recorded and its watermark is still true. Only the files
384
+ * in `updates` have new text, and their version is the one the caller supplied that text at.
385
+ *
386
+ * Re-querying the host for EVERY path would restamp untouched files with whatever version they have
387
+ * now, asserting freshness the resumed graph's sources do not have.
388
+ */
389
+ function resumeVersions(graph, updates, documentVersion) {
390
+ const versions = new Map(graph.watermark);
391
+ for (const path of updates.keys()) {
392
+ const version = documentVersion?.(path);
393
+ if (version === undefined)
394
+ versions.delete(path);
395
+ else
396
+ versions.set(path, version);
397
+ }
398
+ return versions;
399
+ }
400
+ const newFoldState = () => ({
401
+ authored: [],
402
+ winningSource: new Map(),
403
+ checkpoints: [],
404
+ });
405
+ /**
406
+ * Record where each identity's WINNING definition came from.
407
+ *
408
+ * The merge consumes the worklist in order, so the last writer seen is the winner — exactly the
409
+ * composer's rule, observed rather than re-derived.
410
+ */
411
+ function note(state, components) {
412
+ for (const c of components) {
413
+ const key = identityOf(c);
414
+ const prior = state.winningSource.get(key);
415
+ state.winningSource.set(key, {
416
+ ...c.provenance,
417
+ seen: (prior?.seen ?? 0) + 1,
418
+ maxGeneration: Math.max(c.provenance.generation, prior?.maxGeneration ?? c.provenance.generation),
419
+ });
420
+ }
421
+ }
422
+ /**
423
+ * Consume one parsed worklist file into the fold state.
424
+ *
425
+ * Shared by the full build and the resume so an incrementally rebuilt graph cannot describe its
426
+ * components differently from a freshly built one.
427
+ */
428
+ function fileConsumer(state, projectId, worklist) {
429
+ // A path can occupy SEVERAL worklist positions — a library file pulled in by two ancestors — and
430
+ // the occurrences can differ in `project` and `generation`. A plain `Map<path, item>` keeps the
431
+ // last one, so components contributed at the earlier position were stamped with the later
432
+ // position's provenance on an ordinary full build, no resume involved. The fold visits the
433
+ // worklist in order, so each path's occurrences are consumed in order too: queue them and take
434
+ // the next one per call, holding the final occurrence for any extra calls.
435
+ const pending = new Map();
436
+ for (const item of worklist) {
437
+ const queue = pending.get(item.path);
438
+ if (queue)
439
+ queue.push(item);
440
+ else
441
+ pending.set(item.path, [item]);
442
+ }
443
+ return (path, parsed) => {
444
+ const queue = pending.get(path);
445
+ const item = queue && (queue.length > 1 ? queue.shift() : queue[0]);
446
+ const generation = item?.generation ?? 0;
447
+ const provenance = {
448
+ project: item?.project ?? projectId,
449
+ generation,
450
+ sourceFile: path,
451
+ };
452
+ if (generation === 0) {
453
+ // COPIED before collecting. The merge folds this very object into the document and later
454
+ // files then deep-merge onto it in place, so an authored component holding a reference
455
+ // would end up showing the merged result — reporting what the project HAS under the name
456
+ // of what one of its files DECLARES, which is the one distinction the authored graph
457
+ // exists to make.
458
+ const components = collectComponents(structuredClone(parsed), provenance);
459
+ state.authored.push(...components);
460
+ note(state, components);
461
+ return;
462
+ }
463
+ note(state, collectComponents(parsed, provenance));
464
+ };
465
+ }
466
+ /** Which positions this build should retain, given the caller's checkpoint request. */
467
+ function checkpointSchedule(worklist, request) {
468
+ if (!request)
469
+ return new Set();
470
+ const max = typeof request === 'object'
471
+ ? (request.max ?? DEFAULT_MAX_CHECKPOINTS)
472
+ : DEFAULT_MAX_CHECKPOINTS;
473
+ return new Set(checkpointPositions(worklist, max));
474
+ }
475
+ /** Retain one checkpoint, copying the live document because the fold goes on mutating it. */
476
+ function captureCheckpoint(state, wanted, index, live, overwrites) {
477
+ if (!wanted.has(index))
478
+ return;
479
+ state.checkpoints.push({
480
+ index,
481
+ merged: structuredClone(live),
482
+ authoredCount: state.authored.length,
483
+ winningSource: new Map(state.winningSource),
484
+ // A snapshot, not the live array: it goes on growing as the suffix merges.
485
+ overwrites: [...overwrites],
486
+ });
487
+ }
488
+ /** Turn a completed fold into the published graph. Shared so build and resume agree. */
489
+ function finishGraph(input) {
490
+ const { state } = input;
491
+ const rootMainPath = `${input.componentPath}/main.yaml`;
492
+ const effective = collectComponents(input.mergedValue, {
493
+ project: input.projectId,
494
+ generation: 0,
495
+ sourceFile: rootMainPath,
496
+ }).map((c) => {
497
+ const won = state.winningSource.get(identityOf(c));
498
+ return won
499
+ ? {
500
+ ...c,
501
+ provenance: {
502
+ project: won.project,
503
+ generation: won.generation,
504
+ sourceFile: won.sourceFile,
505
+ // Beat a definition from FURTHER UP the inheritance chain — which is what "overrides an
506
+ // inherited one" means. A component redefined twice within one project is `redefined`
507
+ // but overrides nothing inherited.
508
+ overrides: won.generation < won.maxGeneration,
509
+ redefined: won.seen > 1,
510
+ },
511
+ }
512
+ : c;
513
+ });
514
+ // AD-7a: what each source WAS when it was read. Scoped to the files this graph is actually built
515
+ // from, so a stamp left over from a file no longer in the worklist cannot claim freshness for it.
516
+ const watermark = new Map();
517
+ for (const path of input.sources.keys()) {
518
+ const version = input.readVersions?.get(path);
519
+ if (version !== undefined)
520
+ watermark.set(path, version);
521
+ }
522
+ return {
523
+ projectId: input.projectId,
524
+ componentPath: input.componentPath,
525
+ mergedValue: input.mergedValue,
526
+ authored: state.authored,
527
+ effective,
528
+ ...withProvenance([...input.variableSets]),
529
+ unadmittedVariableFiles: input.unadmittedVariableFiles,
530
+ libraryVariableSets: input.libraryVariableSets,
531
+ overwrites: input.overwrites,
532
+ missingIncludes: input.missingIncludes,
533
+ variableSets: input.variableSets,
534
+ worklist: input.worklist,
535
+ sources: input.sources,
536
+ watermark,
537
+ checkpoints: state.checkpoints,
538
+ ...(input.resumedFrom === undefined
539
+ ? {}
540
+ : { resumedFrom: input.resumedFrom }),
541
+ };
542
+ }
543
+ /**
544
+ * Parse without letting one broken file destroy the graph (AD-10, Story 3.6).
545
+ *
546
+ * A developer produces dozens of transient invalid states an hour. Throwing here would mean the
547
+ * graph disappears mid-keystroke, which is precisely when it is most wanted.
548
+ */
549
+ function safeParse(text) {
550
+ try {
551
+ return parse(text, { keepSourceTokens: true }) ?? {};
552
+ }
553
+ catch {
554
+ return {};
555
+ }
556
+ }
557
+ /** The directory a project's files live under — used to scope watchers. */
558
+ export const projectFolderOf = (componentPath) => dirnameUri(componentPath);
559
+ //# sourceMappingURL=effectiveGraph.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"effectiveGraph.js","sourceRoot":"","sources":["../src/effectiveGraph.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAEvE,OAAO,EACL,+BAA+B,EAC/B,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACrB,eAAe,EACf,OAAO,IAAI,eAAe,EAC1B,WAAW,GASZ,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,uBAAuB,GACxB,MAAM,kBAAkB,CAAC;AAE1B;;;;;;;GAOG;AACH,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAuCpE;;;;GAIG;AACH,SAAS,cAAc,CAAC,IAA0B;IAIhD,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,+BAA+B,CAAC,IAAI,CAAC,CAAC;IACnE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,kBAAkB,EAAE,UAAU,EAAE,CAAC;AAC7D,CAAC;AAiKD;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAC3B,IAAoB,EACpB,KAAkC;IAElC,OAAO;QACL,IAAI,EAAE,KAAK,EAAE,GAAG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C,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,SAAS;QACT,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,GAAG,CAAC,KAAK,CAAC,WAAW,KAAK,SAAS;YACjC,CAAC,CAAC,EAAE;YACJ,CAAC,CAAC,EAAE,WAAW,EAAE,KAAK,CAAC,WAAW,EAAE,CAAC;KACxC,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAS,SAAS,CAAC,IAAY;IAC7B,IAAI,CAAC;QACH,OAAO,KAAK,CAAC,IAAI,EAAE,EAAE,gBAAgB,EAAE,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC;IACvD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAED,2EAA2E;AAC3E,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,aAAqB,EAAU,EAAE,CAC/D,UAAU,CAAC,aAAa,CAAC,CAAC"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Turning a thrown error into something a diagnostic publisher can use (Story 3.6, AD-9).
3
+ *
4
+ * A developer produces dozens of transient invalid states in an hour of typing, and every one of
5
+ * them reaches the index as an exception. What a publisher needs from each is not a string: it
6
+ * needs a CODE to branch on, the FILE and RANGE to underline, and the original error kept intact
7
+ * so nothing is lost on the way. A message alone forces the consumer to parse English back into
8
+ * structure, which is how "Error at file /a/b.yaml: ..." becomes a squiggle in the wrong place.
9
+ *
10
+ * Phase 2 Story 2.1 publishes these. Nothing here publishes anything — this only makes the
11
+ * failure describable.
12
+ */
13
+ /** Zero-based, matching the editor conventions a publisher will map onto. */
14
+ export interface SourcePosition {
15
+ readonly line: number;
16
+ readonly column: number;
17
+ }
18
+ export interface SourceRange {
19
+ readonly start: SourcePosition;
20
+ readonly end: SourcePosition;
21
+ }
22
+ export type FailureCode =
23
+ /** The YAML in a worklist file could not be parsed. */
24
+ 'parse-failed'
25
+ /** The worklist could not be resolved — a missing `type: project` target, a cycle. */
26
+ | 'resolve-failed'
27
+ /** Anything else that stopped the compose. */
28
+ | 'compose-failed';
29
+ export interface IndexFailure {
30
+ readonly code: FailureCode;
31
+ readonly message: string;
32
+ /** The file the failure is about, when the error names one. */
33
+ readonly sourceFile?: string;
34
+ /** Where in that file, when the error carries a position. */
35
+ readonly range?: SourceRange;
36
+ /**
37
+ * The original error, unflattened.
38
+ *
39
+ * Kept because the cause chain is where the actual YAML error lives — the composer wraps it to
40
+ * add the filename, and a consumer that only got the wrapper would have the name of the file
41
+ * and nothing about what is wrong inside it.
42
+ */
43
+ readonly cause?: unknown;
44
+ }
45
+ /**
46
+ * Describe a thrown error as a structured failure. Never throws and never returns undefined:
47
+ * a failure that cannot be described is still a failure, and swallowing it is what AC 3 forbids.
48
+ */
49
+ export declare function describeFailure(error: unknown, fallbackFile?: string): IndexFailure;
50
+ //# sourceMappingURL=failures.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"failures.d.ts","sourceRoot":"","sources":["../src/failures.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,6EAA6E;AAC7E,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;IAC/B,QAAQ,CAAC,GAAG,EAAE,cAAc,CAAC;CAC9B;AAED,MAAM,MAAM,WAAW;AACrB,uDAAuD;AACrD,cAAc;AAChB,sFAAsF;GACpF,gBAAgB;AAClB,8CAA8C;GAC5C,gBAAgB,CAAC;AAErB,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,+DAA+D;IAC/D,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,6DAA6D;IAC7D,QAAQ,CAAC,KAAK,CAAC,EAAE,WAAW,CAAC;IAC7B;;;;;;OAMG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;CAC1B;AA2DD;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,OAAO,EACd,YAAY,CAAC,EAAE,MAAM,GACpB,YAAY,CA2Dd"}