codewhale.history 2.0.0 → 2.2.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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # CodeWhale Tools Pack
2
2
 
3
- A portable pack of global CodeWhale commands: `//tools` and `//history`.
3
+ A portable pack of global CodeWhale commands: `//tools`, `//history`, and `//snapshot`.
4
4
 
5
5
  Cross-platform — works on Windows, Mac, Linux.
6
6
 
@@ -12,7 +12,8 @@ tools_for_codewhale/
12
12
  ├── package.json # npm package config
13
13
  ├── tools-install.js # Cross-platform installer (skills + instructions)
14
14
  ├── skills/
15
- │ ├── history/SKILL.md # //history — calls codewhale-history
15
+ │ ├── history/SKILL.md # //history — calls codewhale-history
16
+ │ ├── snapshot/SKILL.md # //snapshot — pre-edit file backups
16
17
  │ └── tools/tools-skill/SKILL.md # //tools — lists all available tools
17
18
  ├── instructions.md # Trigger config (drop into any .codewhale/)
18
19
  └── README.md # This file
@@ -26,7 +27,7 @@ One command:
26
27
  npm install -g codewhale.history && codewhale-tools-install
27
28
  ```
28
29
 
29
- Then in any CodeWhale workspace, `//tools` and `//history` work immediately.
30
+ Then in any CodeWhale workspace, `//tools`, `//history`, and `//snapshot` work immediately.
30
31
 
31
32
  ### Manual per-workspace install (if already globally installed)
32
33
 
@@ -38,6 +39,7 @@ codewhale-tools-install -p <target-path> # specific workspace
38
39
  ## After install
39
40
  - **`//tools`** — lists every tool available in the current session
40
41
  - **`//history`** — lists all chat sessions for the current workspace with cost totals
42
+ - **`//snapshot`** — toggle pre-edit file backups (`on`, `off`, `status`)
41
43
 
42
44
  ## Requirements
43
45
  - Node.js (for the `codewhale-history` command)
package/instructions.md CHANGED
@@ -5,3 +5,6 @@ When the user types `//tools`, immediately load the `tools` skill (from `tools-s
5
5
 
6
6
  ## //history Command
7
7
  When the user types `//history`, immediately load the `history` skill (from `history/SKILL.md`) and list all CodeWhale chat sessions for the current workspace with message count, tokens, cost, and totals. This works in all sessions once the skill is installed globally.
8
+
9
+ ## //snapshot Command
10
+ When the user types `//snapshot`, immediately load the `snapshot` skill (from `snapshot/SKILL.md`) and follow its instructions. `//snapshot on` enables automatic pre-edit file backups to `_snapshots/` when no Git repo is present. `//snapshot off` disables it. `//snapshot status` reports the current state. This works in all sessions once the skill is installed globally.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "codewhale.history",
3
- "version": "2.0.0",
4
- "description": "CodeWhale utility commands: session history, tool listing — global install",
3
+ "version": "2.2.0",
4
+ "description": "CodeWhale utility commands: session history, tool listing, file snapshot — global install",
5
5
  "bin": {
6
6
  "codewhale-history": "./_list_sessions.js",
7
7
  "codewhale-tools-install": "./tools-install.js"
@@ -0,0 +1,34 @@
1
+ ---
2
+ name: snapshot
3
+ description: Toggle automatic pre-edit file snapshotting on or off. Triggered by //snapshot on and //snapshot off.
4
+ ---
5
+
6
+ # `//snapshot` Command
7
+
8
+ When the user types `//snapshot on`, `//snapshot off`, or `//snapshot status`, manage automatic file backup before edits.
9
+
10
+ ## Behavior
11
+
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 `Copy-Item <file> _snapshots/<relative-path>.<N>` (PowerShell)
18
+ - Increment N per file (v1, v2, v3...)
19
+ - Do NOT snapshot brand-new files being created for the first time
20
+
21
+ ### `//snapshot off`
22
+ 1. Write a note to persist `snapshot_enabled=false`.
23
+ 2. Reply "Snapshotting is now off. Existing snapshots in `_snapshots/` have been preserved."
24
+ 3. Stop snapshotting before future edits.
25
+
26
+ ### `//snapshot status`
27
+ 1. Read the snapshot-enabled note.
28
+ 2. Count files in `_snapshots/` (if directory exists).
29
+ 3. Report: whether snapshotting is on/off, the snapshot directory exists, and file count.
30
+
31
+ ## Notes
32
+ - The skill is installed globally — works in any workspace
33
+ - Snapshot state is session-scoped — does not persist across different CodeWhale sessions
34
+ - Use `//snapshot off` before switching to a Git-tracked project to avoid redundant copies
package/tools-install.js CHANGED
@@ -2,7 +2,7 @@
2
2
  /**
3
3
  * CodeWhale Tools Installer
4
4
  *
5
- * Installs global skills and workspace triggers for //tools and //history.
5
+ * Installs global skills and workspace triggers for //tools, //history, and //snapshot.
6
6
  *
7
7
  * Usage:
8
8
  * node tools-install.js # current directory
@@ -39,7 +39,7 @@ if (fs.existsSync(skillsSource)) {
39
39
  console.log(' WARNING: Skills folder not found.');
40
40
  }
41
41
 
42
- // ── 2. Install instructions ────────────────────────────
42
+ // ── 2. Install instructions (append mode) ──────────────
43
43
  console.log('[2/3] Setting up workspace instructions...');
44
44
  const dotCodeWhale = path.join(workspacePath, '.codewhale');
45
45
  const instructionsDest = path.join(dotCodeWhale, 'instructions.md');
@@ -51,13 +51,21 @@ if (!fs.existsSync(dotCodeWhale)) {
51
51
  }
52
52
 
53
53
  if (fs.existsSync(instructionsSource)) {
54
+ const newContent = fs.readFileSync(instructionsSource, 'utf-8');
54
55
  if (fs.existsSync(instructionsDest)) {
55
- const backup = instructionsDest + '.bak';
56
- fs.cpSync(instructionsDest, backup);
57
- console.log(' Backed up existing instructions.md -> instructions.md.bak');
56
+ const existingContent = fs.readFileSync(instructionsDest, 'utf-8');
57
+ // Only append if it's not already there (idempotent)
58
+ if (!existingContent.includes('## //tools Command') && !existingContent.includes('## //history Command') && !existingContent.includes('## //snapshot Command')) {
59
+ const separator = `\n\n---\n\n`;
60
+ fs.writeFileSync(instructionsDest, existingContent + separator + newContent, 'utf-8');
61
+ console.log(' Appended //tools, //history, and //snapshot instructions to existing instructions.md');
62
+ } else {
63
+ console.log(' //tools, //history, and //snapshot already present in instructions.md — skipped.');
64
+ }
65
+ } else {
66
+ fs.writeFileSync(instructionsDest, newContent, 'utf-8');
67
+ console.log(' Created fresh instructions.md.');
58
68
  }
59
- fs.cpSync(instructionsSource, instructionsDest);
60
- console.log(' instructions.md deployed.');
61
69
  } else {
62
70
  console.log(' WARNING: instructions.md not found.');
63
71
  }
@@ -69,6 +77,7 @@ let errors = 0;
69
77
  const checklist = {
70
78
  'history skill': path.join(skillsDest, 'history', 'SKILL.md'),
71
79
  'tools skill': path.join(skillsDest, 'tools', 'tools-skill', 'SKILL.md'),
80
+ 'snapshot skill': path.join(skillsDest, 'snapshot', 'SKILL.md'),
72
81
  'workspace instructions': instructionsDest
73
82
  };
74
83
 
@@ -85,7 +94,7 @@ console.log('');
85
94
  if (errors === 0) {
86
95
  console.log('=== Installation complete! ===');
87
96
  console.log('Make sure codewhale-history is installed globally: npm install -g <path-to-tools_for_codewhale>');
88
- console.log('Then type //tools or //history in any CodeWhale session.');
97
+ console.log('Then type //tools, //history, or //snapshot in any CodeWhale session.');
89
98
  } else {
90
99
  console.log(`=== Installation finished with ${errors} error(s). ===`);
91
100
  }