prizmkit 1.0.45 → 1.0.58

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.
Files changed (64) hide show
  1. package/bundled/VERSION.json +3 -3
  2. package/bundled/adapters/claude/agent-adapter.js +2 -1
  3. package/bundled/adapters/claude/command-adapter.js +4 -3
  4. package/bundled/agents/prizm-dev-team-dev.md +1 -1
  5. package/bundled/dev-pipeline/README.md +3 -4
  6. package/bundled/dev-pipeline/assets/prizm-dev-team-integration.md +2 -3
  7. package/bundled/dev-pipeline/launch-bugfix-daemon.sh +2 -2
  8. package/bundled/dev-pipeline/launch-daemon.sh +2 -2
  9. package/bundled/dev-pipeline/lib/branch.sh +76 -0
  10. package/bundled/dev-pipeline/run-bugfix.sh +58 -149
  11. package/bundled/dev-pipeline/run.sh +60 -153
  12. package/bundled/dev-pipeline/scripts/parse-stream-progress.py +1 -1
  13. package/bundled/dev-pipeline/templates/bootstrap-tier1.md +8 -16
  14. package/bundled/dev-pipeline/templates/bootstrap-tier2.md +10 -18
  15. package/bundled/dev-pipeline/templates/bootstrap-tier3.md +20 -24
  16. package/bundled/dev-pipeline/templates/bugfix-bootstrap-prompt.md +6 -6
  17. package/bundled/dev-pipeline/tests/conftest.py +19 -131
  18. package/bundled/dev-pipeline/tests/test_generate_bootstrap_prompt.py +207 -0
  19. package/bundled/dev-pipeline/tests/test_utils.py +51 -110
  20. package/bundled/rules/prizm/prizm-commit-workflow.md +3 -3
  21. package/bundled/skills/_metadata.json +15 -16
  22. package/bundled/skills/app-planner/SKILL.md +8 -7
  23. package/bundled/skills/bug-fix-workflow/SKILL.md +174 -0
  24. package/bundled/skills/bug-planner/SKILL.md +20 -32
  25. package/bundled/skills/bugfix-pipeline-launcher/SKILL.md +3 -5
  26. package/bundled/skills/dev-pipeline-launcher/SKILL.md +4 -6
  27. package/bundled/skills/feature-workflow/SKILL.md +25 -42
  28. package/bundled/skills/prizm-kit/SKILL.md +57 -21
  29. package/bundled/skills/prizm-kit/assets/{claude-md-template.md → project-memory-template.md} +2 -2
  30. package/bundled/skills/prizmkit-analyze/SKILL.md +41 -29
  31. package/bundled/skills/prizmkit-clarify/SKILL.md +40 -30
  32. package/bundled/skills/prizmkit-code-review/SKILL.md +48 -43
  33. package/bundled/skills/prizmkit-committer/SKILL.md +30 -68
  34. package/bundled/skills/prizmkit-implement/SKILL.md +48 -26
  35. package/bundled/skills/prizmkit-init/SKILL.md +57 -66
  36. package/bundled/skills/prizmkit-plan/SKILL.md +46 -20
  37. package/bundled/skills/prizmkit-prizm-docs/SKILL.md +60 -19
  38. package/bundled/skills/prizmkit-prizm-docs/assets/PRIZM-SPEC.md +23 -23
  39. package/bundled/skills/prizmkit-retrospective/SKILL.md +142 -65
  40. package/bundled/skills/prizmkit-retrospective/assets/retrospective-template.md +13 -0
  41. package/bundled/skills/prizmkit-specify/SKILL.md +63 -13
  42. package/bundled/skills/refactor-workflow/SKILL.md +105 -49
  43. package/bundled/team/prizm-dev-team.json +2 -2
  44. package/package.json +1 -1
  45. package/src/scaffold.js +3 -3
  46. package/bundled/dev-pipeline/lib/worktree.sh +0 -164
  47. package/bundled/dev-pipeline/tests/__init__.py +0 -0
  48. package/bundled/dev-pipeline/tests/test_check_session.py +0 -131
  49. package/bundled/dev-pipeline/tests/test_cleanup_logs.py +0 -119
  50. package/bundled/dev-pipeline/tests/test_detect_stuck.py +0 -207
  51. package/bundled/dev-pipeline/tests/test_generate_bugfix_prompt.py +0 -181
  52. package/bundled/dev-pipeline/tests/test_generate_prompt.py +0 -190
  53. package/bundled/dev-pipeline/tests/test_init_bugfix_pipeline.py +0 -153
  54. package/bundled/dev-pipeline/tests/test_init_pipeline.py +0 -241
  55. package/bundled/dev-pipeline/tests/test_update_bug_status.py +0 -142
  56. package/bundled/dev-pipeline/tests/test_update_feature_status.py +0 -338
  57. package/bundled/dev-pipeline/tests/test_worktree.py +0 -236
  58. package/bundled/dev-pipeline/tests/test_worktree_integration.py +0 -796
  59. package/bundled/skills/prizm-kit/assets/codebuddy-md-template.md +0 -35
  60. package/bundled/skills/prizm-kit/assets/hooks/prizm-commit-hook.json +0 -15
  61. package/bundled/skills/prizmkit-summarize/SKILL.md +0 -51
  62. package/bundled/skills/prizmkit-summarize/assets/registry-template.md +0 -18
  63. package/bundled/templates/hooks/commit-intent-claude.json +0 -26
  64. /package/bundled/templates/hooks/{commit-intent-codebuddy.json → commit-intent.json} +0 -0
@@ -1,79 +1,156 @@
1
1
  ---
2
2
  name: "prizmkit-retrospective"
3
- description: "Post-feature retrospective. Extracts lessons from completed features, updates Prizm docs TRAPS and RULES. Invoke after feature completion. (project)"
3
+ description: "The SOLE maintainer of .prizm-docs/ project memory. Performs two jobs: (1) structural sync — update KEY_FILES/INTERFACES/DEPENDENCIES to reflect code changes, and (2) knowledge injection — extract TRAPS/RULES/DECISIONS from completed work. Update project documentation after code changes. Run after code review passes and before committing. Must be run before /prizmkit-committer. Trigger on: 'retrospective', 'retro', 'update docs', 'sync docs', 'wrap up', 'done with feature', 'feature complete', 'update project documentation'. (project)"
4
4
  ---
5
5
 
6
6
  # PrizmKit Retrospective
7
7
 
8
- Post-feature retrospective analysis that extracts lessons learned, updates Prizm documentation with discovered traps and rules, and documents improvements for future reference.
8
+ **The sole maintainer of `.prizm-docs/` project memory.** No other skill writes to `.prizm-docs/`. This skill performs two distinct jobs in one pass:
9
9
 
10
- ### When to Use
11
- - After completing a feature (spec, plan, tasks, implementation all done)
12
- - User says "retrospective", "retro", "lessons learned", "what did we learn"
13
- - Before starting a new major feature (to apply lessons from the last one)
10
+ 1. **Structural Sync** — reflect what changed in code (KEY_FILES, INTERFACES, DEPENDENCIES, file counts)
11
+ 2. **Knowledge Injection** extract what was learned (TRAPS, RULES, DECISIONS)
14
12
 
15
- ### prizmkit.retrospective
13
+ Both jobs are necessary because `.prizm-docs/` exists to help AI understand the project. Structural accuracy tells AI *what exists*; knowledge tells AI *why it exists and what to watch out for*.
16
14
 
17
- PRECONDITION: Completed feature with spec.md, plan.md, tasks.md in .prizmkit/specs/
15
+ ## When to Use
16
+
17
+ - **Before every commit** (mandatory in pipeline) — ensures docs and code are in sync
18
+ - After completing a feature (spec, plan, implementation all done)
19
+ - After code review passes (PASS or PASS WITH WARNINGS)
20
+ - User says "retrospective", "retro", "update docs", "sync docs", "wrap up"
21
+ - After refactoring or bugfix cycles (structural sync + optional TRAPS update)
22
+
23
+ ## When NOT to Use
24
+
25
+ - Only comments, whitespace, or formatting changed — no structural/knowledge change
26
+ - Only test files changed — no module-level impact
27
+ - Only .prizm files changed — avoid circular updates
28
+ - User just wants to commit without doc update — use `/prizmkit-committer` directly (but pipeline will flag `docs_missing`)
29
+
30
+ ---
31
+
32
+ ## Job 1: Structural Sync
33
+
34
+ Reflect code changes in `.prizm-docs/` so the project map stays accurate.
35
+
36
+ ### Steps
37
+
38
+ **1a.** Get changed files:
39
+ ```bash
40
+ git diff --cached --name-status
41
+ ```
42
+ If nothing staged, fallback:
43
+ ```bash
44
+ git diff --name-status
45
+ ```
46
+
47
+ **1b.** Read `.prizm-docs/root.prizm` to get MODULE_INDEX. Map each changed file to its module.
48
+
49
+ **1c.** Classify changes:
50
+ - `A` (added) → add to KEY_FILES, check for new INTERFACES
51
+ - `D` (deleted) → remove from KEY_FILES, update FILE count
52
+ - `M` (modified) → check if public interfaces or dependencies changed
53
+ - `R` (renamed) → update all path references
54
+
55
+ **1d.** Update affected docs (bottom-up: L2 → L1 → L0):
56
+
57
+ - **L2** (if exists): Update KEY_FILES, INTERFACES, DEPENDENCIES, CHANGELOG, UPDATED timestamp
58
+ - **L1**: Update FILES count, KEY_FILES (if major files added/removed), INTERFACES (if public API changed), UPDATED timestamp
59
+ - **L0 root.prizm**: Update MODULE_INDEX file counts only if counts changed. Update UPDATED only if structural change (module added/removed).
60
+
61
+ **1e.** If new directory with 3+ source files matches no existing module: create L1 doc immediately, add to MODULE_INDEX, defer L2.
62
+
63
+ **1f.** Enforce size limits:
64
+ - L0 > 4KB → consolidate MODULE_INDEX
65
+ - L1 > 3KB → move details to L2
66
+ - L2 > 5KB → archive old CHANGELOG entries
67
+
68
+ **SKIP structural sync if**: only internal implementation changed (no interface/dependency impact), only comments/whitespace, only test files, only .prizm files, bug fixes with no interface change.
69
+
70
+ ---
71
+
72
+ ## Job 2: Knowledge Injection
73
+
74
+ Extract what was learned and inject it into the modules where AI will read it. This job has value **only when real development work was done** — not for trivial changes.
75
+
76
+ ### When to run Job 2
77
+
78
+ - Feature completion (spec + plan + implementation done)
79
+ - Bugfix with a genuinely new pitfall discovered
80
+ - Refactor that revealed structural insights
81
+ - **Skip for**: trivial fixes, config changes, dependency bumps
18
82
 
19
83
  ### Steps
20
84
 
21
- #### Step 1: Gather Feature Artifacts
22
- Read all feature artifacts from .prizmkit/specs/###-feature-name/:
23
- - spec.md (original requirements and acceptance criteria)
24
- - plan.md (architecture decisions and implementation plan)
25
- - tasks.md (task breakdown and status)
26
- - data-model.md (if exists)
27
- - contracts/ directory (if exists)
28
-
29
- #### Step 2: Analyze Implementation
30
- Compare planned vs actual:
31
- - Tasks completed vs skipped why were tasks skipped?
32
- - Architecture deviations from plan what changed and why?
33
- - Unexpected challenges encountered — what surprised us?
34
- - Time-intensive areas what took longer than expected?
35
-
36
- #### Step 3: Extract Lessons
37
- Categorize findings:
38
- - **What went well** (reinforce these patterns)
39
- - **What went wrong** (create anti-patterns to avoid)
40
- - **What was surprising** (new patterns to document)
41
- - **What would you do differently** (improvement candidates)
42
-
43
- NOTE: If bug fixes were performed during this feature's implementation, they are refinements of the feature itself (completing its intended behavior), NOT separate features. Do not create separate documentation entries or REGISTRY records for bug fixes.
44
-
45
- #### Step 4: Generate Retrospective Document
46
- Write retrospective.md in .prizmkit/specs/###-feature-name/:
47
- ```markdown
48
- # Retrospective: <feature-name>
49
- Date: YYYY-MM-DD
50
-
51
- ## Summary Statistics
52
- - Tasks total: N
53
- - Tasks completed: N
54
- - Tasks skipped: N (with reasons)
55
-
56
- ## Key Decisions
57
- - Decision: <what> | Outcome: <good/bad/neutral> | Lesson: <takeaway>
58
-
59
- ## Patterns Discovered
60
- - Pattern: <name> | Context: <when to apply> | Benefit: <why>
61
-
62
- ## Anti-Patterns Discovered
63
- - Anti-pattern: <name> | Context: <when it occurred> | Fix: <what to do instead>
64
-
65
- ## Improvement Suggestions
66
- - Skill: <skill-name> | Suggestion: <what to improve>
85
+ **2a.** Gather context read the **actual code that was changed** plus any available artifacts:
86
+
87
+ - `git diff HEAD` the real source of truth for what happened
88
+ - `.prizmkit/specs/###-feature-name/plan.md` if feature work, read planned vs actual
89
+ - `.prizmkit/bugfix/<id>/fix-report.md` if bugfix, read what was discovered
90
+ - The relevant `.prizm-docs/` L1/L2 docs for affected modules
91
+
92
+ **2b.** Extract knowledge from what was **observed in code**, not invented:
93
+
94
+ **TRAPS** (highest priority) — things that look safe but break:
95
+ - Format: `- <what looks safe but is dangerous> | FIX: <correct approach>`
96
+ - Source: actual bugs hit, surprising behavior discovered in code, non-obvious coupling
97
+
98
+ **RULES**conventions established or constraints discovered:
99
+ - Format: `- MUST/NEVER/PREFER: <rule>`
100
+ - Source: patterns that proved necessary during implementation
101
+
102
+ **DECISIONS** architecture choices made and why:
103
+ - Format: `- [YYYY-MM-DD] <decision and rationale>`
104
+ - Format: `- REJECTED: <approach> <why it failed>`
105
+ - Source: alternatives tried, design trade-offs made
106
+
107
+ **QUALITY GATE**: Every item must answer: "If a new AI session reads only `.prizm-docs/` and this entry, does it gain actionable understanding that prevents mistakes or accelerates work?" If not, discard.
108
+
109
+ **2c.** Inject into the correct `.prizm-docs/` file:
110
+ - Module-level TRAPS/RULES/DECISIONS → the affected L1 or L2 `.prizm` file
111
+ - Project-level RULES/PATTERNS → `root.prizm`
112
+
113
+ **RULE**: Only add genuinely new information. Never duplicate existing entries. Never rewrite entire files.
114
+
115
+ ---
116
+
117
+ ## Final: Changelog + Stage
118
+
119
+ **3a.** Append to `.prizm-docs/changelog.prizm`:
120
+ - Format: `- YYYY-MM-DD | <module-path> | <verb>: <one-line description>`
121
+ - Verbs: add, update, fix, remove, refactor, rename, deprecate
122
+ - One entry per meaningful change, not one per file
123
+
124
+ **3b.** Stage all doc changes:
125
+ ```bash
126
+ git add .prizm-docs/
67
127
  ```
68
128
 
69
- #### Step 5: Update Prizm Docs
70
- For each lesson learned, update the relevant `.prizm-docs/` files:
71
- - Add discovered pitfalls to the affected module's TRAPS section
72
- - Add new conventions or rules to the affected module's RULES section
73
- - Append decisions to DECISIONS section with rationale
74
- - Update changelog.prizm with retrospective findings
75
-
76
- #### Step 6: Handoff
77
- Suggest next action:
78
- - `prizmkit.specify` — start next feature
79
- - No action needed just documenting for future reference
129
+ **3c.** Handoff:
130
+ - `/prizmkit-committer` proceed to commit
131
+
132
+ ---
133
+
134
+ ## Integration with Pipeline
135
+
136
+ In the dev-pipeline, this skill is the **single doc maintenance step** before commit:
137
+
138
+ ```
139
+ implement → code-review retrospective (memory maintenance) committer (pure commit)
140
+ ```
141
+
142
+ The pipeline enforces a **docs pass condition**: `.prizm-docs/` must show changes in the final commit. This skill is the sole satisfier of that requirement.
143
+
144
+ ## HANDOFF Chain
145
+
146
+ | From | To | Condition |
147
+ |------|----|-----------|
148
+ | `prizmkit-code-review` | **this skill** | Review passes or work is complete |
149
+ | **this skill** | `prizmkit-committer` | Memory maintained, ready to commit |
150
+ | `prizmkit-committer` | — | Committed |
151
+
152
+ ## Output
153
+
154
+ - `.prizm-docs/*.prizm` — Structurally synced + knowledge enriched
155
+ - `.prizm-docs/changelog.prizm` — Appended entries
156
+ - All changes staged via `git add .prizm-docs/`
@@ -0,0 +1,13 @@
1
+ # Retrospective: [FEATURE_NAME]
2
+ Date: YYYY-MM-DD
3
+
4
+ ## Knowledge Captured
5
+ - TRAPS added: N (list affected modules)
6
+ - RULES added: N (list affected modules)
7
+ - DECISIONS recorded: N (list affected modules)
8
+
9
+ ## Key Insights
10
+ - [insight]: [why it matters for future work]
11
+
12
+ ## .prizm-docs/ Updates
13
+ - [file]: [what was updated]
@@ -1,19 +1,25 @@
1
1
  ---
2
2
  name: "prizmkit-specify"
3
- description: "Create structured feature specifications from natural language. Invoke when starting a new feature, user says 'specify', 'define feature', or 'write requirements'. (project)"
3
+ description: "Create structured feature specifications from natural language. Use this skill whenever the user wants to define a new feature, describe what to build, or write requirements. Trigger on: 'specify', 'define feature', 'write requirements', 'new feature', 'what should we build', 'I want to add...', 'I want to build...', 'let's add', 'let's build', 'feature idea', or when the user describes a feature they want. This is the first step in the full dev workflow — always use before /prizmkit-plan. Skip for bug fixes, config tweaks, or simple refactors (use fast path). (project)"
4
4
  ---
5
5
 
6
6
  # PrizmKit Specify
7
7
 
8
8
  Create structured feature specifications from natural language descriptions. This skill transforms a feature idea into a well-structured spec with user stories, acceptance criteria, and scope boundaries.
9
9
 
10
- ## Commands
10
+ ### When to Use
11
+ - Starting a new feature — user says "specify", "define feature", "new feature", "I want to add..."
12
+ - Before `/prizmkit-plan` — to define WHAT will be built before deciding HOW
13
+ - When a feature idea needs to be formalized before implementation
14
+ - When multiple stakeholders need to agree on scope before coding starts
11
15
 
12
- ### prizmkit.specify
16
+ ### When NOT to Use
17
+ - Bug fixes with clear root cause → use fast path (/prizmkit-implement directly)
18
+ - Config tweaks, typo fixes, simple refactors → edit directly
19
+ - Documentation-only changes → no spec needed
20
+ - User already has a detailed spec → skip to /prizmkit-plan
13
21
 
14
- Create a new feature specification.
15
-
16
- **STEPS:**
22
+ ## Execution Steps
17
23
 
18
24
  1. Ask user for feature description (natural language)
19
25
  2. Auto-generate 2-4 word feature slug from description
@@ -35,14 +41,58 @@ Create a new feature specification.
35
41
  - Check: No more than 3 `[NEEDS CLARIFICATION]` markers?
36
42
  8. Output: `spec.md` path and summary
37
43
 
38
- **KEY RULES:**
39
- - Focus on WHAT and WHY, never HOW (no tech stack details)
40
- - Max 3 `[NEEDS CLARIFICATION]` markers
41
- - Every user story MUST have at least one acceptance criterion in Given/When/Then format
42
- - Scope boundaries MUST be explicitly defined
43
- - Feature numbers are zero-padded to 3 digits (e.g., `001`, `012`)
44
+ ## Writing Principles
45
+
46
+ - **Focus on WHAT and WHY, never HOW** — the spec describes the problem space; implementation choices belong in plan.md. Mixing in tech stack details couples the spec to a specific solution and makes it harder to explore alternatives during planning.
47
+ - **Every user story needs acceptance criteria** in Given/When/Then format — without them, the implementer has no way to verify the feature works correctly, and the code reviewer has no baseline to check against.
48
+ - **Scope boundaries must be explicit** — without "Out of scope" boundaries, implementers tend to gold-plate features with capabilities nobody asked for, wasting time and adding complexity.
49
+ - **Max 3 `[NEEDS CLARIFICATION]` markers** — more than 3 means the feature idea isn't mature enough to spec. Suggest the user think through the concept further and return, or use `/prizmkit-clarify` to resolve them interactively.
50
+ - **Feature numbers are zero-padded to 3 digits** (e.g., `001`, `012`) — ensures consistent sorting in file explorers and git logs.
51
+
52
+ ## Handling Vague Inputs
53
+
54
+ When the user's feature description is vague:
55
+ 1. Extract what IS clear and write that into the spec
56
+ 2. Mark genuinely ambiguous parts with `[NEEDS CLARIFICATION]` and include a recommended default
57
+ 3. Suggest running `/prizmkit-clarify` to resolve ambiguities interactively before proceeding to plan
58
+
59
+ The goal is to never block progress — always produce a usable spec, even if it has open questions.
60
+
61
+ ## Example
62
+
63
+ **Input:** "I want users to upload avatars"
64
+
65
+ **Output:** `.prizmkit/specs/003-user-avatar/spec.md`
66
+ ```markdown
67
+ # Feature: User Avatar Upload
68
+
69
+ ## Overview
70
+ Allow users to upload and manage profile avatar images.
71
+
72
+ ## User Stories
73
+
74
+ ### US-1: Upload Avatar
75
+ As a registered user, I want to upload a profile picture,
76
+ so that other users can visually identify me.
77
+
78
+ **Acceptance Criteria:**
79
+ - Given I am on my profile page
80
+ - When I select an image file and click upload
81
+ - Then my avatar is updated and visible across the platform
82
+
83
+ ### US-2: Remove Avatar
84
+ As a registered user, I want to remove my avatar,
85
+ so that I can revert to a default placeholder.
86
+
87
+ ## Scope
88
+ - **In scope:** Upload, display, remove avatar; image format validation
89
+ - **Out of scope:** Image cropping/editing, avatar history
90
+
91
+ ## Open Questions
92
+ - [NEEDS CLARIFICATION] Maximum file size limit? Recommended: 10MB
93
+ ```
44
94
 
45
- **HANDOFF:** `prizmkit.plan` or `prizmkit.clarify`
95
+ **HANDOFF:** `/prizmkit-plan` or `/prizmkit-clarify`
46
96
 
47
97
  ## Template
48
98
 
@@ -1,21 +1,28 @@
1
1
  ---
2
2
  name: "refactor-workflow"
3
3
  tier: 1
4
- description: "[Tier 1] End-to-end refactor workflow: analyze → plan → implement → review → commit. 5-phase behavior-preserving pipeline with mandatory test gates. (project)"
5
- ---
6
-
7
- refactor-workflow-SKILL.md
8
- refactor-workflow/SKILL.md
4
+ description: "End-to-end refactor workflow: analyze → plan → implement → review → commit. 5-phase behavior-preserving pipeline with mandatory test gates. Use this skill whenever the user wants to restructure, clean up, or optimize code without changing behavior. Trigger on: 'refactor', 'clean up code', 'restructure', 'optimize code structure', 'extract module', '重构', '优化代码结构', '代码重构'. (project)"
9
5
  ---
10
6
 
11
7
  # PrizmKit Refactor Workflow
12
8
 
13
- End-to-end orchestration skill for code refactoring and optimization. Chains existing PrizmKit skills (tech-debt-tracker, plan, implement, code-review, committer) into a 5-phase behavior-preserving pipeline with mandatory test gates after each task.
9
+ End-to-end orchestration skill for code refactoring and optimization. Chains existing PrizmKit skills into a 5-phase behavior-preserving pipeline with mandatory test gates after each task.
10
+
11
+ ### When to Use
12
+ - User says "refactor", "clean up code", "restructure", "extract module", "重构", "优化代码结构"
13
+ - Code has accumulated tech debt that needs structural improvement
14
+ - Module needs to be split, merged, or reorganized
15
+ - When behavior must remain unchanged but internal quality needs improvement
16
+
17
+ **Do NOT use when:**
18
+ - User wants to add new features (use `feature-workflow`)
19
+ - User wants to fix bugs (use `bug-planner` + `bugfix-pipeline-launcher`)
20
+ - Change is trivial (single rename, <5 lines) — just do it directly
14
21
 
15
22
  ## Overview
16
23
 
17
24
  ```
18
- prizmkit.refactor <目标模块或描述>
25
+ refactor-workflow
19
26
  → Phase 1: Analyze → refactor-analysis.md
20
27
  → Phase 2: Plan → plan.md (including Tasks section)
21
28
  → Phase 3: Implement → (code)
@@ -27,43 +34,45 @@ prizmkit.refactor <目标模块或描述>
27
34
 
28
35
  | Phase | Name | Skill Used | Artifact |
29
36
  |-------|------|-----------|----------|
30
- | 1 | Analyze 代码分析 | `prizmkit.tech-debt-tracker` + code reading | → `refactor-analysis.md` |
31
- | 2 | Plan 重构方案与任务 | `prizmkit.plan` | → `plan.md` (含 Tasks section) |
32
- | 3 | Implement 实现 | `prizmkit.implement` | (code changes) |
33
- | 4 | Code Review | `prizmkit.code-review` | (review report) |
34
- | 5 | Commit | `prizmkit.committer` | git commit |
37
+ | 1 | Analyze 代码分析 | `/prizmkit-tool-tech-debt-tracker` + code reading | → `refactor-analysis.md` |
38
+ | 2 | Plan 重构方案与任务 | `/prizmkit-plan` | → `plan.md` (含 Tasks section) |
39
+ | 3 | Implement 实现 | `/prizmkit-implement` | (code changes) |
40
+ | 4 | Code Review | `/prizmkit-code-review` | (review report) |
41
+ | 5 | Commit | `/prizmkit-committer` | git commit |
35
42
 
36
43
  ### Key Principles
44
+
37
45
  | Principle | Description |
38
46
  |-----------|-------------|
39
- | **Behavior preservation** | Refactoring MUST NOT change observable behavior. Acceptance criteria = "behavior unchanged + structure improved". |
40
- | **Test gates** | Full test suite MUST run after EVERY task** — not just at checkpoints. |
41
- | **No REGISTRY entry** | Refactoring does not go into REGISTRY.md (no user stories, no feature registration). |
42
- | **Incremental safety** | Each task preserves all tests; if tests fail → STOP and revert. |
47
+ | **Behavior preservation** | Refactoring changes structure, not behavior. If tests pass before and after, behavior is preserved. Acceptance criteria = "behavior unchanged + structure improved". |
48
+ | **Test gates** | Full test suite runs after every task — not just at checkpoints. A refactoring that breaks tests mid-way is much harder to debug than catching it immediately. |
49
+ | **Structural sync only** | Refactoring triggers `/prizmkit-retrospective` Job 1 (structural sync) — update `.prizm-docs/` to reflect file/interface changes. Skip knowledge injection unless a genuinely new pitfall was discovered during refactoring. |
50
+ | **Incremental safety** | Each task preserves all tests (green → green). If tests fail → stop and revert, because later tasks build on the assumption that previous ones are clean. |
43
51
 
44
52
  ### Artifacts
45
53
  Refactor artifacts stored at `.prizmkit/refactor/<refactor-slug>/`:
46
54
  - **`refactor-analysis.md`** — Code analysis (Phase 1)
47
55
  - **`plan.md`** — Refactoring plan with Tasks section (Phase 2)
48
56
 
49
- ## Commands
50
- ### prizmkit.refactor \<目标模块或描述\>
51
- Execute the full refactor pipeline for a module or code area.
52
57
  **INPUT**: Target description. Can be:
53
58
  - Module or file path (e.g., "src/auth/")
54
59
  - Natural language description (e.g., "重构认证模块,提取公共逻辑")
55
60
  - Specific refactoring goal (e.g., "extract payment processing into separate service")
61
+
56
62
  ---
57
63
 
58
64
  ## Phase 1: Analyze — 代码分析
65
+
59
66
  **Goal**: Assess current code state, identify refactoring targets, establish baseline.
67
+
60
68
  **STEPS:**
69
+
61
70
  1. **Read target code**: Thoroughly read and understand the target module/files:
62
71
  - Code structure and architecture
63
72
  - Dependencies (incoming and outgoing)
64
73
  - Current test coverage
65
74
  - Known tech debt (from `.prizm-docs/` TRAPS)
66
- 2. **Invoke `prizmkit.tech-debt-tracker`** on target area:
75
+ 2. **Invoke `/prizmkit-tool-tech-debt-tracker`** on target area:
67
76
  - Receive: debt items, complexity metrics, code smell patterns
68
77
  - Identify highest-impact refactoring opportunities
69
78
  3. **Establish baseline**:
@@ -77,15 +86,21 @@ Execute the full refactor pipeline for a module or code area.
77
86
  - **Risk Assessment**: what could break, cross-module impact, data migration needs
78
87
  - **Baseline Tests**: test suite status (total, passing, failing), coverage estimate, behavior contracts to preserve
79
88
  - **Scope Boundary**: what IS in scope, what is explicitly OUT of scope
89
+
80
90
  **CHECKPOINT CP-RW-1**: `refactor-analysis.md` exists with baseline test results.
91
+
81
92
  ---
93
+
82
94
  ## Phase 2: Plan — 重构方案与任务
95
+
83
96
  **Goal**: Generate technical refactoring plan that preserves behavior, including task breakdown.
97
+
84
98
  **STEPS:**
99
+
85
100
  1. **Read context**: refactor-analysis.md, `.prizm-docs/` (PATTERNS, RULES, TRAPS)
86
- 2. **Invoke `prizmkit.plan`** with refactor-analysis.md as input (in place of spec.md):
87
- - Plan MUST specify: what changes, what stays the same, how behavior is preserved
88
- - plan.md Tasks section: each task MUST be independently testable, MUST preserve all tests (green → green)
101
+ 2. **Invoke `/prizmkit-plan`** with refactor-analysis.md as input (in place of spec.md):
102
+ - Plan specifies: what changes, what stays the same, how behavior is preserved
103
+ - plan.md Tasks section: each task is independently testable and preserves all tests (green → green) — this ensures any failure is immediately traceable to the task that caused it
89
104
  - Artifact path: `.prizmkit/refactor/<refactor-slug>/plan.md`
90
105
  3. **Verify plan constraints**:
91
106
  - All public API contracts preserved
@@ -93,77 +108,109 @@ Execute the full refactor pipeline for a module or code area.
93
108
  - Rollback strategy: how to revert if behavior breaks
94
109
  - Tasks ordered to minimize risk (safe renames first, structural changes later)
95
110
  - Every task ends with "run full test suite"
111
+
96
112
  **CHECKPOINT CP-RW-2**: `plan.md` exists with behavior preservation strategy and Tasks section.
113
+
97
114
  ---
115
+
98
116
  ## Phase 3: Implement — 实现
117
+
99
118
  **Goal**: Execute refactoring tasks with mandatory test verification after each task.
119
+
100
120
  **STEPS:**
121
+
101
122
  1. **For EACH task in plan.md Tasks section**:
102
123
  a. Implement the refactoring change
103
- b. **Run FULL test suite** (not just affected tests)
124
+ b. **Run FULL test suite** (not just affected tests) — refactoring can have surprising cross-module effects that targeted tests miss
104
125
  c. Verify: all previously-passing tests still pass
105
- d. If any test fails → STOP, revert task, investigate
126
+ d. If any test fails → stop, revert task, investigate
106
127
  2. **Progress tracking**:
107
128
  - Mark tasks complete in plan.md Tasks section as they finish
108
129
  - Record test results after each task
130
+
109
131
  **CHECKPOINT CP-RW-3**: All tasks complete, full test suite green.
110
- **KEY RULES:**
111
- - NEVER skip the test gate between tasks
112
- - NEVER allow temporary test failures ("we'll fix it in the next task")
132
+
133
+ **Important constraints for Phase 3:**
134
+ - Never skip the test gate between tasks a broken intermediate state compounds into much harder debugging later
135
+ - Never allow temporary test failures ("we'll fix it in the next task") — this assumption is almost always wrong in refactoring
113
136
  - If a task cannot be completed without breaking tests → split it into smaller tasks
114
137
  - Max 3 attempts per task before escalating to user
138
+
115
139
  ---
140
+
116
141
  ## Phase 4: Code Review — 代码审查
142
+
117
143
  **Goal**: Verify refactoring quality and behavior preservation.
144
+
118
145
  **STEPS:**
119
- 1. **Invoke `prizmkit.code-review`** (scoped to changed files):
146
+
147
+ 1. **Invoke `/prizmkit-code-review`** (scoped to changed files):
120
148
  - Review dimensions for refactoring:
121
149
  - **Behavior preservation**: Does observable behavior remain identical?
122
150
  - **Structural improvement**: Is the code measurably better? (complexity, coupling, readability)
123
151
  - **Test integrity**: Are all tests still meaningful and passing?
124
152
  - **Code quality**: Does refactored code follow project conventions?
125
153
  - Verdict: PASS / PASS_WITH_WARNINGS / NEEDS_FIXES
126
- 2. **Run full test suite one final time**: All tests MUST pass
154
+ 2. **Run full test suite one final time**: All tests must pass
127
155
  3. **Handle review results**:
128
- - **PASS / PASS_WITH_WARNINGS**: Proceed to Phase 6
156
+ - **PASS / PASS_WITH_WARNINGS**: Proceed to Phase 5
129
157
  - **NEEDS_FIXES**: Return to Phase 3 (max 2 review rounds)
158
+
130
159
  **CHECKPOINT CP-RW-4**: Code review passes, all tests green.
160
+
131
161
  ---
162
+
132
163
  ## Phase 5: Commit — 提交
164
+
133
165
  **Goal**: Commit with refactor convention.
166
+
134
167
  **STEPS:**
135
- 1. **Invoke `prizmkit.committer`**:
168
+
169
+ 1. **Invoke `/prizmkit-retrospective`** (Job 1: structural sync only):
170
+ - Update KEY_FILES/INTERFACES/DEPENDENCIES in affected `.prizm-docs/` files
171
+ - Skip knowledge injection unless refactoring revealed a genuinely new pitfall (e.g. a non-obvious coupling)
172
+ - If structural changes are significant (module split/merge), update L1 doc
173
+ - Stage doc changes: `git add .prizm-docs/`
174
+ 2. **Invoke `/prizmkit-committer`**:
136
175
  - Commit message: `refactor(<scope>): <description>`
137
176
  - Include all refactored code + any test updates
138
177
  - Do NOT push
139
- - Do NOT invoke `prizmkit.summarize` (no REGISTRY entry for refactoring)
140
- 2. **Update `.prizm-docs/`** if needed:
141
- - Updated module structure documentation
142
- - New PATTERNS discovered
143
- - Resolved TRAPS (remove if debt is paid)
178
+
144
179
  **CHECKPOINT CP-RW-5**: Commit recorded with `refactor()` prefix.
180
+
145
181
  ---
182
+
146
183
  ## Fast Path — 快速路径
184
+
147
185
  For single-file refactoring (rename, extract method, <30 lines changed):
186
+
148
187
  ```
149
188
  Phase 1 (Analyze) → Phase 3 (Implement) → Phase 4 (Review) → Phase 5 (Commit)
150
189
  ```
190
+
151
191
  Skip Phase 2 (Plan).
192
+
152
193
  **CRITERIA** (ALL must be true):
153
194
  - Single file change
154
195
  - Estimated change < 30 lines
155
196
  - Well-known refactoring pattern (rename, extract method/class, inline, move)
156
197
  - No cross-module impact
157
198
  - No dependency changes
199
+
158
200
  **Fast Path still requires:**
159
201
  - refactor-analysis.md (lightweight version with baseline)
160
202
  - Full test suite run after implementation
161
203
  - Code review
162
204
  - `refactor(<scope>):` commit convention
205
+
163
206
  ---
207
+
164
208
  ## Resume — 中断恢复
209
+
165
210
  The pipeline supports resuming from the last completed phase by detecting existing artifacts.
211
+
166
212
  **Detection logic**: Check `.prizmkit/refactor/<slug>/` for:
213
+
167
214
  | Artifact Found | Resume From |
168
215
  |---------------|------------|
169
216
  | (nothing) | Phase 1: Analyze |
@@ -171,9 +218,13 @@ The pipeline supports resuming from the last completed phase by detecting existi
171
218
  | `refactor-analysis.md` + `plan.md` | Phase 3: Implement |
172
219
  | All docs + code changes exist | Phase 4: Review |
173
220
  | All docs + review passed | Phase 5: Commit |
174
- **Resume command**: `prizmkit.refactor <slug>` — if `<slug>` matches an existing `.prizmkit/refactor/<slug>/` directory, resume instead of starting fresh.
221
+
222
+ **Resume**: If `<slug>` matches an existing `.prizmkit/refactor/<slug>/` directory, resume instead of starting fresh.
223
+
175
224
  ---
225
+
176
226
  ## Error Handling
227
+
177
228
  | Scenario | Action |
178
229
  |----------|--------|
179
230
  | Cannot identify target module | Ask user for clarification |
@@ -184,22 +235,27 @@ The pipeline supports resuming from the last completed phase by detecting existi
184
235
  | Review fails after 2 rounds | Escalate with review findings |
185
236
  | Refactoring creates circular dependency | STOP, revise plan |
186
237
  | Performance regression detected | STOP, investigate, revise approach |
238
+
187
239
  ---
240
+
188
241
  ## Relationship to Other Skills
242
+
189
243
  | Skill | Role in Refactor Workflow |
190
244
  |-------|--------------------------|
191
- | `prizmkit-tool-tech-debt-tracker` | Phase 1: identify debt and complexity |
192
- | `prizmkit-plan` | Phase 2: refactoring plan + task generation |
193
- | `prizmkit-implement` | Phase 3: execute refactoring tasks |
194
- | `prizmkit-code-review` | Phase 4: review quality and behavior preservation |
195
- | `prizmkit-committer` | Phase 5: commit with `refactor()` convention |
245
+ | `/prizmkit-tool-tech-debt-tracker` | Phase 1: identify debt and complexity |
246
+ | `/prizmkit-plan` | Phase 2: refactoring plan + task generation |
247
+ | `/prizmkit-implement` | Phase 3: execute refactoring tasks |
248
+ | `/prizmkit-code-review` | Phase 4: review quality and behavior preservation |
249
+ | `/prizmkit-committer` | Phase 5: commit with `refactor()` convention |
250
+ | `/prizmkit-retrospective` | Phase 5: structural sync before commit (Job 1 only, skip knowledge injection unless new pitfall) |
196
251
  | `feature-workflow` | Handoff target when new behavior is needed |
197
- | `prizmkit-specify` | NOT used (no user stories for refactoring) |
198
- | `prizmkit-analyze` | NOT used (no spec ↔ plan consistency needed) |
199
- | `prizmkit-summarize` | NOT used (no REGISTRY entry for refactoring) |
200
- | `prizmkit-retrospective` | Optional: post-refactor lessons learned |
252
+ | `/prizmkit-specify` | NOT used (no user stories for refactoring) |
253
+ | `/prizmkit-analyze` | NOT used (no spec ↔ plan consistency needed) |
254
+
201
255
  ---
256
+
202
257
  ## Comparison with Feature and Bug Fix Pipelines
258
+
203
259
  | Dimension | Feature Workflow | Refactor Workflow | Bug Fix Pipeline |
204
260
  |-----------|-----------------|-------------------|------------------|
205
261
  | Input | Natural language requirement | Module/code target | Bug description |
@@ -211,9 +267,9 @@ The pipeline supports resuming from the last completed phase by detecting existi
211
267
  | Test Strategy | TDD per task | Full suite after EVERY task | Reproduction test |
212
268
  | Scope Guard | N/A | ✅ (enforced) | N/A |
213
269
  | Behavior Change | ✅ Expected | ❌ Forbidden | ✅ Fix behavior |
214
- ## Path References
215
- All internal asset paths MUST use `${SKILL_DIR}` placeholder for cross-IDE compatibility.
270
+
216
271
  ## Output
272
+
217
273
  - `refactor-analysis.md` (Phase 1 artifact)
218
274
  - `plan.md` with Tasks section (Phase 2 artifact)
219
275
  - Refactored implementation code (Phase 3)