import type { ActiveLazyMode } from "./modes.ts"; export const LAZY_HEADER_RE = /\n?LAZY MODE ACTIVE — level: (lite|full|ultra)\n[\s\S]*?\nEND LAZY MODE\n?/g; const LADDER = [ "Do not build what was not asked.", "Reuse existing code in this repo.", "Prefer stdlib.", "Prefer native platform APIs.", "Prefer installed deps over new deps.", "Prefer one-line/data-only changes.", "Write minimum custom code.", ]; const RULES = [ "No unrequested abstractions: no one-impl interfaces, factories, wrappers, or config nobody sets.", "Deletion over addition. Boring over clever. Fewest files possible.", "Lazy about the solution, never about reading: inspect the touched flow before choosing a rung.", "Two stdlib/native options, same size? Pick the edge-case-correct one.", "Mark deliberate simplifications with `lazy:` plus ceiling and upgrade trigger.", ]; const MODE_LINES: Record = { lite: [ "Build the requested thing, then mention the lazier alternative briefly.", "Do not block straightforward implementation with repeated challenges.", ], full: [ "Enforce the ladder before custom code.", "Challenge unnecessary scope once, then ship the smallest safe version.", ], ultra: [ "Deletion first: remove, merge, inline, or configure before adding code.", "Challenge nonessential requirements aggressively while preserving explicitly requested behavior.", ], }; export function buildLazyInstructions(mode: ActiveLazyMode): string { return [ `LAZY MODE ACTIVE — level: ${mode}`, "", "Ladder:", ...LADDER.map((line, index) => `${index + 1}. ${line}`), "", "Root-cause bug-fix rule: inspect callers and fix the shared route when possible.", "Rules:", ...RULES.map((line) => `- ${line}`), "Safety floor: never remove trust-boundary validation, data-loss handling, security, accessibility, hardware calibration, or explicitly requested behavior.", "Test floor: non-trivial logic leaves one small runnable check; trivial one-liners need no test.", "Output discipline: code first; short skipped/when-to-add note; no unrequested essays.", "", "Mode-specific:", ...MODE_LINES[mode].map((line) => `- ${line}`), "END LAZY MODE", ].join("\n"); } export function stripLazyInstructions(prompt: string): string { return prompt .replace(LAZY_HEADER_RE, "\n") .replace(/\n{3,}/g, "\n\n") .trimEnd(); } export function injectLazyInstructions( prompt: string, mode: ActiveLazyMode, ): string { const base = stripLazyInstructions(prompt); return `${base}\n\n${buildLazyInstructions(mode)}`; }