codecruise 0.1.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.
Files changed (129) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +111 -0
  3. package/bin/codecruise.js +68 -0
  4. package/config/CLAUDE.md +107 -0
  5. package/config/agents/analyst.md +48 -0
  6. package/config/agents/architect-reviewer.md +161 -0
  7. package/config/agents/architect.md +119 -0
  8. package/config/agents/critic.md +63 -0
  9. package/config/agents/developer.md +96 -0
  10. package/config/agents/devops.md +81 -0
  11. package/config/agents/orchestrator.md +91 -0
  12. package/config/agents/planner.md +139 -0
  13. package/config/agents/retro.md +52 -0
  14. package/config/agents/reviewer.md +101 -0
  15. package/config/agents/security-reviewer.md +57 -0
  16. package/config/agents/stack/expo/AGENT.md +473 -0
  17. package/config/agents/stack/expo/rules/critical.md +427 -0
  18. package/config/agents/stack/expo/rules/native.md +455 -0
  19. package/config/agents/stack/expo/rules/navigation.md +445 -0
  20. package/config/agents/stack/expo/rules/performance.md +415 -0
  21. package/config/agents/stack/fastify/AGENT.md +397 -0
  22. package/config/agents/stack/fastify/rules/api-design.md +283 -0
  23. package/config/agents/stack/fastify/rules/critical.md +232 -0
  24. package/config/agents/stack/fastify/rules/queues.md +303 -0
  25. package/config/agents/stack/fastify/rules/security.md +384 -0
  26. package/config/agents/stack/index.yaml +48 -0
  27. package/config/agents/stack/nextjs/AGENT.md +421 -0
  28. package/config/agents/stack/nextjs/rules/components.md +413 -0
  29. package/config/agents/stack/nextjs/rules/critical.md +391 -0
  30. package/config/agents/stack/nextjs/rules/performance.md +403 -0
  31. package/config/agents/stack/nextjs/rules/styling.md +334 -0
  32. package/config/agents/stack/shared-ts/AGENT.md +384 -0
  33. package/config/agents/stack/shared-ts/rules/critical.md +315 -0
  34. package/config/agents/stack/shared-ts/rules/patterns.md +384 -0
  35. package/config/agents/stack/shared-ts/rules/zod.md +427 -0
  36. package/config/agents/tester.md +79 -0
  37. package/config/commands/architect-discuss.md +366 -0
  38. package/config/commands/architect-list.md +160 -0
  39. package/config/commands/architect-review.md +111 -0
  40. package/config/commands/architect.md +118 -0
  41. package/config/commands/compact.md +118 -0
  42. package/config/commands/companion.md +279 -0
  43. package/config/commands/dashboard.md +152 -0
  44. package/config/commands/doctor.md +227 -0
  45. package/config/commands/dogfood-report.md +101 -0
  46. package/config/commands/flags/run-autonomous.md +110 -0
  47. package/config/commands/flags/run-pause.md +80 -0
  48. package/config/commands/ingest.md +173 -0
  49. package/config/commands/init.md +128 -0
  50. package/config/commands/metrics.md +87 -0
  51. package/config/commands/parallel.md +320 -0
  52. package/config/commands/pause.md +55 -0
  53. package/config/commands/plan-review.md +130 -0
  54. package/config/commands/plan.md +216 -0
  55. package/config/commands/production-check.md +308 -0
  56. package/config/commands/refine.md +323 -0
  57. package/config/commands/resume.md +72 -0
  58. package/config/commands/retro.md +121 -0
  59. package/config/commands/retry.md +75 -0
  60. package/config/commands/role.md +310 -0
  61. package/config/commands/run.md +417 -0
  62. package/config/commands/scope.md +85 -0
  63. package/config/commands/setup-permissions.md +104 -0
  64. package/config/commands/skip.md +75 -0
  65. package/config/commands/spec-forge.md +213 -0
  66. package/config/commands/spec-help.md +194 -0
  67. package/config/commands/spec-patch.md +342 -0
  68. package/config/commands/spec-resolve.md +110 -0
  69. package/config/commands/spec-review.md +153 -0
  70. package/config/commands/status.md +114 -0
  71. package/config/commands/sync.md +131 -0
  72. package/config/commands/task.md +138 -0
  73. package/config/commands/verify.md +124 -0
  74. package/config/hooks/README.md +632 -0
  75. package/config/hooks/activity-log.sh +187 -0
  76. package/config/hooks/anti-rationalize.sh +52 -0
  77. package/config/hooks/capture-verification.sh +112 -0
  78. package/config/hooks/collect-metrics.sh +135 -0
  79. package/config/hooks/enforce-file-scope.sh +75 -0
  80. package/config/hooks/enforce-state-machine.sh +161 -0
  81. package/config/hooks/enforce-tdd.sh +180 -0
  82. package/config/hooks/format.sh +40 -0
  83. package/config/hooks/lib/activity-helpers.sh +162 -0
  84. package/config/hooks/lib/read-settings.sh +71 -0
  85. package/config/hooks/load-context-skills.sh +95 -0
  86. package/config/hooks/notify.sh +81 -0
  87. package/config/hooks/pre-commit.sample +35 -0
  88. package/config/hooks/protect-files.sh +63 -0
  89. package/config/hooks/track-agents.sh +41 -0
  90. package/config/hooks/track-commands.sh +37 -0
  91. package/config/hooks/track-enforcement.sh +44 -0
  92. package/config/hooks/track-ooda.sh +77 -0
  93. package/config/hooks/validate-commit-msg.sh +35 -0
  94. package/config/hooks/validate-plan.sh +213 -0
  95. package/config/hooks/verify-criteria.sh +46 -0
  96. package/config/hooks/verify-todo-completion.sh +140 -0
  97. package/config/rules/comments.md +25 -0
  98. package/config/rules/decision-rules.md +308 -0
  99. package/config/rules/hygiene.md +247 -0
  100. package/config/rules/pattern-detection.md +372 -0
  101. package/config/rules/profiles.md +193 -0
  102. package/config/rules/recovery.md +83 -0
  103. package/config/rules/scope-detection.md +213 -0
  104. package/config/rules/standards.md +127 -0
  105. package/config/rules/workflow.md +121 -0
  106. package/config/schemas.md +767 -0
  107. package/config/settings.json +195 -0
  108. package/config/skills/backend/SKILL.md +734 -0
  109. package/config/skills/database/SKILL.md +426 -0
  110. package/config/skills/frontend/SKILL.md +434 -0
  111. package/config/skills/git/SKILL.md +396 -0
  112. package/config/skills/index.yaml +36 -0
  113. package/config/skills/observability/SKILL.md +430 -0
  114. package/config/skills/package-dev/SKILL.md +498 -0
  115. package/config/skills/performance/SKILL.md +378 -0
  116. package/config/skills/resilience/SKILL.md +573 -0
  117. package/config/skills/testing/SKILL.md +398 -0
  118. package/config/skills/testing-patterns/SKILL.md +276 -0
  119. package/config/skills/typescript/SKILL.md +152 -0
  120. package/config/templates/CLAUDE.md +70 -0
  121. package/config/templates/README.md +117 -0
  122. package/config/templates/steering/adr-template.md +102 -0
  123. package/config/templates/steering/product.md +60 -0
  124. package/config/templates/steering/rfc-template.md +159 -0
  125. package/config/templates/steering/structure.md +146 -0
  126. package/config/templates/steering/tech.md +85 -0
  127. package/package.json +40 -0
  128. package/src/install.js +163 -0
  129. package/src/report.js +310 -0
@@ -0,0 +1,310 @@
1
+ ---
2
+ name: role
3
+ description: Analyze codebase and generate structured role for CLAUDE.md
4
+ model: sonnet
5
+ tools: Read, Write, Edit, Glob, Grep, Bash
6
+ ---
7
+
8
+ # /role Command
9
+
10
+ Analyze the codebase, ask clarifying questions, and generate a structured role section for CLAUDE.md.
11
+
12
+ ## Philosophy
13
+
14
+ **Don't make users write roles manually.** Scan the code, infer the domain, ask smart questions, generate the role.
15
+
16
+ ## Usage
17
+
18
+ ```bash
19
+ /role # Analyze project, update root CLAUDE.md
20
+ /role apps/web # Analyze specific directory, create/update nested CLAUDE.md
21
+ /role --dry-run # Show what would be generated without writing
22
+ /role --update # Re-analyze and refresh existing role
23
+ ```
24
+
25
+ ## Process
26
+
27
+ ### 1. Scan Codebase
28
+
29
+ Gather signals from:
30
+
31
+ ```bash
32
+ # Package info
33
+ package.json # name, description, dependencies
34
+ pnpm-workspace.yaml # monorepo structure
35
+ turbo.json / nx.json # monorepo tooling
36
+
37
+ # Folder structure
38
+ apps/ # Application types
39
+ packages/ # Shared packages
40
+ src/ # Source organization
41
+
42
+ # Key files
43
+ *.config.ts # Framework configs
44
+ schema.prisma / drizzle # Database
45
+ Dockerfile # Deployment
46
+ ```
47
+
48
+ ### 2. Analyze Signals
49
+
50
+ #### Tech Stack Detection
51
+
52
+ | Signal | Detection |
53
+ |--------|-----------|
54
+ | Frontend | react, next, vue, angular, svelte in deps |
55
+ | Backend | express, fastify, hono, nest in deps |
56
+ | Mobile | expo, react-native in deps |
57
+ | Database | prisma, drizzle, typeorm, postgres, mongodb |
58
+ | Auth | next-auth, lucia, passport, jwt |
59
+ | API Style | trpc, graphql, rest patterns |
60
+
61
+ #### Domain Detection
62
+
63
+ Scan for domain-specific keywords in:
64
+ - File names and folder names
65
+ - Package names
66
+ - README content
67
+ - Type/interface names
68
+
69
+ | Keywords | Likely Domain |
70
+ |----------|---------------|
71
+ | wallet, transaction, currency, payment, invoice | Fintech |
72
+ | cart, product, checkout, inventory, order | E-commerce |
73
+ | patient, appointment, prescription, health | Healthcare |
74
+ | course, lesson, student, enrollment | EdTech |
75
+ | post, comment, feed, follower, like | Social |
76
+ | cli, sdk, api, plugin, extension | DevTools |
77
+ | dashboard, analytics, metrics, report | Analytics |
78
+ | booking, reservation, availability | Booking/Travel |
79
+
80
+ #### Pattern Detection
81
+
82
+ | Pattern | Signal |
83
+ |---------|--------|
84
+ | Monorepo | pnpm-workspace.yaml, turbo.json, apps/, packages/ |
85
+ | TDD | vitest, jest, *.test.ts files |
86
+ | Type-safe | typescript, zod, strict mode |
87
+ | API-first | openapi, swagger, trpc |
88
+
89
+ ### 3. Ask Clarifying Questions
90
+
91
+ Based on analysis, ask 2-4 targeted questions:
92
+
93
+ ```
94
+ Analyzing codebase...
95
+
96
+ Detected:
97
+ ├── Stack: Next.js 15, Fastify, PostgreSQL, Expo
98
+ ├── Structure: Monorepo (apps: web, api, mobile, worker)
99
+ ├── Patterns: TDD, TypeScript strict, tRPC
100
+ └── Domain signals: "wallet", "transaction", "budget" → Fintech?
101
+
102
+ Questions:
103
+
104
+ 1. Domain: Is this a personal finance / fintech app?
105
+ [Y] Yes [n] No, it's: ___
106
+
107
+ 2. Key expertise needed beyond standard engineering?
108
+ Examples: "multi-currency handling", "PCI compliance", "decimal precision"
109
+ > ___
110
+
111
+ 3. Target users?
112
+ [c] Consumers [b] Businesses [d] Developers [o] Other: ___
113
+
114
+ 4. Any domain-specific rules I should always follow?
115
+ Example: "Never use floats for money, always decimal/string"
116
+ > ___
117
+ ```
118
+
119
+ ### 4. Generate Role Section
120
+
121
+ #### For Root CLAUDE.md (Project-wide)
122
+
123
+ ```markdown
124
+ ## Role
125
+
126
+ You are a senior fintech engineer building a personal finance app.
127
+
128
+ **Domain expertise:**
129
+ - Personal finance and expense tracking
130
+ - Multi-currency transaction handling
131
+ - Budget management and financial planning
132
+
133
+ **Technical focus:**
134
+ - Full-stack TypeScript (Next.js + Fastify + Expo)
135
+ - PostgreSQL with Drizzle ORM
136
+ - tRPC for type-safe APIs
137
+
138
+ **Critical rules:**
139
+ - Never use floats for money — use decimal strings
140
+ - All financial calculations must handle currency precision
141
+ - User financial data requires audit logging
142
+ ```
143
+
144
+ #### For Nested CLAUDE.md (Directory-specific)
145
+
146
+ ```markdown
147
+ # Web App
148
+
149
+ Frontend for the personal finance app.
150
+
151
+ ## Role
152
+
153
+ You are a senior frontend engineer specializing in:
154
+ - React 19 with Next.js 15 App Router
155
+ - Accessible, mobile-first UI with Tailwind
156
+ - Complex form handling for financial data
157
+ - Real-time updates with tRPC subscriptions
158
+
159
+ **Key patterns:**
160
+ - Use `@figu/design-tokens` for all styling
161
+ - Forms use react-hook-form + zod validation
162
+ - All money inputs use decimal string format
163
+ ```
164
+
165
+ ### 5. Update CLAUDE.md
166
+
167
+ #### If CLAUDE.md exists with Role section:
168
+ - Ask: "Update existing role? [Y/n]"
169
+ - Replace the `## Role` section only
170
+
171
+ #### If CLAUDE.md exists without Role section:
172
+ - Insert `## Role` section after project description
173
+
174
+ #### If no CLAUDE.md:
175
+ - Create from template with role filled in
176
+
177
+ ### 6. Output
178
+
179
+ ```
180
+ ✓ Role generated for: figu
181
+
182
+ Domain: Fintech / Personal Finance
183
+ Stack: Next.js, Fastify, PostgreSQL, Expo
184
+ Expertise: Multi-currency, budget tracking, financial precision
185
+
186
+ Updated: CLAUDE.md
187
+
188
+ Role section:
189
+ ─────────────────────────────────────────────
190
+ ## Role
191
+
192
+ You are a senior fintech engineer building a personal finance app.
193
+ ...
194
+ ─────────────────────────────────────────────
195
+
196
+ Run /role apps/web to generate frontend-specific role.
197
+ Run /role apps/api to generate backend-specific role.
198
+ ```
199
+
200
+ ## Options
201
+
202
+ | Flag | Description |
203
+ |------|-------------|
204
+ | `--dry-run` | Show generated role without writing |
205
+ | `--update` | Re-analyze and refresh existing role |
206
+ | `--force` | Overwrite without confirmation |
207
+ | `--minimal` | Generate shorter role (3-4 lines) |
208
+
209
+ ## Directory-Specific Roles
210
+
211
+ When targeting a specific directory:
212
+
213
+ ```bash
214
+ /role apps/web
215
+ ```
216
+
217
+ **Process:**
218
+ 1. Analyze that directory specifically
219
+ 2. Infer specialization (frontend/backend/mobile/etc.)
220
+ 3. Generate role tailored to that area
221
+ 4. Create/update `apps/web/CLAUDE.md`
222
+
223
+ **Example outputs:**
224
+
225
+ ```bash
226
+ /role apps/api
227
+ # → "You are a senior backend engineer specializing in..."
228
+
229
+ /role apps/mobile
230
+ # → "You are a senior mobile engineer specializing in..."
231
+
232
+ /role packages/db
233
+ # → "You are a senior database engineer specializing in..."
234
+
235
+ /role infra
236
+ # → "You are a senior devops engineer specializing in..."
237
+ ```
238
+
239
+ ## Role Templates by Specialization
240
+
241
+ ### Frontend Engineer
242
+ ```markdown
243
+ You are a senior frontend engineer specializing in:
244
+ - {framework} with {meta-framework}
245
+ - Accessible, responsive UI design
246
+ - State management and data fetching
247
+ - Performance optimization (Core Web Vitals)
248
+ ```
249
+
250
+ ### Backend Engineer
251
+ ```markdown
252
+ You are a senior backend engineer specializing in:
253
+ - {framework} with TypeScript
254
+ - RESTful/{tRPC/GraphQL} API design
255
+ - Database optimization and query performance
256
+ - Authentication and authorization flows
257
+ ```
258
+
259
+ ### Mobile Engineer
260
+ ```markdown
261
+ You are a senior mobile engineer specializing in:
262
+ - {React Native/Expo/Flutter}
263
+ - Cross-platform development
264
+ - Offline-first architecture
265
+ - Native module integration when needed
266
+ ```
267
+
268
+ ### Database Engineer
269
+ ```markdown
270
+ You are a senior database engineer specializing in:
271
+ - {PostgreSQL/MySQL/MongoDB} optimization
272
+ - Schema design and migrations
273
+ - Query performance and indexing
274
+ - Data integrity and transactions
275
+ ```
276
+
277
+ ### DevOps Engineer
278
+ ```markdown
279
+ You are a senior devops engineer specializing in:
280
+ - {Docker/Kubernetes} containerization
281
+ - CI/CD pipeline design
282
+ - Infrastructure as code
283
+ - Monitoring and observability
284
+ ```
285
+
286
+ ## Integration
287
+
288
+ After `/role`:
289
+ - `/init` will skip role questions (already defined)
290
+ - `/run` uses the role context for better implementation
291
+ - Nested CLAUDE.md roles activate when working in those directories
292
+
293
+ ## Examples
294
+
295
+ ```bash
296
+ # New project - generate root role
297
+ /role
298
+
299
+ # Preview without writing
300
+ /role --dry-run
301
+
302
+ # Generate role for frontend app
303
+ /role apps/web
304
+
305
+ # Generate role for all major directories
306
+ /role apps/web && /role apps/api && /role apps/mobile
307
+
308
+ # Update after major changes
309
+ /role --update
310
+ ```
@@ -0,0 +1,417 @@
1
+ ---
2
+ name: run
3
+ description: Execute TODOs using adaptive OODA loop with continuous sensing and intelligent routing
4
+ model: sonnet
5
+ tools: Read, Write, Edit, Bash, Glob, Grep, Task
6
+ ---
7
+
8
+ # /run — OODA Execution Loop
9
+
10
+ Adaptive execution using Boyd's OODA loop: **Observe → Orient → Decide → Act**.
11
+
12
+ ## Mode Detection
13
+
14
+ | Input | Mode | Action |
15
+ |-------|------|--------|
16
+ | `/run "intent"` | NEW | Detect scope, clarify, plan, execute |
17
+ | `/run phase-01` | RESUME | Load roadmap, execute TODOs |
18
+ | `/run` | RESUME | Continue from progress.yaml |
19
+
20
+ ## Options
21
+
22
+ | Option | Default | Description |
23
+ |--------|---------|-------------|
24
+ | `--tempo` | `balanced` | `ship-fast`, `balanced`, `careful` |
25
+ | `--checkpoint` | `subfeature` | `subfeature`, `feature`, `none` |
26
+ | `--on-error` | `ask` | `ask`, `skip`, `abort`, `replan` |
27
+ | `--autonomous` | `false` | Run without human intervention |
28
+ | `--promise` | none | Verify condition before complete |
29
+ | `--max-turns` | `100` | Safety limit for autonomous |
30
+
31
+ ## Tempo Profiles
32
+
33
+ | Tempo | OBSERVE | ORIENT | TDD | Use When |
34
+ |-------|---------|--------|-----|----------|
35
+ | `ship-fast` | Minimal | Skip if confident | Quick verify | Prototyping, low-risk |
36
+ | `balanced` | Standard | Pattern check | Full cycle | Normal work |
37
+ | `careful` | Full sensing | Deep analysis | Full + review | Critical, unfamiliar |
38
+
39
+ ## OODA Execution Loop
40
+
41
+ ```
42
+ ┌─────────────────────────────────────────────────────────┐
43
+ │ OODA LOOP │
44
+ ├─────────────────────────────────────────────────────────┤
45
+ │ │
46
+ │ ┌──────────┐ │
47
+ │ │ OBSERVE │ ← Sense environment before each TODO │
48
+ │ └────┬─────┘ │
49
+ │ ↓ │
50
+ │ ┌──────────┐ │
51
+ │ │ ORIENT │ ← Pattern analysis, confidence calc │
52
+ │ └────┬─────┘ │
53
+ │ ↓ │
54
+ │ ┌──────────┐ │
55
+ │ │ DECIDE │ ← Route: execute / skip / replan / ask │
56
+ │ └────┬─────┘ │
57
+ │ ↓ │
58
+ │ ┌──────────┐ │
59
+ │ │ ACT │ ← TDD cycle, commit, update state │
60
+ │ └────┬─────┘ │
61
+ │ │ │
62
+ │ └──────────→ Back to OBSERVE │
63
+ │ │
64
+ └─────────────────────────────────────────────────────────┘
65
+ ```
66
+
67
+ ### 1. OBSERVE (Before Each TODO)
68
+
69
+ Sense the environment. Don't execute blind.
70
+
71
+ ```yaml
72
+ observe:
73
+ todo_state:
74
+ - Read TODO from queue
75
+ - Check depends_on satisfied
76
+
77
+ environment:
78
+ - git status (uncommitted changes?)
79
+ - External deps (docker, API health)
80
+ - Branch correct?
81
+
82
+ patterns:
83
+ - Retry rate last 3 TODOs
84
+ - Error type clustering
85
+ - Time since last success
86
+
87
+ context:
88
+ - Exchange count
89
+ - Token usage trend
90
+ ```
91
+
92
+ **Output**: `observation` object with signals.
93
+
94
+ ### 2. ORIENT (Analyze & Assess)
95
+
96
+ Update mental model. This is the schwerpunkt.
97
+
98
+ ```yaml
99
+ orient:
100
+ confidence: high | medium | low
101
+
102
+ factors:
103
+ - TODO complexity (files, dependencies)
104
+ - Related TODO success rate
105
+ - Pattern match to previous failures
106
+ - Skill availability
107
+
108
+ warnings:
109
+ - "3 consecutive retries in this module"
110
+ - "Similar TODO failed: todo-1.1a-003"
111
+ - "External dep flaky (2 timeouts)"
112
+
113
+ recommendations:
114
+ - proceed | proceed_cautious | replan | escalate
115
+ ```
116
+
117
+ **Confidence Calculation**:
118
+ ```
119
+ high: No warnings, related TODOs succeeded, skill available
120
+ medium: Minor warnings, some retries in module
121
+ low: Pattern match to failures, external dep issues, 3+ retries
122
+ ```
123
+
124
+ ### 3. DECIDE (Intelligent Routing)
125
+
126
+ Choose action based on orientation, not just queue position.
127
+
128
+ | Confidence | Tempo: ship-fast | Tempo: balanced | Tempo: careful |
129
+ |------------|------------------|-----------------|----------------|
130
+ | High | Execute | Execute | Execute |
131
+ | Medium | Execute | Execute + monitor | Ask user |
132
+ | Low | Skip, log | Ask: execute/skip/replan | Pause, replan |
133
+
134
+ **Decision Options**:
135
+
136
+ ```yaml
137
+ decisions:
138
+ execute:
139
+ action: Run TDD cycle
140
+ when: confidence >= threshold
141
+
142
+ execute_cautious:
143
+ action: Run TDD with extra verification
144
+ when: medium confidence, balanced tempo
145
+
146
+ skip_and_continue:
147
+ action: Mark skipped, proceed to next
148
+ when: low confidence, ship-fast tempo
149
+
150
+ replan:
151
+ action: Trigger section re-planning
152
+ when: 3+ failures in module, pattern detected
153
+ output: "Auth module failing consistently. Re-plan? [y/n]"
154
+
155
+ escalate:
156
+ action: Pause, surface to human
157
+ when: blocker detected, autonomous mode
158
+ ```
159
+
160
+ ### 4. ACT (TDD Cycle)
161
+
162
+ Execute the decided action.
163
+
164
+ ```yaml
165
+ act:
166
+ tdd_cycle:
167
+ RED: Write failing tests
168
+ GREEN: Implement until tests pass
169
+ REFACTOR: Clean up
170
+ VERIFY: lint ✓ | tsc ✓ | test ✓
171
+
172
+ on_pass:
173
+ - Mark TODO done
174
+ - Commit with conventional message
175
+ - Update progress.yaml
176
+ - → OBSERVE next TODO
177
+
178
+ on_fail:
179
+ - Increment retry counter
180
+ - Log error pattern
181
+ - → OBSERVE (not retry immediately)
182
+ ```
183
+
184
+ **Key**: After ACT, return to OBSERVE, not "next TODO". This enables re-orientation.
185
+
186
+ ## Pattern Detection (In-Loop)
187
+
188
+ Patterns detected during ORIENT phase:
189
+
190
+ | Pattern | Detection | Response |
191
+ |---------|-----------|----------|
192
+ | Retry spike | 3+ retries in last 5 TODOs | Lower confidence |
193
+ | Error clustering | Same error type 3+ times | Flag blocker |
194
+ | Module failing | 3+ failures in same module | Suggest replan |
195
+ | External dep down | Connection errors | Skip dependents |
196
+ | Context bloat | 20+ exchanges | Suggest /compact |
197
+
198
+ ## Adaptive Re-planning
199
+
200
+ When DECIDE routes to `replan`:
201
+
202
+ ```
203
+ ═══════════════════════════════════════════════════════════
204
+ ⚠ PATTERN DETECTED: Auth module failing (replan 1/2)
205
+
206
+ Last 3 TODOs in auth/ failed:
207
+ todo-1.2a-003: "JWT validation error" (3 retries)
208
+ todo-1.2a-004: "Token refresh failed" (2 retries)
209
+ todo-1.2a-005: "Session storage error" (3 retries)
210
+
211
+ Analysis: Possible architecture issue in auth design.
212
+
213
+ Options:
214
+ [c] Continue anyway (force execute)
215
+ [r] Re-plan auth section (generate new approach)
216
+ [s] Skip auth, continue other work
217
+ [p] Pause for investigation
218
+
219
+ Choice: _
220
+ ═══════════════════════════════════════════════════════════
221
+ ```
222
+
223
+ ## Guardrails (Prevent Infinite Loops)
224
+
225
+ Replan is **not** "retry forever." Hard limits prevent runaway costs.
226
+
227
+ ### Limits
228
+
229
+ | Guardrail | Default | Purpose |
230
+ |-----------|---------|---------|
231
+ | `max_replans_per_module` | 2 | Same module can't replan endlessly |
232
+ | `max_replans_per_feature` | 3 | Feature-level cap |
233
+ | `max_retries_per_todo` | 3 | Individual TODO retry cap |
234
+ | `on_limit_hit` | `escalate` | What happens at limit |
235
+
236
+ ### Behavior When Limit Hit
237
+
238
+ ```
239
+ ⛔ GUARDRAIL: auth module replanned 2x, still failing
240
+
241
+ Replan history:
242
+ 1. Changed JWT → session tokens (failed)
243
+ 2. Changed to OAuth flow (failed)
244
+
245
+ This section needs human intervention.
246
+
247
+ Options:
248
+ [1] Skip auth module, continue other work
249
+ [2] Pause for manual investigation
250
+ [3] Abort run
251
+
252
+ ❌ Cannot replan again (limit: 2/module)
253
+ ```
254
+
255
+ ### Cost Protection
256
+
257
+ ```yaml
258
+ guardrails:
259
+ max_replans_per_module: 2
260
+ max_replans_per_feature: 3
261
+ max_retries_per_todo: 3
262
+ on_limit_hit: escalate|abort|skip_module
263
+
264
+ # Optional cost tracking
265
+ cost_limit: 5.00 # USD, stop if exceeded
266
+ cost_current: 1.23
267
+ ```
268
+
269
+ ### ORIENT Checks Guardrails
270
+
271
+ Before suggesting replan, ORIENT verifies:
272
+
273
+ ```yaml
274
+ orient:
275
+ can_replan: true|false
276
+ replan_count_module: 1
277
+ replan_limit_module: 2
278
+
279
+ # If can_replan: false
280
+ recommendation: escalate # Not replan
281
+ reason: "Module replan limit (2) reached"
282
+ ```
283
+
284
+ ### The Rule
285
+
286
+ ```
287
+ Retry: Try same approach again (max 3x per TODO)
288
+ Replan: Try different approach (max 2x per module)
289
+ Escalate: Human decides (when limits hit)
290
+ ```
291
+
292
+ **No infinite loops. No runaway costs.**
293
+
294
+ ## State: execution_state in progress.yaml
295
+
296
+ ```yaml
297
+ execution_state:
298
+ status: running|paused|stopped|completed|error
299
+ scope: feature-1.1
300
+ tempo: balanced
301
+
302
+ current_todo: todo-1.1b-004
303
+
304
+ # OODA state
305
+ ooda:
306
+ last_observation: 2026-02-20T10:30:00Z
307
+ confidence: medium
308
+ consecutive_failures: 2
309
+ patterns_detected: ["retry_spike"]
310
+
311
+ # Guardrails (prevent infinite loops)
312
+ guardrails:
313
+ max_retries_per_todo: 3
314
+ max_replans_per_module: 2
315
+ max_replans_per_feature: 3
316
+ on_limit_hit: escalate
317
+
318
+ # Per-module replan tracking
319
+ module_replans:
320
+ auth: 1 # 1 replan used, 1 remaining
321
+ api: 0
322
+
323
+ queue:
324
+ total: 14
325
+ completed: [todo-1.1a-001, ...]
326
+ pending: [todo-1.1b-004, ...]
327
+ failed: []
328
+ skipped: []
329
+ replanned: []
330
+
331
+ stats:
332
+ todos_completed: 10
333
+ todos_remaining: 4
334
+ total_retries: 2
335
+ replan_count: 1
336
+ avg_confidence: 0.85
337
+ ```
338
+
339
+ ## Output Format
340
+
341
+ **OBSERVE**:
342
+ ```
343
+ 👁 OBSERVE: todo-1.1b-004
344
+ Environment: ✓ git clean | ✓ deps up | ✓ branch correct
345
+ Patterns: ⚠ 2 retries last 3 TODOs
346
+ ```
347
+
348
+ **ORIENT**:
349
+ ```
350
+ 🧭 ORIENT: confidence=medium
351
+ Module success rate: 70%
352
+ Similar TODO (todo-1.1a-003): passed after 2 retries
353
+ → Proceed with caution
354
+ ```
355
+
356
+ **DECIDE**:
357
+ ```
358
+ ⚡ DECIDE: execute_cautious
359
+ Extra verification enabled
360
+ ```
361
+
362
+ **ACT**:
363
+ ```
364
+ ▶ ACT: todo-1.1b-004 | Verify directory structure
365
+
366
+ RED 3 tests written → ✗ 3 failing
367
+ GREEN implemented → ✓ 3 passing
368
+ VERIFY lint ✓ | tsc ✓ | test ✓
369
+
370
+ ✓ COMPLETE | 2m 15s | commit: abc123
371
+ ```
372
+
373
+ **Checkpoint** (includes pattern summary):
374
+ ```
375
+ ═══════════════════════════════════════════════════════════
376
+ ✓ CHECKPOINT: subfeature-1.1a
377
+
378
+ Progress: 7/7 TODOs | 45m | 3 commits
379
+
380
+ OODA Summary:
381
+ Avg confidence: 0.87
382
+ Patterns: none detected
383
+ Replans: 0
384
+
385
+ Next: subfeature-1.1b (4 TODOs)
386
+
387
+ [c]ontinue [p]ause [a]bort
388
+ ═══════════════════════════════════════════════════════════
389
+ ```
390
+
391
+ ## Autonomous Mode
392
+
393
+ | Aspect | Interactive | Autonomous |
394
+ |--------|-------------|------------|
395
+ | Low confidence | Asks user | Auto-skip, log blocker |
396
+ | Replan trigger | Asks user | Log, continue unblocked |
397
+ | Checkpoints | Pauses | Logs only |
398
+ | Blockers | Waits | Notifies, skips dependents |
399
+
400
+ ## Integration
401
+
402
+ | Command | Integration |
403
+ |---------|-------------|
404
+ | `/pause` | Sets status = paused |
405
+ | `/resume` | Continues from current OBSERVE |
406
+ | `/skip` | DECIDE override: skip current |
407
+ | `/retry` | Reset TODO, back to OBSERVE |
408
+ | `/companion` | Pattern data shared with ORIENT |
409
+ | `/retro` | Triggered by replan decisions |
410
+
411
+ ## Quality Bar
412
+
413
+ - OODA loop cycles continuously (not linear)
414
+ - Pattern detection in-loop, not post-hoc
415
+ - Confidence-based routing, not blind execution
416
+ - Re-orientation when patterns emerge
417
+ - Tempo adapts to situation