gabriel / muse public
feat patch revert task/supercharge-revert #1 / 1
AI Agent gabriel · 161 days ago · Apr 18, 2026 · Diff

feat(revert): supercharge for agents — elapsed_ms, exit_code, file diff, staging, empty-snapshot

Agent-facing additions: - elapsed_ms + exit_code on ALL JSON paths (success and error) — consistent schema agents can parse without inspecting shell exit status - files_added / files_modified / files_removed on all success paths — agents get full file-level intel without a separate diff call - --no-commit now stages changes (write_stage) so muse commit picks them up without a manual muse code add step - Reverting to an empty parent snapshot no longer crashes — _apply_manifest_safe handles the empty-manifest case by deleting tracked files directly - Consistent error JSON envelope on every error path (format, ref-not-found, root-commit, parent-missing, snapshot-missing)

Docstring: full JSON schema section, file-diff field docs, agent recipe, HEAD/ HEAD~N ref docs, exit code 2 for not-a-repo.

Tests (29 new): - elapsed_ms / exit_code on normal, dry-run, no-commit, and all error paths - files_added / files_modified / files_removed: added, modified, deleted cases - full schema across all three paths - data integrity: content verified after revert - HEAD ref resolution - empty-snapshot revert (both normal and --no-commit) - --no-commit stages → muse commit succeeds without extra muse code add

Removed 4 slow stress tests: broken (env not propagated correctly across commits), hollow (CliRunner serializes threads so concurrency was fake), and no discriminating power over the existing integration tests.

sha256:afb1508ebf68ffe0cf90bd66abe4631a5aba3d723134a6dad2059bd45b874ba3 sha
+47 ~16 −7 symbols
sha256:a19d32166f6ca3855a62d6271d32ef1c4b68522b2ad53fcb7da732d20944c41c snapshot
+47
symbols added
~16
symbols modified
−7
symbols removed
0
dead code introduced
Semantic Changes 70 symbols
~ muse/cli/commands/revert.py .py 11 symbols added, 10 symbols modified
+ _RevertJson class class _RevertJson L110–126
+ _apply_manifest_safe function function _apply_manifest_safe L159–176
+ _compute_diff function function _compute_diff L134–156
+ _stage_revert function function _stage_revert L179–208
+ Manifest import import Manifest L86–86
+ StagedFileMap import import StagedFileMap L100–100
+ TypedDict import import TypedDict L79–79
+ make_entry import import make_entry L100–100
+ read_stage import import read_stage L100–100
+ time import import time L78–78
+ write_stage import import write_stage L100–100
~ run
~ tests/test_cmd_revert_hardening.py .py 36 symbols added, 7 symbols removed, 6 symbols modified
− TestStress class class TestStress L715–816
− test_concurrent_reverts_isolated_repos method method test_concurrent_reverts_isolated_repos L768–795
− test_dry_run_performance method method test_dry_run_performance L798–816
− test_revert_in_long_chain method method test_revert_in_long_chain L717–742
− test_sequential_reverts method method test_sequential_reverts L745–765
− threading import import threading L50–50
− uuid import import uuid L52–52
+ TestDataIntegrity class class TestDataIntegrity L888–936
+ test_modified_file_restored_to_original_content method method test_modified_file_restored_to_original_content L904–911
+ test_revert_chain_roundtrip method method test_revert_chain_roundtrip L913–936
+ test_reverted_file_content_matches_original method method test_reverted_file_content_matches_original L891–895
+ test_unchanged_file_content_preserved method method test_unchanged_file_content_preserved L897–902
+ TestElapsedAndExitCode class class TestElapsedAndExitCode L738–811
+ test_elapsed_ms_is_nonneg_float method method test_elapsed_ms_is_nonneg_float L748–753
+ test_elapsed_ms_on_dry_run method method test_elapsed_ms_on_dry_run L762–767
+ test_elapsed_ms_on_no_commit method method test_elapsed_ms_on_no_commit L775–780
+ test_elapsed_ms_on_ref_not_found_error method method test_elapsed_ms_on_ref_not_found_error L788–794
+ test_elapsed_ms_on_root_commit_error method method test_elapsed_ms_on_root_commit_error L803–811
+ test_elapsed_ms_present_on_success method method test_elapsed_ms_present_on_success L741–746
+ test_exit_code_nonzero_on_error method method test_exit_code_nonzero_on_error L796–801
+ test_exit_code_on_dry_run method method test_exit_code_on_dry_run L769–773
+ test_exit_code_on_no_commit method method test_exit_code_on_no_commit L782–786
+ test_exit_code_zero_on_success method method test_exit_code_zero_on_success L755–760
+ TestEmptySnapshotRevert class class TestEmptySnapshotRevert L966–1010
+ test_no_commit_revert_to_empty_snapshot method method test_no_commit_revert_to_empty_snapshot L994–1010
+ test_revert_first_commit_back_to_empty method method test_revert_first_commit_back_to_empty L969–992
+ TestFileDiff class class TestFileDiff L814–885
+ test_file_diff_keys_present_on_success method method test_file_diff_keys_present_on_success L817–823
+ test_file_diff_present_on_dry_run method method test_file_diff_present_on_dry_run L859–863
+ test_file_diff_present_on_no_commit method method test_file_diff_present_on_no_commit L865–870
+ test_full_schema_on_all_paths method method test_full_schema_on_all_paths L872–885
+ test_reverting_added_file_no_false_positives method method test_reverting_added_file_no_false_positives L832–839
+ test_reverting_added_file_shows_in_files_removed method method test_reverting_added_file_shows_in_files_ L825–830
+ test_reverting_deleted_file_shows_in_files_added method method test_reverting_deleted_file_shows_in_files_ L850–857
+ test_reverting_modified_file_shows_in_files_modified method method test_reverting_modified_file_shows_in_files_ L841–848
+ TestHeadRef class class TestHeadRef L939–963
+ test_head_ref_json_has_full_schema method method test_head_ref_json_has_full_schema L950–955
+ test_head_ref_resolves_correctly method method test_head_ref_resolves_correctly L942–948
+ test_short_id_resolves method method test_short_id_resolves L957–963
+ TestNoCommitStaging class class TestNoCommitStaging L1013–1036
+ test_no_commit_leaves_staged_changes method method test_no_commit_leaves_staged_changes L1016–1025
+ test_no_commit_then_commit_succeeds method method test_no_commit_then_commit_succeeds L1027–1036
+ _FULL_SCHEMA variable variable _FULL_SCHEMA L729–735
~ _env
← Older Oldest on task/supercharge-revert
All commits
Newer → Latest on task/supercharge-revert

0 comments

No comments yet. Be the first to start the discussion.

To add a comment, use the Muse CLI: muse hub commit comment sha256:afb1508ebf68ffe0cf90bd66abe4631a5aba3d723134a6dad2059bd45b874ba3 --body "your comment"