import { getAgentDir, type ExtensionAPI } from "@earendil-works/pi-coding-agent"; import { readCoverFile, resolveCoverPath, spliceCover } from "./system-prompt-cover-config.ts"; export { COVER_FILE_NAME, readCoverFile, resolveCoverPath, spliceCover } from "./system-prompt-cover-config.ts"; /** * Replaces Pi's default system prompt preamble with the bundle-managed cover while * preserving every other prompt section in its original position. * * The cover is read on each `before_agent_start`, so edits to `SYSTEM_COVER.md` take * effect on the next turn of an already-running session rather than requiring a restart. * * Returning `systemPrompt` sets Pi's `forceSystemPrompt`, which is projected onto the * request at send time. That is deliberate: it is the only path that keeps the rendered * section order intact. The options-based alternative (`customPrompt`) would suppress * `tools`, `rules`, and `docs`, and any later re-injection cannot restore their original * positions. Pi still diffs and persists the structured sections in the transcript. */ export default function systemPromptCoverExtension(pi: ExtensionAPI): void { pi.on("before_agent_start", (event) => { const cover = readCoverFile(resolveCoverPath(getAgentDir())); if (cover === undefined) { return; } return { systemPrompt: spliceCover(event.systemPrompt, cover) }; }); }