/** * SMI-914: Usage Tracker * * High-level API for tracking skill usage events. * Handles: * - Start/end tracking for duration measurement * - User ID anonymization * - Context hashing * - Periodic cleanup of old events */ import type { SkillUsageEvent, SkillUsageOutcome, SkillMetrics } from './types.js'; /** * UsageTracker configuration options */ export interface UsageTrackerOptions { /** * Custom database path (defaults to ~/.skillsmith/analytics.db) */ dbPath?: string; /** * Auto-cleanup interval in milliseconds (0 to disable, default: 1 hour) */ cleanupInterval?: number; } /** * High-level usage tracking API * * @example * ```typescript * const tracker = new UsageTracker(); * * // Start tracking a skill invocation * const trackingId = tracker.startTracking('anthropic/commit', 'user123'); * * // ... skill execution ... * * // End tracking with outcome * tracker.endTracking(trackingId, 'success', { framework: 'react' }); * * // Get metrics * const metrics = tracker.getMetrics('anthropic/commit'); * * // Cleanup when done * tracker.close(); * ``` */ export declare class UsageTracker { private storage; private pendingEvents; private cleanupTimer; private sessionCleanupTimer; /** * @deprecated Use UsageTracker.create(options) — async factory with WASM fallback. * This constructor always throws to prevent silent data loss. */ constructor(_options?: UsageTrackerOptions); /** * Async factory — supports both native and WASM SQLite. * * @param options - Configuration options * @returns Fully initialised UsageTracker instance */ static create(options?: UsageTrackerOptions): Promise; /** * Start tracking a skill invocation * * @param skillId - The skill identifier (e.g., 'anthropic/commit') * @param userId - Raw user identifier (will be anonymized) * @returns Tracking ID to use when ending tracking */ startTracking(skillId: string, userId: string): string; /** * End tracking and record the event * * @param trackingId - The tracking ID from startTracking * @param outcome - The outcome of the skill invocation * @param context - Optional project context (will be hashed) */ endTracking(trackingId: string, outcome: SkillUsageOutcome, context?: Record): void; /** * Record a complete event directly (for events that don't need start/end tracking) * * @param skillId - The skill identifier * @param userId - Raw user identifier (will be anonymized) * @param taskDuration - Duration in milliseconds * @param outcome - The outcome * @param context - Optional project context */ recordEvent(skillId: string, userId: string, taskDuration: number, outcome: SkillUsageOutcome, context?: Record): void; /** * Get metrics for a skill * * @param skillId - The skill identifier * @returns Aggregated metrics or null if no data */ getMetrics(skillId: string): SkillMetrics | null; /** * Get events for a skill * * @param skillId - The skill identifier * @param limit - Maximum number of events * @returns Array of usage events */ getEvents(skillId: string, limit?: number): SkillUsageEvent[]; /** * Get total event count * * @returns Number of stored events */ getEventCount(): number; /** * Get count of pending (unfinished) trackings * * @returns Number of pending trackings */ getPendingCount(): number; /** * Clean up events older than 30 days * * @returns Number of deleted events */ cleanup(): number; /** * Clean up stale sessions that have exceeded the timeout * This prevents unbounded memory growth from sessions that are started but never ended */ private cleanupStaleSessions; /** * Close the tracker and release resources */ close(): void; /** * Dispose of the tracker (alias for close) * Clears all intervals and releases resources */ dispose(): void; } //# sourceMappingURL=usage-tracker.d.ts.map