Skip to content

classifyImpact

Returns the files affected by changing the given file, classified into direct references (one hop) and transitive references (two or more hops). Direct references also carry a reference count.

getImpactSet returns a flat list, so it cannot distinguish “files you must review directly” from “files worth a sanity check”. classifyImpact separates impact into two tiers and attaches the closest direct file (via) on each transitive entry, which makes review prioritization and path visualization easier.

The MCP impact-analysis tool formats the output of this function directly.

function classifyImpact(
graph: ContextGraph,
filePath: string,
): {
directlyAffected: { file: string; references: number }[];
transitivelyAffected: { file: string; via: string }[];
};
ParameterTypeRequiredDescription
graphContextGraphThe graph built by buildContextGraph.
filePathstringThe path of the file whose impact you want to classify.

Returns an object.

  • directlyAffected — Files that reference filePath directly. references is the reference count within the same source (the total number of times that file links to filePath). Sorted by file path.
  • transitivelyAffected — Files reached indirectly rather than directly. via is the closest “directly affected file” on the path. Sorted by file path.
import { buildContextGraph, classifyImpact, loadDocuments } from "@contextlint/core";
const documents = loadDocuments(["docs/**/*.md"]);
const graph = buildContextGraph(documents);
const impact = classifyImpact(graph, "docs/architecture.md");
console.log(`Direct impact: ${impact.directlyAffected.length}`);
for (const item of impact.directlyAffected) {
console.log(` - ${item.file} (${item.references} refs)`);
}
console.log(`Transitive impact: ${impact.transitivelyAffected.length}`);
for (const item of impact.transitivelyAffected) {
console.log(` - ${item.file} (via: ${item.via})`);
}