/** * Spec 14 R1, R2 — Call Graph Construction, Centrality, and Risk Ranking * * Builds a weighted call graph from the `function_calls` table, computes * PageRank and betweenness centrality, and produces a risk ranking. * * All advisory — zero violations. Reports and annotations only. */ import type Database from 'better-sqlite3'; import type { RiskEntry, GraphStats } from '../types.js'; export interface CallGraph { /** Adjacency: nodeId → (neighborId → edgeWeight) */ adjacency: Map>; /** Set of all node IDs in the graph */ nodeIds: Set; /** nodeId → function name */ nodeNames: Map; /** nodeId → file path */ nodePaths: Map; } export interface CentralityScores { pageRank: Map; betweenness: Map; /** Number of pivots sampled (Brandes-Pich when > 0) */ betweennessPivotCount: number; } /** * Build a weighted call graph from the `function_calls` table. * * Resolves `callee_name` TEXT → `functions.id` via name join. Edge weight * is the count of call sites between the same (caller, callee) pair. */ export declare function buildCallGraph(db: Database.Database): { graph: CallGraph; unresolvedCount: number; unresolvedShare: number; }; /** * Build a call graph from the persistent `graph_cache` table (fast path). */ export declare function buildCallGraphFromCache(db: Database.Database): { graph: CallGraph; unresolvedCount: number; unresolvedShare: number; }; /** * Populate `graph_cache` with call and import graph edges. * Called after a full sync or scoped sync. */ export declare function populateCallGraphCache(db: Database.Database): void; /** * Compute PageRank on a weighted directed graph. * * Standard iterative algorithm: damping factor 0.85, convergence 1e-6, * max 100 iterations. */ export declare function computePageRank(adjacency: Map>, nodeIds: Set, damping?: number, convergence?: number): Map; /** * Compute Brandes betweenness centrality. * * When `nodeCount <= 2000`, uses exact Brandes. * Above that, uses Brandes-Pich pivot sampling with `BETWEENNESS_PIVOT_COUNT` pivots. * Returns scores and the number of pivots sampled (0 = exact). */ export declare function computeBetweenness(adjacency: Map>, nodeIds: Set): { scores: Map; pivotCount: number; }; /** * Compute a risk score for every function. * * risk = max(pageRank percentile, betweenness percentile) * × complexity percentile * × (1 + untested) — where untested = 1 if true, 0 otherwise */ export declare function computeRisk(db: Database.Database, adjacency: Map>, nodeIds: Set, nodeNames: Map, nodePaths: Map): RiskEntry[]; export declare function getGraphStats(db: Database.Database): GraphStats; //# sourceMappingURL=callGraph.d.ts.map