fix(curator): authoritative absorbed_into on delete + restore cron skill links on rollback (#18671) (#18731)
* fix(curator): authoritative absorbed_into declarations on skill delete Closes #18671. The classification pipeline that feeds cron-ref rewriting used to infer consolidation vs pruning from two brittle signals: the curator model's post-hoc YAML summary block, and a substring heuristic scanning other tool calls for the removed skill's name. Both miss in real consolidations — the model forgets the YAML under reasoning pressure, and the heuristic misses when the umbrella's patch content describes the absorbed behavior abstractly instead of naming the old slug. When both miss, the skill falls through to 'no-evidence fallback' pruned, and #18253's cron rewriter drops the cron ref entirely instead of mapping it to the umbrella. Same observable symptom as pre-#18253: 'Skill(s) not found and skipped' at the next cron run. The fix makes the model declare intent at the moment of deletion. skill_manage(action='delete') now accepts absorbed_into: - absorbed_into='<umbrella>' -> consolidated, target must exist on disk - absorbed_into='' -> explicit prune, no forwarding target - missing -> legacy path, falls through to heuristic/YAML The curator reconciler reads these declarations off llm_meta.tool_calls BEFORE either the YAML block or the substring heuristic. Declaration wins. Fallback logic stays intact for backward compat with any caller (human or older curator conversation) that doesn't populate the arg. Changes - tools/skill_manager_tool.py: add absorbed_into param to skill_manage + _delete_skill. Validate target exists when non-empty. Reject absorbed_into=<self>. Wire through dispatcher + registry + schema. - agent/curator.py: new _extract_absorbed_into_declarations() walks tool calls for skill_manage(delete) with the arg. _reconcile_classification accepts absorbed_declarations= and treats them as authoritative. Curator prompt updated to require the arg on every delete. - Tests: 7 new skill_manager tests covering the tool contract (valid target, empty string, nonexistent target, self-reference, whitespace, backward compat, dispatcher plumbing). 11 new curator tests covering the extractor + authoritative reconciler path + mixed-legacy-and- declared runs. Validation - 307/307 targeted tests pass (curator + cron + skill_manager suites). - E2E #18671 repro: 3 narrow skills, 1 umbrella, cron job referencing all 3. Model emits NO YAML block. Heuristic misses (patch prose doesn't name old slugs). Delete calls carry absorbed_into. Result: both PR skills correctly classified 'consolidated' + cron rewritten ['pr-review-format', 'pr-review-checklist', 'stale-junk'] -> ['hermes-agent-dev']; stale-junk pruned via absorbed_into=''. - E2E backward-compat: delete without absorbed_into, model emits YAML -> routed via existing 'model' source, cron still rewritten correctly. * feat(curator): capture + restore cron skill links across snapshot/rollback Before this, rolling back a curator run restored the skills tree but cron jobs still pointed at the umbrella skills the curator had rewritten them to. The user would see their old narrow skills back on disk but their cron jobs still configured with the merged umbrella — not actually 'back to how it was'. Snapshot side: snapshot_skills() now captures ~/.hermes/cron/jobs.json alongside the skills tarball, as cron-jobs.json. The manifest gets a new 'cron_jobs' block with {backed_up, jobs_count} so rollback (and the CLI confirm dialog) can surface what's in the snapshot. If jobs.json is missing/unreadable/malformed, snapshot proceeds without cron data — the skills backup is the core guarantee; cron is additive. Rollback side: after the skills extract succeeds, the new _restore_cron_skill_links() reconciles the backed-up jobs into the live jobs.json SURGICALLY. Only 'skills' and 'skill' fields are restored, and only on jobs matched by id. Everything else about a cron job — schedule, last_run_at, next_run_at, enabled, prompt, workdir, hooks — is live state the user or scheduler has modified since the snapshot; overwriting it would regress unrelated activity. Reconciliation rules: - Job in backup AND live, skills differ → skills restored. - Job in backup AND live, skills match → no-op. - Job in backup, NOT in live → skipped (user deleted it after snapshot; their choice is later than the snapshot). - Job in live, NOT in backup → untouched (user created it after snapshot). - Snapshot missing cron-jobs.json at all → rollback still succeeds, reports 'not captured' (older pre-feature snapshots keep working). Writes go through cron.jobs.save_jobs under the same _jobs_file_lock the scheduler uses, so rollback doesn't race tick(). Also: - hermes_cli/curator.py: rollback confirm dialog now shows 'cron jobs: N (will be restored for skill-link fields only)' when the snapshot has cron data, or 'not in snapshot (<reason>)' otherwise. - rollback()'s message string includes a 'cron links: ...' clause summarizing the reconciliation outcome. Tests - 9 new cases: snapshot-with-cron, snapshot-without-cron, malformed-json captured-as-raw, full rollback-restores-skills-and-cron, rollback touches only skill fields, rollback skips user-deleted jobs, rollback leaves user-created jobs untouched, rollback still works with pre-feature snapshot that has no cron-jobs.json, standalone unit test on _restore_cron_skill_links exercising the full report shape. Validation - 484/484 targeted tests pass (curator + cron + skill_manager suites). - E2E: real snapshot_skills, real cron rewrite, real rollback. Before: ['pr-review-format', 'pr-review-checklist', 'pr-triage-salvage']. After curator: ['hermes-agent-dev']. After rollback: ['pr-review-format', 'pr-review-checklist', 'pr-triage-salvage']. Non-skill fields (id, name, prompt) preserved across the round trip.
This commit is contained in:
@@ -371,6 +371,57 @@ class TestDeleteSkill:
|
||||
_delete_skill("my-skill")
|
||||
assert not (tmp_path / "devops").exists()
|
||||
|
||||
def test_delete_with_absorbed_into_valid_target(self, tmp_path):
|
||||
with _skill_dir(tmp_path):
|
||||
_create_skill("umbrella", VALID_SKILL_CONTENT)
|
||||
_create_skill("narrow", VALID_SKILL_CONTENT)
|
||||
result = _delete_skill("narrow", absorbed_into="umbrella")
|
||||
assert result["success"] is True
|
||||
assert "absorbed into 'umbrella'" in result["message"]
|
||||
assert not (tmp_path / "narrow").exists()
|
||||
assert (tmp_path / "umbrella").exists()
|
||||
|
||||
def test_delete_with_absorbed_into_empty_string_means_pruned(self, tmp_path):
|
||||
with _skill_dir(tmp_path):
|
||||
_create_skill("stale-skill", VALID_SKILL_CONTENT)
|
||||
result = _delete_skill("stale-skill", absorbed_into="")
|
||||
assert result["success"] is True
|
||||
# Empty absorbed_into is explicit prune — no "absorbed into" suffix in message
|
||||
assert "absorbed into" not in result["message"]
|
||||
|
||||
def test_delete_with_absorbed_into_nonexistent_target_rejected(self, tmp_path):
|
||||
with _skill_dir(tmp_path):
|
||||
_create_skill("narrow", VALID_SKILL_CONTENT)
|
||||
result = _delete_skill("narrow", absorbed_into="ghost-umbrella")
|
||||
assert result["success"] is False
|
||||
assert "does not exist" in result["error"]
|
||||
# Skill must NOT have been deleted on validation failure
|
||||
assert (tmp_path / "narrow").exists()
|
||||
|
||||
def test_delete_with_absorbed_into_equals_self_rejected(self, tmp_path):
|
||||
with _skill_dir(tmp_path):
|
||||
_create_skill("narrow", VALID_SKILL_CONTENT)
|
||||
result = _delete_skill("narrow", absorbed_into="narrow")
|
||||
assert result["success"] is False
|
||||
assert "cannot equal" in result["error"]
|
||||
assert (tmp_path / "narrow").exists()
|
||||
|
||||
def test_delete_with_absorbed_into_whitespace_only_treated_as_prune(self, tmp_path):
|
||||
# Leading/trailing whitespace only: .strip() → "" → pruned path
|
||||
with _skill_dir(tmp_path):
|
||||
_create_skill("narrow", VALID_SKILL_CONTENT)
|
||||
result = _delete_skill("narrow", absorbed_into=" ")
|
||||
assert result["success"] is True
|
||||
assert "absorbed into" not in result["message"]
|
||||
|
||||
def test_delete_without_absorbed_into_backward_compat(self, tmp_path):
|
||||
# Legacy callers that don't pass the arg still work — the curator
|
||||
# reconciler falls back to its heuristic+YAML logic for such deletes.
|
||||
with _skill_dir(tmp_path):
|
||||
_create_skill("my-skill", VALID_SKILL_CONTENT)
|
||||
result = _delete_skill("my-skill")
|
||||
assert result["success"] is True
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# write_file / remove_file
|
||||
@@ -485,6 +536,25 @@ class TestSkillManageDispatcher:
|
||||
result = json.loads(raw)
|
||||
assert result["success"] is True
|
||||
|
||||
def test_delete_via_dispatcher_threads_absorbed_into(self, tmp_path):
|
||||
# Dispatcher must plumb absorbed_into through to _delete_skill so the
|
||||
# validation + message suffix paths are exercised end-to-end.
|
||||
with _skill_dir(tmp_path):
|
||||
skill_manage(action="create", name="umbrella", content=VALID_SKILL_CONTENT)
|
||||
skill_manage(action="create", name="narrow", content=VALID_SKILL_CONTENT)
|
||||
raw = skill_manage(action="delete", name="narrow", absorbed_into="umbrella")
|
||||
result = json.loads(raw)
|
||||
assert result["success"] is True
|
||||
assert "absorbed into 'umbrella'" in result["message"]
|
||||
|
||||
def test_delete_via_dispatcher_rejects_missing_absorbed_target(self, tmp_path):
|
||||
with _skill_dir(tmp_path):
|
||||
skill_manage(action="create", name="narrow", content=VALID_SKILL_CONTENT)
|
||||
raw = skill_manage(action="delete", name="narrow", absorbed_into="ghost")
|
||||
result = json.loads(raw)
|
||||
assert result["success"] is False
|
||||
assert "does not exist" in result["error"]
|
||||
|
||||
|
||||
class TestSecurityScanGate:
|
||||
"""_security_scan_skill is gated by skills.guard_agent_created config flag."""
|
||||
|
||||
Reference in New Issue
Block a user