@claude-pw/framework 0.5.0 → 0.5.2

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/install.js CHANGED
@@ -15,7 +15,7 @@ const path = require('path');
15
15
  const readline = require('readline');
16
16
  const { execSync } = require('child_process');
17
17
 
18
- const VERSION = '0.3.0';
18
+ const VERSION = require('./package.json').version;
19
19
 
20
20
  // --- Colors ---
21
21
  const c = {
@@ -290,14 +290,18 @@ async function main() {
290
290
  let projectName = '';
291
291
 
292
292
  // Parse arguments
293
- for (const arg of args) {
293
+ let extractDir = null;
294
+ for (let i = 0; i < args.length; i++) {
295
+ const arg = args[i];
294
296
  if (arg === '--update') updateOnly = true;
297
+ else if (arg === '--extract') { extractDir = args[++i]; }
295
298
  else if (arg === '--version') { console.log(`claude-pw ${VERSION}`); process.exit(0); }
296
299
  else if (arg === '--help' || arg === '-h') {
297
300
  console.log('claude-pw — Structured Project Workflow for Claude Code\n');
298
301
  console.log('Usage:');
299
302
  console.log(' claude-pw [project-name] Create new project');
300
303
  console.log(' claude-pw --update Update .claude/ in existing project');
304
+ console.log(' claude-pw --extract <dir> Extract templates to directory (for /cpw-update)');
301
305
  console.log(' claude-pw --version Show version');
302
306
  process.exit(0);
303
307
  } else if (arg.startsWith('-')) {
@@ -318,6 +322,23 @@ async function main() {
318
322
 
319
323
  const date = new Date().toISOString().slice(0, 10);
320
324
 
325
+ // ============================================================
326
+ // EXTRACT MODE (for /cpw-update command)
327
+ // ============================================================
328
+ if (extractDir) {
329
+ if (!extractDir || typeof extractDir !== 'string') {
330
+ error('Usage: --extract <directory>');
331
+ process.exit(1);
332
+ }
333
+ fs.cpSync(templatesDir, extractDir, { recursive: true });
334
+ const releasesFile = path.join(scriptDir, 'RELEASES.md');
335
+ if (fs.existsSync(releasesFile)) {
336
+ fs.copyFileSync(releasesFile, path.join(extractDir, 'RELEASES.md'));
337
+ }
338
+ fs.writeFileSync(path.join(extractDir, '.version'), VERSION);
339
+ process.exit(0);
340
+ }
341
+
321
342
  // ============================================================
322
343
  // UPDATE MODE
323
344
  // ============================================================
@@ -372,15 +393,23 @@ async function main() {
372
393
  console.log(' settings.json (merge, custom hooks preserved)');
373
394
  console.log(' config.json (merge new fields)');
374
395
  if (allModified.length > 0) {
375
- console.log(`\n ${c.yellow('Modified by you (will be overwritten):')}`);
396
+ console.log(`\n ${c.yellow('Modified (differs from new version):')}`);
376
397
  for (const f of allModified) console.log(` ${f}`);
398
+ console.log(`\n For intelligent merge of modified files, use ${c.bold('/cpw-update')} inside Claude instead.`);
377
399
  }
378
400
  console.log(`\n Backup: .claude.backup.* (created before changes)\n`);
379
401
 
380
- const confirm = await askQuestion('Apply? [y/N]: ');
381
- if (!/^[yYsS]$/.test(confirm)) {
382
- info('Cancelled.');
383
- process.exit(0);
402
+ const confirm = await askQuestion(`${allModified.length > 0 ? 'Replace all (r) / Cancel (c): ' : 'Apply? [y/N]: '}`);
403
+ if (allModified.length > 0) {
404
+ if (!/^[rR]$/.test(confirm)) {
405
+ info('Cancelled. Use /cpw-update inside Claude for merge support.');
406
+ process.exit(0);
407
+ }
408
+ } else {
409
+ if (!/^[yYsS]$/.test(confirm)) {
410
+ info('Cancelled.');
411
+ process.exit(0);
412
+ }
384
413
  }
385
414
 
386
415
  // Backup
@@ -428,6 +457,10 @@ async function main() {
428
457
 
429
458
  // Write version
430
459
  fs.writeFileSync(versionFile, VERSION);
460
+
461
+ // Leave marker for /cpw-next-step to detect
462
+ fs.writeFileSync(path.join('.planning', '.updated-from'), installedVersion);
463
+
431
464
  info(`Actualizado a claude-pw v${VERSION}`);
432
465
  process.exit(0);
433
466
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@claude-pw/framework",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "Structured Project Workflow for Claude Code — adaptive pipeline, context management, quality gates",
5
5
  "bin": {
6
6
  "claude-pw": "./install.js"
@@ -2,8 +2,20 @@
2
2
  description: "Load context and execute the next pipeline stage"
3
3
  ---
4
4
 
5
+ ## Arguments
6
+ - No arguments: normal flow (respects `autoAdvance` from config)
7
+ - `--phase`: auto-advance all steps in the current phase, pause at UAT. Overrides `autoAdvance` to `auto` for this invocation only. Does NOT cross to next phase.
8
+
5
9
  ## 0. Health check (session start)
6
10
 
11
+ ### Post-update detection
12
+ If `.planning/.updated-from` exists:
13
+ - Read the file — it contains the previous version
14
+ - Show: "Framework updated from v{old} to v{current}. Running health check..."
15
+ - Delete the file
16
+ - Run `/cpw-health` (full diagnostic, not just session-recovery)
17
+ - After health check completes, continue normally
18
+
7
19
  ### Handoff detection
8
20
  If `.planning/handoff.md` exists:
9
21
  - Show the handoff summary to the user
@@ -25,8 +37,19 @@ Delegate to the session-recovery agent in CHECK mode:
25
37
  - If INCONSISTENT: show diagnostic. Do NOT continue without user decision.
26
38
 
27
39
  ## 1. Load context
40
+
41
+ If STATUS.md does not exist:
42
+ - Report:
43
+ ```
44
+ No STATUS.md found — this project hasn't been initialized yet.
45
+
46
+ Next: run `/cpw-startup` to set up the project.
47
+ ```
48
+ - STOP. Do not continue.
49
+
28
50
  - Read STATUS.md -> phase, step, stage
29
51
  - Read indicated sub-plan (plans/phase-N.md)
52
+ - If the file does not exist: report "Sub-plan plans/phase-N.md not found. STATUS.md may be pointing to a non-existent phase. Run `/cpw-health` to diagnose." STOP.
30
53
  - If `plans/phase-N-context.md` exists (from /cpw-discuss), load it too
31
54
  - Load ONLY files in "Required context" — nothing else
32
55
  - Read `.planning/config.json` -> autoAdvance (off | auto | yolo)
@@ -258,7 +281,7 @@ Then execute the current stage (check docs/tooling.md for tools mapped to this s
258
281
  Max retries: [from `maxConsecutiveFailures` in config, default: 3]
259
282
  Wait for the agent's structured report.
260
283
  - If SUCCESS → proceed to ACCEPTANCE with the report as summary
261
- - If PARTIAL → present partial results to user. Options: continue to ACCEPTANCE / retry / abort
284
+ - If PARTIAL → if autoAdvance is auto/yolo or `--phase`: retry automatically (up to max retries). Otherwise: present partial results to user. Options: continue to ACCEPTANCE / retry / abort
262
285
  - If FAILED → present failure details. Options: retry with modified design / abort step
263
286
  - Deviations field → included in ACCEPTANCE summary for reviewer visibility
264
287
  - **TEST:** The implementer already ran tests. Review its test report.
@@ -309,7 +332,7 @@ If no self-check triggers or gates don't pass: continue normally.
309
332
  ### Auto-reflect check (CLOSE sub-step 5)
310
333
  Read `autoReflect` from `.planning/config.json` (default: "remind").
311
334
  If `autoReflect` is `"auto"` AND `.planning/learnings/queue.md` has entries:
312
- - Run a lightweight reflection (steps 1.5, 2, 4, 5 of /cpw-reflect skip history scan and dedup)
335
+ - Run a lightweight reflection: semantic validation classify each entry with learning-extractor apply approved changes → cleanup queue (skip history scan, skip user presentation for confidence ≥ 0.80, skip dedup)
313
336
  - Auto-approve entries with confidence ≥ 0.80
314
337
  - Present entries with confidence < 0.80 for manual approval
315
338
  - `make commit m="learn: auto-reflect session learnings"`
@@ -319,7 +342,8 @@ Update STATUS.md with the new stage when finished.
319
342
 
320
343
  ## 2. Advance based on mode
321
344
 
322
- Read `autoAdvance` from `.planning/config.json` (default: "off").
345
+ If `--phase` flag was passed, set effective autoAdvance = "auto" for this invocation.
346
+ Otherwise, read `autoAdvance` from `.planning/config.json` (default: "off").
323
347
  Read `maxConsecutiveFailures` from config (default: 3 for auto, 5 for yolo).
324
348
 
325
349
  ### off (default)
@@ -348,7 +372,13 @@ In yolo mode, Claude designs, implements, tests, closes, validates phases, and a
348
372
  - Commit messages are auto-generated in auto and yolo (no pause)
349
373
  - Phase validation always runs automatically when last step completes
350
374
  - Between phases: auto and yolo continue automatically (run tooling audit → next step); off always stops
351
- - If context fills up (3+ auto-advanced steps), suggest /clear and re-invoke /cpw-next-step
375
+ - `--phase` flag: ALWAYS stop between phases, regardless of effective autoAdvance. Report:
376
+ ```
377
+ Phase N complete. UAT next.
378
+
379
+ Next: continue with `/cpw-next-step` for UAT.
380
+ ```
381
+ - If context fills up (3+ auto-advanced steps), suggest /clear and re-invoke /cpw-next-step (add `--phase` if it was active)
352
382
 
353
383
  ## 3. Phase validation (auto-triggered when all steps are done)
354
384
 
@@ -267,12 +267,20 @@ Save responses in `.planning/config.json`:
267
267
  "modelProfile": "quality|balanced|budget",
268
268
  "modelOverrides": {},
269
269
  "gitStrategy": "trunk-based|feature-branch|gitflow",
270
- "commitPlanning": false
270
+ "commitPlanning": false,
271
+ "toolingSources": ["skills.sh", "claude-code-templates"],
272
+ "maxConsecutiveFailures": 3,
273
+ "autoReflect": "remind"
271
274
  }
272
275
  ```
273
276
 
274
277
  If the user has no preference, use defaults (off/standard/balanced/no).
275
278
 
279
+ Advanced settings (not asked during interview — edit `.planning/config.json` directly):
280
+ - `toolingSources`: where to search for skills/MCPs during tooling audit (default: `["skills.sh", "claude-code-templates"]`)
281
+ - `maxConsecutiveFailures`: halt auto-advance after N failures in same stage (default: 3 for auto, 5 for yolo)
282
+ - `autoReflect`: process learning queue automatically (`off` / `remind` / `auto`, default: `remind`)
283
+
276
284
  **If `commitPlanning: true`:**
277
285
  - Remove `.planning/` from `.gitignore`
278
286
  - Planning artifacts (config, learnings, decisions, debug sessions) will be tracked in git
@@ -0,0 +1,119 @@
1
+ ---
2
+ description: "Update claude-pw framework — diff, merge, apply intelligently"
3
+ ---
4
+
5
+ ## 1. Check version
6
+
7
+ ```bash
8
+ INSTALLED=$(cat .claude/.claude-pw-version 2>/dev/null || echo "0.0.0")
9
+ AVAILABLE=$(npx @claude-pw/framework --version 2>/dev/null)
10
+ ```
11
+
12
+ If same version: "Already up to date at v${INSTALLED}." STOP.
13
+ If different: show "Update available: v${INSTALLED} → v${AVAILABLE}"
14
+
15
+ ## 2. Extract new templates
16
+
17
+ ```bash
18
+ rm -rf /tmp/cpw-update
19
+ npx @claude-pw/framework --extract /tmp/cpw-update
20
+ ```
21
+
22
+ Read `/tmp/cpw-update/RELEASES.md` and show changelog entries between installed and available versions.
23
+
24
+ ## 3. Diff files
25
+
26
+ Compare each file in these categories:
27
+
28
+ | Category | Project path | Template path |
29
+ |----------|-------------|---------------|
30
+ | Commands | `.claude/commands/*.md` | `/tmp/cpw-update/claude/commands/*.md` |
31
+ | Agents | `.claude/agents/*.md` | `/tmp/cpw-update/claude/agents/*.md` |
32
+ | Rules | `.claude/rules/*.md` | `/tmp/cpw-update/claude/rules/*.md` |
33
+ | Hooks | `.claude/hooks/*.js` | `/tmp/cpw-update/claude/hooks/*.js` |
34
+ | Settings | `.claude/settings.json` | `/tmp/cpw-update/claude/settings.json` |
35
+ | Config | `.planning/config.json` | `/tmp/cpw-update/planning/config.json` |
36
+
37
+ For each file, classify:
38
+ - **NEW** — in template only → will be added
39
+ - **UNCHANGED** — identical content → skip
40
+ - **UPDATED** — template changed, user didn't modify → safe overwrite
41
+ - **CONFLICT** — both changed → needs merge
42
+ - **CUSTOM** — in project only → preserve (user's own file)
43
+
44
+ Heuristic for UPDATED vs CONFLICT: if project file differs from new template AND contains sections/lines not present in the new template, it's a CONFLICT. If the new template is a strict superset of the project file (only additions), it's UPDATED.
45
+
46
+ ## 4. Present summary
47
+
48
+ ```
49
+ Update: v{INSTALLED} → v{AVAILABLE}
50
+
51
+ Commands:
52
+ UPDATED cpw-next-step.md (+25 lines)
53
+ UNCHANGED cpw-startup.md
54
+ NEW cpw-new-command.md
55
+ ...
56
+
57
+ Agents:
58
+ UPDATED implementer.md (+20 lines)
59
+ CONFLICT researcher.md — you added custom content
60
+ CUSTOM my-agent.md — your file, preserved
61
+ ...
62
+
63
+ Config:
64
+ NEW FIELDS [list of new fields with defaults]
65
+
66
+ Apply? (all / review conflicts first / cancel)
67
+ ```
68
+
69
+ ## 5. Apply changes
70
+
71
+ ### NEW and UPDATED files:
72
+ Copy from `/tmp/cpw-update/` to project. Overwrite safely.
73
+
74
+ ### CONFLICT files:
75
+ For each conflicted file:
76
+ 1. Read user's version (project file)
77
+ 2. Read new template version (`/tmp/cpw-update/`)
78
+ 3. Identify user's custom additions (sections, rules, modifications not in template)
79
+ 4. Merge: start with new template, re-add user's custom sections at appropriate locations
80
+ 5. Show the merged result to user: "Here's the merged version of [file]. OK? (yes / edit / skip)"
81
+ 6. If skip: keep user's version unchanged
82
+
83
+ ### settings.json:
84
+ Merge: add new hooks from template, preserve user's custom hooks. Do NOT overwrite existing hooks.
85
+
86
+ ### config.json:
87
+ Add new fields with defaults. Do NOT overwrite user's existing values.
88
+
89
+ ### CUSTOM files:
90
+ Never touch. Report: "[file] is your custom file — preserved."
91
+
92
+ ## 6. Finalize
93
+
94
+ Update version:
95
+ ```bash
96
+ echo "{AVAILABLE}" > .claude/.claude-pw-version
97
+ ```
98
+
99
+ Clean up:
100
+ ```bash
101
+ rm -rf /tmp/cpw-update
102
+ ```
103
+
104
+ Commit:
105
+ `make commit m="chore: update claude-pw to v{AVAILABLE}"`
106
+
107
+ Report:
108
+ ```
109
+ Updated to v{AVAILABLE}.
110
+
111
+ Next: `/cpw-next-step` to continue with the plan.
112
+ ```
113
+
114
+ ## Rollback
115
+
116
+ If the user reports issues after update:
117
+ - Previous state is in git history: `git diff HEAD~1 -- .claude/`
118
+ - Revert: `git checkout HEAD~1 -- .claude/`
119
+ - Or selectively: `git checkout HEAD~1 -- .claude/agents/researcher.md`