import assert from "node:assert/strict"; import { readFileSync } from "node:fs"; import path from "node:path"; import { describe, it } from "vitest"; import { systemPromptFor } from "../system-prompts.ts"; const root = path.resolve(import.meta.dirname, ".."); const packageJson = () => JSON.parse(readFileSync(path.join(root, "package.json"), "utf8")) as { pi?: { extensions?: string[]; prompts?: string[]; skills?: string[] }; }; const repositoryPackage = () => JSON.parse( readFileSync(path.join(root, "../..", "package.json"), "utf8"), ) as { pi?: { extensions?: string[]; prompts?: string[]; skills?: string[] }; }; describe("the-system internal prompt model", () => { it("ships conditional System format skills without exporting them statically", () => { const extension = packageJson(); assert.deepEqual(extension.pi, { extensions: ["index.ts"] }); const repository = repositoryPackage(); assert.ok(!repository.pi?.skills?.includes("extensions/the-system/skills")); assert.ok( !repository.pi?.prompts?.includes("extensions/the-system/prompts"), ); for (const name of [ "the-system-gfm", "the-system-tex", "the-system-mermaid", ]) { const skill = readFileSync( path.join(root, "skills", name, "SKILL.md"), "utf8", ); assert.match(skill, new RegExp(`name: ${name}`)); assert.match(skill, /description: Use when /); assert.doesNotMatch( skill, /Apply the active System contracts|create another System bundle|board state|stage progression/, ); assert.doesNotMatch( skill.split("---", 3)[1] ?? "", /System Markdown contract|already been selected|bundle|create|author/, ); } }); it("ships a generally invocable vertical-slices skill", () => { const skill = readFileSync( path.join(root, "skills", "vertical-slices", "SKILL.md"), "utf8", ); assert.match(skill, /name: vertical-slices/); assert.match( skill, /description: "Use when planning or implementing vertical slices, walking skeletons, or thin end-to-end increments\."/, ); assert.match( skill, /A slice is complete only when its behavior is integrated, observable, tested, and freshly verified/, ); assert.match( skill, /A plan defines the required outcome, not the implementation order/, ); assert.match(skill, /slice boundaries are not human approval points/); assert.doesNotMatch(skill, /The System|\.system/); }); it("governs System document formats in each Markdown stage", () => { for (const stage of [ "init", "research", "spec", "spec-verify", "phase", "plan", "issue", ]) { const prompt = systemPromptFor(stage, ""); assert.match( prompt, /Task lists contain only static checkable criteria and remain unchecked/, ); assert.match( prompt, /Never diagram \/system stage progression or plan, spec, issue, or board progress/, ); assert.match(prompt, /Replace or remove obsolete canonical text/); assert.match(prompt, /use absolute HTTPS links for external sources/); } }); it("keeps System instructions internal to the /system command", () => { const prompts = readFileSync(path.join(root, "system-prompts.ts"), "utf8"); assert.match(prompts, /The System document contract/); assert.match(prompts, /The System Markdown contract/); assert.match(prompts, /load its matching the-system-\* skill/); assert.match(prompts, /No instructions were supplied/); assert.match(prompts, /\/system view /); }); });