feat: auto-resolve @path references in skill templates to absolute paths

Skill loaders previously only told agents that @path references are
relative to the skill directory, but agents often failed to resolve
them. Now @path/with/slash patterns are automatically expanded to
absolute paths during template construction.
This commit is contained in:
YeonGyu-Kim
2026-02-09 11:37:57 +09:00
parent 8dd07973a9
commit 70ac962fca
6 changed files with 133 additions and 4 deletions
+17
View File
@@ -0,0 +1,17 @@
import { join } from "path"
/**
* Resolves @path references in skill content to absolute paths.
*
* Matches @references that contain at least one slash (e.g., @scripts/search.py, @data/)
* to avoid false positives with decorators (@param), JSDoc tags (@ts-ignore), etc.
*
* Email addresses are excluded since they have alphanumeric characters before @.
*/
export function resolveSkillPathReferences(content: string, basePath: string): string {
const normalizedBase = basePath.endsWith("/") ? basePath.slice(0, -1) : basePath
return content.replace(
/(?<![a-zA-Z0-9])@([a-zA-Z0-9_-]+\/[a-zA-Z0-9_.\-\/]*)/g,
(_, relativePath: string) => join(normalizedBase, relativePath)
)
}