create-universal-ai-context 2.5.0 → 2.6.0-final

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 (153) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +331 -294
  3. package/bin/create-ai-context.js +1507 -775
  4. package/lib/adapters/aider.js +131 -131
  5. package/lib/adapters/antigravity.js +205 -205
  6. package/lib/adapters/claude.js +397 -397
  7. package/lib/adapters/cline.js +125 -125
  8. package/lib/adapters/continue.js +138 -138
  9. package/lib/adapters/copilot.js +131 -131
  10. package/lib/adapters/index.js +78 -78
  11. package/lib/adapters/windsurf.js +138 -138
  12. package/lib/ai-context-generator.js +234 -234
  13. package/lib/ai-orchestrator.js +432 -432
  14. package/lib/call-tracer.js +444 -444
  15. package/lib/content-preservation.js +243 -243
  16. package/lib/cross-tool-sync/file-watcher.js +274 -274
  17. package/lib/cross-tool-sync/index.js +41 -40
  18. package/lib/cross-tool-sync/sync-manager.js +540 -512
  19. package/lib/cross-tool-sync/sync-service.js +297 -297
  20. package/lib/detector.js +726 -726
  21. package/lib/doc-discovery.js +741 -741
  22. package/lib/drift-checker.js +920 -920
  23. package/lib/environment-detector.js +239 -239
  24. package/lib/index.js +399 -399
  25. package/lib/install-hooks.js +82 -82
  26. package/lib/installer.js +419 -419
  27. package/lib/migrate.js +328 -328
  28. package/lib/placeholder.js +632 -632
  29. package/lib/prompts.js +341 -341
  30. package/lib/smart-merge.js +540 -540
  31. package/lib/spinner.js +60 -60
  32. package/lib/static-analyzer.js +729 -729
  33. package/lib/template-coordination.js +148 -148
  34. package/lib/template-populator.js +843 -843
  35. package/lib/template-renderer.js +392 -392
  36. package/lib/utils/fs-wrapper.js +79 -79
  37. package/lib/utils/path-utils.js +60 -60
  38. package/lib/validate.js +155 -155
  39. package/package.json +1 -1
  40. package/templates/AI_CONTEXT.md.template +245 -245
  41. package/templates/base/README.md +260 -257
  42. package/templates/base/RPI_WORKFLOW_PLAN.md +325 -320
  43. package/templates/base/agents/api-developer.md +76 -76
  44. package/templates/base/agents/context-engineer.md +525 -525
  45. package/templates/base/agents/core-architect.md +76 -76
  46. package/templates/base/agents/database-ops.md +76 -76
  47. package/templates/base/agents/deployment-ops.md +76 -76
  48. package/templates/base/agents/integration-hub.md +76 -76
  49. package/templates/base/analytics/README.md +114 -114
  50. package/templates/base/automation/config.json +58 -58
  51. package/templates/base/automation/generators/code-mapper.js +308 -308
  52. package/templates/base/automation/generators/index-builder.js +321 -321
  53. package/templates/base/automation/hooks/post-commit.sh +83 -83
  54. package/templates/base/automation/hooks/pre-commit.sh +103 -103
  55. package/templates/base/ci-templates/README.md +108 -108
  56. package/templates/base/ci-templates/github-actions/context-check.yml +144 -144
  57. package/templates/base/ci-templates/github-actions/validate-docs.yml +105 -105
  58. package/templates/base/commands/analytics.md +238 -238
  59. package/templates/base/commands/auto-sync.md +172 -172
  60. package/templates/base/commands/collab.md +194 -194
  61. package/templates/base/commands/context-optimize.md +226 -0
  62. package/templates/base/commands/help.md +485 -450
  63. package/templates/base/commands/rpi-implement.md +164 -115
  64. package/templates/base/commands/rpi-plan.md +147 -93
  65. package/templates/base/commands/rpi-research.md +145 -88
  66. package/templates/base/commands/session-resume.md +144 -144
  67. package/templates/base/commands/session-save.md +112 -112
  68. package/templates/base/commands/validate-all.md +77 -77
  69. package/templates/base/commands/verify-docs-current.md +86 -86
  70. package/templates/base/config/base.json +57 -57
  71. package/templates/base/config/environments/development.json +13 -13
  72. package/templates/base/config/environments/production.json +17 -17
  73. package/templates/base/config/environments/staging.json +13 -13
  74. package/templates/base/config/local.json.example +21 -21
  75. package/templates/base/context/.meta/generated-at.json +18 -18
  76. package/templates/base/context/ARCHITECTURE_SNAPSHOT.md +156 -156
  77. package/templates/base/context/CODE_TO_WORKFLOW_MAP.md +94 -94
  78. package/templates/base/context/FILE_OWNERSHIP.md +57 -57
  79. package/templates/base/context/INTEGRATION_POINTS.md +92 -92
  80. package/templates/base/context/KNOWN_GOTCHAS.md +195 -195
  81. package/templates/base/context/TESTING_MAP.md +95 -95
  82. package/templates/base/context/WORKFLOW_INDEX.md +129 -129
  83. package/templates/base/context/workflows/WORKFLOW_TEMPLATE.md +294 -294
  84. package/templates/base/indexes/agents/CAPABILITY_MATRIX.md +255 -255
  85. package/templates/base/indexes/agents/CATEGORY_INDEX.md +44 -44
  86. package/templates/base/indexes/code/CATEGORY_INDEX.md +38 -38
  87. package/templates/base/indexes/routing/CATEGORY_INDEX.md +39 -39
  88. package/templates/base/indexes/search/CATEGORY_INDEX.md +39 -39
  89. package/templates/base/indexes/workflows/CATEGORY_INDEX.md +38 -38
  90. package/templates/base/knowledge/README.md +98 -98
  91. package/templates/base/knowledge/sessions/README.md +88 -88
  92. package/templates/base/knowledge/sessions/TEMPLATE.md +150 -150
  93. package/templates/base/knowledge/shared/decisions/0001-adopt-context-engineering.md +144 -144
  94. package/templates/base/knowledge/shared/decisions/README.md +49 -49
  95. package/templates/base/knowledge/shared/decisions/TEMPLATE.md +123 -123
  96. package/templates/base/knowledge/shared/patterns/README.md +62 -62
  97. package/templates/base/knowledge/shared/patterns/TEMPLATE.md +120 -120
  98. package/templates/base/plans/PLAN_TEMPLATE.md +316 -250
  99. package/templates/base/research/RESEARCH_TEMPLATE.md +245 -153
  100. package/templates/base/schemas/agent.schema.json +141 -141
  101. package/templates/base/schemas/anchors.schema.json +54 -54
  102. package/templates/base/schemas/automation.schema.json +93 -93
  103. package/templates/base/schemas/command.schema.json +134 -134
  104. package/templates/base/schemas/hashes.schema.json +40 -40
  105. package/templates/base/schemas/manifest.schema.json +117 -117
  106. package/templates/base/schemas/plan.schema.json +136 -136
  107. package/templates/base/schemas/research.schema.json +115 -115
  108. package/templates/base/schemas/roles.schema.json +34 -34
  109. package/templates/base/schemas/session.schema.json +77 -77
  110. package/templates/base/schemas/settings.schema.json +244 -244
  111. package/templates/base/schemas/staleness.schema.json +53 -53
  112. package/templates/base/schemas/team-config.schema.json +42 -42
  113. package/templates/base/schemas/workflow.schema.json +126 -126
  114. package/templates/base/session/checkpoints/.gitkeep +2 -2
  115. package/templates/base/session/current/state.json +20 -20
  116. package/templates/base/session/history/.gitkeep +2 -2
  117. package/templates/base/settings.json +3 -3
  118. package/templates/base/standards/COMPATIBILITY.md +219 -219
  119. package/templates/base/standards/EXTENSION_GUIDELINES.md +280 -280
  120. package/templates/base/standards/QUALITY_CHECKLIST.md +211 -211
  121. package/templates/base/standards/README.md +66 -66
  122. package/templates/base/sync/anchors.json +6 -6
  123. package/templates/base/sync/hashes.json +6 -6
  124. package/templates/base/sync/staleness.json +10 -10
  125. package/templates/base/team/README.md +168 -168
  126. package/templates/base/team/config.json +79 -79
  127. package/templates/base/team/roles.json +145 -145
  128. package/templates/base/tools/bin/claude-context.js +151 -151
  129. package/templates/base/tools/lib/anchor-resolver.js +276 -276
  130. package/templates/base/tools/lib/config-loader.js +363 -363
  131. package/templates/base/tools/lib/detector.js +350 -350
  132. package/templates/base/tools/lib/diagnose.js +206 -206
  133. package/templates/base/tools/lib/drift-detector.js +373 -373
  134. package/templates/base/tools/lib/errors.js +199 -199
  135. package/templates/base/tools/lib/index.js +36 -36
  136. package/templates/base/tools/lib/init.js +192 -192
  137. package/templates/base/tools/lib/logger.js +230 -230
  138. package/templates/base/tools/lib/placeholder.js +201 -201
  139. package/templates/base/tools/lib/session-manager.js +354 -354
  140. package/templates/base/tools/lib/validate.js +521 -521
  141. package/templates/base/tools/package.json +49 -49
  142. package/templates/handlebars/aider-config.hbs +146 -80
  143. package/templates/handlebars/antigravity.hbs +377 -377
  144. package/templates/handlebars/claude.hbs +183 -183
  145. package/templates/handlebars/cline.hbs +62 -62
  146. package/templates/handlebars/continue-config.hbs +116 -116
  147. package/templates/handlebars/copilot.hbs +130 -130
  148. package/templates/handlebars/partials/gotcha-list.hbs +11 -11
  149. package/templates/handlebars/partials/header.hbs +3 -3
  150. package/templates/handlebars/partials/workflow-summary.hbs +16 -16
  151. package/templates/handlebars/windsurf-rules.hbs +69 -69
  152. package/templates/hooks/post-commit.hbs +28 -29
  153. package/templates/hooks/pre-commit.hbs +46 -46
@@ -1,320 +1,325 @@
1
- # RPI (Research, Plan, Implement) Workflow
2
-
3
- **Created:** {{DATE}}
4
- **Platform:** Claude Code
5
- **Context Budget:** 200k tokens max, target <40%
6
- **Output Budget:** 30k tokens max per response
7
-
8
- ---
9
-
10
- ## Executive Summary
11
-
12
- The RPI workflow prevents the "slop" and "dumb zone" problems in AI-assisted development. By separating research, planning, and implementation into distinct phases, we achieve:
13
-
14
- - **90% fewer cascading errors**
15
- - **3× faster feature implementation**
16
- - **5× faster issue resolution**
17
- - **Self-documenting changes**
18
-
19
- ---
20
-
21
- ## Phase 1: RESEARCH
22
-
23
- ### Purpose
24
- Understand the system, locate relevant components, prevent context pollution
25
-
26
- ### Artifacts
27
- - Research document in `.ai-context/research/active/[feature]_research.md`
28
- - 150-word summary for parent context
29
-
30
- ### Process
31
- 1. Load WORKFLOW_INDEX.md first (saves 100k+ tokens)
32
- 2. Use parallel Explore agents (3 simultaneous)
33
- 3. Trace call chains with line numbers
34
- 4. Map dependencies (internal + external)
35
- 5. Identify test coverage gaps
36
- 6. Document open questions
37
-
38
- ### Context Budget
39
- - Starting: Up to 50k tokens for exploration
40
- - Ending: 20k tokens (research doc only)
41
- - Compaction: After each phase
42
-
43
- ### Exit Criteria
44
- - [ ] Research document created
45
- - [ ] 3-20 relevant files identified
46
- - [ ] Call chains traced with line numbers
47
- - [ ] Dependencies mapped
48
- - [ ] 150-word summary generated
49
-
50
- ---
51
-
52
- ## Phase 2: PLAN
53
-
54
- ### Purpose
55
- Design implementation with file:line precision, get human alignment
56
-
57
- ### Artifacts
58
- - Plan document in `.ai-context/plans/active/[feature]_plan.md`
59
- - Step-by-step implementation roadmap
60
-
61
- ### Process
62
- 1. Load research document
63
- 2. Reference workflow gotchas
64
- 3. Create modification list with exact line numbers
65
- 4. Plan testing strategy
66
- 5. Estimate context budget per step
67
- 6. Define rollback plan
68
-
69
- ### Context Budget
70
- - Research doc: 20k tokens
71
- - Plan creation: 15k tokens
72
- - Total: 35k tokens (17.5%)
73
-
74
- ### Exit Criteria
75
- - [ ] Plan document created with file:line references
76
- - [ ] All modifications listed with risk level
77
- - [ ] Test strategy defined
78
- - [ ] Rollback plan documented
79
- - [ ] Human review completed
80
-
81
- ---
82
-
83
- ## Phase 3: IMPLEMENT
84
-
85
- ### Purpose
86
- Execute atomically with continuous testing
87
-
88
- ### Golden Rule
89
- ```
90
- ONE CHANGE → ONE TEST → ONE COMMIT
91
- ```
92
-
93
- ### Process
94
- 1. Load plan and affected workflow sections
95
- 2. Make single, atomic change
96
- 3. Run affected tests immediately
97
- 4. Commit if tests pass
98
- 5. Update documentation
99
- 6. Repeat until plan complete
100
-
101
- ### Context Budget
102
- - Plan: 15k tokens
103
- - Active code: 30k tokens
104
- - Test results: 15k tokens
105
- - Total: 60k tokens (30%)
106
-
107
- ### Context Reset (Every 3 Steps)
108
- 1. Update progress checklist
109
- 2. Re-read plan document
110
- 3. Verify scope alignment
111
- 4. Compact if >35% utilization
112
-
113
- ### Exit Criteria
114
- - [ ] All plan steps completed
115
- - [ ] All tests passing
116
- - [ ] Documentation updated
117
- - [ ] Changes committed
118
-
119
- ---
120
-
121
- ## Template Files
122
-
123
- ### RESEARCH_TEMPLATE.md
124
-
125
- ```markdown
126
- # Research: [Feature/Bug Name]
127
-
128
- **Date:** YYYY-MM-DD
129
- **Researcher:** Claude Code
130
- **Status:** IN_PROGRESS | COMPLETE | BLOCKED
131
-
132
- ---
133
-
134
- ## Objective
135
- [Clear statement of what we're trying to understand]
136
-
137
- ---
138
-
139
- ## Relevant Files Explored
140
-
141
- | File | Lines | Key Findings |
142
- |------|-------|--------------|
143
- | `path/to/file.py` | 100-200 | Entry point for [feature] |
144
-
145
- ---
146
-
147
- ## Code Flow Analysis
148
-
149
- [Entry Point] → [Function A] → [Function B] → [Exit Point]
150
-
151
- ```
152
- entry_function() [file.py:100]
153
- ├─ helper_a() [file.py:150]
154
- │ └─ utility() [utils.py:50]
155
- └─ helper_b() [file.py:200]
156
- ```
157
-
158
- ---
159
-
160
- ## Dependencies Identified
161
-
162
- **External:**
163
- - API Name (purpose)
164
-
165
- **Internal:**
166
- - service_file.py (purpose)
167
-
168
- ---
169
-
170
- ## Test Files & Coverage
171
-
172
- **Existing:**
173
- - tests/test_feature.py - Covers main flow
174
-
175
- **Gaps:**
176
- - ❌ No test for error scenario
177
-
178
- ---
179
-
180
- ## Open Questions
181
-
182
- - [ ] Question 1
183
- - [ ] Question 2
184
-
185
- ---
186
-
187
- ## Summary (for Plan Phase, 150 words max)
188
-
189
- [Concise summary for parent context]
190
- ```
191
-
192
- ---
193
-
194
- ### PLAN_TEMPLATE.md
195
-
196
- ```markdown
197
- # Implementation Plan: [Feature/Fix Name]
198
-
199
- **Date:** YYYY-MM-DD
200
- **Based on:** research/active/[feature]_research.md
201
- **Status:** DRAFT | APPROVED | IMPLEMENTING | COMPLETE
202
-
203
- ---
204
-
205
- ## Research Summary
206
- [From Phase 1 - max 200 words]
207
-
208
- ---
209
-
210
- ## Scope Definition
211
-
212
- **In Scope:**
213
- - [Explicit list]
214
-
215
- **Out of Scope:**
216
- - [What we're NOT touching]
217
-
218
- ---
219
-
220
- ## Files to Modify
221
-
222
- | File | Lines | Change | Risk |
223
- |------|-------|--------|------|
224
- | `path/file.py` | 100-150 | Add parameter | LOW |
225
-
226
- ---
227
-
228
- ## Step-by-Step Implementation
229
-
230
- ### Step 1: [Action Name]
231
-
232
- **File:** `path/to/file.py`
233
- **Lines:** 100-120
234
-
235
- **Current:**
236
- ```python
237
- def existing_function():
238
- pass
239
- ```
240
-
241
- **Proposed:**
242
- ```python
243
- def existing_function(new_param: str = "default"):
244
- pass
245
- ```
246
-
247
- **Test:** `pytest tests/test_file.py -k test_name`
248
-
249
- ---
250
-
251
- ### Step 2: [Action Name]
252
- ...
253
-
254
- ---
255
-
256
- ## Verification Checklist
257
-
258
- - [ ] Syntax check passes
259
- - [ ] Unit tests pass
260
- - [ ] Integration tests pass
261
- - [ ] E2E test passes
262
-
263
- ---
264
-
265
- ## Rollback Plan
266
-
267
- - Revert: `git revert HEAD`
268
- - Safe commit: `[hash]`
269
-
270
- ---
271
-
272
- ## Documentation Updates Required
273
-
274
- - [ ] Workflow file: [name]
275
- - [ ] Agent file: [name]
276
- - [ ] AI_CONTEXT.md section: [name]
277
- ```
278
-
279
- ---
280
-
281
- ## Error Recovery Protocol
282
-
283
- | Error Type | Response |
284
- |------------|----------|
285
- | Syntax Error | STOP. Fix immediately in same session. |
286
- | Import Error | Check file paths, verify imports. |
287
- | Runtime Error | Create research subtask before fixing. |
288
- | Test Failure | Do NOT add more code. Investigate first. |
289
- | 3+ Failures | STOP. Compact context. Start new session. |
290
-
291
- ---
292
-
293
- ## Context Management
294
-
295
- ### Compaction Triggers
296
- - After 5+ file reads without tool use
297
- - Error loop (3+ failed attempts)
298
- - Session > 1 hour
299
- - Context > 35% utilization
300
-
301
- ### Compaction Actions
302
- 1. Save progress to SESSION_HANDOFF.md
303
- 2. Archive tool results
304
- 3. Keep only essential context
305
- 4. Continue or start fresh session
306
-
307
- ---
308
-
309
- ## Key Principles
310
-
311
- 1. **<40% Context Rule:** Performance degrades beyond 40% context utilization
312
- 2. **Sub-Agents:** Use parallel Explore agents for context isolation
313
- 3. **On-Demand Loading:** Load information as needed, not upfront
314
- 4. **Mental Alignment:** Plans align human and AI understanding
315
- 5. **Atomic Changes:** Small, testable, reversible modifications
316
-
317
- ---
318
-
319
- **Version:** 1.1
320
- **Status:** TEMPLATE
1
+ # RPI (Research, Plan, Implement) Workflow
2
+
3
+ **Created:** {{DATE}}
4
+ **Platform:** Claude Code
5
+ **Context Budget:** 200k tokens max, target <40%
6
+ **Output Budget:** 30k tokens max per response
7
+
8
+ ---
9
+
10
+ ## Executive Summary
11
+
12
+ The RPI workflow prevents the "slop" and "dumb zone" problems in AI-assisted development. By separating research, planning, and implementation into distinct phases, we achieve:
13
+
14
+ - **90% fewer cascading errors**
15
+ - **3× faster feature implementation**
16
+ - **5× faster issue resolution**
17
+ - **Self-documenting changes**
18
+
19
+ **Key Innovation: Parallel Agents with Chunked Todolists**
20
+
21
+ Each RPI phase inherently utilizes parallel agents and produces chunk-based outputs designed for consumption by the next phase. This creates a self-aware pipeline where:
22
+ - RPI-Research outputs chunks knowing RPI-Plan will consume them
23
+ - RPI-Plan creates chunk-todolists knowing RPI-Implement will process them
24
+ - Each phase loops through chunks, marking completion as it progresses
25
+
26
+ ---
27
+
28
+ ## Phase 1: RESEARCH
29
+
30
+ ### Purpose
31
+ Understand the system, locate relevant components, prevent context pollution
32
+
33
+ ### Artifacts
34
+ - Research document in `.ai-context/research/active/[feature]_research.md`
35
+ - **Chunked Research Sections** (3-7 chunks based on complexity)
36
+ - 150-word summary for parent context
37
+
38
+ ### Process
39
+ 1. Load WORKFLOW_INDEX.md first (saves 100k+ tokens)
40
+ 2. **Spawn 3-5 parallel Explore agents** (one per research domain)
41
+ 3. Each agent produces a **Research Chunk** with:
42
+ - Chunk ID (e.g., `CHUNK-R1`, `CHUNK-R2`)
43
+ - Explored files with line numbers
44
+ - Call chains traced
45
+ - Dependencies found
46
+ - Chunk status: `COMPLETE` | `IN_PROGRESS` | `BLOCKED`
47
+ 4. Aggregate chunks into unified research document
48
+ 5. Format output specifically for RPI-Plan consumption
49
+
50
+ ### Parallel Agent Strategy
51
+ ```
52
+ ┌─────────────────────────────────────────────────────────┐
53
+ │ RPI-RESEARCH PARALLEL EXECUTION │
54
+ ├─────────────────────────────────────────────────────────┤
55
+ Agent 1: API/Route Entry Points → CHUNK-R1 │
56
+ │ Agent 2: Business Logic & Models → CHUNK-R2 │
57
+ Agent 3: Database/Storage Layer → CHUNK-R3 │
58
+ Agent 4: External Integrations → CHUNK-R4 │
59
+ Agent 5: Test Coverage Analysis → CHUNK-R5 │
60
+ └─────────────────────────────────────────────────────────┘
61
+ ```
62
+
63
+ ### Inter-Phase Awareness
64
+ **RPI-Research KNOWS that RPI-Plan will:**
65
+ - Read each chunk sequentially
66
+ - Generate a planning todolist per chunk
67
+ - Mark chunks as `PLANNED` when processed
68
+ - Require: chunk IDs, file:line refs, dependency list
69
+
70
+ ### Context Budget
71
+ - Starting: Up to 50k tokens for exploration
72
+ - Ending: 20k tokens (research doc only)
73
+ - Compaction: After each phase
74
+
75
+ ### Exit Criteria
76
+ - [ ] Research document created with chunked structure
77
+ - [ ] 3-20 relevant files identified per chunk
78
+ - [ ] Call chains traced with line numbers
79
+ - [ ] Dependencies mapped per chunk
80
+ - [ ] 150-word summary generated
81
+ - [ ] **Chunk manifest created for RPI-Plan**
82
+
83
+ ---
84
+
85
+ ## Phase 2: PLAN
86
+
87
+ ### Purpose
88
+ Design implementation with file:line precision, get human alignment
89
+
90
+ ### Artifacts
91
+ - Plan document in `.ai-context/plans/active/[feature]_plan.md`
92
+ - **Chunk-Based Todolists** (one per research chunk)
93
+ - Step-by-step implementation roadmap
94
+
95
+ ### Process
96
+ 1. Load research document with chunks
97
+ 2. **For each Research Chunk (CHUNK-Rn):**
98
+ a. Create corresponding Plan Chunk (CHUNK-Pn)
99
+ b. Generate specific todolist for that chunk
100
+ c. Mark research chunk as `PLANNED`
101
+ d. Record dependencies between plan chunks
102
+ 3. Reference workflow gotchas
103
+ 4. Create modification list with exact line numbers
104
+ 5. Plan testing strategy per chunk
105
+ 6. Define rollback plan
106
+ 7. **Loop until all research chunks are processed**
107
+
108
+ ### Chunk-Based Todolist Generation
109
+ ```
110
+ ┌─────────────────────────────────────────────────────────┐
111
+ RPI-PLAN CHUNK PROCESSING LOOP │
112
+ ├─────────────────────────────────────────────────────────┤
113
+ FOR each CHUNK-Rn in research_chunks: │
114
+ │ 1. Read CHUNK-Rn content │
115
+ │ 2. Create CHUNK-Pn todolist: │
116
+ - [ ] Analyze files from CHUNK-Rn │
117
+ - [ ] Define modifications with line numbers │
118
+ │ - [ ] Specify tests for this chunk │
119
+ │ - [ ] Document rollback for this chunk │
120
+ │ 3. Mark CHUNK-Rn as PLANNED │
121
+ │ 4. Link CHUNK-Pn dependencies │
122
+ │ 5. Proceed to next CHUNK-R(n+1) │
123
+ END LOOP │
124
+ │ Generate unified plan document │
125
+ └─────────────────────────────────────────────────────────┘
126
+ ```
127
+
128
+ ### Inter-Phase Awareness
129
+ **RPI-Plan KNOWS that:**
130
+ - RPI-Research structured chunks for sequential processing
131
+ - RPI-Implement will read each CHUNK-Pn as an atomic unit
132
+ - Each CHUNK-Pn must be independently implementable
133
+ - Chunk dependencies must be explicit for proper ordering
134
+
135
+ ### Context Budget
136
+ - Research doc: 20k tokens
137
+ - Plan creation: 15k tokens
138
+ - Total: 35k tokens (17.5%)
139
+
140
+ ### Exit Criteria
141
+ - [ ] Plan document created with file:line references
142
+ - [ ] **All research chunks marked as PLANNED**
143
+ - [ ] **Chunk-todolists created for each chunk**
144
+ - [ ] All modifications listed with risk level
145
+ - [ ] Test strategy defined per chunk
146
+ - [ ] Rollback plan documented
147
+ - [ ] Human review completed
148
+ - [ ] **Chunk manifest created for RPI-Implement**
149
+
150
+ ---
151
+
152
+ ## Phase 3: IMPLEMENT
153
+
154
+ ### Purpose
155
+ Execute atomically with continuous testing
156
+
157
+ ### Golden Rule
158
+ ```
159
+ ONE CHUNK → COMPLETE TODOLIST → MARK DONE → NEXT CHUNK
160
+ ```
161
+
162
+ ### Process
163
+ 1. Load plan document with chunk-todolists
164
+ 2. **For each Plan Chunk (CHUNK-Pn):**
165
+ a. Load chunk-specific todolist
166
+ b. Execute each todo item atomically:
167
+ - Make single change
168
+ - Run chunk-specific test
169
+ - Commit if pass, stop if fail
170
+ c. Update documentation for this chunk
171
+ d. Mark CHUNK-Pn as `IMPLEMENTED`
172
+ e. Mark corresponding CHUNK-Rn in research as `IMPLEMENTED`
173
+ f. Proceed to next CHUNK-P(n+1)
174
+ 3. **Loop until all plan chunks are processed**
175
+ 4. Run full test suite after all chunks complete
176
+
177
+ ### Chunk-Based Implementation Loop
178
+ ```
179
+ ┌─────────────────────────────────────────────────────────┐
180
+ RPI-IMPLEMENT CHUNK PROCESSING LOOP │
181
+ ├─────────────────────────────────────────────────────────┤
182
+ FOR each CHUNK-Pn in plan_chunks: │
183
+ │ 1. Load CHUNK-Pn todolist │
184
+ │ 2. FOR each TODO item in CHUNK-Pn: │
185
+ │ a. Make atomic change │
186
+ │ b. Run specified test │
187
+ │ c. If PASS: commit, mark TODO complete │
188
+ │ d. If FAIL: stop, investigate, fix │
189
+ │ 3. Update chunk documentation │
190
+ │ 4. Mark CHUNK-Pn as IMPLEMENTED │
191
+ │ 5. Update research CHUNK-Rn status to COMPLETE │
192
+ │ 6. Context reset if >35% utilization │
193
+ │ 7. Proceed to CHUNK-P(n+1) │
194
+ END LOOP │
195
+ │ Run full test suite │
196
+ │ Archive plan and research documents │
197
+ └─────────────────────────────────────────────────────────┘
198
+ ```
199
+
200
+ ### Inter-Phase Awareness
201
+ **RPI-Implement KNOWS that:**
202
+ - RPI-Plan structured chunks for atomic implementation
203
+ - Each CHUNK-Pn contains a complete, ordered todolist
204
+ - Chunk dependencies dictate execution order
205
+ - Marking chunks updates both plan and research documents
206
+
207
+ ### Context Budget
208
+ - Plan: 15k tokens
209
+ - Active code: 30k tokens
210
+ - Test results: 15k tokens
211
+ - Total: 60k tokens (30%)
212
+
213
+ ### Context Reset (Every 3 Chunks or 35% Utilization)
214
+ 1. Update progress checklist
215
+ 2. Re-read plan document
216
+ 3. Verify scope alignment
217
+ 4. Compact if >35% utilization
218
+
219
+ ### Exit Criteria
220
+ - [ ] **All plan chunks marked as IMPLEMENTED**
221
+ - [ ] **All research chunks marked as COMPLETE**
222
+ - [ ] All tests passing
223
+ - [ ] Documentation updated per chunk
224
+ - [ ] Changes committed
225
+
226
+ ---
227
+
228
+ ## Inter-Phase Communication Protocol
229
+
230
+ The key innovation of the enhanced RPI workflow is **inter-phase awareness**. Each phase produces output specifically formatted for the next phase's consumption.
231
+
232
+ ### Research → Plan Communication
233
+ ```
234
+ CHUNK_MANIFEST:
235
+ ├── CHUNK-R1: (status, files, dependencies, ready_for_planning)
236
+ ├── CHUNK-R2: (status, files, dependencies, ready_for_planning)
237
+ └── CHUNK-Rn: ...
238
+
239
+ INTER_PHASE_CONTRACT:
240
+ ├── expected_consumer: "rpi-plan"
241
+ ├── chunk_processing_order: "sequential"
242
+ ├── mark_as_planned_when: "chunk_todolist_created"
243
+ └── required_output: "CHUNK-Pn per CHUNK-Rn"
244
+ ```
245
+
246
+ ### Plan → Implement Communication
247
+ ```
248
+ CHUNK_MANIFEST:
249
+ ├── CHUNK-P1: (todolist, tests, rollback, dependencies)
250
+ ├── CHUNK-P2: (todolist, tests, rollback, dependencies)
251
+ └── CHUNK-Pn: ...
252
+
253
+ INTER_PHASE_CONTRACT:
254
+ ├── expected_consumer: "rpi-implement"
255
+ ├── chunk_processing_order: "dependency-ordered"
256
+ ├── mark_as_implemented_when: "all_todos_complete"
257
+ └── update_research_status: true
258
+ ```
259
+
260
+ ---
261
+
262
+ ## Error Recovery Protocol
263
+
264
+ | Error Type | Response |
265
+ |------------|----------|
266
+ | Syntax Error | STOP. Fix immediately in same session. |
267
+ | Import Error | Check file paths, verify imports. |
268
+ | Runtime Error | Create research subtask before fixing. |
269
+ | Test Failure | Do NOT add more code. Investigate first. |
270
+ | 3+ Failures | STOP. Compact context. Start new session. |
271
+ | **Chunk Failure** | Mark chunk as BLOCKED, proceed to independent chunks, revisit later. |
272
+
273
+ ---
274
+
275
+ ## Context Management
276
+
277
+ ### Compaction Triggers
278
+ - After 5+ file reads without tool use
279
+ - Error loop (3+ failed attempts)
280
+ - Session > 1 hour
281
+ - Context > 35% utilization
282
+ - **After every 3 chunks processed**
283
+
284
+ ### Compaction Actions
285
+ 1. Save progress to SESSION_HANDOFF.md
286
+ 2. Archive tool results
287
+ 3. Keep only essential context
288
+ 4. Continue or start fresh session
289
+ 5. **Preserve chunk manifest with current status**
290
+
291
+ ---
292
+
293
+ ## Key Principles
294
+
295
+ 1. **<40% Context Rule:** Performance degrades beyond 40% context utilization
296
+ 2. **Parallel Sub-Agents:** Use 3-5 parallel Explore agents for context isolation
297
+ 3. **Chunk-Based Processing:** All phases produce and consume chunk-structured data
298
+ 4. **Inter-Phase Awareness:** Each phase knows how the next phase reads its output
299
+ 5. **Atomic Changes:** Small, testable, reversible modifications per todo item
300
+ 6. **Loop-Based Completion:** Process chunks in loops, marking progress explicitly
301
+ 7. **Bidirectional Status Updates:** Implement updates plan AND research status
302
+
303
+ ---
304
+
305
+ ## Quick Reference: Chunk Status Flow
306
+
307
+ ```
308
+ RESEARCH CHUNKS PLAN CHUNKS
309
+ ┌─────────────────┐ ┌─────────────────┐
310
+ │ CHUNK-R1 │ │ CHUNK-P1 │
311
+ Status: FOUND │────────────│ Status: READY │
312
+ COMPLETE │ │ IMPLEMENTING │
313
+ PLANNED │←───────────│ IMPLEMENTED │
314
+ IMPLEMENTED │←───────────│ COMPLETE │
315
+ └─────────────────┘ └─────────────────┘
316
+ ```
317
+
318
+ **Status Transitions:**
319
+ - Research: `FOUND` → `COMPLETE` → `PLANNED` → `IMPLEMENTED`
320
+ - Plan: `DRAFT` → `READY` → `IMPLEMENTING` → `IMPLEMENTED` → `COMPLETE`
321
+
322
+ ---
323
+
324
+ **Version:** 2.0 (Enhanced with Parallel Agents & Chunked Todolists)
325
+ **Status:** TEMPLATE