Skip to content
Merged
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
132 changes: 115 additions & 17 deletions hermes_plugin_kit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,42 @@ def _call_session_db(
return method(*args, **kwargs)


#: Where Hermes has exposed its skill companion-file support, newest first.
#:
#: The host serves `references/`, `templates/`, `assets/` and `scripts/`
#: alongside a skill body through its own skills tool -- it has done so since
#: at least the revision this kit pins -- and returns them as `linked_files`.
#: That route has nothing to do with `register_skill`'s signature, so probing
#: the signature alone cannot see it.
#:
#: The module moved during an upstream refactor, hence a list rather than one
#: path. A name missing from every candidate means "could not tell", never
#: "the host cannot do it".
_HOST_COMPANION_FILE_PROBES = (
("tools.skills_tool_plugin", "_plugin_skill_linked_files"),
("tools.skills_tool", "_plugin_skill_linked_files"),
)


def _host_serves_skill_companion_files() -> bool | None:
"""Whether the host serves skill companion files through its skills tool.

``True`` when a known support routine is importable, ``None`` when that
cannot be determined. Never ``False``: absence of a private helper the kit
happens to know about is not evidence the host lacks the capability, and
treating it as such is what produced a warning telling plugin authors to
build a workaround for something that already worked.
"""
for module_name, attribute in _HOST_COMPANION_FILE_PROBES:
try:
module = importlib.import_module(module_name)
except Exception:
continue
if getattr(module, attribute, None) is not None:
return True
return None


def _signature_accepts_kwarg(callable_obj: Any, name: str) -> bool:
"""Return whether ``callable_obj``'s live signature has ``name`` or accepts ``**kwargs``.

Expand Down Expand Up @@ -776,13 +812,31 @@ def _split_params(params: dict | None) -> tuple[dict, list, dict]:


def _augment_description(description: str, required: list, examples: dict) -> str:
if not required:
return description
bits = [
f"`{key}`" + (f" (e.g. {examples[key]!r})" if key in examples else "")
for key in required
"""Surface required keys and every supplied example.

Examples used to reach the model only for required keys: an example on an
optional key was collected and then dropped, so a plugin could ship a
perfectly good one that no agent ever saw. An example is guidance about
shape; whether the key is mandatory is a separate fact, and conflating
them silently discarded the guidance.
"""
parts = [description]
if required:
bits = [
f"`{key}`" + (f" (e.g. {examples[key]!r})" if key in examples else "")
for key in required
]
parts.append(f"Required: {', '.join(bits)}.")

optional_examples = [
f"`{key}` (e.g. {examples[key]!r})"
for key in examples
if key not in required
]
return f"{description} Required: {', '.join(bits)}."
if optional_examples:
parts.append(f"Optional: {', '.join(optional_examples)}.")

return " ".join(parts)


def build_schema(name: str, description: str, params: dict | None) -> dict:
Expand Down Expand Up @@ -1371,6 +1425,10 @@ def _default_reference_tool_name(skill_name: str) -> str:
return f"{normalized}_read_reference"


#: How many reference filenames to name before summarising the rest.
_REFERENCE_NAMES_IN_DESCRIPTION = 8


def plugin_reference_tool(
skill: PluginSkill,
*,
Expand Down Expand Up @@ -1412,11 +1470,37 @@ def plugin_reference_tool(

references_dir = skill.references_dir
tool_name = name or _default_reference_tool_name(skill.name)
tool_description = description or (
f"List or read companion reference files for the {skill.name!r} skill. Omit file_path "
"to list every available file; pass either a listed path or its skill-relative "
"references/<path> form to read one file's content."
# Name the files in the default description. An agent selects tools by
# description at call time, so a tool that lists nothing asks it to spend a
# speculative no-argument call to discover whether anything is worth
# reading -- a cost it will not pay for a tool that promises nothing. Two
# readers built this way were registered on three deployed profiles and
# called zero times in eight days. references_dir is known here, so the
# names cost nothing.
available = sorted(
candidate.relative_to(references_dir.resolve()).as_posix()
for candidate in references_dir.resolve().rglob("*")
if candidate.is_file()
)
if description:
tool_description = description
elif available:
shown = ", ".join(available[:_REFERENCE_NAMES_IN_DESCRIPTION])
if len(available) > _REFERENCE_NAMES_IN_DESCRIPTION:
shown += f", and {len(available) - _REFERENCE_NAMES_IN_DESCRIPTION} more"
tool_description = (
f"Read the {skill.name!r} skill's companion reference files: {shown}. "
f"Consult these before acting on that skill when the details matter. "
f"Omit file_path to list every file; pass a listed path, or its "
f"skill-relative references/<path> form, to read one."
)
else:
tool_description = (
f"List or read companion reference files for the {skill.name!r} skill. "
f"No files are present yet. Omit file_path to list every available "
f"file; pass either a listed path or its skill-relative "
f"references/<path> form to read one file's content."
)

def _read_plugin_reference(args: dict, **_: Any) -> dict:
file_path = args.get("file_path")
Expand Down Expand Up @@ -2559,13 +2643,27 @@ def register_plugin(
if wants_references_dir and _signature_accepts_kwarg(ctx.register_skill, "references_dir"):
skill_kwargs["references_dir"] = skill.references_dir
elif wants_references_dir:
log.warning(
"hermes_plugin_kit: host register_skill() does not yet accept references_dir; "
"name=%s references_dir=%s will not be surfaced to the agent until the host "
"adds support",
skill.name,
skill.references_dir,
)
# Say only what was observed. register_skill not taking the kwarg
# means the kwarg was not taken -- it does not mean the files go
# unserved, because the host's skills tool serves them by another
# route entirely.
if _host_serves_skill_companion_files():
log.debug(
"hermes_plugin_kit: host register_skill() does not accept references_dir; "
"name=%s references_dir=%s is served by the host's skills tool instead "
"(returned as linked_files alongside the skill body)",
skill.name,
skill.references_dir,
)
else:
log.info(
"hermes_plugin_kit: host register_skill() does not accept references_dir; "
"name=%s references_dir=%s was not passed through it. Hermes may still "
"serve these files through its skills tool -- check skill_view before "
"assuming otherwise. Use plugin_reference_tool only if it does not",
skill.name,
skill.references_dir,
)

# The signature probe above can be fooled by a permissive **kwargs shape (a bare
# Mock(spec=...) test double, or a decorator applied without functools.wraps) that
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
schema: spec-driven
created: 2026-09-21

# This changes observable behaviour -- what the kit claims about the host and
# what it surfaces to an agent -- but there is no capability spec covering the
# registration-claims surface to modify. openspec/specs/ is empty until the
# first change archives, and the only spec in flight covers the test harness.
#
# Writing a delta here would mean inventing a capability to satisfy the
# validator, which the shipped template explicitly warns against. The honest
# marker is skip_specs, and this surface deserves a real spec once the store
# has one to modify.
skip_specs: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
## Context

Evidence came from a fleet survey of 11 `state.db` stores across 5 pods over 8
days (1,681 plugin tool calls), reported by the memory-sync maintainer, plus
direct verification against two Hermes checkouts here.

The host-side capability is real and not new. `_plugin_skill_linked_files`
exists at `tools/skills_tool.py` in the pinned revision `f80f453` and at
`tools/skills_tool_plugin.py` on main after an upstream refactor. Support dirs
are enumerated in both.

## Goals / Non-Goals

**Goals:**

- Stop asserting a negative the kit cannot establish.
- Give an agent a reason to call the reference tool.
- Stop discarding examples.

**Non-Goals:**

- Removing `plugin_reference_tool`. It remains the right answer where the host
genuinely does not serve files, and consumers depend on it.
- Changing registration behaviour. The kwarg is still dropped when the host
does not take it, and the skill still registers.
- Any upstream Hermes change.

## Decisions

**Probe positively; treat "cannot tell" as unknown, never as absent.** The
check returns `True` or `None` — never `False`. The kit knows a handful of
private module paths, and those move; a name it cannot find is not evidence
about the host. This is the whole lesson of the defect, encoded in the return
type rather than left to a comment.

**Not a warning.** When the host serves the files, this is a debug detail.
When the kit cannot tell, it is informational and names the check an author
can run. A warning asserts something is wrong, and nothing is.

**Name files in the default description, not just the mechanism.** An agent
selects on description at call time. `references_dir` is known at build time,
so enumeration is free. Capped, with an overflow count, so a large directory
does not flood the tool list.

**Examples belong to the argument, not to its required-ness.** An example is
guidance about shape; whether a key is mandatory is a separate fact. Rendering
optional examples under their own heading keeps both legible.

## Risks / Trade-offs

- The probe reads private host names, which can move again — it already has
once. That is why it is a candidate list and why failure means unknown. The
cost of a stale probe is a slightly less specific log line, not a wrong
claim.
- Naming files makes the description depend on directory contents, so adding a
file changes the tool description. That is intended; a stale description is
what caused the original problem.
- Neither the probe nor a recorded plugin context would have caught this: both
reason about shape. Only reading the host's other tool did. Worth holding
onto when the harness tempts a similar inference.

## Migration

None. Consumers already using `plugin_reference_tool` keep working; those who
adopted it because of the false warning may now find the host route sufficient,
but nothing forces that decision.

## Open Questions

- Whether the kit should expose the capability check publicly so a plugin can
branch on it rather than always registering a reference tool. Deferred: one
consumer's behaviour is not yet enough to design an API around.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
## Why

The kit told plugin authors a host capability was missing that has existed all
along, and one of them built a workaround that then went unused.

`register_plugin` probes `register_skill`'s signature for a `references_dir`
keyword. When it is absent the kit warns that the directory "will not be
surfaced to the agent until the host adds support". Hermes serves skill
companion files through its *skills tool*, not through `register_skill` —
`_plugin_skill_linked_files` returns `references/`, `templates/`, `assets/`
and `scripts/` as `linked_files` in the same response as the skill body.
Verified present at both the pinned revision `f80f453` and upstream main; the
module moved during a refactor but the capability did not appear or disappear.

A signature probe cannot establish that a capability is missing. It can only
establish that one function does not take one argument. The kit asserted the
stronger claim, and a fleet survey traced the consequence: the warning fired
on every pod boot, a plugin built `plugin_reference_tool` to work around it,
and the resulting tools were called zero times in eight days across three
profiles while the real route sat available and unmentioned.

Two smaller defects share that theme of guidance never reaching the agent. The
reference tool's default description names no files, so an agent must spend a
speculative call to learn whether anything is worth reading. And an example
supplied for an *optional* argument is collected and then dropped, so a plugin
can ship good guidance no agent ever sees.

## What Changes

- The kit stops claiming the capability is missing. It checks whether the host
serves companion files and, when it cannot tell, says what it observed
instead of asserting absence. Not a warning either way: nothing is wrong.
- `plugin_reference_tool`'s default description names the available files and
says when to consult them.
- Examples on optional arguments reach the description, under their own
`Optional:` heading so required and optional stay distinguishable.

## Capabilities

### New Capabilities

<!-- None. -->

### Modified Capabilities

<!-- None at the spec level: this corrects what the kit *claims* about a host
and what it surfaces to an agent. The registration behaviour itself --
the kwarg is dropped, the skill still registers -- is unchanged. -->

## Impact

- `hermes_plugin_kit/__init__.py` — capability probe, corrected log, default
description, `_augment_description`.
- `tests/test_kit.py` — two existing assertions updated: the behaviour they
guard is unchanged, only the claim in the log.
- `tests/test_testing_harness.py` — new coverage for all three.
- No host change required. That is the point: the capability already exists.
25 changes: 25 additions & 0 deletions openspec/changes/stop-claiming-references-dir-unsupported/tasks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
## 1. Stop asserting the capability is missing

- [x] 1.1 Add a capability check that looks for the host's companion-file
support across its known module locations, returning unknown rather than
false when it cannot tell. Verify: it reports the capability present
against both the pinned revision and upstream main, and unknown with no
host importable.
- [x] 1.2 Replace the warning with what was actually observed, at a level that
does not claim something is wrong. Verify: no run asserts the files go
unserved, and the message points at the host's skills tool.
- [x] 1.3 Update the two existing assertions that pinned the old wording,
preserving the behaviour they guard. Verify: the kwarg is still dropped
and the skill still registers, with and without a host importable.

## 2. Give the reference tool a reason to be called

- [x] 2.1 Name the available files in the default description, capped with an
overflow count, and say when to consult them. Verify: the filenames
appear, and an explicitly supplied description is left untouched.

## 3. Stop discarding examples on optional arguments

- [x] 3.1 Surface optional examples under their own heading. Verify: an
example on an optional key reaches the description without being
labelled required, and required examples are unchanged.
Loading
Loading