/** * File summarization using GLM 4.6v-flash * * This module provides functionality to summarize source code files, * extracting key information like purpose, exports, and dependencies. * Designed for parallel processing with the concurrency pool. */ import type { LLMClient, ChatMessage } from "../../llm/client.js"; import type { ConcurrencyPool, ProgressCallback } from "../../llm/pool.js"; /** * Summary information extracted from a source file */ export interface FileSummary { /** Brief description of the file's purpose (1-3 sentences) */ summary: string; /** List of exported symbols (functions, classes, constants, types) */ exports: string[]; /** List of dependencies (imported modules/packages) */ dependencies: string[]; } /** * Result of summarizing a single file */ export interface FileSummarizationResult { /** Path to the file that was summarized */ filePath: string; /** The extracted summary, or null if summarization failed */ summary: FileSummary | null; /** Error message if summarization failed */ error?: string; } /** * Input for batch file summarization */ export interface FileToSummarize { /** Relative path to the file (for display/caching) */ filePath: string; /** Absolute path to the file on disk */ absolutePath: string; } /** * Error thrown when parsing summarization response fails */ export declare class SummarizationParseError extends Error { /** The raw response that failed to parse */ readonly rawResponse: string; /** Specific parsing issue encountered */ readonly parseIssue: string; constructor(message: string, rawResponse: string, parseIssue: string); } /** * System prompt for file summarization with GLM 4.6v-flash * * This prompt instructs the LLM to analyze source code files and extract: * - A concise summary of the file's purpose * - List of exported symbols * - List of dependencies/imports */ export declare const FILE_SUMMARIZATION_PROMPT = "You are a code analysis assistant that summarizes source code files.\n\n## Your Task\n\nAnalyze the provided source code file and extract key information about it.\n\n## Output Format\n\nYou MUST respond with ONLY a valid JSON object. No markdown, no explanation, no code blocks.\n\nThe JSON object must have exactly these fields:\n- \"summary\": A brief description of the file's purpose (1-3 sentences, max 200 characters)\n- \"exports\": An array of exported symbol names (functions, classes, constants, types, interfaces)\n- \"dependencies\": An array of imported module/package names (just the module name, not the full path)\n\nExample output:\n{\n \"summary\": \"HTTP client wrapper for making authenticated API requests with retry logic and timeout support.\",\n \"exports\": [\"HttpClient\", \"HttpError\", \"createClient\", \"DEFAULT_TIMEOUT\"],\n \"dependencies\": [\"node:http\", \"node:https\", \"./config\", \"./utils/retry\"]\n}\n\n## Guidelines\n\n1. **Summary**: Focus on WHAT the file does, not HOW it does it. Be concise.\n\n2. **Exports**: Include ALL exported items:\n - Named exports (export function, export class, export const, export type, export interface)\n - Default exports (note as \"default\" if the actual name is unclear)\n - Re-exports (export { x } from './y')\n - Only include items that are actually exported, not internal implementations\n\n3. **Dependencies**: Include ALL imports:\n - Node.js built-in modules (e.g., \"node:fs\", \"node:path\")\n - Third-party packages (e.g., \"lodash\", \"express\")\n - Local/relative imports (e.g., \"./utils\", \"../config\")\n - Type-only imports count as dependencies\n\n4. **Edge Cases**:\n - If file has no exports, use an empty array: []\n - If file has no imports, use an empty array: []\n - If file purpose is unclear, describe what you observe\n\nRemember: Output ONLY the JSON object. No other text."; /** * Truncate file content to fit within character limits * * Truncates content intelligently by keeping the beginning of the file * (which typically contains imports and key exports) and appending a * truncation notice. * * @param content - The file content to truncate * @param maxChars - Maximum characters to keep (default: 50000) * @returns Truncated content with notice if truncation occurred */ export declare function truncateForSummarization(content: string, maxChars?: number): string; /** * Build messages for the summarization LLM call * * @param filePath - Path to the file being summarized * @param content - Content of the file (will be truncated if too large) * @returns Array of ChatMessage ready for the LLM client */ declare function buildSummarizationMessages(filePath: string, content: string): ChatMessage[]; /** * Extract JSON object from LLM response * * Handles various response formats: * - Raw JSON object * - JSON wrapped in markdown code blocks * - JSON with leading/trailing whitespace * * @param response - Raw LLM response string * @returns Extracted JSON string */ declare function extractJSON(response: string): string; /** * Parse and validate LLM response into FileSummary * * @param response - Raw response string from the LLM * @returns Validated FileSummary object * @throws SummarizationParseError if parsing or validation fails */ declare function parseSummarizationResponse(response: string): FileSummary; /** * Summarize a single file using the LLM * * Loads file content just-in-time to minimize memory usage. * * @param client - LLM client instance * @param model - Model ID to use (e.g., "glm-4.6v-flash") * @param filePath - Relative path to the file (for display) * @param absolutePath - Absolute path to the file on disk * @returns Promise resolving to FileSummary * @throws LLMClientError if the API call fails * @throws SummarizationParseError if response parsing fails * @throws Error if file cannot be read */ export declare function summarizeFile(client: LLMClient, model: string, filePath: string, absolutePath: string): Promise; /** * Summarize multiple files in parallel using the concurrency pool * * Uses the pool to limit concurrent API calls and prevent rate limiting. * File contents are loaded just-in-time within each task to minimize memory usage. * Returns results for all files, including those that failed. * * @param client - LLM client instance * @param model - Model ID to use (e.g., "glm-4.6v-flash") * @param pool - Concurrency pool for rate limiting * @param files - Array of files to summarize (with absolute paths) * @param onProgress - Optional progress callback * @returns Promise resolving to Map of file paths to summaries */ export declare function summarizeFiles(client: LLMClient, model: string, pool: ConcurrencyPool, files: FileToSummarize[], onProgress?: ProgressCallback): Promise>; export { extractJSON as _extractJSON }; export { parseSummarizationResponse as _parseSummarizationResponse }; export { buildSummarizationMessages as _buildSummarizationMessages }; //# sourceMappingURL=summarize.d.ts.map