validateSkillPointerTarget function
Validates a pointer body for a read of path; returns the refusal
reason, or null when the pointer is a valid builtin SKILL.md reference
for path's own directory. Checks, in order:
- the body carries exactly one
builtin://skills/...target; - the target names an existing builtin skill;
- the target's skill name matches the directory containing
path(a pointer may only resolve its own skill — a stray pointer cannot redirect one skill's path at another skill's body).
Implementation
String? validateSkillPointerTarget(String path, String content) {
final target = skillPointerTarget(content);
if (target == null) {
return 'pointer target must be a single builtin://skills/<name>/SKILL.md '
'URI';
}
final name = targetSkillName(target);
if (name == null || builtinSkillTextAt(target) == null) {
return 'pointer target $target is not a compiled-in builtin skill';
}
final dir = path.contains('/')
? path.substring(0, path.lastIndexOf('/'))
: '';
final dirName = dir.contains('/') ? dir.substring(dir.lastIndexOf('/') + 1) : dir;
if (dirName.isNotEmpty && dirName != name) {
return 'pointer target $target does not match the skill directory '
'$dirName';
}
return null;
}