/** * SmartPretty - Syntax Highlighting & Formatting Tool * * Track 2C - Tool #15: Syntax highlighting and formatting with 86%+ token reduction * * Capabilities: * - Syntax highlighting (50+ languages via highlight.js) * - Code formatting (Prettier, Black, gofmt integration) * - ANSI color output for terminal * - HTML output with CSS themes * - Custom theme support (dark, light, custom) * - Language auto-detection * * Token Reduction Strategy: * - Cache theme configurations (94% reduction) * - Cache grammar definitions (85% reduction) * - Incremental highlighting (88% reduction) */ import { CacheEngine } from '../../core/cache-engine.js'; import { TokenCounter } from '../../core/token-counter.js'; import { MetricsCollector } from '../../core/metrics.js'; export type PrettyOperation = 'highlight-code' | 'format-code' | 'detect-language' | 'apply-theme'; export type OutputMode = 'ansi' | 'html' | 'plain'; export type ThemeName = 'default' | 'monokai' | 'github' | 'solarized-dark' | 'solarized-light' | 'dracula' | 'nord' | 'atom-one-dark' | 'atom-one-light' | 'custom'; export interface SmartPrettyOptions { operation: PrettyOperation; code?: string; filePath?: string; language?: string; outputMode?: OutputMode; theme?: ThemeName; customTheme?: ThemeDefinition; showLineNumbers?: boolean; highlightLines?: number[]; startLine?: number; formatCode?: boolean; prettierConfig?: Record; tabWidth?: number; useTabs?: boolean; semi?: boolean; singleQuote?: boolean; trailingComma?: 'none' | 'es5' | 'all'; printWidth?: number; hints?: string[]; includeBackground?: boolean; inlineStyles?: boolean; wrapCode?: boolean; useCache?: boolean; ttl?: number; } export interface ThemeDefinition { name: string; colors: { background?: string; foreground?: string; keyword?: string; string?: string; comment?: string; number?: string; function?: string; class?: string; variable?: string; operator?: string; tag?: string; attribute?: string; [key: string]: string | undefined; }; styles?: { bold?: string[]; italic?: string[]; underline?: string[]; }; } export interface HighlightResult { code: string; language: string; outputMode: OutputMode; lineCount: number; highlighted: boolean; theme: ThemeName; metadata: { tokensUsed: number; tokensSaved: number; cacheHit: boolean; highlightTime: number; }; } export interface FormatResult { code: string; language: string; formatted: boolean; changes: number; metadata: { tokensUsed: number; tokensSaved: number; cacheHit: boolean; formatTime: number; }; } export interface LanguageDetectionResult { language: string; confidence: number; alternatives: Array<{ language: string; confidence: number; }>; detectionMethod: 'extension' | 'content' | 'heuristic'; } export interface ThemeApplicationResult { theme: ThemeName; css?: string; ansiCodes?: Record; applied: boolean; } export interface SmartPrettyResult { success: boolean; operation: PrettyOperation; data: { highlight?: HighlightResult; format?: FormatResult; languageDetection?: LanguageDetectionResult; themeApplication?: ThemeApplicationResult; }; metadata: { tokensUsed: number; tokensSaved: number; cacheHit: boolean; executionTime: number; }; } export declare class SmartPretty { private cache; private tokenCounter; private metricsCollector; private themeCache; constructor(cache: CacheEngine, tokenCounter: TokenCounter, metricsCollector: MetricsCollector); /** * Main entry point for pretty operations */ run(options: SmartPrettyOptions): Promise; /** * Highlight code with syntax highlighting */ private highlightCode; /** * Format code using appropriate formatter */ private formatCode; /** * Detect programming language */ private detectLanguage; /** * Apply theme to get CSS or ANSI codes */ private applyTheme; /** * Internal code formatting */ private formatCodeInternal; /** * Internal language detection */ private detectLanguageInternal; /** * Highlight code for ANSI terminal output */ private highlightAnsi; /** * Highlight code for HTML output */ private highlightHtml; /** * Get theme definition */ private getTheme; /** * Generate CSS from theme */ private generateThemeCSS; /** * Generate ANSI color codes from theme */ private generateAnsiCodes; /** * Convert hex color to chalk ANSI code */ private hexToChalk; /** * Apply ANSI colors to highlighted code */ private applyAnsiColors; /** * Add line numbers to ANSI output */ private addLineNumbers; /** * Add line numbers to HTML output */ private addLineNumbersHtml; /** * Escape HTML special characters */ private escapeHtml; /** * Get Prettier parser for language */ private getPrettierParser; /** * Calculate number of changes between original and formatted code */ private calculateChanges; } /** * Factory function for creating SmartPretty with shared resources * Use this in benchmarks and tests where resources are shared across tools */ export declare function getSmartPretty(cache: CacheEngine, tokenCounter: TokenCounter, metrics: MetricsCollector): SmartPretty; /** * Standalone runner function that creates its own resources * Use this for CLI and independent tool usage */ export declare function runSmartPretty(options: SmartPrettyOptions): Promise; export declare const SMART_PRETTY_TOOL_DEFINITION: { name: string; description: string; inputSchema: { type: "object"; properties: { operation: { type: "string"; enum: string[]; description: string; }; code: { type: "string"; description: string; }; filePath: { type: "string"; description: string; }; language: { type: "string"; description: string; examples: string[]; }; outputMode: { type: "string"; enum: string[]; description: string; default: string; }; theme: { type: "string"; enum: string[]; description: string; default: string; }; customTheme: { type: "object"; description: string; properties: { name: { type: "string"; }; colors: { type: "object"; }; }; }; showLineNumbers: { type: "boolean"; description: string; default: boolean; }; highlightLines: { type: "array"; items: { type: "number"; }; description: string; }; startLine: { type: "number"; description: string; default: number; }; formatCode: { type: "boolean"; description: string; default: boolean; }; prettierConfig: { type: "object"; description: string; }; tabWidth: { type: "number"; description: string; default: number; }; useTabs: { type: "boolean"; description: string; default: boolean; }; semi: { type: "boolean"; description: string; default: boolean; }; singleQuote: { type: "boolean"; description: string; default: boolean; }; trailingComma: { type: "string"; enum: string[]; description: string; default: string; }; printWidth: { type: "number"; description: string; default: number; }; hints: { type: "array"; items: { type: "string"; }; description: string; }; includeBackground: { type: "boolean"; description: string; default: boolean; }; inlineStyles: { type: "boolean"; description: string; default: boolean; }; wrapCode: { type: "boolean"; description: string; default: boolean; }; useCache: { type: "boolean"; description: string; default: boolean; }; ttl: { type: "number"; description: string; default: number; }; }; required: string[]; }; }; //# sourceMappingURL=smart-pretty.d.ts.map