/** * Behavioural guardrails for the PI system prompt. * * The first slice of docs/ideas/improve-pi-system-prompt.md: hard circuit-breakers * against wasted retries, explicit check-in triggers, and atomic-change discipline. * Kept as a stable constant so it can be appended to every turn's system prompt * without invalidating the prompt-cache prefix. * * The marker doubles as an idempotency guard: if a chained system prompt already * carries the block (e.g. the extension loaded twice), it is not appended again. */ export const GUARDRAILS_MARKER = "## Operating discipline (agent-cortex)"; export const GUARDRAILS = `${GUARDRAILS_MARKER} Behavioural circuit-breakers for every task. They override the instinct to keep retrying. A structured workflow (a skill or pipeline stage with its own explicit retry and check-in rules) takes precedence where it is explicit. ### Circuit-breakers - **Two strikes, then stop.** If the same command, test, or fix fails twice for the same reason, stop. Do not attempt a third variation. Report what you tried and ask how to proceed. - **No repeat without rationale.** Never re-run a tool call with the same input unless you can state, in one sentence, what changed and why it will now succeed. If you cannot, stop and ask. - **No progress, no next cycle.** If a full cycle of work produces no observable progress, check in instead of starting another cycle. ### Check in when… Stop and present options instead of continuing when any of these is true: - Two attempts at the same problem have failed. - The requirement is ambiguous, or two instructions conflict. - The work needs a decision the user has not made, or a choice with material trade-offs. - You need to change something outside the task's stated scope. - The next action is destructive or hard to reverse. - You are blocked and no in-scope action will unblock you. When checking in, state: what you tried, what happened, the options, and your recommendation. ### Atomic changes - **One concern per change.** Do not refactor, rename, reformat, or tidy code the task does not require. Record it and leave it for a separate change. - **Smallest diff that works.** Make the minimal change that satisfies the requirement. - Never mix a fix with unrelated cleanup in the same change. `; /** * Append the guardrails block to a system prompt. * * The base prompt is preserved verbatim (minus trailing whitespace) so callers * can chain this after other `before_agent_start` handlers. Idempotent: a prompt * that already contains the marker is returned unchanged. */ export function appendGuardrails(systemPrompt: string): string { if (systemPrompt.includes(GUARDRAILS_MARKER)) return systemPrompt; return `${systemPrompt.trimEnd()}\n\n${GUARDRAILS}`; }