chief-clancy 0.1.4 → 0.1.6

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/bin/install.js CHANGED
@@ -48,6 +48,13 @@ async function choose(question, options, defaultChoice = 1) {
48
48
  return raw.trim() || String(defaultChoice);
49
49
  }
50
50
 
51
+ const crypto = require('crypto');
52
+
53
+ function fileHash(filePath) {
54
+ const content = fs.readFileSync(filePath);
55
+ return crypto.createHash('sha256').digest('hex', content);
56
+ }
57
+
51
58
  function copyDir(src, dest) {
52
59
  // Use lstatSync (not statSync) to detect symlinks — statSync follows them and misreports
53
60
  if (fs.existsSync(dest)) {
@@ -64,6 +71,73 @@ function copyDir(src, dest) {
64
71
  }
65
72
  }
66
73
 
74
+ /**
75
+ * Build a manifest of installed files with SHA-256 hashes.
76
+ * Format: { "relative/path.md": "<sha256>", ... }
77
+ */
78
+ function buildManifest(baseDir) {
79
+ const manifest = {};
80
+ function walk(dir, prefix) {
81
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
82
+ const full = path.join(dir, entry.name);
83
+ const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
84
+ if (entry.isDirectory()) {
85
+ walk(full, rel);
86
+ } else {
87
+ const content = fs.readFileSync(full);
88
+ manifest[rel] = crypto.createHash('sha256').update(content).digest('hex');
89
+ }
90
+ }
91
+ }
92
+ walk(baseDir, '');
93
+ return manifest;
94
+ }
95
+
96
+ /**
97
+ * Detect files modified by the user since last install by comparing
98
+ * current file hashes against the stored manifest. Returns array of
99
+ * { rel, absPath } for modified files.
100
+ */
101
+ function detectModifiedFiles(baseDir, manifestPath) {
102
+ if (!fs.existsSync(manifestPath)) return [];
103
+ let manifest;
104
+ try {
105
+ manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
106
+ } catch { return []; }
107
+
108
+ const modified = [];
109
+ for (const [rel, hash] of Object.entries(manifest)) {
110
+ const absPath = path.join(baseDir, rel);
111
+ if (!fs.existsSync(absPath)) continue;
112
+ const content = fs.readFileSync(absPath);
113
+ const currentHash = crypto.createHash('sha256').update(content).digest('hex');
114
+ if (currentHash !== hash) {
115
+ modified.push({ rel, absPath });
116
+ }
117
+ }
118
+ return modified;
119
+ }
120
+
121
+ /**
122
+ * Back up modified files to a patches directory alongside the install.
123
+ * Returns the backup directory path if any files were backed up.
124
+ */
125
+ function backupModifiedFiles(modified, patchesDir) {
126
+ if (modified.length === 0) return null;
127
+ fs.mkdirSync(patchesDir, { recursive: true });
128
+ for (const { rel, absPath } of modified) {
129
+ const backupPath = path.join(patchesDir, rel);
130
+ fs.mkdirSync(path.dirname(backupPath), { recursive: true });
131
+ fs.copyFileSync(absPath, backupPath);
132
+ }
133
+ // Write metadata so /clancy:update workflow knows what was backed up
134
+ fs.writeFileSync(
135
+ path.join(patchesDir, 'backup-meta.json'),
136
+ JSON.stringify({ backed_up: modified.map(m => m.rel), date: new Date().toISOString() }, null, 2)
137
+ );
138
+ return patchesDir;
139
+ }
140
+
67
141
  async function main() {
68
142
  console.log('');
69
143
  console.log(blue(' ██████╗██╗ █████╗ ███╗ ██╗ ██████╗██╗ ██╗'));
@@ -115,14 +189,42 @@ async function main() {
115
189
  console.log(dim(` Installing to: ${dest}`));
116
190
 
117
191
  try {
192
+ // Determine manifest and patches paths (sibling to commands dir)
193
+ const claudeDir = path.dirname(path.dirname(dest)); // .claude/ (parent of commands/)
194
+ const manifestPath = path.join(claudeDir, 'clancy', 'manifest.json');
195
+ const patchesDir = path.join(claudeDir, 'clancy', 'local-patches');
196
+
118
197
  if (fs.existsSync(dest) || fs.existsSync(workflowsDest)) {
119
198
  console.log('');
199
+
200
+ // Detect user-modified files before overwriting
201
+ const modified = detectModifiedFiles(dest, manifestPath);
202
+ const modifiedWorkflows = detectModifiedFiles(workflowsDest, manifestPath.replace('manifest.json', 'workflows-manifest.json'));
203
+ const allModified = [...modified, ...modifiedWorkflows];
204
+
205
+ if (allModified.length > 0) {
206
+ console.log(blue(' Modified files detected:'));
207
+ for (const { rel } of allModified) {
208
+ console.log(` ${dim('•')} ${rel}`);
209
+ }
210
+ console.log('');
211
+ console.log(dim(' These will be backed up to .claude/clancy/local-patches/'));
212
+ console.log(dim(' before overwriting. You can reapply them after the update.'));
213
+ console.log('');
214
+ }
215
+
120
216
  const overwrite = await ask(blue(` Commands already exist at ${dest}. Overwrite? [y/N] `));
121
217
  if (!overwrite.trim().toLowerCase().startsWith('y')) {
122
218
  console.log('\n Aborted. No files changed.');
123
219
  rl.close();
124
220
  process.exit(0);
125
221
  }
222
+
223
+ // Back up modified files before overwriting
224
+ if (allModified.length > 0) {
225
+ backupModifiedFiles(allModified, patchesDir);
226
+ console.log(green(`\n ✓ ${allModified.length} modified file(s) backed up to local-patches/`));
227
+ }
126
228
  }
127
229
 
128
230
  copyDir(COMMANDS_SRC, dest);
@@ -149,6 +251,14 @@ async function main() {
149
251
  // Write VERSION file so /clancy:doctor and /clancy:update can read the installed version
150
252
  fs.writeFileSync(path.join(dest, 'VERSION'), PKG.version);
151
253
 
254
+ // Write manifests so future updates can detect user-modified files
255
+ fs.mkdirSync(path.dirname(manifestPath), { recursive: true });
256
+ fs.writeFileSync(manifestPath, JSON.stringify(buildManifest(dest), null, 2));
257
+ fs.writeFileSync(
258
+ manifestPath.replace('manifest.json', 'workflows-manifest.json'),
259
+ JSON.stringify(buildManifest(workflowsDest), null, 2)
260
+ );
261
+
152
262
  console.log('');
153
263
  console.log(green(' ✓ Clancy installed successfully.'));
154
264
  console.log('');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chief-clancy",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Autonomous, board-driven development for Claude Code — scaffolds docs, integrates Kanban boards, runs tickets in a loop.",
5
5
  "keywords": [
6
6
  "claude",
@@ -336,9 +336,50 @@ When updating a value:
336
336
 
337
337
  ---
338
338
 
339
+ ### Save as global defaults
340
+
341
+ At the bottom of the settings menu (before Exit), show:
342
+
343
+ ```
344
+ [{N}] Save as defaults save current settings for all future projects
345
+ ```
346
+
347
+ When selected:
348
+
349
+ 1. Read the current `.clancy/.env` and extract only the non-credential, non-board-specific settings:
350
+ - `MAX_ITERATIONS`
351
+ - `CLANCY_MODEL`
352
+ - `CLANCY_BASE_BRANCH`
353
+ - `PLAYWRIGHT_ENABLED`
354
+ - `PLAYWRIGHT_STARTUP_WAIT`
355
+
356
+ 2. Write these to `~/.clancy/defaults.json`:
357
+ ```json
358
+ {
359
+ "MAX_ITERATIONS": "5",
360
+ "CLANCY_MODEL": "claude-sonnet-4-6",
361
+ "CLANCY_BASE_BRANCH": "main"
362
+ }
363
+ ```
364
+
365
+ 3. Print: `✓ Defaults saved to ~/.clancy/defaults.json — new projects will inherit these settings.`
366
+
367
+ 4. Loop back to the settings menu.
368
+
369
+ **Never save credentials, board-specific settings (status filter, sprint, label), or webhook URLs to global defaults.**
370
+
371
+ ---
372
+
373
+ ## Step 6 — Load global defaults during init
374
+
375
+ When `/clancy:init` creates `.clancy/.env`, check if `~/.clancy/defaults.json` exists. If so, pre-populate the `.env` with those values instead of the built-in defaults. The user's answers during init still take priority — defaults are only used for settings that init doesn't ask about (max iterations, model, etc.).
376
+
377
+ ---
378
+
339
379
  ## Notes
340
380
 
341
381
  - All changes are written to `.clancy/.env` immediately after confirmation
342
382
  - Switching boards verifies credentials before making any changes — nothing is written if verification fails
343
383
  - `/clancy:init` remains available for a full re-setup (re-scaffolds scripts and docs)
344
384
  - This command never restarts any servers or triggers any ticket processing
385
+ - Global defaults (`~/.clancy/defaults.json`) are optional — if the file doesn't exist, built-in defaults are used
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## Overview
4
4
 
5
- Remove Clancy's slash commands from the local project, globally, or both. Optionally remove the `.clancy/` project folder (which includes `.clancy/.env`). Never touch `CLAUDE.md` under any circumstances.
5
+ Remove Clancy's slash commands from the local project, globally, or both. Optionally remove the `.clancy/` project folder (which includes `.clancy/.env`). Clean up CLAUDE.md and .gitignore changes made during init.
6
6
 
7
7
  ---
8
8
 
@@ -41,7 +41,46 @@ If "Both" was chosen in Step 1: confirm once for both, remove all four directori
41
41
 
42
42
  ---
43
43
 
44
- ## Step 3 — Offer to remove .clancy/ (if present)
44
+ ## Step 3 — Clean up CLAUDE.md
45
+
46
+ Check whether `CLAUDE.md` exists in the current project directory.
47
+
48
+ If it does, check for Clancy markers (`<!-- clancy:start -->` and `<!-- clancy:end -->`):
49
+
50
+ **If markers found:**
51
+
52
+ Read the full file content. Determine whether Clancy created the file or appended to an existing one:
53
+
54
+ - **Clancy created it** (the file contains only whitespace outside the markers — no meaningful content before `<!-- clancy:start -->` or after `<!-- clancy:end -->`): delete the entire file.
55
+ - **Clancy appended to an existing file** (there is meaningful content outside the markers): remove everything from `<!-- clancy:start -->` through `<!-- clancy:end -->` (inclusive), plus any blank lines immediately before the start marker that were added as spacing. Write the cleaned file back.
56
+
57
+ Print `✓ CLAUDE.md cleaned up.` (or `✓ CLAUDE.md removed.` if deleted).
58
+
59
+ **If no markers found:** skip — Clancy didn't modify this file.
60
+
61
+ **If CLAUDE.md does not exist:** skip.
62
+
63
+ ---
64
+
65
+ ## Step 4 — Clean up .gitignore
66
+
67
+ Check whether `.gitignore` exists in the current project directory.
68
+
69
+ If it does, check whether it contains the Clancy entries (`# Clancy credentials` and/or `.clancy/.env`):
70
+
71
+ **If found:** remove the `# Clancy credentials` comment line and the `.clancy/.env` line. Also remove any blank line immediately before or after the removed block to avoid leaving double blank lines. Write the cleaned file back.
72
+
73
+ If the file is now empty (or contains only whitespace) after removal, delete it entirely — Clancy created it during init.
74
+
75
+ Print `✓ .gitignore cleaned up.` (or `✓ .gitignore removed.` if deleted).
76
+
77
+ **If not found:** skip — Clancy didn't modify this file.
78
+
79
+ **If .gitignore does not exist:** skip.
80
+
81
+ ---
82
+
83
+ ## Step 5 — Offer to remove .clancy/ (if present)
45
84
 
46
85
  Check whether `.clancy/` exists in the current project directory.
47
86
 
@@ -59,7 +98,7 @@ If `.clancy/` does not exist, skip this step entirely.
59
98
 
60
99
  ---
61
100
 
62
- ## Step 4 — Final message
101
+ ## Step 6 — Final message
63
102
 
64
103
  ```
65
104
  Clancy uninstalled. To reinstall: npx chief-clancy
@@ -69,7 +108,6 @@ Clancy uninstalled. To reinstall: npx chief-clancy
69
108
 
70
109
  ## Hard constraints
71
110
 
72
- - **Never touch any `.env` at the project root** — Clancy's credentials live in `.clancy/.env` and are only removed as part of `.clancy/` in Step 3
73
- - **Never touch `CLAUDE.md`**under any circumstances, in any scenario
74
- - Steps 1–2 (commands removal) and Step 3 (`.clancy/` removal) are always asked separately never bundle them into one confirmation
75
- - If the user says no to commands removal in Step 2, skip Step 3 entirely and stop
111
+ - **Never touch any `.env` at the project root** — Clancy's credentials live in `.clancy/.env` and are only removed as part of `.clancy/` in Step 5
112
+ - Steps 1–2 (commands removal), Steps 3–4 (CLAUDE.md and .gitignore cleanup), and Step 5 (`.clancy/` removal) are always asked separately never bundle them into one confirmation
113
+ - If the user says no to commands removal in Step 2, skip all remaining steps and stop
@@ -2,66 +2,201 @@
2
2
 
3
3
  ## Overview
4
4
 
5
- Update Clancy itself to the latest version via npx.
5
+ Check for Clancy updates via npm, display changelog for versions between installed and latest, obtain user confirmation, and execute clean installation.
6
6
 
7
7
  ---
8
8
 
9
- ## Step 1 — Check current version
9
+ ## Step 1 — Detect installed version
10
10
 
11
- Read current version from the installed package (check `~/.claude/commands/clancy/` or `./.claude/commands/clancy/` for a `VERSION` file, or from npm).
11
+ Determine whether Clancy is installed locally or globally by checking both locations:
12
12
 
13
13
  ```bash
14
- npm view chief-clancy version 2>/dev/null || echo "unknown"
14
+ LOCAL_VERSION_FILE="./.claude/commands/clancy/VERSION"
15
+ GLOBAL_VERSION_FILE="$HOME/.claude/commands/clancy/VERSION"
16
+
17
+ if [ -f "$LOCAL_VERSION_FILE" ] && grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+' "$LOCAL_VERSION_FILE"; then
18
+ INSTALLED=$(cat "$LOCAL_VERSION_FILE")
19
+ INSTALL_TYPE="LOCAL"
20
+ elif [ -f "$GLOBAL_VERSION_FILE" ] && grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+' "$GLOBAL_VERSION_FILE"; then
21
+ INSTALLED=$(cat "$GLOBAL_VERSION_FILE")
22
+ INSTALL_TYPE="GLOBAL"
23
+ else
24
+ INSTALLED="unknown"
25
+ INSTALL_TYPE="UNKNOWN"
26
+ fi
27
+
28
+ echo "$INSTALLED"
29
+ echo "$INSTALL_TYPE"
15
30
  ```
16
31
 
32
+ Parse output:
33
+ - First line = installed version (or "unknown")
34
+ - Second line = install type (LOCAL, GLOBAL, or UNKNOWN)
35
+
36
+ **If version is unknown:**
37
+ ```
38
+ ## Clancy Update
39
+
40
+ **Installed version:** Unknown
41
+
42
+ Your installation doesn't include version tracking.
43
+
44
+ Running fresh install...
45
+ ```
46
+
47
+ Proceed to Step 4 (treat as version 0.0.0 for comparison).
48
+
17
49
  ---
18
50
 
19
- ## Step 2 — Run the updater
51
+ ## Step 2 — Check latest version
52
+
53
+ Check npm for the latest published version:
54
+
55
+ ```bash
56
+ npm view chief-clancy version 2>/dev/null
57
+ ```
58
+
59
+ **If npm check fails:**
60
+ ```
61
+ Couldn't check for updates (offline or npm unavailable).
62
+
63
+ To update manually: `npx chief-clancy@latest`
64
+ ```
65
+
66
+ Exit.
67
+
68
+ ---
69
+
70
+ ## Step 3 — Compare versions and confirm
71
+
72
+ Compare installed vs latest:
73
+
74
+ **If installed == latest:**
75
+ ```
76
+ ## Clancy Update
77
+
78
+ **Installed:** X.Y.Z
79
+ **Latest:** X.Y.Z
80
+
81
+ You're already on the latest version.
82
+ ```
83
+
84
+ Exit.
85
+
86
+ **If update available**, fetch the changelog from GitHub and show what's new BEFORE updating:
87
+
88
+ ```bash
89
+ curl -s https://raw.githubusercontent.com/Pushedskydiver/clancy/main/CHANGELOG.md
90
+ ```
91
+
92
+ Extract only the entries between the installed version and the latest version. Display:
20
93
 
21
94
  ```
22
- Updating Clancy...
95
+ ## Clancy Update Available
96
+
97
+ **Installed:** {installed}
98
+ **Latest:** {latest}
99
+
100
+ ### What's New
101
+ ────────────────────────────────────────────────────────────
102
+
103
+ {relevant CHANGELOG entries between installed and latest}
104
+
105
+ ────────────────────────────────────────────────────────────
106
+
107
+ ⚠️ **Note:** The update performs a clean install of Clancy command folders:
108
+ - `.claude/commands/clancy/` will be replaced
109
+ - `.claude/clancy/workflows/` will be replaced
110
+
111
+ If you've modified any Clancy files directly, they'll be automatically backed up
112
+ to `.claude/clancy/local-patches/` before overwriting.
113
+
114
+ Your project files are preserved:
115
+ - `.clancy/` project folder (scripts, docs, .env, progress log) ✓
116
+ - `CLAUDE.md` ✓
117
+ - Custom commands not in `commands/clancy/` ✓
118
+ - Custom hooks ✓
23
119
  ```
24
120
 
25
- Run:
121
+ Ask the user: **"Proceed with update?"** with options:
122
+ - "Yes, update now"
123
+ - "No, cancel"
124
+
125
+ **If user cancels:** Exit.
126
+
127
+ ---
128
+
129
+ ## Step 4 — Run the update
130
+
131
+ Run the installer using the detected install type:
132
+
26
133
  ```bash
27
- npx chief-clancy@latest
134
+ npx -y chief-clancy@latest
28
135
  ```
29
136
 
30
- This re-runs the installer, which copies the latest command files into the correct `.claude/commands/clancy/` directory (global or local, matching the existing install location).
137
+ The installer auto-detects whether to install globally or locally based on the existing install.
31
138
 
32
- The update only touches `.claude/commands/clancy/` (slash commands and workflows). It never modifies:
33
- - `.clancy/clancy-once.sh` or `.clancy/clancy-afk.sh` — shell scripts are not updated
34
- - `.clancy/docs/` codebase documentation
35
- - `.clancy/progress.txt` progress log
36
- - `.clancy/.env` credentials
139
+ This only touches `.claude/commands/clancy/` and `.claude/clancy/workflows/`. It never modifies:
140
+ - `.clancy/clancy-once.sh` or `.clancy/clancy-afk.sh` — shell scripts
141
+ - `.clancy/docs/` codebase documentation
142
+ - `.clancy/progress.txt` progress log
143
+ - `.clancy/.env` credentials
37
144
  - `CLAUDE.md`
38
145
 
39
- **To update the shell scripts** (`.clancy/clancy-once.sh`, `.clancy/clancy-afk.sh`), re-run `/clancy:init` — it will detect the existing setup and re-scaffold the scripts without asking for credentials again.
146
+ **To update the shell scripts**, re-run `/clancy:init` — it will detect the existing setup and re-scaffold the scripts without asking for credentials again.
40
147
 
41
148
  ---
42
149
 
43
- ## Step 3Show changelog diff
150
+ ## Step 5Clear update cache and confirm
44
151
 
45
- After update, fetch and display the CHANGELOG section for any versions between old and new:
152
+ Clear the update check cache so the statusline indicator disappears:
46
153
 
154
+ ```bash
155
+ rm -f "$HOME/.claude/cache/clancy-update-check.json"
156
+ rm -f "./.claude/cache/clancy-update-check.json"
47
157
  ```
48
- Updated Clancy from v{old} to v{new}.
49
158
 
50
- What's new:
51
- {relevant CHANGELOG entries}
159
+ Display completion message:
160
+
161
+ ```
162
+ ╔═══════════════════════════════════════════════════════════╗
163
+ ║ Clancy Updated: v{old} → v{new} ║
164
+ ╚═══════════════════════════════════════════════════════════╝
165
+
166
+ ⚠️ Restart Claude Code to pick up the new commands.
52
167
 
53
168
  View full changelog: github.com/Pushedskydiver/clancy/blob/main/CHANGELOG.md
54
169
  ```
55
170
 
56
- If version is already latest:
171
+ ---
172
+
173
+ ## Step 6 — Check for local patches
174
+
175
+ After the update completes, check if the installer backed up any locally modified files:
176
+
177
+ Check for `.claude/clancy/local-patches/backup-meta.json` (local install) or `~/.claude/clancy/local-patches/backup-meta.json` (global install).
178
+
179
+ **If patches were found:**
180
+
57
181
  ```
58
- Clancy is already up to date (v{version}).
182
+ Local patches were backed up before the update.
183
+ Your modified files are in .claude/clancy/local-patches/
184
+
185
+ To review what changed:
186
+ Compare each file in local-patches/ against its counterpart in
187
+ .claude/commands/clancy/ or .claude/clancy/workflows/ and manually
188
+ reapply any customisations you want to keep.
189
+
190
+ Backed up files:
191
+ {list from backup-meta.json}
59
192
  ```
60
193
 
194
+ **If no patches:** Continue normally (no message needed).
195
+
61
196
  ---
62
197
 
63
198
  ## Notes
64
199
 
65
200
  - If the user installed globally, the update applies globally
66
201
  - If the user installed locally, the update applies locally
67
- - After updating, the new commands take effect immediately in Claude Code
202
+ - After updating, restart Claude Code for new commands to take effect