Skip to content

feat: add history tracking, undo/redo, and cross-platform trash management#379

Merged
nicholas-fedor merged 3 commits intomainfrom
feat/undo-and-restore
Mar 4, 2026
Merged

feat: add history tracking, undo/redo, and cross-platform trash management#379
nicholas-fedor merged 3 commits intomainfrom
feat/undo-and-restore

Conversation

@nicholas-fedor
Copy link
Owner

@nicholas-fedor nicholas-fedor commented Mar 4, 2026

This PR transforms go-remove from a simple file removal tool into a comprehensive Go binary management utility with full history tracking, undo/redo capabilities, and cross-platform trash support. All removals are now tracked with metadata (module path, version, VCS revision, checksums) and can be restored from trash when needed.

Problem

The existing go-remove tool provided only basic file removal without any safety mechanisms or recovery options. Users had no way to:

  • Track what binaries were removed and when
  • Restore accidentally deleted Go binaries
  • View historical removal records with build metadata
  • Recover binaries with their original module information intact

Solution

Implement a complete history management system with persistent storage, cross-platform trash handling, and an enhanced TUI for browsing and restoring removed binaries. The solution captures build information from Go binaries before removal, stores records in BadgerDB, and moves files to system trash (XDG on Linux, Recycle Bin on Windows) for safe recovery.

Changes

  • feat(buildinfo): Add package to extract Go binary metadata (module path, version, VCS revision, checksums)
  • feat(history): Implement history tracking with undo/redo capability and persistent BadgerDB storage
  • feat(trash): Add cross-platform trash management (XDG for Linux, Recycle Bin for Windows)
  • feat(cli): Enhance TUI with history browser, undo/redo commands, and improved navigation
  • feat(ci): Add macOS and RISC-V support to goreleaser, harden GitHub Actions workflows
  • docs: Add comprehensive CONTRIBUTING.md with development guidelines
  • test: Add extensive unit tests, integration tests, and fuzz testing across all new packages

Summary by CodeRabbit

  • New Features

    • Added undo functionality to restore the most recent deletion
    • Added restore mode to browse and restore from deletion history
    • Introduced persistent deletion history tracking with database storage
    • Enhanced TUI with history viewing and restoration capabilities
    • Added new CLI flags --undo and --restore for command-line workflows
  • Documentation

    • Added comprehensive contributing guidelines
    • Updated README with installation instructions, new features, and usage examples
  • Build

    • Added Makefile with targets for testing, linting, building, and releasing

- Add trash management with platform-specific implementations
- Implement history tracking for operation logging
- Create storage layer for persistent data management
- Add build info extraction for version metadata
- Establish integration testing framework with mocks
- Add Darwin (macOS) and riscv64 architecture support to release builds
- Improve version detection and install command generation from build info
- Refactor collision detection in history manager to use direct filesystem checks
- Extend storage schema with ReinstallCommand for accurate binary restoration
- Fix test instability issues and remove deprecated --version CLI flag
- Refactor getStoragePath() to verify directory writability with fallback chain
- Add isDirWritable() helper to test permissions via temp file creation
- Return errors from getStoragePath() for proper error handling
- Preserve symlinks during directory copying using Lstat instead of Stat
- Exclude darwin/riscv64 from goreleaser builds
@nicholas-fedor nicholas-fedor enabled auto-merge (squash) March 4, 2026 14:47
@coderabbitai
Copy link

coderabbitai bot commented Mar 4, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 01ed4417-5ead-423a-b7f4-b10b2239b393

📥 Commits

Reviewing files that changed from the base of the PR and between 2dafdc4 and d0af68a.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (47)
  • .github/workflows/build.yaml
  • .github/workflows/lint-gh-actions.yaml
  • .github/workflows/lint.yaml
  • .github/workflows/release-prod.yaml
  • .github/workflows/security.yaml
  • .github/workflows/test.yaml
  • .golangci.yaml
  • .goreleaser.yaml
  • .mockery.yaml
  • CONTRIBUTING.md
  • Makefile
  • README.md
  • cmd/root.go
  • cmd/root_test.go
  • go.mod
  • internal/buildinfo/doc.go
  • internal/buildinfo/extractor.go
  • internal/buildinfo/extractor_test.go
  • internal/buildinfo/mocks/Extractor.go
  • internal/cli/cli.go
  • internal/cli/cli_test.go
  • internal/cli/mocks/ProgramRunner.go
  • internal/cli/tui.go
  • internal/cli/tui_fuzz_test.go
  • internal/cli/tui_test.go
  • internal/history/doc.go
  • internal/history/entry.go
  • internal/history/manager.go
  • internal/history/manager_test.go
  • internal/history/mocks/Manager.go
  • internal/storage/keys.go
  • internal/storage/mocks/Storer.go
  • internal/storage/storage.go
  • internal/storage/storage_test.go
  • internal/trash/mocks/Trasher.go
  • internal/trash/trash.go
  • internal/trash/trash_linux.go
  • internal/trash/trash_test.go
  • internal/trash/trash_windows.go
  • license-header.txt
  • testing/integration/buildinfo/buildinfo_integration_test.go
  • testing/integration/cli/cli_integration_test.go
  • testing/integration/fs/fs_integration_test.go
  • testing/integration/history/manager_integration_test.go
  • testing/integration/logger/logger_integration_test.go
  • testing/integration/storage/storage_integration_test.go
  • testing/integration/trash/trash_integration_test.go

Walkthrough

This PR introduces a complete deletion history and restoration system, featuring platform-specific trash handling, persistent storage via Badger database, build-info extraction from Go binaries, and corresponding CLI/TUI integration with undo and restore commands. The changes span workflow configuration, dependency management, multiple new internal subsystems, comprehensive test coverage, and documentation updates.

Changes

Cohort / File(s) Summary
GitHub Actions Workflows
.github/workflows/build.yaml, lint.yaml, test.yaml, lint-gh-actions.yaml, release-prod.yaml, security.yaml
Added persist-credentials: false to checkout steps across multiple workflows; refactored security.yaml to use per-job permissions instead of global; updated environment variable handling in lint-gh-actions.yaml.
Build & Linter Configuration
.golangci.yaml, .goreleaser.yaml, .mockery.yaml
Added variable name exclusion for linting; expanded Go build matrix (Darwin GOOS, riscv64 GOARCH) with updated ignore rules; configured Mockery to include license header boilerplate in generated mocks.
Dependency Management
go.mod, Makefile
Added Badger/v4 and OpenTelemetry indirect dependencies; introduced comprehensive Makefile with targets for lint, test, coverage, build, mocks, release, and utility commands.
Documentation
README.md, CONTRIBUTING.md, license-header.txt
Substantially expanded README with installation, quick-start, feature descriptions, restore workflows, and updated command reference; added detailed CONTRIBUTING guidelines; introduced license header template.
Core History System
internal/history/doc.go, entry.go, manager.go, manager_test.go, mocks/Manager.go
Implemented complete history management layer: Manager interface with record/undo/restore/query operations; HistoryEntry and RestoreResult data structures; comprehensive test suite with mocked dependencies.
Storage Layer
internal/storage/storage.go, keys.go, storage_test.go, mocks/Storer.go
Introduced Badger-based persistent storage: Storer interface with CRUD and list operations, HistoryRecord struct, key generation/parsing utilities, error handling, and extensive test coverage.
Trash Management
internal/trash/trash.go, trash_linux.go, trash_windows.go, trash_test.go, mocks/Trasher.go
Implemented XDG-compliant trash operations: platform-specific implementations for Linux (full XDG support) and Windows (Recycle Bin integration), TrashEntry struct, Trasher interface with move/restore/delete operations, and comprehensive tests.
Build Info Extraction
internal/buildinfo/doc.go, extractor.go, extractor_test.go, mocks/Extractor.go
Added extraction of module metadata from Go binaries: DefaultExtractor with versioning, checksum calculation, platform support detection, reinstallability checks, and testify mocks for interface compliance.
CLI Root Command
cmd/root.go, cmd/root_test.go
Extended root command with undo (-u/--undo) and restore (-r/--restore) flags; added platform-aware storage path resolution; integrated history manager initialization; added comprehensive CLI error variables; includes tests for storage path validation.
CLI & TUI Core
internal/cli/cli.go, cli_test.go, mocks/ProgramRunner.go
Added HistoryManager and RestoreMode to CLI config/dependencies; updated Run to wire history manager into removal and TUI flows; modified RunTUI signature to accept history manager parameter; updated test calls accordingly.
TUI History Integration
internal/cli/tui.go, tui_test.go, tui_fuzz_test.go
Significantly expanded TUI with history mode: added HistoryMsg, log capture setup, polling mechanism, history-aware rendering (viewHistory), restore/undo/delete operations, multi-mode state management, and fuzzing tests for robustness.
Integration Tests
testing/integration/buildinfo/buildinfo_integration_test.go, cli/cli_integration_test.go, fs/fs_integration_test.go, history/manager_integration_test.go, logger/logger_integration_test.go, storage/storage_integration_test.go
Added six comprehensive integration test suites with mocked dependencies, covering full lifecycle workflows, error handling, edge cases, concurrency, and orchestration between components; includes 6000+ lines of test code.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI as Root<br/>Command
    participant HistMgr as History<br/>Manager
    participant Extractor
    participant Trash
    participant Storage
    participant Logger

    User->>CLI: go-remove <binary>
    activate CLI
    CLI->>HistMgr: RecordDeletion(ctx, path)
    activate HistMgr
    HistMgr->>Extractor: Extract(ctx, path)
    activate Extractor
    Extractor-->>HistMgr: BuildInfoData
    deactivate Extractor
    HistMgr->>Extractor: CalculateChecksum(path)
    activate Extractor
    Extractor-->>HistMgr: checksum
    deactivate Extractor
    HistMgr->>Trash: MoveToTrash(ctx, path)
    activate Trash
    Trash-->>HistMgr: trashPath
    deactivate Trash
    HistMgr->>Storage: SaveRecord(ctx, record)
    activate Storage
    Storage-->>HistMgr: success
    deactivate Storage
    HistMgr->>Logger: Log success
    HistMgr-->>CLI: HistoryEntry
    deactivate HistMgr
    CLI->>User: Success message
    deactivate CLI
Loading
sequenceDiagram
    participant User
    participant CLI as Root<br/>Command
    participant TUI
    participant HistMgr as History<br/>Manager
    participant Storage
    participant Trash

    User->>CLI: go-remove --restore
    activate CLI
    CLI->>TUI: RunTUI(..., historyMgr)
    activate TUI
    TUI->>HistMgr: GetHistory(ctx)
    activate HistMgr
    HistMgr->>Storage: ListRecords(ctx)
    activate Storage
    Storage-->>HistMgr: records
    deactivate Storage
    HistMgr-->>TUI: entries
    deactivate HistMgr
    TUI->>User: Display history
    Note over User,TUI: User selects entry
    User->>TUI: Select entry + restore
    activate TUI
    TUI->>HistMgr: Restore(ctx, entryID)
    activate HistMgr
    HistMgr->>Storage: GetRecord(ctx, key)
    activate Storage
    Storage-->>HistMgr: record
    deactivate Storage
    HistMgr->>Trash: RestoreFromTrash(ctx, trashPath)
    activate Trash
    Trash-->>HistMgr: success
    deactivate Trash
    HistMgr->>Storage: UpdateRecord(ctx)
    activate Storage
    Storage-->>HistMgr: success
    deactivate Storage
    HistMgr-->>TUI: RestoreResult
    deactivate HistMgr
    TUI->>User: Restore complete
    deactivate TUI
    deactivate CLI
Loading

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~120 minutes

Possibly related PRs

  • PR #368: Updates logger API (NewLoggerWithCapture, LogCaptureFunc) that is directly integrated into cmd/root.go and TUI with SetCaptureFunc, establishing capture infrastructure for history/UI interaction.
  • PR #365: Migrates Bubble Tea and lipgloss to v2 API, modifying TUI layer (internal/cli/tui.go) and RunTUI signature changes that overlap with history integration in this PR.
✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/undo-and-restore

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@nicholas-fedor nicholas-fedor merged commit 616cc59 into main Mar 4, 2026
9 of 15 checks passed
@nicholas-fedor nicholas-fedor deleted the feat/undo-and-restore branch March 4, 2026 14:49
Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gosec found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant