Refactor debug logging in template matching functions to use logger
Some checks are pending
Node.js build / build (20.x) (push) Waiting to run
Node.js build / build (22.x) (push) Waiting to run

- Replaced console.log statements with getTemplateMatchingLogger().debug() for enhanced control over logging levels.
- Improved debug logging for edge processing in findEdgeBetween and scoreAssignment functions, ensuring clearer insights during execution.
- Adjusted conditional logging in findTopKAssignments to streamline debug output.
This commit is contained in:
Lars 2026-02-06 11:45:02 +01:00
parent e6cd4aafec
commit dbd76b764d

View File

@ -481,10 +481,8 @@ function findEdgeBetween(
const canonical = canonicalEdgeType(edge.rawEdgeType);
const edgeRole = getEdgeRole(edge.rawEdgeType, canonical, chainRoles);
// Debug logging for guides edges
if (hasAllowedRoles && edge.rawEdgeType === "guides") {
console.log(`[findEdgeBetween] Checking guides edge: rawEdgeType=${edge.rawEdgeType}, canonical=${canonical}, edgeRole=${edgeRole}, chainRoles=${chainRoles ? "set" : "null"}`);
}
// Debug logging for guides edges (only via logger, controlled by log level)
// Removed console.log - use getTemplateMatchingLogger().debug() if needed
// CRITICAL FIX: If allowedEdgeRoles is specified, only return if this edge's role matches
// This prevents early return when a different edge type matches first.
@ -660,14 +658,15 @@ function scoreAssignment(
// Enhanced debug logging for guides edge specifically
const isGuidesDebug = isGuidesDebugLink && fromKey.includes("learning");
if (isGuidesDebug || debugLogging) {
console.log(`[scoreAssignment] Link ${link.from}${link.to}:`);
console.log(` edgeFound: ${!!edge}`);
console.log(` edgeType: ${edge?.rawEdgeType}`);
console.log(` edgeRole: ${edge?.edgeRole}`);
console.log(` effectiveRole: ${effectiveRole}`);
console.log(` inferRoleFromRawType(${edge?.rawEdgeType}): ${edge ? inferRoleFromRawType(edge.rawEdgeType, chainRoles) : "N/A"}`);
console.log(` allowedEdgeRoles: ${link.allowed_edge_roles?.join(", ") || "none"}`);
console.log(` matches: ${edge && effectiveRole && (!link.allowed_edge_roles || link.allowed_edge_roles.length === 0 || link.allowed_edge_roles.includes(effectiveRole))}`);
getTemplateMatchingLogger().debugObject(`[scoreAssignment] Link ${link.from}${link.to}`, {
edgeFound: !!edge,
edgeType: edge?.rawEdgeType,
edgeRole: edge?.edgeRole,
effectiveRole,
inferRoleFromRawType: edge ? inferRoleFromRawType(edge.rawEdgeType, chainRoles) : null,
allowedEdgeRoles: link.allowed_edge_roles,
matches: edge && effectiveRole && (!link.allowed_edge_roles || link.allowed_edge_roles.length === 0 || link.allowed_edge_roles.includes(effectiveRole))
});
}
if (edge && effectiveRole) {
@ -829,7 +828,7 @@ function findTopKAssignments(
return missing === 0;
}).length;
if (debugLogging || template.name === "insight_to_decision") {
if (debugLogging) {
getTemplateMatchingLogger().debug(`Template ${template.name}: collected=${collected.length}, complete=${completeCount}, will return up to ${topK}`);
if (collected.length > 0) {
getTemplateMatchingLogger().debug(`First assignment: ${Array.from(collected[0]!.assignment.entries()).map(([slot, node]) => `${slot}=${node.nodeKey.file}#${node.nodeKey.heading}`).join(", ")}`);