fix(installer): rewrite relative workflow.md paths in verbatim skills

Some AI tools (e.g., opencode) resolve relative markdown links from the
project root instead of the skill file's directory, causing co-located
workflow.md files to not be found. This patch rewrites (workflow.md)
references in SKILL.md to use {project-root}-prefixed absolute paths
during verbatim skill installation, consistent with template-generated
artifacts.

Fixes #1956

Made-with: Cursor
This commit is contained in:
leon 2026-03-14 15:02:53 +08:00
parent 405fd93e50
commit fbe43dcdcf
1 changed files with 18 additions and 0 deletions

View File

@ -686,6 +686,24 @@ LOAD and execute from: {project-root}/{{bmadFolderName}}/{{path}}
};
await fs.copy(sourceDir, skillDir, { filter });
// Rewrite relative workflow.md references to use {project-root} absolute paths.
// Some AI tools resolve relative paths from CWD instead of the skill file's
// directory, causing co-located files like workflow.md to not be found.
try {
const skillMdPath = path.join(skillDir, 'SKILL.md');
if (await fs.pathExists(skillMdPath)) {
let skillContent = await fs.readFile(skillMdPath, 'utf8');
const workflowLinkPattern = /\]\((?:\.\/)?workflow\.md\)/g;
if (workflowLinkPattern.test(skillContent)) {
const skillRelativePath = path.relative(projectDir, skillDir).split(path.sep).join('/');
skillContent = skillContent.replaceAll(/\]\((?:\.\/)?workflow\.md\)/g, `]({project-root}/${skillRelativePath}/workflow.md)`);
await fs.writeFile(skillMdPath, skillContent, 'utf8');
}
}
} catch {
// Non-fatal: skip rewrite for this skill and continue installing remaining skills
}
count++;
}