/** * Symbol-aware code chunker for embedding indexing. * * Chunks code by semantic boundaries (functions, classes, methods) * rather than fixed line counts. Reuses graph symbol data when available. * * Fallback: line-based chunking with overlap when symbol data unavailable. */ export interface CodeChunk { /** Unique ID for the chunk. */ id: string; /** File path relative to project root. */ filePath: string; /** Start line (1-based). */ startLine: number; /** End line (1-based, inclusive). */ endLine: number; /** The actual text content of the chunk. */ content: string; /** Symbol name if this chunk corresponds to a symbol. */ symbolName?: string; /** Symbol kind (function, class, method, etc). */ symbolKind?: string; } export interface ChunkerConfig { /** Max chunk size in characters. Larger symbols get split. Default: 2000. */ maxChunkSize?: number; /** Line-based chunk size (fallback). Default: 50 lines. */ linesPerChunk?: number; /** Overlap lines between chunks (fallback). Default: 10. */ overlapLines?: number; } export interface SymbolInfo { name: string; kind: string; startLine: number; endLine: number; } /** * Chunk a file's content using symbol boundaries. * Falls back to line-based chunking when no symbols are provided. */ export declare function chunkFile(filePath: string, content: string, symbols?: SymbolInfo[], config?: ChunkerConfig): CodeChunk[]; /** * Batch-chunk multiple files at once. */ export declare function chunkFiles(files: Array<{ filePath: string; content: string; symbols?: SymbolInfo[]; }>, config?: ChunkerConfig): CodeChunk[]; export interface RollupConfig { /** * Chunks smaller than this many tokens are candidates for merging * with their neighbour. Default: 50. */ minChunkTokens?: number; /** * Upper bound after merging — we will stop growing a chunk once * adding the next neighbour would exceed this. Default: 400. */ maxChunkTokens?: number; /** * Token estimator. Default uses `char/4` which is a reasonable * proxy for BPE-style tokenizers (cl100k, o200k) on source code * without pulling in a 5MB tokenizer table. */ estimateTokens?: (text: string) => number; } /** `char/4` token estimate — cheap, dependency-free, accurate within ~10-15% for code. */ export declare function estimateTokensCharQuarter(text: string): number; /** * Rolls up small adjacent chunks **from the same file** into larger * merged chunks, preserving line contiguity. Improves embedding * quality by avoiding hundreds of tiny helper-function chunks that * dominate the index with near-identical content. * * Rules: * 1. Iterate chunks in original order; group by file. * 2. Merge a chunk with the previous merged group iff: * • they are in the same file, * • their line ranges are contiguous (prev.endLine + 1 == cur.startLine), * • at least one of them is under `minChunkTokens`, * • merging doesn't exceed `maxChunkTokens`. * 3. When symbols differ, the merged chunk drops `symbolName`/`symbolKind` * because it no longer represents a single symbol. * * The input array is not mutated. */ export declare function rollupSmallChunks(chunks: CodeChunk[], config?: RollupConfig): CodeChunk[]; //# sourceMappingURL=chunker.d.ts.map