import type { ExtensionAPI } from "@mariozechner/pi-coding-agent"; import { formatSkillsForPrompt, loadSkills } from "@mariozechner/pi-coding-agent"; import { registerPromptSegment } from "../../../vera-prompt-inspector/src/registry"; // Vera's prompt-rules extension replaces Pi's default base prompt // entirely, which incidentally throws away the skills section Pi would // normally inject via `formatSkillsForPrompt`. This extension re-adds // it as a dedicated, inspector-visible segment, using the same Pi APIs // so the format stays in sync with Pi's own behaviour. export default function skillCatalog(pi: ExtensionAPI) { pi.on("before_agent_start", async (_event, ctx) => { // skillPaths is required to be iterable by Pi (skills.js:352); // pass an empty array even when we only want default discovery. const result = loadSkills({ cwd: ctx.cwd, skillPaths: [], includeDefaults: true, }); const block = formatSkillsForPrompt(result.skills); // `formatSkillsForPrompt` returns text with a leading "\n\n"; strip // it so the finalizer in vera-prompt-inspector can add its own // separator consistently. const text = block.replace(/^\n+/, ""); const visibleCount = result.skills.filter((s) => !s.disableModelInvocation).length; registerPromptSegment({ id: "skills", label: "skill catalog", category: "catalog", kind: "cached-per-session", text, details: [ { label: "skills", value: String(visibleCount) }, { label: "diagnostics", value: String(result.diagnostics?.length ?? 0) }, ], }); return undefined; }); }