--- before/brief.mjs +++ after/brief.mjs @@ -export function buildBrief(input) { - return [ - `Goal: ${input.goal.trim()}`, - `Stack: ${input.stack.trim()}`, - `Current state: ${input.current.trim()}` - ].join("\n"); -} +const limits = { goal: 500, stack: 160, current: 800 }; + +function normalize(value, limit) { + return String(value ?? "").replace(/\s+/g, " ").trim().slice(0, limit); +} + +export function buildBrief(input = {}) { + const goal = normalize(input.goal, limits.goal); + if (!goal) throw new TypeError("A primary goal is required"); + + const stack = normalize(input.stack, limits.stack) || "To confirm"; + const current = normalize(input.current, limits.current) || "To confirm"; + return [`Goal: ${goal}`, `Stack: ${stack}`, `Current state: ${current}`].join("\n"); +}