Skip to content

The agent that grows with you

fix(memory): list approved patches as edits, not overwrites

emozilla9a9fbd6d3a61
diff --git a/hermes_cli/write_approval_commands.py b/hermes_cli/write_approval_commands.py
index 92701022762..a37e44be340 100644
--- a/hermes_cli/write_approval_commands.py
+++ b/hermes_cli/write_approval_commands.py
@@ -76,14 +76,14 @@ def _approve(subsystem: str, rest: list[str], memory_store) -> str:
return f"No pending {subsystem} write with id '{target}'."
targets = [rec]
- applied, failed, overwritten, removed = 0, [], [], []
+ applied, failed, overwritten, patched, removed = 0, [], [], [], []
for rec in targets:
ok, msg, result = _apply_one(subsystem, rec, memory_store)
if ok:
wa.discard_pending(subsystem, rec["id"])
applied += 1
overwritten.extend(f" {rec['id']}: {text}" for text in _changed_entries(result, "replaced"))
- overwritten.extend(f" {rec['id']}: {text}" for text in _changed_entries(result, "patched"))
+ patched.extend(f" {rec['id']}: {text}" for text in _changed_entries(result, "patched"))
removed.extend(f" {rec['id']}: {text}" for text in _changed_entries(result, "removed"))
else:
failed.append(f"{rec['id']}: {msg}")
@@ -94,6 +94,10 @@ def _approve(subsystem: str, rest: list[str], memory_store) -> str:
# is the last person who can notice a clause went missing, so show what was lost.
out.append("Overwrote entire entry (re-add anything you still need):")
out.extend(overwritten)
+ if patched:
+ # A patch keeps the rest of the entry, so show it as it was, not as lost text.
+ out.append("Patched entry (as it was before the edit):")
+ out.extend(patched)
if removed:
out.append("Removed entry (re-add anything you still need):")
out.extend(removed)
diff --git a/tests/tools/test_write_approval.py b/tests/tools/test_write_approval.py
index 3b59de0c8db..dd7c3f1e7da 100644
--- a/tests/tools/test_write_approval.py
+++ b/tests/tools/test_write_approval.py
@@ -172,6 +172,24 @@ def test_handle_approve_surfaces_overwritten_entry(hermes_home):
assert store.memory_entries == ["RULE B: CI is per-head."]
+def test_handle_approve_lists_a_patch_as_the_entry_before_the_edit(hermes_home):
+ """An approved patch keeps the rest of its entry; the approve output called it an
+ overwrite and told the user to re-add text they had deliberately changed."""
+ from hermes_cli.write_approval_commands import handle_pending_subcommand
+ from tools.memory_tool import MemoryStore
+ from tools import write_approval as wa
+ store = MemoryStore(); store.load_from_disk()
+ entry = "RULE A: gate merges. RULE B: ci per HEAD. RULE C: never squash."
+ store.add("memory", entry)
+ wa.stage_write("memory", {"action": "batch", "target": "memory", "operations": [
+ {"action": "patch", "old_text": "ci per HEAD", "content": "CI is per-head", "matched_entry": entry}]},
+ summary="batch", origin="background_review")
+ out = handle_pending_subcommand(wa.MEMORY, ["approve", "all"], memory_store=store)
+ assert "Patched entry (as it was before the edit):" in out and entry in out
+ assert "Overwrote" not in out
+ assert store.memory_entries == ["RULE A: gate merges. RULE B: CI is per-head. RULE C: never squash."]
+
+
_KEPT = "Repo lives in ~/src/app; tests via make test"
_REVIEWED = "Staging DB: pg-staging-2 (old cluster, retiring)"