/** * Symbol Graph Service * * High-level API for code navigation operations: * - go_to_definition: resolve where a symbol is declared * - get_references: find all usages of a symbol * - get_dependencies: file import graph (BFS, with depth limit) * - list_definitions: filtered browse of all symbols in a project * * Also owns centrality recomputation (triggered after ETL completes). */ import { type ActiveGraphDiagnostics } from "@massa-th0th/shared"; import { type DefinitionLookupResult } from "./definition-lookup.js"; import { type ArchitectureMap } from "./architecture.js"; /** Public edge-type names surfaced by the query layer. */ export type EdgeType = "call" | "data_flow" | "http_call" | "emit" | "listen" | "import" | "type_ref" | "extend" | "implement"; export interface EdgeQueryOptions { /** Filter by edge type(s). Omit for all types. */ types?: EdgeType[]; /** Source symbol FQN ('rel/path.ts#Name') — restricts to outgoing edges. */ fromSymbol?: string; /** Target symbol FQN — restricts to incoming edges. */ toSymbol?: string; /** Constrain to edges originating from a specific file. */ fromFile?: string; /** Edge direction relative to fromSymbol/toSymbol. Default 'both'. */ direction?: "outgoing" | "incoming" | "both"; limit?: number; } export interface EdgeResult { fromFile: string; fromLine: number; symbolName: string; refKind: string; targetFqn?: string; /** Typed-edge metadata (route, event, paramIndex, callerFqn). */ meta?: Record | null; } export interface DefinitionResult { fqn: string; name: string; kind: string; file: string; lineStart: number; lineEnd: number; exported: boolean; docComment?: string; snippet?: string; centralityScore: number; } export interface ReferenceResult { fromFile: string; fromLine: number; refKind: string; symbolName: string; targetFqn?: string; context?: string; } export interface DependencyNode { file: string; depth: number; } export interface DependencyEdge { from: string; to: string; specifier: string; importedNames: string[]; isExternal: boolean; } export interface DependencyGraph { nodes: DependencyNode[]; edges: DependencyEdge[]; } export interface CentralityResult { filePath: string; score: number; updatedAt: number; } export interface ListDefinitionsOptions { kind?: string[]; file?: string; exportedOnly?: boolean; search?: string; limit?: number; } export interface ProjectMapResult extends ActiveGraphDiagnostics { projectId: string; stats: { files: number; chunks: number; symbols: number; status: string; lastIndexedAt: string | null; }; topCentralFiles: CentralityResult[]; symbolsByKind: Record; filesByLanguage: Record; recentFiles: Array<{ filePath: string; indexedAt: string | null; }>; /** Counts of typed structural edges grouped by ref_kind (D1). */ edgesByKind?: Record; /** Files grouped by top-level package/module boundary. */ packages?: ArchitectureMap["packages"]; /** Bootstrap / entry-point candidates. */ entryPoints?: ArchitectureMap["entryPoints"]; /** API surface: HTTP routes / handlers. */ routes?: ArchitectureMap["routes"]; /** Most-depended-on files (centrality + in-degree + symbol count). */ hotspots?: ArchitectureMap["hotspots"]; /** De-facto modules from community detection over the file-import graph. */ communities?: ArchitectureMap["communities"]; /** De-facto layers inferred from community structure + fan-in/out. */ layers?: ArchitectureMap["layers"]; } export interface GetProjectMapOptions { centralityLimit?: number; recentLimit?: number; /** @internal Deterministic concurrency sensor used by DB-backed tests. */ afterGenerationCaptured?: (generationId: string | null) => void | Promise; } export declare class SymbolGraphService { private readonly identityLookup; private static instance; private projectRootCache; /** * Maximum entries retained in projectRootCache. Without a cap, an adversarial * caller cycling distinct projectIds grows the map for the process lifetime. * Map preserves INSERTION order in JS; we promote a key to most-recently-used * on GET via delete+set, and evict the oldest key on SET while over the cap. * Mirrors ReadFileTool's FILE_CACHE_MAX_ENTRIES / evictOldest pattern. */ private readonly PROJECT_ROOT_CACHE_MAX_ENTRIES; constructor(identityLookup?: import("./definition-lookup.js").DefinitionLookupService); static getInstance(): SymbolGraphService; /** Returns true if the project has any indexed symbols. */ hasData(projectId: string): Promise; /** * Find where a symbol is defined. * * Disambiguation order when multiple results: * 1. Symbols defined in `fromFile` (same-file priority) * 2. Symbols defined in direct imports of `fromFile` * 3. All other results, sorted by centrality desc */ goToDefinition(projectId: string, symbolName: string, fromFile?: string, resolvedLookup?: DefinitionLookupResult): Promise; /** Stable service-level identity result for callers that need ambiguity details. */ lookupDefinition(projectId: string, query: string): Promise; /** * Find all usage sites of a symbol. * * Resolves via FQN if provided, otherwise searches by name. * Enriches top results with 3-line code context. */ getReferences(projectId: string, symbolName: string, fqn?: string, resolvedLookup?: DefinitionLookupResult): Promise; /** * Query typed structural edges (CALLS / IMPORTS / DATA_FLOWS / HTTP_CALLS / * EMITS / LISTENS) with optional filtering by edge type, source/target * symbol, file, and direction. * * Backed by `symbol_references` rows with typed `ref_kind` values + `meta`. * Designed for later trace_path / impact_analysis traversal. */ getEdges(projectId: string, opts?: EdgeQueryOptions): Promise; /** * BFS over the import graph to build a file dependency tree. * maxDepth default = 3 to avoid graph explosion. */ getDependencies(projectId: string, filePath: string, maxDepth?: number): Promise; listDefinitions(projectId: string, opts?: ListDefinitionsOptions): Promise; getTopCentralFiles(projectId: string, limit?: number): Promise; /** * Aggregate view of a project — stats, central files, symbol breakdown by * kind, file count by language extension, and most-recently indexed files. * Consumes symbol_files, symbol_definitions, and workspace metadata. */ getProjectMap(projectId: string, opts?: GetProjectMapOptions): Promise; /** * Compute the architecture map (D4): packages, entry points, routes, * hotspots, layers, and communities. Best-effort — returns null when there * isn't enough graph data to produce a meaningful map. * * Isolation: each repo call is awaited separately and any thrown error * propagates to the caller, which catches and logs it, leaving the existing * project_map response intact. */ private computeArchitectureMapSafe; /** * Recompute PageRank scores for all files in the project. * Should be called after a full index completes. */ recomputeCentrality(projectId: string): Promise; private toDefinitionResult; /** * Read lines [lineStart, lineEnd] from a relative project path. * Used to enrich definition results with code previews. */ private readSnippet; /** Read N lines of context around a given line number from a relative path. */ private readContext; /** Resolve a relative path against the project root (best-effort). */ private resolveToAbsolute; private getProjectRoot; /** * Evict the oldest (first-inserted) entries from projectRootCache until it is * under PROJECT_ROOT_CACHE_MAX_ENTRIES. Called BEFORE the new insert so the cap * is honored post-insert with a single iteration. */ private evictOldestProjectRoot; } export declare const symbolGraphService: SymbolGraphService; //# sourceMappingURL=symbol-graph.service.d.ts.map