/** * MAMA (Memory-Augmented MCP Architecture) - Decision Context Formatter * * Formats decision history with token budget enforcement and top-N selection * Tasks: 6.1-6.6, 8.1-8.5 (Context formatting with top-N selection) * AC #1: Context under 500 tokens * AC #4: Rolling summary for large histories * AC #5: Top-N selection with summary * * @module decision-formatter * @version 2.0 * @date 2025-11-14 */ /** * Decision object for formatting */ export interface DecisionForFormat { id?: string; topic?: string; decision: string; reasoning?: string | null; outcome?: string | null; failure_reason?: string | null; limitation?: string | null; user_involvement?: string; confidence?: number; created_at: number | string; updated_at?: number | string; superseded_by?: string | null; relevanceScore?: number; similarity?: number; recency_age_days?: number; recency_score?: number; final_score?: number; trust_context?: TrustContext | string | null; evidence?: string | string[] | unknown; alternatives?: string | string[] | unknown; risks?: string; /** ISO 8601 date when the event actually occurred. Null if not set. */ event_date?: string | null; /** Source event timestamp in milliseconds when known. Null if not set. */ event_datetime?: number | null; } /** * Trust context object */ export interface TrustContext { source?: { file?: string; line?: number; author?: string; timestamp?: number | string; }; causality?: { impact?: string; }; verification?: { test_file?: string; result?: string; }; context_match?: { user_intent?: string; }; track_record?: { recent_successes?: unknown[]; recent_failures?: unknown[]; success_rate?: number; sample_size?: number; }; } /** * Semantic edges for related decisions */ export interface SemanticEdges { refines?: Array<{ topic: string; decision: string; }>; refined_by?: Array<{ topic: string; decision: string; }>; contradicts?: Array<{ topic: string; decision: string; }>; contradicted_by?: Array<{ topic: string; decision: string; }>; } /** * Formatting options */ export interface FormatOptions { maxTokens?: number; useTopN?: boolean; topN?: number; useTeaser?: boolean; limit?: number; } /** * Format decision context for Claude injection with top-N selection * * Task 6.1-6.2, 8.1-8.5: Build context format template with top-N selection * AC #1: Format decision history * AC #4: Handle large histories with rolling summary * AC #5: Top-N selection with summary (top 3 full detail, rest summarized) * * Story 014.7.10 - Task 5: Fallback Formatting * Tries Instant Answer format first (if trust_context available), falls back to legacy * * @param decisions - Decision chain (sorted by relevance) * @param options - Formatting options * @returns Formatted context for injection */ export declare function formatContext(decisions: DecisionForFormat[], options?: FormatOptions): string | null; /** * Format decisions using legacy format (no trust context) * * Story 014.7.10 - Task 5.1: Fallback formatting * AC #3: Graceful degradation for decisions without trust_context * * @param decisions - Decision chain (sorted by relevance) * @param options - Formatting options * @returns Formatted context (legacy format) */ export declare function formatLegacyContext(decisions: DecisionForFormat[], options?: FormatOptions): string | null; /** * Ensure token budget is enforced * * Task 6.3-6.5: Token budget enforcement * AC #1: Context stays under 500 tokens */ export declare function ensureTokenBudget(text: string, maxTokens: number): string; /** * Estimate token count from text * * Task 6.4: Simple token estimation * Heuristic: ~1 token per 4 characters */ export declare function estimateTokens(text: string): number; /** * Format context in Claude-friendly Instant Answer format * * Story 014.7.10: Claude-Friendly Context Formatting * AC #1: Instant Answer format with trust components */ export declare function formatInstantAnswer(decision: DecisionForFormat | null, options?: FormatOptions): string | null; /** * Extract quick answer from decision */ export declare function extractQuickAnswer(decision: DecisionForFormat): string | null; /** * Extract code example from reasoning */ export declare function extractCodeExample(decision: DecisionForFormat): string | null; /** * Format trust context section * * Story 014.7.10 AC #2: Trust Context display */ export declare function formatTrustContext(trustCtx: TrustContext | null | undefined): string | null; /** * Format decision as curiosity-inducing teaser */ export declare function formatTeaser(decision: DecisionForFormat | null): string | null; /** * Format mama.recall() results in readable format */ export declare function formatRecall(decisions: DecisionForFormat[], semanticEdges?: SemanticEdges | null): string; /** * Format recent decisions list (all topics, chronological) */ export declare function formatList(decisions: DecisionForFormat[], options?: FormatOptions): string; //# sourceMappingURL=decision-formatter.d.ts.map