Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/freehand/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -1039,10 +1039,16 @@ def skills(cwd: Path, project: bool = True) -> list[dict[str, str]]:
continue
name = meta.get("name") or f.parent.name
found[name] = {"name": name, "description": " ".join((meta.get("description") or "").split())[:500],
"path": str(f)}
"path": str(f), "model_invocation": _model_invocation(meta.get("disable-model-invocation"))}
return list(found.values())


def _model_invocation(value: str | None) -> bool:
"""Whether a skill may be offered to the model. `disable-model-invocation: true` (or yes) in a SKILL.md's
frontmatter keeps it out of the model's context while leaving it available to the person as a slash command."""
return (value or "").strip().lower() not in ("true", "yes", "1")


def context_block(cwd: Path, max_chars: int = 40000, project: bool = True) -> str:
"""Environment and instructions, sent once at the start of a session as part of the first message: the person's
own AGENTS.md, the project's, where the skills are, and which MCP servers there are. *project* is False in a
Expand All @@ -1056,7 +1062,7 @@ def context_block(cwd: Path, max_chars: int = 40000, project: bool = True) -> st
if len(text) > max_chars:
text = text[:max_chars] + f"\n…[truncated; full file: {f}]"
parts.append(f'<{tag} path="{f}">\n{text.strip()}\n</{tag}>')
listed = skills(cwd, project)
listed = [s for s in skills(cwd, project) if s["model_invocation"]]
if listed:
rows = "\n".join(f"- {s['name']}: {s['description']} ({s['path']})" for s in listed)
parts.append("<skills>\nInstructions the person keeps for particular kinds of task, one file each. Read a "
Expand Down
36 changes: 36 additions & 0 deletions tests/test_skill_disable_model_invocation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""A skill marked `disable-model-invocation: true` stays available to the person but is not put in the model's
context, the same way Claude Code and Pi treat that frontmatter field."""
from freehand import session, usercommands


def _skill(root, name, front):
d = root / name
d.mkdir(parents=True)
(d / "SKILL.md").write_text("---\n" + front + "\n---\n# body\n", encoding="utf-8")
return d


def test_disable_model_invocation_keeps_skill_out_of_context_but_in_slash_menu(tmp_path, isolated_home):
_skill(isolated_home / "skills", "manual-skill",
"name: manual-skill\ndescription: only run by hand\ndisable-model-invocation: true")
_skill(isolated_home / "skills", "normal-skill",
"name: normal-skill\ndescription: for the model")

block = session.context_block(tmp_path)

# The person can still invoke it explicitly ...
names = [c["name"] for c in usercommands.available(tmp_path)]
assert "manual-skill" in names
assert "normal-skill" in names

# ... but only the normal skill is described to the model.
assert "normal-skill" in block
assert "manual-skill" not in block, "disable-model-invocation: true skill leaked into the model context"
assert "only run by hand" not in block


def test_disable_model_invocation_accepts_yes_and_case(tmp_path, isolated_home):
_skill(isolated_home / "skills", "s1", "description: one\ndisable-model-invocation: yes")
_skill(isolated_home / "skills", "s2", "description: two\ndisable-model-invocation: TRUE")
block = session.context_block(tmp_path)
assert "s1" not in block and "s2" not in block