@staix/vault-mem-ui 0.0.0-stage → 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/LICENSE +21 -0
  3. package/README.md +96 -2
  4. package/THIRD_PARTY_NOTICES.md +164 -0
  5. package/bin/vmem-ui.ts +26 -0
  6. package/dist/panel.css +666 -0
  7. package/dist/panel.js +355 -0
  8. package/package.json +53 -4
  9. package/src/client/App.tsx +167 -0
  10. package/src/client/a11y.ts +54 -0
  11. package/src/client/acon.ts +46 -0
  12. package/src/client/components.tsx +243 -0
  13. package/src/client/data.ts +66 -0
  14. package/src/client/fake.ts +48 -0
  15. package/src/client/graph-export.tsx +21 -0
  16. package/src/client/host.ts +80 -0
  17. package/src/client/markdown/parse.ts +620 -0
  18. package/src/client/markdown/render.tsx +270 -0
  19. package/src/client/panel.css +666 -0
  20. package/src/client/panel.tsx +66 -0
  21. package/src/client/prefs.ts +76 -0
  22. package/src/client/standalone.ts +44 -0
  23. package/src/client/store.ts +201 -0
  24. package/src/client/views/assertions.tsx +109 -0
  25. package/src/client/views/common.ts +15 -0
  26. package/src/client/views/history.tsx +205 -0
  27. package/src/client/views/lint.tsx +27 -0
  28. package/src/client/views/log.tsx +64 -0
  29. package/src/client/views/note.tsx +128 -0
  30. package/src/client/views/notes.tsx +34 -0
  31. package/src/client/views/overview.tsx +74 -0
  32. package/src/client/views/promote.tsx +112 -0
  33. package/src/client/views/proposals.tsx +55 -0
  34. package/src/client/views/settings.tsx +57 -0
  35. package/src/client/write.ts +144 -0
  36. package/src/graph/decisionChains.ts +122 -0
  37. package/src/graph/derive.ts +338 -0
  38. package/src/graph/export.ts +44 -0
  39. package/src/graph/insights.ts +254 -0
  40. package/src/graph/labels.ts +67 -0
  41. package/src/graph/layout/client.ts +139 -0
  42. package/src/graph/layout/engine.ts +107 -0
  43. package/src/graph/layout/fa2.d.ts +8 -0
  44. package/src/graph/layout/protocol.ts +70 -0
  45. package/src/graph/layout/worker.ts +132 -0
  46. package/src/graph/model.ts +230 -0
  47. package/src/graph/positions.ts +41 -0
  48. package/src/graph/search.ts +54 -0
  49. package/src/graph/style.ts +301 -0
  50. package/src/graph/target.ts +38 -0
  51. package/src/graph/types.ts +64 -0
  52. package/src/graph/view/GraphView.tsx +279 -0
  53. package/src/graph/view/SidePanels.tsx +141 -0
  54. package/src/graph/view/cache.ts +42 -0
  55. package/src/graph/view/canvas.ts +309 -0
  56. package/src/graph/view/graph-snapshot.ts +75 -0
  57. package/src/graph/view/lod.ts +30 -0
  58. package/src/graph/view/motion.ts +4 -0
  59. package/src/graph/view/state.ts +240 -0
  60. package/src/plugin/assets.ts +33 -0
  61. package/src/plugin/graph.ts +71 -0
  62. package/src/plugin/index.ts +23 -0
  63. package/src/server/cli.ts +99 -0
  64. package/src/server/host.ts +287 -0
@@ -0,0 +1,132 @@
1
+ // Worker side of the layout protocol. The panel module calls `runLayoutWorker()` when `isLayoutWorkerContext()` is
2
+ // true, so the worker is the panel's own same-origin module: `new Worker(new URL(import.meta.url), {type: "module",
3
+ // name: LAYOUT_WORKER_NAME})`. No blob: URL, no separate asset.
4
+
5
+ import { createLayoutEngine, type LayoutEngine } from "./engine";
6
+ import { CONVERGED_MOVEMENT, CONVERGED_STREAK, LAYOUT_WORKER_NAME, MAX_LAYOUT_ITERATIONS, type FromWorker, type ToWorker } from "./protocol";
7
+
8
+ interface WorkerScope {
9
+ name?: string;
10
+ postMessage(message: FromWorker, transfer?: Transferable[]): void;
11
+ addEventListener(type: "message", listener: (event: MessageEvent<ToWorker>) => void): void;
12
+ close(): void;
13
+ }
14
+
15
+ /** True only inside a worker started under LAYOUT_WORKER_NAME (not on a page, not in another worker). */
16
+ export function isLayoutWorkerContext(scope: unknown = globalThis): boolean {
17
+ const s = scope as Partial<WorkerScope> & { document?: unknown };
18
+ return typeof s.document === "undefined" && typeof s.postMessage === "function" && s.name === LAYOUT_WORKER_NAME;
19
+ }
20
+
21
+ export interface LayoutLoopOptions {
22
+ /** Defaults to setTimeout; tests may inject a scheduler. */
23
+ schedule?: (fn: () => void, ms: number) => unknown;
24
+ now?: () => number;
25
+ }
26
+
27
+ /** Wires the protocol onto a worker scope. Exported for tests; production calls runLayoutWorker(). */
28
+ export function attachLayoutWorker(scope: WorkerScope, options: LayoutLoopOptions = {}): void {
29
+ const schedule = options.schedule ?? ((fn: () => void, ms: number) => setTimeout(fn, ms));
30
+ const now = options.now ?? (() => performance.now());
31
+ let engine: LayoutEngine | null = null;
32
+ let batchMs = 16;
33
+ let maxIterations = MAX_LAYOUT_ITERATIONS;
34
+ /** Iteration count at which the current run ends: init grants maxIterations, and so does each restart by "fix". */
35
+ let limit = MAX_LAYOUT_ITERATIONS;
36
+ let convergedMovement = CONVERGED_MOVEMENT;
37
+ let convergedStreak = CONVERGED_STREAK;
38
+ let streak = 0;
39
+ let state: "idle" | "running" | "paused" | "stopped" | "done" = "idle";
40
+ let pending = false;
41
+
42
+ const post = (message: FromWorker, transfer?: Transferable[]) => scope.postMessage(message, transfer);
43
+ const fail = (cause: unknown) => {
44
+ const message = cause instanceof Error ? cause.message : String(cause);
45
+ state = "stopped";
46
+ post({ type: "error", message: `graph layout stopped: ${message}; reload the graph to restart the layout, or keep the cached positions` });
47
+ };
48
+ const sendPositions = () => {
49
+ const positions = engine!.positions();
50
+ post({ type: "positions", positions, iterations: engine!.iterations }, [positions.buffer]);
51
+ };
52
+
53
+ // One batch: iterate until the batch interval is used up, send positions once, then yield so pause/stop/teardown
54
+ // messages are handled between batches.
55
+ const tick = () => {
56
+ pending = false;
57
+ if (state !== "running" || !engine) return;
58
+ try {
59
+ const start = now();
60
+ let settled = false;
61
+ do {
62
+ engine.step(1);
63
+ streak = engine.movement < convergedMovement ? streak + 1 : 0;
64
+ settled = streak >= convergedStreak || engine.nodeCount === 0;
65
+ } while (!settled && engine.iterations < limit && now() - start < batchMs);
66
+ sendPositions();
67
+ if (settled || engine.iterations >= limit) {
68
+ state = "done";
69
+ post({ type: "state", state: "done" });
70
+ return;
71
+ }
72
+ } catch (error) {
73
+ fail(error);
74
+ return;
75
+ }
76
+ pending = true;
77
+ schedule(tick, 0);
78
+ };
79
+ const run = () => {
80
+ state = "running";
81
+ post({ type: "state", state: "running" });
82
+ if (!pending) { pending = true; schedule(tick, 0); }
83
+ };
84
+
85
+ scope.addEventListener("message", (event) => {
86
+ const message = event.data;
87
+ try {
88
+ switch (message.type) {
89
+ case "init":
90
+ engine = createLayoutEngine(message.graph, message.settings);
91
+ batchMs = message.batchMs;
92
+ maxIterations = message.maxIterations ?? MAX_LAYOUT_ITERATIONS;
93
+ limit = maxIterations;
94
+ convergedMovement = message.convergedMovement ?? CONVERGED_MOVEMENT;
95
+ convergedStreak = message.convergedStreak ?? CONVERGED_STREAK;
96
+ streak = 0;
97
+ post({ type: "ready" });
98
+ run();
99
+ break;
100
+ case "pause":
101
+ if (state === "running") { state = "paused"; post({ type: "state", state: "paused" }); }
102
+ break;
103
+ case "resume":
104
+ if (state === "paused") run();
105
+ break;
106
+ case "fix":
107
+ if (!engine || state === "stopped") break;
108
+ for (const node of message.nodes) engine.setFixed(node.index, node.fixed, node.position);
109
+ streak = 0;
110
+ // A settled or capped layout runs again with a fresh budget so released nodes move; a paused one stays
111
+ // paused until resumed (and keeps its budget).
112
+ if (state === "done") { limit = engine.iterations + maxIterations; run(); }
113
+ break;
114
+ case "stop":
115
+ if (engine && state !== "stopped") { state = "stopped"; sendPositions(); post({ type: "state", state: "stopped" }); }
116
+ break;
117
+ case "teardown":
118
+ state = "stopped";
119
+ engine = null;
120
+ scope.close();
121
+ break;
122
+ }
123
+ } catch (error) {
124
+ fail(error);
125
+ }
126
+ });
127
+ }
128
+
129
+ /** Entry for the panel module: `if (isLayoutWorkerContext()) runLayoutWorker();` */
130
+ export function runLayoutWorker(): void {
131
+ attachLayoutWorker(globalThis as unknown as WorkerScope);
132
+ }
@@ -0,0 +1,230 @@
1
+ // Graph model for the graph view.
2
+ // Ported from STAIxBWLB/maru@b33341df src/lib/graph/model.ts. The maru version derived the graph from
3
+ // VaultEntry[] and overlaid communities from reports/vault-graph.json; here the graph comes only from the
4
+ // provider's graph snapshot, through GraphInput (see ./types.ts), so buildGraphModel replaces buildVaultGraph
5
+ // and enrichGraph, and the knowledge-root/VaultGraphFile helpers are gone.
6
+
7
+ import type { GraphInput } from "./types";
8
+
9
+ /** Where a node came from. "unknown" = ghost (no path to classify). */
10
+ export type GraphNodeOrigin = "workspace" | "knowledge" | "unknown";
11
+ /** The pair an edge connects; "cross" spans the workspace/knowledge boundary. */
12
+ export type GraphEdgeOrigin = "workspace" | "knowledge" | "cross";
13
+
14
+ export interface GraphNode {
15
+ id: string;
16
+ label: string;
17
+ /** null = ghost (unresolved wikilink target — F3(b)'s input). */
18
+ relPath: string | null;
19
+ ownerWorkspacePath?: string | null;
20
+ origin: GraphNodeOrigin;
21
+ type: string;
22
+ domain: string | null;
23
+ degree: number;
24
+ community: number | null;
25
+ isGodNode: boolean;
26
+ /** frontmatter created/decided_date/date — decision-chain lane ordering. */
27
+ date: string | null;
28
+ /** Last modification time (ISO) — stale-note detection; null for ghosts. */
29
+ updatedAt: string | null;
30
+ }
31
+
32
+ export interface GraphEdge {
33
+ source: string;
34
+ target: string;
35
+ /** frontmatter field name, or "wiki_link" for body links. */
36
+ relation: string;
37
+ fromFrontmatter: boolean;
38
+ origin: GraphEdgeOrigin;
39
+ }
40
+
41
+ export interface GraphModel {
42
+ nodes: GraphNode[];
43
+ edges: GraphEdge[];
44
+ enriched: boolean;
45
+ builtAt: number;
46
+ }
47
+
48
+ /** Stable visibility identity for an edge. The model de-duplicates identical
49
+ * source/target/relation tuples, so this key can mask relation-filtered edges
50
+ * without rebuilding the Sigma topology. */
51
+ export function graphEdgeVisibilityKey(
52
+ edge: Pick<GraphEdge, "source" | "target" | "relation" | "fromFrontmatter">,
53
+ ): string {
54
+ return JSON.stringify([edge.source, edge.target, edge.relation, edge.fromFrontmatter]);
55
+ }
56
+
57
+ /** Recompute incident-edge degree for a derived model. Graph consumers must
58
+ * not keep displaying the full-vault degree after relation/local pruning. */
59
+ export function withGraphDegrees(model: GraphModel): GraphModel {
60
+ const degrees = new Map(model.nodes.map((node) => [node.id, 0]));
61
+ for (const edge of model.edges) {
62
+ degrees.set(edge.source, (degrees.get(edge.source) ?? 0) + 1);
63
+ degrees.set(edge.target, (degrees.get(edge.target) ?? 0) + 1);
64
+ }
65
+ return {
66
+ ...model,
67
+ nodes: model.nodes.map((node) => ({ ...node, degree: degrees.get(node.id) ?? 0 })),
68
+ };
69
+ }
70
+
71
+ const GOD_NODE_COUNT = 10;
72
+
73
+ /** Edge class from its endpoints. A ghost endpoint is not evidence of a
74
+ * crossing, so "unknown" inherits the known side instead of counting as cross. */
75
+ export function edgeOrigin(
76
+ a: GraphNodeOrigin,
77
+ b: GraphNodeOrigin,
78
+ ): GraphEdgeOrigin {
79
+ if (a === "unknown") return b === "unknown" ? "workspace" : b;
80
+ if (b === "unknown" || a === b) return a;
81
+ return "cross";
82
+ }
83
+
84
+ /** Build the model from the provider graph input. Self loops and duplicate source/target/relation triples are
85
+ * dropped, edge targets that are not in the input become unresolved ("ghost") nodes, degrees are counted and the
86
+ * ten best-connected non-MOC notes are marked as god nodes. `enriched` is true when communities were supplied. */
87
+ export function buildGraphModel(input: GraphInput, builtAt: number = Date.now()): GraphModel {
88
+ const communities = input.communities;
89
+ const nodes = new Map<string, GraphNode>();
90
+ for (const n of input.nodes) {
91
+ if (nodes.has(n.id)) continue;
92
+ // Invariant: a node without a path is a ghost, whatever type the input claims; filters, chains and insights
93
+ // classify ghosts by type === "unresolved".
94
+ const type = n.relPath === null ? "unresolved" : (n.type?.trim() || "untyped");
95
+ nodes.set(n.id, {
96
+ id: n.id,
97
+ label: n.label,
98
+ relPath: n.relPath,
99
+ ownerWorkspacePath: n.ownerWorkspacePath ?? null,
100
+ origin: n.relPath === null ? "unknown" : (n.origin ?? "knowledge"),
101
+ type,
102
+ domain: n.domain?.trim() || null,
103
+ degree: 0,
104
+ // Own properties only: an id such as `constructor` must not read Object.prototype.
105
+ community: communities && Object.hasOwn(communities, n.id) && Number.isFinite(communities[n.id]) ? communities[n.id]! : null,
106
+ isGodNode: false,
107
+ date: n.date ?? null,
108
+ updatedAt: n.relPath === null ? null : (n.updatedAt ?? null),
109
+ });
110
+ }
111
+ const ensure = (id: string) => {
112
+ if (nodes.has(id)) return;
113
+ nodes.set(id, {
114
+ id, label: id, relPath: null, ownerWorkspacePath: null, origin: "unknown", type: "unresolved",
115
+ domain: null, degree: 0, community: null, isGodNode: false, date: null, updatedAt: null,
116
+ });
117
+ };
118
+
119
+ const edges: GraphEdge[] = [];
120
+ const seenEdges = new Set<string>();
121
+ for (const e of input.edges) {
122
+ if (e.source === e.target) continue;
123
+ const key = `${e.source}\u0000${e.target}\u0000${e.relation}`;
124
+ if (seenEdges.has(key)) continue;
125
+ seenEdges.add(key);
126
+ ensure(e.source);
127
+ ensure(e.target);
128
+ edges.push({
129
+ source: e.source,
130
+ target: e.target,
131
+ relation: e.relation,
132
+ fromFrontmatter: e.fromFrontmatter,
133
+ origin: edgeOrigin(nodes.get(e.source)!.origin, nodes.get(e.target)!.origin),
134
+ });
135
+ }
136
+
137
+ for (const edge of edges) {
138
+ nodes.get(edge.source)!.degree += 1;
139
+ nodes.get(edge.target)!.degree += 1;
140
+ }
141
+
142
+ const godCandidates = [...nodes.values()]
143
+ .filter((n) => n.type !== "moc" && n.type !== "unresolved")
144
+ .sort((a, b) => b.degree - a.degree)
145
+ .slice(0, GOD_NODE_COUNT);
146
+ for (const node of godCandidates) {
147
+ if (node.degree > 0) node.isGodNode = true;
148
+ }
149
+
150
+ return { nodes: [...nodes.values()], edges, enriched: communities !== undefined, builtAt };
151
+ }
152
+
153
+ /** Precomputed 1-hop adjacency for hover highlighting. Cached per model so
154
+ * the 3-4 callers in a render cycle (insights + focusSubgraph) share one build
155
+ * instead of each rebuilding O(E). A new model identity (vault edit / enrich)
156
+ * misses and rebuilds; keyed weakly so old models get collected. */
157
+ const adjacencyCache = new WeakMap<GraphModel, Map<string, Set<string>>>();
158
+
159
+ export function buildAdjacency(model: GraphModel): Map<string, Set<string>> {
160
+ const cached = adjacencyCache.get(model);
161
+ if (cached) return cached;
162
+ const adjacency = new Map<string, Set<string>>();
163
+ const add = (a: string, b: string) => {
164
+ let set = adjacency.get(a);
165
+ if (!set) {
166
+ set = new Set();
167
+ adjacency.set(a, set);
168
+ }
169
+ set.add(b);
170
+ };
171
+ for (const edge of model.edges) {
172
+ add(edge.source, edge.target);
173
+ add(edge.target, edge.source);
174
+ }
175
+ adjacencyCache.set(model, adjacency);
176
+ return adjacency;
177
+ }
178
+
179
+ /** k-hop subgraph around a focus node (focus mode, k=2 per spec). */
180
+ export function focusSubgraph(
181
+ model: GraphModel,
182
+ focusId: string,
183
+ k: number = 2,
184
+ direction: "both" | "incoming" | "outgoing" = "both",
185
+ ): GraphModel {
186
+ const adjacency = direction === "both" ? buildAdjacency(model) : new Map<string, Set<string>>();
187
+ if (direction !== "both") {
188
+ for (const edge of model.edges) {
189
+ const from = direction === "outgoing" ? edge.source : edge.target;
190
+ const to = direction === "outgoing" ? edge.target : edge.source;
191
+ if (!adjacency.has(from)) adjacency.set(from, new Set());
192
+ adjacency.get(from)!.add(to);
193
+ }
194
+ }
195
+ const keep = new Set<string>([focusId]);
196
+ let frontier = [focusId];
197
+ for (let hop = 0; hop < k; hop += 1) {
198
+ const next: string[] = [];
199
+ for (const id of frontier) {
200
+ for (const neighbor of adjacency.get(id) ?? []) {
201
+ if (!keep.has(neighbor)) {
202
+ keep.add(neighbor);
203
+ next.push(neighbor);
204
+ }
205
+ }
206
+ }
207
+ frontier = next;
208
+ }
209
+ return {
210
+ ...model,
211
+ nodes: model.nodes.filter((n) => keep.has(n.id)),
212
+ edges: model.edges.filter((e) => keep.has(e.source) && keep.has(e.target)),
213
+ };
214
+ }
215
+
216
+ /** Generated content: notes whose relPath matches a configured generated
217
+ * pattern (trailing "/" = prefix match, otherwise exact filename match),
218
+ * both case-insensitive. Untyped notes are visible authored content — they
219
+ * are NOT generated. Ghosts (`relPath: null`, type "unresolved") are governed
220
+ * by the showUnresolved filter, not here. */
221
+ export function isGeneratedNode(node: GraphNode, patterns: readonly string[]): boolean {
222
+ if (node.type === "unresolved") return false;
223
+ if (!node.relPath) return false;
224
+ const relPath = node.relPath.toLowerCase();
225
+ const fileName = relPath.split("/").pop() ?? relPath;
226
+ return patterns.some((raw) => {
227
+ const pattern = raw.toLowerCase();
228
+ return pattern.endsWith("/") ? relPath.startsWith(pattern) : fileName === pattern;
229
+ });
230
+ }
@@ -0,0 +1,41 @@
1
+ // Ported from STAIxBWLB/maru@b33341df src/lib/graph/positions.ts.
2
+ // Position validation for the graph canvas. Disk-cached and worker-computed
3
+ // coordinates can go non-finite (NaN/Infinity from a degenerate FA2 run) or
4
+ // absurdly large (a node flung out by an unstable layout); both silently break
5
+ // rendering and camera fitting. These guards keep bad values out of the
6
+ // renderer and out of the cache.
7
+
8
+ /** Coordinates beyond this magnitude are treated as corrupt. */
9
+ export const MAX_POSITION_MAGNITUDE = 1e6;
10
+
11
+ /** A usable graph coordinate: finite and within the sanity bound. */
12
+ export function isUsableCoordinate(value: unknown): value is number {
13
+ return (
14
+ typeof value === "number" &&
15
+ Number.isFinite(value) &&
16
+ Math.abs(value) <= MAX_POSITION_MAGNITUDE
17
+ );
18
+ }
19
+
20
+ /** True when every coordinate in the buffer is finite. Used to gate the
21
+ * debounced disk-cache save — a single NaN would poison the whole cache. */
22
+ export function isFinitePositions(positions: ArrayLike<number>): boolean {
23
+ for (let i = 0; i < positions.length; i += 1) {
24
+ if (!Number.isFinite(positions[i])) return false;
25
+ }
26
+ return true;
27
+ }
28
+
29
+ /** Drop entries with non-finite or out-of-bounds coordinates. Returns a new
30
+ * record; the input is not mutated. */
31
+ export function sanitizePositions(
32
+ positions: Record<string, [number, number]>,
33
+ ): Record<string, [number, number]> {
34
+ const clean: Record<string, [number, number]> = {};
35
+ for (const [id, point] of Object.entries(positions)) {
36
+ if (!Array.isArray(point)) continue;
37
+ const [x, y] = point;
38
+ if (isUsableCoordinate(x) && isUsableCoordinate(y)) clean[id] = [x, y];
39
+ }
40
+ return clean;
41
+ }
@@ -0,0 +1,54 @@
1
+ // Ported from STAIxBWLB/maru@b33341df src/lib/graph/search.ts.
2
+ // Search ranking for the graph toolbar combobox. Searches the CURRENT
3
+ // filtered graph (visibleModel nodes); ranking: exact label → label prefix →
4
+ // label substring → relPath substring, ties broken alphabetically for stable
5
+ // arrow-key navigation.
6
+
7
+ export interface GraphSearchResult {
8
+ id: string;
9
+ label: string;
10
+ relPath: string | null;
11
+ }
12
+
13
+ export const GRAPH_SEARCH_LIMIT = 20;
14
+
15
+ /** The same match category used by ranked search, or null when the node does not match. */
16
+ export function graphSearchRank(node: { label: string; relPath: string | null }, query: string): number | null {
17
+ const q = query.trim().toLowerCase();
18
+ if (!q) return null;
19
+ const label = node.label.toLowerCase();
20
+ if (label === q) return 0;
21
+ if (label.startsWith(q)) return 1;
22
+ if (label.includes(q)) return 2;
23
+ if (node.relPath && node.relPath.toLowerCase().includes(q)) return 3;
24
+ return null;
25
+ }
26
+
27
+ export function graphNodeMatchesSearch(
28
+ node: { label: string; relPath: string | null },
29
+ query: string,
30
+ ): boolean {
31
+ const q = query.trim().toLowerCase();
32
+ if (!q) return true;
33
+ return node.label.toLowerCase().includes(q)
34
+ || Boolean(node.relPath?.toLowerCase().includes(q));
35
+ }
36
+
37
+ export function rankGraphSearch(
38
+ nodes: readonly { id: string; label: string; relPath: string | null }[],
39
+ query: string,
40
+ limit: number = GRAPH_SEARCH_LIMIT,
41
+ ): GraphSearchResult[] {
42
+ const q = query.trim().toLowerCase();
43
+ if (!q) return [];
44
+ const scored: { node: GraphSearchResult; rank: number }[] = [];
45
+ for (const node of nodes) {
46
+ const rank = graphSearchRank(node, q);
47
+ if (rank == null) continue;
48
+ scored.push({ node: { id: node.id, label: node.label, relPath: node.relPath }, rank });
49
+ }
50
+ scored.sort(
51
+ (a, b) => a.rank - b.rank || a.node.label.localeCompare(b.node.label) || a.node.id.localeCompare(b.node.id),
52
+ );
53
+ return scored.slice(0, limit).map((entry) => entry.node);
54
+ }