2026-02-09 11:37:57 +09:00
|
|
|
import { join } from "path"
|
|
|
|
|
|
2026-03-27 16:59:04 +09:00
|
|
|
function looksLikeFilePath(path: string): boolean {
|
|
|
|
|
if (path.endsWith("/")) return true
|
|
|
|
|
const lastSegment = path.split("/").pop() ?? ""
|
|
|
|
|
return /\.[a-zA-Z0-9]+$/.test(lastSegment)
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-09 11:37:57 +09:00
|
|
|
/**
|
|
|
|
|
* 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.
|
2026-03-27 16:59:04 +09:00
|
|
|
* Also skips npm scoped packages (@scope/package) by requiring a file extension or trailing slash.
|
2026-02-09 11:37:57 +09:00
|
|
|
*
|
|
|
|
|
* 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,
|
2026-03-27 16:59:04 +09:00
|
|
|
(match, relativePath: string) => {
|
|
|
|
|
if (!looksLikeFilePath(relativePath)) return match
|
|
|
|
|
return join(normalizedBase, relativePath)
|
|
|
|
|
}
|
2026-02-09 11:37:57 +09:00
|
|
|
)
|
|
|
|
|
}
|