fix(prompt): render skills without pi shape casts

This commit is contained in:
ZacharyZhang-NY committed 2026-04-22 18:39:56 -04:00
1 parent 9f35dc7446
commit dca148a125
2 files changed
+46 -19

No files matched your search

+30 -19
View File
@@ -1,6 +1,5 @@
import { DEPARTMENT_LABELS } from "@shared/constants"; import { DEPARTMENT_LABELS } from "@shared/constants";
import type { DepartmentId } from "@shared/types"; import type { DepartmentId } from "@shared/types";
import { formatSkillsForPrompt } from "@mariozechner/pi-coding-agent";
import { import {
buildTaskSection, buildTaskSection,
buildReviewSection, buildReviewSection,
@@ -30,27 +29,39 @@ function isLeadershipRole(ctx: PromptContext): boolean {
} }
/** /**
* Render the skill manifest block using pi-coding-agent's XML format. * Render the Agent Skills manifest from the runtime projection. The prompt
* * carries only name, description, and SKILL.md location; the agent reads the
* The full SKILL.md content is NOT injected — only name/description/filePath. * full file on demand through the filesystem tool.
* The agent loads SKILL.md on demand via the `read` tool (progressive
* disclosure). Pi's `formatSkillsForPrompt` expects its full `Skill` shape, so
* we supply synthetic values for the two fields we don't track (`sourceInfo`,
* `disableModelInvocation`). Cast is safe because pi's XML renderer only reads
* `name`, `description`, `filePath`, and `disableModelInvocation`.
*/ */
function buildSkillManifest(skills: ProjectedSkill[] | undefined): string { function buildSkillManifest(skills: ProjectedSkill[] | undefined): string {
if (!skills || skills.length === 0) return ""; if (!skills || skills.length === 0) return "";
const piShapedSkills = skills.map((s) => ({ const lines = [
name: s.name, "\n\nThe following skills provide specialized instructions for specific tasks.",
description: s.description, "Use the read tool to load a skill's file when the task matches its description.",
filePath: s.filePath, "When a skill file references a relative path, resolve it against the skill directory (parent of SKILL.md / dirname of the path) and use that absolute path in tool commands.",
baseDir: s.baseDir, "",
disableModelInvocation: false, "<available_skills>",
// sourceInfo is required by pi's Skill interface but never read by ];
// formatSkillsForPrompt. Leaving it undefined and asserting the shape.
})); for (const skill of skills) {
return formatSkillsForPrompt(piShapedSkills as never); lines.push(" <skill>");
lines.push(` <name>${escapeSkillXml(skill.name)}</name>`);
lines.push(` <description>${escapeSkillXml(skill.description)}</description>`);
lines.push(` <location>${escapeSkillXml(skill.filePath)}</location>`);
lines.push(" </skill>");
}
lines.push("</available_skills>");
return lines.join("\n");
}
function escapeSkillXml(value: string): string {
return value
.replaceAll("&", "&amp;")
.replaceAll("<", "&lt;")
.replaceAll(">", "&gt;")
.replaceAll('"', "&quot;")
.replaceAll("'", "&apos;");
} }
export function buildSystemPrompt(ctx: PromptContext): string { export function buildSystemPrompt(ctx: PromptContext): string {
@@ -79,4 +79,20 @@ describe("buildSystemPrompt leadership classification", () => {
expect(prompt).toContain("New hires for your team should report to you by default"); expect(prompt).toContain("New hires for your team should report to you by default");
expect(prompt).not.toContain("Operating Instructions (Individual Contributor)"); expect(prompt).not.toContain("Operating Instructions (Individual Contributor)");
}); });
it("renders projected skills without pi skill shape casts", () => {
const prompt = buildSystemPrompt(buildCtx({
skills: [{
name: "ui<review>&qa",
description: "Use for A&B \"checks\" and 'snapshots'.",
filePath: "/tmp/skills/ui<review>&qa/SKILL.md",
baseDir: "/tmp/skills/ui<review>&qa",
}],
}));
expect(prompt).toContain("<available_skills>");
expect(prompt).toContain("<name>ui&lt;review&gt;&amp;qa</name>");
expect(prompt).toContain("<description>Use for A&amp;B &quot;checks&quot; and &apos;snapshots&apos;.</description>");
expect(prompt).toContain("<location>/tmp/skills/ui&lt;review&gt;&amp;qa/SKILL.md</location>");
});
}); });