@jamiefutch/pi-backup 1.1.9 → 1.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # pi-backup — Pi Backup & Restore Utilities
2
2
 
3
- Complete backup/restore for Pi coding agent. Backs up **everything** needed to restore to identical state after a clean reinstall.
3
+ Complete, cross-platform backup/restore for the Pi coding agent. Backs up **everything** needed to restore to an equivalent state after a clean reinstall, with an interactive `/pi-backup` manager and 7-Zip-first archive support.
4
4
 
5
5
  ## Installation
6
6
 
@@ -27,6 +27,13 @@ pi install /path/to/pi-backup
27
27
 
28
28
  Then restart Pi or run `/reload`.
29
29
 
30
+ ### Developer documentation
31
+
32
+ Repository-specific agent guidance is available in:
33
+
34
+ - `.pi/agents.md` — pi-backup project conventions and safety rules
35
+ - `.pi/agents/pi-development-expert.md` — detailed Pi extension, package, SDK, TUI, provider, and resource-development guidance
36
+
30
37
  ---
31
38
 
32
39
  ## Scripts
@@ -44,6 +51,18 @@ Then restart Pi or run `/reload`.
44
51
 
45
52
  ---
46
53
 
54
+ ## Archive format and compression
55
+
56
+ External backups are compressed automatically:
57
+
58
+ - If `7zz`, `7z`, or `7za` is available on **macOS, Linux, or Windows**, Pi Backup uses 7-Zip and creates a `.7z` archive.
59
+ - Otherwise it falls back to native platform tools and creates a `.zip` archive (`zip`/`unzip` on macOS/Linux, `Compress-Archive`/`Expand-Archive` on Windows).
60
+ - Restoring a `.7z` archive requires 7-Zip to be installed and available on `PATH`.
61
+ - The TUI uses the same preference for creating, restoring, copying, and viewing manifests.
62
+ - Internal backups remain uncompressed directories for fast rollback.
63
+
64
+ The executable may be named `7zz`, `7z`, or `7za`.
65
+
47
66
  ## Usage
48
67
 
49
68
  ### TUI Extension (after package install)
@@ -56,7 +75,7 @@ Opens the **Pi Backup Manager** interactive menu:
56
75
 
57
76
  ```
58
77
  Pi Backup Manager — 8 backups (1 internal, 7 external)
59
- External dir: ~/projects/personal/pi-utils/backups
78
+ External dir: ~/pi-backups
60
79
 
61
80
  → 📦 Create internal backup (~/.pi/backups/ — quick rollback)
62
81
  💾 Create external backup (survives reinstall)
@@ -83,7 +102,7 @@ External dir: ~/projects/personal/pi-utils/backups
83
102
  Backups (8 total)
84
103
 
85
104
  → 📁 pi-backup-20260812-112053 │ 2026-08-12 11:20:53 │ 1.6 MB │ 347 files
86
- 💾 pi-backup-20260812-112019.zip │ 2026-08-12 11:20:19 │ 1.6 MB │ 1 files • compressed
105
+ 💾 pi-backup-20260812-112019.7z │ 2026-08-12 11:20:19 │ 1.6 MB │ 1 files • compressed
87
106
  💾 pi-backup-20260812-095402.zip │ 2026-08-12 09:54:02 │ 1.6 MB │ 1 files • compressed
88
107
  ...
89
108
  🔄 Refresh
@@ -95,7 +114,7 @@ Columns: **Location icon** • **Name** • **Timestamp** • **Size** • **Fil
95
114
  #### Backup Actions (after selecting a backup)
96
115
 
97
116
  ```
98
- Backup: pi-backup-20260812-112019.zip
117
+ Backup: pi-backup-20260812-112019.7z
99
118
 
100
119
  → 🔄 Restore this backup (2026-08-12 11:20:19)
101
120
  📋 Copy to internal (~/.pi/backups/)
@@ -106,7 +125,7 @@ Backup: pi-backup-20260812-112019.zip
106
125
 
107
126
  | Action | Description |
108
127
  |--------|-------------|
109
- | **🔄 Restore** | Runs `restore-pi.sh` — overwrites all Pi config (requires confirmation) |
128
+ | **🔄 Restore** | Runs the platform restore script — overwrites all Pi config (requires confirmation) |
110
129
  | **📋 Copy to internal** | Copies external backup to `~/.pi/backups/` for quick access (external only) |
111
130
  | **📄 View manifest** | Opens `MANIFEST.txt` in editor (extracts from compressed archives) |
112
131
  | **🗑️ Delete** | Permanently removes backup (requires confirmation) |
@@ -116,7 +135,7 @@ Backup: pi-backup-20260812-112019.zip
116
135
  | Location | Path | Survives Clean Reinstall? | Format |
117
136
  |----------|------|---------------------------|--------|
118
137
  | **Internal** | `~/.pi/backups/` | ❌ NO (wiped by `rm -rf ~/.pi`) | Uncompressed dirs |
119
- | **External** | `~/projects/personal/pi-utils/backups/` | ✅ YES | Compressed (.7z/.zip) |
138
+ | **External** | `~/pi-backups/` | ✅ YES | Compressed (.7z/.zip) |
120
139
 
121
140
  > **Key point**: Always create an **external backup** before a clean reinstall. Internal backups are for quick rollbacks during normal use only.
122
141
 
@@ -124,17 +143,17 @@ Backup: pi-backup-20260812-112019.zip
124
143
 
125
144
  #### 1. Backup (before reinstall)
126
145
  ```bash
127
- ~/projects/personal/pi-backup/backup-pi.sh
146
+ ./backup-pi.sh
128
147
  ```
129
148
 
130
149
  #### 2. Clean Reinstall
131
150
  ```bash
132
- ~/projects/personal/pi-backup/pi-clean-reinstall.sh
151
+ ./pi-clean-reinstall.sh
133
152
  ```
134
153
 
135
- #### 3. Restore
154
+ #### 3. Restore a directory, `.7z` archive, or `.zip` archive
136
155
  ```bash
137
- ~/projects/personal/pi-backup/restore-pi.sh ~/projects/personal/pi-utils/backups/pi-backup-20260811-143000
156
+ ./restore-pi.sh ~/pi-backups/pi-backup-20260811-143000.7z
138
157
  ```
139
158
 
140
159
  #### 4. Reinstall npm deps + verify
@@ -148,7 +167,7 @@ pi --version
148
167
 
149
168
  ### Windows (PowerShell)
150
169
 
151
- On Windows, use the `.ps1` scripts from PowerShell 7 (`pwsh`). The backup data directory defaults to `~/projects/personal/pi-utils/backups`.
170
+ On Windows, use the `.ps1` scripts from PowerShell 7 (`pwsh`). The backup data directory defaults to `~/pi-backups`.
152
171
 
153
172
  ```powershell
154
173
  # 1. Backup (before reinstall)
@@ -158,7 +177,7 @@ On Windows, use the `.ps1` scripts from PowerShell 7 (`pwsh`). The backup data d
158
177
  .\pi-clean-reinstall.ps1
159
178
 
160
179
  # 3. Restore
161
- .\restore-pi.ps1 ~\projects\personal\pi-utils\backups\pi-backup-20260811-143000
180
+ .\restore-pi.ps1 ~\pi-backups\pi-backup-20260811-143000
162
181
 
163
182
  # 4. Reinstall npm deps + verify
164
183
  cd ~\.pi\agent; npm install
@@ -172,17 +191,17 @@ Customize locations in PowerShell with environment variables (same names as the
172
191
  $env:PI_ROOT='C:\Users\you\.pi'; $env:BACKUP_ROOT='D:\pi-backups'; .\backup-pi.ps1
173
192
  ```
174
193
 
175
- > **Note**: If the Execution Policy blocks scripts, run once: `Set-ExecutionPolicy -Scope CurrentUser RemoteSigned`. Backups are created as `.zip` via the built-in `Compress-Archive` (no external tools needed).
194
+ > **Note**: If the Execution Policy blocks scripts, run once: `Set-ExecutionPolicy -Scope CurrentUser RemoteSigned`. With 7-Zip (`7zz`, `7z`, or `7za`) on `PATH`, backups are created as `.7z`; otherwise PowerShell's built-in `Compress-Archive` creates `.zip` files. `restore-pi.ps1` prefers 7-Zip when available and uses `Expand-Archive` for ZIP fallback.
176
195
 
177
196
  ## What Gets Backed Up
178
197
 
179
198
  | Category | Paths |
180
199
  |----------|-------|
181
- | **Core config** | `settings.json`, `auth.json`, `models.json`, `trust.json`, `keybindings.json`, `pix.json`, `optimizer.json`, `hermes-memory-config.json` |
200
+ | **Core config** | `settings.json`, `auth.json`, `models.json`, `trust.json`, `keybindings.json`, `pix.json`, `optimizer.json`, `lmstudio.json.bak`, `hermes-memory-config.json`, `pi.code-workspace` |
182
201
  | **Extension configs** | `pi-hermes-memory-cleanup/scoped-memory.json`, `loop-police.json`, `pi-rtk/config.json`, `context-mode/config.json`, `pi-timeout/config.json`, `pi-context-viewer/config.json`, `pix-optimizer/config.json`, `pi-nvidia-nim/config.json` |
183
202
  | **Global skills** | `~/.pi/agent/skills/` |
184
203
  | **Project skills & memory** | `~/.pi/agent/projects-memory/<project>/` |
185
- | **Local extension source** | `~/projects/personal/pi-timeout/`, `pi-chunk/`, `pi-hermes-memory-cleanup/`, `pi-context-docs/` |
204
+ | **Local extension source** | `$LOCAL_EXT_ROOT/pi-timeout/`, `pi-chunk/`, `pi-hermes-memory-cleanup/`, `pi-context-docs/` (defaults to `~/projects/`) |
186
205
  | **npm manifests** | `package.json`, `package-lock.json`, `npm-shrinkwrap.json` from `~/.pi/agent/npm/` |
187
206
  | **Hermes memory (active)** | `MEMORY.md`, `USER.md`, `failures.md`, `retired-*.md` |
188
207
  | **Cleanup backups** | Last 5 from `~/.pi/agent/hermes-cleanup/` |
@@ -192,11 +211,11 @@ The backup script output:
192
211
  ════════════════════════════════════════════════════════════
193
212
  Pi Complete Backup
194
213
  ════════════════════════════════════════════════════════════
195
- Source: /Users/jamiefutch/.pi
196
- Destination: ~/projects/personal/pi-utils/backups/pi-backup-20260811-143000
214
+ Source: ~/.pi
215
+ Destination: ~/pi-backups/pi-backup-20260811-143000
197
216
  ...
198
217
  Backup complete!
199
- Location: ~/projects/personal/pi-utils/backups/pi-backup-20260811-143000
218
+ Location: ~/pi-backups/pi-backup-20260811-143000
200
219
  Size: 12M
201
220
  Files: 347
202
221
  ```
@@ -216,7 +235,7 @@ Files: 347
216
235
  ## Backup Location
217
236
 
218
237
  ```
219
- ~/projects/personal/pi-utils/backups/
238
+ ~/pi-backups/
220
239
  ├── pi-backup-20260811-143000/
221
240
  │ ├── MANIFEST.txt
222
241
  │ ├── settings.json
@@ -242,7 +261,7 @@ The external backup location is resolved in this priority order:
242
261
 
243
262
  1. **`BACKUP_ROOT`** environment variable (highest priority)
244
263
  2. **`externalBackupDir`** key in `~/.pi/agent/settings.json`
245
- 3. **Default**: `~/projects/personal/pi-utils/backups/`
264
+ 3. **Default**: `~/pi-backups/`
246
265
 
247
266
  ```json
248
267
  // ~/.pi/agent/settings.json
@@ -273,11 +292,14 @@ If the default directory already contains backups, it is treated as configured a
273
292
  | Variable | Default | Purpose |
274
293
  |----------|---------|---------|
275
294
  | `PI_ROOT` | `~/.pi` | Override Pi root directory |
276
- | `BACKUP_ROOT` | `~/projects/personal/pi-utils/backups` | Override backup destination (highest priority for the TUI too) |
295
+ | `BACKUP_ROOT` | `~/pi-backups` | Override backup destination (highest priority for the TUI too) |
296
+ | `LOCAL_EXT_ROOT` | `~/projects` | Override the directory containing local extension source repositories |
297
+ | `KEEP_UNCOMPRESSED` | `0` | Keep the uncompressed staging directory after external backup; the TUI sets this automatically for internal backups |
298
+ | `PKG_MANAGER` | `bun` | Package manager used by the clean-reinstall scripts (`bun`, `npm`, etc.) |
277
299
 
278
300
  ```bash
279
301
  # Custom locations
280
- PI_ROOT=/custom/.pi BACKUP_ROOT=/mnt/backups ~/projects/personal/pi-backup/backup-pi.sh
302
+ PI_ROOT=/custom/.pi BACKUP_ROOT=/mnt/backups ./backup-pi.sh
281
303
  ```
282
304
 
283
305
  ---
@@ -286,10 +308,10 @@ PI_ROOT=/custom/.pi BACKUP_ROOT=/mnt/backups ~/projects/personal/pi-backup/backu
286
308
 
287
309
  ```bash
288
310
  # Daily backup at 3 AM
289
- 0 3 * * * ~/projects/personal/pi-backup/backup-pi.sh >> ~/pi-backup.log 2>&1
311
+ 0 3 * * * ./backup-pi.sh >> ~/pi-backup.log 2>&1
290
312
 
291
313
  # Keep last 30 backups
292
- 0 4 * * * find ~/projects/personal/pi-utils/backups -maxdepth 1 -type d -name 'pi-backup-*' -mtime +30 -exec rm -rf {} \;
314
+ 0 4 * * * find ~/pi-backups -maxdepth 1 -type d -name 'pi-backup-*' -mtime +30 -exec rm -rf {} \;
293
315
  ```
294
316
 
295
317
  ---
package/backup-pi.ps1 CHANGED
@@ -15,11 +15,14 @@ $ErrorActionPreference = 'Stop'
15
15
 
16
16
  # ─── Config ────────────────────────────────────────────────
17
17
  $PiRoot = if ($env:PI_ROOT) { $env:PI_ROOT } else { Join-Path $HOME '.pi' }
18
- $BackupRoot = if ($env:BACKUP_ROOT) { $env:BACKUP_ROOT } else { Join-Path $HOME 'projects\personal\pi-utils\backups' }
18
+ $BackupRoot = if ($env:BACKUP_ROOT) { $env:BACKUP_ROOT } else { Join-Path $HOME 'pi-backups' }
19
+ $LocalExtRoot = if ($env:LOCAL_EXT_ROOT) { $env:LOCAL_EXT_ROOT } else { Join-Path $HOME 'projects' }
19
20
  $Timestamp = Get-Date -Format 'yyyyMMdd-HHmmss'
20
21
  $ArchiveBase = "pi-backup-$Timestamp"
21
22
  $ArchiveDir = Join-Path $BackupRoot $ArchiveBase
22
23
  $KeepUncompressed = $env:KEEP_UNCOMPRESSED -eq '1'
24
+ $SevenZip = @('7zz', '7z', '7za') | ForEach-Object { Get-Command $_ -ErrorAction SilentlyContinue } | Select-Object -First 1
25
+ $ArchiveExtension = if ($SevenZip) { '7z' } else { 'zip' }
23
26
 
24
27
  function Log { Write-Host "[INFO] $args" -ForegroundColor Cyan }
25
28
  function OK { Write-Host "[OK] $args" -ForegroundColor Green }
@@ -58,13 +61,13 @@ function Copy-Tree([string]$src, [string]$dst, [string[]]$excludeDirs = @(), [st
58
61
  & robocopy @robocopyArgs | Out-Null
59
62
  } else {
60
63
  # Fallback: manual recursive copy with exclusions
61
- $dirs = if ($excludeDirs.Count) { @{ } } else { @{ } }
62
64
  Get-ChildItem -LiteralPath $src | ForEach-Object {
65
+ $item = $_
63
66
  $skip = $false
64
- if ($_.PSIsContainer -and $_.Name -in $excludeDirs) { $skip = $true }
65
- if (-not $_.PSIsContainer -and $_.Name -like $excludeFiles) { $skip = $true }
67
+ if ($item.PSIsContainer -and $item.Name -in $excludeDirs) { $skip = $true }
68
+ if (-not $item.PSIsContainer -and ($excludeFiles | Where-Object { $item.Name -like $_ })) { $skip = $true }
66
69
  if (-not $skip) {
67
- Copy-Item -LiteralPath $_.FullName -Destination (Join-Path $dst $_.Name) -Recurse -Force
70
+ Copy-Item -LiteralPath $item.FullName -Destination (Join-Path $dst $item.Name) -Recurse -Force
68
71
  }
69
72
  }
70
73
  }
@@ -125,7 +128,7 @@ if (Test-Path -LiteralPath $projMem) {
125
128
  Log "5/8 Local extension source code..."
126
129
  $localExts = @('pi-timeout', 'pi-chunk', 'pi-hermes-memory-cleanup', 'pi-context-docs')
127
130
  foreach ($ext in $localExts) {
128
- $src = Join-Path $HOME "projects\personal\$ext"
131
+ $src = Join-Path $LocalExtRoot $ext
129
132
  if (Test-Path -LiteralPath $src) {
130
133
  $dst = Join-Path $ArchiveDir "local-extensions\$ext"
131
134
  $extDstDir = Join-Path $ArchiveDir 'local-extensions'
@@ -134,7 +137,7 @@ foreach ($ext in $localExts) {
134
137
  Copy-Tree $src $dst -excludeDirs @('node_modules','dist','build','coverage','.git') -excludeFiles @('*.log')
135
138
  OK " $ext/ (source only)"
136
139
  } else {
137
- Warn " $ext - not found at ~/projects/personal/$ext"
140
+ Warn " $ext - not found at $LocalExtRoot/$ext"
138
141
  }
139
142
  }
140
143
 
@@ -200,15 +203,25 @@ $manifest += ($relFiles -join "`n") + "`n"
200
203
  Set-Content -LiteralPath (Join-Path $ArchiveDir 'MANIFEST.txt') -Value $manifest -Encoding UTF8
201
204
 
202
205
  # ── 9. Compress ───────────────────────────────────────────
203
- Log "9/9 Compressing backup..."
204
- $archivePath = Join-Path $BackupRoot ($ArchiveBase + '.zip')
205
- try {
206
- Compress-Archive -LiteralPath $ArchiveDir -DestinationPath $archivePath -CompressionLevel Optimal -Force
207
- OK " $archivePath"
208
- } catch {
209
- Warn " Compress-Archive failed: $_.Exception.Message"
210
- Warn " Keeping uncompressed staging dir: $ArchiveDir"
211
- $archivePath = $null
206
+ $archivePath = $null
207
+ if ($KeepUncompressed) {
208
+ Log "9/9 Skipping compression for internal backup"
209
+ } else {
210
+ Log "9/9 Compressing backup ($ArchiveExtension)..."
211
+ $archivePath = Join-Path $BackupRoot ($ArchiveBase + ".$ArchiveExtension")
212
+ try {
213
+ if ($SevenZip) {
214
+ & $SevenZip.Source a -t7z -mx=9 $archivePath $ArchiveDir | Out-Null
215
+ if ($LASTEXITCODE -ne 0) { throw "7zip exited with code $LASTEXITCODE" }
216
+ } else {
217
+ Compress-Archive -LiteralPath $ArchiveDir -DestinationPath $archivePath -CompressionLevel Optimal -Force
218
+ }
219
+ OK " $archivePath"
220
+ } catch {
221
+ Warn " Compress-Archive failed: $_.Exception.Message"
222
+ Warn " Keeping uncompressed staging dir: $ArchiveDir"
223
+ $archivePath = $null
224
+ }
212
225
  }
213
226
 
214
227
  # ── 10. Clean up staging dir (unless told to keep it) ─────
@@ -229,5 +242,5 @@ if ($archivePath) {
229
242
  if ($KeepUncompressed) { Log "Staging: $ArchiveDir" }
230
243
  Write-Host ""
231
244
  Log "To restore after reinstall:"
232
- Log " ~/projects/personal/pi-backup/restore-pi.ps1 $archivePath"
245
+ Log " .\restore-pi.ps1 $archivePath"
233
246
  Write-Host ""
package/backup-pi.sh CHANGED
@@ -7,7 +7,8 @@ set -euo pipefail
7
7
 
8
8
  # ─── Config ──────────────────────────────────────────────────────
9
9
  PI_ROOT="${PI_ROOT:-$HOME/.pi}"
10
- BACKUP_ROOT="${BACKUP_ROOT:-$HOME/projects/personal/pi-utils/backups}"
10
+ BACKUP_ROOT="${BACKUP_ROOT:-$HOME/pi-backups}"
11
+ LOCAL_EXT_ROOT="${LOCAL_EXT_ROOT:-$HOME/projects}"
11
12
  TIMESTAMP="$(date +%Y%m%d-%H%M%S)"
12
13
  BACKUP_DIR="$BACKUP_ROOT/pi-backup-$TIMESTAMP" # staging dir (compressed into archive below)
13
14
  KEEP_UNCOMPRESSED="${KEEP_UNCOMPRESSED:-0}" # set to 1 to keep the staging dir after archiving
@@ -29,7 +30,7 @@ elif command -v zip >/dev/null 2>&1; then
29
30
  ZIP_TOOL="zip"
30
31
  ZIP_EXT="zip"
31
32
  fi
32
- [[ -n "$ZIP_TOOL" ]] || { echo -e "${RED}[ERR]${NC} Neither 7zip nor zip found. Install one for compressed backups."; exit 1; }
33
+ [[ -n "$ZIP_TOOL" ]] || { echo "[ERR] Neither 7zip nor zip found. Install one for compressed backups." >&2; exit 1; }
33
34
  ARCHIVE="$BACKUP_ROOT/pi-backup-$TIMESTAMP.$ZIP_EXT"
34
35
 
35
36
  # ─── Colors ──────────────────────────────────────────────────────
@@ -131,14 +132,14 @@ main() {
131
132
  "pi-context-docs"
132
133
  )
133
134
  for ext in "${local_exts[@]}"; do
134
- if [[ -d "$HOME/projects/personal/$ext" ]]; then
135
+ if [[ -d "$LOCAL_EXT_ROOT/$ext" ]]; then
135
136
  mkdir -p "$BACKUP_DIR/local-extensions/$ext"
136
137
  # Copy source, exclude node_modules, dist, build, .git, coverage
137
138
  rsync -a --exclude 'node_modules' --exclude 'dist' --exclude 'build' --exclude '.git' --exclude 'coverage' --exclude '*.log' \
138
- "$HOME/projects/personal/$ext/" "$BACKUP_DIR/local-extensions/$ext/"
139
+ "$LOCAL_EXT_ROOT/$ext/" "$BACKUP_DIR/local-extensions/$ext/"
139
140
  ok " $ext/ (source only)"
140
141
  else
141
- warn " $ext — not found at ~/projects/personal/$ext"
142
+ warn " $ext — not found at $LOCAL_EXT_ROOT/$ext"
142
143
  fi
143
144
  done
144
145
 
@@ -223,7 +224,7 @@ EOF
223
224
  [[ "$KEEP_UNCOMPRESSED" == "1" ]] && log "Staging: $BACKUP_DIR"
224
225
  echo
225
226
  log "To restore after reinstall:"
226
- log " ~/projects/personal/pi-backup/restore-pi.sh $ARCHIVE"
227
+ log " ./restore-pi.sh $ARCHIVE"
227
228
  echo
228
229
  }
229
230
 
@@ -1,5 +1,5 @@
1
1
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
- import { execSync, execFileSync } from "node:child_process";
2
+ import { execFileSync } from "node:child_process";
3
3
  import { join, dirname } from "node:path";
4
4
  import { fileURLToPath } from "node:url";
5
5
  import { existsSync, mkdirSync, readdirSync, statSync, readFileSync, writeFileSync, rmSync, cpSync } from "node:fs";
@@ -9,7 +9,7 @@ const IS_WINDOWS = process.platform === "win32";
9
9
  const PI_ROOT = join(HOME_DIR, ".pi");
10
10
  const INTERNAL_BACKUP_DIR = join(PI_ROOT, "backups");
11
11
  const SETTINGS_FILE = join(PI_ROOT, "agent", "settings.json");
12
- const DEFAULT_EXTERNAL_DIR = join(HOME_DIR, "projects", "personal", "pi-utils", "backups");
12
+ const DEFAULT_EXTERNAL_DIR = join(HOME_DIR, "pi-backups");
13
13
  const PACKAGE_ROOT = dirname(dirname(fileURLToPath(import.meta.url)));
14
14
 
15
15
  interface BackupInfo {
@@ -90,6 +90,41 @@ function getRestoreScriptPath(): string {
90
90
  return join(PACKAGE_ROOT, IS_WINDOWS ? "restore-pi.ps1" : "restore-pi.sh");
91
91
  }
92
92
 
93
+ function findSevenZip(): string | null {
94
+ const lookup = IS_WINDOWS ? "where.exe" : "which";
95
+ for (const candidate of ["7zz", "7z", "7za"]) {
96
+ try {
97
+ execFileSync(lookup, [candidate], { stdio: "ignore" });
98
+ return candidate;
99
+ } catch {}
100
+ }
101
+ return null;
102
+ }
103
+
104
+ function expandZipWithPowerShell(archivePath: string, destination: string): void {
105
+ execFileSync("pwsh", [
106
+ "-NoProfile",
107
+ "-Command",
108
+ "Expand-Archive -LiteralPath $env:PI_BACKUP_ARCHIVE -DestinationPath $env:PI_BACKUP_DEST -Force",
109
+ ], {
110
+ env: { ...process.env, PI_BACKUP_ARCHIVE: archivePath, PI_BACKUP_DEST: destination },
111
+ });
112
+ }
113
+
114
+ function extractArchive(archivePath: string, destination: string): void {
115
+ const sevenZip = findSevenZip();
116
+ if (sevenZip) {
117
+ execFileSync(sevenZip, ["x", "-y", `-o${destination}`, archivePath]);
118
+ return;
119
+ }
120
+ if (archivePath.endsWith(".zip")) {
121
+ if (IS_WINDOWS) expandZipWithPowerShell(archivePath, destination);
122
+ else execFileSync("unzip", ["-q", archivePath, "-d", destination]);
123
+ return;
124
+ }
125
+ throw new Error("7zip is required to extract .7z backups and was not found on PATH");
126
+ }
127
+
93
128
  function ensureDirs(externalDir: string) {
94
129
  if (!existsSync(INTERNAL_BACKUP_DIR)) mkdirSync(INTERNAL_BACKUP_DIR, { recursive: true });
95
130
  if (!existsSync(externalDir)) mkdirSync(externalDir, { recursive: true });
@@ -238,12 +273,9 @@ function copyBackupToInternal(backup: BackupInfo): { success: boolean; output: s
238
273
  if (backup.isCompressed) {
239
274
  const tmpDir = join(INTERNAL_BACKUP_DIR, `.tmp-${Date.now()}`);
240
275
  mkdirSync(tmpDir, { recursive: true });
241
- if (backup.name.endsWith(".zip")) {
242
- execSync(`unzip -q "${backup.path}" -d "${tmpDir}"`);
243
- } else {
244
- execSync(`7z x -o"${tmpDir}" "${backup.path}" >/dev/null`);
245
- }
276
+ extractArchive(backup.path, tmpDir);
246
277
  const extracted = readdirSync(tmpDir)[0];
278
+ if (!extracted) throw new Error(`Archive is empty: ${backup.path}`);
247
279
  cpSync(join(tmpDir, extracted), destPath, { recursive: true });
248
280
  rmSync(tmpDir, { recursive: true, force: true });
249
281
  } else {
@@ -432,19 +464,15 @@ async function confirmDelete(ctx: any, backup: BackupInfo) {
432
464
  }
433
465
 
434
466
  async function viewManifest(ctx: any, backup: BackupInfo) {
435
- let manifestPath: string;
467
+ let content: string;
436
468
  if (backup.isCompressed) {
437
469
  const tmpDir = join(INTERNAL_BACKUP_DIR, `.tmp-manifest-${Date.now()}`);
438
470
  mkdirSync(tmpDir, { recursive: true });
439
471
  try {
440
- if (backup.name.endsWith(".zip")) {
441
- execSync(`unzip -q "${backup.path}" "*/MANIFEST.txt" -d "${tmpDir}"`);
442
- } else {
443
- execSync(`7z x -o"${tmpDir}" "${backup.path}" "*/MANIFEST.txt" >/dev/null`);
444
- }
472
+ extractArchive(backup.path, tmpDir);
445
473
  const found = findFile(tmpDir, "MANIFEST.txt");
446
- if (found) manifestPath = found;
447
- else throw new Error("MANIFEST.txt not found in archive");
474
+ if (!found) throw new Error("MANIFEST.txt not found in archive");
475
+ content = readFileSync(found, "utf-8");
448
476
  } catch (e: any) {
449
477
  ctx.ui.notify(`Failed to extract manifest: ${e.message}`, "error");
450
478
  rmSync(tmpDir, { recursive: true, force: true });
@@ -452,15 +480,14 @@ async function viewManifest(ctx: any, backup: BackupInfo) {
452
480
  }
453
481
  rmSync(tmpDir, { recursive: true, force: true });
454
482
  } else {
455
- manifestPath = join(backup.path, "MANIFEST.txt");
456
- }
457
-
458
- if (!existsSync(manifestPath)) {
459
- ctx.ui.notify("No manifest found in backup", "warning");
460
- return;
483
+ const manifestPath = join(backup.path, "MANIFEST.txt");
484
+ if (!existsSync(manifestPath)) {
485
+ ctx.ui.notify("No manifest found in backup", "warning");
486
+ return;
487
+ }
488
+ content = readFileSync(manifestPath, "utf-8");
461
489
  }
462
490
 
463
- const content = readFileSync(manifestPath, "utf-8");
464
491
  await ctx.ui.editor(`MANIFEST — ${backup.name}`, content);
465
492
  }
466
493
 
@@ -515,7 +542,7 @@ The external backup directory is resolved in this order:
515
542
 
516
543
  1. **BACKUP_ROOT** environment variable (highest priority)
517
544
  2. **settings.json** → \`externalBackupDir\`
518
- 3. **Default**: \`~/projects/personal/pi-utils/backups/\`
545
+ 3. **Default**: \`~/pi-backups/\`
519
546
 
520
547
  Use **⚙️ Configure external backup directory** in the main menu to change the settings.json value.
521
548
 
@@ -540,13 +567,13 @@ Use **⚙️ Configure external backup directory** in the main menu to change th
540
567
 
541
568
  \`\`\`bash
542
569
  # Create external backup (uses BACKUP_ROOT or default)
543
- ~/projects/personal/pi-backup/backup-pi.sh
570
+ ./backup-pi.sh
544
571
 
545
572
  # Override backup location
546
- BACKUP_ROOT=/mnt/backups ~/projects/personal/pi-backup/backup-pi.sh
573
+ BACKUP_ROOT=/mnt/backups ./backup-pi.sh
547
574
 
548
575
  # Restore from external
549
- ~/projects/personal/pi-backup/restore-pi.sh ~/projects/personal/pi-utils/backups/pi-backup-20260811-143000
576
+ ./restore-pi.sh ~/pi-backups/pi-backup-20260811-143000
550
577
  \`\`\`
551
578
 
552
579
  ## What Gets Backed Up
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jamiefutch/pi-backup",
3
- "version": "1.1.9",
3
+ "version": "1.1.11",
4
4
  "description": "Pi package: Pi backup/restore scripts and TUI extension. Back up and restore all Pi config, skills, extensions, and memory; /pi-backup interactive manager.",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -73,7 +73,7 @@ Log "================================================================"
73
73
  OK "Clean reinstall complete!"
74
74
  Write-Host ""
75
75
  Log "Next steps:"
76
- Log " 1. Restore: ~/projects/personal/pi-backup/restore-pi.ps1 <backup-dir>"
76
+ Log " 1. Restore: ./restore-pi.ps1 <backup-dir>"
77
77
  Log " 2. Reinstall npm deps: cd ~/.pi/agent && npm install"
78
78
  Log " 3. Verify: pi --version, /ctx-doctor, /loop-police-status, /scoped-memory-status"
79
79
  Write-Host ""
@@ -85,7 +85,7 @@ main() {
85
85
  ok "Clean reinstall complete!"
86
86
  echo
87
87
  log "Next steps:"
88
- log " 1. Restore: ~/projects/personal/pi-backup/restore-pi.sh <backup-dir>"
88
+ log " 1. Restore: ./restore-pi.sh <backup-dir>"
89
89
  log " 2. Reinstall npm deps: cd ~/.pi/agent && npm install"
90
90
  log " 3. Verify: pi --version, /ctx-doctor, /loop-police-status, /scoped-memory-status"
91
91
  echo
package/restore-pi.ps1 CHANGED
@@ -4,8 +4,8 @@
4
4
  #
5
5
  # Usage:
6
6
  # .\restore-pi.ps1 <backup-directory-or-archive>
7
- # .\restore-pi.ps1 ~\projects\personal\pi-utils\backups\pi-backup-20260811-143000
8
- # .\restore-pi.ps1 ~\projects\personal\pi-utils\backups\pi-backup-20260811-143000.zip
7
+ # .\restore-pi.ps1 ~\pi-backups\pi-backup-20260811-143000
8
+ # .\restore-pi.ps1 ~\pi-backups\pi-backup-20260811-143000.zip
9
9
  # =============================================================
10
10
  [CmdletBinding()]
11
11
  param(
@@ -17,6 +17,7 @@ $ErrorActionPreference = 'Stop'
17
17
 
18
18
  # ─── Config ────────────────────────────────────────────────
19
19
  $PiRoot = if ($env:PI_ROOT) { $env:PI_ROOT } else { Join-Path $HOME '.pi' }
20
+ $LocalExtRoot = if ($env:LOCAL_EXT_ROOT) { $env:LOCAL_EXT_ROOT } else { Join-Path $HOME 'projects' }
20
21
 
21
22
  function Log { Write-Host "[INFO] $args" -ForegroundColor Cyan }
22
23
  function OK { Write-Host "[OK] $args" -ForegroundColor Green }
@@ -30,10 +31,10 @@ Usage: $($MyInvocation.MyCommand.Name) <backup-directory-or-archive>
30
31
  Restores a Pi backup created by backup-pi.ps1
31
32
 
32
33
  Examples:
33
- .\$($MyInvocation.MyCommand.Name) ~\projects\personal\pi-utils\backups\pi-backup-20260811-143000
34
- .\$($MyInvocation.MyCommand.Name) ~\projects\personal\pi-utils\backups\pi-backup-20260811-143000.zip
34
+ .\$($MyInvocation.MyCommand.Name) ~\pi-backups\pi-backup-20260811-143000
35
+ .\$($MyInvocation.MyCommand.Name) ~\pi-backups\pi-backup-20260811-143000.zip
35
36
 
36
- Accepts either an uncompressed backup directory or a compressed zip archive
37
+ Accepts either an uncompressed backup directory or a compressed zip/7z archive
37
38
  (as produced by backup-pi.ps1).
38
39
 
39
40
  Prerequisites:
@@ -48,17 +49,32 @@ if (-not $BackupArg) { Show-Usage }
48
49
  # ─── Archive handling ─────────────────────────────────────
49
50
  $STAGE = $null
50
51
  $BackupDir = $null
52
+ $SevenZip = @('7zz', '7z', '7za') | ForEach-Object { Get-Command $_ -ErrorAction SilentlyContinue } | Select-Object -First 1
51
53
 
52
54
  if (Test-Path -LiteralPath $BackupArg -PathType Container) {
53
55
  # Uncompressed directory backup
54
56
  $BackupDir = $BackupArg
55
- } elseif (Test-Path -LiteralPath $BackupArg) {
56
- # Compressed zip archive: extract to a temp dir first
57
+ } elseif (Test-Path -LiteralPath $BackupArg -PathType Leaf) {
58
+ # Compressed archive: prefer 7zip when installed, otherwise use native ZIP support.
59
+ $extension = [System.IO.Path]::GetExtension($BackupArg).ToLowerInvariant()
60
+ if ($extension -notin @('.zip', '.7z')) {
61
+ Err "Unsupported backup archive: $BackupArg (need .zip or .7z)"
62
+ exit 1
63
+ }
64
+ if ($extension -eq '.7z' -and -not $SevenZip) {
65
+ Err "7zip is required to extract .7z backups. Install 7-Zip and ensure it is on PATH."
66
+ exit 1
67
+ }
57
68
  $STAGE = Join-Path $env:TEMP ("pi-restore-" + [guid]::NewGuid().ToString('N'))
58
69
  New-Item -ItemType Directory -Path $STAGE -Force | Out-Null
59
70
  Log "Extracting archive: $BackupArg"
60
71
  try {
61
- Expand-Archive -LiteralPath $BackupArg -DestinationPath $STAGE -Force
72
+ if ($SevenZip) {
73
+ & $SevenZip.Source x -y "-o$STAGE" $BackupArg | Out-Null
74
+ if ($LASTEXITCODE -ne 0) { throw "7zip exited with code $LASTEXITCODE" }
75
+ } else {
76
+ Expand-Archive -LiteralPath $BackupArg -DestinationPath $STAGE -Force
77
+ }
62
78
  } catch {
63
79
  Err "Failed to extract archive: $($_.Exception.Message)"
64
80
  Remove-Item -LiteralPath $STAGE -Recurse -Force -ErrorAction SilentlyContinue
@@ -70,7 +86,7 @@ if (Test-Path -LiteralPath $BackupArg -PathType Container) {
70
86
  $BackupDir = $top.FullName
71
87
  Log "Extracted to: $BackupDir"
72
88
  } else {
73
- Err "Backup not found: $BackupArg (need a directory or .zip)"
89
+ Err "Backup not found: $BackupArg (need a directory, .zip, or .7z)"
74
90
  exit 1
75
91
  }
76
92
 
@@ -187,7 +203,7 @@ Log "5/8 Local extension source code..."
187
203
  $localSrc = Join-Path $BackupDir 'local-extensions'
188
204
  if (Test-Path -LiteralPath $localSrc -PathType Container) {
189
205
  foreach ($ext in Get-ChildItem -LiteralPath $localSrc -Directory) {
190
- $dst = Join-Path $HOME "projects\personal\$($ext.Name)"
206
+ $dst = Join-Path $LocalExtRoot $ext.Name
191
207
  New-Item -ItemType Directory -Path $dst -Force | Out-Null
192
208
  Copy-Tree $ext.FullName $dst
193
209
  OK " $($ext.Name)/ restored"
package/restore-pi.sh CHANGED
@@ -6,6 +6,7 @@ set -euo pipefail
6
6
 
7
7
  # ─── Config ──────────────────────────────────────────────────────
8
8
  PI_ROOT="${PI_ROOT:-$HOME/.pi}"
9
+ LOCAL_EXT_ROOT="${LOCAL_EXT_ROOT:-$HOME/projects}"
9
10
 
10
11
  # ─── Colors ──────────────────────────────────────────────────────
11
12
  RED='\033[0;31m'
@@ -27,9 +28,9 @@ Usage: $0 <backup-directory-or-archive>
27
28
  Restores a Pi backup created by backup-pi.sh
28
29
 
29
30
  Examples:
30
- $0 ~/projects/personal/pi-utils/backups/pi-backup-20260811-143000
31
- $0 ~/projects/personal/pi-utils/backups/pi-backup-20260811-143000.7z
32
- $0 ~/projects/personal/pi-utils/backups/pi-backup-20260811-143000.zip
31
+ $0 ~/pi-backups/pi-backup-20260811-143000
32
+ $0 ~/pi-backups/pi-backup-20260811-143000.7z
33
+ $0 ~/pi-backups/pi-backup-20260811-143000.zip
33
34
 
34
35
  Accepts either an uncompressed backup directory or a compressed
35
36
  zip/7z archive (as produced by backup-pi.sh).
@@ -60,19 +61,13 @@ elif [[ -f "$BACKUP_ARG" && "$BACKUP_ARG" =~ \.(zip|7z)$ ]]; then
60
61
  # Compressed archive: extract to a temp dir first
61
62
  STAGE="$(mktemp -d)"
62
63
  log "Extracting archive: $BACKUP_ARG"
63
- if [[ "$BACKUP_ARG" == *.zip ]]; then
64
- if command -v unzip >/dev/null 2>&1; then
65
- unzip -q "$BACKUP_ARG" -d "$STAGE"
66
- else
67
- # 7z can also extract zip; fall back to it
68
- local tool="$(pick_extract_tool)"
69
- [[ -n "$tool" ]] || { err "No unzip or 7zip available to extract the archive."; exit 1; }
70
- "$tool" x -o"$STAGE" "$BACKUP_ARG" >/dev/null
71
- fi
72
- else
73
- local tool="$(pick_extract_tool)"
74
- [[ -n "$tool" ]] || { err "7zip is required to extract .7z backups. Install it."; exit 1; }
64
+ tool="$(pick_extract_tool)"
65
+ if [[ -n "$tool" ]]; then
75
66
  "$tool" x -o"$STAGE" "$BACKUP_ARG" >/dev/null
67
+ elif [[ "$BACKUP_ARG" == *.zip ]] && command -v unzip >/dev/null 2>&1; then
68
+ unzip -q "$BACKUP_ARG" -d "$STAGE"
69
+ else
70
+ err "No 7zip or native ZIP extractor available for $BACKUP_ARG."; exit 1
76
71
  fi
77
72
  # The archive holds one top-level pi-backup-* dir
78
73
  BACKUP_DIR="$(find "$STAGE" -mindepth 1 -maxdepth 1 -type d | head -1)"
@@ -177,8 +172,8 @@ main() {
177
172
  for ext in "$BACKUP_DIR/local-extensions"/*/; do
178
173
  [[ -d "$ext" ]] || continue
179
174
  name="$(basename "$ext")"
180
- mkdir -p "$HOME/projects/personal/$name"
181
- rsync -a "$ext/" "$HOME/projects/personal/$name/"
175
+ mkdir -p "$LOCAL_EXT_ROOT/$name"
176
+ rsync -a "$ext/" "$LOCAL_EXT_ROOT/$name/"
182
177
  ok " $name/ restored"
183
178
  done
184
179
  else