Shadow Sentinel
Autonomous OS-Level Revision & Backup Daemon with Multi-Tenant Path-Hashing and Loop-Coupling.
Shadow Sentinel monitors directory trees in real-time via the Linux kernel (inotify), captures
atomic .bak revisions and unified diffs (.diff) on every file modification, and provides
instant 1-command restores with immutable revision IDs and loop-coupling safety.
Why This Is a Breakthrough
For thirty years, developers and system administrators have faced an "impossible triangle" when trying to protect their work on Linux:
- Traditional Nightly Backups (Cron, Rsync, Cloud Snapshots): They run once a day (usually at 2:00 AM). If you, a script, or an AI agent overwrite a critical configuration at 3:30 PM, up to 13 hours of uncommitted work vanish forever.
- Automatic Git-Watchers (
gitwatch): They attempt to capture changes in real time, but crash constantly on rapid consecutive writes due to.git/index.lockcollisions and quickly bloat your drive when large logfiles enter the folder. - Filesystem-Level Snapshots (ZFS, Btrfs): They operate on raw disk blocks, making it cumbersome to quickly restore a single broken file or inspect human-readable line-by-line diffs.
How Shadow Sentinel Solves All Three at Once:
- Real-Time Kernel Protection: The microsecond a file is touched and closed, Sentinel catches the write. You never lose work between morning and evening.
- Logarithmic Multi-Scale Time Horizon: Thanks to its geometric Decade Cascade, a single project folder retains snapshots from 3 seconds ago, 5 minutes ago, today's morning shift, last weekend, and all the way back across months or years.
- Tiny, Predictable Storage Footprint: Because each tier strictly caps at 10 revisions per path hash, an entire 35-day revision history for a typical script consumes less than a few megabytes of space. Storage never explodes.
- Hardware Isolation on Separate Volumes: You can redirect the entire backup vault to an
external physical SSD, a mounted secondary drive, or a network share
(
/etc/shadow-sentinel/config.json). Even if your primary operating system drive is formatted or crashes, your shadow vault on the separate volume keeps every historic version safe and intact.
Dual-Version Architecture & Documentation Notice
This documentation serves as the Single Source of Truth (SSOT) for both production releases:
- Version 1.0.1 (Stable Baseline): Legacy baseline package available via PyPI
1.0.1. - Version 2.1.0 (Current Major Release): Multi-tenant path-hashing, immutable backup IDs, explicit restore verification, ANSI-decoupled column alignment, interactive TUI, decade cascade, nano viewer, marker migration assistant, and self-cleaning lifecycle.
Every section and feature below is explicitly tagged with its supported version.
Version Comparison
| Architectural Feature | Version 1.0.1 (Baseline) | Version 2.1.0 (Current Major) |
|---|---|---|
| Kernel inotify (libc.so.6 ctypes) | Yes (Zero deps) | Yes (Zero deps) |
| Marker Parameters | 1 Parameter: <size_mb> |
3 Parameters: <size_mb> [start] [end] |
| Marker Migration Assistant | Not available | Auto-detects & migrates legacy markers |
| Subfolder Policy Handling | Parent inheritance only | Deepest marker wins (Longest prefix) |
| Multi-Tenant Path-Hashing | Flat vault namespace | 6-char dir hash (zero collisions) |
| Backup Revision IDs | Dynamic index numbering | Immutable IDs + restore confirmation |
| Backup Buffer Type | Single 10-revision FIFO | Decade-Tier Cascade (T1..T128) |
| Max Retention Window | 14 Days flat (all files) | Scaled: T1-4 14d, T5-9 60d, T10+ 365d |
| Diff Retention Lifecycle | 30 Days flat logs | 1:1 Twin with matching .bak file |
| Directory Ceiling Emergency Cap | 500 MB (prunes to 80%) | 500 MB (prunes to 80%) |
| Vault Ejection for Giant Files | Yes (ejects > MB limit) | Yes (ejects > MB limit) |
| Restore Undo-Safety | Yes (Loop-coupled) | Yes (Loop-coupled + path verify) |
| Terminal Display Mode | Complete scrollable table | Interactive As-You-Type Live Explorer |
| Terminal Input Ergonomics | Standard prompt | 2-line layout + ANSI-aligned columns |
| Search Engine | Argument filter: sentinel <term> |
Live wildcard (*) OR content grep |
| Direct File Inspection | CLI only | Direct nano view (sentinel nano <ID>) |
| File Type Visual Classification | Plain text paths | Functional extension icons (📚, 🐍) |
| Catalog Integrity | Append-only index | Self-healing (auto-purges ghost files) |
| Zombie Process Reaper | Manual pkill required | Auto-terminates orphan daemons on boot |
| Automated Update Notifier | Not available | Strict SemVer PyPI check + whatsnew |
The AI Agent Dilemma [Applies to v1.0.1 and v2.1.0]
Autonomous AI coding agents, Copilots, and LLM automation pipelines are transforming development. However, they introduce a terrifying new failure mode: silent, automated destruction of code.
The LLM Code Truncation & Hallucination Trap
Large Language Models have a notorious habit of code "laziness" and structural truncation:
- Replacing hundreds of lines of critical logic with:
// ... rest of implementation remains unchanged ... - Overwriting multi-thousand-line configuration files with incomplete, summarized snippets.
- Truncating files or writing empty 0-byte files when token limits, parser errors, or API timeouts occur.
- Hallucinating breaking parameter changes across multiple scripts simultaneously.
The Nightmare Scenario: Immediate vs. Delayed Detection
- If you catch it immediately: You still waste stressful hours digging through editor undo buffers, stash queues, or attempting to manually reconstruct what the model wiped out.
- If you catch it hours or days later: The damage is catastrophic. The agent continued running, git working trees are dirty, commits were never made, and the original, working code is gone forever. Regular backups taken once a day or once a week cannot save intraday edits.
The Sentinel Safety Net
Shadow Sentinel runs silently in the background directly under the agent's feet at the OS level.
The microsecond an AI agent or automated script calls write() or overwrites a file:
- Sentinel's kernel-level inotify intercept catches the write before the file closes.
- The previous working version is sealed into an atomic, timestamped
.bakrevision. - A human-readable unified
.diffis generated showing exactly what the agent altered or removed. - If an agent ruins a file, you restore it with a single command:
sentinel restore <ID>.
Core Engine Capabilities (Available in v1.0.1 and v2.1.0)
-
Decentralized Marker Control (
sentinel_marker):- No tedious editing of central configuration files.
- Simply drop a
sentinel_markerfile into any directory to monitor that tree recursively. - Sentinel automatically discovers all marked roots on startup.
-
Retroactive Legacy Backup Onboarding:
- On service startup, Sentinel scans for pre-existing
.bakrevisions on the drive and silently catalogs them. Legacy backups become immediately restoreable viasentinel restore <ID>.
- On service startup, Sentinel scans for pre-existing
-
Dynamic File-Size Ceiling (Self-Pruning Vault):
- The value inside
sentinel_markersets the protected size ceiling (e.g.5for 5 MB). - If a file (such as a runaway logfile) exceeds this ceiling, it is automatically ejected from the shadow vault. Small scripts, configurations, and source code stay 100% protected.
- The value inside
-
Loop-Coupling (Undo-Safe Restore):
- Restoring a file with
sentinel restore <ID>overwrites the target file. - The running inotify daemon immediately intercepts this write and seals the overwritten version into a brand-new backup revision. Mistaken restores can instantly be undone!
- Restoring a file with
-
Flapping & Cooldown Debounce:
- Rapid consecutive writes are debounced with a 3-second quiet window to prevent spam.
-
Zero Dependencies:
- Pure Python standard library with native
ctypesbindings directly tolibc.so.6. - No external tools like
inotifywaitor background Git daemons required.
- Pure Python standard library with native
Major Architecture Additions in Version 2.1.0
1. Decade-Tier Cascade Ring Buffers (Up to Tier 128)
Rather than a single FIFO buffer that risks being pushed out by rapid repetitive loops, v2.1.0 provides a geometric order-of-magnitude cascade ($3 \times 10^{(k-1)}$ seconds):
- Tier 1 (3s): Immediate typos and terminal misclicks (spans 30 seconds).
- Tier 2 (30s): Rapid script loops and syntax breakages (spans 5 minutes).
- Tier 3 (300s): 5-minute session checkpoints (spans 50 minutes).
- Tier 4 (3,000s): 50-minute work shift states (spans 8.3 hours / full workday).
- Tier 5 (30,000s): 8.3-hour multi-shift states (spans 3.5 days / full weekend).
- Tier 6 (300,000s): 3.5-day milestones (spans over 35 days / full month).
- Tier 7 (3,000,000s): ~35-day milestones (spans ~350 days / 1 year).
- Tier 8 (30,000,000s): ~350-day milestones (spans ~9.5 years).
- Tiers up to T128: Geometrically scaling to years and decades for archival deployments.
Each tier maintains its own dedicated ring buffer of 10 revisions. Even if an AI agent runs wild in a 5-second loop all night long, Tiers 4, 5, and 6 retain the pristine code from before the experiment began.
2. Multi-Tenant Path-Hashing & Isolated Tier Pruning
Backups incorporate a deterministic 6-character directory hash in their vault filename
([basename].[hash].T[tier].[ts].bak). Identical filenames across different project trees or
customer webspaces (such as app.py, index.html, or .env) never collide, and tier rotation is
strictly isolated per directory and path hash.
3. Immutable Revision IDs & Explicit Restore Verification
Catalog revision IDs remain permanently frozen once assigned instead of shifting when subsequent
writes arrive. Restoring via sentinel restore <ID> or interactive mode verifies both source
revision and full target path with explicit confirmation safety.
4. Hierarchical Range Markers & Nested Subfolder Overrides
v2.1.0 supports fine-grained tuning per folder via a 3-parameter marker format:
[max_size_mb] [start_tier] [end_tier]
- Example:
5 1 4(5 MB ceiling, Tiers 1 through 4 active — default for developer projects). - Example:
50 3 8(50 MB limit, Tiers 3 to 8 only — skips high-frequency 3s/30s spam for DBs). Nested subdirectories automatically override parent policies using longest-prefix matching.
5. Marker Migration Assistant
v2.1.0 detects legacy single-parameter markers (e.g. 5 or empty files) and automatically
prompts the admin to upgrade them to the modern 3-parameter format (5 1 4), preserving existing
size limits while activating the cascade.
6. Interactive Guided Live-Filter Explorer (TUI) & ANSI Alignment
Running sentinel with no arguments in a terminal launches the interactive explorer:
- Automatically detects terminal height (
shutil.get_terminal_size()) to prevent scroll cutoffs. - Pixel-Perfect Column Alignment: ANSI color codes are decoupled from width calculations so columns align cleanly across every terminal emulator.
- As-You-Type Live Search: Type search terms without pressing Enter; the match counter updates live on every keystroke. Backspace edits query in-place.
- Dual Search Modes: Search by filename wildcard (
*.py,*conf*,T4) OR full-text content search across backup files. - Ergonomic 2-Line Prompt: Status bar positioned above the active input line; cursor remains naturally positioned behind typed characters.
7. Direct Nano Viewer
Inspect historic .bak files inside nano in read-only mode (sentinel nano <ID>).
Exit nano (Ctrl+X) to return directly to the Sentinel explorer.
8. Extension-Based File Classification Icons
Table outputs visually categorize files by extension:
🐍Python (.py,.pyw)🐚Shell Scripts (.sh,.bash,.zsh)📚Markdown & Documentation (.md)🗄️Databases (.db,.sqlite,.sql,.db-wal)⚙️Configs (.json,.yaml,.toml,.conf,.ini,.env)📋Logs (.log,.out,.err)📝Plain Text (.txt,.csv,.rst)
9. Self-Healing Catalog Index
The catalog automatically validates that physical .bak files exist on disk during every load.
If the auto-pruner purged an old revision, ghost records are immediately purged from the index.
10. Self-Cleaning Service Lifecycle & Zombie Reaper
sentinel service install and sentinel restart automatically scan for and terminate orphaned
legacy background daemons (including older test environments or unmanaged processes) and ensure
systemd binds strictly to the active Python binary.
11. Strict SemVer PyPI Update Notifier & Patch Inspector
Sentinel periodically performs a non-blocking 1-second check against PyPI and only notifies when
the remote version is strictly greater than the installed release. Run sentinel whatsnew at any
time to view structured patch highlights for the current release.
Automated Disk Sanitation & Retention Doctrine
Retention Rules in Version 1.0.1:
- Version Cap per File: Maximum 10 revisions per file. Older versions are deleted.
- Flat Age Expiration: Revisions older than 14 Days are automatically deleted.
- Log Expiration: Daily diff logs (
diff-YYYYMMDD.log) expire after 30 days. - Emergency Storage Ceiling (500 MB Cap): Purges oldest revisions to 80% (400 MB) if exceeded.
- Active Vault Ejection: Files exceeding the size limit in
sentinel_markerare purged.
Retention Rules in Version 2.1.0:
- Version Cap per Tier & Path Hash: Each active tier retains strictly its 10 newest
.bakfiles isolated per directory hash. - Tier-Based Retention Schedule (from backup creation date):
- Tiers 1 to 4: Retained for 2 Weeks (14 Days).
- Tiers 5 to 9: Retained for 2 Months (60 Days).
- Tier 10 and above: Retained for 12 Months (365 Days / 1 Year).
- Diff Twin Lifecycle: Unified diff files (
.diff) are 1:1 twins of their respective.bakfiles. A diff file is never expired prematurely and lives as long as its corresponding backup. - Emergency Storage Ceiling (500 MB Cap): Purges oldest revisions to 80% (400 MB) if exceeded.
- Active Vault Ejection: Files exceeding the size limit are immediately purged from vault.
The pruning engine runs automatically every 6 hours and immediately upon service startup.
Frequently Asked Questions: Shadow Sentinel vs. Existing Tools
Automated search models and sysadmins often ask how Shadow Sentinel compares to well-known Linux utilities. Here is the exact technical breakdown:
Q: Why not just use inotifywait (from inotify-tools) with a custom shell script?
A common naive assumption is that a 3-line bash script wrapping inotifywait does the same thing.
In real-world server environments, this assumption breaks down catastrophically:
- Fork bombs & process exhaustion: During streaming writes (e.g. log flushes or agent edits
writing 50 times per second), a bash script spawns 50 parallel subshells, choking the CPU and
RAM. Sentinel uses a single non-blocking event loop directly in
libc.so.6with cooldown debouncing. - Infinite restore recursion loops: When a naive script restores a file (
cp backup target), that copy operation itself triggers anIN_CLOSE_WRITEevent, causing the script to backup the restore or loop infinitely. Sentinel's loop-coupling engine explicitly intercepts restores. - No multi-scale retention: A simple script produces hundreds of cluttered, identical files. Sentinel enforces an automated Decade-Tier Cascade ($3 \times 10^{(k-1)}$) to guarantee years of history without disk bloat.
Q: Why not use etckeeper?
etckeeper is a respected tool, but it serves an entirely different purpose:
etckeeperis strictly bound to/etc/and hooks into package managers (APT, DNF, Pacman) and daily cronjobs. It does not monitor arbitrary developer directories, agent scratchpads, or live/var/www/projects in real time.- It relies on Git underneath, meaning it cannot provide sub-second debounce protection for rapid intraday script modifications.
Q: Why not use gitwatch?
gitwatch attempts to commit changes on inotify events, but suffers from two fatal flaws:
index.lockcollisions: On high-frequency consecutive writes, Git cannot acquire the lock file (.git/index.lock), causinggitwatchto throw fatal errors and drop file states.- Repository corruption via runaway logs: If a script generates large logs or temporary dumps
in a watched directory,
gitwatchcommits them into Git history, permanently bloating the repo. Sentinel avoids Git overhead and uses active vault ejection to purge oversized files.
Q: Why not use lsyncd (Live Syncing Daemon)?
lsyncd is an asynchronous 1:1 mirroring tool combining inotify with rsync.
lsyncdsynchronizes file states to a remote target. If an AI agent or a broken command corrupts a local file,lsyncdimmediately mirrors that corrupted file to the backup destination!lsyncddoes not maintain a multi-tier revision history, does not generate unified line-by-line diffs, and does not provide an instant 1-command local rollback.
Q: Why not use Meta's Watchman?
Watchman is an open-source file-watching service by Meta designed for build systems (e.g. Jest,
Buck, React Native).
Watchmanwatches directory trees to notify external compilers when to rebuild assets.- It is NOT a revision control or backup tool: it does not create
.bakcopies, maintains no shadow vault, creates no diffs, and has no restore capabilities.
Q: Why not File Integrity Monitoring (FIM) tools like Tripwire, AIDE, or osquery?
Security FIM tools monitor checksums to detect unauthorized intrusions and generate security alerts. They tell you that a file was compromised, but they do NOT store historical revisions, do not provide unified diff comparisons, and cannot restore your files when an accident occurs.
Q: What about Microsoft Sentinel or Redis Sentinel?
This is a purely linguistic coincidence:
- Microsoft Sentinel is an enterprise cloud SIEM (Security Information and Event Management) suite running in Azure to detect cyber attacks across corporate networks.
- Redis Sentinel is an automated high-availability failover monitor for Redis database clusters.
- Shadow Sentinel is a lightweight, zero-dependency Linux OS-level filesystem revision guard.
Installation
Universal 1-Command Installer (Recommended for all Linux distributions):
curl -sSL https://raw.githubusercontent.com/automatician/shadow-sentinel/main/install.sh | sudo bash
Or via Pipx:
pipx install shadow-sentinel
sudo sentinel service install
Or via standard pip (inside virtual environments):
pip install shadow-sentinel
sudo sentinel service install
Legacy v1.0.1 Baseline Installation:
pip install shadow-sentinel==1.0.1
sudo sentinel service install
Command Reference by Version
| Command | Supported Version | Description |
|---|---|---|
sentinel |
v2.0+ |
Launches Interactive Guided As-You-Type Explorer (TUI). |
sentinel |
v1.0+ |
Displays full table of revisions in the current marker root. |
sentinel [filter] |
v1.0+ |
Filters list by term (v2.0+ adds wildcard * and tier T4). |
sentinel nano <ID> |
v2.0+ |
Opens the exact .bak revision in nano (read-only view). |
sentinel view <ID> |
v2.0+ |
Alias for sentinel nano <ID>. |
sentinel restore <ID> |
v1.0+ |
Restores revision <ID> with loop-coupling safety. |
sentinel diff <ID> |
v1.0+ |
Outputs unified diff of revision <ID> to stdout. |
sentinel init [MB] |
v1.0+ |
Initializes marker with size limit (defaults T1..T4 in v2.1+). |
sentinel init [MB] [start] [end] |
v2.0+ |
Initializes custom cascade range (e.g. 10 3 8). |
sentinel markers |
v1.0+ |
Lists active marked roots with size limits and active tiers. |
sentinel whatsnew |
v2.0.1+ |
Displays structured release notes and patch highlights. |
sentinel restart |
v2.0.1+ |
Intuitive direct alias to restart background service cleanly. |
sentinel service install |
v1.0+ |
Installs and enables systemd background service. |
sentinel service restart |
v1.0+ |
Restarts daemon (reaps zombies, rescans all markers). |
sentinel service status |
v1.0+ |
Displays systemd service status. |
sentinel version |
v1.0+ |
Displays version, copyright, and SPDX license info. |
sentinel help |
v1.0+ |
Displays full interactive manual. |
Storage & Configuration [v1.0.1 & v2.1.0]
Linux FHS Standard Paths:
- Root Daemon:
/var/lib/shadow-sentinel/ - User Daemon:
~/.local/share/shadow-sentinel/
Custom Storage Redirection (/etc/shadow-sentinel/config.json):
To store backups, vaults, and indices in a custom directory (e.g. a separate SSD or network mount),
create /etc/shadow-sentinel/config.json (for root) or ~/.config/shadow-sentinel/config.json
(for user):
{
"storage_dir": "/mnt/external_volume/sentinel_vault"
}
Environment Variable Override:
export SENTINEL_STORAGE_DIR=/mnt/external_volume/sentinel_vault
Metadata
Release files for shadow-sentinel 2.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| shadow_sentinel-2.1.0.tar.gz | 34.0 kB | Without provenance | Details for shadow_sentinel-2.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| shadow_sentinel-2.1.0-py3-none-any.whl | Python 3 | none | any | Details for shadow_sentinel-2.1.0-py3-none-any.whl |
Total release size: 59.2 kB
Release files / shadow_sentinel-2.1.0.tar.gz
| Download URL | shadow_sentinel-2.1.0.tar.gz |
|---|---|
| Size | 34.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9fd1d438f33e764ee18ea3124eac90cce1464712f3c49c11a8d90e5820a39231
|
|
BLAKE2b-256 checksum How to use checksums |
b336fc4cd32954f32676855fba564814be8ae83c1f766c8e8dce38516e612cc7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Release files / shadow_sentinel-2.1.0-py3-none-any.whl
| Download URL | shadow_sentinel-2.1.0-py3-none-any.whl |
|---|---|
| Size | 25.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
27429b213c80fb39f9389c65c1908b4bedfe6cafabb614a702910cea6f588f3f
|
|
BLAKE2b-256 checksum How to use checksums |
9aca9c30436649e6247fef7671885037b86d306fd6e81850fde1a6140af322d2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Security for shadow-sentinel 2.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.