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 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.", "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)}`; }