The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(curator): keep bundled skills out of the LLM consolidation list
zengzheqing061f37d85476
diff --git a/agent/curator.py b/agent/curator.pyindex 1a0ce2b6793..f46e16eed33 100644--- a/agent/curator.py+++ b/agent/curator.py@@ -120,11 +120,6 @@ def get_archive_after_days() -> int:return _config_number("archive_after_days", DEFAULT_ARCHIVE_AFTER_DAYS, int)-def get_prune_builtins() -> bool:- """Bundled built-ins are curation candidates (ON by default); a suppression list keeps them archived across `hermes update` re-seeds. Hub skills are never pruned."""- return bool(_load_config().get("prune_builtins", True))--def get_consolidate() -> bool:"""LLM consolidation pass — OFF by default (prune only, no aux-model fork); ``hermes curator run --consolidate`` overrides per invocation."""return bool(_load_config().get("consolidate", DEFAULT_CONSOLIDATE))@@ -441,17 +436,6 @@ CURATOR_REVIEW_PROMPT = ()-CURATOR_PRUNE_BUILTINS_NOTE = (- "\n\nPRUNE-BUILTINS MODE IS ON: bundled built-in skills "- "ARE included in the candidate list below and MAY be "- "archived for staleness/irrelevance, overriding hard "- "rule #1 for bundled skills ONLY. Hub-installed skills "- "remain strictly off-limits. Treat a stale built-in the "- "same as a stale agent-created skill: archive it (never "- "delete). It will be restored on `hermes update` only if "- "the user explicitly restores it."-)-# --- Per-run reports — {YYYYMMDD-HHMMSS}/run.json + REPORT.md under logs/curator/ ---def _reports_root() -> Path:@@ -814,12 +798,23 @@ def _render_report_markdown(p: Dict[str, Any]) -> str:# --- Orchestrator — spawn a forked AIAgent for the LLM review pass ---def _render_candidate_list() -> str:- """Human/agent-readable list of curator-managed skills with usage stats."""- rows = skill_usage.curated_report()+ """Human/agent-readable list of LLM consolidation candidates.++ Bundled built-ins are excluded even when ``curator.prune_builtins`` is+ on. 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.+ """+ rows = [+ r for r in skill_usage.curated_report()+ if not skill_usage.is_bundled(r["name"])+ ]if not rows:- return "No curator-managed skills to review."+ return "No agent-created skills to review."cron_referenced = _cron_referenced_skills()- return "\n".join([f"Curator-managed skills ({len(rows)}):\n"] + [+ return "\n".join([f"Agent-created skills ({len(rows)}):\n"] + [f"- {r['name']} provenance={r.get('provenance', 'agent')} state={r['state']} "f"pinned={'yes' if r.get('pinned') else 'no'} cron={'yes' if r['name'] in cron_referenced else 'no'} "f"activity={r.get('activity_count', 0)} use={r.get('use_count', 0)} view={r.get('view_count', 0)} "@@ -854,8 +849,11 @@ def _consolidation_pass(prefix: str, auto_summary: str, dry_run: bool, before_nafinal_summary = f"{prefix}{auto_summary}; llm: skipped (no candidates)"llm_meta = _llm_meta("skipped (no candidates)")else:- # With prune-builtins on, bundled skills are candidates too: relax hard rule #1 for them (archive only; hub stays off-limits).- prompt = f"{CURATOR_REVIEW_PROMPT}{CURATOR_PRUNE_BUILTINS_NOTE if get_prune_builtins() else ''}\n\n{candidate_list}"+ # Bundled built-ins are not in the candidate list, even under+ # prune_builtins: archival is the deterministic pass's job, and+ # the bundled policy is archive-only. Hard rule #1 therefore+ # stands unqualified.+ prompt = f"{CURATOR_REVIEW_PROMPT}\n\n{candidate_list}"if dry_run:prompt = f"{CURATOR_DRY_RUN_BANNER}\n\n{prompt}"llm_meta = _run_llm_review(prompt)diff --git a/tests/agent/test_curator.py b/tests/agent/test_curator.pyindex 95bf7d29c40..3b008a5d11b 100644--- a/tests/agent/test_curator.py+++ b/tests/agent/test_curator.py@@ -320,6 +320,97 @@ def _disable_prune_builtins(curator_env, monkeypatch):monkeypatch.setattr(u, "_prune_builtins_enabled", lambda: False)+def _write_bundled_and_agent(curator_env, u):+ """One bundled built-in + one agent-created skill under the test home."""+ skills_dir = curator_env["home"] / "skills"+ _write_skill(skills_dir, "bundled-fixture")+ _write_skill(skills_dir, "agent-fixture")+ (skills_dir / ".bundled_manifest").write_text(+ "bundled-fixture:deadbeef\n", encoding="utf-8",+ )+ u.mark_agent_created("agent-fixture")+ return skills_dir+++def test_llm_candidate_list_omits_bundled_when_prune_builtins_on(+ curator_env, monkeypatch,+):+ """prune_builtins makes built-ins archive-eligible, not LLM rewrite targets.++ ``curated_report()`` includes bundled skills when the flag is on so the+ deterministic walk can archive them. The consolidation prompt must not+ list those same names: every background ``skill_manage`` write to a+ bundled skill is refused, and enough refusals abort the rest of the pass.+ """+ c = curator_env["curator"]+ u = curator_env["usage"]+ _write_bundled_and_agent(curator_env, u)+ _enable_prune_builtins(curator_env, monkeypatch)++ listing = c._render_candidate_list()+ assert "agent-fixture" in listing+ assert "bundled-fixture" not in listing+++def test_llm_prompt_does_not_invite_bundled_writes_when_prune_builtins_on(+ curator_env, monkeypatch,+):+ """The delivered review prompt must not override hard rule #1.++ ``PRUNE-BUILTINS MODE IS ON`` used to tell the model bundled skills were+ in the candidate list and may be archived by the LLM. Archival is the+ deterministic pass's job; the LLM pass must not be asked to mutate them.+ """+ c = curator_env["curator"]+ u = curator_env["usage"]+ _write_bundled_and_agent(curator_env, u)+ _enable_prune_builtins(curator_env, monkeypatch)++ captured = {}++ def _stub(prompt):+ captured["prompt"] = prompt+ return {"final": "", "summary": "s", "model": "", "provider": "",+ "tool_calls": [], "error": None}++ monkeypatch.setattr(c, "_run_llm_review", _stub)+ c.run_curator_review(synchronous=True, consolidate=True, dry_run=True)++ prompt = captured["prompt"]+ assert "agent-fixture" in prompt+ assert "bundled-fixture" not in prompt+ assert "PRUNE-BUILTINS MODE IS ON" not in prompt+++def test_prune_builtins_still_archives_bundled_via_deterministic_pass(+ curator_env, monkeypatch,+):+ """Flag on: a long-idle bundled skill is archived without the LLM list."""+ c = curator_env["curator"]+ u = curator_env["usage"]+ skills_dir = _write_bundled_and_agent(curator_env, u)+ _enable_prune_builtins(curator_env, monkeypatch)++ super_old = (datetime.now(timezone.utc) - timedelta(days=200)).isoformat()+ data = u.load_usage()+ data["bundled-fixture"] = u._empty_record()+ data["bundled-fixture"]["last_used_at"] = super_old+ data["bundled-fixture"]["created_at"] = super_old+ data["bundled-fixture"]["use_count"] = 1+ u.save_usage(data)++ # Eligible for the deterministic walk...+ names = set(u.list_agent_created_skill_names())+ assert "bundled-fixture" in names+ # ...but not for the LLM rewrite pass.+ assert "bundled-fixture" not in c._render_candidate_list()++ counts = c.apply_automatic_transitions()+ assert counts["archived"] >= 1+ assert not (skills_dir / "bundled-fixture").exists()+ assert "bundled-fixture" in u.read_suppressed_names()++diff --git a/tests/tools/test_skill_manager_tool.py b/tests/tools/test_skill_manager_tool.pyindex 720169fb113..de6b46e596b 100644--- a/tests/tools/test_skill_manager_tool.py+++ b/tests/tools/test_skill_manager_tool.py@@ -613,6 +613,59 @@ class TestSkillManageDispatcher:assert (tmp_path / "bundled" / "SKILL.md").exists()+ def test_background_review_still_refuses_bundled_when_prune_builtins_on(self, tmp_path):+ """curator.prune_builtins is archive-only — it does not unlock writes.++ The flag lets ``apply_automatic_transitions`` archive unused built-ins+ via ``archive_skill()``. The shared write preflight covers patch/edit/+ delete/write_file/remove_file; honouring the flag there would let the+ consolidation pass rewrite upstream-owned skills.++ The read-before-write contract is fully satisfied first (the skill is+ marked as read, exactly as ``skill_view`` would during a normal+ consolidation pass), so any refusal below must come from the bundled+ branch of the write guard itself — not from the weaker "content not+ loaded" layer. A guard that returns early for bundled skills under the+ flag would let this write through, which is exactly what this test+ pins against.+ """+ from tools.skill_manager_tool import mark_background_review_skill_read+ from tools.skill_provenance import (+ BACKGROUND_REVIEW,+ reset_current_write_origin,+ set_current_write_origin,+ )++ token = set_current_write_origin(BACKGROUND_REVIEW)+ try:+ with _skill_dir(tmp_path), \+ patch("tools.skill_usage.is_protected_builtin", return_value=False), \+ patch("tools.skill_usage.is_hub_installed", return_value=False), \+ patch("tools.skill_usage.is_bundled",+ side_effect=lambda skill_name: skill_name == "bundled"), \+ patch("tools.skill_usage._prune_builtins_enabled", return_value=True):+ skill_manage(action="create", name="bundled", content=VALID_SKILL_CONTENT)+ # Normal consolidation flow: the fork reads the skill first.+ mark_background_review_skill_read(tmp_path / "bundled" / "SKILL.md")+ raw = skill_manage(+ action="patch",+ name="bundled",+ old_string="Step 1: Do the thing.",+ new_string="Step 1: Do the new thing.",+ )+ finally:+ reset_current_write_origin(token)++ result = json.loads(raw)+ assert result["success"] is False+ # Must be the bundled-guard refusal ("...for bundled skill '<name>'"),+ # not the read-before-write refusal ("...has not been loaded...").+ assert "for bundled" in result["error"].lower()+ assert "not been loaded" not in result["error"].lower()+ assert "Step 1: Do the thing." in (tmp_path / "bundled" / "SKILL.md").read_text(+ encoding="utf-8",+ )+class TestPatchRecoveryLoop:"""#33064 — the recovery guidance must be FOLLOWABLE, not just well-worded.