The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(skills): background review can improve every skill, not just curator-managed ones
Tekniume3d2e57c9ec2
diff --git a/agent/background_review.py b/agent/background_review.pyindex 3b34116af21..99fa233583b 100644--- a/agent/background_review.py+++ b/agent/background_review.py@@ -463,9 +463,8 @@ _SKILL_REVIEW_PROMPT = ("loaded via /skill-name or you read via skill_view. If any of them covers the territory of the ""new learning, PATCH that one first (re-load it with skill_view during this review — see ""Read-before-write below). It is the skill that was in play, so it's the right one to extend — "- "but only if it is curator-managed. Bundled, hub, pinned, and user-owned skills are off-limits "- "to you no matter how relevant (see Protected skills below); for those, fall through to the "- "next option.\n"+ "whoever wrote it: hand-written, installed, bundled, and pinned skills are all yours to "+ "improve.\n"" 2. UPDATE AN EXISTING UMBRELLA (via skills_list + skill_view). If no loaded skill fits but ""an existing class-level skill does, patch it. Add a subsection, a pitfall, or broaden a ""trigger.\n"@@ -502,21 +501,7 @@ _SKILL_REVIEW_PROMPT = ("'how to do this class of task for this user'. When they complain about how you handled a ""task, the skill that governs that task needs to carry the lesson.\n\n""If you notice two existing skills that overlap, note it in your reply — the background "- "curator handles consolidation at scale.\n\n"- "Protected skills (DO NOT edit these):\n"- " • Bundled skills (shipped with Hermes, e.g. 'hermes-agent').\n"- " • Hub-installed skills (installed via 'hermes skills install').\n"- " • Skills in skills.external_dirs (externally owned).\n"- " • PINNED skills (marked via 'hermes curator pin'). You are an autonomous no-user-present "- "actor, so pin blocks your writes too — content updates included. Only the user, in a "- "foreground session, can change a pinned skill.\n"- " • USER-OWNED skills — anything not curator-managed. A skill the user hand-wrote, installed "- "by URL, or asked a foreground agent to create is theirs, not yours; your writes to it WILL be "- "refused. This includes skills that were loaded or consulted this session: being in play does "- "not make one yours to edit. If such a skill is wrong or outdated, say so in your reply and "- "recommend 'hermes curator adopt <name>' — do not try to patch it.\n"- "If the only skills that need updating are protected, say\n"- "'Nothing to save.' and stop.\n\n"+ "curator handles consolidation at scale. Never delete a skill here.\n\n""Do NOT capture" + _DO_NOT_CAPTURE_BLOCK +"'Nothing to save.' is a real option but should NOT be the default. If the session ran ""smoothly with no corrections and produced no new technique, just say 'Nothing to save.' and "@@ -544,8 +529,7 @@ _COMBINED_REVIEW_PROMPT = (" 1. UPDATE A CURRENTLY-LOADED SKILL. Check what skills were loaded via /skill-name or ""skill_view in the conversation. If one of them covers the learning, PATCH it first (re-load ""it with skill_view during this review — see Read-before-write below). It was in play; it's "- "the right place — provided it is curator-managed. Protected and user-owned skills are "- "off-limits however relevant; fall through when one of those is the best fit.\n"+ "the right place, whoever wrote it.\n"" 2. UPDATE AN EXISTING UMBRELLA (skills_list + skill_view to find the right one). Patch it.\n"" 3. ADD A SUPPORT FILE under an existing umbrella via skill_manage action=write_file. Three ""kinds: `references/<topic>.md` for topical depth (decision tables, recipes, quirks, condensed "@@ -570,20 +554,7 @@ _COMBINED_REVIEW_PROMPT = ("owns — never both. Duplicating it is how a memory file ends up restating SKILL.md until both ""hit their size limits.\n\n""If you notice overlapping existing skills, mention it — the background curator handles "- "consolidation.\n\n"- "Protected skills (DO NOT edit these):\n"- " • Bundled skills (shipped with Hermes, e.g. 'hermes-agent').\n"- " • Hub-installed skills (installed via 'hermes skills install').\n"- " • Skills in skills.external_dirs (externally owned).\n"- " • PINNED skills (marked via 'hermes curator pin'). Pin blocks autonomous writes entirely — "- "content updates included — because no user is present to consent. Only a foreground session "- "can change one.\n"- " • USER-OWNED skills — anything not curator-managed (hand-written, URL-installed, or created "- "by a foreground agent at the user's request). Your writes to these WILL be refused, including "- "to skills loaded or consulted this session. If one is wrong, say so in your reply and "- "recommend 'hermes curator adopt <name>' instead.\n"- "If the only skills that need updating are protected, say\n"- "'Nothing to save.' and stop.\n\n"+ "consolidation. Never delete a skill here.\n\n""Do NOT capture as skills" + _DO_NOT_CAPTURE_BLOCK +"Act on whichever of the two dimensions has real signal. If genuinely nothing stands out on ""either, say 'Nothing to save.' and stop — but don't reach for that conclusion as a default."diff --git a/agent/curator.py b/agent/curator.pyindex 5a8a69c94c9..122cab3b406 100644--- a/agent/curator.py+++ b/agent/curator.py@@ -835,9 +835,9 @@ def _render_candidate_list() -> str:Bundled built-ins are excluded even when ``curator.prune_builtins`` ison. That flag makes them eligible for *deterministic archival*(``apply_automatic_transitions`` → ``archive_skill``), not for the- rewrite/umbrella pass. Listing them here invites ``skill_manage``- writes that ``_background_review_write_guard`` unconditionally- refuses, burning tool calls until the loop guard aborts the run.+ rewrite/umbrella pass. Listing them here invites umbrella deletes+ that ``_background_review_delete_guard`` unconditionally refuses,+ burning tool calls until the loop guard aborts the run.Skills in ``skills.disabled`` (global or platform list) are excluded forthe same reason on the read side: ``skill_view`` — the pass's only readdiff --git a/tests/tools/test_skill_manager_tool.py b/tests/tools/test_skill_manager_tool.pyindex 3b13669a73c..254e197ead5 100644--- a/tests/tools/test_skill_manager_tool.py+++ b/tests/tools/test_skill_manager_tool.py@@ -927,37 +927,42 @@ class TestExternalSkillMutations:assert not (local / "ext-skill").exists()- def test_background_review_refuses_to_patch_pinned_skill(self, tmp_path):- """#25839: the autonomous review fork respects pin like the curator- does — a pinned skill is off-limits to background maintenance, even- for patch/edit (which a foreground user-directed call is allowed to- perform). Without a user in the loop there is no one to consent."""+ def test_background_review_improves_any_skill_but_deletes_only_managed_ones(self, tmp_path):+ """#134289: the review fork improves every skill it learns from (user-owned with no usage+ record, pinned, bundled, hub-installed), while delete keeps the ownership/pin guard."""+ from tools.skill_manager_guards import mark_background_review_skill_readfrom tools.skill_provenance import (BACKGROUND_REVIEW,reset_current_write_origin,set_current_write_origin,)- def _fake_get_record(skill_name):- return {"pinned": True} if skill_name == "my-skill" else {"pinned": False}-- with _skill_dir(tmp_path):+ with _skill_dir(tmp_path), \+ patch("tools.skill_usage.load_usage", return_value={}), \+ patch("tools.skill_usage.get_record", return_value={"pinned": True}), \+ patch("tools.skill_usage.is_bundled", return_value=True), \+ patch("tools.skill_usage.is_hub_installed", return_value=True):_create_skill("my-skill", VALID_SKILL_CONTENT)token = set_current_write_origin(BACKGROUND_REVIEW)try:- with patch("tools.skill_usage.get_record", side_effect=_fake_get_record):- raw = skill_manage(- action="patch",- name="my-skill",- old_string="Do the thing.",- new_string="Do the new thing.",- )+ mark_background_review_skill_read(tmp_path / "my-skill" / "SKILL.md")+ patched = json.loads(skill_manage(+ action="patch", name="my-skill",+ old_string="Do the thing.", new_string="Do the new thing."))+ written = json.loads(skill_manage(+ action="write_file", name="my-skill",+ file_path="references/lesson.md", file_content="# Lesson\n"))+ deleted = json.loads(skill_manage(+ action="delete", name="my-skill", absorbed_into="my-skill"))finally:reset_current_write_origin(token)- result = json.loads(raw)- assert result["success"] is False- assert "pinned" in result["error"].lower()+ assert patched["success"] is True, patched+ assert written["success"] is True, written+ assert "Do the new thing." in (tmp_path / "my-skill" / "SKILL.md").read_text(encoding="utf-8")+ assert deleted["success"] is False+ assert "Refusing background curator delete" in deleted["error"]+ assert (tmp_path / "my-skill" / "SKILL.md").exists()def test_background_review_fails_closed_when_ownership_lookup_errors(self, tmp_path):@@ -976,10 +981,7 @@ class TestExternalSkillMutations:side_effect=ValueError("corrupt usage data"),):raw = skill_manage(- action="patch",- name="manual-skill",- old_string="Do the thing.",- new_string="Changed.",+ action="delete", name="manual-skill", absorbed_into="manual-skill",)finally:reset_current_write_origin(token)@@ -992,18 +994,16 @@ class TestExternalSkillMutations:).read_text(encoding="utf-8")class TestBackgroundOwnershipPolicyConsistency:- """The autonomous write policy must not depend on its own side effects.+ """The autonomous delete policy must not depend on its own side effects.Issue #67140: the ownership guard keyed on ``isinstance(usage_rec, dict)``,- so a local skill with NO usage record passed. The successful write then- called ``bump_patch()``, creating a ``created_by: null`` record — and the- identical write was refused from then on. "Allowed exactly once" is a race- with our own bookkeeping, not a policy.+ so a local skill with NO usage record passed once and was refused after+ the first write created a ``created_by: null`` record. Ownership now gates+ only delete (#134289), and that verdict must stay stable."""@staticmethod- def _bg_patch(tmp_path, name, old, new):- from tools.skill_manager_guards import mark_background_review_skill_read+ def _bg_delete(name):from tools.skill_provenance import (BACKGROUND_REVIEW,reset_current_write_origin,@@ -1012,32 +1012,22 @@ class TestBackgroundOwnershipPolicyConsistency:token = set_current_write_origin(BACKGROUND_REVIEW)try:- mark_background_review_skill_read(tmp_path / name / "SKILL.md")- return json.loads(skill_manage(- action="patch", name=name, old_string=old, new_string=new,- ))+ return json.loads(skill_manage(action="delete", name=name, absorbed_into="umbrella"))finally:reset_current_write_origin(token)- def test_repeated_identical_write_gets_the_same_answer(self, tmp_path, monkeypatch):- """The real #67140 shape: no stubbing of load_usage, so the first write's- telemetry side effect is live. Both attempts must agree."""+ def test_repeated_identical_delete_gets_the_same_answer(self, tmp_path, monkeypatch):+ """No stubbing of load_usage: telemetry side effects are live. Both attempts agree."""monkeypatch.setenv("HERMES_HOME", str(tmp_path / ".hermes"))(tmp_path / ".hermes" / "skills").mkdir(parents=True, exist_ok=True)with _skill_dir(tmp_path):_create_skill("flip-skill", VALID_SKILL_CONTENT)- first = self._bg_patch(- tmp_path, "flip-skill", "Do the thing.", "Do the new thing.",- )- second = self._bg_patch(- tmp_path, "flip-skill", "Do the thing.", "Do the new thing.",- )+ first = self._bg_delete("flip-skill")+ second = self._bg_delete("flip-skill")- assert first["success"] == second["success"], (- "autonomous write policy flipped between two identical attempts: "- f"first={first.get('success')} second={second.get('success')}"- )- assert first["success"] is False+ assert first["success"] is second["success"] is False+ assert "not curator-managed" in first["error"]+ assert "not curator-managed" in second["error"]def test_foreground_write_to_unmanaged_skill_still_allowed(self, tmp_path, monkeypatch):"""Fail-closed applies to AUTONOMOUS writes only. A user-directed@@ -1052,15 +1042,13 @@ class TestBackgroundOwnershipPolicyConsistency:))assert res["success"] is True- def test_adopted_skill_becomes_writable_by_autonomous_curation(self, tmp_path, monkeypatch):- """Adoption is the documented path from refused to allowed."""+ def test_adoption_lifts_the_autonomous_delete_refusal(self, tmp_path, monkeypatch):+ """Adoption is the documented path from refused to allowed for archival."""monkeypatch.setenv("HERMES_HOME", str(tmp_path / ".hermes"))with _skill_dir(tmp_path):_create_skill("adopt-me", VALID_SKILL_CONTENT)with patch("tools.skill_usage.load_usage", return_value={}):- before = self._bg_patch(- tmp_path, "adopt-me", "Do the thing.", "Do the new thing.",- )+ before = self._bg_delete("adopt-me")with patch("tools.skill_usage.load_usage",return_value={"adopt-me": {"created_by": "agent"}},@@ -1068,12 +1056,10 @@ class TestBackgroundOwnershipPolicyConsistency:"tools.skill_usage.get_record",side_effect=lambda n: {"created_by": "agent", "pinned": False},):- after = self._bg_patch(- tmp_path, "adopt-me", "Do the thing.", "Do the new thing.",- )+ after = self._bg_delete("adopt-me")- assert before["success"] is False- assert after["success"] is True, after+ assert "not curator-managed" in before["error"]+ assert "curator-managed" not in after.get("error", ""), after# ---------------------------------------------------------------------------diff --git a/tools/skill_manager_guards.py b/tools/skill_manager_guards.pyindex e8240f88d5c..914c321db27 100644--- a/tools/skill_manager_guards.py+++ b/tools/skill_manager_guards.py@@ -161,13 +161,13 @@ def _pinned_guard(name: str) -> Optional[str]:return None-def _background_review_write_guard(- name: str, skill_dir: Path, action: str) -> Optional[Dict[str, Any]]:- """Refuse autonomous curator writes to anything but curator-owned sediment. The review fork- has no user in the loop, so it is also blocked on pinned/external/bundled/hub skills."""+def _background_review_delete_guard(name: str, skill_dir: Path) -> Optional[Dict[str, Any]]:+ """Refuse autonomous deletes of anything but curator-owned sediment. Content writes are not+ gated by ownership: the review fork exists to improve every skill it learns from, and every+ write is ledgered and reversible, while an archive removes a skill the user relies on."""if not _is_background_review():return None- refuse = f"Refusing background curator {action} for"+ refuse = "Refusing background curator delete for"if _is_pinned(name, "pinned skill guard"):return _refusal(f"{refuse} pinned skill '{name}': pinned skills "@@ -189,26 +189,17 @@ def _background_review_write_guard((skill_usage.is_bundled, "bundled")):if predicate(name):return _refusal(f"{refuse} {label} skill '{name}'.")- # Not curator-managed (no `created_by: "agent"`) => user-owned. A MISSING- # record and an explicit `created_by: null` must resolve IDENTICALLY (keying- # on presence made the policy depend on the guard's own side effect: the- # first write created a null record, the next identical write was refused).+ # Not curator-managed (no `created_by: "agent"`) => user-owned, never archived+ # autonomously. A MISSING record and `created_by: null` must resolve identically:+ # keying on presence let the guard's own bookkeeping flip the verdict (#67140).usage_rec = skill_usage.load_usage().get(name)- # Skills that are not curator-managed are off-limits to autonomous curation. This prevents the LLM- # consolidation pass from mutating skills the user owns (manually authored, URL-installed, or- # created by a foreground `skill_manage(create)` at the user's request), which lack the `created_by:- # "agent"` marker. Keying on `isinstance(usage_rec, dict)` made the policy depend on the guard's own- # side effect: a local skill with no telemetry record passed, the successful write called- # bump_patch() which created a `created_by: null` record, and the very same write was refused from- # then on. "Allowed exactly once" is not a policy — it is a race with our own bookkeeping. Fail- # closed for both shapes; `hermes curator adopt <name>` is the supported way in. See #67140.if not skill_usage._is_curator_managed_record(usage_rec):_detail = (f"created_by={usage_rec.get('created_by')!r}" if isinstance(usage_rec, dict)else "no usage record")return _refusal(f"{refuse} skill '{name}': the skill is not "- f"curator-managed ({_detail}). User-owned skills are off-limits to autonomous "- f"curation. Run `hermes curator adopt {name}` to opt it in.")+ f"curator-managed ({_detail}). Only curator-managed skills may be archived "+ f"autonomously. Run `hermes curator adopt {name}` to opt it in.")except Exception:logger.warning("owned skill guard lookup failed for %s", name, exc_info=True)return _refusal(@@ -231,11 +222,11 @@ def _background_review_read_before_write_guard(def _background_review_preflight(action: str, name: str) -> Optional[Dict[str, Any]]:- if action not in {"edit", "patch", "delete", "write_file", "remove_file"}:+ if action != "delete":return Nonefrom tools import skill_manager_tool as _smtexisting = _smt._find_skill(name)- return _background_review_write_guard(name, existing["path"], action) if existing else None+ return _background_review_delete_guard(name, existing["path"]) if existing else Nonedef _curator_consolidation_delete_guard(diff --git a/tools/skill_manager_tool.py b/tools/skill_manager_tool.pyindex 18b0c3cd2de..1d183319e53 100644--- a/tools/skill_manager_tool.py+++ b/tools/skill_manager_tool.py@@ -28,7 +28,7 @@ from agent.skill_utils import (parse_frontmatter as _parse_frontmatter,SKILL_PROMPT_DESC_LIMIT)from tools.skill_manager_guards import (- _background_review_preflight, _background_review_read_before_write_guard, _background_review_write_guard,+ _background_review_delete_guard, _background_review_preflight, _background_review_read_before_write_guard,_containing_skills_root, _curator_consolidation_delete_guard, _is_path_redirect, _pinned_guard,_validate_delete_target, _is_background_review, _refusal as _err)from tools.skill_manager_batch import (@@ -382,12 +382,13 @@ def _resolve_supporting_file(skill_dir: Path, file_path: str):def _locate_for_write(name: str, action: str, not_found_suffix: str = ""):- """Find the skill; run the background-review write guard -> ``(skill_dir, None)`` | ``(None, error_dict)``."""+ """Find the skill; a delete also runs the background-review delete guard -> ``(skill_dir, None)``+ | ``(None, error_dict)``."""existing = _find_skill(name)if not existing:return None, _err(_skill_not_found_error(name, not_found_suffix))skill_dir = existing["path"]- guard = _background_review_write_guard(name, skill_dir, action)+ guard = _background_review_delete_guard(name, skill_dir) if action == "delete" else Nonereturn (None, guard) if guard else (skill_dir, None)diff --git a/website/docs/user-guide/features/curator.md b/website/docs/user-guide/features/curator.mdindex fcd16c1610f..70ad4235471 100644--- a/website/docs/user-guide/features/curator.md+++ b/website/docs/user-guide/features/curator.md@@ -276,11 +276,15 @@ existing `last_activity_at`, so handing over a library you already stoppedusing does not buy it a fresh 90-day window. Expect adopted long-idle skills togo `stale` (or `archived`) on the next pass; that is the point.-Adoption is also what unblocks autonomous *improvement*. The background review-fork refuses to patch a skill that isn't curator-managed, so if it notices one-of your skills is outdated it will say so and recommend adoption rather than-edit it. Foreground (user-directed) edits are never affected — you and the-agent can always edit your own skills on request.+Adoption only governs *archival*. The background self-improvement review can+patch, rewrite, and add support files to any skill it learns from (hand-written,+URL-installed, bundled, hub-installed, external, or pinned), so lessons land in+the skill that governs the task whoever wrote it. Every such write is recorded+in the skill ledger. It may archive (delete) only curator-managed skills, never+pinned ones. To review those writes before they land, turn on+`skills.write_approval` (see [Gating agent skill writes](./skills.md#gating-agent-skill-writes-skillswrite_approval)).+A bundled or hub-installed skill the review has edited counts as locally+modified, so `hermes update` / `hermes skills update` stop overwriting it.:::note `created_by` is a policy flag, not a provenance claimThe stored field is named `created_by`, but it is consumed as "may autonomous