Files
oh-my-pi/packages/coding-agent/test/skill-prompt-message.test.ts
T
metaphorics fa64097992 fix(coding-agent): identify user-invoked skills and expose skill directory
User-invoked skills (typed /skill:, steered, follow-up, interrupted/
resumed via compaction, ACP, RPC) only appended a bare "Skill: <path>"
line, so the model neither learned the user had invoked that specific
skill nor where the skill directory was. Relative paths in skill bodies
(scripts/, templates/) could not be resolved.

Route all user-invoked paths through a self-identifying, baseDir-aware
prompt template; keep hidden autoload skills on the minimal non-user
format. Interactive skillCommands now carries the loaded Skill object
instead of a bare path so baseDir flows through without reconstruction.
The invocation kind defaults to "user" to keep buildSkillPromptMessage
source-compatible.

Op: correct
Restores: spec:user-invoked-skill-prompt-self-identifies-and-exposes-skill-directory
2026-06-30 23:11:05 +09:00

61 lines
2.2 KiB
TypeScript

import { describe, expect, test } from "bun:test";
import * as fs from "node:fs/promises";
import * as os from "node:os";
import * as path from "node:path";
import { buildSkillPromptMessage, type Skill } from "@oh-my-pi/pi-coding-agent/extensibility/skills";
import { removeWithRetries, Snowflake } from "@oh-my-pi/pi-utils";
async function createSkill(body: string): Promise<{ dir: string; skill: Skill }> {
const dir = await fs.mkdtemp(path.join(os.tmpdir(), `omp-skill-prompt-${Snowflake.next()}-`));
const filePath = path.join(dir, "SKILL.md");
await Bun.write(filePath, `---\nname: reviewer\ndescription: Review code\n---\n\n${body}\n`);
return {
dir,
skill: {
name: "reviewer",
description: "Review code",
filePath,
baseDir: dir,
source: "test",
},
};
}
describe("buildSkillPromptMessage", () => {
test("defaults public skill prompt rendering to user-invoked bug-fix directory guidance", async () => {
const { dir, skill } = await createSkill("Review the supplied code carefully.");
try {
const built = await buildSkillPromptMessage(skill, "focus on risks");
expect(built.message).toContain("Review the supplied code carefully.");
expect(built.message).toContain('The user has invoked the "reviewer" skill');
expect(built.message).toContain(`[Skill directory: ${dir}]`);
expect(built.message).toMatch(/[Rr]esolve any relative paths/);
expect(built.message).toContain("User: focus on risks");
expect(built.details).toMatchObject({
name: "reviewer",
path: skill.filePath,
args: "focus on risks",
lineCount: 1,
});
} finally {
await removeWithRetries(dir);
}
});
test("keeps autoload skills on non-user minimal framing", async () => {
const { dir, skill } = await createSkill("Review silently loaded context.");
try {
const built = await buildSkillPromptMessage(skill, "", "autoload");
expect(built.message).toContain("Review silently loaded context.");
expect(built.message).toContain(`Skill: ${skill.filePath}`);
expect(built.message).not.toContain("The user has invoked");
expect(built.message).not.toContain("[Skill directory:");
expect(built.details).toMatchObject({ name: "reviewer", path: skill.filePath, lineCount: 1 });
} finally {
await removeWithRetries(dir);
}
});
});