@beehexa/hexasync-template-index 2608.20.18 → 2608.20.32
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/dist/checkpoints.d.ts +47 -0
- package/dist/checkpoints.d.ts.map +1 -0
- package/dist/checkpoints.js +59 -0
- package/dist/checkpoints.js.map +1 -0
- package/dist/cursorContext.d.ts +204 -0
- package/dist/cursorContext.d.ts.map +1 -0
- package/dist/cursorContext.js +479 -0
- package/dist/cursorContext.js.map +1 -0
- package/dist/detectors.d.ts +103 -0
- package/dist/detectors.d.ts.map +1 -0
- package/dist/detectors.js +104 -0
- package/dist/detectors.js.map +1 -0
- package/dist/discovery.d.ts +249 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +455 -0
- package/dist/discovery.js.map +1 -0
- package/dist/effectiveGraph.d.ts +251 -0
- package/dist/effectiveGraph.d.ts.map +1 -0
- package/dist/effectiveGraph.js +559 -0
- package/dist/effectiveGraph.js.map +1 -0
- package/dist/failures.d.ts +50 -0
- package/dist/failures.d.ts.map +1 -0
- package/dist/failures.js +125 -0
- package/dist/failures.js.map +1 -0
- package/dist/graph.d.ts +47 -0
- package/dist/graph.d.ts.map +1 -0
- package/dist/graph.js +230 -0
- package/dist/graph.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -0
- package/dist/queries.d.ts +102 -0
- package/dist/queries.d.ts.map +1 -0
- package/dist/queries.js +469 -0
- package/dist/queries.js.map +1 -0
- package/dist/ranges.d.ts +104 -0
- package/dist/ranges.d.ts.map +1 -0
- package/dist/ranges.js +411 -0
- package/dist/ranges.js.map +1 -0
- package/dist/resolveField.d.ts +125 -0
- package/dist/resolveField.d.ts.map +1 -0
- package/dist/resolveField.js +234 -0
- package/dist/resolveField.js.map +1 -0
- package/dist/tier1Service.d.ts +96 -0
- package/dist/tier1Service.d.ts.map +1 -0
- package/dist/tier1Service.js +194 -0
- package/dist/tier1Service.js.map +1 -0
- package/dist/tier2Service.d.ts +195 -0
- package/dist/tier2Service.d.ts.map +1 -0
- package/dist/tier2Service.js +642 -0
- package/dist/tier2Service.js.map +1 -0
- package/dist/yamlScalar.d.ts +17 -0
- package/dist/yamlScalar.d.ts.map +1 -0
- package/dist/yamlScalar.js +101 -0
- package/dist/yamlScalar.js.map +1 -0
- package/package.json +4 -4
package/dist/queries.js
ADDED
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
import { REFERENCE_PROPERTIES, resolveReferenceKind, nestedReferenceBlockFor, COLLECTIONS_KEYED_BY_REFERENCE, KEY_REFERENCE_PROPERTY, } from '@beehexa/hexasync-template-model';
|
|
2
|
+
import { findComponentRanges, componentRangeKey } from './ranges.js';
|
|
3
|
+
/** What a cancelled query resolves to. Never thrown — cancellation is an ordinary outcome. */
|
|
4
|
+
export const QUERY_CANCELLED = Symbol('query-cancelled');
|
|
5
|
+
/**
|
|
6
|
+
* Every query below is ASYNC, including the ones a synchronous call would serve perfectly well.
|
|
7
|
+
*
|
|
8
|
+
* That is AD-11, and it is deliberate rather than ceremonial: "every call crossing the boundary
|
|
9
|
+
* is asynchronous, including in-host where a synchronous call would work", so that promoting the
|
|
10
|
+
* index into an LSP process later is a transport swap instead of a rewrite of every call site.
|
|
11
|
+
* The traversals themselves stay synchronous — the engine inside the hexagon is sync, the
|
|
12
|
+
* boundary is not.
|
|
13
|
+
*/
|
|
14
|
+
const settle = async (compute, options) => {
|
|
15
|
+
// A THUNK, and a yield before it runs.
|
|
16
|
+
//
|
|
17
|
+
// This took its argument by value, so `settle(traverse(...), options)` evaluated the whole
|
|
18
|
+
// traversal before the signal was ever read: the check filtered the RESULT rather than cancelling
|
|
19
|
+
// the work, and a caller that cancelled immediately after the call still got a full answer, since
|
|
20
|
+
// there was no await point between the two. The only realistic cancellation shape is exactly that
|
|
21
|
+
// one — a caller already holding `cancelled: true` would not have called — so the one case the
|
|
22
|
+
// tests covered (a pre-cancelled signal) was the one that cannot occur.
|
|
23
|
+
//
|
|
24
|
+
// Yielding first lets a synchronous `signal.cancelled = true` after the call land before the work
|
|
25
|
+
// starts, and then the work is skipped outright rather than computed and discarded. The traversals
|
|
26
|
+
// stay synchronous once begun, which is what AD-11's note about the engine inside the hexagon
|
|
27
|
+
// says; abandoning mid-walk would need yield points the merge does not have. Recorded in
|
|
28
|
+
// NOTES-epic-3.md §6 as a known bound rather than implied by a check that could not fire.
|
|
29
|
+
if (options?.signal?.cancelled)
|
|
30
|
+
return QUERY_CANCELLED;
|
|
31
|
+
await Promise.resolve();
|
|
32
|
+
if (options?.signal?.cancelled)
|
|
33
|
+
return QUERY_CANCELLED;
|
|
34
|
+
return compute();
|
|
35
|
+
};
|
|
36
|
+
const identityKey = (collection, id) => `${collection}\u0000${id}`;
|
|
37
|
+
/**
|
|
38
|
+
* A reference value as an id, or `undefined` when it is not one.
|
|
39
|
+
*
|
|
40
|
+
* YAML gives `tableId: 42` a number and `enabled: true` a boolean, and the graph keys components by
|
|
41
|
+
* `String(id)` — so a numeric reference has a real target that a string-only check could never find.
|
|
42
|
+
* Objects and arrays are not ids; `null` and `''` are not either.
|
|
43
|
+
*/
|
|
44
|
+
function scalarId(value) {
|
|
45
|
+
if (typeof value === 'string')
|
|
46
|
+
return value === '' ? undefined : value;
|
|
47
|
+
if (typeof value === 'number' && Number.isFinite(value))
|
|
48
|
+
return String(value);
|
|
49
|
+
if (typeof value === 'boolean')
|
|
50
|
+
return String(value);
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* One index per graph, built once.
|
|
55
|
+
*
|
|
56
|
+
* A snapshot is immutable and deep-frozen, so an index over it can never go stale — which makes it
|
|
57
|
+
* the ideal thing to cache and made rebuilding it per call pure waste. It was rebuilt on EVERY
|
|
58
|
+
* relation query, and `relatedTaskOf` rebuilt it again for every `objects` component in a nested
|
|
59
|
+
* loop. A `WeakMap` keyed on the graph means an evicted snapshot takes its index with it.
|
|
60
|
+
*/
|
|
61
|
+
const indexCache = new WeakMap();
|
|
62
|
+
function indexOf(graph) {
|
|
63
|
+
const cached = indexCache.get(graph);
|
|
64
|
+
if (cached)
|
|
65
|
+
return cached;
|
|
66
|
+
const exact = new Map();
|
|
67
|
+
const byId = new Map();
|
|
68
|
+
for (const c of graph.effective) {
|
|
69
|
+
exact.set(identityKey(c.collection, c.id), c);
|
|
70
|
+
const bucket = byId.get(c.id);
|
|
71
|
+
if (bucket)
|
|
72
|
+
bucket.push(c);
|
|
73
|
+
else
|
|
74
|
+
byId.set(c.id, [c]);
|
|
75
|
+
}
|
|
76
|
+
const index = { exact, byId };
|
|
77
|
+
indexCache.set(graph, index);
|
|
78
|
+
return index;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The synchronous lookup the async surface is built on. Internal — see the AD-11 note above.
|
|
82
|
+
*
|
|
83
|
+
* Goes through the same index every relation resolution uses. It used to be a `.find`, which keeps
|
|
84
|
+
* the FIRST match where `index.exact` (a `Map.set` loop) keeps the LAST — so with a duplicate
|
|
85
|
+
* identity in one collection, `getComponent` described one component while `relation.to` resolved to
|
|
86
|
+
* the other. One index, one answer.
|
|
87
|
+
*/
|
|
88
|
+
function componentOf(graph, collection, id) {
|
|
89
|
+
return indexOf(graph).exact.get(identityKey(collection, id));
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* One component, with everything a caller needs to show OR NAVIGATE TO it.
|
|
93
|
+
*
|
|
94
|
+
* The range is resolved here rather than carried on every component: it is wanted for the few a
|
|
95
|
+
* developer looks at, and building it for all 273 would mean re-parsing every worklist file at
|
|
96
|
+
* build time — the cost this epic spent itself removing.
|
|
97
|
+
*/
|
|
98
|
+
export async function getComponent(graph, collection, id, options) {
|
|
99
|
+
// Everything INSIDE the thunk, including the range lookup. This is the only query that parses,
|
|
100
|
+
// so doing that work before `settle` made the most expensive query the one cancellation could not
|
|
101
|
+
// help — and the parse happened on every call regardless of the answer.
|
|
102
|
+
return settle(() => {
|
|
103
|
+
const component = componentOf(graph, collection, id);
|
|
104
|
+
if (!component)
|
|
105
|
+
return undefined;
|
|
106
|
+
return {
|
|
107
|
+
component,
|
|
108
|
+
projectId: component.provenance.project,
|
|
109
|
+
sourceFile: component.provenance.sourceFile,
|
|
110
|
+
...(rangeFor(graph, component)
|
|
111
|
+
? { range: rangeFor(graph, component) }
|
|
112
|
+
: {}),
|
|
113
|
+
};
|
|
114
|
+
}, options);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* A component's source range, cached per graph.
|
|
118
|
+
*
|
|
119
|
+
* `findComponentRange` parses the whole file and then scans from offset 0 twice. Uncached, that ran
|
|
120
|
+
* on every `getComponent` — a full YAML parse per lookup, on the extension host thread, for a
|
|
121
|
+
* snapshot that cannot change. The graph is immutable and deep-frozen, so the answer is stable for
|
|
122
|
+
* as long as the graph is reachable; a `WeakMap` releases it with the snapshot.
|
|
123
|
+
*/
|
|
124
|
+
const rangeCache = new WeakMap();
|
|
125
|
+
/**
|
|
126
|
+
* A component's source range, cached per FILE rather than per component.
|
|
127
|
+
*
|
|
128
|
+
* It was per component, and that made the cache quadratic for any caller wanting several from one file:
|
|
129
|
+
* each miss ran `findComponentRange`, which parses the entire document to answer for one component. An
|
|
130
|
+
* outline of a 40-component file therefore paid 40 full parses of that file.
|
|
131
|
+
*
|
|
132
|
+
* Measured before changing it, and the numbers are why this is not a micro-optimisation: Story 3.2's
|
|
133
|
+
* document outline came in at **p95 313 ms, worst project 1,161 ms** against a 200 ms budget, and its
|
|
134
|
+
* workspace query at 561 ms. One parse per file, `findComponentRanges`, brings the whole file's ranges
|
|
135
|
+
* back at once and every later component in it is a map lookup.
|
|
136
|
+
*
|
|
137
|
+
* The graph is immutable and deep-frozen, so the answer is stable for as long as the graph is reachable;
|
|
138
|
+
* a `WeakMap` releases it with the snapshot. A file absent from `graph.sources` caches an empty map, so
|
|
139
|
+
* it is not re-attempted per component either.
|
|
140
|
+
*/
|
|
141
|
+
function rangeFor(graph, component) {
|
|
142
|
+
let perGraph = rangeCache.get(graph);
|
|
143
|
+
if (!perGraph) {
|
|
144
|
+
perGraph = new Map();
|
|
145
|
+
rangeCache.set(graph, perGraph);
|
|
146
|
+
}
|
|
147
|
+
const file = component.provenance.sourceFile;
|
|
148
|
+
let perFile = perGraph.get(file);
|
|
149
|
+
if (!perFile) {
|
|
150
|
+
const text = graph.sources.get(file);
|
|
151
|
+
perFile = text ? findComponentRanges(text) : new Map();
|
|
152
|
+
perGraph.set(file, perFile);
|
|
153
|
+
}
|
|
154
|
+
return perFile.get(componentRangeKey(component.collection, component.id));
|
|
155
|
+
}
|
|
156
|
+
/** Every component of a collection — `objects`, `pullers`, `tables`, … */
|
|
157
|
+
export async function getComponentsByType(graph, collection, options) {
|
|
158
|
+
return settle(() => componentsByType(graph, collection), options);
|
|
159
|
+
}
|
|
160
|
+
function componentsByType(graph, collection) {
|
|
161
|
+
return graph.effective.filter((c) => c.collection === collection);
|
|
162
|
+
}
|
|
163
|
+
/** Walk a component's value for properties that name other components. */
|
|
164
|
+
function relationsOf(component, index) {
|
|
165
|
+
const found = [];
|
|
166
|
+
const seen = new Set();
|
|
167
|
+
// The component's own KEY, when its collection is keyed by a reference. An `objectAssociations`
|
|
168
|
+
// entry is keyed by the objectId it describes, so the key is a real edge — not a coincidence.
|
|
169
|
+
const keyTarget = COLLECTIONS_KEYED_BY_REFERENCE.get(component.collection);
|
|
170
|
+
if (keyTarget) {
|
|
171
|
+
const to = index.exact.get(identityKey(keyTarget, component.id));
|
|
172
|
+
found.push({
|
|
173
|
+
from: component,
|
|
174
|
+
property: KEY_REFERENCE_PROPERTY,
|
|
175
|
+
targetId: component.id,
|
|
176
|
+
...(to ? { to } : {}),
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
// Iterative, not recursive: a component's value is authored data and may nest arbitrarily,
|
|
180
|
+
// and a stack cannot overflow on someone's deeply indented YAML.
|
|
181
|
+
const stack = [component.value];
|
|
182
|
+
while (stack.length) {
|
|
183
|
+
const node = stack.pop();
|
|
184
|
+
if (!node || typeof node !== 'object')
|
|
185
|
+
continue;
|
|
186
|
+
if (seen.has(node))
|
|
187
|
+
continue; // authored YAML can carry aliases, which are shared objects
|
|
188
|
+
seen.add(node);
|
|
189
|
+
if (Array.isArray(node)) {
|
|
190
|
+
stack.push(...node);
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
for (const [property, value] of Object.entries(node)) {
|
|
194
|
+
// A nested block — `table: { id: X }` — is the corpus's dominant reference form, and it
|
|
195
|
+
// carries more than the id, so the reference is the block's `id` specifically.
|
|
196
|
+
const nested = nestedReferenceBlockFor(property);
|
|
197
|
+
if (nested &&
|
|
198
|
+
value &&
|
|
199
|
+
typeof value === 'object' &&
|
|
200
|
+
!Array.isArray(value)) {
|
|
201
|
+
// Coerced, not type-checked. `collectComponents` stringifies ids, so a component authored
|
|
202
|
+
// as `id: 42` is in the graph keyed `'42'` — while demanding a string here dropped the edge
|
|
203
|
+
// entirely: the index stringified one side and required a string on the other.
|
|
204
|
+
const targetId = scalarId(value.id);
|
|
205
|
+
if (targetId !== undefined) {
|
|
206
|
+
const to = nested.collection
|
|
207
|
+
? index.exact.get(identityKey(nested.collection, targetId))
|
|
208
|
+
: undefined;
|
|
209
|
+
found.push({
|
|
210
|
+
from: component,
|
|
211
|
+
property: `${property}.id`,
|
|
212
|
+
targetId,
|
|
213
|
+
...(nested.collection
|
|
214
|
+
? { targetCollection: nested.collection }
|
|
215
|
+
: {}),
|
|
216
|
+
...(to ? { to } : {}),
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
if (REFERENCE_PROPERTIES.includes(property)) {
|
|
221
|
+
// A reference property may hold one id or several.
|
|
222
|
+
for (const raw of Array.isArray(value) ? value : [value]) {
|
|
223
|
+
const targetId = scalarId(raw);
|
|
224
|
+
if (targetId === undefined)
|
|
225
|
+
continue;
|
|
226
|
+
// What the property points into can depend on a SIBLING — `entityId` beside
|
|
227
|
+
// `entityType` — and some values are not references at all. `node` is that containing
|
|
228
|
+
// map, so the discriminator is read where the reference actually sits.
|
|
229
|
+
//
|
|
230
|
+
// POSITION matters too (FR-47): `component.collection` is the collection this whole walk is
|
|
231
|
+
// inside, so `connectorId` on a `connectors[]` entry reads as that connection's own platform
|
|
232
|
+
// identity rather than as a reference to a connection. This walker MUST agree with the one in
|
|
233
|
+
// `hexasync-template-validate`'s REF-K rule — if only one of them knew, the Problems panel and
|
|
234
|
+
// Find References would disagree about the same line.
|
|
235
|
+
const kind = resolveReferenceKind(property, targetId, node, component.collection);
|
|
236
|
+
if (!kind)
|
|
237
|
+
continue;
|
|
238
|
+
found.push({
|
|
239
|
+
from: component,
|
|
240
|
+
property,
|
|
241
|
+
targetId,
|
|
242
|
+
...(kind.collection ? { targetCollection: kind.collection } : {}),
|
|
243
|
+
...resolveTarget(index, kind.collection, targetId),
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
if (value && typeof value === 'object')
|
|
248
|
+
stack.push(value);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return found;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Whether a relation points into `collection`.
|
|
255
|
+
*
|
|
256
|
+
* Prefers the resolved target, falls back to the declared aim, and admits a relation that knows
|
|
257
|
+
* neither — a property the registry has no collection for still names SOMETHING, and dropping it
|
|
258
|
+
* would lose real edges. The one thing it must not do is treat "unknown" as "matches everything",
|
|
259
|
+
* which is what the resolved-target-only form did.
|
|
260
|
+
*/
|
|
261
|
+
function aimsAt(relation, collection) {
|
|
262
|
+
const aim = relation.to?.collection ?? relation.targetCollection;
|
|
263
|
+
return aim === undefined || aim === collection;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Resolve a referenced id into the collection the caller has already decided on.
|
|
267
|
+
*
|
|
268
|
+
* `taskId` names a Task and `pusherId` names a pusher, so those resolve exactly. `entityId` and
|
|
269
|
+
* `targetId` are decided by a sibling before they get here (`resolveReferenceKind`), so this
|
|
270
|
+
* function no longer re-derives the collection from the property name — doing so is what let a
|
|
271
|
+
* collection-less property match a component in any collection and report it resolved.
|
|
272
|
+
*
|
|
273
|
+
* A collection is only absent now when the registry genuinely knows of none, in which case the id
|
|
274
|
+
* resolves by itself and says so when more than one collection claims it, rather than picking one.
|
|
275
|
+
*/
|
|
276
|
+
function resolveTarget(index, collection, targetId) {
|
|
277
|
+
if (collection) {
|
|
278
|
+
const exact = index.exact.get(identityKey(collection, targetId));
|
|
279
|
+
return exact ? { to: exact } : {};
|
|
280
|
+
}
|
|
281
|
+
const candidates = index.byId.get(targetId) ?? [];
|
|
282
|
+
if (candidates.length === 1)
|
|
283
|
+
return { to: candidates[0] };
|
|
284
|
+
if (candidates.length > 1)
|
|
285
|
+
return { ambiguous: true };
|
|
286
|
+
return {};
|
|
287
|
+
}
|
|
288
|
+
/** References this component makes. */
|
|
289
|
+
export async function getOutgoingRelations(graph, collection, id, options) {
|
|
290
|
+
return settle(() => outgoingOf(graph, collection, id), options);
|
|
291
|
+
}
|
|
292
|
+
function outgoingOf(graph, collection, id) {
|
|
293
|
+
const component = componentOf(graph, collection, id);
|
|
294
|
+
return component ? relationsOf(component, indexOf(graph)) : [];
|
|
295
|
+
}
|
|
296
|
+
/** References made TO this component — the blast radius of changing it. */
|
|
297
|
+
export async function getIncomingRelations(graph, collection, id, options) {
|
|
298
|
+
return settle(() => incomingOf(graph, collection, id), options);
|
|
299
|
+
}
|
|
300
|
+
function incomingOf(graph, collection, id) {
|
|
301
|
+
const index = indexOf(graph);
|
|
302
|
+
const found = [];
|
|
303
|
+
for (const component of graph.effective) {
|
|
304
|
+
for (const relation of relationsOf(component, index)) {
|
|
305
|
+
// Matched on identity, not on the id: an incoming reference to the Task named X is not an
|
|
306
|
+
// incoming reference to the association that happens to share its name.
|
|
307
|
+
if (relation.targetId !== id)
|
|
308
|
+
continue;
|
|
309
|
+
// Filter on where the reference AIMS, which is known even when it did not resolve. The
|
|
310
|
+
// earlier `relation.to && …` form was inert for an unresolved id, so every collection
|
|
311
|
+
// matched and a broken `objectIds` reference surfaced as an incoming reference to a puller.
|
|
312
|
+
if (!aimsAt(relation, collection))
|
|
313
|
+
continue;
|
|
314
|
+
found.push(relation);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
return found;
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* The Task a component belongs to.
|
|
321
|
+
*
|
|
322
|
+
* Every Task-centric surface in later phases depends on this. A Task is an `objects` entry, and
|
|
323
|
+
* a non-Task component belongs to one either by naming it (`objectId`) or by being named by it.
|
|
324
|
+
*/
|
|
325
|
+
export async function getRelatedTask(graph, collection, id, options) {
|
|
326
|
+
return settle(() => relatedTaskOf(graph, collection, id), options);
|
|
327
|
+
}
|
|
328
|
+
function relatedTaskOf(graph, collection, id) {
|
|
329
|
+
const component = componentOf(graph, collection, id);
|
|
330
|
+
if (!component)
|
|
331
|
+
return undefined;
|
|
332
|
+
if (component.collection === 'objects')
|
|
333
|
+
return component;
|
|
334
|
+
const index = indexOf(graph);
|
|
335
|
+
// Keyed by the objectId it describes — the association's own key names its Task.
|
|
336
|
+
const keyTarget = COLLECTIONS_KEYED_BY_REFERENCE.get(component.collection);
|
|
337
|
+
if (keyTarget === 'objects') {
|
|
338
|
+
const task = index.exact.get(identityKey('objects', component.id));
|
|
339
|
+
if (task)
|
|
340
|
+
return task;
|
|
341
|
+
}
|
|
342
|
+
// Named by the component: `pullerId` on a Task, or `objectId` on the component.
|
|
343
|
+
const named = relationsOf(component, index)
|
|
344
|
+
.map((relation) => relation.to)
|
|
345
|
+
.filter((target) => target?.collection === 'objects');
|
|
346
|
+
if (named.length > 0)
|
|
347
|
+
return onlyOne(named);
|
|
348
|
+
// Or the Task names it.
|
|
349
|
+
const naming = [];
|
|
350
|
+
for (const task of componentsByType(graph, 'objects')) {
|
|
351
|
+
for (const relation of relationsOf(task, index)) {
|
|
352
|
+
if (relation.targetId !== id)
|
|
353
|
+
continue;
|
|
354
|
+
// The Task must name THIS component, not one in another collection sharing its id.
|
|
355
|
+
if (!aimsAt(relation, collection))
|
|
356
|
+
continue;
|
|
357
|
+
naming.push(task);
|
|
358
|
+
break;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
return onlyOne(naming);
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* The single candidate, or nothing when several claim it.
|
|
365
|
+
*
|
|
366
|
+
* Both loops above used to `return` on the first hit, over `Object.entries` and a LIFO `stack.pop()`
|
|
367
|
+
* — an order that is neither source order nor stable. Two Tasks each naming the same puller
|
|
368
|
+
* therefore got one of them picked arbitrarily and reported with full confidence, while
|
|
369
|
+
* `ComponentRelation.ambiguous` exists in this very file precisely because the codebase refuses to
|
|
370
|
+
* guess elsewhere. Declining is the honest answer, and every Task-centric surface downstream
|
|
371
|
+
* inherits it rather than inheriting a coin flip.
|
|
372
|
+
*/
|
|
373
|
+
function onlyOne(candidates) {
|
|
374
|
+
const distinct = new Map();
|
|
375
|
+
for (const candidate of candidates) {
|
|
376
|
+
if (candidate) {
|
|
377
|
+
distinct.set(identityKey(candidate.collection, candidate.id), candidate);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
return distinct.size === 1 ? [...distinct.values()][0] : undefined;
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* The component plus everything reachable from it, to a depth.
|
|
384
|
+
*
|
|
385
|
+
* Bounded on purpose: an unbounded walk over a 273-component graph returns most of it, which is
|
|
386
|
+
* not a subgraph in any useful sense.
|
|
387
|
+
*/
|
|
388
|
+
export async function getSubgraph(graph, collection, id, depth = 1, options) {
|
|
389
|
+
return settle(() => subgraphOf(graph, collection, id, depth), options);
|
|
390
|
+
}
|
|
391
|
+
function subgraphOf(graph, collection, id, depth) {
|
|
392
|
+
const index = indexOf(graph);
|
|
393
|
+
const start = componentOf(graph, collection, id);
|
|
394
|
+
if (!start)
|
|
395
|
+
return [];
|
|
396
|
+
// Keyed by identity, so a Task and the association sharing its name are two members rather
|
|
397
|
+
// than one that shadows the other.
|
|
398
|
+
const collected = new Map([
|
|
399
|
+
[identityKey(start.collection, start.id), start],
|
|
400
|
+
]);
|
|
401
|
+
let frontier = [start];
|
|
402
|
+
for (let level = 0; level < depth; level++) {
|
|
403
|
+
const next = [];
|
|
404
|
+
for (const component of frontier) {
|
|
405
|
+
for (const relation of relationsOf(component, index)) {
|
|
406
|
+
// An AMBIGUOUS edge has no single `to`, and skipping it dropped both candidates from the
|
|
407
|
+
// blast radius entirely — verified returning only the seed component. The docstring on
|
|
408
|
+
// `ComponentRelation.ambiguous` records 33-61 such ids per real project, so this was the
|
|
409
|
+
// common case rather than a corner. A blast radius that silently omits a candidate is worse
|
|
410
|
+
// than one that includes an extra: the point of it is deciding whether a change is safe.
|
|
411
|
+
const targets = relation.to
|
|
412
|
+
? [relation.to]
|
|
413
|
+
: relation.ambiguous
|
|
414
|
+
? (index.byId.get(relation.targetId) ?? [])
|
|
415
|
+
: [];
|
|
416
|
+
for (const target of targets) {
|
|
417
|
+
const key = identityKey(target.collection, target.id);
|
|
418
|
+
if (collected.has(key))
|
|
419
|
+
continue;
|
|
420
|
+
collected.set(key, target);
|
|
421
|
+
next.push(target);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
if (next.length === 0)
|
|
426
|
+
break;
|
|
427
|
+
frontier = next;
|
|
428
|
+
}
|
|
429
|
+
return [...collected.values()];
|
|
430
|
+
}
|
|
431
|
+
/** Every reference to a component, resolved or not — including ones pointing at nothing. */
|
|
432
|
+
export async function findReferences(graph, collection, id, options) {
|
|
433
|
+
return settle(() => incomingOf(graph, collection, id), options);
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Search components by id, collection, file path, name, description, system and displayType.
|
|
437
|
+
*
|
|
438
|
+
* Case-insensitive substring, deliberately: a developer half-remembering a name should find it,
|
|
439
|
+
* and a stricter match would send them back to grep — which is what the index exists to replace.
|
|
440
|
+
*/
|
|
441
|
+
export async function searchComponents(graph, query, limit = 50, options) {
|
|
442
|
+
return settle(() => searchIn(graph, query, limit), options);
|
|
443
|
+
}
|
|
444
|
+
function searchIn(graph, query, limit) {
|
|
445
|
+
const needle = query.trim().toLowerCase();
|
|
446
|
+
if (needle === '')
|
|
447
|
+
return [];
|
|
448
|
+
const matches = [];
|
|
449
|
+
for (const component of graph.effective) {
|
|
450
|
+
const value = component.value;
|
|
451
|
+
const haystack = [
|
|
452
|
+
component.id,
|
|
453
|
+
component.collection,
|
|
454
|
+
component.provenance.sourceFile,
|
|
455
|
+
typeof value?.name === 'string' ? value.name : '',
|
|
456
|
+
typeof value?.description === 'string' ? value.description : '',
|
|
457
|
+
typeof value?.system === 'string' ? value.system : '',
|
|
458
|
+
typeof value?.displayType === 'string' ? value.displayType : '',
|
|
459
|
+
]
|
|
460
|
+
.join('\n')
|
|
461
|
+
.toLowerCase();
|
|
462
|
+
if (haystack.includes(needle))
|
|
463
|
+
matches.push(component);
|
|
464
|
+
if (matches.length >= limit)
|
|
465
|
+
break;
|
|
466
|
+
}
|
|
467
|
+
return matches;
|
|
468
|
+
}
|
|
469
|
+
//# sourceMappingURL=queries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queries.js","sourceRoot":"","sources":["../src/queries.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,uBAAuB,EACvB,8BAA8B,EAC9B,sBAAsB,GACvB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAarE,8FAA8F;AAC9F,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC;AAOzD;;;;;;;;GAQG;AACH,MAAM,MAAM,GAAG,KAAK,EAClB,OAAgB,EAChB,OAAsB,EACO,EAAE;IAC/B,uCAAuC;IACvC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E;SAChE;aACE,IAAI,CAAC,IAAI,CAAC;aACV,WAAW,EAAE,CAAC;QAEjB,IAAI,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC;YAAE,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACvD,IAAI,OAAO,CAAC,MAAM,IAAI,KAAK;YAAE,MAAM;IACrC,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/dist/ranges.d.ts
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { SourceRange } from './failures.js';
|
|
2
|
+
/** Zero-based line/column, the same shape a failure carries, for the same reason. */
|
|
3
|
+
export type { SourceRange } from './failures.js';
|
|
4
|
+
/**
|
|
5
|
+
* The range of one component within a file's text.
|
|
6
|
+
*
|
|
7
|
+
* Matched on the component's own identity — its `id`/`key` inside the named collection — rather
|
|
8
|
+
* than on a positional index. A file's components are not necessarily in the same order as the
|
|
9
|
+
* project's merged view of them, and an index taken from one and applied to the other is the
|
|
10
|
+
* defect this epic already had to fix once in the cursor path.
|
|
11
|
+
*
|
|
12
|
+
* When a file declares the same identity twice, the LAST one wins, because that is what the
|
|
13
|
+
* merge does — navigating to the entry that was overridden would point at text with no effect.
|
|
14
|
+
*/
|
|
15
|
+
export declare function findComponentRange(text: string, collection: string, id: string): SourceRange | undefined;
|
|
16
|
+
/** The key `findComponentRanges` maps by — the same identity pair `getComponent` is asked for. */
|
|
17
|
+
export declare const componentRangeKey: (collection: string, id: string) => string;
|
|
18
|
+
/**
|
|
19
|
+
* EVERY component's range in a file, from ONE parse (Phase 3 Story 3.2 AC 3).
|
|
20
|
+
*
|
|
21
|
+
* `findComponentRange` above parses the whole document to answer for one component, which is right for
|
|
22
|
+
* the one-off lookups it was written for — a hover, a go-to-definition. It is quadratic for a caller
|
|
23
|
+
* that wants them all: `getComponent` cached per component, so an outline of a 40-component file paid
|
|
24
|
+
* 40 full parses of that file.
|
|
25
|
+
*
|
|
26
|
+
* Measured, which is why this exists. Story 3.2's outline came in at **p95 313 ms, worst project
|
|
27
|
+
* 1,161 ms** against a 200 ms budget, and the workspace query at 561 ms. The epic's own contingency note
|
|
28
|
+
* says a missed budget is answered with a different strategy and never a relaxed number, because
|
|
29
|
+
* counter-metric C1 makes responsiveness non-negotiable. This is that strategy: parse once, look up N
|
|
30
|
+
* times.
|
|
31
|
+
*
|
|
32
|
+
* Deliberately shares `collectRanges` with the single-component function rather than reimplementing the
|
|
33
|
+
* item walk. The list-marker widening and the `trimEnd` correction below were each found by a failing
|
|
34
|
+
* test, and a second copy of that logic would not have inherited either.
|
|
35
|
+
*/
|
|
36
|
+
export declare function findComponentRanges(text: string): ReadonlyMap<string, SourceRange>;
|
|
37
|
+
/** The key `findStepRanges` maps by — a stage and a step key, which is how a flow node identifies itself. */
|
|
38
|
+
export declare const stepRangeKey: (stage: string, stepKey: string) => string;
|
|
39
|
+
/** Where something authored sits, and what it says. `sourceText` is sliced here so no caller re-derives offsets. */
|
|
40
|
+
export interface AuthoredRange {
|
|
41
|
+
readonly range: SourceRange;
|
|
42
|
+
readonly sourceText: string;
|
|
43
|
+
}
|
|
44
|
+
/** The key `stepPathKey` builds and `StepRange.paths` maps by — a dot-joined path of authored keys. */
|
|
45
|
+
export declare const stepPathKey: (path: readonly string[]) => string;
|
|
46
|
+
/**
|
|
47
|
+
* One authored path, located — carrying its SEGMENTS as well as its range.
|
|
48
|
+
*
|
|
49
|
+
* The segments are here because the map key cannot be un-joined safely: `.` is a legal character in a YAML key
|
|
50
|
+
* (`api.version` is authored in this corpus), so a consumer that split the key back apart would read one key as two.
|
|
51
|
+
* The frontend flow package learned the same lesson with a space-joined junction id and moved to `JSON.stringify` —
|
|
52
|
+
* this keeps the friendly key AND an unambiguous answer, rather than trading one for the other.
|
|
53
|
+
*/
|
|
54
|
+
export interface AuthoredPathRange extends AuthoredRange {
|
|
55
|
+
readonly path: readonly string[];
|
|
56
|
+
}
|
|
57
|
+
/** Where one step sits, what it says, and where each key INSIDE it sits. */
|
|
58
|
+
export interface StepRange extends AuthoredRange {
|
|
59
|
+
/**
|
|
60
|
+
* Every authored key path within this step, dot-joined → where that key sits (Jazz, 2026-08-17).
|
|
61
|
+
*
|
|
62
|
+
* The producer for a click on a DECISION DIAMOND. A junction's address tail is the path that reaches it —
|
|
63
|
+
* `…key_CHECK:data:if`, `…key_STEP:next:then:if`, `…key_FORWARD:next:expression` (AD-33 rule 4) — so a consumer that
|
|
64
|
+
* can locate a PATH can put the caret on the branch the diamond stands for, rather than on the step's first line.
|
|
65
|
+
* Reported as *"clicking the diamond should let me focus on the actual IF"*: every route resolver in both repos knew
|
|
66
|
+
* the path and nothing could turn one into a position, because the only step-level locator here stopped at the step.
|
|
67
|
+
*
|
|
68
|
+
* The range starts at the KEY, not at its value: the reader is being sent to `if:`, and a caret inside the condition
|
|
69
|
+
* expression reads as an edit position rather than a destination.
|
|
70
|
+
*
|
|
71
|
+
* MAPS only — a path never descends through a sequence, because a route key (`next`, `data`, `then`, `else`,
|
|
72
|
+
* `onError`) is always a mapping key. That also bounds the walk: a step's own keyed sub-arrays
|
|
73
|
+
* (`responseFilters`, `transformations`) are not entered, so the map stays the size of the step's own shape.
|
|
74
|
+
*/
|
|
75
|
+
readonly paths: ReadonlyMap<string, AuthoredPathRange>;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* EVERY step's range inside ONE component, from ONE parse (Story 4.5, AC-4b).
|
|
79
|
+
*
|
|
80
|
+
* The producer AC-4b was waiting for. `workerFlow` takes a `locate` callback and carries whatever it returns; until now
|
|
81
|
+
* nothing could answer it, because the machinery above stops at the component and a flow node is a step *inside* one.
|
|
82
|
+
* Story 4.1 predicted this as "new plumbing, not a port", and it is.
|
|
83
|
+
*
|
|
84
|
+
* ### Why it lives here rather than in the extension
|
|
85
|
+
*
|
|
86
|
+
* AD-3 and NFR-4 forbid a CORE package from opening a file, and this opens none: like `findComponentRange` above, it is
|
|
87
|
+
* given the text — the extension reads it from the graph's own prefetched `sources`. What the rule forbids is the
|
|
88
|
+
* READING, which stays in the adapter. Parsing here reuses the `markerStart` widening and the `trimEnd` correction,
|
|
89
|
+
* each of which was found by a failing test, and spares the extension a `yaml` dependency it does not have today — one
|
|
90
|
+
* that would land in the web bundle the AD-3 gate exists to keep small.
|
|
91
|
+
*
|
|
92
|
+
* ### Stage-agnostic, deliberately
|
|
93
|
+
*
|
|
94
|
+
* It does not know what a stage is called. Every sequence-valued property of the component is walked and every item
|
|
95
|
+
* carrying a `key` scalar recorded under it. `WORKER_STAGES` lives in the flow package, one layer UP, so importing the
|
|
96
|
+
* list would invert the dependency — and a hardcoded copy would go stale the next time a stage is added, a drift this
|
|
97
|
+
* feature has already had to fix once. Properties that merely happen to hold keyed items cost nothing: the map is
|
|
98
|
+
* queried by a stage name the flow model already believes in, so an entry nobody asks for is never read.
|
|
99
|
+
*
|
|
100
|
+
* ONE level deep, which is what keeps that generality safe — a step's own nested arrays (`responseFilters`,
|
|
101
|
+
* `transformations`) sit INSIDE the step item, not beside it, so their keys can never be mistaken for a step's.
|
|
102
|
+
*/
|
|
103
|
+
export declare function findStepRanges(text: string, collection: string, id: string): ReadonlyMap<string, StepRange>;
|
|
104
|
+
//# sourceMappingURL=ranges.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ranges.d.ts","sourceRoot":"","sources":["../src/ranges.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD,qFAAqF;AACrF,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AA0CjD;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,MAAM,GACT,WAAW,GAAG,SAAS,CAmDzB;AAED,kGAAkG;AAClG,eAAO,MAAM,iBAAiB,eAAgB,MAAM,MAAM,MAAM,KAAG,MACvC,CAAC;AAE7B;;;;;;;;;;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