5-phase-workflow 1.8.4 → 1.8.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "5-phase-workflow",
3
- "version": "1.8.4",
3
+ "version": "1.8.6",
4
4
  "description": "A 5-phase feature development workflow for Claude Code",
5
5
  "bin": {
6
6
  "5-phase-workflow": "bin/install.js"
@@ -211,6 +211,11 @@ The skill-creator plugin from the official Claude store helps generate higher-qu
211
211
  - "Generate/update CLAUDE.md? This will analyze your codebase to document structure and conventions."
212
212
  - Options: "Yes (recommended)", "Skip"
213
213
 
214
+ **2k2. Confirm rules generation:**
215
+ - "Generate `.claude/rules/` files? These are scoped instruction files that automatically load when Claude works with matching file types (e.g., testing rules load only when editing test files, code-style rules load only for source files)."
216
+ - Options: "Yes (recommended)", "Skip"
217
+ - Note: Rules complement CLAUDE.md — they provide focused, file-type-scoped directives derived from your project's actual conventions.
218
+
214
219
  **2l. Review detected patterns for skill generation:**
215
220
 
216
221
  Present ONLY patterns that were actually detected in steps 1g and 1h.
@@ -270,7 +275,7 @@ Using the values gathered from Steps 1 and 2, write `.5/config.json` directly.
270
275
  mkdir -p .5
271
276
  ```
272
277
 
273
- **Schema:** Read `.claude/references/configure-tables.md` section "Config Schema" for the full JSON structure. Fill all values from user responses. Write with pretty-printed JSON. Read back to verify correctness.
278
+ **Schema:** Read `.claude/references/configure-tables.md` section "Config Schema" for the full JSON structure. Fill all values from user responses (including `rules.generate` from step 2k2). Write with pretty-printed JSON. Read back to verify correctness.
274
279
 
275
280
  **Update `.5/version.json` with configure timestamp:**
276
281
 
@@ -322,6 +327,13 @@ Analyze the codebase and generate modular documentation:
322
327
  - Quick reference section with links to all `.5/*.md` files
323
328
  - Project overview and build commands
324
329
  - "Getting Started" guide with references to appropriate files
330
+ - Workflow rules section (verbatim):
331
+ ```
332
+ ## Workflow Rules
333
+ When running `/5:` workflow commands, follow the command instructions exactly as written.
334
+ Do not skip steps, combine phases, or proceed to actions not specified in the current command.
335
+ Each phase produces a specific artifact — do not create artifacts belonging to other phases.
336
+ ```
325
337
  - Mandatory coding guidelines:
326
338
  1. Types should be clear and types should be available when possible
327
339
  2. Use doc (jsdoc, javadoc, pydoc, etc) concisely. No doc is better than meaningless doc
@@ -347,6 +359,15 @@ Analyze the codebase and generate modular documentation:
347
359
 
348
360
  Include only patterns/commands where user selected "Generate".
349
361
 
362
+ ### Requirement 3: Generate Scoped Rules (if selected)
363
+ Generate `.claude/rules/` files with project-specific conventions scoped to relevant file types.
364
+ Rules are concise directives (15-40 lines, NOT documentation) derived from codebase analysis.
365
+ Only generate rules for patterns that were actually detected:
366
+ - `code-style.md` — naming, formatting, import conventions (scoped to source files)
367
+ - `testing.md` — test patterns, mocking, fixtures (scoped to test files)
368
+ - `api-patterns.md` — API conventions, error handling (scoped to API/route/controller files)
369
+ - `dependencies.md` — dependency usage patterns, env var conventions (unconditional)
370
+
350
371
  ## Acceptance Criteria
351
372
  - [ ] `.5/` directory created
352
373
  - [ ] All 7 documentation files exist and are populated:
@@ -363,6 +384,10 @@ Include only patterns/commands where user selected "Generate".
363
384
  - [ ] All specified project-specific skills are generated in `.claude/skills/`
364
385
  - [ ] Generated skills reference actual project conventions
365
386
  - [ ] If CLAUDE.md existed before, user-written sections are preserved
387
+ - [ ] `.claude/rules/` directory exists with scoped rule files (if rules generation selected)
388
+ - [ ] Generated rules use `paths:` frontmatter for scoping where applicable
389
+ - [ ] Rules contain concise directives, not documentation
390
+ - [ ] No rules generated for undetected patterns
366
391
  ```
367
392
 
368
393
  **Important:** Use `mkdir -p .5/features/CONFIGURE` before writing the feature spec.
@@ -8,24 +8,27 @@ context: fork
8
8
  ---
9
9
 
10
10
  <role>
11
- You are a Feature Planner. Your only output is a feature specification file.
12
- You do NOT implement code. You write NO code. You spawn ONLY Explore agents (subagent_type=Explore).
13
- You write ONLY to .5/.planning-active and .5/features/{name}/feature.md.
14
- After creating the spec, you are DONE. Do not continue into implementation planning or coding.
11
+ You are a Feature Planner. Your ONLY deliverable is a feature specification file (feature.md).
12
+ You do NOT implement code. You do NOT create implementation plans. You spawn ONLY Explore agents (subagent_type=Explore).
13
+ You write ONLY to .5/.planning-active, .5/features/{name}/codebase-scan.md, and .5/features/{name}/feature.md.
14
+ After creating the spec, you are FINISHED. You do not continue. You do not offer to continue.
15
15
  </role>
16
16
 
17
17
  <constraints>
18
18
  HARD CONSTRAINTS — violations waste tokens and get blocked by plan-guard:
19
19
  - NEVER write code, pseudo-code, or implementation snippets in any output
20
20
  - NEVER describe HOW something will be implemented (file contents, signatures, class structures)
21
+ - NEVER create an implementation plan, file list, component breakdown, or step-by-step build guide — that is Phase 2's job
22
+ - NEVER suggest "shall I continue with implementation planning?" or "let me create the plan" — you are DONE after feature.md
23
+ - NEVER offer to proceed to the next phase — the user will invoke `/5:plan-implementation` themselves
21
24
  - NEVER spawn Task agents with subagent_type other than Explore
22
- - NEVER write to any file except .5/features/{name}/feature.md (where {name} may include a ticket prefix) and .5/.planning-active
25
+ - NEVER write to any file except .5/.planning-active, .5/features/{name}/codebase-scan.md, and .5/features/{name}/feature.md
23
26
  - NEVER call EnterPlanMode — the workflow has its own planning process
24
27
  - NEVER use Bash to create, write, or modify files — this bypasses the plan-guard and is a constraint violation
25
- - NEVER continue past the completion message — when you output "Feature spec created at...", you are DONE
28
+ - NEVER continue past the completion message — when you output "Feature spec created at...", you are FINISHED
26
29
  - The feature spec describes WHAT and WHY, never HOW
27
- - If you feel the urge to implement, STOP and ask a clarifying question instead
28
- - Your output is a SPECIFICATION, not a design document. No code. No file layouts. No API shapes.
30
+ - If you feel the urge to plan implementation or write code, STOP ask a clarifying question instead
31
+ - Your output is a SPECIFICATION, not a design document. No code. No file layouts. No API shapes. No implementation plans.
29
32
  </constraints>
30
33
 
31
34
  <write-rules>
@@ -195,24 +198,23 @@ Populate all sections:
195
198
  - **[DEFERRED]**: The user explicitly said "not now", "later", "skip this" → planner MUST NOT include in the plan
196
199
  - When in doubt, label as **[DECIDED]** — it's safer to honor a decision than to override it
197
200
 
198
- ## PLANNING COMPLETE
201
+ ## PLANNING COMPLETE — MANDATORY STOP
199
202
 
200
- After writing feature.md, output exactly:
203
+ After writing feature.md, output ONLY this message — no additional text, no suggestions, no offers to continue:
201
204
 
202
205
  ```
203
- Feature spec created at `.5/features/{name}/feature.md`
206
+ Feature spec created at `.5/features/{name}/feature.md`
204
207
 
205
- Next steps:
206
- 1. Review the feature spec
207
- 2. If changes needed: /5:discuss-feature {name}
208
- 3. If approved: /clear then /5:plan-implementation {name}
208
+ To review or refine: /5:discuss-feature {name}
209
+ To proceed: /clear /5:plan-implementation {name}
209
210
  ```
210
211
 
211
- STOP. You are a planner. Your job is done. Do not implement.
212
+ **YOU ARE NOW FINISHED.** This is a hard stop. Do not:
213
+ - Suggest next steps beyond the message above
214
+ - Offer to create an implementation plan
215
+ - Offer to continue with any phase
216
+ - Write any additional files
217
+ - Provide a summary of what could be implemented
218
+ - Ask "shall I proceed with..." or "would you like me to..."
212
219
 
213
- <constraints>
214
- REMINDER: You are a Feature Planner. You wrote a specification. You did NOT implement.
215
- If you wrote any code, file paths to create, class names, or function signatures in feature.md,
216
- you have violated your role.
217
- The feature spec contains WHAT and WHY. Phase 2 handles WHERE. Phase 3 handles HOW.
218
- </constraints>
220
+ If the user asks you to continue or implement, respond: "Phase 1 is complete. Please run `/5:plan-implementation {name}` to continue."
@@ -90,6 +90,11 @@ Perform the same detection as configure Steps 1b-1h:
90
90
  - Read each skill's SKILL.md frontmatter
91
91
  - Categorize as workflow-generated (create-*, run-*) or user-created
92
92
 
93
+ **2f. Scan existing rules** — list ALL rule files in `.claude/rules/`:
94
+ - Read each `.md` file
95
+ - Note which are workflow-generated (code-style, testing, api-patterns, dependencies) vs user-created
96
+ - User-created rules are never modified or removed
97
+
93
98
  ### Step 3: Compare and Prepare Summary
94
99
 
95
100
  Use the existing skills in `.claude/skills/` (from Step 2e) as the source of truth — not config.json. Compare what's installed with what's detected in the codebase:
@@ -102,14 +107,22 @@ Use the existing skills in `.claude/skills/` (from Step 2e) as the source of tru
102
107
  - **Stale commands**: a `run-*` skill exists but the command is no longer detected → offer to remove or keep
103
108
  - **User-created skills** (not matching `create-*` or `run-*` naming) → always refresh with current conventions, never remove
104
109
 
110
+ **Rules comparison** (if `rules.generate` is `true` in config.json):
111
+ - **Existing workflow rules** (from Step 2f) — code-style, testing, api-patterns, dependencies
112
+ - **Stale rules**: a workflow rule exists but its prerequisite patterns are no longer detected → offer to remove
113
+ - **New rules**: patterns detected that could benefit from a rule but none exists yet → offer to create
114
+ - **User-created rules** → never modify or remove
115
+
105
116
  ### Step 4: Confirm with User
106
117
 
107
118
  Use `AskUserQuestion` to show a summary and get confirmation. Present:
108
119
 
109
120
  1. **Documentation files that will be rewritten** — list all 7 `.5/*.md` files + CLAUDE.md
110
121
  2. **Skills that will be refreshed** — list ALL skills found in `.claude/skills/` (both workflow-generated and user-created)
111
- 3. **New patterns detected** (if any) — "These patterns were found in your codebase but don't have skills yet: [list]. Create skills for them?"
112
- 4. **Stale patterns** (if any) — "These patterns are in your config but weren't found in the codebase: [list]. Remove them?"
122
+ 3. **Rules that will be refreshed** (if rules enabled) — list workflow-generated rule files in `.claude/rules/`
123
+ 4. **New patterns detected** (if any) — "These patterns were found in your codebase but don't have skills yet: [list]. Create skills for them?"
124
+ 5. **Stale patterns** (if any) — "These patterns are in your config but weren't found in the codebase: [list]. Remove them?"
125
+ 6. **Stale rules** (if any) — "These rule files no longer have matching patterns in the codebase: [list]. Remove them?"
113
126
 
114
127
  Options:
115
128
  - "Proceed with refresh" — regenerate everything as shown
@@ -133,12 +146,20 @@ Refresh ALL existing skills in .claude/skills/:
133
146
  - New skills to create: [list from user confirmation, if any]
134
147
  - Skills to remove: [list from user confirmation, if any]
135
148
 
149
+ Refresh rules in .claude/rules/ (if rules.generate is true):
150
+ - Existing workflow rules: [list from Step 2f]
151
+ - Rules to remove: [list from user confirmation, if any]
152
+ - New rules to create: [if applicable]
153
+
136
154
  Re-analyze the entire codebase (A1 analysis) and:
137
155
  1. Rewrite all 7 .5/*.md documentation files
138
156
  2. Update CLAUDE.md (preserve user-written sections)
139
157
  3. Refresh ALL skills in .claude/skills/ — read current conventions from codebase and update each skill
140
158
  4. Create new skills for newly-added patterns
141
- 5. Remove skills the user chose to drop"
159
+ 5. Remove skills the user chose to drop
160
+ 6. Refresh all workflow-generated rule files in .claude/rules/ with updated conventions
161
+ 7. Create new rule files for newly-detected patterns
162
+ 8. Remove rule files the user chose to drop"
142
163
  ```
143
164
 
144
165
  Use `subagent_type: "general-purpose"` for the Task.
@@ -166,6 +187,9 @@ Show the user a summary:
166
187
  - List of skills refreshed
167
188
  - List of new skills created (if any)
168
189
  - List of skills removed (if any)
190
+ - List of rules refreshed (if any)
191
+ - List of new rules created (if any)
192
+ - List of rules removed (if any)
169
193
  - Timestamp of reconfiguration
170
194
  - Suggest running `/clear` to reset context
171
195
 
@@ -99,9 +99,15 @@ process.stdin.on('end', () => {
99
99
 
100
100
  if (toolName === 'Write' || toolName === 'Edit') {
101
101
  const filePath = toolInput.file_path || '';
102
- if (filePath && !isInsideDotFive(filePath, workspaceDir)) {
102
+ if (!filePath) {
103
+ process.exit(0);
104
+ }
105
+
106
+ const phase = getPlanningPhase(workspaceDir);
107
+
108
+ // First check: block anything outside .5/
109
+ if (!isInsideDotFive(filePath, workspaceDir)) {
103
110
  const blockCount = incrementBlockCount(workspaceDir);
104
- const phase = getPlanningPhase(workspaceDir);
105
111
  const isSourceFile = !filePath.includes('.5/') && !filePath.includes('.claude/');
106
112
  const escalation = blockCount >= 3
107
113
  ? ` CRITICAL: Block #${blockCount}. You have attempted to write source files ${blockCount} times. You are a PLANNER, not an implementer. Writing source code is Phase 3's job. Return to your Progress Checklist, finish your planning artifact, and STOP.`
@@ -118,6 +124,22 @@ process.stdin.on('end', () => {
118
124
  );
119
125
  process.exit(2);
120
126
  }
127
+
128
+ // Second check: during plan-feature, only allow specific files
129
+ if (phase === 'plan-feature' && !isAllowedPlanFeatureFile(filePath, workspaceDir)) {
130
+ const blockCount = incrementBlockCount(workspaceDir);
131
+ const escalation = blockCount >= 3
132
+ ? ` CRITICAL: Block #${blockCount}. You are attempting to create implementation artifacts during Phase 1. Phase 1 ONLY produces feature.md. STOP and output your completion message.`
133
+ : '';
134
+ process.stderr.write(
135
+ `BLOCKED: During plan-feature (Phase 1), you may only write to .planning-active, codebase-scan.md, and feature.md. ` +
136
+ `Attempted: "${filePath}". ` +
137
+ `You are creating implementation artifacts (e.g., plan.md) which belongs to Phase 2. ` +
138
+ `REDIRECT: If you have already written feature.md, output the completion message and STOP. ` +
139
+ `Do NOT create implementation plans, file lists, or any other artifacts.${escalation}`
140
+ );
141
+ process.exit(2);
142
+ }
121
143
  }
122
144
 
123
145
  process.exit(0);
@@ -127,6 +149,23 @@ process.stdin.on('end', () => {
127
149
  }
128
150
  });
129
151
 
152
+ function isAllowedPlanFeatureFile(filePath, workspaceDir) {
153
+ const resolved = path.resolve(workspaceDir, filePath);
154
+ const dotFiveDir = path.join(workspaceDir, '.5');
155
+
156
+ // Allow .5/.planning-active
157
+ if (resolved === path.join(dotFiveDir, '.planning-active')) return true;
158
+
159
+ // Allow .5/features/{name}/feature.md and .5/features/{name}/codebase-scan.md
160
+ const featuresDir = path.join(dotFiveDir, 'features');
161
+ if (resolved.startsWith(featuresDir + path.sep)) {
162
+ const basename = path.basename(resolved);
163
+ if (basename === 'feature.md' || basename === 'codebase-scan.md') return true;
164
+ }
165
+
166
+ return false;
167
+ }
168
+
130
169
  function isInsideDotFive(filePath, workspaceDir) {
131
170
  const resolved = path.resolve(workspaceDir, filePath);
132
171
  const dotFiveDir = path.join(workspaceDir, '.5');
@@ -109,6 +109,9 @@ For each command found: record exact syntax, note variants (e.g., `test:unit`, `
109
109
  },
110
110
  "dotFiveFolder": {
111
111
  "gitignore": true
112
+ },
113
+ "rules": {
114
+ "generate": true
112
115
  }
113
116
  }
114
117
  ```
@@ -166,6 +166,13 @@ CLAUDE.md structure:
166
166
  - **Quick Reference:** Links to all 7 `.5/*.md` files (STACK, STRUCTURE, ARCHITECTURE, CONVENTIONS, TESTING, INTEGRATIONS, CONCERNS)
167
167
  - **Project Overview:** 1-2 paragraphs from README/package.json
168
168
  - **Build & Run Commands:** Build, test, and other detected commands
169
+ - **Workflow Rules:** Include this section verbatim:
170
+ ```
171
+ ## Workflow Rules
172
+ When running `/5:` workflow commands, follow the command instructions exactly as written.
173
+ Do not skip steps, combine phases, or proceed to actions not specified in the current command.
174
+ Each phase produces a specific artifact — do not create artifacts belonging to other phases.
175
+ ```
169
176
  - **Coding Guidelines:** The 6 mandatory principles (types, concise docs, short files, extract methods, SRP/DRY, maintainable/modular)
170
177
  - **Getting Started:** Links to relevant `.5/` files for new devs and specific tasks
171
178
 
@@ -327,6 +334,97 @@ Executes the project's {command} command.
327
334
 
328
335
  ---
329
336
 
337
+ ## C. Generate Scoped Rules
338
+
339
+ If `rules.generate` is `true` in `.5/config.json`, generate `.claude/rules/` files with project-specific conventions scoped to relevant file types.
340
+
341
+ Rules are **concise directives** (15-40 lines each), NOT documentation. Documentation lives in `.5/*.md` files. Rules tell Claude what to do when working with specific file types.
342
+
343
+ ### C1. Determine Which Rules to Generate
344
+
345
+ Based on the A1 analysis results, determine which rules apply:
346
+
347
+ | Rule File | Generate When | Source Analysis |
348
+ |-----------|---------------|-----------------|
349
+ | `code-style.md` | Always (if source files exist) | Conventions Analysis |
350
+ | `testing.md` | Test files detected | Testing Analysis |
351
+ | `api-patterns.md` | Controller/route/handler patterns detected | Architecture Analysis |
352
+ | `dependencies.md` | External integrations detected | Integration Analysis |
353
+
354
+ **Skip** any rule whose prerequisite patterns were not detected. Do NOT generate empty or placeholder rule files.
355
+
356
+ ### C2. Extract Directives and Write Rules
357
+
358
+ For each applicable rule:
359
+
360
+ 1. **Derive `paths:` globs** from detected file locations (e.g., if tests are at `src/**/*.test.ts` and `tests/**/*.spec.ts`, use those patterns)
361
+ 2. **Convert analysis observations into imperative directives** — "Use X", "Always Y", "Never Z"
362
+ 3. **Keep each file 15-40 lines** — be concise and actionable
363
+ 4. **Do NOT repeat** the 6 mandatory coding guidelines from CLAUDE.md
364
+
365
+ Write files to `.claude/rules/`:
366
+
367
+ ```bash
368
+ mkdir -p .claude/rules
369
+ ```
370
+
371
+ ### C3. Rule File Format
372
+
373
+ Each rule file uses YAML frontmatter with `paths:` for scoping. Rules without `paths:` load unconditionally.
374
+
375
+ **Example — `testing.md`:**
376
+
377
+ ```markdown
378
+ ---
379
+ paths:
380
+ - "**/*.test.ts"
381
+ - "**/*.spec.ts"
382
+ ---
383
+
384
+ # Testing Conventions
385
+
386
+ - Use `describe`/`it` blocks with descriptive names
387
+ - Mock external dependencies with jest.mock, never mock internal modules
388
+ - Use factory functions from `tests/factories/` for test data
389
+ - Each test file mirrors its source file path: `src/foo/Bar.ts` → `src/foo/__tests__/Bar.test.ts`
390
+ - Assert one behavior per test
391
+ ```
392
+
393
+ **Example — `code-style.md`:**
394
+
395
+ ```markdown
396
+ ---
397
+ paths:
398
+ - "src/**/*.{ts,tsx}"
399
+ ---
400
+
401
+ # Code Style
402
+
403
+ - Use PascalCase for classes and types, camelCase for functions and variables
404
+ - Import order: external packages → internal modules → relative imports
405
+ - Use absolute imports with `@/` alias
406
+ - Prefer named exports over default exports
407
+ ```
408
+
409
+ **Example — `dependencies.md` (unconditional):**
410
+
411
+ ```markdown
412
+ # Dependency Conventions
413
+
414
+ - Database access through Prisma client only, never raw SQL
415
+ - HTTP requests use axios instance from `src/lib/http.ts`
416
+ - Environment variables accessed via `src/config/env.ts`, never `process.env` directly
417
+ ```
418
+
419
+ ### Refresh Mode Behavior for Rules
420
+
421
+ When running in REFRESH MODE:
422
+ - Re-analyze codebase and overwrite all existing rule files with updated directives
423
+ - Remove rule files for patterns no longer detected in the codebase
424
+ - Create new rule files if new patterns are detected that weren't present before
425
+
426
+ ---
427
+
330
428
  ## Output Contract
331
429
 
332
430
  Returns structured results for each component:
@@ -343,6 +441,7 @@ Component A (Documentation): SUCCESS - Created 7 documentation files + index
343
441
  - CLAUDE.md (index with references)
344
442
  Component B (Pattern Skills): SUCCESS - Generated 3 create-* skills (create-component, create-hook, create-context)
345
443
  Component C (Command Skills): SUCCESS - Generated 2 run-* skills (run-tests, run-lint)
444
+ Component D (Rules): SUCCESS - Generated 3 rule files (code-style, testing, dependencies)
346
445
  ```
347
446
 
348
447
  Or on failure:
@@ -350,6 +449,7 @@ Or on failure:
350
449
  ```
351
450
  Component A (Documentation): FAILED - Unable to read template files
352
451
  Component B (Pattern Skills): FAILED - No patterns found in codebase
452
+ Component D (Rules): SKIPPED - rules.generate is false in config
353
453
  ```
354
454
 
355
455
  ## DO NOT
@@ -357,7 +457,9 @@ Component B (Pattern Skills): FAILED - No patterns found in codebase
357
457
  - DO NOT overwrite existing user-written CLAUDE.md sections
358
458
  - DO NOT generate skills for patterns that don't exist in the project
359
459
  - DO NOT generate command skills for commands that don't exist in the project
460
+ - DO NOT generate rules for patterns not detected in the codebase
360
461
  - DO NOT include `steps` in config.json
361
462
  - DO NOT hardcode conventions - always derive from actual project analysis
362
- - DO NOT generate empty or placeholder skill files
463
+ - DO NOT generate empty or placeholder skill or rule files
363
464
  - DO NOT assume command syntax - always read from actual config files (package.json, Makefile, etc.)
465
+ - DO NOT repeat the 6 mandatory coding guidelines from CLAUDE.md in rule files