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