Skip to content

Commit dd2a1cc

Browse files
committed
fix: resolve skill resource relative paths against skill directory
- Updated loaded skill prompt output to explicitly override the project root relative path rule, ensuring agents correctly resolve relative paths against the skill's directory. - Stripped `file://` protocol formatting from skill locations in context so the agent's file tools recognize them as absolute paths. - Added variable interpolation for `{{SKILL_DIR}}` in skill content. Fixes anomalyco#17101
1 parent 8da511d commit dd2a1cc

3 files changed

Lines changed: 5 additions & 6 deletions

File tree

‎packages/opencode/src/skill/skill.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ export namespace Skill {
207207
` <skill>`,
208208
` <name>${skill.name}</name>`,
209209
` <description>${skill.description}</description>`,
210-
` <location>${pathToFileURL(skill.location).href}</location>`,
210+
` <location>${skill.location}</location>`,
211211
` </skill>`,
212212
]),
213213
"</available_skills>",

‎packages/opencode/src/tool/skill.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ export const SkillTool = Tool.define("skill", async (ctx) => {
5656
})
5757

5858
const dir = path.dirname(skill.location)
59-
const base = pathToFileURL(dir).href
6059

6160
const limit = 10
6261
const files = await iife(async () => {
@@ -84,10 +83,10 @@ export const SkillTool = Tool.define("skill", async (ctx) => {
8483
`<skill_content name="${skill.name}">`,
8584
`# Skill: ${skill.name}`,
8685
"",
87-
skill.content.trim(),
86+
skill.content.trim().replace(/\{\{SKILL_DIR\}\}/g, () => dir),
8887
"",
89-
`Base directory for this skill: ${base}`,
90-
"Relative paths in this skill (e.g., scripts/, reference/) are relative to this base directory.",
88+
`Base directory for this skill: ${dir}`,
89+
"IMPORTANT: When reading files requested by this loaded skill's instructions, you MUST resolve relative paths against the skill's base directory above, NOT the project root.",
9190
"Note: file list is sampled.",
9291
"",
9392
"<skill_files>",

‎packages/opencode/test/tool/skill.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Use this skill.
102102

103103
expect(result.metadata.dir).toBe(dir)
104104
expect(result.output).toContain(`<skill_content name="tool-skill">`)
105-
expect(result.output).toContain(`Base directory for this skill: ${pathToFileURL(dir).href}`)
105+
expect(result.output).toContain(`Base directory for this skill: ${dir}`)
106106
expect(result.output).toContain(`<file>${file}</file>`)
107107
},
108108
})

0 commit comments

Comments
 (0)