litclaude-ai 0.3.6 → 0.3.8

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.
@@ -9,19 +9,36 @@ Use this skill for behavior-preserving restructuring. A refactor changes shape,
9
9
  not observable behavior. If behavior changes, it is a feature or bug fix and
10
10
  needs its own RED test.
11
11
 
12
- ## Refactor Contract
12
+ This skill runs as a disciplined, phased workflow. The phases below are the
13
+ authoritative order: characterize, gate the intent, map the codebase, assess
14
+ coverage, execute step-by-step with verification, then sweep for regressions.
15
+ Do not skip phases. Refactoring without tests is reckless; refactoring without
16
+ understanding the impact zone is destructive.
13
17
 
14
- Before editing:
18
+ ## Tooling in Claude Code terms
15
19
 
16
- - Name the behavior that must remain unchanged.
17
- - Write or identify characterization tests.
18
- - Capture the current output, CLI behavior, hook JSON, or plugin manifest shape.
19
- - Decide the smallest cohesive unit to move, split, rename, or simplify.
20
+ - **LSP tool**: use it for precise analysis and safe edits — go-to-definition to
21
+ grasp context, find-references to map every call site before touching a
22
+ symbol, document/workspace symbols to outline a file, rename to move symbols
23
+ across the workspace, and diagnostics after every change.
24
+ - **Subagents (Agent/Task, namespaced `litclaude:*`)**: fan out read-only
25
+ exploration in parallel. Each subagent receives a self-contained brief —
26
+ children do not see prior conversation, so inline the target, the relevant
27
+ diffs, the constraints, and the exact report shape you want back.
28
+ - **Bash**: run the project's existing test, type-check, lint, and build
29
+ commands. Detect them from the repo; do not assume a runner.
30
+ - **TodoWrite**: keep the phase list and the per-step plan visible and updated
31
+ in real time.
32
+
33
+ ---
20
34
 
21
- ## Characterization First
35
+ ## Phase 0: Characterization First (MANDATORY)
22
36
 
23
- A characterization test pins current behavior before changes. It should assert
24
- the contract, not incidental formatting. For LitClaude, good contracts include:
37
+ A characterization test pins current behavior before any change. It asserts the
38
+ contract, not incidental formatting. Write or identify these tests before you
39
+ touch code, and record that they pass against the unchanged tree.
40
+
41
+ For LitClaude, good contracts include:
25
42
 
26
43
  - CLI command succeeds or fails with a controlled message.
27
44
  - hook JSON contains the expected activation context.
@@ -29,11 +46,326 @@ the contract, not incidental formatting. For LitClaude, good contracts include:
29
46
  - install state preserves unrelated Claude settings.
30
47
  - docs contain required install and publish guidance.
31
48
 
32
- Run the characterization test before refactoring and record that it passes.
49
+ Run the characterization test before refactoring and record that it passes. If
50
+ no such test exists and the target lacks coverage, Phase 3 decides whether you
51
+ add one first, pause, or block.
52
+
53
+ The refactor contract you commit to before editing:
54
+
55
+ - Name the behavior that must remain unchanged.
56
+ - Capture the current output, CLI behavior, hook JSON, or manifest shape.
57
+ - Decide the smallest cohesive unit to move, split, rename, or simplify.
58
+
59
+ ---
60
+
61
+ ## Phase 1: Intent Gate
62
+
63
+ Before any action, classify and validate the request.
64
+
65
+ ### 1.1 Parse the request type
66
+
67
+ | Signal | Classification | Action |
68
+ |--------|----------------|--------|
69
+ | Specific file/symbol named | Explicit | Proceed to Phase 2 |
70
+ | "Refactor X to Y" | Clear transformation | Proceed to Phase 2 |
71
+ | "Improve", "Clean up", "Modernize" | Open-ended | ASK: "What specific improvement?" |
72
+ | Ambiguous scope | Uncertain | ASK: "Which modules or files?" |
73
+ | Missing desired outcome | Incomplete | ASK: "What is the target shape?" |
74
+
75
+ ### 1.2 Validate understanding
76
+
77
+ Confirm all of the following before proceeding:
78
+
79
+ - [ ] Target is clearly identified.
80
+ - [ ] Desired outcome is understood.
81
+ - [ ] Scope is defined (file / module / project).
82
+ - [ ] Success criteria can be articulated.
83
+
84
+ If any item is unclear, stop and ask one focused clarifying question:
85
+
86
+ ```
87
+ I want to confirm the refactoring goal.
88
+
89
+ What I understood: [interpretation]
90
+ What I am unsure about: [specific ambiguity]
91
+
92
+ Options:
93
+ 1. [Option A] - [implications]
94
+ 2. [Option B] - [implications]
95
+
96
+ My recommendation: [suggestion with reasoning]
97
+
98
+ Should I proceed with the recommendation, or would you prefer differently?
99
+ ```
100
+
101
+ ### 1.3 Seed the phase todos
102
+
103
+ Immediately after the request is clear, register the phase list with TodoWrite:
104
+
105
+ ```
106
+ Phase 2: Codebase Analysis - map the target, dependents, tests, conventions
107
+ Phase 3: Codemap - dependency graph + impact-zone risk table
108
+ Phase 4: Coverage Assessment - decide the verification strategy
109
+ Phase 5: Execute - per-step edit -> verify -> revert, with commit checkpoints
110
+ Phase 6: Final Regression Sweep
111
+ ```
112
+
113
+ ---
114
+
115
+ ## Phase 2: Codebase Analysis
116
+
117
+ Mark Phase 2 in_progress.
118
+
119
+ ### 2.1 Parallel exploration with subagents
120
+
121
+ Fan out read-only `litclaude:*` exploration subagents in parallel. Give each one
122
+ a self-contained brief inlining the target and the exact report shape. Useful
123
+ lanes:
124
+
125
+ - **Target lane**: find every definition and occurrence of the target — report
126
+ file paths, line numbers, and usage patterns.
127
+ - **Dependents lane**: find all code that imports, calls, or depends on the
128
+ target — report dependency chains and import graphs.
129
+ - **Convention lane**: find similar patterns already in the codebase — report
130
+ analogous implementations and established conventions to follow.
131
+ - **Test lane**: find all test files touching the target — report paths, test
132
+ names, and coverage indicators.
133
+ - **Architecture lane**: find the module boundaries and design patterns around
134
+ the target — report layer structure and the patterns in use.
135
+
136
+ Each subagent runs with its own context. Collect every lane's findings before
137
+ building the codemap.
138
+
139
+ ### 2.2 Direct LSP and search analysis
140
+
141
+ Alongside subagent results, use the LSP tool directly for precision:
142
+
143
+ - go-to-definition: where is the symbol defined?
144
+ - find-references (include declaration): every usage across the workspace —
145
+ this is your authoritative call-site map.
146
+ - document symbols: a hierarchical outline of the file.
147
+ - workspace symbols: search the symbol by name across the project.
148
+ - diagnostics: capture the baseline error/warning state before any edit.
149
+
150
+ Use Grep for plain-text occurrences the LSP cannot resolve (strings, configs,
151
+ docs). Record the baseline diagnostics — it is the bar every later step must
152
+ hold.
153
+
154
+ Mark Phase 2 completed once all findings are collected.
155
+
156
+ ---
157
+
158
+ ## Phase 3: Codemap
159
+
160
+ Mark Phase 3 in_progress.
161
+
162
+ ### 3.1 Build the definitive codemap
163
+
164
+ From Phase 2 results, construct an explicit map:
165
+
166
+ ```
167
+ ## CODEMAP: [TARGET]
168
+
169
+ ### Core files (direct impact)
170
+ - path/to/file.ts:L10-L50 - primary definition
171
+ - path/to/file2.ts:L25 - key usage
172
+
173
+ ### Dependency graph
174
+ [TARGET]
175
+ imports from:
176
+ - module-a (types)
177
+ - module-b (utils)
178
+ imported by:
179
+ - consumer-1.ts
180
+ - consumer-2.ts
181
+ used by:
182
+ - handler.ts (direct call)
183
+ - service.ts (injected dependency)
184
+
185
+ ### Established patterns
186
+ - Pattern A: [description] - used in N places
187
+ - Pattern B: [description] - established convention
188
+ ```
189
+
190
+ ### 3.2 Impact-zone risk table
191
+
192
+ | Zone | Risk | Files affected | Coverage |
193
+ |------|------|----------------|----------|
194
+ | Core | HIGH | N files | xx% |
195
+ | Consumers | MEDIUM | N files | xx% |
196
+ | Edge | LOW | N files | xx% |
197
+
198
+ ### 3.3 Refactoring constraints
199
+
200
+ From the codemap, write down:
201
+
202
+ - **MUST follow**: the existing patterns identified above.
203
+ - **MUST NOT break**: critical dependencies and public contracts.
204
+ - **Safe to change**: isolated zones with good coverage.
205
+ - **Requires migration**: any breaking change and who it touches.
206
+
207
+ Mark Phase 3 completed.
208
+
209
+ ---
210
+
211
+ ## Phase 4: Coverage Assessment (gating)
212
+
213
+ Mark Phase 4 in_progress.
214
+
215
+ ### 4.1 Detect the test infrastructure
216
+
217
+ Discover the repo's actual commands — read `package.json` scripts,
218
+ `pyproject.toml` / `pytest.ini`, Go test files, or the equivalent. Do not assume
219
+ a runner.
220
+
221
+ ### 4.2 Assess coverage for the target
222
+
223
+ Use the Phase 2 test lane plus direct inspection to answer: which test files
224
+ cover this code, what cases exist, are there integration tests, what edge cases
225
+ are pinned, and roughly what fraction is covered.
226
+
227
+ ### 4.3 Choose the verification strategy
228
+
229
+ | Coverage | Strategy |
230
+ |----------|----------|
231
+ | HIGH (>80%) | Run existing tests after each step. |
232
+ | MEDIUM (50-80%) | Run tests plus add characterization assertions for the gaps. |
233
+ | LOW (<50%) | PAUSE: propose writing characterization tests first. |
234
+ | NONE | BLOCK: refuse the refactor until characterization tests exist. |
235
+
236
+ When coverage is LOW or NONE, stop and ask:
237
+
238
+ ```
239
+ Test coverage for [TARGET] is [LEVEL].
240
+ Refactoring without adequate tests is unsafe.
241
+
242
+ Options:
243
+ 1. Add characterization tests first, then refactor (recommended)
244
+ 2. Proceed with extra caution and manual verification
245
+ 3. Abort
246
+
247
+ Which do you prefer?
248
+ ```
249
+
250
+ ### 4.4 Document the verification plan
251
+
252
+ ```
253
+ ## VERIFICATION PLAN
254
+
255
+ Test commands (from this repo):
256
+ - Unit / integration: <actual command>
257
+ - Type check: <actual command>
258
+ - Lint / build: <actual command if relevant>
259
+
260
+ Per-step checkpoints:
261
+ 1. LSP diagnostics -> no new errors versus baseline
262
+ 2. Targeted tests -> all pass
263
+ 3. Type check -> clean
264
+
265
+ Regression indicators:
266
+ - [specific test that must keep passing]
267
+ - [behavior that must be preserved]
268
+ - [public contract that must not change]
269
+ ```
270
+
271
+ Mark Phase 4 completed.
272
+
273
+ ---
274
+
275
+ ## Phase 5: Execute (per-step edit -> verify -> revert)
276
+
277
+ Mark Phase 5 in_progress.
278
+
279
+ Break the work into atomic steps ordered by dependency. Each step must be
280
+ independently verifiable and independently reversible. Register the steps as
281
+ todos.
282
+
283
+ ### 5.1 Per-step protocol
284
+
285
+ For every step:
286
+
287
+ 1. Mark the step todo in_progress.
288
+ 2. Read the current file state; confirm LSP diagnostics match the baseline.
289
+ 3. Execute the smallest change:
290
+ - **Symbol rename**: use the LSP rename across the workspace, not text
291
+ search-and-replace.
292
+ - **Move or extract**: use the Edit tool for precise edits; keep one cohesive
293
+ unit per step.
294
+ - **Signature change**: update the definition, then walk every call site from
295
+ the find-references map.
296
+ 4. Verify (MANDATORY):
297
+ - LSP diagnostics on touched files — clean or equal to baseline.
298
+ - Run the targeted test command from the verification plan.
299
+ - Run the type check.
300
+ 5. If verification passes, mark the step completed and continue. If it fails,
301
+ enter the Failure Recovery Protocol.
302
+
303
+ ### 5.2 Failure Recovery Protocol
304
+
305
+ When any verification fails:
306
+
307
+ 1. **STOP** immediately — do not stack a second change on a broken step.
308
+ 2. **REVERT** the failed change to the last known-good state.
309
+ 3. **DIAGNOSE** the actual cause (read the failing assertion, the diagnostic,
310
+ the diff).
311
+ 4. Present **OPTIONS** and pick or ask:
312
+ - Fix the root cause and retry the same step.
313
+ - Skip the step if it was optional.
314
+ - Dispatch a read-only `litclaude:*` review subagent — inline the failure,
315
+ the touched files, and ask for a fix strategy.
316
+ - Ask the user for guidance.
317
+
318
+ NEVER proceed to the next step while tests are red.
319
+
320
+ ### 5.3 Commit checkpoints
321
+
322
+ After each logical group of verified steps, create a checkpoint commit so any
323
+ step is cheap to revert:
324
+
325
+ ```
326
+ git add <changed-files>
327
+ git commit -m "refactor(scope): <what changed and why>"
328
+ ```
329
+
330
+ Do not commit broken code, and do not hide a behavior change inside a refactor
331
+ commit.
332
+
333
+ Mark Phase 5 completed when every step is done and committed.
334
+
335
+ ---
336
+
337
+ ## Phase 6: Final Regression Sweep
338
+
339
+ Mark Phase 6 in_progress.
340
+
341
+ 1. Run the full relevant test suite (the real repo command).
342
+ 2. Run the full type check.
343
+ 3. Run the linter.
344
+ 4. Run the build if the project has one.
345
+ 5. Run LSP diagnostics across every changed file — all clean.
346
+ 6. Run one real-surface scenario if the refactor touched install, hooks, or CLI
347
+ (a CLI transcript, a hook JSON dump, or a manifest diff). Compare
348
+ before/after output where practical.
349
+ 7. Record cleanup for any spawned resource (subagent runs, temp files, ports).
350
+
351
+ Summarize:
352
+
353
+ ```
354
+ ## Refactoring complete
355
+
356
+ Changed: <files and what changed>
357
+ Tests: PASS (X/Y) Type check: CLEAN Lint: CLEAN Build: OK
358
+ Behavior: unchanged - characterization tests still green, no new diagnostics.
359
+ ```
360
+
361
+ Mark Phase 6 completed.
362
+
363
+ ---
33
364
 
34
365
  ## Safe Splits
35
366
 
36
- Split by responsibility:
367
+ Split by responsibility, never by arbitrary line range. Every new file must have
368
+ a clear owner:
37
369
 
38
370
  - parsing
39
371
  - registry/state reads
@@ -43,31 +375,63 @@ Split by responsibility:
43
375
  - docs-only policy
44
376
  - QA scripts
45
377
 
46
- Avoid splitting by arbitrary line ranges. A new file must have a clear owner.
378
+ ---
379
+
380
+ ## Critical Rules
381
+
382
+ ### NEVER
383
+ - Skip the LSP diagnostics check after a change.
384
+ - Proceed with failing or red tests.
385
+ - Edit a symbol without first mapping its call sites (find-references).
386
+ - Suppress type or lint errors to make a step pass.
387
+ - Rename a public CLI command without a compatibility alias.
388
+ - Change plugin keys such as `litclaude@litclaude-ai` silently.
389
+ - Alter install paths without migration tests.
390
+ - Delete or weaken tests to make a refactor pass.
391
+ - Commit broken code or hide a behavior change in a refactor commit.
47
392
 
48
- ## Prohibited Moves
393
+ ### ALWAYS
394
+ - Characterize before changing.
395
+ - Map the impact zone before editing.
396
+ - Preview a structural change before applying it.
397
+ - Verify after every step.
398
+ - Follow the established patterns the codemap surfaced.
399
+ - Keep the todos and phase state current.
400
+ - Commit at logical checkpoints.
401
+ - Keep the package `files` allowlist in sync when files move.
49
402
 
50
- - Do not rename public CLI commands without compatibility aliases.
51
- - Do not change plugin keys such as `litclaude@litclaude-ai` silently.
52
- - Do not alter install paths without migration tests.
53
- - Do not hide behavior changes inside refactor commits.
54
- - Do not delete tests to make a refactor pass.
403
+ ### ABORT and consult the user
404
+ - Coverage is NONE for the target and the user declined characterization tests.
405
+ - A change would break a public API or contract.
406
+ - The scope is still unclear after one clarifying question.
407
+ - Three consecutive verification failures on the same step.
408
+ - A user-defined constraint would be violated.
409
+
410
+ ---
55
411
 
56
- ## Verification
412
+ ## Deprecated Libraries and Migration
57
413
 
58
- After refactoring:
414
+ When you hit a deprecated method or API during a refactor:
59
415
 
60
- 1. Run targeted characterization tests.
61
- 2. Run the full relevant suite.
62
- 3. Run one real-surface scenario if the refactor touches install, hooks, or CLI.
63
- 4. Compare before/after outputs where practical.
64
- 5. Record cleanup for spawned resources.
416
+ 1. Dispatch a read-only research `litclaude:*` subagent (or use Context7 docs) to
417
+ find the recommended modern replacement before editing.
418
+ 2. Do NOT auto-upgrade to the latest version unless the user explicitly asked for
419
+ a migration a behavior-preserving refactor must not silently change runtime
420
+ behavior.
421
+ 3. If the user did request a migration, fetch the current API docs first, then
422
+ write characterization tests for the old behavior, then migrate step by step
423
+ under Phase 5.
424
+
425
+ ---
65
426
 
66
427
  ## Review Checklist
67
428
 
68
- - Public behavior unchanged.
429
+ - Public behavior unchanged; characterization tests still green.
69
430
  - Error messages still actionable.
70
431
  - Package `files` allowlist still includes moved files.
71
432
  - Docs still reference the right paths.
72
433
  - Tests fail if the behavior regresses.
73
434
  - No generated or user-owned state was rewritten unexpectedly.
435
+
436
+ Refactoring without tests is reckless. Refactoring without understanding the
437
+ impact zone is destructive. This workflow ensures you do neither.