/** * Analytics Service * * Shared analytics engine for session insights. Powers both the * gitmem-analyze MCP tool (CLI) and the GitMem Console dashboard. * * Uses directQuery for raw Supabase REST access (no ww-mcp dependency). */ import type { Project } from "../types/index.js"; export interface SessionRecord { id: string; session_title: string | null; session_date: string; agent: string; linear_issue: string | null; decisions: unknown[]; open_threads: string[]; closing_reflection: ClosingReflection | null; close_compliance: CloseCompliance | null; created_at: string; project: string; } interface ClosingReflection { what_broke?: string; what_took_longer?: string; do_differently?: string; what_worked?: string; wrong_assumption?: string; scars_applied?: string | string[]; human_additions?: string; } interface CloseCompliance { agent?: string; close_type?: string; scars_applied?: number; learnings_stored?: number; checklist_displayed?: boolean; human_asked_for_corrections?: boolean; questions_answered_by_agent?: boolean; } export interface AgentBreakdown { agent: string; session_count: number; decisions_total: number; threads_total: number; close_types: Record; } export interface SummaryAnalytics { period: { start: string; end: string; days: number; }; total_sessions: number; sessions_with_reflections: number; sessions_with_issues: number; total_decisions: number; total_open_threads: number; agents: AgentBreakdown[]; close_type_distribution: Record; top_issues: Array<{ issue: string; session_count: number; }>; } /** * Fetch sessions within a date range. * Selects only the fields needed for analytics (no embedding column). */ export declare function querySessionsByDateRange(startDate: string, endDate: string, project: Project, agentFilter?: string): Promise; export interface ScarUsageRecord { scar_id: string; scar_title: string | null; scar_severity: string | null; agent: string | null; reference_type: string; execution_successful: boolean | null; surfaced_at: string; } export interface RepeatMistakeRecord { id: string; title: string; related_scar_id: string | null; repeat_mistake_details: { reason?: string; } | null; created_at: string; } export interface BlindspotsData { period: { start: string; end: string; days: number; }; total_scars_surfaced: number; total_scar_usages: number; ignored_scars: Array<{ scar_id: string; title: string; severity: string; times_surfaced: number; times_ignored: number; ignore_rate: number; agents: string[]; }>; failed_applications: Array<{ scar_id: string; title: string; times_applied: number; times_failed: number; failure_rate: number; }>; repeat_mistakes: Array<{ id: string; title: string; original_scar_title: string; reason: string; created_at: string; }>; agent_effectiveness: Array<{ agent: string; scars_surfaced: number; scars_applied: number; application_rate: number; success_rate: number; }>; severity_breakdown: Array<{ severity: string; surfaced: number; applied: number; ignored: number; application_rate: number; }>; } /** * Fetch scar_usage records within a date range. */ export declare function queryScarUsageByDateRange(startDate: string, _endDate: string, _project: Project, agentFilter?: string): Promise; /** * Fetch repeat mistakes from the learnings table within a date range. */ export declare function queryRepeatMistakes(startDate: string, _endDate: string, project: Project): Promise; /** * Resolve scar titles and severities from the learnings table for scar_usage * records that have null/missing title data. */ export declare function enrichScarUsageTitles(usages: ScarUsageRecord[]): Promise; /** * Compute blindspots analytics from scar usage and repeat mistake data. */ export declare function computeBlindspots(usages: ScarUsageRecord[], repeatMistakes: RepeatMistakeRecord[], days: number): BlindspotsData; /** * Compute basic summary statistics from a set of sessions. */ export declare function computeSummary(sessions: SessionRecord[], days: number): SummaryAnalytics; /** * Extract and aggregate closing reflections from sessions. * Returns arrays of each reflection field for further analysis. */ type ReflectionEntry = { text: string; session_id: string; agent: string; date: string; }; type ReflectionCategory = { entries: ReflectionEntry[]; total_count: number; }; export declare function aggregateClosingReflections(sessions: SessionRecord[], maxPerCategory?: number, maxTextLength?: number): { what_broke: ReflectionCategory; what_worked: ReflectionCategory; wrong_assumptions: ReflectionCategory; do_differently: ReflectionCategory; }; /** * Lightweight summary for session_start Pro insights. * Returns a compact object with key 30-day metrics. */ export interface LightweightSummary { total_sessions: number; scars_surfaced: number; scars_applied: number; application_rate: number; top_blindspot: { title: string; ignore_rate: string; times: string; } | null; } export declare function computeLightweightSummary(sessions: SessionRecord[], usages: ScarUsageRecord[]): LightweightSummary; /** * Format blindspot snippet for session_close display. * Returns 2-3 lines showing top 2 most-ignored scars, or null if none qualify. * Threshold: ignore_rate > 50%, surfaced >= 3 times. */ export declare function formatBlindspotSnippet(usages: ScarUsageRecord[]): string | null; /** * Format summary analytics as compact markdown. */ export declare function formatSummary(data: SummaryAnalytics): string; /** * Format reflections as compact markdown (top N per category). */ export declare function formatReflections(data: { period: { start: string; end: string; days: number; }; total_sessions_scanned: number; sessions_with_reflections: number; what_broke: ReflectionCategory; what_worked: ReflectionCategory; wrong_assumptions: ReflectionCategory; do_differently: ReflectionCategory; }, topN?: number): string; /** * Format blindspots as compact markdown. */ export declare function formatBlindspots(data: BlindspotsData): string; export {}; //# sourceMappingURL=analytics.d.ts.map