/** * Code Index Database using SQLite (better-sqlite3) + FTS5 * Replaces LokiJS + FlexSearch with durable, transactional storage. */ import Database from 'better-sqlite3'; import type { CompleteProjectTaskResult, CreateProjectTaskInput, ListProjectTasksOptions, ListProjectTasksTreeNode, ProjectTask, ProjectTaskDeleteMode } from './types/projectTask.js'; import { EnhancedFunctionMetadata, FunctionMetadata, SearchResult, SearchOptions, SchemaDefinition, SchemaIndexMetadata, SchemaUsage } from './types.js'; import { WhitelistEntry, WhitelistType, WhitelistStatus, WhitelistSuggestion } from './types/whitelist.js'; export declare class CodeIndexDB { private static instance; /** Subclasses (e.g. EnhancedCodeIndexDB) need access for extra tables without `as any`. */ protected db: Database.Database; /** Public access to raw SQLite handle — used by ledger writes from external surfaces. */ get rawDb(): Database.Database; private dbPath; private isInitialized; private initializePromise; private functionsAdapter; private whitelistAdapter; private auditResultsAdapter; private analyzerConfigAdapter; private codeMapAdapter; private schemaAdapter; private schemaUsageAdapter; private tasksAdapter; private conventionsAdapter; private fileChurnAdapter; private functionChurnAdapter; private pairHistoryAdapter; private hotspotScoresAdapter; private graphCacheAdapter; private taskRepository; private stmts; private static readonly SCHEMA_VERSION; constructor(dbPath?: string); static getInstance(dbPath?: string): CodeIndexDB; /** Reset the singleton — used by tests that need a fresh in-memory instance. */ static resetInstance(): void; initialize(): Promise; private initializeInternal; private runMigrations; private createSchema; private maybeMigrateFromLokiJS; private ensureInitialized; private rowToFunction; private functionToRow; registerFunction(func: FunctionMetadata | EnhancedFunctionMetadata): Promise; registerFunctions(functions: (FunctionMetadata | EnhancedFunctionMetadata)[]): Promise<{ success: boolean; registered: number; failed: number; errors?: Array<{ function: string; error: string; }>; }>; syncFileIndex(filePath: string, currentFunctions: (FunctionMetadata | EnhancedFunctionMetadata)[]): Promise<{ added: number; updated: number; removed: number; }>; updateDependencyGraph(filePath?: string): Promise; getTransitiveDependencies(functionName: string, maxDepth?: number): Promise>; getTransitiveCallers(functionName: string, maxDepth?: number): Promise>; detectCircularDependencies(): Promise>; calculateDependencyDepths(): Promise; searchFunctions(options: SearchOptions): Promise; private executeCompiledSearch; private rowToFunctionDoc; findDefinition(name: string, filePath?: string): Promise; getAllFunctions(): Promise; getStats(): Promise<{ totalFunctions: number; languages: Record; topDependencies: Array<{ name: string; count: number; }>; filesIndexed: number; lastUpdated: Date; }>; /** Get graph statistics — delegates to graph/callGraph.ts (Spec 14 R1). */ getGraphStats(): import('./types.js').GraphStats; clearIndex(): Promise; close(): Promise; synchronizeFile(filePath: string): Promise<{ added: number; updated: number; removed: number; } | null>; bulkCleanup(): Promise<{ scannedCount: number; removedCount: number; removedFiles: string[]; errors: Array<{ file: string; error: string; }>; }>; deepSync(projectRoot?: string, progressCallback?: (progress: { current: number; total: number; file: string; }) => void): Promise<{ syncedFiles: number; addedFunctions: number; updatedFunctions: number; removedFunctions: number; errors: Array<{ file: string; error: string; }>; }>; /** * For a set of file paths, re-parse each file and return only functions * whose content_hash differs from the stored value (plus new functions). * Deleted functions are removed from the index. * * Returns the list of changed/new function metadata for scoped analysis, * and the set of file paths that were actually touched. */ detectChangedFunctions(filePaths: string[]): Promise<{ changedFunctions: EnhancedFunctionMetadata[]; deletedFunctions: EnhancedFunctionMetadata[]; changedFilePaths: string[]; errors: Array<{ file: string; error: string; }>; }>; /** * Given a project root, detect all indexed files whose mtime is newer than * the stored last_modified timestamp. Returns file paths for further processing. */ detectModifiedFiles(projectRoot: string): Promise; /** * Get content hashes for a set of file paths. Returns a map: * file_path → { name → content_hash } */ getContentHashesForFiles(filePaths: string[]): Map>; private mergeFilters; private applyFilters; private excludeTermsFromResults; private initializeDefaultWhitelists; getWhitelist(type?: WhitelistType, status?: WhitelistStatus): Promise; addWhitelistEntry(entry: Omit): Promise; updateWhitelistStatus(name: string, status: WhitelistStatus): Promise; isWhitelisted(name: string, type: WhitelistType): boolean; detectWhitelistCandidates(): Promise; storeAuditResults(auditResult: any, projectPath: string): Promise; getAuditResults(auditId: string): Promise; getMostRecentAuditResults(projectPath?: string, resultScope?: 'full' | 'scoped'): Promise; hasOpenTaskByFingerprint(fingerprint: string | null | undefined): boolean; private cleanupExpiredAudits; storeAnalyzerConfig(analyzerName: string, config: Record, options?: { projectPath?: string; isGlobal?: boolean; metadata?: any; }): Promise; getAnalyzerConfig(analyzerName: string, projectPath?: string): Promise | null>; getAllAnalyzerConfigs(projectPath?: string): Promise>; deleteAnalyzerConfig(analyzerName: string, options?: { projectPath?: string; isGlobal?: boolean; }): Promise; resetAnalyzerConfigs(projectPath?: string): Promise; storeCodeMapSection(mapId: string, sectionType: string, content: string, metadata?: any): Promise; getCodeMapSection(mapId: string, sectionType: string): Promise<{ content: string; metadata: any; } | null>; listCodeMapSections(mapId: string): Promise>; clearOldCodeMaps(olderThanHours?: number): Promise; deleteCodeMap(mapId: string): Promise; storeSchema(schema: SchemaDefinition): Promise; getSchema(schemaId: string): Promise; getAllSchemas(): Promise>; deleteSchema(schemaId: string): Promise; recordSchemaUsage(usage: SchemaUsage, schemaId?: string): Promise; /** * Clear all schema_usage entries for a given file path. * Used for idempotent per-file writes during indexing — stale entries * from a previous scan are removed before fresh references are inserted. */ clearSchemaUsageForFile(filePath: string): void; getSchemaUsage(options?: { schemaId?: string; tableName?: string; filePath?: string; functionName?: string; usageType?: string; }): Promise; findFunctionsUsingTable(tableName: string): Promise>; getSchemaStats(): Promise<{ totalSchemas: number; totalTables: number; totalUsagePatterns: number; mostUsedTables: Array<{ tableName: string; usageCount: number; }>; usageByType: Record; }>; searchWithSchemaContext(query: string, options?: SearchOptions & { includeSchemaUsage?: boolean; }): Promise; }>; private getTaskRepository; createProjectTask(input: CreateProjectTaskInput): Promise; getProjectTask(taskId: string): Promise; listProjectTasks(projectPath: string, options?: ListProjectTasksOptions): Promise; listProjectTasksTree(projectPath: string, options?: Omit): Promise; listActionableProjectTasks(projectPath: string, options?: Omit): Promise; completeProjectTask(taskId: string): Promise; updateProjectTask(taskId: string, patch: unknown): Promise; deleteProjectTask(taskId: string, mode?: ProjectTaskDeleteMode): Promise; /** Upsert a key-value pair in the meta table. */ setMeta(key: string, value: string): void; /** Retrieve a value from the meta table, or null if absent. */ getMeta(key: string): string | null; /** Store per-file provenance context in the meta table. */ storeFileProvenance(filePath: string, provenanceData: { dbProvenanced: Array<{ identifier: string; reason: string; source: string; chain?: string[]; }>; validatorProvenanced: Array<{ identifier: string; reason: string; source: string; chain?: string[]; }>; }): void; /** Retrieve per-file provenance context, or null if not stored. */ getFileProvenance(filePath: string): { dbProvenanced: Array<{ identifier: string; reason: string; source: string; chain?: string[]; }>; validatorProvenanced: Array<{ identifier: string; reason: string; source: string; chain?: string[]; }>; } | null; /** Store the inferred receiver set as a meta record. */ storeInferredReceivers(inferred: Array<{ identifier: string; file: string; reason: string; }>): void; /** Retrieve the inferred receiver set, or null if not stored. */ getInferredReceivers(): Array<{ identifier: string; file: string; reason: string; }> | null; /** Import coverage entries, replacing any existing data for the given basis. */ importCoverageData(entries: Array<{ functionName: string; filePath: string; lineNumber: number; basis: 'static-reach' | 'measured'; covered: boolean; source?: string; }>): void; /** Get all coverage entries for a given basis. */ getCoverageByBasis(basis: 'static-reach' | 'measured'): Array<{ functionName: string; filePath: string; lineNumber: number; basis: string; covered: boolean; source: string | null; importedAt: string | null; }>; /** Clear coverage data, optionally scoped to a single basis. */ clearCoverageData(basis?: 'static-reach' | 'measured'): void; /** Check if measured coverage data is stale (older than the last full sync). */ isCoverageStale(): boolean; /** Get coverage rate by risk decile for the coverage report. */ getCoverageByRiskDecile(decileCount?: number): Array<{ decile: number; covered: number; total: number; rate: number; }>; /** Get untested functions in the top risk decile. */ getUntestedTopDecile(topDecile?: number): Array<{ functionName: string; filePath: string; lineNumber: number; riskScore: number; basis: string; }>; } //# sourceMappingURL=codeIndexDB.d.ts.map