import { EventEmitter } from 'events'; import type { CodeIndexer, IndexStatus, IndexProgress } from '../search/indexer.js'; import type { GlanceyConfig } from '../config.js'; import type { BackendFallbackInfo } from '../embeddings/types.js'; import { type TokenSavingsStats } from './token-tracking.js'; /** * Command names that can be tracked */ export type CommandName = 'index_codebase' | 'search_code' | 'search_similar' | 'get_index_status' | 'clear_index' | 'get_project_instructions' | 'commit' | 'get_symbols_overview' | 'find_symbol' | 'find_referencing_symbols' | 'search_for_pattern' | 'replace_symbol_body' | 'insert_before_symbol' | 'insert_after_symbol' | 'rename_symbol' | 'write_memory' | 'read_memory' | 'list_memories' | 'delete_memory' | 'edit_memory' | 'create_worktree' | 'list_worktrees' | 'remove_worktree' | 'worktree_status' | 'list_concepts' | 'search_by_concept' | 'summarize_codebase' | 'open_dashboard' | 'init_project'; /** * Command usage statistics */ export interface CommandUsage { command: CommandName; count: number; label: string; } /** * Events emitted by the DashboardStateManager */ export interface DashboardStateEvents { progress: (progress: IndexProgress) => void; 'indexing:start': () => void; 'indexing:complete': (result: { filesIndexed: number; chunksCreated: number; }) => void; 'status:change': (status: IndexStatus) => void; 'usage:update': (usage: CommandUsage[]) => void; } export declare class DashboardStateManager extends EventEmitter { private indexer; private config; private projectPath; private version; private isIndexing; private lastProgress; private commandUsage; private backendFallback; constructor(); /** * Get the path to the usage file */ private getUsageFilePath; /** * Load command usage from disk */ private loadUsageFromDisk; /** * Save command usage to disk */ private saveUsageToDisk; /** * Scan agent worktree directories for their usage.json files * and return aggregated counts. */ private loadWorktreeUsage; /** * Set the indexer instance for the dashboard to use */ setIndexer(indexer: CodeIndexer): void; /** * Set the configuration for the dashboard to display */ setConfig(config: GlanceyConfig): void; /** * Set the project path */ setProjectPath(projectPath: string): void; /** * Set the package version */ setVersion(version: string): void; /** * Get the package version */ getVersion(): string | null; /** * Set backend fallback info when a fallback occurred during initialization */ setBackendFallback(fallback: BackendFallbackInfo): void; /** * Clear backend fallback info (when backend is successfully reinitialized) */ clearBackendFallback(): void; /** * Get backend fallback info if a fallback occurred */ getBackendFallback(): BackendFallbackInfo | null; /** * Get the current index status */ getStatus(): Promise; /** * Get the current configuration */ getConfig(): GlanceyConfig | null; /** * Get the project path */ getProjectPath(): string | null; /** * Check if indexing is in progress */ isIndexingInProgress(): boolean; /** * Get the last progress update */ getLastProgress(): IndexProgress | null; /** * Called when indexing starts */ onIndexingStart(): void; /** * Called with progress updates during indexing */ onProgress(progress: IndexProgress): void; /** * Update just the message portion of the current progress. * Useful for sub-progress updates (e.g., Ollama batch progress). */ updateProgressMessage(message: string): void; /** * Update sub-progress within the current phase. * Allows embedding backends to report their own progress with percentage. * The current/total values represent sub-progress within the phase. */ updateSubProgress(current: number, total: number, message: string): void; /** * Called when indexing completes */ onIndexingComplete(result: { filesIndexed: number; chunksCreated: number; }): void; /** * Called when status changes */ onStatusChange(status: IndexStatus): void; /** * Trigger a reindex of the codebase. * Returns a promise that resolves when indexing completes. */ triggerReindex(forceReindex?: boolean): Promise<{ filesIndexed: number; chunksCreated: number; } | null>; /** * Record a command usage */ recordCommandUsage(command: CommandName): void; /** * Get the full list of tracked command names */ private getAllCommandNames; /** * Get command usage statistics (main project + agent worktrees combined) */ getCommandUsage(): CommandUsage[]; /** * Get usage breakdown: main project vs agent worktrees. * Useful for dashboard to show where usage is coming from. */ getUsageBreakdown(): { main: CommandUsage[]; agents: CommandUsage[]; total: CommandUsage[]; }; /** * Get total command count for percentage calculations (includes agent worktrees) */ getTotalCommandCount(): number; /** * Get token savings statistics (main project only) */ getTokenSavings(): TokenSavingsStats; /** * Get token savings with worktree breakdown */ getTokenSavingsWithWorktrees(): { main: TokenSavingsStats; agents: TokenSavingsStats; total: TokenSavingsStats; }; /** * Get the token tracker for recording savings */ getTokenTracker(): import("./token-tracking.js").TokenSavingsTracker; /** * Emit token savings update event for real-time dashboard updates */ emitTokenSavingsUpdate(): void; } /** * Singleton instance of the dashboard state manager */ export declare const dashboardState: DashboardStateManager; //# sourceMappingURL=state.d.ts.map