/** * Injection-policy v1 (Wave 4d, ADR-005/ADR-010) — the heuristic * "when-to-recall" layer. This is deliberately a THIN layer above pack * selection, not part of search: the store answers "what matches", * the policy answers "should anything be injected at all, and how much". * * v1 heuristics (no ML — instrumented via usefulness events so it can * become learned later): * 1. Task-type gating — trivial/smalltalk or very short prompts get no * injection unless they explicitly reference memory ("remember", * "last time", "we decided", ...). * 2. Confidence threshold — only memories whose selection score clears * `minScore` are injected; a pack of weak matches is worse than none. * 3. Token-budget-aware top-k — the longer the prompt already is, the * smaller the injection budget ("long context kills retrieval"). * * Every injected memory is recorded as a recall_served usefulness event * (ADR-010) so served-but-never-used patterns can tune this layer. */ import type { DB } from '../storage/db.js'; import type { Config } from '../config/config.js'; import { type PackMemory } from './pack.js'; export interface PolicyDecision { inject: boolean; /** Machine-readable reason — stable strings, used in tests + telemetry. */ reason: 'injected' | 'no-eligible-memories' | 'prompt-too-short' | 'smalltalk' | 'below-min-score' | 'policy-disabled'; memories: PackMemory[]; pack: string; budget_tokens: number; } export interface PolicyInput { repo: string; project?: string | null; branch?: string | null; prompt: string; /** Requested budget; the policy may shrink it, never grow it. */ budgetTokens?: number; now?: number; } export declare function shrinkBudgetForPrompt(baseBudget: number, promptChars: number): number; export declare function decideInjection(db: DB, config: Config, input: PolicyInput): PolicyDecision;