/** * Ultra-compact formatters for optimizing project indexes for AI context usage. * * This module provides multiple output formats for project indexes, each optimized * for different use cases. The formats prioritize token efficiency while maintaining * readability and essential information. * * ## Available Formats * * - **DSL**: Custom domain-specific language (90% token reduction) * - **Graph**: Dependency graph with signatures (92% token reduction) * - **Markdown**: Human-readable documentation format (93% token reduction) * - **Tree**: ASCII art visualization (97% token reduction) * - **Auto**: Automatically selects the best format based on project size * * ## Token Efficiency * * All formats are designed to fit within AI context windows efficiently: * - DSL format: Best balance of readability and compression (90% reduction) * - 1000 files ≈ 21K tokens (DSL format, 90% reduction) * - 2000 files ≈ 42K tokens (recommended maximum) * - 5000+ files automatically uses Graph format (92% reduction) * - Tree format: Manual choice for visualizing project structure * * @example Basic formatting * ```typescript * import { toDSL, toTree, toMarkdown } from 'code-map'; * * const index = await indexer.processProject(); * * // Visual tree structure for any size project * const treeOutput = toTree(index); * * // Ultra-compact for AI context * const dslOutput = toDSL(index); * * // Human-readable documentation * const markdownOutput = toMarkdown(index); * ``` * * @example Auto-format selection * ```typescript * import { formatAuto } from 'code-map'; * * const { format, content } = formatAuto(index); * console.log(`Selected ${format} format for ${index.metadata.totalFiles} files`); * ``` * * @module Formatters */ import type { ProjectIndex } from '../types/index.js'; /** * Supported output format types for project indexes. * * Each format optimizes for different use cases: * - `json`: Raw structured data * - `dsl`: Ultra-compact custom syntax * - `graph`: Dependency-focused representation * - `markdown`: Human-readable documentation */ export type FormatType = 'json' | 'dsl' | 'graph' | 'markdown' | 'tree'; /** * Convert project index to ultra-compact DSL (Domain Specific Language) format. * * This format provides the best balance of readability and token efficiency, * achieving 90% token reduction compared to compact JSON. Perfect for AI * context usage while remaining human-readable. * * ## Format Structure * ``` * # Legend: fn=function cl=class cn=constant m=methods p=properties * * filepath > dependency1,dependency2 * fn functionName(param:type):returnType async * cl ClassName(2m,3p) extends BaseClass * cn CONSTANT_NAME:string * ``` * * @param index - Project index to format * @returns DSL-formatted string representation * * @example * ```typescript * const index = await indexer.processProject(); * const dslOutput = toDSL(index); * * console.log(dslOutput); * // src/utils.ts > * // fn processData(input:string):Promise async * // cn API_URL:string * ``` */ export declare function toDSL(index: ProjectIndex): string; /** * Convert project index to dependency graph format with code signatures. * * This format emphasizes dependency relationships and provides 92% token * reduction. Ideal for large projects where dependency analysis is the * primary concern. * * ## Format Structure * ``` * DEPS: * fileA→fileB * fileB→fileC * * SIGS: * fileA: fn:functionName cl:ClassName(2m,1p) cn:CONSTANT * ``` * * @param index - Project index to format * @returns Graph-formatted string representation * * @example * ```typescript * const index = await indexer.processProject(); * const graphOutput = toGraph(index); * * console.log(graphOutput); * // DEPS: * // utils→types * // components/Button→utils * // * // SIGS: * // utils: fn:processData,fn:validateInput cn:CONFIG * // components/Button: cl:Button(3m,2p) * ``` */ export declare function toGraph(index: ProjectIndex): string; /** * Convert project index to ASCII tree format for visual project structure. * * This format provides a visual tree representation of the project structure * using ASCII art characters. Perfect for quickly understanding the project * hierarchy and file organization. This format is complementary to other formats * and focuses on structure visualization rather than code content analysis. * * ## Format Structure * - Uses ASCII art characters (├── └── │) for tree structure * - Directories shown with trailing slash * - Directories sorted before files at each level * - Files and directories sorted alphabetically within their type * * @param index - Project index to format * @returns Tree-formatted string representation * * @example * ```typescript * const index = await indexer.processProject(); * const treeOutput = toTree(index); * * console.log(treeOutput); * // project/ * // ├── src/ * // │ ├── components/ * // │ │ └── Button.tsx * // │ ├── index.ts * // │ └── utils.ts * // └── package.json * ``` */ export declare function toTree(index: ProjectIndex): string; /** * Convert project index to human-readable Markdown documentation format. * * This format provides the highest readability with 93% token reduction. * Perfect for generating project documentation, README files, or reports * that need to be easily understood by developers. * * ## Format Structure * - Organized by directory * - Clear dependency listings * - Detailed function and class information * - Project statistics summary * * @param index - Project index to format * @returns Markdown-formatted string representation * * @example * ```typescript * const index = await indexer.processProject(); * const markdownOutput = toMarkdown(index); * * console.log(markdownOutput); * // # Project Structure * // * // ## src/ * // * // ### utils.ts * // **Dependencies:** ./types * // **Functions:** processData(), validateInput() * // **Constants:** API_URL, DEFAULT_CONFIG * ``` */ export declare function toMarkdown(index: ProjectIndex): string; /** * Automatically select the optimal format based on project size and token efficiency. * * This function intelligently chooses between available formats to maximize * readability while staying within practical token limits for AI context usage. * Tree format is excluded from auto-selection as it serves a different purpose * (structure visualization rather than content analysis). * * ## Selection Logic * * - **≤5000 files**: DSL format (best readability, 90% compression) * - **>5000 files**: Graph format (maximum compression, 92% reduction) * * ## Token Budget Philosophy * * Uses DSL format for most projects since it provides the best balance of * readability and token efficiency, and only switches to graph format for * very large projects where maximum compression is needed. * * **Token estimates:** * - Small projects: DSL format (excellent readability) * - 1000 files ≈ 21K tokens (DSL, 10% of 200K context) ✓ * - 2000 files ≈ 42K tokens (DSL, 21% of context) ⚠️ * - 5000 files ≈ 105K tokens (DSL, 53% of context) - switches to Graph * * @param index - Project index to format * @returns Object containing the selected format type and formatted content * * @example * ```typescript * const index = await indexer.processProject(); * const { format, content } = formatAuto(index); * * console.log(`Auto-selected ${format} format`); * console.log(`Content length: ${content.length} characters`); * * if (format === 'dsl') { * console.log('Using readable DSL format'); * } else { * console.log('Using compact graph format for large project'); * } * ``` */ export declare function formatAuto(index: ProjectIndex): { format: FormatType; content: string; }; /** * Calculate compression statistics for a formatted output. * * Provides detailed metrics about token and size reduction compared to * compact JSON baseline. Useful for analyzing format efficiency and * making informed decisions about context usage. * * @param original - Original project index * @param formatted - Formatted string output * @returns Compression statistics object * * @example * ```typescript * const index = await indexer.processProject(); * const dslOutput = toDSL(index); * const stats = getCompressionStats(index, dslOutput); * * console.log(`Original size: ${stats.originalSize} characters`); * console.log(`Compressed size: ${stats.compressedSize} characters`); * console.log(`Token reduction: ${stats.reduction}%`); * console.log(`Estimated tokens: ${stats.estimatedTokens}`); * * // Example output: * // Original size: 245680 characters * // Compressed size: 24568 characters * // Token reduction: 90% * // Estimated tokens: 7019 * ``` */ export declare function getCompressionStats(original: ProjectIndex, formatted: string): { /** Size of compact JSON representation in characters */ originalSize: number; /** Size of formatted output in characters */ compressedSize: number; /** Token reduction percentage (0-100) */ reduction: number; /** Estimated token count for formatted output */ estimatedTokens: number; }; //# sourceMappingURL=index-formatter.d.ts.map