From e3d9a0296f87b6c21949f7a1754c8fc1cee85928 Mon Sep 17 00:00:00 2001 From: fchengyan <3181088318@qq.com> Date: Sun, 6 Dec 2026 19:35:20 +0800 Subject: [PATCH] fix(session): keep disable-model-invocation skills out of model context A SKILL.md that sets `disable-model-invocation: true` is still offered to the person as a slash command, but is no longer listed in the block sent to the model, matching Claude Code / Pi semantics. Fixes #190. Added regression tests covering true/yes/TRUE values and confirming the skill stays invokable by the person. --- src/freehand/session.py | 10 ++++-- tests/test_skill_disable_model_invocation.py | 36 ++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 tests/test_skill_disable_model_invocation.py diff --git a/src/freehand/session.py b/src/freehand/session.py index fc0cb96..e935a6c 100644 --- a/src/freehand/session.py +++ b/src/freehand/session.py @@ -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 @@ -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') - 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("\nInstructions the person keeps for particular kinds of task, one file each. Read a " diff --git a/tests/test_skill_disable_model_invocation.py b/tests/test_skill_disable_model_invocation.py new file mode 100644 index 0000000..c5b0412 --- /dev/null +++ b/tests/test_skill_disable_model_invocation.py @@ -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