/** * Token usage estimation and tracking. * * Estimates token consumption using heuristics (1 token ~ 4 chars). * Logs events to TOKEN_USAGE.jsonl for value-proof metrics. * * @task T4454 * @epic T4454 */ /** Token event types. */ export type TokenEventType = 'manifest_read' | 'manifest_query' | 'full_file_read' | 'file_read' | 'skill_inject' | 'protocol_inject' | 'prompt_build' | 'spawn_output' | 'spawn_complete' | 'session_start' | 'session_end'; /** A token usage event entry. */ export interface TokenEvent { timestamp: string; event_type: TokenEventType; estimated_tokens: number; source: string; task_id: string | null; session_id: string | null; context: Record; } /** Estimate token count from text. ~4 characters per token. */ export declare function estimateTokens(text: string): number; /** Estimate token count from a file. */ export declare function estimateTokensFromFile(filePath: string): number; /** Log a token usage event to the JSONL file. */ export declare function logTokenEvent(eventType: TokenEventType, tokens: number, source: string, taskId?: string, context?: Record, cwd?: string): Promise; /** Track a file read with token estimate. */ export declare function trackFileRead(filePath: string, purpose: 'manifest' | 'full_file' | 'full' | 'skill' | 'protocol' | string, taskId?: string, cwd?: string): Promise; /** Track a manifest query (partial read). */ export declare function trackManifestQuery(queryType: string, resultCount: number, taskId?: string, cwd?: string): Promise; /** Track skill injection with tokens. */ export declare function trackSkillInjection(skillName: string, tier: number, tokens: number, taskId?: string, cwd?: string): Promise; /** Track final prompt size. */ export declare function trackPromptBuild(prompt: string, taskId: string, skillsUsed: string, cwd?: string): Promise; /** Track subagent output tokens. */ export declare function trackSpawnOutput(taskId: string, outputText: string, sessionId?: string, cwd?: string): Promise; /** Track complete spawn cycle (prompt + output). */ export declare function trackSpawnComplete(taskId: string, promptTokens: number, outputTokens: number, sessionId?: string, cwd?: string): Promise; /** Start tracking tokens for a session. */ export declare function startTokenSession(sessionId: string, cwd?: string): Promise; /** Token session summary shape. */ export interface TokenSessionSummary { session_id: string; start: string; end: string; tokens: { manifest_reads: number; full_file_reads: number; skill_injections: number; prompt_builds: number; total: number; }; savings: { avoided_tokens: number; savings_percent: number; }; } /** End token tracking session with summary. */ export declare function endTokenSession(cwd?: string): Promise; /** Get token usage summary for a time period. */ export declare function getTokenSummary(days?: number, cwd?: string): Record; /** Compare manifest vs full file token usage strategies. */ export declare function compareManifestVsFull(manifestEntries: number): Record; /** Get tracking status. */ export declare function getTrackingStatus(): { tracking_enabled: boolean; env_var: string; }; //# sourceMappingURL=token-estimation.d.ts.map