Enhance template matching and chain inspection features
Node.js build / build (20.x) (push) Waiting to run
Node.js build / build (22.x) (push) Waiting to run

- Added new properties to TemplateMatch interface for tracking slots and links completeness, and confidence levels.
- Updated resolveCanonicalEdgeType function to handle optional edge vocabulary.
- Enhanced computeFindings function to include missing link constraints findings.
- Improved inspectChains function to report on links completeness and confidence levels.
- Refactored tests to utilize real configuration files and improve integration with the vault structure.
- Updated helper functions to support loading from real vault paths, enhancing test reliability.
This commit is contained in:
Lars committed 2026-01-18 22:10:44 +01:00
1 parent 0b763511d8
commit 3bb59afdda
13 files changed
+1127 -720

No files matched your search

+20 -3
View File
@@ -67,6 +67,9 @@ export interface TemplateMatch {
edgeRole: string;
rawEdgeType: string;
}>;
slotsComplete: boolean;
linksComplete: boolean;
confidence: "confirmed" | "plausible" | "weak";
}
export interface ChainInspectorReport {
@@ -124,7 +127,7 @@ export function resolveCanonicalEdgeType(
}
// Check if raw type is already canonical
if (edgeVocabulary.byCanonical.has(rawEdgeType)) {
if (edgeVocabulary?.byCanonical.has(rawEdgeType)) {
return { canonical: rawEdgeType, matchedBy: "canonical" };
}
@@ -617,7 +620,7 @@ function computeFindings(
const { canonical } = resolveCanonicalEdgeType(edge.rawEdgeType, edgeVocabulary);
const edgeTypeToCheck = canonical || edge.rawEdgeType;
for (const [roleName, role] of Object.entries(chainRoles.roles)) {
for (const [roleName, role] of Object.entries(chainRoles?.roles || {})) {
if (CAUSAL_ROLE_NAMES.includes(roleName)) {
// Check both canonical and raw type (permissive)
if (role.edge_types.includes(edgeTypeToCheck) || role.edge_types.includes(edge.rawEdgeType)) {
@@ -932,7 +935,7 @@ export async function inspectChains(
// Count role matches (using canonical if available)
if (chainRoles && canonical) {
for (const [roleName, role] of Object.entries(chainRoles.roles)) {
for (const [roleName, role] of Object.entries(chainRoles?.roles || {})) {
if (role.edge_types.includes(canonical)) {
roleMatches[roleName] = (roleMatches[roleName] || 0) + 1;
}
@@ -1033,6 +1036,20 @@ export async function inspectChains(
}
}
// missing_link_constraints finding
if (match.slotsComplete && match.requiredLinks > 0 && !match.linksComplete) {
const severity = templateMatchingProfileName === "decisioning" ? "warn" : "info";
findings.push({
code: "missing_link_constraints",
severity,
message: `Template ${match.templateName}: slots complete but link constraints missing (${match.satisfiedLinks}/${match.requiredLinks} satisfied)`,
evidence: {
file: context.file,
sectionHeading: context.heading,
},
});
}
// weak_chain_roles finding
if (match.roleEvidence && match.roleEvidence.length > 0) {
const hasCausalRole = match.roleEvidence.some((ev) =>
+42
View File
@@ -39,6 +39,9 @@ export interface TemplateMatch {
edgeRole: string;
rawEdgeType: string;
}>;
slotsComplete: boolean;
linksComplete: boolean;
confidence: "confirmed" | "plausible" | "weak";
}
const CAUSAL_ROLE_NAMES = ["causal", "influences", "enables_constraints"];
@@ -446,6 +449,7 @@ function findBestAssignment(
}
}
// Calculate completeness and confidence (will be set after matching)
bestMatch = {
templateName: template.name,
score: result.score,
@@ -454,6 +458,9 @@ function findBestAssignment(
satisfiedLinks: result.satisfiedLinks,
requiredLinks: result.requiredLinks,
roleEvidence: result.roleEvidence.length > 0 ? result.roleEvidence : undefined,
slotsComplete: false, // Will be set later
linksComplete: false, // Will be set later
confidence: "weak", // Will be set later
};
}
return;
@@ -583,6 +590,41 @@ export async function matchTemplates(
}
}
// Calculate completeness and confidence for each match
// Get causal-ish roles from config or use default
const causalIshRoles: string[] = templatesConfig.defaults?.roles?.causal_ish || CAUSAL_ROLE_NAMES;
for (const match of matches) {
// Calculate slotsComplete
match.slotsComplete = match.missingSlots.length === 0;
// Calculate linksComplete
const template = templatesConfig.templates.find((t) => t.name === match.templateName);
const normalized = template ? normalizeTemplate(template) : { slots: [], links: [] };
if (normalized.links.length === 0) {
match.linksComplete = true; // No links means complete
} else {
match.linksComplete = match.satisfiedLinks === match.requiredLinks;
}
// Calculate confidence
const hasCausalRole = match.roleEvidence?.some((ev) => causalIshRoles.includes(ev.edgeRole)) ?? false;
const slotsFilled = Object.keys(match.slotAssignments).length;
const minSlotsFilled = profile?.min_slots_filled_for_gap_findings ?? 2;
const minScore = profile?.min_score_for_gap_findings ?? 0;
if (match.slotsComplete && match.linksComplete && hasCausalRole) {
match.confidence = "confirmed";
} else if (
(match.slotsComplete && (!match.linksComplete || !hasCausalRole)) ||
(slotsFilled >= minSlotsFilled && match.score >= minScore)
) {
match.confidence = "plausible";
} else {
match.confidence = "weak";
}
}
// Sort by score desc, then name asc (deterministic)
matches.sort((a, b) => {
if (b.score !== a.score) {