import type { Vault } from "./vault.js"; /** * v3.9.0-rc.35 (external-audit AS#5 / R-B) — hard cap on the number of notes * the wikilink graph ingests, mirroring the `MAX_VISITED` cap on `find_path` * BFS (rc.34 R-5). `obsidian_get_communities` is always-registered and reads * EVERY `.md` to build a full adjacency map + run Louvain; on a pathological / * very large vault that is unbounded I/O + memory for a single tool call. We * cap the node set (newest-first by the vault's own listing order) so the * worst case is bounded regardless of vault size — defense-in-depth, not a * correctness limit (real vaults are far below the cap; Louvain itself is * already bounded by `MAX_PASSES`). */ export declare const MAX_GRAPH_NODES = 50000; export interface WikilinkGraph { /** Node ID = vault-relative path (forward-slash normalized). */ nodes: string[]; /** Adjacency: nodeId → neighborNodeId → edge weight. Symmetric. */ adjacency: Map>; /** Total edge weight × 2 (= sum of all edge weights, undirected). */ totalWeight2m: number; /** Degree per node (sum of incident edge weights). */ degree: Map; } export interface CommunityResult { /** Number of distinct communities found. */ community_count: number; /** Modularity Q ∈ [-0.5, 1] of the final partition. */ modularity: number; /** Number of greedy passes run. */ iterations: number; /** * v3.9.0-rc.15 — true if Louvain reached a stable partition (a pass made no * moves); false if it hit the `MAX_PASSES` cap with moves still pending (the * partition is valid but may be sub-optimal — callers can surface this). */ converged: boolean; /** community_id → member note paths, sorted by in-community degree desc. */ communities: Array<{ id: number; size: number; /** Sorted by descending in-community degree (= "central" first). */ members: string[]; /** Single most-central member (highest in-community degree). */ representative: string; }>; /** Inverted index: note path → community id. */ membership: Map; } /** * Build the undirected wikilink graph from the vault. Each edge = a * resolved wikilink (we ignore broken ones — they wouldn't be part of * the graph anyway). Bidirectional links contribute weight 2 (one per * direction); unidirectional contribute weight 1. * * Resolution: we use case-insensitive basename match (matches the * existing tools' behavior). A wikilink `[[Foo]]` resolves to a note * named `Foo.md` if exactly one such note exists; otherwise to the * first match by walk order. */ export declare function buildWikilinkGraph(vault: Vault): Promise; /** * Greedy modularity-based community detection. Single-phase Louvain. * * Returns the partition + modularity + community summary. */ export declare function detectCommunities(graph: WikilinkGraph): CommunityResult; /** * Newman–Girvan modularity Q = Σ_ij [A_ij − k_i·k_j/2m]·δ(c_i,c_j) / 2m, decomposed as * Q = Σ_c [ in_c/2m − (tot_c/2m)² ] where `in_c` is the intra-community edge weight (the * adjacency rep counts each undirected edge twice) and `tot_c` the community's degree sum. * * v3.10.0-rc.43 (M7) — FIX: the prior implementation summed the null-model penalty * `(k_i·k_j/2m)` ONLY over ADJACENT same-community pairs (it lived inside the `for (…of * neighbors)` loop), but the standard formula penalizes ALL same-community pairs incl. * non-adjacent ones (where A_ij=0 but −k_i·k_j/2m still applies). The truncated penalty * inflated Q and could rank a degenerate single-community partition ABOVE the correct * split. Now the penalty is the exact Σ_c tot_c² over per-community degree sums. */ export declare function computeModularity(graph: WikilinkGraph, community: Map): number; //# sourceMappingURL=communities.d.ts.map