skillFromText function

Skill? skillFromText(
  1. String text, {
  2. required String filePath,
  3. required String fallbackName,
  4. required SkillScope scope,
  5. required SkillSource source,
  6. String? embeddedText,
})

Parses one SKILL.md text into a Skill (shared by disk discovery and the compiled-in built-ins, issue #1151). Returns null when the name is empty.

Implementation

Skill? skillFromText(
  String text, {
  required String filePath,
  required String fallbackName,
  required SkillScope scope,
  required SkillSource source,
  String? embeddedText,
}) {
  final (frontmatter, body) = parseFrontmatterTyped(text);
  final manifest = SkillManifest.fromFrontmatter(
    frontmatter,
    skillName: fallbackName,
  );
  final name = ('${frontmatter['name'] ?? fallbackName}').trim();
  if (name.isEmpty) return null;
  return Skill(
    name: name,
    description: _skillDescription(manifest, body),
    filePath: filePath,
    scope: scope,
    source: source,
    manifest: manifest,
    embeddedText: embeddedText,
  );
}