Skip to main content

Work Wiki Diff System

Track every file change before commits for time-travel debugging.
╔═════════════════════════════════════════════════════════════════════╗
║                    WORK WIKI DIFF OVERVIEW                           ║
╠═════════════════════════════════════════════════════════════════════╣
║                                                                      ║
║   File Saved                                                         ║
║        │                                                             ║
║        ▼                                                             ║
║   ┌───────────────────────┐                                          ║
║   │ Git Diff Calculator   │  Uses Rust git2 library                  ║
║   │ (Native Rust)         │  No shell commands                       ║
║   └───────────────────────┘                                          ║
║        │                                                             ║
║        │ Calculate diff against HEAD                                 ║
║        ▼                                                             ║
║   ┌───────────────────────┐                                          ║
║   │ Deduplication Check   │  Skip if same diff already stored        ║
║   └───────────────────────┘                                          ║
║        │                                                             ║
║        ▼                                                             ║
║   ┌───────────────────────┐                                          ║
║   │ work-wiki-diff.db     │  Store diff history                      ║
║   └───────────────────────┘                                          ║
║        │                                                             ║
║        ▼                                                             ║
║   ┌───────────────────────┐                                          ║
║   │ Timeline Viewer       │  Visual diff history UI                  ║
║   └───────────────────────┘                                          ║
║                                                                      ║
╚═════════════════════════════════════════════════════════════════════╝

How It Works

Every file save triggers diff capture.
╔═════════════════════════════════════════════════════════════════════╗
║                      DIFF CAPTURE FLOW                               ║
╠═════════════════════════════════════════════════════════════════════╣
║                                                                      ║
║   You Save a File                                                    ║
║        │                                                             ║
║        ▼                                                             ║
║   ┌───────────────────────────────────────────────────────────────┐  ║
║   │  1. Find Git Repository                                       │  ║
║   │     git2::Repository::discover()                              │  ║
║   │     Walks up directory tree to find .git                      │  ║
║   └───────────────────────────────────────────────────────────────┘  ║
║        │                                                             ║
║        ▼                                                             ║
║   ┌───────────────────────────────────────────────────────────────┐  ║
║   │  2. Calculate Diff                                            │  ║
║   │     Compare: HEAD commit vs working tree                      │  ║
║   │     Extract: added lines, deleted lines, diff content         │  ║
║   └───────────────────────────────────────────────────────────────┘  ║
║        │                                                             ║
║        ▼                                                             ║
║   ┌───────────────────────────────────────────────────────────────┐  ║
║   │  3. Check for Duplicates                                      │  ║
║   │     If same diff content exists: SKIP                         │  ║
║   │     If new diff: SAVE                                         │  ║
║   └───────────────────────────────────────────────────────────────┘  ║
║        │                                                             ║
║        ▼                                                             ║
║   ┌───────────────────────────────────────────────────────────────┐  ║
║   │  4. Store in Database                                         │  ║
║   │     - File path                                               │  ║
║   │     - Timestamp                                               │  ║
║   │     - Git HEAD hash                                           │  ║
║   │     - Diff content                                            │  ║
║   │     - Lines added/deleted                                     │  ║
║   └───────────────────────────────────────────────────────────────┘  ║
║                                                                      ║
╚═════════════════════════════════════════════════════════════════════╝

Timeline Viewer

Visual history of all changes to a file.
╔═════════════════════════════════════════════════════════════════════╗
║                    TIMELINE VIEWER UI                                ║
╠═════════════════════════════════════════════════════════════════════╣
║                                                                      ║
║   ┌──────────────────┬───────────────────────────────────────────┐   ║
║   │    TIMELINE      │           DIFF PANEL                      │   ║
║   │                  │                                           │   ║
║   │   [*] +5 -2      │   @@ -1,5 +1,6 @@                         │   ║
║   │   │   3m ago     │    context line                           │   ║
║   │   │   HEAD:ab12  │   -removed line                           │   ║
║   │   │   [Restore]  │   +added line                             │   ║
║   │   │              │    context line                           │   ║
║   │   │              │                                           │   ║
║   │   [ ] +3 -0      │                                           │   ║
║   │   │   1h ago     │                                           │   ║
║   │   │   HEAD:cd34  │                                           │   ║
║   │   │   [Restore]  │                                           │   ║
║   │   │              │                                           │   ║
║   │   [ ] +10 -5     │                                           │   ║
║   │       2h ago     │                                           │   ║
║   │                  │                                           │   ║
║   └──────────────────┴───────────────────────────────────────────┘   ║
║                                                                      ║
║   Click any point to view that diff                                  ║
║   Click [Restore] to revert file to that state                       ║
║                                                                      ║
╚═════════════════════════════════════════════════════════════════════╝

Restore Flow

Revert a file to any previous state.
╔═════════════════════════════════════════════════════════════════════╗
║                       RESTORE FLOW                                   ║
╠═════════════════════════════════════════════════════════════════════╣
║                                                                      ║
║   User Clicks [Restore]                                              ║
║        │                                                             ║
║        ▼                                                             ║
║   ┌───────────────────────────────────────────────────────────────┐  ║
║   │  Confirmation Dialog                                          │  ║
║   │  "Restore file.rs to state from 2 hours ago?"                 │  ║
║   └───────────────────────────────────────────────────────────────┘  ║
║        │                                                             ║
║        │ User confirms                                               ║
║        ▼                                                             ║
║   ┌───────────────────────────────────────────────────────────────┐  ║
║   │  Parse Diff Content                                           │  ║
║   │  - Identify hunk headers (@@ -1,5 +1,6 @@)                    │  ║
║   │  - Find added lines (+)                                       │  ║
║   │  - Find removed lines (-)                                     │  ║
║   └───────────────────────────────────────────────────────────────┘  ║
║        │                                                             ║
║        ▼                                                             ║
║   ┌───────────────────────────────────────────────────────────────┐  ║
║   │  Reverse Apply                                                │  ║
║   │  - Remove lines that were added (+)                           │  ║
║   │  - Add back lines that were removed (-)                       │  ║
║   └───────────────────────────────────────────────────────────────┘  ║
║        │                                                             ║
║        ▼                                                             ║
║   ┌───────────────────────────────────────────────────────────────┐  ║
║   │  Write New Content                                            │  ║
║   │  Save restored file to disk                                   │  ║
║   └───────────────────────────────────────────────────────────────┘  ║
║        │                                                             ║
║        ▼                                                             ║
║   ┌───────────────────────────────────────────────────────────────┐  ║
║   │  Record New History                                           │  ║
║   │  The restore itself is tracked as a new change                │  ║
║   └───────────────────────────────────────────────────────────────┘  ║
║                                                                      ║
╚═════════════════════════════════════════════════════════════════════╝

Key Features

╔═════════════════════════════════════════════════════════════════════╗
║                       KEY FEATURES                                   ║
╠═════════════════════════════════════════════════════════════════════╣
║                                                                      ║
║   TIME-TRAVEL DEBUGGING                                              ║
║   ┌───────────────────────────────────────────────────────────────┐  ║
║   │ "What did this file look like 2 hours ago?"                   │  ║
║   │                                                               │  ║
║   │  - Browse file history by timestamp                           │  ║
║   │  - View exact diff at any point                               │  ║
║   │  - Restore to any previous state                              │  ║
║   └───────────────────────────────────────────────────────────────┘  ║
║                                                                      ║
║   PRE-COMMIT REVIEW                                                  ║
║   ┌───────────────────────────────────────────────────────────────┐  ║
║   │ "What changes will this commit include?"                      │  ║
║   │                                                               │  ║
║   │  - See all uncommitted changes                                │  ║
║   │  - Review before committing                                   │  ║
║   │  - Spot unintended modifications                              │  ║
║   └───────────────────────────────────────────────────────────────┘  ║
║                                                                      ║
║   AUTOMATIC CLEANUP                                                  ║
║   ┌───────────────────────────────────────────────────────────────┐  ║
║   │ Retention Policy: 30 days (configurable)                      │  ║
║   │                                                               │  ║
║   │  - Old diffs automatically deleted                            │  ║
║   │  - Keeps database size manageable                             │  ║
║   │  - Large files (>1MB) skip diff content storage               │  ║
║   └───────────────────────────────────────────────────────────────┘  ║
║                                                                      ║
╚═════════════════════════════════════════════════════════════════════╝

Native Rust Implementation

Why we use Rust git2 instead of shell commands.
╔═════════════════════════════════════════════════════════════════════╗
║                   NATIVE RUST BENEFITS                               ║
╠═════════════════════════════════════════════════════════════════════╣
║                                                                      ║
║   TRADITIONAL APPROACH (Shell)          OUR APPROACH (Rust git2)     ║
║   ═══════════════════════════          ══════════════════════════    ║
║                                                                      ║
║   subprocess spawn                      direct library call          ║
║        │                                     │                       ║
║        ▼                                     ▼                       ║
║   shell escaping needed                 no escaping needed           ║
║        │                                     │                       ║
║        ▼                                     ▼                       ║
║   parse text output                     structured data              ║
║        │                                     │                       ║
║        ▼                                     ▼                       ║
║   slower (~100ms)                       faster (~10ms)               ║
║                                                                      ║
║   ┌───────────────────────────────────────────────────────────────┐  ║
║   │  RESULT: ~10x faster diff calculation                         │  ║
║   │          No shell injection risks                             │  ║
║   │          Better error handling                                │  ║
║   └───────────────────────────────────────────────────────────────┘  ║
║                                                                      ║
╚═════════════════════════════════════════════════════════════════════╝

Design Principles Applied

╔═════════════════════════════════════════════════════════════════════╗
║                     DESIGN PRINCIPLES                                ║
╠═════════════════════════════════════════════════════════════════════╣
║                                                                      ║
║   SIMPLICITY (SMPC)                                                  ║
║   ┌───────────────────────────────────────────────────────────────┐  ║
║   │ [x] Single Rust module handles all diff operations            │  ║
║   │ [x] Native git2 (no external process spawning)                │  ║
║   │ [x] Automatic deduplication (skip identical diffs)            │  ║
║   └───────────────────────────────────────────────────────────────┘  ║
║                                                                      ║
║   ORDER FROM CHAOS (OFAC)                                            ║
║   ┌───────────────────────────────────────────────────────────────┐  ║
║   │ [x] Restore any point-in-time file state                      │  ║
║   │ [x] HEAD hash tracks commit context                           │  ║
║   │ [x] Auto-cleanup via retention_days setting                   │  ║
║   └───────────────────────────────────────────────────────────────┘  ║
║                                                                      ║
╚═════════════════════════════════════════════════════════════════════╝

Configuration

SettingDefaultDescription
retention_days30Days to keep diffs before cleanup
max_file_size1MBFiles larger than this skip content storage
enabledtrueEnable/disable diff capture