mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-11-06 05:17:15 +00:00
fix(memory): list approved patches as edits, not overwrites
Approving a staged patch printed its entry under "Overwrote entire entry (re-add anything you still need)". A patch keeps the rest of the entry, so that told the user to restore text they had changed on purpose. Approved patches now get their own section that shows the entry as it was before the edit. Reported by Greptile on #137523.
This commit is contained in:
1 parent
bda0df67d6
commit
9a9fbd6d3a
2 files changed
+24
-2
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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)"
|
||||
|
||||
|
||||
Reference in new issue
Block a user