diff --git a/README.md b/README.md index 86f02c4..e80bfff 100644 --- a/README.md +++ b/README.md @@ -543,9 +543,10 @@ blueprint, environment-variable, and credential-file metadata shapes. Runtime activation and setup behavior remain owned by Hermes Agent. `plugin_skill` also accepts an optional `references_dir` for a companion -directory of reference files sibling to `SKILL.md` (Hermes' own convention -names these `references`, `templates`, `assets`, or `scripts`, but any -directory name is accepted) — as long as it's actually inside the skill's +directory of reference files sibling to `SKILL.md` (Hermes serves these from +four fixed names — `references`, `templates`, `assets`, or `scripts`; the kit +accepts any name, but only those four are surfaced by the host, see below) +— as long as it's actually inside the skill's own directory tree (any depth of subdirectory is fine; a path outside it, including via a symlink, raises `ValueError` immediately, regardless of `optional`). Without that check, `references_dir` would accept literally any @@ -568,26 +569,41 @@ plugin_skill( ) ``` -**This is forward-compatible groundwork, not yet an effective capability.** -`register_plugin` only forwards `references_dir` to `ctx.register_skill` when -the host's own signature accepts that parameter (checked at registration -time via `inspect.signature`, so older hosts are never called with an -argument they don't understand). That check is a best-effort probe, not a -guarantee — a host reached through a generic `**kwargs` shape (a decorator -applied without `functools.wraps`, or a test double built with a bare -`Mock(spec=...)` instead of `create_autospec(...)`) can report acceptance it -doesn't actually have, so `register_plugin` also retries once without -`references_dir` if the host rejects it at call time, logging a warning -either way. As of this writing, no released Hermes Agent host reads or -serves plugin-skill companion files, so declaring `references_dir` today -does not make the directory agent-visible. Once a host adds support, plugins -that already declare `references_dir` start working with no further -kit-side change. - -**`plugin_reference_tool` makes the directory agent-visible today, without -waiting on a host.** It builds an ordinary `@tool`-decorated function — no -`register_skill` involvement at all — that lists or reads files under a -skill's `references_dir`: +**Hermes already serves plugin-skill companion files — but by convention, not +from this parameter.** When the host serves a plugin skill it scans the +`SKILL.md` directory for four fixed category directories — `references`, +`templates`, `assets`, and `scripts` — and returns whatever it finds under +them as `linked_files` alongside the skill body (any file type, at any depth). +It derives that location from `SKILL.md` itself, which is why the host's +`register_skill` has no `references_dir` parameter and does not need one. + +Two consequences worth being precise about: + +- **Name the directory `references`** (or one of the other three) and put it + beside `SKILL.md`. The kit accepts any directory name, but a name outside + those four is never surfaced by the host — the kit's laxity here buys + nothing on the host side. +- **`references_dir` is inert as a host argument.** `register_plugin` forwards + it to `ctx.register_skill` only when the host's signature accepts it + (checked via `inspect.signature`, so older hosts are never called with an + argument they don't understand), and no host accepts it. That probe is + best-effort, not a guarantee — a host reached through a generic `**kwargs` + shape (a decorator applied without `functools.wraps`, or a test double built + with a bare `Mock(spec=...)` instead of `create_autospec(...)`) can report + acceptance it doesn't have, so `register_plugin` retries once without + `references_dir` if the host rejects it at call time. When it drops the + argument it logs at debug rather than warning, because the files are served + anyway; the louder message is reserved for hosts where companion-file + support can't be confirmed. + +So declaring `references_dir` is still worth doing — it drives the kit's own +validation and `plugin_reference_tool` below — but it is not what makes the +directory visible. Placement and naming are. + +**`plugin_reference_tool` gives the model an explicit read tool for the same +directory.** The host's `linked_files` lists companion files when a skill is +viewed; this builds an ordinary `@tool`-decorated function — no +`register_skill` involvement at all — that lists or reads them on demand: ```python reader = plugin_reference_tool(skill, toolset="temporal-awareness") diff --git a/hermes_plugin_kit/__init__.py b/hermes_plugin_kit/__init__.py index c9b09fd..5a2b1cc 100644 --- a/hermes_plugin_kit/__init__.py +++ b/hermes_plugin_kit/__init__.py @@ -1409,12 +1409,17 @@ def plugin_skill( fires when the field is still non-``None``.) ``references_dir`` is passed to the host's ``register_skill`` **only when the host's own - signature accepts it** -- as of this writing, no released ``hermes-agent`` host surfaces - plugin-skill companion files, so declaring ``references_dir`` today does not yet make the - directory agent-visible. It is forward-compatible groundwork: once a host adds support, - plugins that already declare ``references_dir`` start working with no further kit-side change. - Until then, ``register_plugin`` logs a warning naming the skill so the gap stays visible rather - than silently doing nothing. + signature accepts it**, and no host accepts it -- because none needs to. Hermes serves + plugin-skill companion files by convention, scanning the ``SKILL.md`` directory for four + fixed category directories (``references``, ``templates``, ``assets``, ``scripts``) and + returning what it finds as ``linked_files`` beside the skill body. It derives that location + from ``SKILL.md`` itself, so the parameter is inert as a host argument. + + That makes placement and naming the thing that matters: this field drives kit-side validation + and :func:`plugin_reference_tool`, but a directory named outside those four is never surfaced + by the host no matter what is declared here. ``register_plugin`` logs at debug when it drops + the argument against a host whose companion-file support it can confirm, and louder when it + cannot. """ if not isinstance(name, str) or not _SKILL_NAME_RE.fullmatch(name): raise ValueError("skill name must match [a-zA-Z0-9_-]+ and contain no namespace") @@ -1466,12 +1471,11 @@ def plugin_reference_tool( ) -> Callable: """Build a ``@tool``-decorated handler that lists or reads ``skill.references_dir``. - Companion-file support in ``register_skill`` (see ``references_dir`` on :func:`plugin_skill`) - is forward-compatible groundwork only -- no released Hermes Agent host serves those files to - the agent yet. This factory sidesteps that gap entirely: it builds an ordinary tool, using the - same ``@tool``/``register_plugin`` mechanism every other plugin capability already goes - through, so the agent can read the directory's contents today on any host, regardless of - ``register_skill`` support. + This complements, rather than substitutes for, the host's own companion-file support. Hermes + lists these files as ``linked_files`` when the skill is viewed (see ``references_dir`` on + :func:`plugin_skill`); this factory gives the model an explicit tool to list and read them on + demand, through the same ``@tool``/``register_plugin`` mechanism every other plugin capability + goes through, without depending on the skill having been viewed first. Call with no arguments (or ``file_path=None``) to list every file under ``references_dir``. Call with ``file_path`` set to a path relative to ``references_dir`` to read that file's diff --git a/skills/hermes-plugins/references/plugin-kit.md b/skills/hermes-plugins/references/plugin-kit.md index e520fdf..1643e05 100644 --- a/skills/hermes-plugins/references/plugin-kit.md +++ b/skills/hermes-plugins/references/plugin-kit.md @@ -35,7 +35,7 @@ guidance, not a second implementation specification. | Session slash command | `@command` | `register_plugin` | Name is bare lowercase kebab-case; handler receives raw trailing text and may be sync or async. | | Request or execution middleware | `@middleware`, `MiddlewareKind` | `register_plugin` | Callback is synchronous; request phases replace payloads, execution phases call single-use `next_call`. | | Lifecycle hook | `@hook` | `register_plugin` | Hermes kwargs and return values pass through; exceptions are re-raised for Hermes isolation. | -| Plugin-owned skill | `plugin_skill` | `register_plugin(..., skills=...)` | Hermes adds the plugin namespace; missing required skills fail, optional skills warn and skip. Optional `references_dir` (a companion reference-files directory) is forward-compatible groundwork only — no released host surfaces it yet; see [`README.md`](../../../README.md#commands-middleware-hooks-and-plugin-skills). | +| Plugin-owned skill | `plugin_skill` | `register_plugin(..., skills=...)` | Hermes adds the plugin namespace; missing required skills fail, optional skills warn and skip. Optional `references_dir` (a companion reference-files directory) drives kit-side validation and `plugin_reference_tool`; the host serves companion files by convention instead, from `references`/`templates`/`assets`/`scripts` beside `SKILL.md`, so name the directory accordingly. See [`README.md`](../../../README.md#commands-middleware-hooks-and-plugin-skills). | | Agent-visible skill reference files (today) | `plugin_reference_tool` | `register_plugin` (its return value is an ordinary `@tool` function — add it to the plugin's declarations) | Sidesteps `register_skill` entirely by exposing `references_dir` as a normal tool call; accepts both paths listed by the tool and skill-relative `references/` forms, while rejecting any path that resolves outside `references_dir` (symlink, absolute path, or `../`) and any non-string `file_path`. `references_dir` itself must be inside the skill's own directory — enforced by `plugin_skill` and re-checked here. | | Context engine | Hermes `ContextEngine` instance | `register_plugin(..., context_engine=...)` | Singular native engine registration; schemas and recovery dispatch stay in `get_tool_schemas()` / `handle_tool_call()`, never duplicated with `@tool`. | | Host-managed call | `invoke_host_tool` | None | Use for supported non-registry capabilities such as `send_message`; pre/post-tool hooks remain active. | diff --git a/tests/test_hermes_contract.py b/tests/test_hermes_contract.py index bb42bd6..8381644 100644 --- a/tests/test_hermes_contract.py +++ b/tests/test_hermes_contract.py @@ -840,5 +840,51 @@ def _message_thread_id_for_send(value: str) -> int | None: bot.shutdown.assert_awaited_once() + def test_host_serves_plugin_skill_companion_files_from_four_fixed_dirs(self) -> None: + """Pin the convention the kit's docs tell plugin authors to follow. + + ``register_skill`` has no ``references_dir`` parameter and needs none: + the host derives companion files from the ``SKILL.md`` directory. The + kit therefore documents "name it one of these four, put it beside + SKILL.md" -- a claim about the host, so it belongs in the contract + lane. If the category set or the traversal changes upstream, that + guidance goes stale silently, which is exactly how it went stale + before. + """ + from tools.skills_tool import _plugin_skill_linked_files # type: ignore + + with tempfile.TemporaryDirectory() as tmp: + skill_root = Path(tmp) + (skill_root / "SKILL.md").write_text("# skill\n", encoding="utf-8") + for category in ("references", "templates", "assets", "scripts"): + (skill_root / category).mkdir() + # Any file type, at any depth -- not just top-level *.md. + (skill_root / "references" / "guide.md").write_text("g", encoding="utf-8") + (skill_root / "references" / "nested").mkdir() + (skill_root / "references" / "nested" / "data.csv").write_text("a,b", encoding="utf-8") + (skill_root / "templates" / "t.py").write_text("x = 1", encoding="utf-8") + (skill_root / "assets" / "logo.png").write_bytes(b"\x89PNG") + (skill_root / "scripts" / "run.sh").write_text("echo hi", encoding="utf-8") + # A directory outside the convention must not be surfaced. + (skill_root / "docs").mkdir() + (skill_root / "docs" / "ignored.md").write_text("no", encoding="utf-8") + + linked = _plugin_skill_linked_files(skill_root) + + self.assertIsNotNone(linked, "host returned no companion files at all") + self.assertEqual( + sorted(linked), + ["assets", "references", "scripts", "templates"], + "the documented category set no longer matches the host", + ) + self.assertNotIn("docs", linked) + self.assertIn( + str(Path("references") / "nested" / "data.csv"), + linked["references"], + "nested and non-markdown companion files are documented as served", + ) + self.assertIn(str(Path("assets") / "logo.png"), linked["assets"]) + + if __name__ == "__main__": unittest.main()