prizmkit 1.1.129 → 1.1.131

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 (88) hide show
  1. package/bundled/VERSION.json +3 -3
  2. package/bundled/dev-pipeline/.env.example +1 -1
  3. package/bundled/dev-pipeline/prizmkit_runtime/checkpoint_state.py +445 -8
  4. package/bundled/dev-pipeline/prizmkit_runtime/runner_classification.py +87 -66
  5. package/bundled/dev-pipeline/prizmkit_runtime/runner_models.py +53 -3
  6. package/bundled/dev-pipeline/prizmkit_runtime/runner_recovery.py +55 -25
  7. package/bundled/dev-pipeline/prizmkit_runtime/runner_status.py +4 -0
  8. package/bundled/dev-pipeline/prizmkit_runtime/runners.py +15 -1
  9. package/bundled/dev-pipeline/scripts/generate-bootstrap-prompt.py +398 -6
  10. package/bundled/dev-pipeline/scripts/generate-bugfix-prompt.py +61 -3
  11. package/bundled/dev-pipeline/scripts/generate-refactor-prompt.py +64 -4
  12. package/bundled/dev-pipeline/scripts/prompt_framework.py +156 -7
  13. package/bundled/dev-pipeline/scripts/update-bug-status.py +53 -0
  14. package/bundled/dev-pipeline/scripts/update-checkpoint.py +294 -69
  15. package/bundled/dev-pipeline/scripts/update-feature-status.py +57 -0
  16. package/bundled/dev-pipeline/scripts/update-refactor-status.py +53 -0
  17. package/bundled/dev-pipeline/templates/bootstrap-prompt.md +2 -2
  18. package/bundled/dev-pipeline/templates/bootstrap-tier3.md +20 -14
  19. package/bundled/dev-pipeline/templates/bugfix-bootstrap-prompt.md +21 -4
  20. package/bundled/dev-pipeline/templates/refactor-bootstrap-prompt.md +18 -0
  21. package/bundled/dev-pipeline/templates/sections/bugfix-phase-diagnose-plan.md +1 -1
  22. package/bundled/dev-pipeline/templates/sections/bugfix-phase-review.md +5 -15
  23. package/bundled/dev-pipeline/templates/sections/bugfix-phase-test.md +21 -0
  24. package/bundled/dev-pipeline/templates/sections/checkpoint-system.md +10 -10
  25. package/bundled/dev-pipeline/templates/sections/headless-commit-authorization.md +16 -0
  26. package/bundled/dev-pipeline/templates/sections/phase-prizmkit-test.md +26 -23
  27. package/bundled/dev-pipeline/templates/sections/phase-review-full.md +12 -8
  28. package/bundled/dev-pipeline/templates/sections/refactor-phase-review.md +1 -1
  29. package/bundled/dev-pipeline/templates/sections/refactor-phase-test.md +21 -0
  30. package/bundled/dev-pipeline/tests/test_checkpoint_state.py +362 -3
  31. package/bundled/dev-pipeline/tests/test_generate_bootstrap_prompt.py +404 -24
  32. package/bundled/dev-pipeline/tests/test_generate_bugfix_prompt.py +132 -0
  33. package/bundled/dev-pipeline/tests/test_generate_refactor_prompt.py +91 -0
  34. package/bundled/dev-pipeline/tests/test_python_runner_parity.py +411 -18
  35. package/bundled/dev-pipeline/tests/test_unified_cli.py +3 -3
  36. package/bundled/skills/_metadata.json +62 -25
  37. package/bundled/skills/app-planner/SKILL.md +4 -3
  38. package/bundled/skills/bug-fix-workflow/SKILL.md +89 -180
  39. package/bundled/skills/bug-planner/SKILL.md +12 -27
  40. package/bundled/skills/bugfix-pipeline-launcher/SKILL.md +131 -220
  41. package/bundled/skills/bugfix-pipeline-launcher/references/configuration.md +36 -90
  42. package/bundled/skills/feature-pipeline-launcher/SKILL.md +129 -271
  43. package/bundled/skills/feature-pipeline-launcher/references/configuration.md +35 -76
  44. package/bundled/skills/feature-planner/SKILL.md +27 -22
  45. package/bundled/skills/feature-planner/assets/planning-guide.md +4 -4
  46. package/bundled/skills/feature-workflow/SKILL.md +94 -121
  47. package/bundled/skills/prizmkit/SKILL.md +130 -94
  48. package/bundled/skills/prizmkit/references/workflow-state-protocol.md +181 -0
  49. package/bundled/skills/prizmkit-code-review/SKILL.md +114 -84
  50. package/bundled/skills/prizmkit-code-review/references/review-report-template.md +1 -1
  51. package/bundled/skills/prizmkit-code-review/references/workflow-state-protocol.md +181 -0
  52. package/bundled/skills/prizmkit-committer/SKILL.md +131 -47
  53. package/bundled/skills/prizmkit-committer/references/workflow-state-protocol.md +181 -0
  54. package/bundled/skills/prizmkit-implement/SKILL.md +99 -73
  55. package/bundled/skills/prizmkit-implement/references/implementation-subagent-procedure.md +1 -1
  56. package/bundled/skills/prizmkit-implement/references/workflow-state-protocol.md +181 -0
  57. package/bundled/skills/prizmkit-init/SKILL.md +5 -5
  58. package/bundled/skills/prizmkit-plan/SKILL.md +132 -105
  59. package/bundled/skills/prizmkit-plan/references/workflow-state-protocol.md +181 -0
  60. package/bundled/skills/prizmkit-retrospective/SKILL.md +111 -53
  61. package/bundled/skills/prizmkit-retrospective/references/knowledge-injection-steps.md +7 -6
  62. package/bundled/skills/prizmkit-retrospective/references/structural-sync-steps.md +5 -4
  63. package/bundled/skills/prizmkit-retrospective/references/workflow-state-protocol.md +181 -0
  64. package/bundled/skills/prizmkit-test/SKILL.md +28 -6
  65. package/bundled/skills/prizmkit-test/references/examples.md +1 -1
  66. package/bundled/skills/prizmkit-test/references/test-report-template.md +1 -1
  67. package/bundled/skills/prizmkit-test/references/workflow-state-protocol.md +181 -0
  68. package/bundled/skills/prizmkit-workflow/SKILL.md +266 -0
  69. package/bundled/skills/prizmkit-workflow/references/workflow-state-protocol.md +181 -0
  70. package/bundled/skills/recovery-workflow/SKILL.md +62 -241
  71. package/bundled/skills/recovery-workflow/evals/evals.json +17 -33
  72. package/bundled/skills/recovery-workflow/references/detection.md +28 -52
  73. package/bundled/skills/recovery-workflow/scripts/detect-recovery-state.py +105 -439
  74. package/bundled/skills/refactor-pipeline-launcher/SKILL.md +136 -275
  75. package/bundled/skills/refactor-pipeline-launcher/references/configuration.md +53 -88
  76. package/bundled/skills/refactor-planner/SKILL.md +12 -57
  77. package/bundled/skills/refactor-planner/references/behavior-preservation.md +111 -230
  78. package/bundled/skills/refactor-planner/references/error-recovery.md +37 -0
  79. package/bundled/skills/refactor-planner/references/planning-phases.md +11 -17
  80. package/bundled/skills/refactor-planner/scripts/validate-and-generate-refactor.py +1 -1
  81. package/bundled/skills/refactor-workflow/SKILL.md +98 -139
  82. package/bundled/templates/project-memory-template.md +4 -4
  83. package/package.json +1 -1
  84. package/src/index.js +4 -0
  85. package/src/prompts.js +10 -3
  86. package/src/scaffold.js +1 -1
  87. package/bundled/dev-pipeline/tests/test-deploy-safety.sh +0 -223
  88. package/bundled/skills/feature-pipeline-launcher/scripts/preflight-check.py +0 -462
@@ -1,306 +1,187 @@
1
- # Behavior Preservation Guide
1
+ # Behavior Preservation Planning Guide
2
2
 
3
- This guide covers strategies for ensuring that refactoring changes structure without changing behavior. Every refactor item must declare a behavior preservation strategy.
3
+ This guide helps the planner select and describe behavior-preservation evidence for each refactor item. It is a planning reference only: inspect existing code and test configuration as read-only evidence, then record what the downstream refactor session must prove. Do not run tests, change code, capture runtime snapshots, or perform rollback from this planner.
4
4
 
5
- ---
5
+ ## Table of Contents
6
6
 
7
- ## 1. Preservation Strategies
7
+ 1. [Planning Boundary](#planning-boundary)
8
+ 2. [Preservation Strategies](#preservation-strategies)
9
+ 3. [Strategy Selection](#strategy-selection)
10
+ 4. [Behavior-Risk Checklist](#behavior-risk-checklist)
11
+ 5. [Coverage Assessment](#coverage-assessment)
12
+ 6. [Plan-Readiness Checklist](#plan-readiness-checklist)
8
13
 
9
- ### Strategy: test-gate
14
+ ## Planning Boundary
10
15
 
11
- **Definition**: Run the full test suite after each refactoring change. All previously-passing tests must continue to pass.
16
+ For every refactor item, the planner must:
12
17
 
13
- **How it works**:
14
- 1. Run the full test suite before starting the refactor item (establish baseline)
15
- 2. Implement the refactoring change
16
- 3. Run the full test suite again
17
- 4. Compare: all tests that passed before must still pass
18
- 5. If any test fails -> revert the change, investigate, and retry
18
+ - choose a primary strategy: `test-gate`, `snapshot`, or `manual`;
19
+ - identify the observable behavior that must remain stable;
20
+ - identify existing evidence sources when they are discoverable by reading the repository;
21
+ - record missing evidence and any prerequisite item needed to close the gap;
22
+ - write measurable acceptance criteria that a non-interactive downstream session can evaluate;
23
+ - avoid claiming that tests, snapshots, or manual verification have already run.
19
24
 
20
- **When to use**:
21
- - Target area has good test coverage (>60%)
22
- - Tests are reliable (no flaky tests in the target area)
23
- - Test suite runs in reasonable time (<5 minutes for the relevant subset)
24
- - Tests cover the behavior contracts you need to preserve
25
+ ## Preservation Strategies
25
26
 
26
- **Strengths**:
27
- - Most reliable automated strategy
28
- - Catches regressions immediately
29
- - Well-understood and widely practiced
30
- - Works with any test framework
27
+ ### Strategy: `test-gate`
31
28
 
32
- **Limitations**:
33
- - Only as good as test coverage — untested behavior can still break
34
- - Slow test suites may bottleneck iteration speed
35
- - Flaky tests create false negatives
29
+ Use when the target has reliable automated tests that cover the behavior being preserved.
30
+
31
+ Planning requirements:
32
+
33
+ - name the relevant test files, suites, or project-native test command when discoverable;
34
+ - identify the behavior contracts represented by those tests;
35
+ - require evidence that previously passing relevant tests remain passing after the structural change;
36
+ - note known flaky tests or coverage gaps;
37
+ - add a prerequisite planning item when missing tests make the refactor unsafe.
36
38
 
37
- **Configuration in refactor-list.json**:
38
39
  ```json
39
40
  {
40
41
  "behavior_preservation": {
41
42
  "strategy": "test-gate",
42
- "existing_tests": true
43
+ "existing_tests": true,
44
+ "new_tests_needed": []
43
45
  }
44
46
  }
45
47
  ```
46
48
 
47
- ---
48
-
49
- ### Strategy: snapshot
49
+ ### Strategy: `snapshot`
50
50
 
51
- **Definition**: Capture the observable output/state of the target code before and after refactoring, then compare.
51
+ Use when formal coverage is insufficient but deterministic observable behavior can be compared.
52
52
 
53
- **How it works**:
54
- 1. Identify observable outputs of the target code (API responses, rendered UI, log output, file output)
55
- 2. Capture a "before" snapshot by exercising the code with representative inputs
56
- 3. Implement the refactoring change
57
- 4. Capture an "after" snapshot with the same inputs
58
- 5. Compare: snapshots must match (or differ only in acceptable ways like formatting)
53
+ Planning requirements:
59
54
 
60
- **When to use**:
61
- - Test coverage is insufficient but behavior is observable
62
- - The code produces deterministic output for given inputs
63
- - You can identify representative inputs that exercise the key behavior paths
64
- - API endpoints, CLI tools, data processing pipelines
55
+ - define representative inputs;
56
+ - define the observable outputs or state to compare;
57
+ - define allowed normalization or acceptable differences;
58
+ - require before/after evidence from the same inputs;
59
+ - identify non-deterministic fields that must be excluded or normalized.
65
60
 
66
- **Strengths**:
67
- - Works even when formal tests are missing
68
- - Captures real behavior rather than test assertions
69
- - Can detect subtle regressions that tests might miss
70
-
71
- **Limitations**:
72
- - Requires deterministic behavior (non-deterministic outputs need normalization)
73
- - May miss edge cases if representative inputs are incomplete
74
- - Snapshot comparison tools may need configuration for acceptable differences
75
- - More manual setup than test-gate
76
-
77
- **Configuration in refactor-list.json**:
78
61
  ```json
79
62
  {
80
63
  "behavior_preservation": {
81
- "strategy": "snapshot"
64
+ "strategy": "snapshot",
65
+ "existing_tests": false,
66
+ "new_tests_needed": []
82
67
  },
83
68
  "acceptance_criteria": [
84
- "API responses for /api/users/* match before/after snapshots",
85
- "CLI output for --help remains unchanged"
69
+ "Responses for the documented API cases match the approved baseline after normalization",
70
+ "CLI help output preserves all documented flags and exit codes"
86
71
  ]
87
72
  }
88
73
  ```
89
74
 
90
- ---
91
-
92
- ### Strategy: manual
75
+ ### Strategy: `manual`
93
76
 
94
- **Definition**: Human verification is required to confirm behavior is preserved. Used as a last resort.
77
+ Use only when neither reliable tests nor deterministic observable output can prove preservation.
95
78
 
96
- **When to use**:
97
- - No test coverage AND no easily observable deterministic output
98
- - UI-heavy changes where visual regression is the primary concern
99
- - Legacy code with unknown behavior contracts
100
- - Code that interacts with external services in non-reproducible ways
79
+ Planning requirements:
101
80
 
102
- **How it works**:
103
- 1. Document the current behavior (screenshots, recordings, written descriptions)
104
- 2. Implement the refactoring change
105
- 3. Human manually verifies the behavior matches the documentation
106
- 4. Human signs off on the change
81
+ - state exactly which behavior requires human judgment;
82
+ - define a reproducible verification checklist;
83
+ - identify required screenshots, recordings, or written baselines;
84
+ - mark the item as high verification risk;
85
+ - avoid subjective criteria such as “looks correct” without named observations.
107
86
 
108
- **Strengths**:
109
- - Works for any situation
110
- - Humans can assess subjective quality (UI layout, user experience)
111
- - Can catch issues that automated tools miss
112
-
113
- **Limitations**:
114
- - Slowest strategy — blocks on human availability
115
- - Error-prone — humans miss regressions, especially subtle ones
116
- - Not scalable — each item needs separate human attention
117
- - Not repeatable — different humans may verify differently
118
-
119
- **Configuration in refactor-list.json**:
120
87
  ```json
121
88
  {
122
89
  "behavior_preservation": {
123
- "strategy": "manual"
90
+ "strategy": "manual",
91
+ "existing_tests": false,
92
+ "new_tests_needed": []
124
93
  },
125
94
  "acceptance_criteria": [
126
- "Manual verification confirms email login, social login, and password reset behavior remain unchanged"
95
+ "The verification checklist covers email login, social login, and password reset without changing their documented outcomes"
127
96
  ]
128
97
  }
129
98
  ```
130
99
 
131
- ---
132
-
133
- ## 2. Choosing the Right Strategy
134
-
135
- Use this decision tree to select the appropriate strategy for each refactor item:
136
-
137
- 1. If the target area has reliable test coverage above 60%, choose `test-gate`.
138
- 2. If tests exist but are flaky, plan a prerequisite item to stabilize tests first; if stabilization is out of scope, choose `snapshot`.
139
- 3. If test coverage is below 60% but behavior is deterministic and observable, choose `snapshot`.
140
- 4. If neither reliable tests nor deterministic observable output exist, choose `manual` and flag the item as high risk.
141
-
142
- ### Strategy Selection Table
143
-
144
- | Test Coverage | Output Observable | Recommended Strategy | Risk Level |
145
- |--------------|-------------------|---------------------|------------|
146
- | High (>60%) | Yes | test-gate | Low |
147
- | High (>60%) | No | test-gate | Low |
148
- | Medium (30-60%) | Yes | test-gate + snapshot | Medium |
149
- | Medium (30-60%) | No | test-gate (acknowledge gaps) | Medium |
150
- | Low (<30%) | Yes | snapshot | Medium-High |
151
- | Low (<30%) | No | manual | High |
152
- | None (0%) | Yes | snapshot | High |
153
- | None (0%) | No | manual | Very High |
154
-
155
- ### Mixed Strategies
156
-
157
- For complex items, you can combine strategies:
158
- - **test-gate + snapshot**: Run tests AND compare output snapshots. Provides defense in depth.
159
- - **test-gate + manual**: Run tests AND have a human verify UI/UX aspects.
160
- - Use the primary strategy in the `behavior_preservation` field and note the secondary in `verification_notes`.
161
-
162
- ---
163
-
164
- ## 3. Common Behavior-Breaking Pitfalls
165
-
166
- These are patterns that frequently cause unintended behavior changes during refactoring. Check for each one when planning.
167
-
168
- ### 3.1 Side Effect Ordering
169
-
170
- **Pitfall**: Reordering function calls or module initialization can change side effects.
171
-
172
- **Example**: Moving `initLogger()` after `loadConfig()` when the logger depends on config.
100
+ ## Strategy Selection
173
101
 
174
- **Prevention**: Map side effects and their dependencies before restructuring. Document execution order constraints.
102
+ Choose the smallest strategy that can credibly prove behavior preservation:
175
103
 
176
- ### 3.2 Error Handling Changes
104
+ 1. Reliable relevant tests exist and cover the contract: choose `test-gate`.
105
+ 2. Tests are incomplete but behavior is deterministic and observable: choose `snapshot`.
106
+ 3. Tests are flaky: plan stabilization as a prerequisite, or use `snapshot` when stabilization is explicitly out of scope.
107
+ 4. Neither automated evidence source is viable: choose `manual` and document the risk.
177
108
 
178
- **Pitfall**: Extracting code into a new function changes which errors are caught and where.
109
+ | Existing Evidence | Observable Output | Primary Strategy | Planning Risk |
110
+ |---|---|---|---|
111
+ | Reliable tests | Any | `test-gate` | Low |
112
+ | Partial tests | Deterministic | `snapshot` or `test-gate` with documented gaps | Medium |
113
+ | No reliable tests | Deterministic | `snapshot` | High |
114
+ | No reliable tests | Non-deterministic or subjective | `manual` | Very high |
179
115
 
180
- **Example**: A try/catch block that previously caught errors from inline code no longer catches them when the code is extracted to a separate function with its own error handling.
116
+ When a complex item needs more than one evidence type, keep one primary strategy in `behavior_preservation` and record supplemental evidence in acceptance criteria or verification notes.
181
117
 
182
- **Prevention**: Trace error propagation paths before and after. Ensure the same errors reach the same handlers.
118
+ ## Behavior-Risk Checklist
183
119
 
184
- ### 3.3 Closure and Scope Changes
120
+ Inspect the target and capture relevant risks in the item description or acceptance criteria.
185
121
 
186
- **Pitfall**: Moving code changes what variables are in scope, especially with closures.
122
+ ### Side-effect ordering
187
123
 
188
- **Example**: Extracting a closure that captures `this` into a standalone function loses the `this` binding.
124
+ Record initialization, mutation, and external-call ordering that must not change.
189
125
 
190
- **Prevention**: Identify all captured variables. Ensure they are passed as parameters or the binding is preserved.
126
+ ### Error propagation
191
127
 
192
- ### 3.4 Import Order Side Effects
128
+ Record which errors reach which handlers, including error types, messages, codes, and retry behavior.
193
129
 
194
- **Pitfall**: In some languages/frameworks, import order matters (module initialization, polyfills, monkey-patching).
130
+ ### Closure and binding semantics
195
131
 
196
- **Example**: Moving an import of a polyfill to a different position causes it to load after the code that needs it.
132
+ Record captured variables, `this` binding, lifetime, and scope assumptions affected by extraction or movement.
197
133
 
198
- **Prevention**: Identify imports with side effects. Document order constraints. Test module initialization explicitly.
134
+ ### Import-time behavior
199
135
 
200
- ### 3.5 Default Parameter Changes
136
+ Record side-effect imports, polyfills, registration order, and module initialization dependencies.
201
137
 
202
- **Pitfall**: Extracting a function and adding default parameters changes behavior for callers that relied on the old defaults.
138
+ ### Defaults and type coercion
203
139
 
204
- **Example**: Original: `function process(data, format) { format = format || 'json'; ... }` — Refactored: `function process(data, format = 'json') { ... }` These behave differently for `process(data, '')` (empty string).
140
+ Record existing default-value and coercion behavior, especially where falsy values differ from missing values.
205
141
 
206
- **Prevention**: Audit all default value logic. Use identical defaulting behavior in the refactored version.
142
+ ### Async timing and concurrency
207
143
 
208
- ### 3.6 Async/Await Conversion Gotchas
144
+ Record ordering, atomicity, cancellation, race, and shared-state constraints.
209
145
 
210
- **Pitfall**: Converting callbacks to async/await can change error propagation, timing, and concurrency.
146
+ ### Public interfaces
211
147
 
212
- **Example**: Callback errors that were silently swallowed now throw unhandled promise rejections.
148
+ Record exports, signatures, import paths, configuration keys, CLI flags, response shapes, and compatibility commitments.
213
149
 
214
- **Prevention**: Map all error paths in the callback version. Ensure async version handles every path. Test with error scenarios.
150
+ ### Operational observability
215
151
 
216
- ### 3.7 Type Coercion Changes
152
+ Record log patterns, metrics, alerts, performance limits, and other externally observed behavior that consumers rely on.
217
153
 
218
- **Pitfall**: Moving code between contexts can change implicit type coercion behavior.
154
+ ## Coverage Assessment
219
155
 
220
- **Example**: `==` comparisons that relied on type coercion break when types change due to new module boundaries.
156
+ Assess coverage by reading existing repository evidence only:
221
157
 
222
- **Prevention**: Prefer strict equality. Audit type assumptions at module boundaries.
158
+ - test runner configuration;
159
+ - relevant test files and their imports;
160
+ - assertions that describe behavior contracts;
161
+ - existing coverage reports when already present;
162
+ - project documentation and CI configuration.
223
163
 
224
- ### 3.8 Timing and Race Conditions
164
+ Do not generate fresh coverage evidence from this planner. When current coverage cannot be established from existing files, record it as `unknown` rather than guessing.
225
165
 
226
- **Pitfall**: Restructuring async code can change execution timing, revealing or creating race conditions.
227
-
228
- **Example**: Splitting a synchronous operation into two async steps creates a window where state is inconsistent.
229
-
230
- **Prevention**: Identify shared mutable state. Ensure atomicity is preserved. Test concurrent scenarios.
231
-
232
- ---
233
-
234
- ## 4. Test Coverage Assessment
235
-
236
- Before refactoring, assess the test coverage of the target area to select the appropriate preservation strategy.
237
-
238
- ### Quick Coverage Assessment
239
-
240
- If a formal coverage tool is available:
241
- ```bash
242
- # JavaScript (Istanbul/nyc)
243
- npx nyc --reporter=text -- npm test -- --grep "target-module"
244
-
245
- # Python (pytest-cov)
246
- pytest --cov=target_module --cov-report=term-missing
247
-
248
- # Go
249
- go test -coverprofile=coverage.out ./target-package/...
250
- ```
251
-
252
- ### Manual Coverage Assessment
253
-
254
- When coverage tools aren't available, assess manually:
255
-
256
- 1. **List all public functions/methods** in the target area
257
- 2. **Search for test files** that import or reference the target
258
- 3. **Check test assertions** — do they test behavior or just structure?
259
- 4. **Identify untested paths** — error handling, edge cases, default behavior
260
-
261
- ### Coverage-Based Planning Decisions
262
-
263
- | Coverage Level | Planning Decision |
264
- |---------------|-------------------|
265
- | >80% | Proceed with test-gate. High confidence in behavior preservation. |
266
- | 60-80% | Proceed with test-gate. Note gaps in refactor item descriptions for the pipeline to be cautious about. |
267
- | 30-60% | Consider writing additional tests before refactoring as a normal `R-NNN` prerequisite item. Or use snapshot strategy for low-coverage areas. |
268
- | <30% | Strongly recommend writing tests first. If user declines, use snapshot or manual strategy and flag as high risk. |
269
- | 0% | WARN user explicitly. Recommend writing tests as a prerequisite. If user insists on proceeding, use manual strategy and document all known behaviors. |
270
-
271
- ### Adding Tests as a Prerequisite Item
272
-
273
- When test coverage is insufficient, add a prerequisite refactor item using the normal `R-NNN` sequence. If the prerequisite is added before other generated items, it is usually `R-001`; downstream refactors depend on that ID.
274
-
275
- ```
276
- Refactor Item R-001:
277
- Title: Add test coverage for [target area] before refactoring
278
- Type: restructure
279
- Scope: [test files]
280
- Priority: critical
281
- Complexity: medium
282
- Behavior Preservation: manual (no existing tests to gate against)
283
- Acceptance Criteria:
284
- - Test coverage for [target area] reaches >60%
285
- - Tests cover: [list key behavior contracts]
286
- - All new tests pass
287
- Dependencies: none
288
- ```
166
+ Planning decisions:
289
167
 
290
- This item runs first, establishing the test baseline that all subsequent items use for their test-gate strategy.
168
+ - Strong relevant coverage: use `test-gate` and name the evidence source.
169
+ - Partial coverage: list uncovered paths and consider a prerequisite test item.
170
+ - No relevant coverage: prefer a prerequisite test item or a snapshot strategy.
171
+ - No viable automated evidence: use `manual`, document the verification protocol, and flag the risk.
291
172
 
292
- ---
173
+ A prerequisite test item remains a planning artifact. It must describe the missing contracts and measurable evidence without claiming the tests were already written or run.
293
174
 
294
- ## 5. Behavior Verification Checklist
175
+ ## Plan-Readiness Checklist
295
176
 
296
- Before marking a refactor item as complete, verify:
177
+ Before finalizing each refactor item, verify the plan states:
297
178
 
298
- - [ ] All previously-passing tests still pass
299
- - [ ] No new warnings or deprecation notices in test output
300
- - [ ] No new lint errors introduced
301
- - [ ] Public API surface is unchanged (same exports, same function signatures)
302
- - [ ] Error messages and error codes are unchanged (consumers may depend on these)
303
- - [ ] Logging output is unchanged (monitoring/alerting may depend on log patterns)
304
- - [ ] Configuration interface is unchanged (env vars, config files, CLI flags)
305
- - [ ] Performance characteristics are within acceptable bounds (no regression >10%)
306
- - [ ] No dead code left behind (unused imports, unreachable functions)
179
+ - [ ] the primary preservation strategy;
180
+ - [ ] the behavior contracts that must remain stable;
181
+ - [ ] the existing evidence sources, or an explicit `unknown`/missing-evidence statement;
182
+ - [ ] prerequisite evidence work when necessary;
183
+ - [ ] measurable post-change acceptance criteria;
184
+ - [ ] public interface and compatibility constraints;
185
+ - [ ] error, logging, configuration, and performance constraints when relevant;
186
+ - [ ] supplemental browser or manual evidence when automated evidence is insufficient;
187
+ - [ ] no claim that implementation or verification has already occurred.
@@ -0,0 +1,37 @@
1
+ # Refactor Planner Error Recovery
2
+
3
+ Load this reference when validation fails, the planning session is interrupted, existing planning artifacts are detected, or the user exits before a valid final plan is produced.
4
+
5
+ ## Validation Recovery
6
+
7
+ - Warnings only: present the warnings and ask whether to continue.
8
+ - Validation errors: group related errors, correct the planning draft, and regenerate. Limit automatic correction to three attempts before asking the user how to proceed.
9
+ - Keep `.prizmkit/plans/refactor-list.json` at the project-root `.prizmkit/plans/` path.
10
+ - Do not alter source code or run project tests while recovering a planning artifact.
11
+
12
+ ## Resume Detection
13
+
14
+ | Artifact Found | Resume Point |
15
+ |---|---|
16
+ | No planning artifact | Phase 1: Project Context |
17
+ | Draft in `.prizmkit/plans/` | Phase matching the draft's completeness |
18
+ | Incomplete final refactor list | Phase 6: Completeness Review |
19
+ | Valid final refactor list | Mode D: Summary |
20
+
21
+ Read the artifact directly because `.prizmkit` content may be gitignored. Preserve existing valid entries and resume only the unfinished planning work.
22
+
23
+ ## Session Exit Gate
24
+
25
+ Activate the exit gate when all of these are true:
26
+
27
+ - the user explicitly invoked `refactor-planner`;
28
+ - validation has not passed;
29
+ - no valid final refactor list was produced in this session.
30
+
31
+ Use `AskUserQuestion` with these options:
32
+
33
+ - **Continue to completion (Recommended)** — resume from the detected planning phase.
34
+ - **Save draft and exit** — save current planning content as `.prizmkit/plans/refactor-list.draft.json`.
35
+ - **Abandon** — exit without saving new planning content.
36
+
37
+ When saving a draft, state clearly that it is not validated and can be resumed by running `refactor-planner` again.
@@ -19,9 +19,9 @@ For each refactoring goal:
19
19
 
20
20
  ## Phase 5: Per-Item Confirmation Loop
21
21
 
22
- For each item, display:
22
+ For each item, present the structured fields and use `AskUserQuestion` for the decision:
23
23
 
24
- ```
24
+ ```text
25
25
  Refactor Item R-001:
26
26
  Title: [title]
27
27
  Type: [extract/rename/restructure/simplify/decouple/migrate]
@@ -35,15 +35,9 @@ Refactor Item R-001:
35
35
  - [criterion 1]
36
36
  - [criterion 2]
37
37
  Dependencies: [none / R-002, R-003]
38
-
39
- Confirm? (Y/modify/skip)
40
38
  ```
41
39
 
42
- - **Y**: Accept item as-is
43
- - **modify**: User provides changes, update item, re-display for confirmation
44
- - **skip**: Remove item from the list
45
-
46
- Continue until all items are confirmed or skipped.
40
+ Offer `Accept`, `Modify`, and `Skip` as selectable options. Re-display modified items before acceptance, and continue until all items are accepted or skipped.
47
41
 
48
42
  ---
49
43
 
@@ -83,9 +77,9 @@ Every item MUST declare a behavior preservation strategy. Read `${SKILL_DIR}/ref
83
77
 
84
78
  | Strategy | When to Use |
85
79
  |----------|-------------|
86
- | `test-gate` | Target area has good test coverage. Run full test suite after each change. |
87
- | `snapshot` | Compare output/state before and after. Used when tests are insufficient but behavior is observable. |
88
- | `manual` | Human verification required. Last resort when neither tests nor snapshots are feasible. |
80
+ | `test-gate` | Reliable tests cover the preserved contract; record the relevant evidence and the required downstream pass condition. |
81
+ | `snapshot` | Deterministic output or state can be compared; record representative inputs, normalization, and required equivalence. |
82
+ | `manual` | Human judgment is unavoidable; record a reproducible checklist and flag the higher verification risk. |
89
83
 
90
84
  Flag items using `manual` strategy prominently — they carry the highest risk of behavior regression.
91
85
 
@@ -130,11 +124,11 @@ Anti-pattern: do not generate an all-high refactor list unless every item indepe
130
124
 
131
125
  ## Browser Verification
132
126
 
133
- Browser verification is supported for UI-affecting refactors, but it is supplemental. Every refactor still uses `behavior_preservation.strategy` as the primary behavior-preservation contract:
127
+ Browser verification is supported for UI-affecting refactors, but it is supplemental. Every refactor still uses `behavior_preservation.strategy` as the primary preservation contract:
134
128
 
135
- - `strategy: test-gate` — Rely on existing test suite. Pipeline runs tests before and after refactoring.
136
- - `strategy: snapshot` — Compare behavior before/after refactoring using executable snapshots (outputs, API responses, side effects)
137
- - `strategy: manual` — Require human verification that behavior is preserved
129
+ - `strategy: test-gate` — Record the relevant existing tests and the required downstream pass condition.
130
+ - `strategy: snapshot` — Record the representative inputs, observable outputs, and allowed normalization for downstream comparison.
131
+ - `strategy: manual` — Record a reproducible human-verification checklist and the reason automated evidence is insufficient.
138
132
 
139
133
  For refactors that modify UI code, add `browser_interaction.verify_steps` when visual or browser-flow verification is useful. Also keep behavior-preservation acceptance criteria explicit:
140
134
 
@@ -150,4 +144,4 @@ Acceptance Criteria:
150
144
  4. Component is reusable in other views
151
145
  ```
152
146
 
153
- The refactor pipeline AI will use the snapshot strategy to verify external behavior is preserved during refactoring.
147
+ The generated plan supplies this evidence contract to the autonomous refactor session; this planner does not execute the verification.
@@ -32,7 +32,7 @@ from datetime import datetime, timezone
32
32
 
33
33
  SCHEMA_VERSION = "dev-pipeline-refactor-list-v1"
34
34
 
35
- VALID_STATUSES = {"pending", "in_progress", "completed", "failed", "skipped"}
35
+ VALID_STATUSES = {"pending", "in_progress", "completed", "failed", "skipped", "auto_skipped"}
36
36
  VALID_TYPES = {"extract", "rename", "restructure", "simplify", "decouple", "migrate"}
37
37
  VALID_PRIORITIES = {"critical", "high", "medium", "low"}
38
38
  VALID_COMPLEXITIES = {"low", "medium", "high"}