@agent-wiki/mcp 0.21.1 → 0.21.4
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/atlassian.d.ts +23 -0
- package/dist/atlassian.d.ts.map +1 -1
- package/dist/atlassian.js +92 -1
- package/dist/atlassian.js.map +1 -1
- package/dist/atlassian.test.d.ts +7 -0
- package/dist/atlassian.test.d.ts.map +1 -0
- package/dist/atlassian.test.js +220 -0
- package/dist/atlassian.test.js.map +1 -0
- package/dist/cobol/__tests__/field-lineage.test.js +525 -1
- package/dist/cobol/__tests__/field-lineage.test.js.map +1 -1
- package/dist/cobol/__tests__/parser.test.js +32 -0
- package/dist/cobol/__tests__/parser.test.js.map +1 -1
- package/dist/cobol/evidence-mapping.d.ts +1 -1
- package/dist/cobol/evidence-mapping.d.ts.map +1 -1
- package/dist/cobol/evidence-mapping.js +1 -0
- package/dist/cobol/evidence-mapping.js.map +1 -1
- package/dist/cobol/field-lineage.d.ts +53 -2
- package/dist/cobol/field-lineage.d.ts.map +1 -1
- package/dist/cobol/field-lineage.js +339 -16
- package/dist/cobol/field-lineage.js.map +1 -1
- package/dist/cobol/parser.d.ts.map +1 -1
- package/dist/cobol/parser.js +7 -0
- package/dist/cobol/parser.js.map +1 -1
- package/dist/evidence-report.d.ts +10 -0
- package/dist/evidence-report.d.ts.map +1 -1
- package/dist/evidence-report.js +23 -1
- package/dist/evidence-report.js.map +1 -1
- package/dist/evidence-report.test.js +32 -0
- package/dist/evidence-report.test.js.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +4 -1
- package/dist/server.js.map +1 -1
- package/docs/evidence-envelope.md +61 -2
- package/docs/tools.md +67 -1
- package/package.json +1 -1
|
@@ -1,14 +1,49 @@
|
|
|
1
1
|
import { resolveCanonicalId, displayLabel, normalizeCopybookName } from "./graph.js";
|
|
2
|
+
function emptyDiagnosticsByKind() {
|
|
3
|
+
return { "parsed-zero-data-items": 0 };
|
|
4
|
+
}
|
|
5
|
+
function countDiagnosticsByKind(diagnostics) {
|
|
6
|
+
const counts = emptyDiagnosticsByKind();
|
|
7
|
+
for (const d of diagnostics)
|
|
8
|
+
counts[d.kind]++;
|
|
9
|
+
return counts;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Fill in field-lineage fields that older on-disk artifacts (pre-#30) don't
|
|
13
|
+
* carry. Loaders should run any JSON parsed from `field-lineage.json` through
|
|
14
|
+
* this before treating it as a `SerializedFieldLineage` — the interface
|
|
15
|
+
* declares the new fields non-optional, so a raw cast would silently lie.
|
|
16
|
+
*/
|
|
17
|
+
export function normalizeLoadedFieldLineage(raw) {
|
|
18
|
+
const summary = raw.summary;
|
|
19
|
+
return {
|
|
20
|
+
...raw,
|
|
21
|
+
summary: {
|
|
22
|
+
...summary,
|
|
23
|
+
inferred: {
|
|
24
|
+
...summary.inferred,
|
|
25
|
+
// #35 — pre-#35 artifacts predate the semantic tier; backfill to 0.
|
|
26
|
+
semantic: summary.inferred?.semantic ?? 0,
|
|
27
|
+
},
|
|
28
|
+
diagnosticsByKind: summary.diagnosticsByKind ?? emptyDiagnosticsByKind(),
|
|
29
|
+
},
|
|
30
|
+
diagnostics: raw.diagnostics ?? [],
|
|
31
|
+
inferredSemantic: raw.inferredSemantic ?? [],
|
|
32
|
+
};
|
|
33
|
+
}
|
|
2
34
|
function emptyCopybookLineage() {
|
|
3
35
|
return {
|
|
4
36
|
summary: {
|
|
5
37
|
deterministic: { copybooks: 0, programs: 0, fields: 0 },
|
|
6
|
-
inferred: { copybooks: 0, programs: 0, highConfidence: 0, ambiguous: 0 },
|
|
38
|
+
inferred: { copybooks: 0, programs: 0, highConfidence: 0, ambiguous: 0, semantic: 0 },
|
|
39
|
+
diagnosticsByKind: emptyDiagnosticsByKind(),
|
|
7
40
|
},
|
|
8
41
|
copybookUsage: [],
|
|
9
42
|
deterministic: [],
|
|
10
43
|
inferredHighConfidence: [],
|
|
11
44
|
inferredAmbiguous: [],
|
|
45
|
+
inferredSemantic: [],
|
|
46
|
+
diagnostics: [],
|
|
12
47
|
};
|
|
13
48
|
}
|
|
14
49
|
export function combineFieldLineage(copybookLineage, attachments = {}) {
|
|
@@ -142,8 +177,18 @@ function buildInferredEntry(candidate, confidence, competingMatches) {
|
|
|
142
177
|
...candidate.evidence,
|
|
143
178
|
competingMatches,
|
|
144
179
|
};
|
|
180
|
+
// For semantic entries the two fields have intentionally different names —
|
|
181
|
+
// start the rationale with the rename pair so a human reviewer sees the gap
|
|
182
|
+
// up front, instead of the misleading "Same field name" prefix that's
|
|
183
|
+
// accurate for the name-keyed tiers. Participant carries the qualified
|
|
184
|
+
// path; the leaf segment is the field name.
|
|
185
|
+
const leftLeaf = ordered.left.qualifiedName.split(".").pop() ?? "";
|
|
186
|
+
const rightLeaf = ordered.right.qualifiedName.split(".").pop() ?? "";
|
|
187
|
+
const namePart = confidence === "semantic"
|
|
188
|
+
? `Renamed field (${leftLeaf} ↔ ${rightLeaf})`
|
|
189
|
+
: "Same field name";
|
|
145
190
|
const rationaleParts = [
|
|
146
|
-
|
|
191
|
+
namePart,
|
|
147
192
|
evidence.pictureMatch ? "matching PIC" : undefined,
|
|
148
193
|
evidence.usageEvidence === "explicit-match" ? "matching USAGE" : undefined,
|
|
149
194
|
evidence.levelMatch ? `same level ${ordered.left.level}` : undefined,
|
|
@@ -208,8 +253,54 @@ function formatHostVars(hostVars) {
|
|
|
208
253
|
export function buildFieldLineage(models) {
|
|
209
254
|
const parsedCopybooks = models.filter((model) => isCopybook(model.sourceFile));
|
|
210
255
|
const parsedPrograms = models.filter((model) => !isCopybook(model.sourceFile));
|
|
211
|
-
|
|
212
|
-
|
|
256
|
+
// Flatten every copybook once; reused for the zero-data-items diagnostic,
|
|
257
|
+
// `fieldCount` in `rawCopybookUsage`, and the inferred-candidate set below.
|
|
258
|
+
// Includes copybooks that will later be filtered out as duplicates — the
|
|
259
|
+
// dup filter is applied per-consumer, not at the flatten boundary.
|
|
260
|
+
const flattenedByCopybook = new Map();
|
|
261
|
+
for (const copybook of parsedCopybooks) {
|
|
262
|
+
const copybookId = `copybook:${resolveCanonicalId(copybook)}`;
|
|
263
|
+
const rootSiblingNames = copybook.dataItems.map((item) => item.name);
|
|
264
|
+
flattenedByCopybook.set(copybookId, flattenDataItems(copybook.dataItems, copybookId, copybook.sourceFile, [], rootSiblingNames));
|
|
265
|
+
}
|
|
266
|
+
// #30 — surface copybooks whose parsed AST yielded no data items. The
|
|
267
|
+
// canonical case is listing-extracted copybooks where header text at
|
|
268
|
+
// columns other than 7 escapes the comment filter (pre-#28). They were
|
|
269
|
+
// silently dropped from every lineage family because rawCopybookUsage
|
|
270
|
+
// filters by fieldCount; the user couldn't distinguish "no shared usage"
|
|
271
|
+
// from "the copybook itself didn't parse." Only .cpy is diagnosed — a
|
|
272
|
+
// .cbl program with zero WORKING-STORAGE data items is legitimate
|
|
273
|
+
// (PROCEDURE-only / LINKAGE-only programs).
|
|
274
|
+
//
|
|
275
|
+
// Check `copybook.dataItems` directly (per physical file), NOT the
|
|
276
|
+
// `flattenedByCopybook` cache. `resolveCanonicalId` is basename-only, so
|
|
277
|
+
// two .cpy files with the same basename collide in the cache; consulting
|
|
278
|
+
// the cache here would let a non-empty `claims/COMMON.cpy` mask an empty
|
|
279
|
+
// `billing/COMMON.cpy` (or vice-versa), defeating the diagnostic in the
|
|
280
|
+
// exact "messy listing-extracted corpus" shape it targets.
|
|
281
|
+
const diagnostics = [];
|
|
282
|
+
for (const copybook of parsedCopybooks) {
|
|
283
|
+
if (copybook.dataItems.length === 0) {
|
|
284
|
+
diagnostics.push({
|
|
285
|
+
kind: "parsed-zero-data-items",
|
|
286
|
+
sourceFile: copybook.sourceFile,
|
|
287
|
+
isCopybook: true,
|
|
288
|
+
rationale: "Parser produced 0 data items — listing-extracted header, "
|
|
289
|
+
+ "88-level-only fragment, pure COPY chain, or unsupported format.",
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
const withDiagnostics = (base) => ({
|
|
294
|
+
...base,
|
|
295
|
+
summary: {
|
|
296
|
+
...base.summary,
|
|
297
|
+
diagnosticsByKind: countDiagnosticsByKind(diagnostics),
|
|
298
|
+
},
|
|
299
|
+
diagnostics,
|
|
300
|
+
});
|
|
301
|
+
if (parsedCopybooks.length === 0 || parsedPrograms.length === 0) {
|
|
302
|
+
return diagnostics.length > 0 ? withDiagnostics(emptyCopybookLineage()) : null;
|
|
303
|
+
}
|
|
213
304
|
const copybooksByLogicalName = new Map();
|
|
214
305
|
for (const copybook of parsedCopybooks) {
|
|
215
306
|
const logicalName = resolveCanonicalId(copybook);
|
|
@@ -248,17 +339,12 @@ export function buildFieldLineage(models) {
|
|
|
248
339
|
sourceFile: copybook.sourceFile,
|
|
249
340
|
programs: consumers,
|
|
250
341
|
exactPrograms,
|
|
251
|
-
fieldCount:
|
|
342
|
+
fieldCount: flattenedByCopybook.get(copybookId)?.length ?? 0,
|
|
252
343
|
};
|
|
253
344
|
}).filter((entry) => entry.programs.length > 0)
|
|
254
345
|
.sort((a, b) => a.copybookId.localeCompare(b.copybookId));
|
|
255
|
-
if (rawCopybookUsage.length === 0)
|
|
256
|
-
return null;
|
|
257
|
-
const flattenedByCopybook = new Map();
|
|
258
|
-
for (const copybook of parsedCopybooks.filter((entry) => !duplicateLogicalNames.has(resolveCanonicalId(entry)))) {
|
|
259
|
-
const copybookId = `copybook:${resolveCanonicalId(copybook)}`;
|
|
260
|
-
const rootSiblingNames = copybook.dataItems.map((item) => item.name);
|
|
261
|
-
flattenedByCopybook.set(copybookId, flattenDataItems(copybook.dataItems, copybookId, copybook.sourceFile, [], rootSiblingNames));
|
|
346
|
+
if (rawCopybookUsage.length === 0) {
|
|
347
|
+
return diagnostics.length > 0 ? withDiagnostics(emptyCopybookLineage()) : null;
|
|
262
348
|
}
|
|
263
349
|
const deterministic = [];
|
|
264
350
|
for (const usage of rawCopybookUsage) {
|
|
@@ -359,10 +445,95 @@ export function buildFieldLineage(models) {
|
|
|
359
445
|
|| a.left.qualifiedName.localeCompare(b.left.qualifiedName)
|
|
360
446
|
|| compareCopybook(a.right.copybook, b.right.copybook)
|
|
361
447
|
|| a.right.qualifiedName.localeCompare(b.right.qualifiedName));
|
|
448
|
+
// #35 — second pass: shape-keyed matcher for renamed-field detection.
|
|
449
|
+
// Groups candidates by `(PIC, USAGE, level)` instead of field name and
|
|
450
|
+
// emits a pair only when *all five* gates hold:
|
|
451
|
+
// 1. picture match — implicit in the shape-key grouping
|
|
452
|
+
// 2. usage explicit on both sides — `both-missing` doesn't qualify;
|
|
453
|
+
// losing the name signal AND missing USAGE leaves too little
|
|
454
|
+
// 3. parent context exact — top-level / suffix don't qualify
|
|
455
|
+
// 4. ≥ 2 shared siblings — one is too weak without name alignment
|
|
456
|
+
// 5. zero competing matches inside the semantic pool — no
|
|
457
|
+
// `semantic-ambiguous` companion tier in this iteration
|
|
458
|
+
//
|
|
459
|
+
// Pairs whose field names match would already have been emitted by the
|
|
460
|
+
// name-keyed pass; drop them here to avoid double-reporting.
|
|
461
|
+
const semanticCandidateFields = rawCopybookUsage.flatMap((usage) => (flattenedByCopybook.get(usage.copybookId) ?? [])
|
|
462
|
+
.filter((field) => usage.exactPrograms.length > 0)
|
|
463
|
+
.filter((field) => Boolean(field.picture) && Boolean(field.usage))
|
|
464
|
+
.map((field) => ({ field, programs: usage.exactPrograms })));
|
|
465
|
+
const shapeGroups = new Map();
|
|
466
|
+
for (const candidate of semanticCandidateFields) {
|
|
467
|
+
const shapeKey = `${normalizePicture(candidate.field.picture)}|${normalizeUsage(candidate.field.usage)}|${candidate.field.level}`;
|
|
468
|
+
const list = shapeGroups.get(shapeKey) ?? [];
|
|
469
|
+
list.push(candidate);
|
|
470
|
+
shapeGroups.set(shapeKey, list);
|
|
471
|
+
}
|
|
472
|
+
const semanticCandidatesRaw = [];
|
|
473
|
+
for (const [, fields] of shapeGroups.entries()) {
|
|
474
|
+
for (let i = 0; i < fields.length; i++) {
|
|
475
|
+
for (let j = i + 1; j < fields.length; j++) {
|
|
476
|
+
const left = fields[i];
|
|
477
|
+
const right = fields[j];
|
|
478
|
+
if (left.field.copybookId === right.field.copybookId)
|
|
479
|
+
continue;
|
|
480
|
+
if (compareField(left.field, right.field) > 0)
|
|
481
|
+
continue;
|
|
482
|
+
// Name-matched pairs belong to the high / ambiguous tier — exclude
|
|
483
|
+
// them here so they don't double up.
|
|
484
|
+
if (left.field.fieldName.toUpperCase() === right.field.fieldName.toUpperCase())
|
|
485
|
+
continue;
|
|
486
|
+
const parentContextMatch = determineParentContextMatch(left.field, right.field);
|
|
487
|
+
if (parentContextMatch !== "exact")
|
|
488
|
+
continue; // Gate 3
|
|
489
|
+
const siblingOverlap = sortUnique(left.field.siblings.filter((sibling) => right.field.siblings.includes(sibling)));
|
|
490
|
+
if (siblingOverlap.length < 2)
|
|
491
|
+
continue; // Gate 4
|
|
492
|
+
// Gates 1, 2, and level match are guaranteed by the shape-key grouping.
|
|
493
|
+
semanticCandidatesRaw.push({
|
|
494
|
+
fieldName: left.field.fieldName, // display value; left/right names actually differ
|
|
495
|
+
left: left.field,
|
|
496
|
+
right: right.field,
|
|
497
|
+
leftPrograms: left.programs,
|
|
498
|
+
rightPrograms: right.programs,
|
|
499
|
+
evidence: {
|
|
500
|
+
pictureMatch: true,
|
|
501
|
+
usageEvidence: "explicit-match",
|
|
502
|
+
levelMatch: true,
|
|
503
|
+
qualifiedNameMatch: "renamed",
|
|
504
|
+
parentContextMatch,
|
|
505
|
+
siblingOverlap,
|
|
506
|
+
},
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
// Competing-match count is local to the semantic pool — a field that's
|
|
512
|
+
// also in a name-keyed pair doesn't count as "competing" with its
|
|
513
|
+
// semantic peers, and vice-versa.
|
|
514
|
+
const semanticCounts = new Map();
|
|
515
|
+
for (const candidate of semanticCandidatesRaw) {
|
|
516
|
+
semanticCounts.set(inferredCandidateKey(candidate.left), (semanticCounts.get(inferredCandidateKey(candidate.left)) ?? 0) + 1);
|
|
517
|
+
semanticCounts.set(inferredCandidateKey(candidate.right), (semanticCounts.get(inferredCandidateKey(candidate.right)) ?? 0) + 1);
|
|
518
|
+
}
|
|
519
|
+
const inferredSemantic = semanticCandidatesRaw
|
|
520
|
+
.map((candidate) => {
|
|
521
|
+
const competingMatches = Math.max((semanticCounts.get(inferredCandidateKey(candidate.left)) ?? 1) - 1, (semanticCounts.get(inferredCandidateKey(candidate.right)) ?? 1) - 1);
|
|
522
|
+
return { candidate, competingMatches };
|
|
523
|
+
})
|
|
524
|
+
.filter(({ competingMatches }) => competingMatches === 0) // Gate 5
|
|
525
|
+
.map(({ candidate, competingMatches }) => buildInferredEntry(candidate, "semantic", competingMatches))
|
|
526
|
+
.sort((a, b) => compareCopybook(a.left.copybook, b.left.copybook)
|
|
527
|
+
|| a.left.qualifiedName.localeCompare(b.left.qualifiedName)
|
|
528
|
+
|| compareCopybook(a.right.copybook, b.right.copybook)
|
|
529
|
+
|| a.right.qualifiedName.localeCompare(b.right.qualifiedName));
|
|
362
530
|
const sortedDeterministic = deterministic.sort((a, b) => a.copybooks[0].id.localeCompare(b.copybooks[0].id) ||
|
|
363
531
|
a.qualifiedNames[0].localeCompare(b.qualifiedNames[0]));
|
|
364
|
-
if (sortedDeterministic.length === 0
|
|
365
|
-
|
|
532
|
+
if (sortedDeterministic.length === 0
|
|
533
|
+
&& inferredHighConfidence.length === 0
|
|
534
|
+
&& inferredAmbiguous.length === 0
|
|
535
|
+
&& inferredSemantic.length === 0) {
|
|
536
|
+
return diagnostics.length > 0 ? withDiagnostics(emptyCopybookLineage()) : null;
|
|
366
537
|
}
|
|
367
538
|
const participatingCopybookIds = new Set();
|
|
368
539
|
const participatingProgramIds = new Set();
|
|
@@ -407,16 +578,24 @@ export function buildFieldLineage(models) {
|
|
|
407
578
|
fields: sortedDeterministic.length,
|
|
408
579
|
},
|
|
409
580
|
inferred: {
|
|
581
|
+
// `copybooks` / `programs` deliberately count name-keyed entries only
|
|
582
|
+
// (high + ambiguous). Excluding semantic keeps this counter byte-
|
|
583
|
+
// stable on corpora without rename pairs — the regression-lock
|
|
584
|
+
// contract from #35.
|
|
410
585
|
copybooks: inferredCopybookIds.size,
|
|
411
586
|
programs: inferredProgramIds.size,
|
|
412
587
|
highConfidence: inferredHighConfidence.length,
|
|
413
588
|
ambiguous: inferredAmbiguous.length,
|
|
589
|
+
semantic: inferredSemantic.length,
|
|
414
590
|
},
|
|
591
|
+
diagnosticsByKind: countDiagnosticsByKind(diagnostics),
|
|
415
592
|
},
|
|
416
593
|
copybookUsage,
|
|
417
594
|
deterministic: sortedDeterministic,
|
|
418
595
|
inferredHighConfidence,
|
|
419
596
|
inferredAmbiguous,
|
|
597
|
+
inferredSemantic,
|
|
598
|
+
diagnostics,
|
|
420
599
|
};
|
|
421
600
|
}
|
|
422
601
|
export function generateFieldLineagePage(lineage) {
|
|
@@ -438,6 +617,12 @@ export function generateFieldLineagePage(lineage) {
|
|
|
438
617
|
...entry.left.programs.map((program) => `"raw/${program.sourceFile}"`),
|
|
439
618
|
...entry.right.programs.map((program) => `"raw/${program.sourceFile}"`),
|
|
440
619
|
]),
|
|
620
|
+
...(lineage.inferredSemantic ?? []).flatMap((entry) => [
|
|
621
|
+
`"raw/${entry.left.copybook.sourceFile}"`,
|
|
622
|
+
`"raw/${entry.right.copybook.sourceFile}"`,
|
|
623
|
+
...entry.left.programs.map((program) => `"raw/${program.sourceFile}"`),
|
|
624
|
+
...entry.right.programs.map((program) => `"raw/${program.sourceFile}"`),
|
|
625
|
+
]),
|
|
441
626
|
...(callBound?.entries.flatMap((entry) => [
|
|
442
627
|
`"raw/${entry.caller.sourceFile}"`,
|
|
443
628
|
`"raw/${entry.callee.sourceFile}"`,
|
|
@@ -454,10 +639,13 @@ export function generateFieldLineagePage(lineage) {
|
|
|
454
639
|
lines.push(`sources: [${sources.join(", ")}]`);
|
|
455
640
|
lines.push("---");
|
|
456
641
|
lines.push("");
|
|
642
|
+
renderCoverageSection(lines, lineage, callBound, db2);
|
|
643
|
+
const semanticCount = lineage.summary.inferred?.semantic ?? 0;
|
|
457
644
|
const overviewHasCopybook = lineage.copybookUsage.length > 0
|
|
458
645
|
|| lineage.deterministic.length > 0
|
|
459
646
|
|| lineage.inferredHighConfidence.length > 0
|
|
460
|
-
|| lineage.inferredAmbiguous.length > 0
|
|
647
|
+
|| lineage.inferredAmbiguous.length > 0
|
|
648
|
+
|| semanticCount > 0;
|
|
461
649
|
lines.push("## Overview");
|
|
462
650
|
lines.push("");
|
|
463
651
|
lines.push("| Metric | Count |");
|
|
@@ -470,6 +658,11 @@ export function generateFieldLineagePage(lineage) {
|
|
|
470
658
|
lines.push(`| Inferred programs | ${lineage.summary.inferred.programs} |`);
|
|
471
659
|
lines.push(`| Inferred high-confidence candidates | ${lineage.summary.inferred.highConfidence} |`);
|
|
472
660
|
lines.push(`| Inferred ambiguous candidates | ${lineage.summary.inferred.ambiguous} |`);
|
|
661
|
+
// Only surface the semantic row when there's content — keeps Overview
|
|
662
|
+
// byte-identical for rename-free corpora (#35 regression-lock contract).
|
|
663
|
+
if (semanticCount > 0) {
|
|
664
|
+
lines.push(`| Semantic-inferred candidates | ${semanticCount} |`);
|
|
665
|
+
}
|
|
473
666
|
}
|
|
474
667
|
if (callBound) {
|
|
475
668
|
lines.push(`| Call sites with USING args | ${callBound.summary.callSites} |`);
|
|
@@ -479,11 +672,34 @@ export function generateFieldLineagePage(lineage) {
|
|
|
479
672
|
lines.push(`| Shared DB2 tables | ${db2.summary.sharedTables} |`);
|
|
480
673
|
lines.push(`| DB2 cross-program pairs | ${db2.entries.length} |`);
|
|
481
674
|
}
|
|
675
|
+
// Defensive `?.` — interface declares these non-optional, but renderer may
|
|
676
|
+
// run over a pre-#30 in-memory shape (test fixture, legacy loader bypassing
|
|
677
|
+
// normalizeLoadedFieldLineage). Render a missing count rather than crash.
|
|
678
|
+
const zeroDataItemsCount = lineage.summary.diagnosticsByKind?.["parsed-zero-data-items"] ?? 0;
|
|
679
|
+
if (zeroDataItemsCount > 0) {
|
|
680
|
+
lines.push(`| Copybooks with zero parsed data items | ${zeroDataItemsCount} |`);
|
|
681
|
+
}
|
|
482
682
|
lines.push("");
|
|
683
|
+
if (zeroDataItemsCount > 0) {
|
|
684
|
+
lines.push("## Excluded Inputs");
|
|
685
|
+
lines.push("");
|
|
686
|
+
lines.push("Copybooks whose parsed AST yielded no data items. Common causes: "
|
|
687
|
+
+ "listing-extracted header text at columns other than 7, 88-level-only "
|
|
688
|
+
+ "fragments, pure COPY chains, or unsupported formats.");
|
|
689
|
+
lines.push("");
|
|
690
|
+
lines.push("| File | Kind | Rationale |");
|
|
691
|
+
lines.push("|------|------|-----------|");
|
|
692
|
+
const sortedDiagnostics = [...(lineage.diagnostics ?? [])].sort((a, b) => a.sourceFile.localeCompare(b.sourceFile));
|
|
693
|
+
for (const d of sortedDiagnostics) {
|
|
694
|
+
lines.push(`| \`raw/${d.sourceFile}\` | \`${d.kind}\` | ${d.rationale} |`);
|
|
695
|
+
}
|
|
696
|
+
lines.push("");
|
|
697
|
+
}
|
|
483
698
|
const hasCopybookContent = lineage.copybookUsage.length > 0
|
|
484
699
|
|| lineage.deterministic.length > 0
|
|
485
700
|
|| lineage.inferredHighConfidence.length > 0
|
|
486
|
-
|| lineage.inferredAmbiguous.length > 0
|
|
701
|
+
|| lineage.inferredAmbiguous.length > 0
|
|
702
|
+
|| (lineage.inferredSemantic ?? []).length > 0;
|
|
487
703
|
if (hasCopybookContent) {
|
|
488
704
|
lines.push("## Copybook Usage");
|
|
489
705
|
lines.push("");
|
|
@@ -548,6 +764,31 @@ export function generateFieldLineagePage(lineage) {
|
|
|
548
764
|
}
|
|
549
765
|
}
|
|
550
766
|
lines.push("");
|
|
767
|
+
// Semantic-inferred (#35) — only render when present. Keeping the
|
|
768
|
+
// subsection conditional preserves byte-identical output on rename-free
|
|
769
|
+
// corpora (regression lock from the issue).
|
|
770
|
+
const semanticEntries = lineage.inferredSemantic ?? [];
|
|
771
|
+
if (semanticEntries.length > 0) {
|
|
772
|
+
lines.push("### Semantic-Inferred");
|
|
773
|
+
lines.push("");
|
|
774
|
+
lines.push("Pairs matched on shape `(PIC, USAGE, level)` plus exact parent path plus ≥2 sibling overlap. **No name alignment** — the two fields have different names. Lower trust than high-confidence; review one-by-one before relying on these.");
|
|
775
|
+
lines.push("");
|
|
776
|
+
lines.push("| Left field | Right field | Left | Right | Programs | Evidence |");
|
|
777
|
+
lines.push("|------------|-------------|------|-------|----------|----------|");
|
|
778
|
+
for (const entry of semanticEntries) {
|
|
779
|
+
const leftLeaf = entry.left.qualifiedName.split(".").pop() ?? entry.fieldName;
|
|
780
|
+
const rightLeaf = entry.right.qualifiedName.split(".").pop() ?? entry.fieldName;
|
|
781
|
+
const evidence = [
|
|
782
|
+
`PIC ${entry.left.picture ?? "—"}`,
|
|
783
|
+
`USAGE ${entry.left.usage ?? "—"}`,
|
|
784
|
+
entry.evidence.siblingOverlap.length > 0
|
|
785
|
+
? `siblings: ${entry.evidence.siblingOverlap.join(", ")}`
|
|
786
|
+
: undefined,
|
|
787
|
+
].filter((v) => Boolean(v)).join("; ");
|
|
788
|
+
lines.push(`| ${leftLeaf} | ${rightLeaf} | ${displayLabel(entry.left.copybook.id)}<br>${formatInferredStructure(entry.left)} | ${displayLabel(entry.right.copybook.id)}<br>${formatInferredStructure(entry.right)} | ${formatInferredPrograms(entry.left, entry.right)} | ${evidence} |`);
|
|
789
|
+
}
|
|
790
|
+
lines.push("");
|
|
791
|
+
}
|
|
551
792
|
}
|
|
552
793
|
if (callBound && (callBound.entries.length > 0 || callBound.diagnostics.length > 0)) {
|
|
553
794
|
lines.push("## Call Boundary Field Lineage");
|
|
@@ -731,6 +972,88 @@ function renderDb2Exclusions(lines, diagnostics) {
|
|
|
731
972
|
}
|
|
732
973
|
lines.push("");
|
|
733
974
|
}
|
|
975
|
+
/**
|
|
976
|
+
* Compact "top N excluded reasons" for a coverage-row cell. Kinds with
|
|
977
|
+
* zero counts are dropped first so the cell never renders a noise entry
|
|
978
|
+
* like `0 system-call`. Sort is count desc, kind asc on tie — pinning the
|
|
979
|
+
* tie-break gives byte-stable output across rebuilds when two kinds have
|
|
980
|
+
* the same count.
|
|
981
|
+
*/
|
|
982
|
+
function topExclusionReasons(byKind, limit = 2) {
|
|
983
|
+
const ranked = Object.entries(byKind)
|
|
984
|
+
.filter(([, count]) => count > 0)
|
|
985
|
+
.sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]));
|
|
986
|
+
if (ranked.length === 0)
|
|
987
|
+
return "—";
|
|
988
|
+
return ranked.slice(0, limit).map(([kind, count]) => `${count} ${kind}`).join(", ");
|
|
989
|
+
}
|
|
990
|
+
/**
|
|
991
|
+
* Coverage gauge rendered at the top of `field-lineage.md`. Three rows —
|
|
992
|
+
* Copybook / Call boundary / DB2 — each showing what was indexed, what
|
|
993
|
+
* yielded lineage, and the top excluded reasons. Empty families omit their
|
|
994
|
+
* row. All counts derive from existing summary fields on the artifact; no
|
|
995
|
+
* new aggregation logic.
|
|
996
|
+
*/
|
|
997
|
+
function renderCoverageSection(lines, lineage, callBound, db2) {
|
|
998
|
+
// Pre-#30 in-memory shapes may lack diagnosticsByKind; declaring as
|
|
999
|
+
// Record<string, number> means the `?? 0` reads on known keys are
|
|
1000
|
+
// defensible even if the field is absent.
|
|
1001
|
+
const copybookDiagByKind = lineage.summary.diagnosticsByKind ?? {};
|
|
1002
|
+
const zeroDataItemsCount = copybookDiagByKind["parsed-zero-data-items"] ?? 0;
|
|
1003
|
+
const semanticCount = lineage.summary.inferred?.semantic ?? 0;
|
|
1004
|
+
const copybookHasContent = lineage.copybookUsage.length > 0
|
|
1005
|
+
|| lineage.deterministic.length > 0
|
|
1006
|
+
|| lineage.inferredHighConfidence.length > 0
|
|
1007
|
+
|| lineage.inferredAmbiguous.length > 0
|
|
1008
|
+
|| semanticCount > 0
|
|
1009
|
+
|| zeroDataItemsCount > 0;
|
|
1010
|
+
const rows = [];
|
|
1011
|
+
if (copybookHasContent) {
|
|
1012
|
+
// Indexed = universe of copybooks observed = participating (yielded
|
|
1013
|
+
// lineage) + zero-data-items drops. Single-consumer / REPLACING-only
|
|
1014
|
+
// copybooks aren't currently tracked as diagnostics so they don't
|
|
1015
|
+
// appear; once added, sum their counter in here.
|
|
1016
|
+
const indexed = lineage.copybookUsage.length + zeroDataItemsCount;
|
|
1017
|
+
// Yielding splits inferred into the name-keyed and shape-keyed halves
|
|
1018
|
+
// (#35). The semantic suffix is conditional so the cell stays byte-
|
|
1019
|
+
// identical on rename-free corpora — regression lock contract.
|
|
1020
|
+
const yielding = semanticCount > 0
|
|
1021
|
+
? `${lineage.summary.deterministic.copybooks} deterministic, ${lineage.summary.inferred.copybooks} inferred, ${semanticCount} semantic`
|
|
1022
|
+
: `${lineage.summary.deterministic.copybooks} deterministic, ${lineage.summary.inferred.copybooks} inferred`;
|
|
1023
|
+
rows.push(`| Copybook | ${indexed} | ${yielding} | ${topExclusionReasons(copybookDiagByKind)} |`);
|
|
1024
|
+
}
|
|
1025
|
+
if (callBound) {
|
|
1026
|
+
// Indexed = total CALL ... USING sites attempted = resolved sites
|
|
1027
|
+
// (`summary.callSites`) + per-site drops. shape-mismatch and
|
|
1028
|
+
// caller-arg-not-top-level are per-arg drops *within* a resolved
|
|
1029
|
+
// site, so they don't add to the site total.
|
|
1030
|
+
const cbd = callBound.summary.diagnosticsByKind;
|
|
1031
|
+
const siteDropped = cbd["unresolved-callee"]
|
|
1032
|
+
+ cbd["dynamic-call"]
|
|
1033
|
+
+ cbd["arity-mismatch"]
|
|
1034
|
+
+ cbd["system-call"];
|
|
1035
|
+
const totalSites = callBound.summary.callSites + siteDropped;
|
|
1036
|
+
rows.push(`| Call boundary | ${totalSites} call site(s) | ${callBound.summary.pairs} pair(s) | ${topExclusionReasons(callBound.summary.diagnosticsByKind)} |`);
|
|
1037
|
+
}
|
|
1038
|
+
if (db2) {
|
|
1039
|
+
// Indexed = all distinct DB2 tables touched by ≥1 program =
|
|
1040
|
+
// sharedTables (had both writer and reader) + writer-only +
|
|
1041
|
+
// reader-only. non-classifiable-op is per-reference, not per-table,
|
|
1042
|
+
// and self-loop is per-pair within a shared table — neither adds to
|
|
1043
|
+
// the table total.
|
|
1044
|
+
const dbd = db2.summary.diagnosticsByKind;
|
|
1045
|
+
const totalTables = db2.summary.sharedTables + dbd["writer-only"] + dbd["reader-only"];
|
|
1046
|
+
rows.push(`| DB2 | ${totalTables} table(s) | ${db2.summary.pairs} writer→reader pair(s) | ${topExclusionReasons(db2.summary.diagnosticsByKind)} |`);
|
|
1047
|
+
}
|
|
1048
|
+
if (rows.length === 0)
|
|
1049
|
+
return;
|
|
1050
|
+
lines.push("## Coverage");
|
|
1051
|
+
lines.push("");
|
|
1052
|
+
lines.push("| Family | Indexed | Yielding lineage | Excluded (top reasons) |");
|
|
1053
|
+
lines.push("|--------|---------|------------------|------------------------|");
|
|
1054
|
+
lines.push(...rows);
|
|
1055
|
+
lines.push("");
|
|
1056
|
+
}
|
|
734
1057
|
function groupCallBoundByPair(entries) {
|
|
735
1058
|
const groups = new Map();
|
|
736
1059
|
for (const entry of entries) {
|