pi-web-runtime / sandbox /skill-defaults.py
Mike0021's picture
Only hf-cli on by default; the user's skill choices kept across machines
314746a verified
Raw History Blame Contribute Delete
1.07 kB
"""skill-defaults.py <skills dir> <enabled skill>...: the image's skill defaults. The listed skills are on,
every other one is off (`disable-model-invocation: true`: not offered to the model, still usable as
/skill:<name>, and turned on in Pi Web's Settings > Skills). Pi Web keeps a user's own choices in the agent
dir and puts them back on every new machine (lib/skill-choices.ts)."""
import pathlib, re, sys
root, enabled = pathlib.Path(sys.argv[1]), set(sys.argv[2:])
skills = sorted(root.glob("*/SKILL.md"))
assert any(p.parent.name in enabled for p in skills), f"none of {sorted(enabled)} in {root}"
for skill in skills:
name, text = skill.parent.name, skill.read_text()
head = re.match(r"\A---[ \t]*\n(.*?\n)---", text, re.S)
assert head, f"{name}: no frontmatter"
body = re.sub(r"(?m)^disable-model-invocation:.*\n", "", head.group(1))
if name not in enabled:
body += "disable-model-invocation: true\n"
skill.write_text(text[: head.start(1)] + body + text[head.end(1):])
print("on " if name in enabled else "off", name)