MCPcopy Index your code
hub / github.com/VectifyAI/OpenKB / _write_skill

Function _write_skill

tests/test_skill_validator.py:20–69  ·  view source on GitHub ↗

Create a skill directory with the requested contents. frontmatter: "default" -> a valid minimal frontmatter with matching name + long desc str -> use that exact frontmatter block (between --- markers) None -> write the body with NO frontmatter at all

(
    parent: Path,
    name: str,
    *,
    frontmatter: str | None = "default",
    body: str = "# body\n",
    refs: dict[str, str] | None = None,
    scripts: dict[str, str] | None = None,
    skill_md_bytes: int | None = None,
)

Source from the content-addressed store, hash-verified

18
19
20def _write_skill(
21 parent: Path,
22 name: str,
23 *,
24 frontmatter: str | None = "default",
25 body: str = "# body\n",
26 refs: dict[str, str] | None = None,
27 scripts: dict[str, str] | None = None,
28 skill_md_bytes: int | None = None,
29) -> Path:
30 """Create a skill directory with the requested contents.
31
32 frontmatter:
33 "default" -> a valid minimal frontmatter with matching name + long desc
34 str -> use that exact frontmatter block (between --- markers)
35 None -> write the body with NO frontmatter at all
36 """
37 skill_dir = parent / name
38 skill_dir.mkdir(parents=True, exist_ok=True)
39 if frontmatter == "default":
40 fm = f"name: {name}\ndescription: A useful and descriptive skill activation signal."
41 else:
42 fm = frontmatter
43
44 if fm is None:
45 text = body
46 else:
47 text = f"---\n{fm}\n---\n\n{body}"
48
49 if skill_md_bytes is not None:
50 text = text + ("x" * skill_md_bytes)
51 (skill_dir / "SKILL.md").write_text(text, encoding="utf-8")
52
53 if refs:
54 refs_dir = skill_dir / "references"
55 refs_dir.mkdir(exist_ok=True)
56 for relpath, content in refs.items():
57 target = refs_dir / relpath
58 target.parent.mkdir(parents=True, exist_ok=True)
59 target.write_text(content, encoding="utf-8")
60
61 if scripts:
62 scripts_dir = skill_dir / "scripts"
63 scripts_dir.mkdir(exist_ok=True)
64 for relpath, content in scripts.items():
65 target = scripts_dir / relpath
66 target.parent.mkdir(parents=True, exist_ok=True)
67 target.write_text(content, encoding="utf-8")
68
69 return skill_dir
70
71
72# ---------------------------------------------------------------------------

Calls

no outgoing calls

Tested by

no test coverage detected