import assert from "node:assert/strict"; import { readFileSync } from "node:fs"; import { join } from "node:path"; import { describe, it } from "node:test"; const readProjectFile = (file: string): string => readFileSync(join(process.cwd(), file), "utf-8"); describe("pi-subagents delegation policy guidance", () => { it("keeps delegation operator-authorized and cost-bounded", () => { const skill = readProjectFile("skills/pi-subagents/SKILL.md"); const prompting = readProjectFile("skills/pi-subagents/references/prompting-and-roles.md"); const recipes = readProjectFile("skills/pi-subagents/references/constraints-and-recipes.md"); const lanes = readProjectFile("skills/pi-subagents/references/multi-lane-orchestration.md"); const guidance = [skill, prompting, recipes, lanes].join("\n"); assert.match(skill, /parent works directly by default/i); assert.match(skill, /only when the operator\s+requested delegation in the current request.*applicable user\/project\s+instructions/is); assert.match(skill, /task size, complexity, risk, tool-call count, recipe fit.*does not independently authorize delegation/is); assert.match(skill, /smallest bounded shape.*earns its token and\s+elapsed-time overhead/is); assert.match(prompting, /all launch guidance.*assumes delegation was requested by the operator/is); assert.match(recipes, /recipes select a shape; they do not authorize delegation/i); assert.match(lanes, /only after delegation is operator-authorized.*materially improves/is); assert.doesNotMatch(guidance, /not the routine primary doer/i); assert.doesNotMatch(guidance, /delegate[^\n]*(?:most|all) non-trivial requests/i); assert.doesNotMatch(guidance, /use this at the start of non-trivial work/i); }); // Upstream 0.79 makes the parent subagent tools model-only. Selesai registers `subagent`, `bg_wait`, // `subagent_wait` and `subagent_supervisor` for codemode instead, so that prohibition must not be copied here. it("keeps the Selesai codemode contract instead of the upstream model-only prohibition", () => { const upstreamProhibition = /`subagent`, `subagents_enable`, `subagent_supervisor`, `contact_supervisor`, and `structured_output`[^\n]*model-only/; for (const file of ["skills/pi-subagents/SKILL.md", "skills/pi-subagents/references/execution-controls.md"]) { assert.doesNotMatch(readProjectFile(file), upstreamProhibition, `${file} must state the Selesai codemode contract`); } const readme = readProjectFile("README.md"); assert.match(readme, /`subagent_wait`[^\n]*`codemode` exposure/); assert.match(readme, /`contact_supervisor` and `structured_output` remain model-only/); }); });