The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(update): record every autostash disposition in the update receipt
Konstantin Khlopkovecd054539c34
diff --git a/hermes_cli/update_cmd_stash.py b/hermes_cli/update_cmd_stash.pyindex 87614fe3014..1c5b2841cf2 100644--- a/hermes_cli/update_cmd_stash.py+++ b/hermes_cli/update_cmd_stash.py@@ -181,6 +181,18 @@ def _warn_orphaned_update_autostashes(git_cmd: list[str], cwd: Path) -> int:return 0+def _record_stash_disposition(outcome: str, stash_ref: str, detail: str = "") -> None:+ """Note the autostash disposition in the update receipt so a parked stash is visible+ to automation reading receipts instead of stdout (#115363: an update that ended with+ local changes parked in the stash reported a bare success with no trace of them)."""+ from hermes_cli.update_receipt import record_step+ record_step(+ "local_changes_stash",+ outcome != "parked",+ f"{outcome}: {stash_ref}" + (f" ({detail})" if detail else ""),+ )++def _print_stash_cleanup_guidance(stash_ref: str, stash_selector: Optional[str] = None) -> None:print(" Check `git status` first so you don't accidentally reapply the same change twice.")print(" Find the saved entry with: git stash list --format='%gd %H %s'")@@ -213,6 +225,7 @@ def _park_stashed_changes(stash_ref: str) -> None:print("ℹ️ Local changes were stashed before updating and were NOT re-applied (--keep-stash).")print(f" Stash ref: {stash_ref}")print(f" Restore manually with: git stash apply {stash_ref}")+ _record_stash_disposition("parked", stash_ref, "--keep-stash")def _git_untracked_paths(git_cmd: list[str], cwd: Path) -> set[str] | None:@@ -323,6 +336,7 @@ def _apply_stash(git_cmd: list[str], cwd: Path, stash_ref: str) -> bool:_reset_hard(git_cmd, cwd) # conflict markers make hermes unrunnable; changes stay in the stashprint("Working tree reset to clean state.")print(f"Restore your changes later with: git stash apply {stash_ref}")+ _record_stash_disposition("parked", stash_ref, "restore hit conflicts")return False # code update succeeded; cmd_update continues (deps, skills, gateway)@@ -350,15 +364,17 @@ def _restore_stashed_changes(_critical_module_import_failures, _git_untracked_paths, _restored_python_paths, _validate_python_files_syntax,)if prompt_user and not _confirm_restore(stash_ref, input_fn):+ _record_stash_disposition("parked", stash_ref, "restore declined")return Falsepreexisting_untracked = _git_untracked_paths(git_cmd, cwd)if preexisting_untracked is None:print(" The stash was not restored because its cleanup baseline is unknown.")print(f" Restore manually with: git stash apply {stash_ref}")+ _record_stash_disposition("parked", stash_ref, "untracked baseline unknown")return Falseclean_import_failures = _critical_module_import_failures(cwd, report_runtime_errors=True)if not _apply_stash(git_cmd, cwd, stash_ref):- return False+ return False # disposition already recorded inside _apply_stashdef reject(failing_target: str, detail) -> None:_reject_unsafe_stash_restore(git_cmd, cwd, stash_ref, preexisting_untracked, failing_target, detail)@@ -374,6 +390,7 @@ def _restore_stashed_changes(reject(f"agent import {module or 'unknown'}", error[1])break_drop_restored_stash(git_cmd, cwd, stash_ref)+ _record_stash_disposition("restored", stash_ref)print("⚠ Local changes were restored on top of the updated codebase.")print(" Review `git diff` / `git status` if Hermes behaves unexpectedly.")return True@@ -399,6 +416,8 @@ def _discard_stashed_changes(git_cmd: list[str], cwd: Path, stash_ref: str) -> bprint("⚠ Configured to discard local changes, but Hermes couldn't drop the saved stash entry.")_print_first_line(drop.stderr)_print_stash_cleanup_guidance(stash_ref, stash_selector)+ _record_stash_disposition("parked", stash_ref, "configured discard failed")return Falseprint("→ Discarded local source changes (updates.non_interactive_local_changes=discard).")+ _record_stash_disposition("discarded", stash_ref)return Truediff --git a/tests/hermes_cli/test_update_autostash.py b/tests/hermes_cli/test_update_autostash.pyindex 1ab59e69a3f..8d48a6d12df 100644--- a/tests/hermes_cli/test_update_autostash.py+++ b/tests/hermes_cli/test_update_autostash.py@@ -1274,3 +1274,113 @@ def test_prune_orphan_rescue_refs_with_real_git_unpins_objects(tmp_path):# And gc can now reclaim the snapshot's objects.git("gc", "-q", "--prune=now")assert git("cat-file", "-e", snap_sha, check=False).returncode != 0+++# ---------------------------------------------------------------------------+# Autostash disposition must be visible in the update receipt (#115363): an+# unattended update whose restore hits conflicts parks the stash and reports+# success — the receipt is the only channel an operator reads.+# ---------------------------------------------------------------------------+++class _ReceiptProbe:+ """Minimal stand-in for the active update receipt: records steps."""++ def __init__(self):+ self.steps = []++ def step(self, name, ok, detail=""):+ self.steps.append({"name": name, "ok": ok, "detail": detail})+++def test_conflicted_restore_records_parked_step_in_receipt(monkeypatch, tmp_path):+ import subprocess+ from hermes_cli import update_receipt++ def git(*args, check=True):+ return subprocess.run(["git", *args], cwd=tmp_path, capture_output=True, text=True, check=check)++ git("init", "-q", "-b", "main")+ git("config", "user.email", "[email protected]")+ git("config", "user.name", "t")+ source = tmp_path / "tools" / "terminal_tool.py"+ source.parent.mkdir()+ source.write_text("VALUE = 1\n", encoding="utf-8")+ git("add", "-A")+ git("commit", "-qm", "init")++ # Local edit whose restore will conflict with the pulled change.+ source.write_text("VALUE = 2\n", encoding="utf-8")+ stash_ref = hermes_main._stash_local_changes_if_needed(["git"], tmp_path)+ assert stash_ref+ # Simulate the pull moving the same lines: the stash apply now conflicts.+ git("checkout", "HEAD")+ source.write_text("VALUE = 3\n", encoding="utf-8")+ git("add", "-A")+ git("commit", "-qm", "pulled change")++ probe = _ReceiptProbe()+ monkeypatch.setattr(update_receipt, "_current", probe, raising=False)++ restored = hermes_main._restore_stashed_changes(["git"], tmp_path, stash_ref, prompt_user=False)++ assert restored is False+ disposition = [s for s in probe.steps if s["name"] == "local_changes_stash"]+ assert len(disposition) == 1+ assert disposition[0]["ok"] is False+ assert "parked" in disposition[0]["detail"]+ assert stash_ref in disposition[0]["detail"]+ assert git("stash", "list").stdout.strip(), "stash must survive for manual recovery"+++def test_clean_restore_records_restored_step_in_receipt(monkeypatch, tmp_path):+ import subprocess+ from hermes_cli import update_receipt++ def git(*args, check=True):+ return subprocess.run(["git", *args], cwd=tmp_path, capture_output=True, text=True, check=check)++ git("init", "-q", "-b", "main")+ git("config", "user.email", "[email protected]")+ git("config", "user.name", "t")+ source = tmp_path / "tools" / "terminal_tool.py"+ source.parent.mkdir()+ source.write_text("VALUE = 1\n", encoding="utf-8")+ git("add", "-A")+ git("commit", "-qm", "init")++ source.write_text("VALUE = 2\n", encoding="utf-8")+ stash_ref = hermes_main._stash_local_changes_if_needed(["git"], tmp_path)+ assert stash_ref++ probe = _ReceiptProbe()+ monkeypatch.setattr(update_receipt, "_current", probe, raising=False)++ restored = hermes_main._restore_stashed_changes(["git"], tmp_path, stash_ref, prompt_user=False)++ assert restored is True+ disposition = [s for s in probe.steps if s["name"] == "local_changes_stash"]+ assert len(disposition) == 1+ assert disposition[0]["ok"] is True+ assert "restored" in disposition[0]["detail"]+ assert stash_ref in disposition[0]["detail"]+++def test_keep_stash_park_records_parked_step_in_receipt(capsys):+ probe = _ReceiptProbe()+ import hermes_cli.update_cmd_stash as stash_mod+ from hermes_cli import update_receipt++ original = update_receipt._current+ update_receipt._current = probe+ try:+ stash_mod._park_stashed_changes("deadbeefcafe")+ finally:+ update_receipt._current = original++ out = capsys.readouterr().out+ assert "--keep-stash" in out+ disposition = [s for s in probe.steps if s["name"] == "local_changes_stash"]+ assert len(disposition) == 1+ assert disposition[0]["ok"] is False+ assert "parked" in disposition[0]["detail"]