import { ChunkMetadata, RawChunk } from "../../core/dist/index.js"; //#region packages/chunker/src/call-graph-extractor.d.ts /** * Call-graph extractor using tree-sitter AST. * * Extracts function-level call sites from parsed code, producing * caller→callee edges for blast-radius and dependency analysis. */ interface CallEdge$1 { /** File containing the call */ callerFile: string; /** Function/method making the call (or '' for top-level) */ callerName: string; /** Name of the function/method being called */ calleeName: string; /** 1-based line number of the call site */ line: number; } /** * Extract call edges from a source file using tree-sitter AST. * Prefers WASM runtime; falls back to native tree-sitter. * Returns null if neither runtime is available or doesn't support the language. */ declare function extractCallEdges(content: string, filePath: string): CallEdge$1[] | null; //#endregion //#region packages/chunker/src/chunker.interface.d.ts /** * Interface for content chunkers. * Each chunker splits a specific content type into searchable chunks. */ interface IChunker { /** Split content into chunks */ chunk(content: string, metadata: ChunkMetadata): RawChunk[]; } //#endregion //#region packages/chunker/src/chunker-factory.d.ts /** * Create the appropriate chunker for a file extension. * * Uses WASM tree-sitter AST-based chunking when available. * Falls back to regex-based CodeChunker. * * **Breaking change**: Now returns `Promise` because WASM init is async. */ declare function createChunker(fileExtension: string): Promise; /** * Create a chunker synchronously (legacy API). * Uses whatever runtime is already initialized. */ declare function createChunkerSync(fileExtension: string): IChunker; //#endregion //#region packages/chunker/src/code-chunker.d.ts declare class CodeChunker implements IChunker { private readonly maxChunkSize; constructor(options?: { maxChunkSize?: number; }); chunk(content: string, metadata: ChunkMetadata): RawChunk[]; private findDeclarationBoundaries; private fallbackChunk; private splitByLines; private getLineNumber; } //#endregion //#region packages/chunker/src/extractors/call-extractor.d.ts /** * AST-based call extractor. * * Replaces regex-based call graph analysis with tree-sitter AST queries. * Returns `CallEdge[]` compatible with the existing call-graph-extractor. */ interface CallEdge { callerFile: string; callerName: string; calleeName: string; line: number; } /** * Extract call edges from source code using AST queries. * * @param content - The source code to analyze. * @param ext - The file extension (e.g., `.ts`, `.py`). * @param filePath - The file path for the returned CallEdge records. * @returns Array of extracted call edges, or empty array if language unsupported. */ declare function extractCalls(content: string, ext: string, filePath?: string): Promise; //#endregion //#region packages/chunker/src/extractors/types.d.ts /** * Shared type definitions for AST extractors. * * These types match the interfaces in `@aikit/analyzers/types.ts` so that * downstream consumers can seamlessly switch from regex-based to AST-based extraction. */ interface SymbolInfo { name: string; kind: 'function' | 'class' | 'interface' | 'type' | 'const' | 'enum' | 'variable' | 'method'; exported: boolean; filePath: string; line: number; signature?: string; /** Return type annotation (e.g. "Promise", "string") */ returnType?: string; /** First line of JSDoc/docstring */ jsdoc?: string; /** Decorator names (e.g. ["@Controller('/api')", "@Injectable"]) */ decorators?: string[]; /** Condensed body for interfaces/types (e.g. "{ id: string; name: string }") */ typeBody?: string; } interface ImportInfo { source: string; specifiers: string[]; filePath: string; isExternal: boolean; confidence: 'high' | 'medium' | 'low'; } interface PatternMatch { pattern: string; description: string; locations: string[]; confidence: 'high' | 'medium' | 'low'; } interface EntryPoint { name: string; type: 'lambda-handler' | 'main' | 'bin' | 'server' | 'cli' | 'test' | 'cdk-construct'; filePath: string; trigger?: string; } //#endregion //#region packages/chunker/src/extractors/entry-point-detector.d.ts /** * Detect entry points from source code using AST queries. * * @param content - The source code to analyze. * @param ext - The file extension (e.g., `.ts`, `.py`). * @param filePath - The file path for the returned EntryPoint records. * @returns Array of detected entry points, or empty array if language unsupported. */ declare function detectEntryPoints(content: string, ext: string, filePath?: string): Promise; //#endregion //#region packages/chunker/src/extractors/import-extractor.d.ts /** * Extract imports from source code using AST queries. * * @param content - The source code to analyze. * @param ext - The file extension (e.g., `.ts`, `.py`). * @param filePath - The file path for the returned ImportInfo records. * @returns Array of extracted imports, or empty array if language unsupported. */ declare function extractImports(content: string, ext: string, filePath?: string): Promise; //#endregion //#region packages/chunker/src/extractors/pattern-detector.d.ts /** * Detect design patterns from source code using AST queries. * * @param content - The source code to analyze. * @param ext - The file extension (e.g., `.ts`, `.py`). * @param filePath - The file path for location info. * @returns Array of detected patterns, or empty array if language unsupported. */ declare function detectPatterns(content: string, ext: string, filePath?: string): Promise; //#endregion //#region packages/chunker/src/extractors/scope-resolver.d.ts /** * AST-based scope resolver. * * NEW capability: resolves the enclosing scope (function/class/module) for any * AST node. Used by other extractors to determine caller context. */ interface ScopeInfo { /** Name of the enclosing scope (or '' for top-level). */ name: string; /** The scope type (function, class, module). */ type: 'function' | 'class' | 'module'; /** 1-based start line of the scope. */ line: number; } /** * Resolve the enclosing scope chain for a given line in source code. * * @param content - The source code to analyze. * @param ext - The file extension. * @param targetLine - 1-based line number to resolve scope for. * @returns Array of scopes from innermost to outermost, ending with module. */ declare function resolveScopes(content: string, ext: string, targetLine: number): Promise; //#endregion //#region packages/chunker/src/extractors/symbol-extractor.d.ts /** * Extract symbols from source code using AST queries. * * @param content - The source code to analyze. * @param ext - The file extension (e.g., `.ts`, `.py`). * @param filePath - The file path for the returned SymbolInfo records. * @returns Array of extracted symbols, or empty array if language unsupported. */ declare function extractSymbols(content: string, ext: string, filePath?: string): Promise; //#endregion //#region packages/chunker/src/generic-chunker.d.ts declare class GenericChunker implements IChunker { private readonly maxChunkSize; private readonly overlap; constructor(options?: { maxChunkSize?: number; overlap?: number; }); chunk(content: string, metadata: ChunkMetadata): RawChunk[]; } //#endregion //#region packages/chunker/src/markdown-chunker.d.ts declare class MarkdownChunker implements IChunker { private readonly maxChunkSize; private readonly minChunkSize; constructor(options?: { maxChunkSize?: number; minChunkSize?: number; }); chunk(content: string, metadata: ChunkMetadata): RawChunk[]; private splitByHeadings; private splitByParagraphs; } //#endregion //#region packages/chunker/src/wasm/diagnostics.d.ts interface WasmDiagnosticInfo { mode: 'wasm' | 'regex' | 'unknown'; reason: string; pathsChecked: { path: string; exists: boolean; }[]; os: string; arch: string; nodeVersion: string; webTreeSitterImportable: boolean; healAttempted: boolean; healSuccess: boolean; healError: string | null; initError: string | null; wasmDir: string | null; grammarCount: number; } declare const WasmDiagnostics: { get(): WasmDiagnosticInfo; update(partial: Partial): void; reset(): void; }; //#endregion //#region packages/chunker/src/wasm/languages.d.ts /** * Language registry for web-tree-sitter WASM grammars. * * Maps file extensions to vendored .wasm grammar file names * and resolves their absolute paths on disk. */ /** All supported extensions. */ declare const SUPPORTED_EXTENSIONS: Set; /** * Find the package's own bundled wasm/ directory (always present in published package). * Checks ONLY package-relative paths, NOT user cache. * Used by heal to know where to copy FROM. */ declare function findBundledWasmDir(): string | null; /** * Resolve the absolute path to a vendored .wasm grammar file for a given extension. * Returns null if the extension is not supported or the file doesn't exist. */ declare function resolveGrammarPath(ext: string): string | null; /** Resolve the parser runtime WASM path. */ declare function resolveParserWasmPath(): string | null; //#endregion //#region packages/chunker/src/wasm/types.d.ts /** * Minimal type definitions for web-tree-sitter 0.24.x. * * web-tree-sitter uses `export = Parser` (CJS-style) which doesn't interop * cleanly with ESM `import type` under `moduleResolution: NodeNext` without * `esModuleInterop`. We define our own interfaces for the subset we use. */ interface WasmPoint { row: number; column: number; } interface WasmSyntaxNode { type: string; text: string; startPosition: WasmPoint; endPosition: WasmPoint; startIndex: number; endIndex: number; children: WasmSyntaxNode[]; namedChildren: WasmSyntaxNode[]; childCount: number; namedChildCount: number; parent: WasmSyntaxNode | null; nextSibling: WasmSyntaxNode | null; previousSibling: WasmSyntaxNode | null; nextNamedSibling: WasmSyntaxNode | null; previousNamedSibling: WasmSyntaxNode | null; isNamed: boolean; firstChild: WasmSyntaxNode | null; lastChild: WasmSyntaxNode | null; firstNamedChild: WasmSyntaxNode | null; lastNamedChild: WasmSyntaxNode | null; childForFieldName(fieldName: string): WasmSyntaxNode | null; descendantsOfType(types: string | string[], startPosition?: WasmPoint, endPosition?: WasmPoint): WasmSyntaxNode[]; } interface WasmTree { rootNode: WasmSyntaxNode; delete(): void; } interface WasmLanguage { query(source: string): WasmQuery; readonly version: number; readonly fieldCount: number; } interface WasmQuery { matches(rootNode: WasmSyntaxNode, options?: { startPosition?: WasmPoint; endPosition?: WasmPoint; matchLimit?: number; }): WasmQueryMatch[]; captures(rootNode: WasmSyntaxNode, options?: { startPosition?: WasmPoint; endPosition?: WasmPoint; matchLimit?: number; }): WasmQueryCapture[]; captureNames: string[]; delete(): void; } interface WasmQueryMatch { pattern: number; captures: WasmQueryCapture[]; } interface WasmQueryCapture { name: string; node: WasmSyntaxNode; } interface WasmParser { parse(input: string): WasmTree; setLanguage(language: WasmLanguage | null): void; delete(): void; } /** The Parser constructor + statics as returned by web-tree-sitter. */ interface WasmParserModule { new (): WasmParser; init(moduleOptions?: { locateFile?: (scriptName: string, scriptDirectory: string) => string; }): Promise; Language: { load(input: string | Uint8Array): Promise; }; } //#endregion //#region packages/chunker/src/wasm/query-executor.d.ts /** Known query types that can be loaded. */ type QueryType = 'symbols' | 'imports' | 'calls' | 'patterns' | 'entry-points'; /** Structured result from a single query match. */ interface QueryResult { /** The pattern index within the .scm file that matched. */ pattern: number; /** All captures in this match, keyed by capture name → node info. */ captures: Map; } /** Information about a single captured node. */ interface CaptureInfo { /** The capture name (e.g., 'name', 'node', 'kind'). */ name: string; /** The captured node's text content. */ text: string; /** AST node type (e.g., 'function_declaration', 'identifier'). */ nodeType: string; /** 0-based start line. */ startLine: number; /** 0-based end line. */ endLine: number; /** 0-based start column. */ startColumn: number; /** 0-based end column. */ endColumn: number; /** The raw AST node (for advanced traversal). */ node: WasmSyntaxNode; } declare class QueryExecutor { /** Cache: `"typescript:symbols"` → compiled WasmQuery */ private queryCache; /** Cache: loaded .scm source text to avoid re-reading disk. */ private scmCache; /** * Execute a query type against a parsed AST tree. * * @param rootNode - The root node of a parsed AST tree. * @param language - The Language object for the parsed file. * @param ext - The file extension (e.g., `.ts`). * @param queryType - Which query to execute (e.g., `'symbols'`). * @returns Array of structured results, or empty array if query not found. */ execute(rootNode: WasmSyntaxNode, language: WasmLanguage, ext: string, queryType: QueryType): QueryResult[]; /** * Execute a query and return flat captures instead of grouped matches. * Useful when you care about individual nodes, not match grouping. */ executeCaptures(rootNode: WasmSyntaxNode, language: WasmLanguage, ext: string, queryType: QueryType): CaptureInfo[]; /** * Execute a raw .scm query string (not from file) against a tree. * Useful for ad-hoc queries and testing. */ executeRaw(rootNode: WasmSyntaxNode, language: WasmLanguage, scmSource: string): QueryResult[]; /** * Get (or compile and cache) a query for the given language + type. * Returns null if the .scm file doesn't exist. */ private getOrCompile; /** Load .scm file content, cached. Returns null if file not found. */ private loadScm; /** Clear all caches. */ dispose(): void; /** Resolve the directory path for a language's queries. */ static resolveQueryDir(langDir: string): string; } //#endregion //#region packages/chunker/src/wasm/runtime.d.ts declare class WasmRuntime { private static instance; private parser; private languages; /** Track which grammar files have been loaded (by path) to avoid re-loading. */ private loadedGrammars; /** Number of WASM crash recovery attempts this session. */ private recoveryAttempts; /** * Max auto-recovery attempts before giving up permanently. * Set to 1 — we observed crash-cascading in practice where a corrupted parser * repeatedly fails even after recreation. A single retry catches transient * WASM-loader flukes; a second failure means the grammar/ABI is genuinely broken. * The session then falls back to regex analysis rather than burning CPU on retries. */ private static readonly MAX_RECOVERIES; /** Max content size (bytes) to attempt WASM parsing — prevents OOM on huge files. */ private static readonly MAX_PARSE_SIZE; /** Cached web-tree-sitter Parser class module — loaded once, reused. */ private parserModule; /** Initialize the singleton runtime. Returns the instance or null on failure. */ static initialize(): Promise; /** Get the current runtime (null if not initialized). */ static get(): WasmRuntime | null; /** Ensure the runtime is initialized, initializing if needed. */ static ensure(): Promise; /** Reset the singleton (for testing). */ static dispose(): void; /** Clear parser state and loaded grammars. */ private cleanupParser; /** Permanently disable WASM parsing for the rest of the process. */ private disableWasmParsing; private init; /** Get or lazily-cache the web-tree-sitter Parser module. */ private getParserModule; loadLanguage(ext: string): Promise; /** * Parse source code and return the AST tree. * Lazily loads the grammar on first use for the given extension. * Auto-recovers from WASM crashes by recreating the parser (up to MAX_RECOVERIES times). */ parse(content: string, ext: string): Promise; /** * Attempt to recover from a WASM parser crash by disposing the corrupted * parser and creating a fresh one. * * Recovery strategy: * 1. Destroy the corrupted parser and clear all language caches. * 2. Create a fresh parser from the cached module (one-time init already done). * 3. Reload the language grammar that was in use. * * If recovery fails, the parser is unconditionally set to null to prevent * cascading crashes on subsequent parse() calls. WASM parsing is disabled * permanently for the rest of the session. */ private recoverParser; /** * Refresh the user WASM cache from the bundled directory. * Called at the start of init() so the parser always loads fresh files. * Non-throwing — failures are logged but do not prevent parser startup. */ private refreshUserCache; /** Check if a grammar is available (loaded or loadable) for the given extension. */ hasLanguage(ext: string): boolean; /** Check if a grammar is already loaded for the given extension. */ isLanguageLoaded(ext: string): boolean; /** Get the underlying parser instance (for advanced query usage). */ getParser(): WasmParser | null; /** Get a loaded language by extension (null if not loaded yet). */ getLanguage(ext: string): WasmLanguage | null; } /** * Initialize the WASM runtime. Call once at startup. * Returns true if the runtime is available, false otherwise. */ declare function initializeWasm(): Promise; //#endregion //#region packages/chunker/src/wasm-chunker.d.ts declare class WasmChunker implements IChunker { private readonly maxChunkSize; constructor(options?: { maxChunkSize?: number; }); chunk(content: string, metadata: ChunkMetadata): RawChunk[]; /** Find declaration boundaries from AST top-level children. */ private findAstBoundaries; /** Build RawChunk[] from AST boundaries, grouping consecutive preamble items. */ private buildChunks; /** Split text by lines respecting max chunk size. */ private splitByLines; /** Extract file extension from path. */ private extractExt; /** Fallback: return the whole content as a single chunk. */ private singleChunk; } //#endregion export { type CallEdge as AstCallEdge, type CallEdge$1 as CallEdge, type CaptureInfo, CodeChunker, type EntryPoint, GenericChunker, type IChunker, type ImportInfo, MarkdownChunker, type PatternMatch, QueryExecutor, type QueryResult, type QueryType, SUPPORTED_EXTENSIONS, type ScopeInfo, type SymbolInfo, WasmChunker, type WasmDiagnosticInfo, WasmDiagnostics, type WasmLanguage, type WasmParser, type WasmParserModule, type WasmPoint, type WasmQuery, type WasmQueryCapture, type WasmQueryMatch, WasmRuntime, type WasmSyntaxNode, type WasmTree, createChunker, createChunkerSync, detectEntryPoints, detectPatterns, extractCallEdges, extractCalls, extractImports, extractSymbols, findBundledWasmDir, initializeWasm, resolveGrammarPath, resolveParserWasmPath, resolveScopes };