/** * AST-Based Chunking Engine * * Implements semantic code chunking using Tree-sitter AST parsing. * Extracts functions, classes, methods, and other semantic units with * rich metadata including signatures, docstrings, and decorators. * * Inspired by claude-context-local's AST-based chunking approach. * * Features: * - Language-specific node type detection * - Rich metadata extraction (name, signature, docstring, decorators) * - Parent-child relationship tracking * - Semantic tag generation * - Fallback to character-based chunking for unsupported languages * * @module astChunking */ import { type ASTLanguage } from './treeSitterParser.js'; import type { ChunkWithLines } from './chunking.js'; /** * Chunk type classification */ export type ChunkType = 'function' | 'class' | 'method' | 'interface' | 'type' | 'enum' | 'struct' | 'trait' | 'impl' | 'module' | 'variable' | 'import' | 'other'; /** * Rich metadata extracted from AST nodes */ export interface ChunkMetadata { /** Chunk type classification */ type: ChunkType; /** Name of the function/class/method */ name?: string; /** Full function/method signature */ signature?: string; /** Docstring or comment content */ docstring?: string; /** List of decorators/annotations */ decorators?: string[]; /** Parent name (e.g., class name for methods) */ parentName?: string; /** Parent type (e.g., 'class' for methods) */ parentType?: ChunkType; /** Semantic tags for search boosting */ tags?: string[]; /** Programming language */ language: ASTLanguage; /** Whether the function/method is async */ isAsync?: boolean; /** Whether the item is exported */ isExport?: boolean; /** Whether the item is static */ isStatic?: boolean; /** Access modifier (public/private/protected) */ visibility?: 'public' | 'private' | 'protected'; /** Number of parameters (for functions/methods) */ paramCount?: number; /** Return type (if available) */ returnType?: string; /** Generic type parameters */ genericParams?: string[]; } /** * A chunk of code with metadata */ export interface ASTChunk extends ChunkWithLines { /** Rich metadata extracted from AST */ metadata: ChunkMetadata; } /** * Configuration for AST-based chunking */ export interface ASTChunkOptions { /** Target chunk size in characters (default: 4000) */ chunkSize: number; /** Overlap size for very large chunks (default: 200) */ chunkOverlap: number; /** Maximum chunk size before forcing a split (default: 8000) */ maxChunkSize: number; /** Include imports as separate chunks (default: false) */ includeImports: boolean; } /** * Default AST chunking options */ export declare const DEFAULT_AST_OPTIONS: ASTChunkOptions; /** * Extract AST-based chunks from source code * * @param sourceCode - Source code to chunk * @param filePath - File path for language detection * @param options - Chunking options * @returns Array of AST chunks with metadata, or null if AST parsing fails */ export declare function extractASTChunks(sourceCode: string, filePath: string, options?: Partial): Promise; /** * Convert AST chunks to ChunkWithLines format (for compatibility with existing code) * * @param astChunks - AST chunks with metadata * @returns Array of ChunkWithLines without metadata */ export declare function astChunksToChunksWithLines(astChunks: ASTChunk[]): ChunkWithLines[]; /** * Get supported languages for AST chunking * * @returns Array of supported language names */ export declare function getSupportedASTLanguages(): ASTLanguage[]; //# sourceMappingURL=astChunking.d.ts.map