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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ Changes are grouped by software version. Entries under Unreleased describe work

### Fixed

- A redeployment (`hermit deploy` into the same workspace) left a skill the new adapter no longer exports in the
host's skills folder (`.codex/skills`, `.claude/skills`, `.pi/skills`, `.opencode/skills`), where the agent still
loaded it, and a file a skill no longer has inside its copy. Each exported skill's copy is now replaced, and a
skill the last deployment's record names that this one does not export is moved to `.retired-skills/` (as a
role is to `.retired-roles/`); a skill the user put there stays. A redeployment refuses, before writing anything,
when an exported skill would replace a skill folder no deployment wrote or the skills folder is a link (#96).
- ASPIRE's generated programs ran unconfined on the host: cap-harness runs them, and ASPIRE's program validator is
passed by a format string's attribute traversal, so a program could read and write the host's files (other
sessions' workspaces, the judge's Stage 2 runs) and run held-out seeds itself. Every cap-harness process (the
Expand Down
8 changes: 6 additions & 2 deletions docs/framework/adapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,13 @@ and preserves project text outside it. Existing adapter headings are nested unde

The deployment command prepares a workspace; it does not launch the agent. Its output must be empty or a workspace
previously generated for the same host. The source adapter and output workspace cannot contain one another.
A redeployment replaces the copy under `hermit/<id>/`: files the new version no longer has are removed. It refuses,
A redeployment replaces the copy under `hermit/<id>/`: files the new version no longer has are removed. It also
replaces each exported skill's copy in the host's skills folder, and moves a skill the last deployment copied there
that the new version no longer exports to `.retired-skills/` (a stale role goes to `.retired-roles/`), out of the
host's discovery; a skill you put there yourself stays. It refuses,
before writing anything, when a copied file was changed or replaced (by a directory or a link) since the last
deployment or another file is in the way, and
deployment or another file is in the way, when an exported skill would replace a skill folder no deployment wrote,
or when the skills folder is a link (or reached through one), and
names the file; an adapter link that leads outside the adapter is refused too.
The generated `.codex/config.toml`, `.mcp.json`, `.pi/mcp.json`, `mini-swe-agent.yaml` or `opencode.json` is rewritten on
deployment; it is not a general configuration
Expand Down
8 changes: 5 additions & 3 deletions hermit/hosts/claude_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
from hermit.adapter.loader import agent_tools, hook_definitions, load_manifest, not_portable
from hermit.hosts.context import PROJECT_CONTEXT, START, append_context
from hermit.hosts.inputs import (MARKER, PACKAGE_ROOT, _adapter_sandbox_env, adapter_files, adapter_folder,
check_workspace, copy_adapter, copy_skills, folder_note, hook_commands, native_hooks,
render_exports, resources, retire_roles, role_body, server_name, source_label,
subagent_markdown, subagent_name)
check_skills, check_workspace, copy_adapter, copy_skills, folder_note, hook_commands,
native_hooks, render_exports, resources, retire_roles, retire_skills, role_body,
server_name, source_label, subagent_markdown, subagent_name)

NATIVE = {"skills", "agents"}
HOOK_TYPES = {"command", "prompt"}
Expand All @@ -35,6 +35,7 @@ def prepare(adapter: Path, output: Path, python: str, *, learning_material: Path
output.mkdir(parents=True, exist_ok=True)
manifest = load_manifest(adapter)
files = adapter_files(adapter, output, manifest, previous)
check_skills(adapter, output, manifest, previous, output / ".claude" / "skills")
hooks = hook_definitions(adapter, manifest)
settings_path = output / ".claude" / "settings.json" # the hooks' place; other settings in it are kept
settings = json.loads(settings_path.read_text()) if settings_path.is_file() else {}
Expand Down Expand Up @@ -88,6 +89,7 @@ def prepare(adapter: Path, output: Path, python: str, *, learning_material: Path
settings_path.write_text(json.dumps(settings, indent=2) + "\n")
retire_roles(output, previous, role_paths)
skills = copy_skills(adapter, manifest, output / ".claude" / "skills")
retire_skills(output, previous, skills, output / ".claude" / "skills")
copy_adapter(adapter, output, manifest, files, previous)
result = {"host": "claude-code", "adapter_id": manifest["id"], "version": manifest["version"], "adapter": str(adapter),
"workspace": str(output), "context_injected_via": "CLAUDE.md",
Expand Down
8 changes: 5 additions & 3 deletions hermit/hosts/codex.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
from hermit.adapter.loader import agent_tools, hook_definitions, load_manifest, not_portable
from hermit.hosts.context import PROJECT_CONTEXT, append_context
from hermit.hosts.inputs import (MARKER, PACKAGE_ROOT, _adapter_sandbox_env, adapter_files, adapter_folder,
check_context_size, check_workspace, copy_adapter, copy_skills, folder_note,
hook_commands, native_hooks, render_exports, resources, retire_roles, role_body,
server_name, source_label)
check_context_size, check_skills, check_workspace, copy_adapter, copy_skills,
folder_note, hook_commands, native_hooks, render_exports, resources, retire_roles,
retire_skills, role_body, server_name, source_label)

DOC_BYTES = 32 * 1024 # Codex's project_doc_max_bytes when the user's config does not set it
NATIVE = {"skills", "agents"}
Expand Down Expand Up @@ -48,6 +48,7 @@ def prepare(adapter: Path, output: Path, python: str, *, learning_material: Path
output.mkdir(parents=True, exist_ok=True)
manifest = load_manifest(adapter)
files = adapter_files(adapter, output, manifest, previous)
check_skills(adapter, output, manifest, previous, output / ".codex" / "skills")
hooks = hook_definitions(adapter, manifest)
exports = render_exports(adapter, python)
listed, placed = resources(adapter, output, manifest, exports, hooks, NATIVE, HOOK_TYPES)
Expand Down Expand Up @@ -106,6 +107,7 @@ def prepare(adapter: Path, output: Path, python: str, *, learning_material: Path
hooks_path.unlink()
retire_roles(output, previous, role_paths)
skills = copy_skills(adapter, manifest, output / ".codex" / "skills")
retire_skills(output, previous, skills, output / ".codex" / "skills")
copy_adapter(adapter, output, manifest, files, previous)
result = {"host": "codex", "adapter_id": manifest["id"], "version": manifest["version"], "adapter": str(adapter),
"workspace": str(output), "context_injected_via": "AGENTS.md",
Expand Down
76 changes: 68 additions & 8 deletions hermit/hosts/inputs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Inputs shared by the host deployers and by `convert`: rendered exports, names, roles, stale-role
retirement, skills, the adapter's copy and its hooks."""
retirement, skills and stale-skill retirement, the adapter's copy and its hooks."""
import hashlib
import json
import os
Expand Down Expand Up @@ -63,20 +63,80 @@ def source_label(manifest):
return context if isinstance(context, str) else (context or {}).get("entrypoint", "adapter")


def copy_skills(adapter: Path, manifest: dict, target: Path) -> list[str]:
"""Copy every skill directory (one containing SKILL.md) of the adapter's `skills` export into target."""
def skill_sources(adapter: Path, manifest: dict) -> list[Path]:
"""The skill directories (one containing SKILL.md) of the adapter's `skills` export."""
if not manifest.get("skills"):
return []
source = (adapter / manifest["skills"]).resolve()
return [child for child in sorted(source.iterdir()) if (child / "SKILL.md").is_file()] if source.is_dir() else []


def check_skills(adapter: Path, output: Path, manifest: dict, previous: dict, target: Path) -> None:
"""A deployment's skills, checked before anything is written: the skills folder (`target`) and .retired-skills/
are reached with no link on the way (what a deployment replaces and moves stays in the workspace), the previous
record names plain skill directories, and no exported skill would replace one no deployment copied there (the
user's own)."""
for path in (target, output / ".retired-skills"):
if _link_on_way(output, path):
raise ValueError(f"{path.relative_to(output)} is a link or is reached through one; remove it, then deploy "
"again")
owned = _recorded_skills(previous)
for child in skill_sources(adapter, manifest):
if os.path.lexists(target / child.name) and child.name not in owned:
raise ValueError(f"{(target / child.name).relative_to(output)} exists and was not written by a "
"deployment; remove it, then deploy again")


def copy_skills(adapter: Path, manifest: dict, target: Path) -> list[str]:
"""Copy every skill directory of the adapter's `skills` export into target, in place of the copy an earlier
deployment left there (check_skills): no file the skill no longer has survives."""
names = []
if source.is_dir():
for child in sorted(source.iterdir()):
if (child / "SKILL.md").is_file():
shutil.copytree(child, target / child.name, dirs_exist_ok=True, symlinks=True)
names.append(child.name)
for child in skill_sources(adapter, manifest):
_remove(target / child.name)
shutil.copytree(child, target / child.name, symlinks=True)
names.append(child.name)
return names


def retire_skills(output, previous, current, target):
"""Move the skills an earlier deployment copied into `target` (its record's `skills`) that this one does not
(`current`) out of host discovery; keep their contents. A skill the user put there is never in the record."""
for name in _recorded_skills(previous):
path = target / name
if name in current or not os.path.lexists(path):
continue
archive = output / ".retired-skills" / uuid.uuid4().hex
archive.mkdir(parents=True)
path.rename(archive / name)


def _recorded_skills(previous: dict) -> list[str]:
"""The skills the previous deployment's record names, each a plain directory name."""
names = previous.get("skills") or []
if not isinstance(names, list) or any(not isinstance(name, str) or name in ("", ".", "..") or
Path(name).name != name for name in names):
raise ValueError("Previous skill metadata points outside the generated host workspace")
return names


def _link_on_way(output: Path, path: Path) -> bool:
"""Whether a link (or a file) stands on the way from the workspace to `path`, `path` included."""
here = output
for part in path.relative_to(output).parts:
here = here / part
if here.is_symlink() or (here.exists() and not here.is_dir()):
return True
return False


def _remove(path: Path) -> None:
"""`path` gone, whatever it is: a link is removed, never followed."""
if path.is_symlink() or path.is_file():
path.unlink()
elif path.is_dir():
shutil.rmtree(path)


def _adapter_sandbox_env(python: str) -> dict:
"""The variables that put a tool server's Session in its own sandbox, when deploy runs inside a run. A host may
start the server with a cleared environment, so they travel in the server's own `env`. Empty for a standalone
Expand Down
7 changes: 5 additions & 2 deletions hermit/hosts/opencode.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@

from hermit.adapter.loader import agent_tools, hook_definitions, load_manifest, not_portable
from hermit.hosts.context import PROJECT_CONTEXT, START, append_context
from hermit.hosts.inputs import (MARKER, PACKAGE_ROOT, adapter_files, adapter_folder, check_workspace, copy_adapter,
copy_skills, folder_note, render_exports, resources, server_name, source_label)
from hermit.hosts.inputs import (MARKER, PACKAGE_ROOT, adapter_files, adapter_folder, check_skills, check_workspace,
copy_adapter, copy_skills, folder_note, render_exports, resources, retire_skills,
server_name, source_label)

NATIVE = {"skills"}
TOOL_TIMEOUT_MS = 120 * 1000 # Codex's tool_timeout_sec, not OpenCode's 30 s
Expand All @@ -37,6 +38,7 @@ def prepare(adapter: Path, output: Path, python: str, *, learning_material: Path
previous = check_workspace(adapter, output, "opencode")
manifest = load_manifest(adapter)
files = adapter_files(adapter, output, manifest, previous)
check_skills(adapter, output, manifest, previous, output / ".opencode" / "skills")
exports = render_exports(adapter, python)
listed, placed = resources(adapter, output, manifest, exports, hook_definitions(adapter, manifest), NATIVE)
has_tools = bool(agent_tools(manifest)) and serve_tools # the context tool is the harness's, not served
Expand Down Expand Up @@ -65,6 +67,7 @@ def prepare(adapter: Path, output: Path, python: str, *, learning_material: Path
(output / "opencode.json").write_text(json.dumps({"mcp": {"servers": servers}}, indent=2) + "\n")
context_path.write_text(context_text)
skills = copy_skills(adapter, manifest, output / ".opencode" / "skills")
retire_skills(output, previous, skills, output / ".opencode" / "skills")
copy_adapter(adapter, output, manifest, files, previous)
result = {"host": "opencode", "adapter_id": manifest["id"], "version": manifest["version"],
"adapter": str(adapter), "workspace": str(output), "context_injected_via": "AGENTS.md",
Expand Down
7 changes: 5 additions & 2 deletions hermit/hosts/pi.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@

from hermit.adapter.loader import agent_tools, hook_definitions, load_manifest, not_portable
from hermit.hosts.context import PROJECT_CONTEXT, START, append_context
from hermit.hosts.inputs import (MARKER, PACKAGE_ROOT, adapter_files, adapter_folder, check_workspace, copy_adapter,
copy_skills, folder_note, render_exports, resources, server_name, source_label)
from hermit.hosts.inputs import (MARKER, PACKAGE_ROOT, adapter_files, adapter_folder, check_skills, check_workspace,
copy_adapter, copy_skills, folder_note, render_exports, resources, retire_skills,
server_name, source_label)

NATIVE = {"skills"}

Expand All @@ -34,6 +35,7 @@ def prepare(adapter: Path, output: Path, python: str, *, learning_material: Path
previous = check_workspace(adapter, output, "pi")
manifest = load_manifest(adapter)
files = adapter_files(adapter, output, manifest, previous)
check_skills(adapter, output, manifest, previous, output / ".pi" / "skills")
exports = render_exports(adapter, python)
listed, placed = resources(adapter, output, manifest, exports, hook_definitions(adapter, manifest), NATIVE)
has_tools = bool(agent_tools(manifest)) # the context tool is the harness's, not served
Expand Down Expand Up @@ -62,6 +64,7 @@ def prepare(adapter: Path, output: Path, python: str, *, learning_material: Path
indent=2) + "\n")
context_path.write_text(context_text)
skills = copy_skills(adapter, manifest, output / ".pi" / "skills")
retire_skills(output, previous, skills, output / ".pi" / "skills")
copy_adapter(adapter, output, manifest, files, previous)
result = {"host": "pi", "adapter_id": manifest["id"], "version": manifest["version"], "adapter": str(adapter),
"workspace": str(output), "context_injected_via": "AGENTS.md",
Expand Down
Loading
Loading