claude-prism 0.8.0 → 1.0.0

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/bin/cli.mjs CHANGED
@@ -163,14 +163,81 @@ switch (command) {
163
163
  }
164
164
 
165
165
  console.log('🌈 claude-prism update\n');
166
- await update(cwd);
167
- console.log('āœ… UDEC methodology updated');
166
+ const result = await update(cwd);
167
+ if (result?.sourceRepo) {
168
+ console.log('āœ… UDEC methodology updated (from local templates)');
169
+ } else {
170
+ console.log('āœ… UDEC methodology updated');
171
+ }
168
172
  console.log('āœ… Commands updated');
169
173
  console.log('āœ… Commit guard updated');
170
174
  console.log('\n🌈 Prism updated to latest.');
171
175
  break;
172
176
  }
173
177
 
178
+ case 'analytics': {
179
+ const { listSessions, getSessionSummary } = await import('../lib/session.mjs');
180
+ console.log('🌈 claude-prism analytics\n');
181
+
182
+ const sessions = listSessions();
183
+ if (sessions.length === 0) {
184
+ console.log(' No session data yet. Analytics will populate as hooks run.');
185
+ break;
186
+ }
187
+
188
+ let totalBlocks = 0;
189
+ let totalWarnings = 0;
190
+ let totalTestsRun = 0;
191
+ let totalTestsPassed = 0;
192
+ let totalTestsFailed = 0;
193
+ let totalFilesModified = 0;
194
+ let totalFilesCreated = 0;
195
+ let totalTurns = 0;
196
+ let sessionCount = 0;
197
+
198
+ for (const sid of sessions) {
199
+ const summary = getSessionSummary(sid);
200
+ if (!summary) continue;
201
+ sessionCount++;
202
+ totalBlocks += summary.blocks;
203
+ totalWarnings += summary.warnings;
204
+ totalTestsRun += summary.testsRun;
205
+ totalTestsPassed += summary.testsPassed;
206
+ totalTestsFailed += summary.testsFailed;
207
+ totalFilesModified += summary.filesModified;
208
+ totalFilesCreated += summary.filesCreated;
209
+ totalTurns += summary.turns;
210
+ }
211
+
212
+ console.log(` Sessions: ${sessionCount}`);
213
+ console.log(` Total events: ${totalTurns + totalBlocks + totalWarnings + totalTestsRun + totalFilesModified + totalFilesCreated}`);
214
+ console.log('');
215
+ console.log(' Hook Effectiveness:');
216
+ console.log(` Blocks: ${totalBlocks}`);
217
+ console.log(` Warnings: ${totalWarnings}`);
218
+ console.log('');
219
+ console.log(' Test Activity:');
220
+ console.log(` Runs: ${totalTestsRun}`);
221
+ console.log(` Passed: ${totalTestsPassed}`);
222
+ console.log(` Failed: ${totalTestsFailed}`);
223
+ console.log('');
224
+ console.log(' File Activity:');
225
+ console.log(` Modified: ${totalFilesModified}`);
226
+ console.log(` Created: ${totalFilesCreated}`);
227
+
228
+ if (hasFlag('detail')) {
229
+ console.log('\n Recent Sessions:\n');
230
+ const recent = sessions.slice(-5);
231
+ for (const sid of recent) {
232
+ const s = getSessionSummary(sid);
233
+ if (!s) continue;
234
+ const date = new Date(s.startedAt).toISOString().slice(0, 19).replace('T', ' ');
235
+ console.log(` ${date} | events: ${s.totalEvents} | blocks: ${s.blocks} | warns: ${s.warnings} | tests: ${s.testsRun}`);
236
+ }
237
+ }
238
+ break;
239
+ }
240
+
174
241
  default: {
175
242
  console.log(`🌈 claude-prism — UDEC methodology framework for AI coding agents
176
243
 
@@ -181,6 +248,7 @@ Usage:
181
248
  prism doctor Diagnose issues with fix suggestions
182
249
  prism stats Show installation summary
183
250
  prism reset Clear hook state
251
+ prism analytics [--detail] Show usage analytics
184
252
  prism update Re-install using current config
185
253
  prism update --global Update global commands + OMC skill
186
254
  prism uninstall Remove prism from current project
package/lib/installer.mjs CHANGED
@@ -28,7 +28,7 @@ export async function init(projectDir, options = {}) {
28
28
  const nsCommandsDir = join(claudeDir, 'commands', 'claude-prism');
29
29
  mkdirSync(nsCommandsDir, { recursive: true });
30
30
 
31
- const commandFiles = ['prism.md', 'checkpoint.md', 'plan.md', 'doctor.md', 'stats.md', 'help.md', 'update.md'];
31
+ const commandFiles = ['prism.md', 'checkpoint.md', 'plan.md', 'doctor.md', 'stats.md', 'help.md', 'update.md', 'analytics.md'];
32
32
  for (const cmd of commandFiles) {
33
33
  copyFileSync(
34
34
  join(TEMPLATES_DIR, 'commands', 'claude-prism', cmd),
@@ -58,7 +58,7 @@ export async function init(projectDir, options = {}) {
58
58
  const libDestDir = join(claudeDir, 'lib');
59
59
  mkdirSync(libDestDir, { recursive: true });
60
60
  const libSourceDir = join(__dirname);
61
- for (const file of ['state.mjs', 'config.mjs', 'utils.mjs', 'messages.mjs', 'pipeline.mjs']) {
61
+ for (const file of ['state.mjs', 'config.mjs', 'utils.mjs', 'messages.mjs', 'pipeline.mjs', 'session.mjs']) {
62
62
  copyFileSync(join(libSourceDir, file), join(libDestDir, file));
63
63
  }
64
64
 
@@ -73,6 +73,7 @@ export async function init(projectDir, options = {}) {
73
73
  const configPath = join(projectDir, '.claude-prism.json');
74
74
  if (!existsSync(configPath)) {
75
75
  writeFileSync(configPath, JSON.stringify({
76
+ version: 1,
76
77
  hooks: {
77
78
  'commit-guard': { enabled: true, maxTestAge: 300 },
78
79
  'test-tracker': { enabled: true },
@@ -198,6 +199,23 @@ export function uninstall(projectDir) {
198
199
  * @param {string} projectDir
199
200
  */
200
201
  export async function update(projectDir) {
202
+ // Self-update detection: if running inside the claude-prism source repo,
203
+ // use local templates instead of the npx-downloaded package templates
204
+ const localPkgPath = join(projectDir, 'package.json');
205
+ if (existsSync(localPkgPath)) {
206
+ try {
207
+ const localPkg = JSON.parse(readFileSync(localPkgPath, 'utf8'));
208
+ if (localPkg.name === 'claude-prism') {
209
+ // We're in the source repo — use local templates directly
210
+ const localRulesPath = join(projectDir, 'templates', 'rules.md');
211
+ if (existsSync(localRulesPath)) {
212
+ injectRules(projectDir, localRulesPath);
213
+ return { sourceRepo: true };
214
+ }
215
+ }
216
+ } catch { /* not our package, proceed normally */ }
217
+ }
218
+
201
219
  // Migration: rename .prism.json to .claude-prism.json
202
220
  const oldConfigPath = join(projectDir, '.prism.json');
203
221
  const newConfigPath = join(projectDir, '.claude-prism.json');
@@ -255,8 +273,17 @@ export async function update(projectDir) {
255
273
  }
256
274
  }
257
275
 
258
- // Remove old config so init creates a fresh one
259
- if (existsSync(configPath)) rmSync(configPath);
276
+ // Migrate config: add version field if missing
277
+ if (existsSync(configPath)) {
278
+ try {
279
+ const existingConfig = JSON.parse(readFileSync(configPath, 'utf8'));
280
+ if (!existingConfig.version) {
281
+ existingConfig.version = 1;
282
+ writeFileSync(configPath, JSON.stringify(existingConfig, null, 2) + '\n');
283
+ }
284
+ } catch { /* proceed with fresh config */ }
285
+ rmSync(configPath);
286
+ }
260
287
 
261
288
  await init(projectDir, { hooks });
262
289
  }
@@ -275,7 +302,7 @@ export function doctor(projectDir, options = {}) {
275
302
 
276
303
  // Check namespaced commands
277
304
  const nsCommandsDir = join(claudeDir, 'commands', 'claude-prism');
278
- const expectedCommands = ['prism.md', 'checkpoint.md', 'plan.md', 'doctor.md', 'stats.md', 'help.md', 'update.md'];
305
+ const expectedCommands = ['prism.md', 'checkpoint.md', 'plan.md', 'doctor.md', 'stats.md', 'help.md', 'update.md', 'analytics.md'];
279
306
  for (const cmd of expectedCommands) {
280
307
  if (!existsSync(join(nsCommandsDir, cmd))) {
281
308
  issues.push(`Missing command: claude-prism/${cmd}`);
@@ -422,7 +449,7 @@ export function initGlobal(options = {}) {
422
449
  const commandsDir = join(claudeDir, 'commands', 'claude-prism');
423
450
  mkdirSync(commandsDir, { recursive: true });
424
451
 
425
- const commandFiles = ['prism.md', 'checkpoint.md', 'plan.md', 'doctor.md', 'stats.md', 'help.md', 'update.md'];
452
+ const commandFiles = ['prism.md', 'checkpoint.md', 'plan.md', 'doctor.md', 'stats.md', 'help.md', 'update.md', 'analytics.md'];
426
453
  for (const cmd of commandFiles) {
427
454
  copyFileSync(
428
455
  join(TEMPLATES_DIR, 'commands', 'claude-prism', cmd),
@@ -467,7 +494,7 @@ export function dryRun(projectDir, options = {}) {
467
494
 
468
495
  // Commands
469
496
  const nsCommandsDir = join(claudeDir, 'commands', 'claude-prism');
470
- const commandFiles = ['prism.md', 'checkpoint.md', 'plan.md', 'doctor.md', 'stats.md', 'help.md', 'update.md'];
497
+ const commandFiles = ['prism.md', 'checkpoint.md', 'plan.md', 'doctor.md', 'stats.md', 'help.md', 'update.md', 'analytics.md'];
471
498
  for (const cmd of commandFiles) {
472
499
  const target = join(nsCommandsDir, cmd);
473
500
  actions.push({
@@ -497,7 +524,7 @@ export function dryRun(projectDir, options = {}) {
497
524
  });
498
525
  }
499
526
 
500
- for (const lib of ['state.mjs', 'config.mjs', 'utils.mjs', 'messages.mjs', 'pipeline.mjs']) {
527
+ for (const lib of ['state.mjs', 'config.mjs', 'utils.mjs', 'messages.mjs', 'pipeline.mjs', 'session.mjs']) {
501
528
  const target = join(claudeDir, 'lib', lib);
502
529
  actions.push({
503
530
  type: 'lib',
@@ -526,9 +553,9 @@ export function dryRun(projectDir, options = {}) {
526
553
 
527
554
  // ─── internal helpers ───
528
555
 
529
- function injectRules(projectDir) {
556
+ function injectRules(projectDir, overrideRulesPath) {
530
557
  const claudeMdPath = join(projectDir, 'CLAUDE.md');
531
- const rulesPath = join(TEMPLATES_DIR, 'rules.md');
558
+ const rulesPath = overrideRulesPath || join(TEMPLATES_DIR, 'rules.md');
532
559
  if (!existsSync(rulesPath)) return;
533
560
 
534
561
  const rules = readFileSync(rulesPath, 'utf8');
package/lib/pipeline.mjs CHANGED
@@ -8,6 +8,7 @@ import { join } from 'path';
8
8
  import { sanitizeId } from './utils.mjs';
9
9
  import { loadConfig } from './config.mjs';
10
10
  import { getStateDir } from './state.mjs';
11
+ import { logEvent } from './session.mjs';
11
12
 
12
13
  const TOOL_ACTION_MAP = {
13
14
  'Edit': 'edit',
@@ -87,6 +88,18 @@ export function runPipeline(rules, hookEventName) {
87
88
 
88
89
  const result = rule.evaluate(ctx, hookConfig, stateDir);
89
90
 
91
+ // Log rule evaluation for analytics
92
+ if (ctx.sessionId && result.type !== 'pass') {
93
+ try {
94
+ logEvent(ctx.sessionId, {
95
+ type: result.type, // 'block', 'warn'
96
+ rule: name,
97
+ action: ctx.action,
98
+ file: ctx.filePath || undefined,
99
+ });
100
+ } catch { /* logging should never break the pipeline */ }
101
+ }
102
+
90
103
  if (result.type === 'block') {
91
104
  blocked = true;
92
105
  blockMessage = result.message || '🌈 Prism āœ‹ Action blocked.';
@@ -163,6 +176,18 @@ export async function runPipelineAsync(builtInRules, hookEventName) {
163
176
 
164
177
  const result = rule.evaluate(ctx, hookConfig, stateDir);
165
178
 
179
+ // Log rule evaluation for analytics
180
+ if (ctx.sessionId && result.type !== 'pass') {
181
+ try {
182
+ logEvent(ctx.sessionId, {
183
+ type: result.type, // 'block', 'warn'
184
+ rule: name,
185
+ action: ctx.action,
186
+ file: ctx.filePath || undefined,
187
+ });
188
+ } catch { /* logging should never break the pipeline */ }
189
+ }
190
+
166
191
  if (result.type === 'block') {
167
192
  blocked = true;
168
193
  blockMessage = result.message || '🌈 Prism āœ‹ Action blocked.';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-prism",
3
- "version": "0.8.0",
3
+ "version": "1.0.0",
4
4
  "description": "UDEC methodology framework for AI coding agents — Understand, Decompose, Execute, Checkpoint.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -0,0 +1,35 @@
1
+ # /claude-prism:analytics — Usage Analytics
2
+
3
+ When this command is invoked, show aggregated statistics from session event logs:
4
+
5
+ ## Report
6
+
7
+ 1. **Read session data** using `listSessions()` and `getSessionSummary()` from session.mjs
8
+ 2. **Aggregate across all sessions**:
9
+ - Total sessions count
10
+ - Hook effectiveness: blocks and warnings by rule type
11
+ - Test activity: runs, passed, failed
12
+ - File activity: modified, created
13
+ 3. **Display using this format**:
14
+
15
+ ```
16
+ 🌈 claude-prism analytics
17
+
18
+ Sessions: N
19
+ Total events: N
20
+
21
+ Hook Effectiveness:
22
+ Blocks: N
23
+ Warnings: N
24
+
25
+ Test Activity:
26
+ Runs: N
27
+ Passed: N
28
+ Failed: N
29
+
30
+ File Activity:
31
+ Modified: N
32
+ Created: N
33
+ ```
34
+
35
+ 4. **With --detail flag**, also show last 5 sessions with timestamps and per-session counts
@@ -7,7 +7,11 @@ When this command is invoked:
7
7
  - `grep -c '\- \[x\]' <plan-file>` → completed count
8
8
  - `grep -c '\- \[ \]' <plan-file>` → remaining count
9
9
  - Calculate percentage: completed / (completed + remaining)
10
- 3. **Freshness check**: grep for plan's change targets to verify they still exist in codebase
10
+ 3. **Plan-Reality sync** (freshness check):
11
+ - Grep for plan's change targets (patterns, files, functions to modify) to verify they still exist in codebase
12
+ - If target no longer exists → mark task as "already completed (prior work)"
13
+ - If new targets discovered → add to plan's "Risks / Open Questions"
14
+ - Update plan file's `Codebase Audit` section with fresh counts if present
11
15
  4. **Report current status** using this standard format:
12
16
 
13
17
  ### Changes
@@ -20,7 +24,7 @@ When this command is invoked:
20
24
 
21
25
  | Check | Result |
22
26
  |-------|--------|
23
- | TypeScript | āœ…/āŒ [details] |
27
+ | Build | āœ…/āŒ [details] |
24
28
  | Tests | āœ…/āŒ [pass count] |
25
29
  | Lint | āœ…/āŒ or N/A |
26
30
 
@@ -29,6 +33,7 @@ When this command is invoked:
29
33
  ```
30
34
  Phase: [current phase] | Batch: [N/M] | Tasks: [done/total] ([%])
31
35
  [ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–‘ā–‘] 80% — Next: [next batch name]
36
+ Plan freshness: verified [date] | Remaining targets: [N] confirmed in code
32
37
  ```
33
38
 
34
39
  - Batches complete: N/M
@@ -44,11 +49,11 @@ When this command is invoked:
44
49
  | [M] Medium | N | N |
45
50
  | [L] Large | N | N |
46
51
 
47
- 4. **Show summary**:
52
+ 5. **Show summary**:
48
53
  - Files created/modified so far
49
54
  - Tests added and their status
50
55
  - Commits made
51
- 5. **Checkpoint policy check**:
56
+ 6. **Checkpoint policy check**:
52
57
  - If 3+ consecutive approvals → suggest expanding batch size to 5-8
53
58
  - If phase boundary → always stop
54
- 6. **Ask**: "Continue with the current plan, adjust, or stop?"
59
+ 7. **Ask**: "Continue with the current plan, adjust, or stop?"
@@ -7,15 +7,15 @@ When this command is invoked, check all components of the prism installation:
7
7
  1. **CLAUDE.md**: Does it contain `<!-- PRISM:START -->` marker?
8
8
  2. **Config**: Does `.claude-prism.json` exist? Is it valid JSON?
9
9
  3. **Commands**: Do these files exist in `.claude/commands/claude-prism/`?
10
- - prism.md, checkpoint.md, plan.md, doctor.md, stats.md, help.md
10
+ - prism.md, checkpoint.md, plan.md, doctor.md, stats.md, help.md, update.md
11
11
  4. **Hooks**: Do these files exist in `.claude/hooks/`?
12
- - commit-guard.mjs, debug-loop.mjs, test-tracker.mjs, scope-guard.mjs
12
+ - pre-tool.mjs, post-tool.mjs
13
13
  5. **Rules**: Do these files exist in `.claude/rules/`?
14
- - commit-guard.mjs, debug-loop.mjs, test-tracker.mjs, scope-guard.mjs
14
+ - commit-guard.mjs, test-tracker.mjs, plan-enforcement.mjs
15
15
  6. **Lib**: Do these files exist in `.claude/lib/`?
16
- - adapter.mjs, state.mjs, config.mjs, utils.mjs
16
+ - pipeline.mjs, state.mjs, config.mjs, utils.mjs, messages.mjs
17
17
  7. **Settings**: Does `.claude/settings.json` contain prism hook registrations?
18
- 8. **Legacy**: Are there old flat commands (`/prism`, `/checkpoint`) that need migration?
18
+ 8. **Legacy**: Are there old flat commands (`/prism`, `/checkpoint`) or deprecated files (`debug-loop.mjs`, `scope-guard.mjs`, `adapter.mjs`) that need cleanup?
19
19
 
20
20
  ## Report Format
21
21
 
@@ -25,11 +25,11 @@ When this command is invoked, check all components of the prism installation:
25
25
  CLAUDE.md: āœ… PRISM rules present
26
26
  Config: āœ… .claude-prism.json valid
27
27
  Commands: āœ… 7/7 installed
28
- Hooks: āœ… 4/4 installed
29
- Rules: āœ… 4/4 installed
30
- Lib: āœ… 4/4 installed
28
+ Hooks: āœ… 2/2 installed
29
+ Rules: āœ… 3/3 installed
30
+ Lib: āœ… 5/5 installed
31
31
  Settings: āœ… Hooks registered
32
- Legacy: āœ… No old commands found
32
+ Legacy: āœ… No old files found
33
33
 
34
34
  Status: āœ… Healthy
35
35
  ```
@@ -40,3 +40,4 @@ For each issue found, suggest the fix:
40
40
  - Missing files → "Run `prism update` to restore"
41
41
  - Legacy commands → "Run `prism update` to migrate to namespaced commands"
42
42
  - Missing PRISM block → "Run `prism update` to re-inject rules"
43
+ - Deprecated files → "Run `prism update` to clean up legacy files"
@@ -18,26 +18,37 @@ If user requests a new plan:
18
18
 
19
19
  1. **Determine topic** from user's description
20
20
  2. **Create file** at `docs/plans/YYYY-MM-DD-<topic>.md`
21
- 3. **Use UDEC template** (adapt language to project's `.claude-prism.json` language setting):
21
+ 3. **Use UDEC template**:
22
22
 
23
23
  ```
24
24
  ## Goal
25
- One sentence: what and why.
25
+ One sentence: what we're building and why.
26
26
 
27
27
  ## Architecture
28
- Tech stack, key decisions, 2-3 sentences.
28
+ Tech stack, key decisions, 2-3 sentences max.
29
29
 
30
- ## Batch 1: [Name]
31
- - [ ] Task 1.1: [Description] → `path/to/file`
32
- - Test: `path/to/test` — [what to verify]
33
- - Pass criterion: [specific assertion]
34
- - [ ] Task 1.2: ...
30
+ ## Related Plans
31
+ - Depends on: `YYYY-MM-DD-<prior-plan>.md` (status: complete/in-progress)
32
+ - Shared files: list files that overlap with other active plans
33
+ - (Omit this section if no other plans exist)
34
+
35
+ ## Codebase Audit
36
+ - Audit date: YYYY-MM-DD
37
+ - Targets remaining: N files (verified by grep/search)
38
+ - Already completed: N items (by prior work or other branches)
39
+ - Evidence: `grep -r "pattern" --include="*.ext" | wc -l` → N
35
40
 
36
- ## Batch 2: [Name]
37
- - [ ] Task 2.1: ...
41
+ ## Files in Scope
42
+ - `path/to/file1.ts` — [what changes]
43
+ - `path/to/file2.ts` — [what changes]
44
+
45
+ ## Batch 1: [Name]
46
+ - [ ] Task 1.1: [S] [description] | Verify: [auto: build/test/lint]
47
+ - [ ] Task 1.2: [M] [description] | Verify: [auto: test] [manual: visual check]
48
+ - Prerequisite: Task 1.1
38
49
 
39
50
  ## Risks / Open Questions
40
- - [Known uncertainties or potential blockers]
51
+ - [Known unknowns or potential blockers]
41
52
  ```
42
53
 
43
54
  4. **Announce**: "Plan file created. Use /claude-prism:prism to start execution."
@@ -49,4 +60,4 @@ If user specifies a plan file:
49
60
  1. **Read** the specified plan file
50
61
  2. **Show progress** with completion percentage
51
62
  3. **Highlight** current batch (first batch with incomplete tasks)
52
- 4. **List blockers** from "리스크 / 미결 사항" section
63
+ 4. **List blockers** from "Risks / Open Questions" section
@@ -54,23 +54,23 @@ When this command is invoked, follow the UDEC framework strictly:
54
54
 
55
55
  ## E — EXECUTE
56
56
 
57
- 11. Execute in adaptive batches:
57
+ 14. Execute in adaptive batches:
58
58
  - Simple changes (imports, types, config): 5-8 per batch
59
59
  - Standard changes (feature add/modify): 3-4 per batch
60
60
  - Complex changes (new module, architecture): 1-2 per batch
61
- 12. Apply context-aware verification:
61
+ 15. Apply context-aware verification:
62
62
  - `lib/`, `utils/`, `store/`, `hooks/`, `services/` → TDD (failing test → implement → verify)
63
63
  - `components/`, `pages/`, `views/` → Build verification (escalate to TDD if complex logic)
64
64
  - `config/`, `styles/`, `types/` → Build/lint only
65
- 13. **Scope Guard**: Before each change, ask: "Was this requested?" If no → don't do it
66
- 14. **Self-correction triggers**:
65
+ 16. **Scope Guard**: Before each change, ask: "Was this requested?" If no → don't do it
66
+ 17. **Self-correction triggers**:
67
67
  - Same file edited 3+ times **on the same region/logic** → stop, investigate root cause (progressive edits across different regions — imports, logic, JSX — are normal)
68
68
  - File not in plan → pause, ask about scope change
69
69
  - 3 consecutive test failures → stop, reconsider approach
70
70
  - New package needed → ask user first
71
71
  - Adding workarounds on workarounds → design problem, step back
72
- 15. **Verification scoping**: When running build checks (tsc, lint, etc.), filter output to only changed files. Pre-existing errors in other files are not your concern. Example: `tsc --noEmit 2>&1 | grep -i "<changed-file>"`
73
- 16. **Agent failure recovery**: If a delegated agent partially fails or produces incomplete results:
72
+ 18. **Verification scoping**: When running build checks (tsc, lint, etc.), filter output to only changed files. Pre-existing errors in other files are not your concern. Example: `tsc --noEmit 2>&1 | grep -i "<changed-file>"`
73
+ 19. **Agent failure recovery**: If a delegated agent partially fails or produces incomplete results:
74
74
  1. Verify actual file state (read the file, not just the agent's report)
75
75
  2. If partially correct → complete the remaining work directly
76
76
  3. If fully wrong → retry with clearer instructions or execute directly
@@ -100,4 +100,4 @@ If oh-my-claudecode is detected in this environment:
100
100
  - Use `architect` agent for complex decomposition decisions
101
101
  - Use `executor` agents for parallel batch execution when tasks are independent
102
102
  - Use `verifier` agent for checkpoint verification
103
- - Scope Guard thresholds are automatically raised for sub-agents (8 warn / 12 block vs 4/7)
103
+ - Scope Guard thresholds are automatically raised for sub-agents (8 warn / 12 block vs default 4 warn / 7 block for standalone mode)
@@ -62,7 +62,7 @@ Before moving to DECOMPOSE:
62
62
  - MVP scope defined
63
63
  - User confirmed "proceed"
64
64
 
65
- ### 2-4. Assumption Detection (Red Flag Checklist)
65
+ ### 2-5. Assumption Detection (Red Flag Checklist)
66
66
 
67
67
  **If you think you understand fully on first read, you probably don't.**
68
68
 
@@ -109,7 +109,7 @@ Before moving to DECOMPOSE:
109
109
  **Batch composition**:
110
110
  - Mixed: S+S+M = 1 batch, L = 1 batch alone
111
111
  - **[S]-only: up to 8 per batch** (independent small changes can be batched aggressively)
112
- - Aligns with 4-1 adaptive batch size (simple/mechanical: 5-10 per batch)
112
+ - Aligns with 4-1 adaptive batch size (simple/mechanical: 5-8 per batch)
113
113
 
114
114
  ### 3-3. Plan File Persistence
115
115
 
@@ -175,7 +175,7 @@ If any gate fails → resolve before executing. Do not start implementation on a
175
175
  ### 4-1. Batch Execution
176
176
 
177
177
  1. **Adaptive batch size**:
178
- - Simple/mechanical changes (imports, types, config, migration): 5-10 per batch
178
+ - Simple/mechanical changes (imports, types, config, migration): 5-8 per batch
179
179
  - Standard changes (feature add/modify): 3-4 per batch
180
180
  - Complex changes (new module, architecture): 1-2 per batch
181
181
  2. **Git-as-Memory**: commit after each completed batch as a rollback point. Use `git diff` summaries to maintain context in long sessions.
@@ -38,7 +38,8 @@ AI agents optimize for speed, not correctness. Without structure, they skip unde
38
38
  - [Sufficient] Specific file, function, symptom mentioned → skip to DECOMPOSE
39
39
  - [Partial] Direction clear but details missing → explore then ask 1-2 questions
40
40
  - [Insufficient] Abstract, vague, multiple interpretations → must ask questions first
41
- 3. **Check for hidden assumptions** (Red Flag Detection):
41
+ 3. **Environment validation**: Verify project builds, dependencies match, env config identified. If any fail → resolve first.
42
+ 4. **Check for hidden assumptions** (Red Flag Detection):
42
43
 
43
44
  | Red Flag | Question to Ask Yourself |
44
45
  |----------|-------------------------|
@@ -50,63 +51,74 @@ AI agents optimize for speed, not correctness. Without structure, they skip unde
50
51
  | No file/function names | [Insufficient]. Must ask. |
51
52
  | "just", "simply" | Complexity being underestimated |
52
53
 
53
- 4. **Question rules** (if questions needed):
54
+ 5. **Question rules** (if questions needed):
54
55
  - One question at a time
55
56
  - Multiple choice with 2-3 options + recommendation
56
57
  - Include reasoning based on code exploration
57
58
  - Maximum 3 rounds of questions
58
- 5. **Confirm alignment**: Summarize goal in one sentence, get user approval
59
- 6. **Analysis-only requests**: If no code change is needed, report findings and ask: "Further action needed?" Do NOT proceed to D/E/C unless the user requests implementation.
59
+ 6. **Confirm alignment**: Summarize goal in one sentence, get user approval
60
+ 7. **Analysis-only requests**: If no code change is needed, report findings and ask: "Further action needed?" Do NOT proceed to D/E/C unless the user requests implementation.
60
61
 
61
62
  ## D — DECOMPOSE
62
63
 
63
- 7. **Assess complexity** (consider BOTH file count AND logic complexity):
64
+ 8. **Assess complexity** (consider BOTH file count AND logic complexity):
64
65
  - [Simple] 1-2 files, minor changes (<50 LOC) → execute directly, no decomposition needed
65
66
  - [Medium] 3-5 files, OR 1-2 files with significant logic changes (50-150 LOC) → 2-3 batches
66
67
  - [Complex] 6+ files, OR substantial architectural changes → 5+ batches, must create plan file
67
68
  - [Complex system] Unclear scope → reduce scope first, then decompose
68
- 8. **Create batches** following the 5 principles:
69
+ 9. **Create batches** following the 5 principles:
69
70
  - Unit size: 2-5 minutes each (test/implement/verify as separate steps)
70
71
  - Test first: test before implementation in each unit
71
72
  - Independent verification: each unit has a pass criterion
72
73
  - Files specified: list files to create/modify per unit
73
74
  - Dependencies noted: mark if unit depends on a previous one
74
- 9. **Assign size tags** to every task: [S] <30 LOC, [M] 30-100 LOC, [L] >100 LOC
75
- - Batch composition: S+S+M = 1 batch, L = 1 batch alone
76
- 10. **Assign verification strategy** per task: `| Verify: TDD` or `| Verify: Build` or `| Verify: Visual`
77
- 11. **Pre-decomposition checklist**:
75
+ 10. **Assign size tags** to every task: [S] <30 LOC, [M] 30-100 LOC, [L] >100 LOC
76
+ - Batch composition: S+S+M = 1 batch, L = 1 batch alone
77
+ 11. **Assign verification strategy** per task: `| Verify: TDD` or `| Verify: Build` or `| Verify: Visual`
78
+ 12. **Pre-decomposition checklist**:
79
+ - **Codebase audit**: grep/search to verify targets actually exist in code
80
+ - **Cross-plan check**: if other plans exist in `docs/plans/`, identify overlapping files
78
81
  - Required types/interfaces have the necessary fields?
79
82
  - External package APIs behave as expected?
80
83
  - Cross-package dependencies identified and noted as prerequisites?
81
- 12. **Save plan** to `docs/plans/YYYY-MM-DD-<topic>.md`
82
- 13. **Get approval**: "Proceed with this plan?"
84
+ 13. **Quality gate**: Plan file exists and targets verified, project builds, dependencies resolved, environment validated. All must pass before execution.
85
+ 14. **Save plan** to `docs/plans/YYYY-MM-DD-<topic>.md`
86
+ 15. **Get approval**: "Proceed with this plan?"
83
87
 
84
88
  ## E — EXECUTE
85
89
 
86
- 11. Execute in adaptive batches:
90
+ 16. Execute in adaptive batches:
87
91
  - Simple changes (imports, types, config): 5-8 per batch
88
92
  - Standard changes (feature add/modify): 3-4 per batch
89
93
  - Complex changes (new module, architecture): 1-2 per batch
90
- 12. Apply context-aware verification:
91
- - `lib/`, `utils/`, `store/`, `hooks/`, `services/` → TDD (failing test → implement → verify)
92
- - `components/`, `pages/`, `views/` → Build verification (escalate to TDD if complex logic)
93
- - `config/`, `styles/`, `types/` → Build/lint only
94
- 13. **Scope Guard**: Before each change, ask: "Was this requested?" If no → don't do it
95
- 14. **Self-correction triggers**:
96
- - Same file edited 3+ times **on the same region/logic** → stop, investigate root cause (progressive edits across different regions — imports, logic, JSX — are normal)
94
+ 17. **Git-as-Memory**: commit after each completed batch as a rollback point. Use `git diff` summaries to maintain context in long sessions.
95
+ 18. Apply risk-based verification:
96
+ - **High risk** (business logic, auth, data mutation): TDD — failing test → implement → pass. Include negative tests.
97
+ - **Medium risk** (new components with logic, API integration): Build + lint pass
98
+ - **Low risk** (imports, types, style, renaming): Build/lint passes
99
+ - **No test infra** (legacy PHP, WordPress, etc.): Grep-based static check + syntax validation
100
+ - Use **Verification Fallback Ladder**: Automated Tests → Approval Testing → Build → Lint → Smoke Check → Manual Diff Review (use highest available level)
101
+ 19. **Scope Guard**: Before each change, ask: "Was this requested?" If no → don't do it
102
+ 20. **Goal Recitation**: At every batch boundary, re-read the plan and confirm: "Current work aligns with: [original goal]"
103
+ 21. **Self-correction triggers (Thrashing Detector)**:
104
+ - Same file edited 3+ times **on the same region/logic** → stop, investigate root cause
97
105
  - File not in plan → pause, ask about scope change
98
106
  - 3 consecutive test failures → stop, reconsider approach
99
107
  - New package needed → ask user first
100
108
  - Adding workarounds on workarounds → design problem, step back
101
- 15. **Verification scoping**: When running build checks (tsc, lint, etc.), filter output to only changed files. Pre-existing errors in other files are not your concern. Example: `tsc --noEmit 2>&1 | grep -i "<changed-file>"`
102
- 16. **Agent failure recovery**: If a delegated agent partially fails or produces incomplete results:
109
+ - Successive edits reverting previous changes (oscillation) → wrong approach
110
+ - Scope expanding beyond plan → scope creep, return to DECOMPOSE
111
+ - Error messages changing type across fixes → chasing symptoms, back to UNDERSTAND
112
+ 22. **Verification scoping**: Filter build output to only changed files. Pre-existing errors are not your concern.
113
+ 23. **Agent failure recovery**: If a delegated agent partially fails:
103
114
  1. Verify actual file state (read the file, not just the agent's report)
104
115
  2. If partially correct → complete the remaining work directly
105
116
  3. If fully wrong → retry with clearer instructions or execute directly
106
117
 
107
118
  ## C — CHECKPOINT
108
119
 
109
- 20. After each batch, report using this format:
120
+ 24. **Quality gate**: All batch tasks terminal, build passes with zero new errors, no uncommitted changes, plan file updated with `[x]` status. If any fail → continue in EXECUTE.
121
+ 25. After each batch, report using this format:
110
122
 
111
123
  | Item | Before | After |
112
124
  |------|--------|-------|
@@ -115,12 +127,14 @@ AI agents optimize for speed, not correctness. Without structure, they skip unde
115
127
  ```
116
128
  Phase: [current] | Batch: [N/M] | Tasks: [done/total] ([%])
117
129
  [ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–‘ā–‘] 80% — Next: [next batch name]
130
+ Plan freshness: verified [date] | Remaining targets: [N] confirmed in code
118
131
  ```
119
132
 
120
- 21. Include: verification results, files modified, tests status
121
- 22. **Checkpoint policy**: after 3 consecutive approvals, increase batch size to 5-8 for the rest of the phase
122
- 23. Ask: "Continue to next batch?"
123
- 24. User can redirect, adjust scope, or stop at any checkpoint
133
+ 26. **Plan-Reality sync**: Grep for plan targets, mark vanished targets as "already completed", add newly discovered targets.
134
+ 27. Include: verification results, files modified, tests status
135
+ 28. **Checkpoint policy**: after 3 consecutive approvals, increase batch size to 5-8 for the rest of the phase
136
+ 29. Ask: "Continue to next batch?"
137
+ 30. User can redirect, adjust scope, or stop at any checkpoint
124
138
 
125
139
  ## OMC Integration
126
140
 
@@ -129,6 +143,6 @@ If oh-my-claudecode is detected in this environment:
129
143
  - Use `architect` agent for complex decomposition decisions
130
144
  - Use `executor` agents for parallel batch execution when tasks are independent
131
145
  - Use `verifier` agent for checkpoint verification
132
- - Scope Guard thresholds are automatically raised for sub-agents (8 warn / 12 block vs 4/7)
146
+ - Scope Guard thresholds are automatically raised for sub-agents (8 warn / 12 block vs default 4 warn / 7 block for standalone mode)
133
147
 
134
148
  </Steps>