Skip to content

The agent that grows with you

fix(skills): keep absorbed_into in the delete shape; decide every patch shape miss pre-effect

teknium10bd85d314cce
diff --git a/agent/curator.py b/agent/curator.py
index 1b8d25bfdbc..a9198f980d0 100644
--- a/agent/curator.py
+++ b/agent/curator.py
@@ -382,7 +382,7 @@ CURATOR_REVIEW_PROMPT = (
"Your toolset:\n"
" - skills_list, skill_view — read the current landscape\n"
" READ BEFORE WRITE — enforced, not advisory. Before skill_manage "
- "action=patch, action=edit, action=write_file on a file that already "
+ "action=patch, action=write_file on a file that already "
"exists, or action=remove_file, call skill_view on that SAME target in "
"this review turn — skill_view(name) for SKILL.md, "
"skill_view(name, file_path=...) for a supporting file — and build the "
diff --git a/tests/tools/test_skill_manage_schema_diet.py b/tests/tools/test_skill_manage_schema_diet.py
index b26a333a72a..365ad7db3ca 100644
--- a/tests/tools/test_skill_manage_schema_diet.py
+++ b/tests/tools/test_skill_manage_schema_diet.py
@@ -75,10 +75,6 @@ class TestSkillManageSchemaDiet(unittest.TestCase):
self.assertIn("skill_view()", desc)
-if __name__ == "__main__":
- unittest.main()
-
-
def _fits(op, branch):
"""Plain-Python reading of one per-action branch (required + enum + additionalProperties:
false) so the test does not need a JSON-Schema validator."""
@@ -113,3 +109,13 @@ class TestSkillManagePerActionShapes(unittest.TestCase):
{"name": "s", "action": "remove_file", "file_path": "references/a.md"},
{"name": "s", "action": "delete"}):
self.assertEqual(len(self._matches(op)), 1, op)
+
+ def test_curator_consolidation_delete_keeps_absorbed_into(self):
+ """The curator's consolidation delete carries ``absorbed_into=<umbrella>``; with
+ additionalProperties:false a grammar-constrained backend refuses any key the delete
+ branch does not advertise, and the delete guard then fail-closes every consolidation."""
+ self.assertEqual(len(self._matches({"name": "s", "action": "delete", "absorbed_into": "umbrella"})), 1)
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/tests/tools/test_skill_manager_tool.py b/tests/tools/test_skill_manager_tool.py
index 01ca0ce9564..c75667d4fc8 100644
--- a/tests/tools/test_skill_manager_tool.py
+++ b/tests/tools/test_skill_manager_tool.py
@@ -516,6 +516,39 @@ class TestSkillManageDispatcher:
assert "rolled back" not in result["error"] and not sibling_created
assert bare["success"] is False and "file_content" not in bare["error"]
+ @pytest.mark.parametrize("op", [
+ {"action": "patch", "old_string": "body"},
+ {"action": "patch", "old_string": "body", "new_string": "x", "content": "# whole"},
+ ])
+ def test_patch_shape_misses_are_rejected_before_any_sibling_applies(self, tmp_path, op):
+ """A patch missing new_string, or mixing content with old_string/new_string, is a shape
+ miss like the misfiled text slot: decided in _validate_batch_ops, so op[0] is never
+ created and rolled back."""
+ with _skill_dir(tmp_path):
+ _create_skill("my-skill", VALID_SKILL_CONTENT)
+ result = json.loads(skill_manage(action="", name="", operations=[
+ {"name": "sibling", "action": "create", "content": VALID_SKILL_CONTENT},
+ {"name": "my-skill", **op}]))
+ sibling_created = _find_skill("sibling") is not None
+
+ assert result["success"] is False
+ assert "operations[1]" in result["error"]
+ assert "rolled back" not in result["error"] and not sibling_created
+
+ def test_batch_delete_forwards_absorbed_into_to_consolidation_guard(self, tmp_path):
+ """Curator consolidation emits ``[{action: delete, name, absorbed_into: umbrella}]`` through
+ the operations[] shape; the guard must see that umbrella, not None (which fail-closes)."""
+ with _skill_dir(tmp_path), \
+ patch("tools.skill_manager_tool._curator_consolidation_delete_guard",
+ return_value=None) as guard:
+ _create_skill("umbrella", VALID_SKILL_CONTENT)
+ _create_skill("narrow", VALID_SKILL_CONTENT)
+ result = json.loads(skill_manage(action="", name="", operations=[
+ {"name": "narrow", "action": "delete", "absorbed_into": "umbrella"}]))
+
+ assert result["success"] is True, result
+ guard.assert_called_once_with("narrow", "umbrella")
+
def test_unmatched_old_string_with_stray_key_is_not_steered_to_a_rewrite(self, tmp_path):
"""#112677 — the misplaced-text note belongs to argument-shape misses only. A patch whose
real problem is an unmatched old_string used to get "move that text to ... 'content'
diff --git a/tools/skill_manager_batch.py b/tools/skill_manager_batch.py
index a7dd15a12d3..5b710935f9c 100644
--- a/tools/skill_manager_batch.py
+++ b/tools/skill_manager_batch.py
@@ -33,6 +33,9 @@ _PATCH_NEEDS_OLD_STRING = (
"Read the target file first (read_file on the skill's SKILL.md, or the file named by "
"file_path) and copy the snippet verbatim, then retry 'patch'. Do NOT fall back to "
"action='write_file' — that rewrites the entire file and destroys unrelated content.")
+_PATCH_NEEDS_NEW_STRING = "new_string is required for 'patch'. Use an empty string to delete matched text."
+_PATCH_EITHER_OR = ("Pass EITHER content (full SKILL.md rewrite) OR old_string/new_string "
+ "(targeted replacement), not both.")
# Text-slot keys a model confuses: key -> the action that reads it. A 27B model that just
# used write_file's file_content re-emits it on create/patch and then replays the identical
# payload when the error only says the right key is "required" — the hint has to name where
@@ -67,8 +70,15 @@ def _op_shape_error(action: str, args: dict):
for arg, missing, message in _REQUIRED_ARGS.get(action, ()):
if missing(args.get(arg)):
return message + _misplaced_text_hint(action, args)
- if action == "patch" and not args.get("old_string") and not args.get("content"):
- return _PATCH_NEEDS_OLD_STRING + _misplaced_text_hint(action, args)
+ if action == "patch":
+ # Every patch shape miss is decided here, not in the handler, so a batch never applies
+ # op[0] only to roll it back over op[1]'s missing new_string or content+old_string mix.
+ if args.get("content") and (args.get("old_string") or args.get("new_string") is not None):
+ return _PATCH_EITHER_OR
+ if not args.get("old_string") and not args.get("content"):
+ return _PATCH_NEEDS_OLD_STRING + _misplaced_text_hint(action, args)
+ if not args.get("content") and args.get("new_string") is None:
+ return _PATCH_NEEDS_NEW_STRING
return None
diff --git a/tools/skill_manager_tool.py b/tools/skill_manager_tool.py
index cb741d7ec32..abe23bbc07a 100644
--- a/tools/skill_manager_tool.py
+++ b/tools/skill_manager_tool.py
@@ -32,7 +32,8 @@ from tools.skill_manager_guards import (
_background_review_preflight, _background_review_read_before_write_guard, _background_review_write_guard,
_containing_skills_root, _curator_consolidation_delete_guard, _maybe_auto_propose_org_edit,
_org_mirror_write_guard, _pinned_guard, _validate_delete_target, _is_background_review, _refusal as _err)
-from tools.skill_manager_batch import _PATCH_NEEDS_OLD_STRING, _op_shape_error, _skill_manage_batch
+from tools.skill_manager_batch import (
+ _PATCH_EITHER_OR, _PATCH_NEEDS_NEW_STRING, _PATCH_NEEDS_OLD_STRING, _op_shape_error, _skill_manage_batch)
from tools.skills_guard import scan_skill, should_allow_install, format_scan_report
logger = logging.getLogger(__name__)
@@ -462,7 +463,7 @@ def _patch_skill(name: str, old_string: str, new_string: str, file_path: str = N
if not old_string:
return _err(_PATCH_NEEDS_OLD_STRING)
if new_string is None:
- return _err("new_string is required for 'patch'. Use an empty string to delete matched text.")
+ return _err(_PATCH_NEEDS_NEW_STRING)
# No old_string == new_string guard here: fuzzy_find_and_replace rejects that with a
# richer error (file_preview) this layer cannot produce.
skill_dir, guard = _locate_for_write(name, "patch")
@@ -691,8 +692,7 @@ def _act_patch(a):
"""Two shapes: old_string/new_string = targeted replacement (validated in _patch_skill so the
tool and the helper give the same guidance); content alone = full rewrite (the old 'edit')."""
if a["content"] and (a["old_string"] or a["new_string"] is not None):
- return tool_error("Pass EITHER content (full SKILL.md rewrite) OR "
- "old_string/new_string (targeted replacement), not both.", success=False)
+ return tool_error(_PATCH_EITHER_OR, success=False)
if a["content"]:
return _edit_skill(a["name"], a["content"])
return _patch_skill(a["name"], a["old_string"], a["new_string"], a["file_path"], a["replace_all"])
@@ -893,12 +893,17 @@ SKILL_MANAGE_SCHEMA = {
_op_schema("remove_file", {
"file_path": {"type": "string", "description": "Supporting file (write_file's shape)."},
}, ("file_path",)),
- _op_schema("delete", {}, ()),
+ # `absorbed_into` stays in the delete shape: with additionalProperties:false a
+ # grammar-constrained backend would otherwise strip it and the curator's
+ # consolidation delete guard would fail-close every consolidation.
+ _op_schema("delete", {
+ "absorbed_into": {"type": "string",
+ "description": "Curator consolidation only: umbrella skill "
+ "that absorbed this one (must exist)."},
+ }, ()),
]},
},
- # Also accepted, never advertised: the legacy flat single-op fields, and
- # `absorbed_into` on delete ops (curator-only vocabulary; the curator's
- # prompt documents it and the delete guard's error re-teaches it).
+ # Also accepted, never advertised: the legacy flat single-op fields.
},
"required": ["operations"],
},
diff --git a/website/docs/user-guide/features/skills.md b/website/docs/user-guide/features/skills.md
index c9924206cc8..d8f017bdb49 100644
--- a/website/docs/user-guide/features/skills.md
+++ b/website/docs/user-guide/features/skills.md
@@ -437,7 +437,7 @@ Paths support `~` expansion and `${VAR}` environment variable substitution.
### How it works
-- **Create locally, update in place**: New agent-created skills are written to `~/.hermes/skills/` (or `skills.create_dir` when configured — see below). Existing skills are modified where they are found, including skills under `external_dirs`, when the agent uses `skill_manage` actions such as `patch`, `edit`, `write_file`, `remove_file`, or `delete`.
+- **Create locally, update in place**: New agent-created skills are written to `~/.hermes/skills/` (or `skills.create_dir` when configured — see below). Existing skills are modified where they are found, including skills under `external_dirs`, when the agent uses `skill_manage` actions such as `patch` (targeted or full rewrite), `write_file`, `remove_file`, or `delete`.
- **External dirs are not a write-protection boundary**: If an external skill directory is writable by the Hermes process, agent-managed skill updates can change files in that directory. Use filesystem permissions or a separate profile/toolset setup if shared external skills must stay read-only.
- **Local precedence**: If the same skill name exists in both the local dir and an external dir, the local version wins.
- **Full integration**: External skills appear in the system prompt index, `skills_list`, `skill_view`, and as `/skill-name` slash commands — no different from local skills.