codewhale.history 2.3.0 → 2.5.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codewhale.history",
3
- "version": "2.3.0",
3
+ "version": "2.5.0",
4
4
  "description": "CodeWhale utility commands: session history, tool listing, file snapshot — global install",
5
5
  "bin": {
6
6
  "codewhale-history": "./_list_sessions.js",
@@ -10,17 +10,35 @@ When the user types `//snapshot on`, `//snapshot off`, or `//snapshot status`, m
10
10
  ## Behavior
11
11
 
12
12
  ### `//snapshot on`
13
- 1. Check if `.git` exists in the workspace root via `Test-Path .git`.
14
- 2. **If Git repo exists**: reply "This workspace has a Git repo — snapshotting is not needed. Use `git restore <file>` to undo changes."
15
- 3. **If no Git repo**: create `_snapshots/` directory, write a note to persist `snapshot_enabled=true`, then confirm to the user.
16
- 4. From this point forward, before editing any **existing** file:
17
- - Run the following PowerShell command to snapshot with a timestamp:
18
- ```
13
+ 1. Detect the platform from the shell environment:
14
+ - **Windows**: `$env:OS` contains `Windows_NT`, shell is `powershell.exe`
15
+ - **macOS/Linux**: detect by the absence of `$env:OS`, shell is typically `bash` or `zsh`
16
+ 2. Check if `.git` exists in the workspace root:
17
+ - **Windows**: `if (Test-Path .git) { ... }`
18
+ - **macOS/Linux**: `if [ -d .git ]; then ...`
19
+ 3. **If Git repo exists**: reply "This workspace has a Git repo — snapshotting is not needed. Use `git restore <file>` to undo changes."
20
+ 4. **If no Git repo**: create `_snapshots/` directory, write a note to persist `snapshot_enabled=true`, then confirm to the user.
21
+ 5. From this point forward, before editing any **existing** file:
22
+ - **Ensure `_snapshots/` exists** — create it if missing (don't assume it still exists from init time)
23
+ **Windows**: `if (-not (Test-Path '_snapshots')) { New-Item -ItemType Directory -Path '_snapshots' -Force | Out-Null }`
24
+ **macOS/Linux**: `mkdir -p _snapshots`
25
+ - **Snapshot the file** using the appropriate command for the detected platform:
26
+ **Windows (PowerShell):**
27
+ ```powershell
19
28
  $ts = Get-Date -Format 'yyyy-MM-dd_HH-mm-ss'
20
29
  $base = [System.IO.Path]::GetFileNameWithoutExtension('<file>')
21
30
  $ext = [System.IO.Path]::GetExtension('<file>')
22
31
  Copy-Item '<file>' "_snapshots/$base.$ts$ext"
23
32
  ```
33
+ **macOS/Linux (Bash):**
34
+ ```bash
35
+ ts=$(date +%Y-%m-%d_%H-%M-%S)
36
+ base=$(basename "<file>" | sed 's/\.[^.]*$//')
37
+ ext=$(echo "<file>" | sed 's/.*\.//')
38
+ cp "<file>" "_snapshots/${base}.${ts}.${ext}"
39
+ ```
40
+ - **Retry on failure**: if the copy command fails (non-zero exit), recreate `_snapshots/` and retry exactly once.
41
+ - **Final failure**: if the retry also fails, report the error to the user and **do NOT proceed with the edit** — this is a snapshot contract violation.
24
42
  - Result example: `foo.py` → `_snapshots/foo.2026-06-20_11-30-00.py`
25
43
  - Do NOT snapshot brand-new files being created for the first time
26
44