followSkillPointer function
Reads the <path>.pointer sibling of path through readPointer and
classifies it. readPointer returns null when the file does not exist.
The security invariant (gh-1444): only builtin://skills/<name>/SKILL.md
targets naming a compiled-in skill whose name matches the directory of
path resolve; everything else is SkillPointerRefused.
Implementation
Future<SkillPointerFollow> followSkillPointer(
String path,
Future<String?> Function(String pointerPath) readPointer,
) async {
String? content;
try {
content = await readPointer('$path.pointer');
} on Object {
return const SkillPointerAbsent();
}
if (content == null) return const SkillPointerAbsent();
final reason = validateSkillPointerTarget(path, content);
if (reason != null) return SkillPointerRefused(reason);
final target = skillPointerTarget(content)!;
final text = builtinSkillTextAt(target);
if (text == null) {
return SkillPointerRefused(
'pointer target $target is not a compiled-in builtin skill',
);
}
return SkillPointerResolved(text, targetSkillName(target)!);
}