Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions packages/common/src/base/prompts/__tests__/skill.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import type { Skill } from "@getpochi/tools";
import { describe, expect, it } from "vitest";
import { createUseSkillResult } from "../skill";

const baseSkill: Skill = {
name: "demo-skill",
description: "A demo skill",
filePath: ".pochi/skills/demo-skill/SKILL.md",
instructions: "Do the thing.",
};

describe("createUseSkillResult", () => {
it("prepends the skill file path to the result", () => {
const result = createUseSkillResult(baseSkill);
expect(result).toContain(
"Skill location: .pochi/skills/demo-skill/SKILL.md",
);
expect(result).toContain("Do the thing.");
});

it("keeps tool restriction instructions alongside the path", () => {
const result = createUseSkillResult({
...baseSkill,
allowedTools: "readFile writeToFile",
});
expect(result).toContain("Skill location:");
expect(result).toContain(
"This skill is restricted to use only the following tools: readFile writeToFile",
);
expect(result).toContain("Do the thing.");
});

it("omits the location line when no file path is available", () => {
const result = createUseSkillResult({ ...baseSkill, filePath: "" });
expect(result).not.toContain("Skill location:");
expect(result).toBe("Do the thing.");
});
});
9 changes: 9 additions & 0 deletions packages/common/src/base/prompts/skill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ export function createUseSkillResult(skill: Skill): string {

You must ONLY use these approved tools when executing this skill. Do not use any other tools that are not explicitly listed above.

${prompt}`;
}

// Surface the skill's file path so the model can resolve sibling resources
// (scripts/, references/, assets/) relative to the skill's directory.
if (skill.filePath?.trim()) {
prompt = `Skill location: ${skill.filePath.trim()}
Use the directory containing this file as the base directory for resolving any relative resource paths referenced in the instructions below.

${prompt}`;
}

Expand Down
Loading