|
| 1 | +/** |
| 2 | + * Nudge Variant Support |
| 3 | + * |
| 4 | + * Reads GITMEM_NUDGE_VARIANT env var to select alternative header |
| 5 | + * framings for recall/prepare-context output. Used by nudge-bench |
| 6 | + * to A/B test how different wording affects agent compliance. |
| 7 | + * |
| 8 | + * When no env var is set, returns the production default. |
| 9 | + * |
| 10 | + * Variant IDs match nudge-bench/variants/n001-header.ts |
| 11 | + */ |
| 12 | + |
| 13 | +export interface NudgeHeader { |
| 14 | + icon: string; |
| 15 | + text: (count: number) => string; |
| 16 | +} |
| 17 | + |
| 18 | +const VARIANTS: Record<string, NudgeHeader> = { |
| 19 | + // Production default |
| 20 | + "n001-a-institutional": { |
| 21 | + icon: "🧠", |
| 22 | + text: (n) => `INSTITUTIONAL MEMORY ACTIVATED\n\nFound ${n} relevant scar${n === 1 ? "" : "s"} for your plan:`, |
| 23 | + }, |
| 24 | + // Informational/passive |
| 25 | + "n001-b-recalled": { |
| 26 | + icon: "\x1b[38;5;37m⬢\x1b[0m", |
| 27 | + text: (n) => `gitmem ── ${n} learnings recalled`, |
| 28 | + }, |
| 29 | + // Obligation |
| 30 | + "n001-c-review": { |
| 31 | + icon: "\x1b[38;5;37m⬢\x1b[0m", |
| 32 | + text: (n) => `gitmem ── ${n} scar${n === 1 ? "" : "s"} to review`, |
| 33 | + }, |
| 34 | + // Directive |
| 35 | + "n001-d-directive": { |
| 36 | + icon: "\x1b[38;5;37m⬢\x1b[0m", |
| 37 | + text: (n) => `gitmem ── review ${n} learning${n === 1 ? "" : "s"} before proceeding`, |
| 38 | + }, |
| 39 | + // Procedural — ties to confirm_scars |
| 40 | + "n001-e-confirm": { |
| 41 | + icon: "\x1b[38;5;37m⬢\x1b[0m", |
| 42 | + text: (n) => `gitmem ── ${n} scar${n === 1 ? "" : "s"} found — confirm before acting`, |
| 43 | + }, |
| 44 | + // Reasoning — explains WHY (Karpathy: reasoning > command) |
| 45 | + "n001-f-reasoning": { |
| 46 | + icon: "\x1b[38;5;37m⬢\x1b[0m", |
| 47 | + text: (n) => `gitmem ── ${n} past mistake${n === 1 ? "" : "s"} detected that may repeat here — review to avoid the same outcome`, |
| 48 | + }, |
| 49 | +}; |
| 50 | + |
| 51 | +const DEFAULT_VARIANT = "n001-c-review"; |
| 52 | + |
| 53 | +/** |
| 54 | + * Get the active nudge header based on GITMEM_NUDGE_VARIANT env var. |
| 55 | + * Falls back to production default if unset or invalid. |
| 56 | + */ |
| 57 | +export function getNudgeHeader(): NudgeHeader { |
| 58 | + const variantId = process.env.GITMEM_NUDGE_VARIANT; |
| 59 | + if (!variantId) return VARIANTS[DEFAULT_VARIANT]; |
| 60 | + return VARIANTS[variantId] || VARIANTS[DEFAULT_VARIANT]; |
| 61 | +} |
| 62 | + |
| 63 | +/** |
| 64 | + * Format the recall header line using the active nudge variant. |
| 65 | + */ |
| 66 | +export function formatNudgeHeader(scarCount: number): string { |
| 67 | + const header = getNudgeHeader(); |
| 68 | + return `${header.icon} ${header.text(scarCount)}`; |
| 69 | +} |
| 70 | + |
| 71 | +/** |
| 72 | + * Get the active variant ID (for logging/metrics). |
| 73 | + */ |
| 74 | +export function getActiveVariantId(): string { |
| 75 | + const variantId = process.env.GITMEM_NUDGE_VARIANT; |
| 76 | + if (variantId && VARIANTS[variantId]) return variantId; |
| 77 | + return DEFAULT_VARIANT; |
| 78 | +} |
0 commit comments