Skip to content

Commit 42fbd08

Browse files
ruiling-smartbearhaizhongzhengclaude
authored
A plugin names the adapter's files as a deployment does (#108)
* A plugin names the adapter's files as a deployment does; training deploys as hermit deploy does A Claude Code plugin prints, from a SessionStart hook, where its embedded adapter is and the files no export connects, the list a deployment's context gives. Codex, Pi and Hermes plugins, which cannot say where they are installed, list those files under unnamed_files. A test holds that training deploys an adapter as hermit deploy does, file for file on every host, the tools' server entry aside. * Review fixes: a Hermes plugin names the adapter's folder; README and Windows wording; tighter tests A Hermes plugin's register appends the folder note and the list of other files to its system prompt section, within its 4,000 characters. The Claude Code README mentions the hook only when there is one, and the docs say the hook needs a POSIX shell. Tests: a reconversion removes a hook no longer needed; the deployment records differ only in the tools' entries. * Wrap the Hermes plugin's docstring * Hermes plugins report the files, as Codex and Pi do; shorter docs * Name the adapter folder by its constant in the README * Parity test: compare the tool-server files with only the tools' entry taken out The test let a whole tool-server file differ between training and `hermit deploy`, so training losing Hermes's skills settings passed, and whether a host's tools come from the workspace or the session's own server was checked only when a file differed. Now every other file must match byte for byte, the tool-server file must match once the tools' entry is removed (OpenCode, Hermes, mini-swe-agent), and each host's tool handoff is asserted on its own. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Haizhong Zheng <hzzheng@umich.edu> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 6940f26 commit 42fbd08

10 files changed

Lines changed: 278 additions & 34 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ Changes are grouped by software version. Entries under Unreleased describe work
129129

130130
### Added
131131

132+
- `hermit convert` names the adapter's folder and files as a deployment does: a Claude Code plugin prints, from a
133+
`SessionStart` hook, where its embedded adapter is and the files no export connects (the list a deployment's
134+
context gives); Codex, Pi and Hermes plugins list those files under `unnamed_files` in the result and their README.
135+
- A test that training deploys an adapter into a task's workspace as `hermit deploy` does, file for file on every
136+
host, the tools' server entry aside (calls approved; the session's own tool server for a host that cannot start it).
132137
- Task directories in Harbor's format as a task set (`data.tasks: <directory>`, `data.rollouts`), read without Harbor
133138
(`hermit/task/directory.py`), with their own verifier script run in the judge's sandbox (`judge: {path:
134139
hermit.task.verify, name: script}`: `/tests`, `/logs/verifier/reward.txt` or `reward.json`, and `feedback.txt`).

‎docs/framework/commands.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,20 @@ names the machine that produced it.
136136
| Tools | `.mcp.json` | `mcp.json` | generated extension, `pi.registerMcpServer` | `ctx.register_tool`, forwarding to `hermit serve` |
137137
| Roles | `agents/` | refused | refused | refused |
138138
| Hooks | refused | refused | refused | refused |
139+
| The adapter's folder and its other files | named by a `SessionStart` hook | not named: listed under `unnamed_files` | not named: listed under `unnamed_files` | not named: listed under `unnamed_files` |
139140

140141
A part the target's plugin format cannot carry is refused: `convert` exits 2 and names every such part before writing
141142
anything. A non-empty context (`ADAPTER.md`) makes Codex and Pi refuse, and a context over 4,000 characters makes
142143
Hermes refuse. Hooks make every target refuse: no plugin carries them yet, and `deploy --host codex` or
143144
`--host claude-code` connects them in a workspace. `--allow-lossy` emits the plugin without those parts and lists them
144145
under `omitted` in the result.
145146

147+
In training and in a `deploy` workspace, the agent's context says where the adapter's copy is (paths in its
148+
instructions, skills and roles are relative to that folder) and lists the files no export connects, such as a
149+
README or a tool's source. A Claude Code plugin names them with a `SessionStart` hook, which prints the installed
150+
folder and the same list (an output style gets no `${CLAUDE_PLUGIN_ROOT}`); the hook needs a POSIX shell (Git Bash on
151+
Windows). The other targets list them under `unnamed_files` and in the plugin's README.
152+
146153
Why the refusals:
147154

148155
- **Codex** reads no instruction file and no subagent from a plugin. Its plugin format is Agent Plugins v1: root

‎hermit/hosts/inputs.py‎

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -374,25 +374,59 @@ def _hook_line(when: str, hook: dict, rel: str) -> str:
374374
"by the agent from the context: deploy to a host that runs it, or remove it")
375375

376376

377+
def other_files(adapter: Path, manifest: dict, exports: dict, hooks: dict | None) -> list[str]:
378+
"""The adapter's files that no export connects and the context is not (paths in the adapter): what a deployment's
379+
context names under "Other files", and what a plugin carries without naming it (hermit.plugins.common)."""
380+
adapter = adapter.resolve()
381+
covered = {manifest.get("context") or "ADAPTER.md", "exports.yaml"}
382+
if _skill_entries(adapter, manifest):
383+
covered.add(f"{_plain(manifest['skills']).rstrip('/')}/")
384+
if exports.get("agents") and isinstance(manifest.get("agents"), str):
385+
covered.add(f"{_plain(manifest['agents']).rstrip('/')}/")
386+
if hooks and hooks.get("hooks"):
387+
covered.add(_plain(manifest["hooks"]))
388+
doc = adapter / (manifest.get("context") or "ADAPTER.md")
389+
context = doc.read_bytes() if doc.is_file() else None
390+
others = []
391+
for path in sorted(p for p in adapter.rglob("*") if p.is_file()):
392+
if context is not None and path.stat().st_size == len(context) and path.read_bytes() == context:
393+
continue # a copy of the context (a tree's AGENTS.md): already in it
394+
name = path.relative_to(adapter).as_posix()
395+
if (name.split("/")[0] in NOT_COPIED or any(part in CACHES for part in path.parts) or name.endswith(".pyc")
396+
or name in covered or any(name.startswith(c) for c in covered if c.endswith("/"))
397+
or is_internal(name, manifest)):
398+
continue
399+
others.append(name)
400+
return others
401+
402+
403+
def other_files_section(adapter: Path, names: list[str], folder: str | None) -> str:
404+
"""The context's list of `names` (other_files), each with its summary, as paths under `folder` (None: as they are
405+
in the adapter, for a text that names the folder itself)."""
406+
prefix = f"{folder}/" if folder else ""
407+
listed = [f"- `{prefix}{n}`" + (f": {s}" if (s := _summary(adapter.resolve() / n)) else "")
408+
for n in names[:LISTED_FILES]]
409+
if len(names) > LISTED_FILES:
410+
listed.append(f"- and {len(names) - LISTED_FILES} more files" + (f" under `{folder}/`" if folder else ""))
411+
return "Other files of this adapter (read one when it is relevant):\n" + "\n".join(listed)
412+
413+
377414
def resources(adapter: Path, output: Path, manifest: dict, exports: dict, hooks: dict | None,
378415
native: set[str], hook_types: set[str] = frozenset()) -> tuple[str, dict]:
379416
"""The part of the context that names what the host does not connect (`native`: the exports it does, of
380417
skills and agents; `hook_types`: the hook types it runs) and the adapter's other files, with paths in the
381418
workspace; and the record of where each export went ({export: "native" | "files" | "native and files"})."""
382419
adapter = adapter.resolve()
383420
rel = adapter_folder(output, manifest).relative_to(output).as_posix()
384-
sections, record, covered = [], {}, {manifest.get("context") or "ADAPTER.md", "exports.yaml"}
421+
sections, record = [], {}
385422
skills = _skill_entries(adapter, manifest)
386423
if skills:
387424
record["skills"] = "native" if "skills" in native else "files"
388-
covered |= {f"{_plain(manifest['skills']).rstrip('/')}/"}
389425
if "skills" not in native:
390426
sections.append("Skills (this agent does not load them itself: read a skill's SKILL.md before you use "
391427
"it):\n" + "\n".join(f"- `{n}`: {d} (`{rel}/{p}`)" for n, d, p in skills))
392428
if exports.get("agents"):
393429
record["agents"] = "native" if "agents" in native else "files"
394-
if isinstance(manifest.get("agents"), str):
395-
covered |= {f"{_plain(manifest['agents']).rstrip('/')}/"}
396430
if "agents" not in native:
397431
lines = []
398432
for role in exports["agents"]:
@@ -414,27 +448,12 @@ def resources(adapter: Path, output: Path, manifest: dict, exports: dict, hooks:
414448
else:
415449
lines.append(_hook_line(when, hook, rel))
416450
record["hooks"] = "native and files" if ran and lines else "native" if ran else "files"
417-
covered |= {_plain(manifest["hooks"])}
418451
if lines:
419452
sections.append(f"Hooks this agent does not run by itself (from `{rel}/{_plain(manifest['hooks'])}`): "
420453
"at each of these moments, do it yourself:\n" + "\n".join(lines))
421-
doc = adapter / (manifest.get("context") or "ADAPTER.md")
422-
context = doc.read_bytes() if doc.is_file() else None
423-
others = []
424-
for path in sorted(p for p in adapter.rglob("*") if p.is_file()):
425-
if context is not None and path.stat().st_size == len(context) and path.read_bytes() == context:
426-
continue # a copy of the context (a tree's AGENTS.md): already in it
427-
name = path.relative_to(adapter).as_posix()
428-
if (name.split("/")[0] in NOT_COPIED or any(part in CACHES for part in path.parts) or name.endswith(".pyc")
429-
or name in covered or any(name.startswith(c) for c in covered if c.endswith("/"))
430-
or is_internal(name, manifest)):
431-
continue
432-
others.append(name)
454+
others = other_files(adapter, manifest, exports, hooks)
433455
if others:
434-
listed = [f"- `{rel}/{n}`" + (f": {s}" if (s := _summary(adapter / n)) else "") for n in others[:LISTED_FILES]]
435-
if len(others) > LISTED_FILES:
436-
listed.append(f"- and {len(others) - LISTED_FILES} more files under `{rel}/`")
437-
sections.append("Other files of this adapter (read one when it is relevant):\n" + "\n".join(listed))
456+
sections.append(other_files_section(adapter, others, rel))
438457
text = ("### Adapter resources\n\n" + "\n\n".join(sections)) if sections else ""
439458
return text, record
440459

‎hermit/plugins/claude_plugin.py‎

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,48 @@
1010
- roles: subagent files in the conventional `agents/` directory. Naming that directory in the manifest breaks it:
1111
as a string the manifest fails validation, as a list nothing loads.
1212
- skills: the conventional `skills/` directory.
13+
- the adapter's files: embedded under `adapter/`. In training and in a `hermit deploy` workspace the context says
14+
where the adapter's copy is and names the files no export connects (hermit.hosts.inputs.resources). An output
15+
style cannot say where the plugin is installed (Claude Code substitutes `${CLAUDE_PLUGIN_ROOT}` in skills,
16+
agents, hooks and servers, not in an output style), so a `SessionStart` hook says it: Claude Code adds a
17+
SessionStart hook's output to the context. The hook is a POSIX shell command: `sh` on macOS and Linux, Git Bash on
18+
Windows (where Claude Code falls back to PowerShell without Git Bash, and the hook fails).
1319
"""
1420
from __future__ import annotations
1521

1622
from pathlib import Path
1723
import json
1824

25+
from hermit.hosts.inputs import other_files_section
1926
from hermit.plugins.common import (ADAPTER_DIR, AUDIT_LOG, FRAMEWORK_VERSION, SERVER_COMMAND, clear, copy_skills,
20-
embed_adapter, load, prepare_output, record, refuse, server_args,
21-
subagent_file, write_json)
27+
embed_adapter, load, prepare_output,
28+
record, refuse, server_args, subagent_file, write_json)
2229

2330
SCHEMA = "https://anthropic.com/claude-code/plugin.schema.json"
2431
MARKETPLACE = ".claude-plugin/marketplace.json"
32+
FILES_NOTE = "hermit-files.md" # the list of the adapter's other files the hook prints
33+
HOOKS = "hooks/hooks.json"
34+
35+
36+
def folder_hook(bundle, plugin: Path, skills: list[str]) -> str | None:
37+
"""Write the hook that tells the session where the adapter's files are, as the deployment's context does
38+
(hermit.hosts.inputs.folder_note and the "Other files" list), when the adapter has any the agent may be sent to:
39+
files no export connects, or skills and roles whose paths are relative to the adapter. Returns the hooks file."""
40+
others = bundle.other_files
41+
if not (others or bundle.roles or skills):
42+
return None
43+
# the installed path is printf's argument, never part of the command; an adapter id has no % or quote
44+
note = (f"The files of the `{bundle.id}` adapter are in `%s/{ADAPTER_DIR}/`. Paths in its instructions, and in "
45+
f"its skills and roles, are relative to that folder: run a command they give from there "
46+
f"(`cd \"%s/{ADAPTER_DIR}\" && ...`).")
47+
command = f"printf '{note}\\n' \"$CLAUDE_PLUGIN_ROOT\" \"$CLAUDE_PLUGIN_ROOT\""
48+
if others:
49+
# Past 10,000 characters Claude Code keeps a hook's output in a file and shows its first 2,000, which hold the
50+
# folder; the list (at most LISTED_FILES entries, as a deployment's) is shorter for any ordinary adapter.
51+
(plugin / FILES_NOTE).write_text("\n" + other_files_section(bundle.adapter, others, None) + "\n")
52+
command += f" && cat \"$CLAUDE_PLUGIN_ROOT/{FILES_NOTE}\""
53+
write_json(plugin / HOOKS, {"hooks": {"SessionStart": [{"hooks": [{"type": "command", "command": command}]}]}})
54+
return HOOKS
2555

2656

2757
def output_style(name: str, description: str, context: str) -> str:
@@ -35,7 +65,7 @@ def build(adapter: Path, output: Path, python: str, *, allow_lossy: bool = False
3565
output = prepare_output(output, bundle.adapter, MARKETPLACE)
3666
plugin = output / "plugins" / bundle.id
3767
plugin.mkdir(parents=True, exist_ok=True)
38-
clear(plugin, "agents", "output-styles", "skills", ".mcp.json")
68+
clear(plugin, "agents", "output-styles", "skills", ".mcp.json", "hooks", FILES_NOTE)
3969

4070
write_json(output / MARKETPLACE, {
4171
"name": f"{bundle.id}-adapters", "owner": {"name": "hermit"},
@@ -59,23 +89,24 @@ def build(adapter: Path, output: Path, python: str, *, allow_lossy: bool = False
5989
output_style(bundle.id, f"Context of the {bundle.name} harness adapter", context))
6090

6191
skills = copy_skills(bundle, plugin / "skills")
92+
hooks = folder_hook(bundle, plugin, skills)
6293
embed_adapter(bundle, plugin)
6394
record(bundle, plugin)
6495
if bundle.tools:
6596
write_json(plugin / ".mcp.json", {"mcpServers": {bundle.server: {
6697
"type": "stdio", "command": SERVER_COMMAND,
6798
"args": server_args(f"${{CLAUDE_PLUGIN_ROOT}}/{ADAPTER_DIR}", f"${{CLAUDE_PLUGIN_DATA}}/{AUDIT_LOG}")}}})
68-
(plugin / "README.md").write_text(_readme(bundle, output, skills, roles, omitted))
99+
(plugin / "README.md").write_text(_readme(bundle, output, skills, roles, omitted, hooks))
69100
return {"target": "claude-code", "adapter_id": bundle.id, "version": bundle.version,
70101
"framework": FRAMEWORK_VERSION, "output": str(output),
71102
"plugin": str(plugin), "install": [f"claude plugin marketplace add {output}",
72103
f"claude plugin install {bundle.id}@{bundle.id}-adapters"],
73104
"context": f"output-styles/{bundle.id}.md" if bundle.has_context else None,
74105
"skills": skills, "roles": roles, "server_name": bundle.server if bundle.tools else None,
75-
"omitted": omitted}
106+
"folder_hook": hooks, "unnamed_files": [], "omitted": omitted}
76107

77108

78-
def _readme(bundle, output: Path, skills: list, roles: dict, omitted: list) -> str:
109+
def _readme(bundle, output: Path, skills: list, roles: dict, omitted: list, hooks: str | None) -> str:
79110
return "\n".join([
80111
f"# {bundle.name}", "",
81112
f"A Claude Code plugin generated by `hermit convert` from the `{bundle.id}` adapter, version "
@@ -84,6 +115,9 @@ def _readme(bundle, output: Path, skills: list, roles: dict, omitted: list) -> s
84115
"The tools run as `hermit serve`, so `hermit` must be installed and on PATH.", "",
85116
f"- Context: the output style `{bundle.id}`, applied automatically while the plugin is enabled "
86117
"(`force-for-plugin`)." if bundle.has_context else "- Context: none",
118+
(f"- The adapter's files: under `{ADAPTER_DIR}/`, which a `SessionStart` hook names to the session"
119+
+ (f", with the {len(bundle.other_files)} files no export connects" if bundle.other_files else ""))
120+
if hooks else f"- The adapter's files: under `{ADAPTER_DIR}/`, for its tools; none is named to the session",
87121
f"- Skills: {', '.join(skills) or 'none'}", f"- Roles: {', '.join(roles.values()) or 'none'}",
88122
f"- Tools: {', '.join(t['name'] for t in bundle.tools) or 'none'}",
89123
f"- Left out (--allow-lossy): {', '.join(omitted)}" if omitted else "- Left out: nothing", ""])

‎hermit/plugins/codex_plugin.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
from pathlib import Path
1414

1515
from hermit.plugins.common import (ADAPTER_DIR, AUDIT_LOG, FRAMEWORK_VERSION, SERVER_COMMAND, clear, copy_skills,
16-
embed_adapter, load, prepare_output, record, refuse, server_args, write_json)
16+
embed_adapter, load, prepare_output, record, refuse, server_args,
17+
unnamed_line, write_json)
1718

1819
PLUGIN_SCHEMA = "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json"
1920
MCP_SCHEMA = "https://agent-plugins.org/schemas/1.0.0/mcp.schema.json"
@@ -53,9 +54,11 @@ def build(adapter: Path, output: Path, python: str, *, allow_lossy: bool = False
5354
f"codex plugin add {bundle.id}@{bundle.id}-adapters", "```", "",
5455
"The tools run as `hermit serve`, so `hermit` must be installed and on PATH.", "",
5556
f"- Skills: {', '.join(skills) or 'none'}", f"- Tools: {', '.join(t['name'] for t in bundle.tools) or 'none'}",
57+
unnamed_line(bundle, "Codex"),
5658
f"- Left out (--allow-lossy): {', '.join(omitted)}" if omitted else "- Left out: nothing", ""]))
5759
return {"target": "codex", "adapter_id": bundle.id, "version": bundle.version, "framework": FRAMEWORK_VERSION,
5860
"output": str(output),
5961
"plugin": str(plugin), "install": [f"codex plugin marketplace add {output}",
6062
f"codex plugin add {bundle.id}@{bundle.id}-adapters"],
61-
"skills": skills, "server_name": bundle.server if bundle.tools else None, "omitted": omitted}
63+
"skills": skills, "server_name": bundle.server if bundle.tools else None,
64+
"unnamed_files": bundle.other_files, "omitted": omitted}

‎hermit/plugins/common.py‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
from __future__ import annotations
1111

1212
from dataclasses import dataclass
13+
from functools import cached_property
1314
from pathlib import Path
1415
import json
1516
import shutil
1617

1718
from hermit import __version__ as FRAMEWORK_VERSION
1819
from hermit.adapter.loader import agent_tools, hook_definitions, load_manifest
19-
from hermit.hosts.inputs import (copy_skills as _copy_skills, render_exports, role_body, server_name,
20+
from hermit.hosts.inputs import (copy_skills as _copy_skills, other_files, render_exports, role_body, server_name,
2021
subagent_markdown, subagent_name)
2122

2223
# The adapter travels inside the plugin: a plugin that referenced an outside directory would break the moment it
@@ -67,6 +68,13 @@ def server(self) -> str:
6768
def has_context(self) -> bool:
6869
return bool(self.context.strip())
6970

71+
@cached_property
72+
def other_files(self) -> list[str]:
73+
"""The adapter's files no export connects (paths in the adapter). In training and in a `hermit deploy`
74+
workspace the agent's context names them, at the adapter's copy (hermit.hosts.inputs.resources); a plugin
75+
embeds them under `adapter/`."""
76+
return other_files(self.adapter, self.manifest, {"agents": self.roles}, self.hooks)
77+
7078

7179
def load(adapter: Path, python: str) -> Bundle:
7280
adapter = adapter.resolve()
@@ -91,6 +99,14 @@ def refuse(bundle: Bundle, target: str, reasons: dict[str, str], *, allow_lossy:
9199
return sorted(reasons)
92100

93101

102+
def unnamed_line(bundle: Bundle, target: str) -> str:
103+
"""The README's line on the adapter's files that no export connects, which the plugin carries but does not name to
104+
the session (a `hermit deploy` workspace's context names them)."""
105+
if not bundle.other_files:
106+
return "- Files the session is not told about: none"
107+
return f"- Files the session is not told about: {', '.join(bundle.other_files)} (under `{ADAPTER_DIR}/`)"
108+
109+
94110
def prepare_output(output: Path, adapter: Path, own_file: str) -> Path:
95111
"""The output directory: outside the adapter, and empty unless an earlier conversion wrote `own_file` there.
96112
`own_file` is one this framework writes and the host's own packages do not have, so a foreign directory is never

0 commit comments

Comments
 (0)