CRITICAL: After EVERY file modification (Write, Edit, MultiEdit, Shell commands that change files), you MUST run the snapshot script. This is non-negotiable — without snapshots, undo is impossible.
All scripts are located in this skill's directory. Use {baseDir} to reference them:
bash
SCRIPTS="{baseDir}/scripts"
CommandPurposenode "$SCRIPTS/init.js" /path/to/projectStart tracking a projectnode "$SCRIPTS/snapshot.js" /path/to/project "Description"Record current statenode "$SCRIPTS/undo.js" /path/to/project --steps 1Undo last changenode "$SCRIPTS/undo.js" /path/to/project --to <name>Undo to checkpointnode "$SCRIPTS/undo.js" /path/to/project --timestamp "2026-04-10T14:00"Undo to timenode "$SCRIPTS/list.js" /path/to/projectList change historynode "$SCRIPTS/checkpoint.js" /path/to/project "name"Create named checkpointnode "$SCRIPTS/watcher.js" /path/to/project &Start background watcher
Every script outputs exactly one line of JSON. Parse it with your environment's JSON parser — do NOT read the human text.
json
{"action":"init","status":"success","initialized":true,"project":"/abs/path","storagePath":"~/.local/share/...","message":"Tracking initialized"}
json
{"action":"init","status":"success","initialized":false,"project":"/abs/path","storagePath":"~/.local/share/...","message":"Already tracked"}
json
{"action":"snapshot","status":"success","committed":true,"project":"/abs/path","description":"Added error handling","hash":"abc1234","changedFiles":["src/index.js"],"fileCount":1}
json
{"action":"snapshot","status":"success","committed":false,"project":"/abs/path","description":"..."}
(committed=false means no changes since last snapshot)
json
{
"action":"list",
"status":"success",
"project":"/abs/path",
"count":3,
"commits":[
{
"hash":"abc1234",
"date":"2026-04-10 14:05:12 +0800",
"timestamp":"2026-04-10T06:05:12.000Z",
"description":"Added error handling",
"files":[{"status":"M","path":"src/index.js"}],
"isCheckpoint":false,
"isInitial":false
}
],
"checkpoints":[{"name":"checkpoint/before-refactor","hash":"def5678"}]
}
json
{"action":"undo","status":"success","undone":true,"mode":"steps","project":"/abs/path","steps":1,"targetHash":"abc1234","checkpointBranch":"checkpoint/undo-1712736312000"}
json
{"action":"undo","status":"error","error":"not_enough_history","mode":"steps","project":"/abs/path","requested":5}
json
{"action":"checkpoint","status":"success","project":"/abs/path","checkpoint":"before-refactor","branch":"checkpoint/before-refactor"}
On start:
json
{"action":"watcher-start","status":"success","project":"/abs/path","pid":12345,"debounceMs":5000,"pollMs":2000}
On each auto-snapshot:
json
{"action":"watcher-snapshot","status":"success","committed":true,"project":"/abs/path","hash":"abc1234","description":"[watcher] added: 1, modified: 2","timestamp":"2026-04-10T06:05:12.000Z","files":{"added":["new.js"],"changed":["index.js"],"deleted":[]}}
On stop:
json
{"action":"watcher-stop","status":"stopped","project":"/abs/path"}
error codemeaningactionmissing_project_pathNo path argument givenPass absolute pathgit_not_foundGit not installed and auto-install failedInstall git manually (see detail.manual_install_hint, try apt-get install git / brew install git / pkg install git)not_trackedProject not initializedRun init.js firstno_changesNothing changed since last snapshotSafe to skipnot_enough_historyNot enough snapshots to undo requested depthUse fewer stepscheckpoint_not_foundNamed checkpoint doesn't existCheck list.js outputcheckpoint_existsCheckpoint name already takenUse a different nameinvalid_timestampTimestamp format invalidUse ISO 8601no_commits_before_timestampNo snapshots before that timeUse earlier time or different approach
After installing this skill, run init.js on the user's project before any other commands:
bash
node "$SCRIPTS/init.js" /path/to/project
This attempts to auto-install git if missing, then initializes tracking. If git auto-install fails, it returns a structured error with platform details and install hints — use that info to guide manual installation.
After ANY Write/Edit/Shell that modifies files, immediately run:
bash
node "$SCRIPTS/snapshot.js" /path/to/project "Brief description of what changed"
Description guidelines:
bash
node "$SCRIPTS/checkpoint.js" /path/to/project "before-refactor"
bash
node "$SCRIPTS/list.js" /path/to/project
Parse the commits array. Each entry has hash, timestamp, description, files, and isCheckpoint flag.
bash
# Undo last N changes
node "$SCRIPTS/undo.js" /path/to/project --steps 3
# Undo to named checkpoint
node "$SCRIPTS/undo.js" /path/to/project --to before-refactor
# Undo to specific time (ISO 8601)
node "$SCRIPTS/undo.js" /path/to/project --timestamp "2026-04-10T14:00"
After successful undo, inform the user that previous state is preserved on the branch from the JSON's checkpointBranch field.
bash
node "$SCRIPTS/watcher.js" /path/to/project &
Auto-snapshots if you forget. PID in startup JSON. Stop with kill <PID>.
text
~/.local/share/undo-skill/repos/
├── abc123def456/ # Bare git repo (MD5 hash of project path, 12 chars)
│ ├── HEAD
│ ├── refs/heads/main # Latest snapshot
│ ├── refs/heads/checkpoint/undo-1712736312000
│ ├── refs/heads/checkpoint/before-refactor
│ └── _worktree/ # Temp working directory (auto-managed)
└── projects.json # hash → absolute path mapping
.git is NEVER touchedmain = current state; checkpoint/* = preserved states (never deleted)checkpoint/* branches