feat enhanced TOOL: Add diff, backup --user-only, and migrate --auto to BackupRestore.ts #974
Open
sauldataman wants to merge 6 commits intodanielmiessler:mainfrom
Open
feat enhanced TOOL: Add diff, backup --user-only, and migrate --auto to BackupRestore.ts #974sauldataman wants to merge 6 commits intodanielmiessler:mainfrom
diff, backup --user-only, and migrate --auto to BackupRestore.ts #974sauldataman wants to merge 6 commits intodanielmiessler:mainfrom
Conversation
Contributor
Author
|
related to issue #973 |
3af0f47 to
e9d3533
Compare
… upgrades Add three new capabilities to BackupRestore.ts for safe upgrade workflows: - `diff --release <path>`: Compare local installation against a release using SHA-256 hashes. Shows new files, unchanged files, and conflicts (locally modified system files). Automatically excludes PAI/USER/, MEMORY/, settings.json, PAI-Install/, and CLAUDE.md from conflict reporting since they are handled separately. - `backup --user-only --release <path>`: Smart backup that saves only user data: always-backup dirs (PAI/USER/, MEMORY/), settings.json, CLAUDE.md, modified system files, and user-generated files not in the release. Excludes CC runtime dirs (debug/, telemetry/, etc.). Supports --exclude for fine-grained control. - `upgrade --release <path>`: Automated upgrade cycle — checks for full backup, diffs, backs up user data, applies release via cp -r, restores user modifications, and rebuilds CLAUDE.md. Skips restoring CLAUDE.md (regenerated by BuildCLAUDE.ts) but restores settings.json before install.sh runs so its merge logic preserves user config. Ignore patterns are read from the repo's .gitignore rather than hardcoded. All existing commands (backup, restore, list, migrate) are completely unchanged. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…re.ts Add three new capabilities for safer PAI release updates: - diff --release <path>: SHA-256 comparison against release, auto-excludes PAI/USER/, MEMORY/, settings.json, PAI-Install/ from conflict reporting - backup --user-only --release <path>: Smart backup of user data — always includes PAI/USER/, MEMORY/, settings.json, CLAUDE.md, plus modified system files and user-generated files not in the release. Supports --exclude for fine-grained control - migrate --auto [--backup <path>]: Auto-restore user data from a user-only backup after applying a new release. Skips CLAUDE.md (regenerated by BuildCLAUDE.ts), runs BuildCLAUDE.ts after restore All existing commands (backup, restore, list, migrate) unchanged. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
e9d3533 to
b6d1418
Compare
- Replace execSync("bun BuildCLAUDE.ts") with dynamic import of build()
to eliminate the only shell command dependency. All operations now use
Node.js/Bun APIs exclusively (cpSync, readFileSync, createHash, etc.)
- Remove unused execSync import
- Remove empty BACKUP_EXCLUDE_DIRS constant (no dirs are excluded)
- Fix stale --release parameter references in migrate --auto comments,
header docs, and printUsage Migration Flow
- Fix "upgrading" → "migration" in diff output text
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Instead of copying files one by one, use cpSync(backup, target, {recursive: true})
matching the approach used by the original restoreBackup function. Then remove
auto-regenerated files (CLAUDE.md) and the backup manifest afterward.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
cpSync with recursive:true fails on read-only files (e.g. .git/objects/). Switch back to per-file copy with try/catch to skip permission errors gracefully instead of aborting the entire restore. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
fix #973
Enhance
Tools/BackupRestore.tswith three new capabilities for safer PAI release updates:diff --release <path>— Preview which local files differ from a release using SHA-256 comparisonbackup --user-only --release <path>— Back up only user data (PAI/USER/, MEMORY/, settings.json, user-generated files, modified system files) instead of the entire ~/.claude directorymigrate --auto --release <path>— Automatically restore user data from a user-only backup after applying a new releaseAll existing commands (
backup,restore,list,migrate) are completely unchanged.Motivation
The current
migratecommand identifies only_-prefixed skills, settings identity fields, and MEMORY subdirectory names — missing PAI/USER/ content, user-modified hooks/skills, installed Packs, Claude Code auto-memory (projects/), and other user-generated data. It also only produces a text report without performing any restore.These additions give users visibility into what a release update will change (
diff), a way to capture only their data (backup --user-only), and an automated restore path (migrate --auto) — reducing the manual effort and risk of losing customizations during updates.Changes
Single file changed:
Tools/BackupRestore.tsNew commands:
diff --release <path>— SHA-256 comparison against release, excluding PAI/USER/, MEMORY/, settings.json, PAI-Install/ from conflict reporting (handled separately)backup --user-only --release <path>— Backs up user data in three categories: always-backup dirs (PAI/USER/, MEMORY/), modified system files, and user-generated files not in the release. Supports--excludefor fine-grained controlmigrate --auto --release <path>— Restores user data from the latest user-only backup (or--backup <path>), skips CLAUDE.md (regenerated by BuildCLAUDE.ts), then runs BuildCLAUDE.tsUnchanged commands:
backup,restore,list,migrate— no behavioral changesMigration Flow
Test plan
diff --releasecorrectly shows new/unchanged/conflict filesdiffexcludes PAI/USER/, MEMORY/, settings.json, PAI-Install/ from conflictsbackup --user-onlyincludes PAI/USER/, MEMORY/, settings.json, CLAUDE.md, and all user-generated filesbackup --user-only --excludecorrectly removes specified files from backuplistdistinguishes full vs user-only backups with[user-only]tagmigrate --autorestores files from user-only backup, skips CLAUDE.mdmigrate --autoauto-finds latest user-only backup when--backupis not specifiedmigrate(without --auto) works exactly as beforebackup,restore,listwork exactly as before