@getchomp/mcp 0.0.0-stage → 0.2.43

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/LICENSE +21 -0
  2. package/README.md +15 -2
  3. package/dist/conventionsReference.d.ts +84 -0
  4. package/dist/conventionsReference.js +313 -0
  5. package/dist/designSystem/astScanner.d.ts +153 -0
  6. package/dist/designSystem/astScanner.js +2014 -0
  7. package/dist/designSystem/baseline.d.ts +65 -0
  8. package/dist/designSystem/baseline.js +136 -0
  9. package/dist/designSystem/color.d.ts +35 -0
  10. package/dist/designSystem/color.js +265 -0
  11. package/dist/designSystem/config.d.ts +183 -0
  12. package/dist/designSystem/config.js +469 -0
  13. package/dist/designSystem/contrast.d.ts +55 -0
  14. package/dist/designSystem/contrast.js +377 -0
  15. package/dist/designSystem/cssParser.d.ts +63 -0
  16. package/dist/designSystem/cssParser.js +469 -0
  17. package/dist/designSystem/merges.d.ts +57 -0
  18. package/dist/designSystem/merges.js +94 -0
  19. package/dist/designSystem/preprocessors.d.ts +46 -0
  20. package/dist/designSystem/preprocessors.js +1108 -0
  21. package/dist/designSystem/presentation.d.ts +45 -0
  22. package/dist/designSystem/presentation.js +796 -0
  23. package/dist/designSystem/styleVectors.d.ts +27 -0
  24. package/dist/designSystem/styleVectors.js +484 -0
  25. package/dist/designSystem/tokens.d.ts +39 -0
  26. package/dist/designSystem/tokens.js +409 -0
  27. package/dist/designSystem/topology.d.ts +64 -0
  28. package/dist/designSystem/topology.js +254 -0
  29. package/dist/designSystem/types.d.ts +857 -0
  30. package/dist/designSystem/types.js +113 -0
  31. package/dist/designSystem/typography.d.ts +25 -0
  32. package/dist/designSystem/typography.js +244 -0
  33. package/dist/designSystem/uiShapes.d.ts +74 -0
  34. package/dist/designSystem/uiShapes.js +285 -0
  35. package/dist/designSystem/valueClusters.d.ts +76 -0
  36. package/dist/designSystem/valueClusters.js +281 -0
  37. package/dist/designSystemPlugin.d.ts +321 -0
  38. package/dist/designSystemPlugin.js +4730 -0
  39. package/dist/enrichNodesPlugin.d.ts +160 -0
  40. package/dist/enrichNodesPlugin.js +957 -0
  41. package/dist/index.d.ts +65 -0
  42. package/dist/index.js +1298 -0
  43. package/dist/intelligence.d.ts +502 -0
  44. package/dist/intelligence.js +3058 -0
  45. package/dist/pluginRunner.d.ts +364 -0
  46. package/dist/pluginRunner.js +1096 -0
  47. package/dist/plugins/design-system/index.d.ts +14 -0
  48. package/dist/plugins/design-system/index.js +241 -0
  49. package/dist/plugins/enrich-nodes/index.d.ts +388 -0
  50. package/dist/plugins/enrich-nodes/index.js +697 -0
  51. package/dist/plugins/index.d.ts +15 -0
  52. package/dist/plugins/index.js +20 -0
  53. package/dist/plugins/local-shims/index.d.ts +121 -0
  54. package/dist/plugins/local-shims/index.js +237 -0
  55. package/dist/shimsPlugin.d.ts +134 -0
  56. package/dist/shimsPlugin.js +1392 -0
  57. package/package.json +39 -3
@@ -0,0 +1,957 @@
1
+ /**
2
+ * packages/mcp/src/enrichNodesPlugin.ts
3
+ *
4
+ * Node Enrichment Plugin (`L1_SEMANTIC` / `source: 'enrich-nodes'`)
5
+ * Enforces [PAT-DB-03], [PAT-DB-05], [PAT-MCP-08], [PAT-VIS-24], [PAT-VIS-25], [PAT-VIS-26], [PAT-VIS-36].
6
+ *
7
+ * Synthesizes Plugin Presentation Contract v1 (`payload.presentation`) for Layer 1 semantic
8
+ * enrichments (`chomp_enrich_nodes` / `AI_HYPOTHESIS` rows in `entity_overlays`) without ever
9
+ * overwriting or pruning the underlying `AI_HYPOTHESIS` rows:
10
+ * - Scoped strictly to `PackageInspectorDrawer` (`inspectorScopes: ["package"]`) because node-level
11
+ * semantic labels and summaries write directly to the node's primary title, alias, and description.
12
+ * - Surfaces a clean HUD status dot (no canvas Spotlight views) with un-enriched node count, concise
13
+ * value description, and copyable agent prompt instructions.
14
+ * - Renders a streamlined 3-metric Package Inspector card (`Coverage`, `Enriched`, `Stale`) with
15
+ * skimmable click-through line items.
16
+ */
17
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
18
+ import { dirname, resolve } from "node:path";
19
+ import { PLUGIN_PRESENTATION_PAYLOAD_KEY, PLUGIN_PRESENTATION_VERSION, capForPresentation, } from "@getchomp/core";
20
+ import { packageMatchesFilter } from "./intelligence.js";
21
+ export const ENRICH_NODES_PLUGIN_NAME = "enrich-nodes";
22
+ export const SEMANTIC_OVERLAY_LAYER = "L1_SEMANTIC";
23
+ export const SEMANTIC_PRODUCER_SOURCE = "chomp_enrich_nodes";
24
+ export const SEMANTIC_SIDECAR_FILENAME = "semantic.json";
25
+ export const SEMANTIC_SIDECAR_FILE_REL = ".chomp/plugins/enrich-nodes/semantic.json";
26
+ const ENRICH_HUD_DESCRIPTION = "Adds plain-English names and summaries that flag themselves when code changes.";
27
+ function stripNodePrefix(name) {
28
+ const idx = name.indexOf(":");
29
+ return idx >= 0 ? name.slice(idx + 1).trim() : name.trim();
30
+ }
31
+ function getPrimaryEvidenceRecord(node) {
32
+ const ev = node.evidence;
33
+ if (!ev)
34
+ return {};
35
+ if (Array.isArray(ev)) {
36
+ const first = ev.find((r) => Boolean(r?.filePath)) ?? ev[0];
37
+ return {
38
+ filePath: first?.filePath,
39
+ lineNumber: first?.lineNumber,
40
+ snippet: first?.snippet,
41
+ };
42
+ }
43
+ return {
44
+ filePath: ev.filePath,
45
+ lineNumber: ev.lineNumber,
46
+ snippet: ev.snippet,
47
+ };
48
+ }
49
+ function normalizeSemanticEntry(raw) {
50
+ if (!raw || typeof raw !== "object" || Array.isArray(raw))
51
+ return null;
52
+ const r = raw;
53
+ const domain = typeof r.domain === "string" && r.domain.trim() ? r.domain.trim() : undefined;
54
+ const humanLabel = typeof r.humanLabel === "string" && r.humanLabel.trim() ? r.humanLabel.trim() : undefined;
55
+ const summary = typeof r.summary === "string" && r.summary.trim() ? r.summary.trim() : undefined;
56
+ const rationale = typeof r.rationale === "string" && r.rationale.trim() ? r.rationale.trim() : undefined;
57
+ if (!domain && !humanLabel && !summary && !rationale)
58
+ return null;
59
+ const bodyHash = typeof r.bodyHash === "string" && r.bodyHash.trim()
60
+ ? r.bodyHash.trim()
61
+ : r.bodyHash === null
62
+ ? null
63
+ : undefined;
64
+ const updatedAt = typeof r.updatedAt === "string" && r.updatedAt.trim() ? r.updatedAt.trim() : undefined;
65
+ return {
66
+ ...(domain ? { domain } : {}),
67
+ ...(humanLabel ? { humanLabel } : {}),
68
+ ...(summary ? { summary } : {}),
69
+ ...(rationale ? { rationale } : {}),
70
+ ...(bodyHash !== undefined ? { bodyHash } : {}),
71
+ ...(updatedAt ? { updatedAt } : {}),
72
+ };
73
+ }
74
+ export function parseSemanticSidecar(rawText) {
75
+ if (!rawText || !rawText.trim()) {
76
+ return { schemaVersion: 1, domains: [], nodes: {} };
77
+ }
78
+ try {
79
+ const parsed = JSON.parse(rawText);
80
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
81
+ return { schemaVersion: 1, domains: [], nodes: {} };
82
+ }
83
+ const nodes = {};
84
+ const domainSet = new Set();
85
+ if (Array.isArray(parsed.domains)) {
86
+ for (const d of parsed.domains) {
87
+ if (typeof d === "string" && d.trim())
88
+ domainSet.add(d.trim());
89
+ }
90
+ }
91
+ const rawNodes = parsed.nodes;
92
+ if (rawNodes && typeof rawNodes === "object" && !Array.isArray(rawNodes)) {
93
+ for (const [nodeId, rawEntry] of Object.entries(rawNodes)) {
94
+ if (!nodeId.trim())
95
+ continue;
96
+ const normalized = normalizeSemanticEntry(rawEntry);
97
+ if (!normalized)
98
+ continue;
99
+ nodes[nodeId.trim()] = normalized;
100
+ if (normalized.domain)
101
+ domainSet.add(normalized.domain);
102
+ }
103
+ }
104
+ return {
105
+ schemaVersion: 1,
106
+ domains: [...domainSet].sort((a, b) => a.localeCompare(b)),
107
+ nodes,
108
+ };
109
+ }
110
+ catch {
111
+ return { schemaVersion: 1, domains: [], nodes: {} };
112
+ }
113
+ }
114
+ export function serializeSemanticSidecar(sidecar) {
115
+ const domainSet = new Set((sidecar.domains ?? []).map((d) => d.trim()).filter(Boolean));
116
+ const sortedNodes = {};
117
+ for (const key of Object.keys(sidecar.nodes).sort((a, b) => a.localeCompare(b))) {
118
+ const normalized = normalizeSemanticEntry(sidecar.nodes[key]);
119
+ if (!normalized)
120
+ continue;
121
+ sortedNodes[key] = normalized;
122
+ if (normalized.domain)
123
+ domainSet.add(normalized.domain);
124
+ }
125
+ const canonical = {
126
+ schemaVersion: 1,
127
+ domains: [...domainSet].sort((a, b) => a.localeCompare(b)),
128
+ nodes: sortedNodes,
129
+ };
130
+ return `${JSON.stringify(canonical, null, 2)}\n`;
131
+ }
132
+ export function readSemanticSidecar(repoPath) {
133
+ const absPath = resolve(repoPath, SEMANTIC_SIDECAR_FILE_REL);
134
+ if (!existsSync(absPath))
135
+ return null;
136
+ try {
137
+ return parseSemanticSidecar(readFileSync(absPath, "utf8"));
138
+ }
139
+ catch {
140
+ return null;
141
+ }
142
+ }
143
+ export function writeSemanticSidecar(repoPath, sidecar) {
144
+ const absPath = resolve(repoPath, SEMANTIC_SIDECAR_FILE_REL);
145
+ mkdirSync(dirname(absPath), { recursive: true });
146
+ writeFileSync(absPath, serializeSemanticSidecar(sidecar), "utf8");
147
+ return absPath;
148
+ }
149
+ export function mergeNodesIntoSemanticSidecar(repoPath, updates, existingFromDb) {
150
+ const existingOnDisk = readSemanticSidecar(repoPath);
151
+ const sidecar = existingOnDisk
152
+ ? {
153
+ schemaVersion: 1,
154
+ domains: [...existingOnDisk.domains],
155
+ nodes: { ...existingOnDisk.nodes },
156
+ }
157
+ : { schemaVersion: 1, domains: [], nodes: {} };
158
+ if (existingFromDb && existingFromDb.length > 0 && !existingOnDisk) {
159
+ for (const ov of existingFromDb) {
160
+ if (ov.layer !== SEMANTIC_OVERLAY_LAYER || ov.source === ENRICH_NODES_PLUGIN_NAME) {
161
+ continue;
162
+ }
163
+ const norm = normalizeSemanticEntry({
164
+ ...(ov.payload ?? {}),
165
+ bodyHash: ov.bodyHash ?? null,
166
+ updatedAt: ov.updatedAt,
167
+ });
168
+ if (!norm)
169
+ continue;
170
+ sidecar.nodes[ov.entityId] = { ...(sidecar.nodes[ov.entityId] ?? {}), ...norm };
171
+ }
172
+ }
173
+ const nowIso = new Date().toISOString();
174
+ for (const u of updates) {
175
+ const prev = sidecar.nodes[u.nodeId] ?? {};
176
+ const merged = normalizeSemanticEntry({
177
+ ...prev,
178
+ ...(u.domain?.trim() ? { domain: u.domain.trim() } : {}),
179
+ ...(u.humanLabel?.trim() ? { humanLabel: u.humanLabel.trim() } : {}),
180
+ ...(u.summary?.trim() ? { summary: u.summary.trim() } : {}),
181
+ ...(u.rationale?.trim() ? { rationale: u.rationale.trim() } : {}),
182
+ ...(u.bodyHash !== undefined ? { bodyHash: u.bodyHash } : {}),
183
+ updatedAt: nowIso,
184
+ });
185
+ if (merged) {
186
+ sidecar.nodes[u.nodeId] = merged;
187
+ }
188
+ }
189
+ const writtenPath = writeSemanticSidecar(repoPath, sidecar);
190
+ const parsedWritten = parseSemanticSidecar(readFileSync(writtenPath, "utf8"));
191
+ return {
192
+ path: SEMANTIC_SIDECAR_FILE_REL,
193
+ totalNodes: Object.keys(parsedWritten.nodes).length,
194
+ domains: parsedWritten.domains,
195
+ };
196
+ }
197
+ function formatShortDate(iso) {
198
+ if (!iso)
199
+ return null;
200
+ const d = new Date(iso);
201
+ if (Number.isNaN(d.getTime()))
202
+ return null;
203
+ return d.toISOString().slice(0, 10);
204
+ }
205
+ function formatStaleDetail(sem) {
206
+ const shortDate = formatShortDate(sem.updatedAt);
207
+ if (sem.staleReason === "bodyHash_drift") {
208
+ return shortDate ? `Code modified since ${shortDate}` : "Code modified since enrichment";
209
+ }
210
+ return shortDate ? `Marked stale · ${shortDate}` : "Marked stale";
211
+ }
212
+ function formatEnrichHeadline(enrichedCount, unenrichedCount, staleCount, totalCount) {
213
+ if (totalCount === 0)
214
+ return "No nodes in scope";
215
+ if (enrichedCount === 0) {
216
+ return `No nodes summarized yet · ${unenrichedCount} ready`;
217
+ }
218
+ if (unenrichedCount > 0) {
219
+ const base = `${unenrichedCount} node${unenrichedCount === 1 ? "" : "s"} missing summaries`;
220
+ return staleCount > 0 ? `${base} · ${staleCount} stale` : base;
221
+ }
222
+ if (staleCount > 0) {
223
+ return `${staleCount} stale summar${staleCount === 1 ? "y needs" : "ies need"} refresh`;
224
+ }
225
+ return `All ${totalCount} node${totalCount === 1 ? "" : "s"} summarized`;
226
+ }
227
+ function buildOwningDuMap(nodes) {
228
+ const byId = new Map(nodes.map((n) => [n.id, n]));
229
+ const result = new Map();
230
+ for (const n of nodes) {
231
+ if (n.entityType === "DEPLOYMENT_UNIT") {
232
+ result.set(n.id, n);
233
+ continue;
234
+ }
235
+ let cur = n;
236
+ let guard = 0;
237
+ while (cur?.parentBoundaryId && guard++ < 8) {
238
+ const parent = byId.get(cur.parentBoundaryId);
239
+ if (!parent)
240
+ break;
241
+ if (parent.entityType === "DEPLOYMENT_UNIT") {
242
+ result.set(n.id, parent);
243
+ break;
244
+ }
245
+ cur = parent;
246
+ }
247
+ }
248
+ return result;
249
+ }
250
+ function aggregateSemanticOverlays(existingOverlays, nodeById, flagStaleDrift = true) {
251
+ const byEntity = new Map();
252
+ for (const ov of existingOverlays) {
253
+ if (ov.layer !== SEMANTIC_OVERLAY_LAYER)
254
+ continue;
255
+ if (ov.source === ENRICH_NODES_PLUGIN_NAME)
256
+ continue;
257
+ const p = ov.payload ?? {};
258
+ const domain = typeof p.domain === "string" && p.domain.trim() ? p.domain.trim() : undefined;
259
+ const humanLabel = typeof p.humanLabel === "string" && p.humanLabel.trim() ? p.humanLabel.trim() : undefined;
260
+ const summary = typeof p.summary === "string" && p.summary.trim() ? p.summary.trim() : undefined;
261
+ const rationale = typeof p.rationale === "string" && p.rationale.trim() ? p.rationale.trim() : undefined;
262
+ if (!domain && !humanLabel && !summary && !rationale)
263
+ continue;
264
+ const node = nodeById.get(ov.entityId);
265
+ const currentBodyHash = typeof node?.metadata?.bodyHash === "string" ? node.metadata.bodyHash : null;
266
+ const drifted = Boolean(ov.bodyHash && currentBodyHash && ov.bodyHash !== currentBodyHash);
267
+ const computedStale = flagStaleDrift && (Boolean(ov.stale) || drifted);
268
+ const staleReason = computedStale
269
+ ? drifted
270
+ ? "bodyHash_drift"
271
+ : "marked_stale"
272
+ : undefined;
273
+ const prev = byEntity.get(ov.entityId);
274
+ if (!prev) {
275
+ byEntity.set(ov.entityId, {
276
+ entityId: ov.entityId,
277
+ ...(domain ? { domain } : {}),
278
+ ...(humanLabel ? { humanLabel } : {}),
279
+ ...(summary ? { summary } : {}),
280
+ ...(rationale ? { rationale } : {}),
281
+ bodyHash: ov.bodyHash ?? null,
282
+ stale: computedStale,
283
+ ...(staleReason ? { staleReason } : {}),
284
+ producerSources: [ov.source],
285
+ updatedAt: ov.updatedAt,
286
+ });
287
+ }
288
+ else {
289
+ if (domain)
290
+ prev.domain = domain;
291
+ if (humanLabel)
292
+ prev.humanLabel = humanLabel;
293
+ if (summary)
294
+ prev.summary = summary;
295
+ if (rationale)
296
+ prev.rationale = rationale;
297
+ if (ov.bodyHash)
298
+ prev.bodyHash = ov.bodyHash;
299
+ if (computedStale) {
300
+ prev.stale = true;
301
+ if (drifted || !prev.staleReason) {
302
+ prev.staleReason = drifted ? "bodyHash_drift" : "marked_stale";
303
+ }
304
+ }
305
+ if (!prev.producerSources.includes(ov.source))
306
+ prev.producerSources.push(ov.source);
307
+ if (ov.updatedAt && (!prev.updatedAt || ov.updatedAt > prev.updatedAt)) {
308
+ prev.updatedAt = ov.updatedAt;
309
+ }
310
+ }
311
+ }
312
+ return byEntity;
313
+ }
314
+ function buildEnrichmentPrompt(params) {
315
+ const { scopeLabel, pkgKey, enrichedCount, staleCount, unenrichedCount } = params;
316
+ const pkgArg = pkgKey ? `, packageName: "${pkgKey}"` : "";
317
+ if (enrichedCount === 0 && unenrichedCount > 0) {
318
+ return {
319
+ label: "Copy agent prompt",
320
+ text: `Enrich the ${unenrichedCount} un-enriched node${unenrichedCount === 1 ? "" : "s"} in ${scopeLabel}: call \`chomp_enrich_nodes\` (action: "queue"${pkgArg}) to get prioritized nodes with inline code context, save batches with \`defer_refresh: true\`, then finish with \`action: "refresh"\`.`,
321
+ hint: "Generate plain-English names and summaries.",
322
+ };
323
+ }
324
+ if (staleCount > 0 && unenrichedCount === 0) {
325
+ return {
326
+ label: "Copy refresh prompt",
327
+ text: `Refresh ${staleCount} stale node enrichment${staleCount === 1 ? "" : "s"} in ${scopeLabel}: call \`chomp_enrich_nodes\` (action: "queue", status: "stale"${pkgArg}) to compare changed code against previous labels, then update via \`chomp_enrich_nodes\`.`,
328
+ hint: "Refresh summaries for modified nodes.",
329
+ };
330
+ }
331
+ if (unenrichedCount > 0) {
332
+ return {
333
+ label: "Copy agent prompt",
334
+ text: `Enrich ${unenrichedCount} un-enriched node${unenrichedCount === 1 ? "" : "s"}${staleCount > 0 ? ` and refresh ${staleCount} stale node${staleCount === 1 ? "" : "s"}` : ""} in ${scopeLabel}: call \`chomp_enrich_nodes\` (action: "queue"${pkgArg}) and save updates via \`chomp_enrich_nodes\` (use \`defer_refresh: true\`, then \`action: "refresh"\`).`,
335
+ hint: "Name and summarize remaining nodes.",
336
+ };
337
+ }
338
+ return {
339
+ label: "Copy refresh prompt",
340
+ text: `Review node enrichments in ${scopeLabel} via \`chomp_enrich_nodes\` (action: "status"${pkgArg}) and refine any labels or summaries with \`chomp_enrich_nodes\`.`,
341
+ hint: "Refine existing node names and summaries.",
342
+ };
343
+ }
344
+ const INGRESS_PRIORITY_TYPES = new Set([
345
+ "CLASS",
346
+ "NEXTJS_PAGE",
347
+ "NEXTJS_LAYOUT",
348
+ "HTTP_ENDPOINT",
349
+ "CLI_COMMAND",
350
+ "MCP_TOOL",
351
+ "GRAPHQL_RESOLVER",
352
+ "TRPC_PROCEDURE",
353
+ ]);
354
+ function computeEnrichmentPriority(node, degreeByNodeId) {
355
+ if (INGRESS_PRIORITY_TYPES.has(node.entityType) ||
356
+ node.metadata?.flowRole === "INGRESS") {
357
+ return 1;
358
+ }
359
+ if (node.entityType === "EXPORTED_TYPE") {
360
+ return 4;
361
+ }
362
+ if ((degreeByNodeId.get(node.id) ?? 0) >= 2) {
363
+ return 2;
364
+ }
365
+ return 3;
366
+ }
367
+ export function isEnrichmentTargetNode(node, includeExportedTypes = true) {
368
+ if ((node.scope ?? "USER") !== "USER")
369
+ return false;
370
+ if (!(node.type === "CONTRACT" || node.entityType === "CLASS"))
371
+ return false;
372
+ if (node.entityType === "DEPLOYMENT_UNIT")
373
+ return false;
374
+ if (!includeExportedTypes && node.entityType === "EXPORTED_TYPE")
375
+ return false;
376
+ return true;
377
+ }
378
+ export function classifySemanticOverlayMap(graph, existingOverlays, flagStaleDrift = true) {
379
+ const nodeById = new Map(graph.nodes.map((n) => [n.id, n]));
380
+ return aggregateSemanticOverlays(existingOverlays, nodeById, flagStaleDrift);
381
+ }
382
+ function cleanJsDocSummary(commentLines) {
383
+ const cleaned = commentLines
384
+ .map((line) => line
385
+ .replace(/^\s*\/\*\*?/, "")
386
+ .replace(/\*\/\s*$/, "")
387
+ .replace(/^\s*\*\s?/, "")
388
+ .trim())
389
+ .filter((line) => line.length > 0);
390
+ const proseLines = [];
391
+ for (const line of cleaned) {
392
+ if (line.startsWith("@"))
393
+ break;
394
+ proseLines.push(line);
395
+ }
396
+ const joined = proseLines.join(" ").replace(/\s+/g, " ").trim();
397
+ if (!joined)
398
+ return undefined;
399
+ const firstSentenceMatch = joined.match(/^(.+?[.!?])(?:\s|$)/);
400
+ const summary = firstSentenceMatch ? firstSentenceMatch[1] : joined;
401
+ return summary.length > 240 ? `${summary.slice(0, 237)}...` : summary;
402
+ }
403
+ export function extractNodeCodeContext(repoPath, filePath, lineNumber, contextLines = 18, fileLinesCache) {
404
+ if (!repoPath || !filePath || !lineNumber || lineNumber < 1)
405
+ return {};
406
+ const absRoot = resolve(repoPath);
407
+ const absFile = resolve(absRoot, filePath);
408
+ if (absFile !== absRoot && !absFile.startsWith(`${absRoot}/`) && !absFile.startsWith(`${absRoot}\\`)) {
409
+ return {};
410
+ }
411
+ let lines = fileLinesCache?.get(absFile);
412
+ if (lines === undefined) {
413
+ if (!existsSync(absFile)) {
414
+ fileLinesCache?.set(absFile, null);
415
+ return {};
416
+ }
417
+ try {
418
+ lines = readFileSync(absFile, "utf8").split(/\r?\n/);
419
+ fileLinesCache?.set(absFile, lines);
420
+ }
421
+ catch {
422
+ fileLinesCache?.set(absFile, null);
423
+ return {};
424
+ }
425
+ }
426
+ if (!lines || lines.length === 0)
427
+ return {};
428
+ const zeroIdx = Math.min(Math.max(0, lineNumber - 1), lines.length - 1);
429
+ let scanIdx = zeroIdx - 1;
430
+ let skippedDecorators = 0;
431
+ while (scanIdx >= 0 && skippedDecorators < 4) {
432
+ const trimmed = lines[scanIdx].trim();
433
+ if (trimmed === "" || trimmed.startsWith("@")) {
434
+ scanIdx--;
435
+ skippedDecorators++;
436
+ continue;
437
+ }
438
+ break;
439
+ }
440
+ let jsdocSummary;
441
+ let commentStartIdx = null;
442
+ if (scanIdx >= 0 && lines[scanIdx].trim().endsWith("*/")) {
443
+ const endIdx = scanIdx;
444
+ let cur = scanIdx;
445
+ while (cur >= 0 && endIdx - cur <= 25) {
446
+ const t = lines[cur].trim();
447
+ if (t.startsWith("/**")) {
448
+ commentStartIdx = cur;
449
+ jsdocSummary = cleanJsDocSummary(lines.slice(cur, endIdx + 1));
450
+ break;
451
+ }
452
+ if (t.startsWith("/*")) {
453
+ break;
454
+ }
455
+ cur--;
456
+ }
457
+ }
458
+ const clampedCtx = Math.max(1, Math.min(60, contextLines));
459
+ const sliceStart = commentStartIdx !== null ? commentStartIdx : zeroIdx;
460
+ const sliceEnd = Math.min(lines.length, zeroIdx + clampedCtx);
461
+ let codeContext = lines.slice(sliceStart, sliceEnd).join("\n");
462
+ if (codeContext.length > 2400) {
463
+ codeContext = `${codeContext.slice(0, 2397)}...`;
464
+ }
465
+ return {
466
+ ...(jsdocSummary ? { jsdocSummary } : {}),
467
+ ...(codeContext ? { codeContext } : {}),
468
+ };
469
+ }
470
+ function resolveBucketsAndTargets(params) {
471
+ const { graph, existingOverlays, flagStaleDrift, includeExportedTypes } = params;
472
+ const nodeById = new Map(graph.nodes.map((n) => [n.id, n]));
473
+ const owningDuByNodeId = buildOwningDuMap(graph.nodes);
474
+ const enrichedByNodeId = aggregateSemanticOverlays(existingOverlays, nodeById, flagStaleDrift);
475
+ const deploymentUnits = graph.nodes.filter((n) => n.entityType === "DEPLOYMENT_UNIT" && (n.scope ?? "USER") === "USER");
476
+ const duEntries = deploymentUnits.map((du) => {
477
+ const pkgLabel = stripNodePrefix(du.name);
478
+ return { du, pkgLabel, pkgKey: pkgLabel.replace(/^@[^/]+\//, "") };
479
+ });
480
+ if (duEntries.length === 0) {
481
+ duEntries.push({ du: null, pkgLabel: "root", pkgKey: "root" });
482
+ }
483
+ const targetBuckets = duEntries.map(({ du, pkgLabel, pkgKey }) => {
484
+ const targetNodes = graph.nodes.filter((n) => {
485
+ if (!isEnrichmentTargetNode(n, includeExportedTypes))
486
+ return false;
487
+ if (du)
488
+ return owningDuByNodeId.get(n.id)?.id === du.id;
489
+ return !owningDuByNodeId.has(n.id);
490
+ });
491
+ const enrichedNodes = [];
492
+ const unenrichedNodes = [];
493
+ for (const n of targetNodes) {
494
+ const sem = enrichedByNodeId.get(n.id);
495
+ if (sem)
496
+ enrichedNodes.push({ node: n, sem });
497
+ else
498
+ unenrichedNodes.push(n);
499
+ }
500
+ const staleNodes = enrichedNodes.filter((e) => e.sem.stale);
501
+ return {
502
+ du,
503
+ pkgLabel,
504
+ pkgKey,
505
+ totalCount: targetNodes.length,
506
+ enrichedNodes,
507
+ unenrichedNodes,
508
+ staleNodes,
509
+ };
510
+ });
511
+ const domainCounts = new Map();
512
+ for (const sem of enrichedByNodeId.values()) {
513
+ if (sem.domain) {
514
+ domainCounts.set(sem.domain, (domainCounts.get(sem.domain) ?? 0) + 1);
515
+ }
516
+ }
517
+ const existingDomains = [...domainCounts.entries()]
518
+ .map(([domain, count]) => ({ domain, count }))
519
+ .sort((a, b) => b.count - a.count || a.domain.localeCompare(b.domain));
520
+ return { nodeById, owningDuByNodeId, enrichedByNodeId, targetBuckets, existingDomains };
521
+ }
522
+ export function buildEnrichmentStatus(params) {
523
+ const flagStaleDrift = params.settings?.flagStaleDrift !== false;
524
+ const includeExportedTypes = params.settings?.includeExportedTypes !== false;
525
+ const { targetBuckets, existingDomains } = resolveBucketsAndTargets({
526
+ graph: params.graph,
527
+ existingOverlays: params.existingOverlays,
528
+ flagStaleDrift,
529
+ includeExportedTypes,
530
+ });
531
+ const pkgFilter = params.packageName?.trim();
532
+ const filteredBuckets = pkgFilter
533
+ ? targetBuckets.filter((b) => packageMatchesFilter(b.pkgLabel, b.du ? getPrimaryEvidenceRecord(b.du).filePath : undefined, pkgFilter))
534
+ : targetBuckets;
535
+ let totalContracts = 0;
536
+ let enrichedContracts = 0;
537
+ let unenrichedContracts = 0;
538
+ let staleContracts = 0;
539
+ const packages = filteredBuckets.map((b) => {
540
+ totalContracts += b.totalCount;
541
+ enrichedContracts += b.enrichedNodes.length;
542
+ unenrichedContracts += b.unenrichedNodes.length;
543
+ staleContracts += b.staleNodes.length;
544
+ return {
545
+ packageLabel: b.pkgLabel,
546
+ packageKey: b.pkgKey,
547
+ totalContracts: b.totalCount,
548
+ enrichedContracts: b.enrichedNodes.length,
549
+ unenrichedContracts: b.unenrichedNodes.length,
550
+ staleContracts: b.staleNodes.length,
551
+ coveragePct: b.totalCount > 0 ? Math.round((b.enrichedNodes.length / b.totalCount) * 100) : null,
552
+ };
553
+ });
554
+ const sidecarExists = params.repoPath
555
+ ? existsSync(resolve(params.repoPath, SEMANTIC_SIDECAR_FILE_REL))
556
+ : false;
557
+ return {
558
+ action: "status",
559
+ totalContracts,
560
+ enrichedContracts,
561
+ unenrichedContracts,
562
+ staleContracts,
563
+ coveragePct: totalContracts > 0 ? Math.round((enrichedContracts / totalContracts) * 100) : null,
564
+ includeExportedTypes,
565
+ sidecarPath: SEMANTIC_SIDECAR_FILE_REL,
566
+ sidecarExists,
567
+ domains: existingDomains,
568
+ packages,
569
+ };
570
+ }
571
+ export function buildEnrichmentQueue(params) {
572
+ const flagStaleDrift = params.settings?.flagStaleDrift !== false;
573
+ const includeExportedTypes = params.includeTypes ?? (params.settings?.includeExportedTypes !== false);
574
+ const statusFilter = params.status ?? "needs_enrichment";
575
+ const limit = Math.max(1, Math.min(100, params.limit ?? 40));
576
+ const cursor = Math.max(0, params.cursor ?? 0);
577
+ const includeContext = params.includeContext !== false;
578
+ const contextLines = params.contextLines ?? 18;
579
+ const { nodeById, targetBuckets, existingDomains } = resolveBucketsAndTargets({
580
+ graph: params.graph,
581
+ existingOverlays: params.existingOverlays,
582
+ flagStaleDrift,
583
+ includeExportedTypes,
584
+ });
585
+ const degreeByNodeId = new Map();
586
+ for (const e of params.graph.edges) {
587
+ degreeByNodeId.set(e.sourceId, (degreeByNodeId.get(e.sourceId) ?? 0) + 1);
588
+ if (e.targetId) {
589
+ degreeByNodeId.set(e.targetId, (degreeByNodeId.get(e.targetId) ?? 0) + 1);
590
+ }
591
+ }
592
+ const pkgFilter = params.packageName?.trim();
593
+ const matchingBuckets = pkgFilter
594
+ ? targetBuckets.filter((b) => packageMatchesFilter(b.pkgLabel, b.du ? getPrimaryEvidenceRecord(b.du).filePath : undefined, pkgFilter))
595
+ : targetBuckets;
596
+ const candidates = [];
597
+ const byPackage = {};
598
+ for (const b of matchingBuckets) {
599
+ const pkgStats = { totalMatching: 0, unenriched: 0, stale: 0 };
600
+ if (statusFilter === "needs_enrichment" ||
601
+ statusFilter === "unenriched" ||
602
+ statusFilter === "all") {
603
+ for (const n of b.unenrichedNodes) {
604
+ const ev = getPrimaryEvidenceRecord(n);
605
+ pkgStats.totalMatching++;
606
+ pkgStats.unenriched++;
607
+ candidates.push({
608
+ node: n,
609
+ pkgKey: b.pkgKey,
610
+ priority: computeEnrichmentPriority(n, degreeByNodeId),
611
+ filePath: ev.filePath,
612
+ lineNumber: ev.lineNumber,
613
+ isStale: false,
614
+ });
615
+ }
616
+ }
617
+ if (statusFilter === "needs_enrichment" ||
618
+ statusFilter === "stale" ||
619
+ statusFilter === "all") {
620
+ const list = statusFilter === "all" ? b.enrichedNodes : b.staleNodes;
621
+ for (const { node, sem } of list) {
622
+ const ev = getPrimaryEvidenceRecord(node);
623
+ pkgStats.totalMatching++;
624
+ if (sem.stale)
625
+ pkgStats.stale++;
626
+ candidates.push({
627
+ node,
628
+ pkgKey: b.pkgKey,
629
+ priority: computeEnrichmentPriority(node, degreeByNodeId),
630
+ filePath: ev.filePath,
631
+ lineNumber: ev.lineNumber,
632
+ sem,
633
+ isStale: sem.stale,
634
+ });
635
+ }
636
+ }
637
+ if (pkgStats.totalMatching > 0) {
638
+ byPackage[b.pkgKey] = pkgStats;
639
+ }
640
+ }
641
+ candidates.sort((a, b) => a.priority - b.priority ||
642
+ a.pkgKey.localeCompare(b.pkgKey) ||
643
+ (a.filePath ?? "").localeCompare(b.filePath ?? "") ||
644
+ (a.lineNumber ?? 0) - (b.lineNumber ?? 0) ||
645
+ a.node.id.localeCompare(b.node.id));
646
+ const page = candidates.slice(cursor, cursor + limit);
647
+ const nextCursor = cursor + page.length < candidates.length ? cursor + page.length : null;
648
+ const fileLinesCache = new Map();
649
+ const items = page.map((c) => {
650
+ const parent = c.node.parentBoundaryId ? nodeById.get(c.node.parentBoundaryId) : undefined;
651
+ const parentBoundaryName = parent && (parent.entityType === "CLASS" || parent.entityType === "NAMESPACE")
652
+ ? parent.name
653
+ : undefined;
654
+ const pv = c.node.metadata?.portValves;
655
+ const signature = pv
656
+ ? {
657
+ ...(Array.isArray(pv.inputs) && pv.inputs.length > 0
658
+ ? {
659
+ inputs: pv.inputs.slice(0, 6).map((inp) => ({
660
+ name: inp.name,
661
+ ...(inp.type ? { type: inp.type } : {}),
662
+ })),
663
+ }
664
+ : {}),
665
+ ...(pv.outputType || pv.output?.type
666
+ ? { outputType: pv.outputType ?? pv.output?.type }
667
+ : {}),
668
+ }
669
+ : undefined;
670
+ const ctxSnippet = includeContext
671
+ ? extractNodeCodeContext(params.repoPath, c.filePath, c.lineNumber, contextLines, fileLinesCache)
672
+ : {};
673
+ return {
674
+ nodeId: c.node.id,
675
+ packageKey: c.pkgKey,
676
+ name: c.node.name,
677
+ entityType: c.node.entityType,
678
+ priority: c.priority,
679
+ ...(c.filePath ? { filePath: c.filePath } : {}),
680
+ ...(c.lineNumber !== undefined ? { lineNumber: c.lineNumber } : {}),
681
+ ...(parentBoundaryName ? { parentBoundaryName } : {}),
682
+ ...(signature && (signature.inputs || signature.outputType) ? { signature } : {}),
683
+ isStale: c.isStale,
684
+ ...(c.sem?.staleReason ? { staleReason: c.sem.staleReason } : {}),
685
+ ...(c.sem
686
+ ? {
687
+ previousEnrichment: {
688
+ ...(c.sem.domain ? { domain: c.sem.domain } : {}),
689
+ ...(c.sem.humanLabel ? { humanLabel: c.sem.humanLabel } : {}),
690
+ ...(c.sem.summary ? { summary: c.sem.summary } : {}),
691
+ ...(c.sem.rationale ? { rationale: c.sem.rationale } : {}),
692
+ },
693
+ }
694
+ : {}),
695
+ ...ctxSnippet,
696
+ };
697
+ });
698
+ return {
699
+ action: "queue",
700
+ statusFilter,
701
+ totalMatching: candidates.length,
702
+ returnedCount: items.length,
703
+ cursor,
704
+ nextCursor,
705
+ existingDomains,
706
+ byPackage,
707
+ items,
708
+ };
709
+ }
710
+ export const enrichNodesPlugin = {
711
+ name: ENRICH_NODES_PLUGIN_NAME,
712
+ displayName: "Summaries",
713
+ version: "1.0.0",
714
+ order: 20,
715
+ layer: SEMANTIC_OVERLAY_LAYER,
716
+ inspectorScopes: ["package"],
717
+ description: ENRICH_HUD_DESCRIPTION,
718
+ accepts: (filePath) => filePath === SEMANTIC_SIDECAR_FILE_REL,
719
+ extract: (ctx) => {
720
+ const flagStaleDrift = ctx.settings.flagStaleDrift !== false;
721
+ const hideHudWhenEnriched = ctx.settings.hideHudWhenEnriched === true;
722
+ const includeExportedTypes = ctx.settings.includeExportedTypes !== false;
723
+ const persistSidecar = ctx.settings.persistSidecar !== false;
724
+ const nodeById = new Map(ctx.graph.nodes.map((n) => [n.id, n]));
725
+ const existingDbSemantic = aggregateSemanticOverlays(ctx.existingOverlays, nodeById, flagStaleDrift);
726
+ const hydratedOverlays = [];
727
+ const effectiveExistingOverlays = [...ctx.existingOverlays];
728
+ if (persistSidecar) {
729
+ const sidecarText = ctx.readPluginFile(SEMANTIC_SIDECAR_FILENAME);
730
+ if (sidecarText) {
731
+ const sidecar = parseSemanticSidecar(sidecarText);
732
+ for (const [entityId, entry] of Object.entries(sidecar.nodes)) {
733
+ if (!nodeById.has(entityId))
734
+ continue;
735
+ if (existingDbSemantic.has(entityId))
736
+ continue;
737
+ const payload = {
738
+ ...(entry.domain ? { domain: entry.domain } : {}),
739
+ ...(entry.humanLabel ? { humanLabel: entry.humanLabel } : {}),
740
+ ...(entry.summary ? { summary: entry.summary } : {}),
741
+ ...(entry.rationale ? { rationale: entry.rationale } : {}),
742
+ };
743
+ if (Object.keys(payload).length === 0)
744
+ continue;
745
+ hydratedOverlays.push({
746
+ entityId,
747
+ layer: SEMANTIC_OVERLAY_LAYER,
748
+ source: SEMANTIC_PRODUCER_SOURCE,
749
+ environment: ctx.environment,
750
+ derivation: "AI_HYPOTHESIS",
751
+ ...(entry.bodyHash !== undefined ? { bodyHash: entry.bodyHash } : {}),
752
+ payload,
753
+ merge: true,
754
+ pruneStaleBySource: false,
755
+ });
756
+ effectiveExistingOverlays.push({
757
+ repositoryId: ctx.repoId,
758
+ entityId,
759
+ layer: SEMANTIC_OVERLAY_LAYER,
760
+ source: SEMANTIC_PRODUCER_SOURCE,
761
+ environment: ctx.environment,
762
+ payload,
763
+ bodyHash: entry.bodyHash ?? null,
764
+ derivation: "AI_HYPOTHESIS",
765
+ runId: null,
766
+ updatedAt: entry.updatedAt ?? new Date().toISOString(),
767
+ stale: false,
768
+ });
769
+ }
770
+ }
771
+ }
772
+ const { targetBuckets } = resolveBucketsAndTargets({
773
+ graph: ctx.graph,
774
+ existingOverlays: effectiveExistingOverlays,
775
+ flagStaleDrift,
776
+ includeExportedTypes,
777
+ });
778
+ const buckets = targetBuckets.filter((b) => Boolean(b.du));
779
+ let repoTargetCount = 0;
780
+ let repoEnrichedCount = 0;
781
+ let repoUnenrichedCount = 0;
782
+ let repoStaleCount = 0;
783
+ for (const bucket of buckets) {
784
+ repoTargetCount += bucket.totalCount;
785
+ repoEnrichedCount += bucket.enrichedNodes.length;
786
+ repoUnenrichedCount += bucket.unenrichedNodes.length;
787
+ repoStaleCount += bucket.staleNodes.length;
788
+ }
789
+ const repoHeadline = formatEnrichHeadline(repoEnrichedCount, repoUnenrichedCount, repoStaleCount, repoTargetCount);
790
+ const repoPrompt = repoTargetCount > 0
791
+ ? buildEnrichmentPrompt({
792
+ scopeLabel: `repository "${ctx.repoName}"`,
793
+ enrichedCount: repoEnrichedCount,
794
+ staleCount: repoStaleCount,
795
+ unenrichedCount: repoUnenrichedCount,
796
+ })
797
+ : undefined;
798
+ const overlays = [...hydratedOverlays];
799
+ for (const bucket of buckets) {
800
+ const { du, pkgLabel, pkgKey, totalCount, enrichedNodes, unenrichedNodes, staleNodes, } = bucket;
801
+ const enrichedCount = enrichedNodes.length;
802
+ const unenrichedCount = unenrichedNodes.length;
803
+ const staleCount = staleNodes.length;
804
+ const coveragePct = totalCount > 0 ? Math.round((enrichedCount / totalCount) * 100) : null;
805
+ let status = "ok";
806
+ let badgeText = "0 nodes";
807
+ let badgeTone = "muted";
808
+ if (totalCount === 0) {
809
+ status = "n/a";
810
+ badgeText = "N/A";
811
+ badgeTone = "muted";
812
+ }
813
+ else if (unenrichedCount > 0 || staleCount > 0) {
814
+ status = "warn";
815
+ badgeText =
816
+ staleCount > 0
817
+ ? `${unenrichedCount} missing · ${staleCount} stale`
818
+ : `${unenrichedCount} missing`;
819
+ badgeTone = "warn";
820
+ }
821
+ else {
822
+ status = "ok";
823
+ badgeText = `${coveragePct}% summarized`;
824
+ badgeTone = "good";
825
+ }
826
+ const headline = formatEnrichHeadline(enrichedCount, unenrichedCount, staleCount, totalCount);
827
+ const { items: unenrichedItems, totalCount: totalUnenrichedItems } = capForPresentation(unenrichedNodes.map((n) => ({
828
+ label: stripNodePrefix(n.name),
829
+ detail: "Missing summary",
830
+ tone: "neutral",
831
+ entityId: n.id,
832
+ })), 30);
833
+ const { items: minimalEnrichedItems, totalCount: totalEnrichedItems } = capForPresentation(enrichedNodes.map(({ node, sem }) => ({
834
+ label: sem.humanLabel ?? stripNodePrefix(node.name),
835
+ entityId: node.id,
836
+ })), 20);
837
+ const { items: staleItems, totalCount: totalStaleItems } = capForPresentation(staleNodes.map(({ node, sem }) => ({
838
+ label: sem.humanLabel ?? stripNodePrefix(node.name),
839
+ detail: formatStaleDetail(sem),
840
+ tone: "warn",
841
+ entityId: node.id,
842
+ })), 30);
843
+ const sections = [
844
+ {
845
+ id: "enrichment-overview",
846
+ title: "Summary coverage",
847
+ priority: 10,
848
+ blocks: [
849
+ {
850
+ kind: "metrics",
851
+ items: [
852
+ {
853
+ id: "semantic-coverage",
854
+ label: "Coverage",
855
+ value: coveragePct,
856
+ unit: "%",
857
+ tone: coveragePct === null
858
+ ? "muted"
859
+ : coveragePct === 100
860
+ ? "good"
861
+ : coveragePct > 0
862
+ ? "info"
863
+ : "warn",
864
+ hint: "Share of nodes in this package with plain-English names and summaries.",
865
+ items: unenrichedItems,
866
+ maxVisible: 6,
867
+ totalCount: totalUnenrichedItems,
868
+ emptyText: totalCount === 0
869
+ ? "No nodes in this package."
870
+ : "All nodes in this package are summarized.",
871
+ },
872
+ {
873
+ id: "enriched-count",
874
+ label: "Summarized",
875
+ value: enrichedCount,
876
+ unit: "count",
877
+ tone: enrichedCount > 0 ? "good" : "neutral",
878
+ hint: "Nodes with plain-English names and summaries.",
879
+ items: minimalEnrichedItems,
880
+ maxVisible: 5,
881
+ totalCount: totalEnrichedItems,
882
+ emptyText: "No nodes summarized yet.",
883
+ },
884
+ {
885
+ id: "stale-count",
886
+ label: "Stale",
887
+ value: staleCount,
888
+ unit: "count",
889
+ tone: staleCount > 0 ? "warn" : "good",
890
+ hint: "Nodes modified since their summary was generated.",
891
+ items: staleItems,
892
+ maxVisible: 6,
893
+ totalCount: totalStaleItems,
894
+ emptyText: "No stale summaries.",
895
+ },
896
+ ],
897
+ },
898
+ ],
899
+ },
900
+ ];
901
+ const promptAction = totalCount > 0
902
+ ? buildEnrichmentPrompt({
903
+ scopeLabel: `package "${pkgLabel}"`,
904
+ pkgKey,
905
+ enrichedCount,
906
+ staleCount,
907
+ unenrichedCount,
908
+ })
909
+ : undefined;
910
+ const pkgPresentation = {
911
+ version: PLUGIN_PRESENTATION_VERSION,
912
+ summary: {
913
+ status,
914
+ badge: { text: badgeText, tone: badgeTone },
915
+ headline,
916
+ repoHeadline,
917
+ description: ENRICH_HUD_DESCRIPTION,
918
+ issueCount: staleCount,
919
+ ...(promptAction ? { prompt: promptAction } : {}),
920
+ ...(repoPrompt ? { repoPrompt } : {}),
921
+ ...(hideHudWhenEnriched &&
922
+ totalCount > 0 &&
923
+ unenrichedCount === 0 &&
924
+ staleCount === 0
925
+ ? { hideInHud: true }
926
+ : {}),
927
+ },
928
+ sections,
929
+ };
930
+ overlays.push({
931
+ entityId: du.id,
932
+ layer: SEMANTIC_OVERLAY_LAYER,
933
+ source: ENRICH_NODES_PLUGIN_NAME,
934
+ derivation: "EXTRACTED",
935
+ payload: {
936
+ packageLabel: pkgLabel,
937
+ packageKey: pkgKey,
938
+ totalContracts: totalCount,
939
+ enrichedContracts: enrichedCount,
940
+ unenrichedContracts: unenrichedCount,
941
+ staleContracts: staleCount,
942
+ [PLUGIN_PRESENTATION_PAYLOAD_KEY]: pkgPresentation,
943
+ },
944
+ });
945
+ }
946
+ return {
947
+ overlays,
948
+ summary: {
949
+ totalContracts: repoTargetCount,
950
+ enrichedContracts: repoEnrichedCount,
951
+ unenrichedContracts: repoUnenrichedCount,
952
+ staleContracts: repoStaleCount,
953
+ coveragePct: repoTargetCount > 0 ? Math.round((repoEnrichedCount / repoTargetCount) * 100) : null,
954
+ },
955
+ };
956
+ },
957
+ };