@agent-wiki/mcp 0.21.6 → 0.21.7

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/server.js CHANGED
@@ -1009,16 +1009,133 @@ function qualifiedNameMatches(candidate, requested) {
1009
1009
  return false;
1010
1010
  return candidate.trim().toUpperCase() === requested.trim().toUpperCase();
1011
1011
  }
1012
+ function leafFieldName(qualified) {
1013
+ if (!qualified)
1014
+ return "";
1015
+ const parts = qualified.split(".");
1016
+ return parts[parts.length - 1] ?? "";
1017
+ }
1012
1018
  function inferredEntryMatches(entry, requestedFieldName, requestedQualifiedName, requestedCopybook) {
1013
- if (requestedFieldName && entry.fieldName.toUpperCase() !== requestedFieldName.toUpperCase())
1014
- return false;
1015
- if (!requestedQualifiedName && !requestedCopybook)
1019
+ // Each side of the pair must satisfy ALL filters together. A pre-#44
1020
+ // Codex review caught that the prior implementation checked field_name
1021
+ // and qualified_name independently — that lets a `field_name=CUST-ID +
1022
+ // qualified_name=CUSTOMER-REC.ADDRESS.CUSTOMER-ID` query match a
1023
+ // semantic rename pair `CUSTOMER-ID ↔ CUST-ID` because field_name
1024
+ // hits the right side's leaf while qualified_name hits the left side's
1025
+ // qualified path. Neither endpoint actually satisfies both filters.
1026
+ // Closing that gap means walking sides explicitly.
1027
+ const fnUpper = requestedFieldName?.toUpperCase();
1028
+ const matchesSide = (side) => {
1029
+ if (fnUpper && leafFieldName(side.qualifiedName).toUpperCase() !== fnUpper)
1030
+ return false;
1031
+ if (!copybookMatches(side.copybook, requestedCopybook))
1032
+ return false;
1033
+ if (!qualifiedNameMatches(side.qualifiedName, requestedQualifiedName))
1034
+ return false;
1035
+ return true;
1036
+ };
1037
+ return matchesSide(entry.left) || matchesSide(entry.right);
1038
+ }
1039
+ /**
1040
+ * Match a CALL boundary entry against the query. The copybook filter
1041
+ * doesn't apply — CALL boundary pairs are caller/callee program data
1042
+ * items, not copybook-anchored.
1043
+ *
1044
+ * Walks caller and callee as complete endpoints: each must satisfy ALL
1045
+ * filters together (Codex review #3 on #45). The pre-fix split-check
1046
+ * let `field_name=WS-REC + qualified_name=LK-REC` match a `WS-REC ↔
1047
+ * LK-REC` pair because field_name hit the caller and qualified_name
1048
+ * hit the callee, even though neither endpoint individually satisfied
1049
+ * both — the same cross-side bug already fixed for inferred and DB2.
1050
+ */
1051
+ function callBoundEntryMatches(entry, requestedFieldName, requestedQualifiedName) {
1052
+ const fnUpper = requestedFieldName?.toUpperCase();
1053
+ const matchesEndpoint = (endpoint) => {
1054
+ if (fnUpper !== undefined && endpoint.fieldName.toUpperCase() !== fnUpper)
1055
+ return false;
1056
+ if (!qualifiedNameMatches(endpoint.qualifiedName, requestedQualifiedName))
1057
+ return false;
1058
+ return true;
1059
+ };
1060
+ return matchesEndpoint(entry.caller) || matchesEndpoint(entry.callee);
1061
+ }
1062
+ /**
1063
+ * Match a DB2 entry against the query. DB2 host vars don't carry full
1064
+ * qualified paths, so qualified_name matching falls back to comparing
1065
+ * the leaf segment against the resolved `dataItem.name` on any of the
1066
+ * writer / reader host vars. The response surfaces this fallback as a
1067
+ * `notes` entry so the consumer knows precision is reduced here.
1068
+ * Copybook filter doesn't apply directly (DB2 host vars are program-
1069
+ * declared) — left out by design.
1070
+ */
1071
+ function db2EntryMatches(entry, requestedFieldName, requestedQualifiedName) {
1072
+ if (!requestedFieldName && !requestedQualifiedName)
1016
1073
  return true;
1017
- const leftMatches = copybookMatches(entry.left.copybook, requestedCopybook)
1018
- && qualifiedNameMatches(entry.left.qualifiedName, requestedQualifiedName);
1019
- const rightMatches = copybookMatches(entry.right.copybook, requestedCopybook)
1020
- && qualifiedNameMatches(entry.right.qualifiedName, requestedQualifiedName);
1021
- return leftMatches || rightMatches;
1074
+ // Same-host-var constraint (Codex review #3 on #45): both filters must
1075
+ // satisfy on the *same* host var, not on different ones across writer
1076
+ // and reader. The pre-fix split-check let `field_name=WR-ID +
1077
+ // qualified_name=ANY.RD-NAME` match a CUSTOMERS entry where WR-ID
1078
+ // and RD-NAME lived on separate host vars — a false positive
1079
+ // mirroring the earlier semantic-side bug.
1080
+ const allHostVars = [...entry.writer.hostVars, ...entry.reader.hostVars];
1081
+ const fnUpper = requestedFieldName?.toUpperCase();
1082
+ const qnLeaf = requestedQualifiedName
1083
+ ? leafFieldName(requestedQualifiedName).toUpperCase()
1084
+ : undefined;
1085
+ return allHostVars.some((hv) => {
1086
+ const hvName = hv.name.toUpperCase();
1087
+ const dataItemName = hv.dataItem?.name.toUpperCase();
1088
+ if (fnUpper !== undefined && hvName !== fnUpper && dataItemName !== fnUpper)
1089
+ return false;
1090
+ // qualified_name leaf must match symmetrically with field_name — both
1091
+ // hv.name (the SQL-visible name) and dataItem.name (the resolved
1092
+ // copybook field) qualify. REPLACING-aliased host vars carry the SQL
1093
+ // name in `hv.name` and the original in `dataItem.name`; a query
1094
+ // for `qualified_name=ANY.CLIENT-ID` (the alias) was rejected when
1095
+ // only dataItem.name was checked (Codex review #4 on #45).
1096
+ if (qnLeaf !== undefined && hvName !== qnLeaf && dataItemName !== qnLeaf)
1097
+ return false;
1098
+ return true;
1099
+ });
1100
+ }
1101
+ /**
1102
+ * Compute the set of host-var **names** in a DB2 entry that satisfied the
1103
+ * query — by direct name match, by resolved `dataItem.name` (so REPLACING
1104
+ * aliases like `:CLIENT-ID` carrying `dataItem.name = CUSTOMER-ID` still
1105
+ * count), or by `qualified_name` leaf fallback against `dataItem.name`.
1106
+ *
1107
+ * Returned set is keyed on the host-var's serialized `name` so the column-
1108
+ * pair filter (whose payload only carries `writerHostVar` / `readerHostVar`
1109
+ * names) can decide membership by set lookup. Codex caught that the prior
1110
+ * pair filter only compared against raw host-var names and silently
1111
+ * dropped pairs the parent entry matched via `dataItem.name`.
1112
+ */
1113
+ function matchingDb2HostVarNames(entry, requestedFieldName, requestedQualifiedName) {
1114
+ const allHostVars = [...entry.writer.hostVars, ...entry.reader.hostVars];
1115
+ if (!requestedFieldName && !requestedQualifiedName) {
1116
+ return new Set(allHostVars.map((hv) => hv.name));
1117
+ }
1118
+ // Same-host-var constraint mirrors db2EntryMatches: each filter must
1119
+ // satisfy on the same host var, otherwise the column-pair filter
1120
+ // surface drifts wider than the entry surface and lets pairs through
1121
+ // for host vars no one actually queried.
1122
+ const fnUpper = requestedFieldName?.toUpperCase();
1123
+ const qnLeaf = requestedQualifiedName
1124
+ ? leafFieldName(requestedQualifiedName).toUpperCase()
1125
+ : undefined;
1126
+ const matched = new Set();
1127
+ for (const hv of allHostVars) {
1128
+ const hvName = hv.name.toUpperCase();
1129
+ const dataItemName = hv.dataItem?.name.toUpperCase();
1130
+ if (fnUpper !== undefined && hvName !== fnUpper && dataItemName !== fnUpper)
1131
+ continue;
1132
+ // Match qualified_name leaf against both hv.name and dataItem.name,
1133
+ // symmetric with the field_name check above. See db2EntryMatches.
1134
+ if (qnLeaf !== undefined && hvName !== qnLeaf && dataItemName !== qnLeaf)
1135
+ continue;
1136
+ matched.add(hv.name);
1137
+ }
1138
+ return matched;
1022
1139
  }
1023
1140
  function buildFieldLineageResponse(lineage, query) {
1024
1141
  const fieldName = query.fieldName?.trim();
@@ -1027,6 +1144,7 @@ function buildFieldLineageResponse(lineage, query) {
1027
1144
  if (!fieldName && !qualifiedName) {
1028
1145
  throw new Error("field_lineage requires field_name or qualified_name");
1029
1146
  }
1147
+ // ── Copybook families ──────────────────────────────────────────────
1030
1148
  const deterministic = lineage.deterministic.filter((entry) => {
1031
1149
  if (fieldName && entry.fieldName.toUpperCase() !== fieldName.toUpperCase())
1032
1150
  return false;
@@ -1038,40 +1156,80 @@ function buildFieldLineageResponse(lineage, query) {
1038
1156
  });
1039
1157
  const inferredHighConfidence = lineage.inferredHighConfidence.filter((entry) => inferredEntryMatches(entry, fieldName, qualifiedName, copybook));
1040
1158
  const inferredAmbiguous = lineage.inferredAmbiguous.filter((entry) => inferredEntryMatches(entry, fieldName, qualifiedName, copybook));
1041
- // Top-level envelope summarizes the strongest evidence in the response.
1042
- // Consumers (LLM agents, downstream tools) branch on `confidence` /
1043
- // `abstain` without inspecting per-entry tier detail.
1044
- const evidence = deterministic.length > 0
1045
- ? {
1046
- confidence: "strong",
1047
- basis: "deterministic",
1048
- abstain: false,
1049
- rationale: `${deterministic.length} deterministic match(es) via copybook lineage.`,
1050
- provenance: [],
1051
- }
1052
- : inferredHighConfidence.length > 0
1053
- ? {
1054
- confidence: "weak",
1055
- basis: "inferred",
1056
- abstain: false,
1057
- rationale: `${inferredHighConfidence.length} inferred high-confidence match(es); no deterministic matches.`,
1058
- provenance: [],
1059
- }
1060
- : inferredAmbiguous.length > 0
1061
- ? {
1062
- confidence: "absent",
1063
- basis: "inferred",
1064
- abstain: true,
1065
- rationale: `${inferredAmbiguous.length} ambiguous match(es) only; lineage cannot be determined with confidence.`,
1066
- provenance: [],
1067
- }
1068
- : {
1069
- confidence: "absent",
1070
- basis: "inferred",
1071
- abstain: true,
1072
- rationale: "No matches found for the requested field.",
1073
- provenance: [],
1074
- };
1159
+ // #35 semantic tier — shape-keyed; either side's leaf can match. The
1160
+ // same `inferredEntryMatches` widening (#44 added leaf checks) handles
1161
+ // it, so the filter call shape matches high/ambiguous.
1162
+ const inferredSemantic = (lineage.inferredSemantic ?? []).filter((entry) => inferredEntryMatches(entry, fieldName, qualifiedName, copybook));
1163
+ // ── CALL boundary (#44) ────────────────────────────────────────────
1164
+ // Copybook filter intentionally not applied — CALL boundary entries
1165
+ // pair caller and callee data items by position, not by copybook
1166
+ // identity. A `copybook=...` query implicitly looks for copybook-
1167
+ // family lineage and shouldn't produce false CALL-boundary results.
1168
+ const callBoundAll = lineage.callBoundLineage?.entries ?? [];
1169
+ const callBound = copybook
1170
+ ? []
1171
+ : callBoundAll.filter((entry) => callBoundEntryMatches(entry, fieldName, qualifiedName));
1172
+ // ── DB2 (#44) ──────────────────────────────────────────────────────
1173
+ // Same reasoning for copybook filter: DB2 host vars are program-
1174
+ // declared, not copybook-anchored.
1175
+ const db2All = lineage.db2Lineage?.entries ?? [];
1176
+ const db2 = copybook
1177
+ ? []
1178
+ : db2All.filter((entry) => db2EntryMatches(entry, fieldName, qualifiedName));
1179
+ // Column-pair matches are a flat list across all matching DB2 entries.
1180
+ // Each pair carries enough context (table + programs) to be standalone.
1181
+ // Pair-filter set covers both raw host-var names AND dataItem aliases
1182
+ // (e.g., a `:CLIENT-ID` host var whose `dataItem.name` is `CUSTOMER-ID`
1183
+ // qualifies via the alias), so the pair surface stays consistent with
1184
+ // the entry-level match.
1185
+ const db2ColumnPairs = db2.flatMap((entry) => {
1186
+ const matchingNames = matchingDb2HostVarNames(entry, fieldName, qualifiedName);
1187
+ // `?? []` guards pre-Phase-B artifacts on disk (Codex review #4 on
1188
+ // #45): older `field-lineage.json` files have DB2 entries without a
1189
+ // `columnPairs` field. The renderer already defaults it; the query
1190
+ // path must too, otherwise `.filter(...)` throws a TypeError.
1191
+ return (entry.columnPairs ?? [])
1192
+ .filter((pair) => matchingNames.has(pair.writerHostVar) || matchingNames.has(pair.readerHostVar))
1193
+ .map((pair) => ({
1194
+ table: entry.table,
1195
+ writerProgramId: entry.writer.programId,
1196
+ readerProgramId: entry.reader.programId,
1197
+ ...pair,
1198
+ }));
1199
+ });
1200
+ // ── Cross-family evidence envelope (#44) ───────────────────────────
1201
+ // Strongest evidence across ALL families wins. Pre-#44 this only
1202
+ // considered the copybook tiers and silently abstained when only
1203
+ // CALL boundary or DB2 matches existed.
1204
+ const callBoundDeterministic = callBound.filter((e) => e.confidence === "deterministic").length;
1205
+ const callBoundHigh = callBound.filter((e) => e.confidence === "high").length;
1206
+ const evidence = buildLineageEnvelope({
1207
+ deterministicCopybook: deterministic.length,
1208
+ callBoundDeterministic,
1209
+ db2: db2.length,
1210
+ inferredHigh: inferredHighConfidence.length,
1211
+ callBoundHigh,
1212
+ semantic: inferredSemantic.length,
1213
+ ambiguous: inferredAmbiguous.length,
1214
+ });
1215
+ // ── Family availability — distinguishes "no artifact for family"
1216
+ // from "family exists but query didn't match it" so empty-result
1217
+ // consumers can give actionable feedback to the user.
1218
+ const familyAvailability = {
1219
+ copybook: lineage.deterministic.length > 0
1220
+ || lineage.inferredHighConfidence.length > 0
1221
+ || lineage.inferredAmbiguous.length > 0
1222
+ || (lineage.inferredSemantic ?? []).length > 0,
1223
+ callBound: !!lineage.callBoundLineage && callBoundAll.length > 0,
1224
+ db2: !!lineage.db2Lineage && db2All.length > 0,
1225
+ };
1226
+ // Notes surface limitations the consumer should know about — currently
1227
+ // just the DB2 qualified_name fallback. Empty array (not omitted) so
1228
+ // clients can rely on the field being present.
1229
+ const notes = [];
1230
+ if (qualifiedName && db2All.length > 0) {
1231
+ notes.push("DB2 host vars do not carry a full qualified path — qualified_name matching falls back to comparing the leaf segment against host-var dataItem.name. DB2 matches may include refs where the parent qualified path differs but the leaf agrees.");
1232
+ }
1075
1233
  return {
1076
1234
  query: {
1077
1235
  type: "field_lineage",
@@ -1084,11 +1242,80 @@ function buildFieldLineageResponse(lineage, query) {
1084
1242
  deterministicMatches: deterministic.length,
1085
1243
  inferredHighConfidenceMatches: inferredHighConfidence.length,
1086
1244
  inferredAmbiguousMatches: inferredAmbiguous.length,
1245
+ inferredSemanticMatches: inferredSemantic.length,
1246
+ callBoundMatches: callBound.length,
1247
+ db2Matches: db2.length,
1248
+ db2ColumnPairMatches: db2ColumnPairs.length,
1249
+ familyAvailability,
1087
1250
  },
1088
1251
  evidence,
1089
1252
  deterministic,
1090
1253
  inferredHighConfidence,
1091
1254
  inferredAmbiguous,
1255
+ inferredSemantic,
1256
+ callBound: { entries: callBound },
1257
+ db2: { entries: db2, columnPairs: db2ColumnPairs },
1258
+ notes,
1259
+ };
1260
+ }
1261
+ /**
1262
+ * Compute the top-level evidence envelope from per-family match counts
1263
+ * (#44). Strong wins when any deterministic-tier family hits; weak wins
1264
+ * when only inferred families hit; absent + abstain when only ambiguous
1265
+ * or no matches exist. The rationale text enumerates which families
1266
+ * contributed so an LLM consumer can read off the source without
1267
+ * walking the per-family arrays.
1268
+ */
1269
+ function buildLineageEnvelope(counts) {
1270
+ const det = counts.deterministicCopybook + counts.callBoundDeterministic + counts.db2;
1271
+ const weak = counts.inferredHigh + counts.callBoundHigh + counts.semantic;
1272
+ if (det > 0) {
1273
+ const parts = [];
1274
+ if (counts.deterministicCopybook > 0)
1275
+ parts.push(`${counts.deterministicCopybook} deterministic copybook`);
1276
+ if (counts.callBoundDeterministic > 0)
1277
+ parts.push(`${counts.callBoundDeterministic} CALL boundary`);
1278
+ if (counts.db2 > 0)
1279
+ parts.push(`${counts.db2} DB2 table`);
1280
+ return {
1281
+ confidence: "strong",
1282
+ basis: "deterministic",
1283
+ abstain: false,
1284
+ rationale: `${det} deterministic match(es): ${parts.join(", ")}.`,
1285
+ provenance: [],
1286
+ };
1287
+ }
1288
+ if (weak > 0) {
1289
+ const parts = [];
1290
+ if (counts.inferredHigh > 0)
1291
+ parts.push(`${counts.inferredHigh} inferred high-confidence`);
1292
+ if (counts.callBoundHigh > 0)
1293
+ parts.push(`${counts.callBoundHigh} CALL boundary high`);
1294
+ if (counts.semantic > 0)
1295
+ parts.push(`${counts.semantic} semantic-inferred`);
1296
+ return {
1297
+ confidence: "weak",
1298
+ basis: "inferred",
1299
+ abstain: false,
1300
+ rationale: `${weak} inferred match(es): ${parts.join(", ")}; no deterministic matches.`,
1301
+ provenance: [],
1302
+ };
1303
+ }
1304
+ if (counts.ambiguous > 0) {
1305
+ return {
1306
+ confidence: "absent",
1307
+ basis: "inferred",
1308
+ abstain: true,
1309
+ rationale: `${counts.ambiguous} ambiguous match(es) only; lineage cannot be determined with confidence.`,
1310
+ provenance: [],
1311
+ };
1312
+ }
1313
+ return {
1314
+ confidence: "absent",
1315
+ basis: "inferred",
1316
+ abstain: true,
1317
+ rationale: "No matches found for the requested field.",
1318
+ provenance: [],
1092
1319
  };
1093
1320
  }
1094
1321
  function codeQueryConsumesCompiledArtifacts(args) {