/** * Token tracking module for estimating tokens saved by glancey operations. * * Token estimation is based on the common approximation that 1 token ≈ 4 characters. * This provides a rough estimate for understanding the efficiency gains from using * semantic search vs. reading entire files. */ /** * Token savings event types */ export type TokenSavingsEventType = 'search_code' | 'search_similar' | 'get_symbols_overview' | 'find_symbol' | 'summarize_codebase' | 'list_concepts' | 'search_by_concept'; /** * Record of a single token savings event */ export interface TokenSavingsEvent { type: TokenSavingsEventType; timestamp: number; /** Characters returned to the agent */ charsReturned: number; /** Estimated characters that would have been read without glancey */ charsAvoided: number; /** Number of files that would have been read */ filesAvoided: number; /** Additional context about the operation */ context?: string; } /** * Aggregated token savings statistics */ export interface TokenSavingsStats { /** Total estimated tokens saved */ tokensSaved: number; /** Total characters returned */ charsReturned: number; /** Total characters avoided (not sent to agent) */ charsAvoided: number; /** Total files avoided reading */ filesAvoided: number; /** Number of operations tracked */ operationCount: number; /** Savings breakdown by operation type */ byType: Record; /** Efficiency percentage (chars avoided / total chars) */ efficiencyPercent: number; /** Session start time */ sessionStart: number; } /** * Token savings tracker for a session */ export declare class TokenSavingsTracker { private events; private sessionStart; private onUpdate; private projectPath; private saveTimer; private pendingSave; /** * Set the project path and load persisted data */ setProjectPath(projectPath: string): void; /** * Get the path to the token savings file */ private getFilePath; /** * Load token savings from disk with validation */ private loadFromDisk; /** * Save token savings to disk (debounced to avoid blocking on every event) */ private saveToDisk; /** * Set callback to be called when token savings are updated */ setOnUpdate(callback: () => void): void; /** * Notify that token savings have been updated */ private notifyUpdate; /** * Record a search_code operation * @param charsReturned Characters in the search results * @param matchedFiles Number of files that matched * @param totalFilesSearched Total files in the index */ recordSearchCode(charsReturned: number, matchedFiles: number, totalFilesSearched: number): void; /** * Record a search_similar operation * @param charsReturned Characters in the similar code results * @param matchedChunks Number of similar chunks found */ recordSearchSimilar(charsReturned: number, matchedChunks: number): void; /** * Record a get_symbols_overview operation * @param charsReturned Characters in the symbols overview * @param fileLines Total lines in the file */ recordSymbolsOverview(charsReturned: number, fileLines: number): void; /** * Record a find_symbol operation * @param charsReturned Characters in the symbol results * @param filesSearched Number of files searched */ recordFindSymbol(charsReturned: number, filesSearched: number): void; /** * Record a summarize_codebase operation * @param charsReturned Characters in the summary * @param totalFiles Total files in codebase */ recordSummarizeCodebase(charsReturned: number, totalFiles: number): void; /** * Record a list_concepts operation * @param charsReturned Characters in the concepts list * @param clusterCount Number of concept clusters */ recordListConcepts(charsReturned: number, clusterCount: number): void; /** * Record a search_by_concept operation * @param charsReturned Characters in the concept search results * @param matchedChunks Number of chunks in the concept */ recordSearchByConcept(charsReturned: number, matchedChunks: number): void; /** * Load token savings events from all agent worktree directories. */ private loadWorktreeEvents; /** * Compute stats from a list of events. */ private static computeStats; /** * Get aggregated statistics (main project + agent worktrees combined) */ getStatsWithWorktrees(): { main: TokenSavingsStats; agents: TokenSavingsStats; total: TokenSavingsStats; }; /** * Get aggregated statistics (main project only, excludes worktrees) */ getStats(): TokenSavingsStats; /** * Get recent events (for debugging/display) */ getRecentEvents(limit?: number): TokenSavingsEvent[]; } /** * Global token savings tracker instance */ export declare const tokenTracker: TokenSavingsTracker; //# sourceMappingURL=token-tracking.d.ts.map