UNPKG

mnemos-coder

Version:

CLI-based coding agent with graph-based execution loop and terminal UI

136 lines 3.44 kB
/** * Advanced Symbol-Aware AST Chunker * Chunks code by symbols (functions, classes, structures, control blocks) * Respects embedding model context length constraints */ import Parser from 'tree-sitter'; export interface SymbolChunk { id: string; symbolType: 'function' | 'class' | 'interface' | 'struct' | 'enum' | 'condition_block' | 'loop_block' | 'import' | 'variable' | 'method' | 'constructor' | 'other'; name?: string; signature?: string; startLine: number; endLine: number; content: string; isOverlapped: boolean; chunkIndex?: number; totalChunks?: number; metadata: { language: string; nodeType: string; parentSymbol?: string; parameters?: string[]; returnType?: string; modifiers?: string[]; complexity?: number; nestedLevel: number; }; } export interface ChunkingOptions { maxTokens: number; preserveSignatures: boolean; includeContext: boolean; contextLines: number; minChunkSize: number; splitLargeFunctions: boolean; includeControlFlow: boolean; overlapRatio: number; } export declare class SymbolAwareChunker { private options; private readonly tokensPerChar; constructor(options?: Partial<ChunkingOptions>); /** * AST 노드를 심볼 단위로 청킹 */ chunkBySymbols(rootNode: Parser.SyntaxNode, content: string, language: string, filePath: string): SymbolChunk[]; /** * 재귀적으로 심볼 청크를 추출 */ private extractSymbolChunks; /** * 심볼 타입 결정 */ private getSymbolType; /** * 제어 흐름 노드인지 확인 */ private isControlFlowNode; /** * 심볼 청크 생성 */ private createSymbolChunk; /** * 제어 흐름 청크 생성 */ private createControlFlowChunk; /** * 큰 심볼을 오버랩으로 분할 */ private splitLargeSymbolWithOverlap; /** * 오버랩 라인 수 계산 */ private calculateOverlapLines; /** * 심볼 이름 추출 */ private getSymbolName; /** * 심볼 시그니처 추출 */ private getSymbolSignature; /** * 함수 시그니처 추출 */ private extractFunctionSignature; /** * 클래스 시그니처 추출 */ private extractClassSignature; /** * 심볼 메타데이터 추출 */ private extractSymbolMetadata; /** * 매개변수 추출 */ private extractParameters; /** * 반환 타입 추출 */ private extractReturnType; /** * 수정자 추출 */ private extractModifiers; /** * 복잡도 계산 (순환 복잡도의 간단한 근사치) */ private calculateComplexity; /** * 큰 심볼인지 확인 */ private isLargeSymbol; /** * 청크 ID 생성 */ private createChunkId; /** * 후처리 (중복 제거, 정렬 등) */ private postProcessChunks; /** * 청크를 데이터베이스 형식으로 변환 */ convertToDbFormat(symbolChunks: SymbolChunk[], filePath: string): any[]; /** * 심볼 타입을 데이터베이스 청크 타입으로 매핑 */ private mapSymbolTypeToChunkType; /** * 내용 해시 생성 */ private createHash; } //# sourceMappingURL=SymbolAwareChunker.d.ts.map