k0ntext 3.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.
Files changed (239) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +623 -0
  3. package/bin/k0ntext.js +12 -0
  4. package/dist/agents/cleanup-agent.d.ts +39 -0
  5. package/dist/agents/cleanup-agent.d.ts.map +1 -0
  6. package/dist/agents/cleanup-agent.js +56 -0
  7. package/dist/agents/cleanup-agent.js.map +1 -0
  8. package/dist/agents/performance-agent.d.ts +37 -0
  9. package/dist/agents/performance-agent.d.ts.map +1 -0
  10. package/dist/agents/performance-agent.js +91 -0
  11. package/dist/agents/performance-agent.js.map +1 -0
  12. package/dist/analyzer/index.d.ts +5 -0
  13. package/dist/analyzer/index.d.ts.map +1 -0
  14. package/dist/analyzer/index.js +5 -0
  15. package/dist/analyzer/index.js.map +1 -0
  16. package/dist/analyzer/intelligent-analyzer.d.ts +111 -0
  17. package/dist/analyzer/intelligent-analyzer.d.ts.map +1 -0
  18. package/dist/analyzer/intelligent-analyzer.js +537 -0
  19. package/dist/analyzer/intelligent-analyzer.js.map +1 -0
  20. package/dist/cli/commands/cleanup.d.ts +3 -0
  21. package/dist/cli/commands/cleanup.d.ts.map +1 -0
  22. package/dist/cli/commands/cleanup.js +24 -0
  23. package/dist/cli/commands/cleanup.js.map +1 -0
  24. package/dist/cli/commands/export.d.ts +9 -0
  25. package/dist/cli/commands/export.d.ts.map +1 -0
  26. package/dist/cli/commands/export.js +72 -0
  27. package/dist/cli/commands/export.js.map +1 -0
  28. package/dist/cli/commands/import.d.ts +9 -0
  29. package/dist/cli/commands/import.d.ts.map +1 -0
  30. package/dist/cli/commands/import.js +62 -0
  31. package/dist/cli/commands/import.js.map +1 -0
  32. package/dist/cli/commands/performance.d.ts +9 -0
  33. package/dist/cli/commands/performance.d.ts.map +1 -0
  34. package/dist/cli/commands/performance.js +36 -0
  35. package/dist/cli/commands/performance.js.map +1 -0
  36. package/dist/cli/commands/validate.d.ts +9 -0
  37. package/dist/cli/commands/validate.d.ts.map +1 -0
  38. package/dist/cli/commands/validate.js +82 -0
  39. package/dist/cli/commands/validate.js.map +1 -0
  40. package/dist/cli/commands/watch.d.ts +9 -0
  41. package/dist/cli/commands/watch.d.ts.map +1 -0
  42. package/dist/cli/commands/watch.js +72 -0
  43. package/dist/cli/commands/watch.js.map +1 -0
  44. package/dist/cli/generate.d.ts +3 -0
  45. package/dist/cli/generate.d.ts.map +1 -0
  46. package/dist/cli/generate.js +194 -0
  47. package/dist/cli/generate.js.map +1 -0
  48. package/dist/cli/index.d.ts +9 -0
  49. package/dist/cli/index.d.ts.map +1 -0
  50. package/dist/cli/index.js +448 -0
  51. package/dist/cli/index.js.map +1 -0
  52. package/dist/cli/sync.d.ts +26 -0
  53. package/dist/cli/sync.d.ts.map +1 -0
  54. package/dist/cli/sync.js +163 -0
  55. package/dist/cli/sync.js.map +1 -0
  56. package/dist/config/cleanup-config.d.ts +26 -0
  57. package/dist/config/cleanup-config.d.ts.map +1 -0
  58. package/dist/config/cleanup-config.js +21 -0
  59. package/dist/config/cleanup-config.js.map +1 -0
  60. package/dist/db/client.d.ts +284 -0
  61. package/dist/db/client.d.ts.map +1 -0
  62. package/dist/db/client.js +688 -0
  63. package/dist/db/client.js.map +1 -0
  64. package/dist/db/index.d.ts +6 -0
  65. package/dist/db/index.d.ts.map +1 -0
  66. package/dist/db/index.js +6 -0
  67. package/dist/db/index.js.map +1 -0
  68. package/dist/db/schema.d.ts +41 -0
  69. package/dist/db/schema.d.ts.map +1 -0
  70. package/dist/db/schema.js +226 -0
  71. package/dist/db/schema.js.map +1 -0
  72. package/dist/embeddings/index.d.ts +5 -0
  73. package/dist/embeddings/index.d.ts.map +1 -0
  74. package/dist/embeddings/index.js +5 -0
  75. package/dist/embeddings/index.js.map +1 -0
  76. package/dist/embeddings/openrouter.d.ts +133 -0
  77. package/dist/embeddings/openrouter.d.ts.map +1 -0
  78. package/dist/embeddings/openrouter.js +455 -0
  79. package/dist/embeddings/openrouter.js.map +1 -0
  80. package/dist/index.d.ts +14 -0
  81. package/dist/index.d.ts.map +1 -0
  82. package/dist/index.js +18 -0
  83. package/dist/index.js.map +1 -0
  84. package/dist/mcp.d.ts +29 -0
  85. package/dist/mcp.d.ts.map +1 -0
  86. package/dist/mcp.js +257 -0
  87. package/dist/mcp.js.map +1 -0
  88. package/docs/ARCHIVE/MIGRATE_TO_NEW_REPO.md +222 -0
  89. package/docs/ARCHIVE/MIGRATE_TO_UNIFIED.md +220 -0
  90. package/docs/CLEANUP.md +76 -0
  91. package/docs/MCP_QUICKSTART.md +219 -0
  92. package/docs/QUICKSTART.md +119 -0
  93. package/docs/TROUBLESHOOTING.md +611 -0
  94. package/package.json +100 -0
  95. package/skills/context-optimize/SKILL.md +86 -0
  96. package/skills/implement/SKILL.md +150 -0
  97. package/skills/plan/SKILL.md +143 -0
  98. package/skills/research/SKILL.md +103 -0
  99. package/skills/validate/SKILL.md +62 -0
  100. package/skills/verify-docs/SKILL.md +77 -0
  101. package/src/agents/cleanup-agent.ts +96 -0
  102. package/src/agents/performance-agent.ts +117 -0
  103. package/src/analyzer/index.ts +10 -0
  104. package/src/analyzer/intelligent-analyzer.ts +640 -0
  105. package/src/cli/commands/cleanup.ts +26 -0
  106. package/src/cli/commands/export.ts +82 -0
  107. package/src/cli/commands/import.ts +73 -0
  108. package/src/cli/commands/performance.ts +40 -0
  109. package/src/cli/commands/validate.ts +98 -0
  110. package/src/cli/commands/watch.ts +83 -0
  111. package/src/cli/generate.ts +219 -0
  112. package/src/cli/index.ts +510 -0
  113. package/src/cli/sync.ts +194 -0
  114. package/src/config/cleanup-config.ts +42 -0
  115. package/src/db/client.ts +949 -0
  116. package/src/db/index.ts +19 -0
  117. package/src/db/schema.ts +241 -0
  118. package/src/embeddings/index.ts +11 -0
  119. package/src/embeddings/openrouter.ts +592 -0
  120. package/src/index.ts +57 -0
  121. package/src/mcp.ts +354 -0
  122. package/templates/AI_CONTEXT.md.template +245 -0
  123. package/templates/base/README.md +260 -0
  124. package/templates/base/RPI_WORKFLOW_PLAN.md +325 -0
  125. package/templates/base/agents/api-developer.md +76 -0
  126. package/templates/base/agents/context-engineer.md +525 -0
  127. package/templates/base/agents/core-architect.md +76 -0
  128. package/templates/base/agents/database-ops.md +76 -0
  129. package/templates/base/agents/deployment-ops.md +76 -0
  130. package/templates/base/agents/integration-hub.md +76 -0
  131. package/templates/base/analytics/README.md +114 -0
  132. package/templates/base/automation/config.json +58 -0
  133. package/templates/base/automation/generators/code-mapper.js +308 -0
  134. package/templates/base/automation/generators/index-builder.js +321 -0
  135. package/templates/base/automation/hooks/post-commit.sh +83 -0
  136. package/templates/base/automation/hooks/pre-commit.sh +103 -0
  137. package/templates/base/ci-templates/README.md +108 -0
  138. package/templates/base/ci-templates/github-actions/context-check.yml +144 -0
  139. package/templates/base/ci-templates/github-actions/validate-docs.yml +105 -0
  140. package/templates/base/commands/analytics.md +238 -0
  141. package/templates/base/commands/auto-sync.md +172 -0
  142. package/templates/base/commands/collab.md +194 -0
  143. package/templates/base/commands/context-optimize.md +226 -0
  144. package/templates/base/commands/help.md +485 -0
  145. package/templates/base/commands/rpi-implement.md +164 -0
  146. package/templates/base/commands/rpi-plan.md +147 -0
  147. package/templates/base/commands/rpi-research.md +145 -0
  148. package/templates/base/commands/session-resume.md +144 -0
  149. package/templates/base/commands/session-save.md +112 -0
  150. package/templates/base/commands/validate-all.md +77 -0
  151. package/templates/base/commands/verify-docs-current.md +86 -0
  152. package/templates/base/config/base.json +57 -0
  153. package/templates/base/config/environments/development.json +13 -0
  154. package/templates/base/config/environments/production.json +17 -0
  155. package/templates/base/config/environments/staging.json +13 -0
  156. package/templates/base/config/local.json.example +21 -0
  157. package/templates/base/context/.meta/generated-at.json +18 -0
  158. package/templates/base/context/ARCHITECTURE_SNAPSHOT.md +156 -0
  159. package/templates/base/context/CODE_TO_WORKFLOW_MAP.md +94 -0
  160. package/templates/base/context/FILE_OWNERSHIP.md +57 -0
  161. package/templates/base/context/INTEGRATION_POINTS.md +92 -0
  162. package/templates/base/context/KNOWN_GOTCHAS.md +195 -0
  163. package/templates/base/context/TESTING_MAP.md +95 -0
  164. package/templates/base/context/WORKFLOW_INDEX.md +129 -0
  165. package/templates/base/context/workflows/WORKFLOW_TEMPLATE.md +294 -0
  166. package/templates/base/indexes/agents/CAPABILITY_MATRIX.md +255 -0
  167. package/templates/base/indexes/agents/CATEGORY_INDEX.md +44 -0
  168. package/templates/base/indexes/code/CATEGORY_INDEX.md +38 -0
  169. package/templates/base/indexes/routing/CATEGORY_INDEX.md +39 -0
  170. package/templates/base/indexes/search/CATEGORY_INDEX.md +39 -0
  171. package/templates/base/indexes/workflows/CATEGORY_INDEX.md +38 -0
  172. package/templates/base/knowledge/README.md +98 -0
  173. package/templates/base/knowledge/sessions/README.md +88 -0
  174. package/templates/base/knowledge/sessions/TEMPLATE.md +150 -0
  175. package/templates/base/knowledge/shared/decisions/0001-adopt-context-engineering.md +144 -0
  176. package/templates/base/knowledge/shared/decisions/README.md +49 -0
  177. package/templates/base/knowledge/shared/decisions/TEMPLATE.md +123 -0
  178. package/templates/base/knowledge/shared/patterns/README.md +62 -0
  179. package/templates/base/knowledge/shared/patterns/TEMPLATE.md +120 -0
  180. package/templates/base/plans/PLAN_TEMPLATE.md +316 -0
  181. package/templates/base/plans/active/.gitkeep +0 -0
  182. package/templates/base/plans/completed/.gitkeep +0 -0
  183. package/templates/base/research/RESEARCH_TEMPLATE.md +245 -0
  184. package/templates/base/research/active/.gitkeep +0 -0
  185. package/templates/base/research/completed/.gitkeep +0 -0
  186. package/templates/base/schemas/agent.schema.json +141 -0
  187. package/templates/base/schemas/anchors.schema.json +54 -0
  188. package/templates/base/schemas/automation.schema.json +93 -0
  189. package/templates/base/schemas/command.schema.json +134 -0
  190. package/templates/base/schemas/hashes.schema.json +40 -0
  191. package/templates/base/schemas/manifest.schema.json +117 -0
  192. package/templates/base/schemas/plan.schema.json +136 -0
  193. package/templates/base/schemas/research.schema.json +115 -0
  194. package/templates/base/schemas/roles.schema.json +34 -0
  195. package/templates/base/schemas/session.schema.json +77 -0
  196. package/templates/base/schemas/settings.schema.json +244 -0
  197. package/templates/base/schemas/staleness.schema.json +53 -0
  198. package/templates/base/schemas/team-config.schema.json +42 -0
  199. package/templates/base/schemas/workflow.schema.json +126 -0
  200. package/templates/base/session/checkpoints/.gitkeep +2 -0
  201. package/templates/base/session/current/state.json +20 -0
  202. package/templates/base/session/history/.gitkeep +2 -0
  203. package/templates/base/settings.json +3 -0
  204. package/templates/base/standards/COMPATIBILITY.md +219 -0
  205. package/templates/base/standards/EXTENSION_GUIDELINES.md +280 -0
  206. package/templates/base/standards/QUALITY_CHECKLIST.md +211 -0
  207. package/templates/base/standards/README.md +66 -0
  208. package/templates/base/sync/anchors.json +6 -0
  209. package/templates/base/sync/hashes.json +6 -0
  210. package/templates/base/sync/staleness.json +10 -0
  211. package/templates/base/team/README.md +168 -0
  212. package/templates/base/team/config.json +79 -0
  213. package/templates/base/team/roles.json +145 -0
  214. package/templates/base/tools/bin/claude-context.js +151 -0
  215. package/templates/base/tools/lib/anchor-resolver.js +276 -0
  216. package/templates/base/tools/lib/config-loader.js +363 -0
  217. package/templates/base/tools/lib/detector.js +350 -0
  218. package/templates/base/tools/lib/diagnose.js +206 -0
  219. package/templates/base/tools/lib/drift-detector.js +373 -0
  220. package/templates/base/tools/lib/errors.js +199 -0
  221. package/templates/base/tools/lib/index.js +36 -0
  222. package/templates/base/tools/lib/init.js +192 -0
  223. package/templates/base/tools/lib/logger.js +230 -0
  224. package/templates/base/tools/lib/placeholder.js +201 -0
  225. package/templates/base/tools/lib/session-manager.js +354 -0
  226. package/templates/base/tools/lib/validate.js +521 -0
  227. package/templates/base/tools/package.json +49 -0
  228. package/templates/handlebars/aider-config.hbs +146 -0
  229. package/templates/handlebars/antigravity.hbs +377 -0
  230. package/templates/handlebars/claude.hbs +183 -0
  231. package/templates/handlebars/cline.hbs +62 -0
  232. package/templates/handlebars/continue-config.hbs +116 -0
  233. package/templates/handlebars/copilot.hbs +130 -0
  234. package/templates/handlebars/partials/gotcha-list.hbs +11 -0
  235. package/templates/handlebars/partials/header.hbs +3 -0
  236. package/templates/handlebars/partials/workflow-summary.hbs +16 -0
  237. package/templates/handlebars/windsurf-rules.hbs +69 -0
  238. package/templates/hooks/post-commit.hbs +28 -0
  239. package/templates/hooks/pre-commit.hbs +46 -0
@@ -0,0 +1,260 @@
1
+ # .claude Configuration - {{PROJECT_NAME}}
2
+
3
+ This directory contains a comprehensive context engineering system for the {{PROJECT_NAME}} repository.
4
+
5
+ **Configuration Summary**:
6
+ - **Agents**: {{AGENTS_COUNT}} specialized agents (workflow-aligned)
7
+ - **Commands**: {{COMMANDS_COUNT}} custom commands
8
+ - **Workflows**: {{WORKFLOWS_COUNT}} documented workflows
9
+ - **Context Budget**: 200k tokens max, target <40% utilization
10
+ - **Output Budget**: 30k tokens max per response
11
+ - **Last Updated**: {{DATE}}
12
+
13
+ **System Benefits**:
14
+ - <40% context utilization (vs 60%+ without this system)
15
+ - 10× faster issue resolution with pre-computed knowledge
16
+ - Self-maintaining documentation (zero drift)
17
+ - Proactive bug discovery through validation
18
+
19
+ ---
20
+
21
+ ## Table of Contents
22
+
23
+ 1. [Agent Architecture](#agent-architecture)
24
+ 2. [Custom Commands](#custom-commands)
25
+ 3. [Context Documentation](#context-documentation)
26
+ 4. [RPI Workflow](#rpi-workflow)
27
+ 5. [Quick Start Guide](#quick-start-guide)
28
+ 6. [Self-Maintaining Documentation](#self-maintaining-documentation)
29
+
30
+ ---
31
+
32
+ ## Agent Architecture
33
+
34
+ ### Specialized Agents (Workflow-Aligned)
35
+
36
+ | Agent | Primary Workflows | Use For |
37
+ |-------|------------------|---------|
38
+ | `context-engineer` | INITIALIZATION | Transform this template for any codebase |
39
+ | {{AGENT_TABLE_ROWS}} |
40
+
41
+ **Agent Location:** `.ai-context/agents/*.md`
42
+
43
+ ---
44
+
45
+ ## Custom Commands
46
+
47
+ ### RPI Workflow Commands (3)
48
+ | Command | Description |
49
+ |---------|-------------|
50
+ | `/rpi-research` | Research phase - codebase exploration |
51
+ | `/rpi-plan` | Plan phase - implementation blueprint |
52
+ | `/rpi-implement` | Implement phase - execution with doc updates |
53
+
54
+ ### Validation Commands
55
+ | Command | Description |
56
+ |---------|-------------|
57
+ | `/validate-all` | Complete validation suite |
58
+ | `/verify-docs-current` | Documentation freshness validation |
59
+
60
+ ### System Commands (NEW in v1.1)
61
+ | Command | Description |
62
+ |---------|-------------|
63
+ | `/context-optimize` | Generate RPI TODO list with interactive scoping |
64
+ | `/help` | Comprehensive help system |
65
+ | `/collab` | Team collaboration (handoffs, sync) |
66
+ | `/analytics` | Local usage statistics |
67
+ | `/session-save` | Save current Claude Code session state |
68
+ | `/session-resume` | Restore previously saved session |
69
+
70
+ **Command Location:** `.ai-context/commands/*.md`
71
+
72
+ ---
73
+
74
+ ## Context Documentation
75
+
76
+ ### 3-Level Chain-of-Index Architecture
77
+
78
+ **Purpose:** Minimize context usage through progressive loading
79
+
80
+ **Level 1 - Category Indexes (5 files in `indexes/`):**
81
+ | Category | Purpose | Load When |
82
+ |----------|---------|-----------|
83
+ | `workflows/CATEGORY_INDEX.md` | Workflow categories | Starting workflow task |
84
+ | `code/CATEGORY_INDEX.md` | Domain × Layer overview | Finding code files |
85
+ | `search/CATEGORY_INDEX.md` | Search strategies | Low-level debugging |
86
+ | `agents/CATEGORY_INDEX.md` | Agent selection matrix | Choosing agent |
87
+ | `routing/CATEGORY_INDEX.md` | Task routing | Classifying task type |
88
+
89
+ **Level 2 - Domain Indexes:** See `indexes/workflows/*.md`, `indexes/code/*.md`
90
+
91
+ **Level 3 - Detail Files:** workflows/, agents/, commands/
92
+
93
+ ### Pre-Computed Knowledge
94
+
95
+ | File | Purpose |
96
+ |------|---------|
97
+ | `ARCHITECTURE_SNAPSHOT.md` | High-level system map |
98
+ | `FILE_OWNERSHIP.md` | What each file does |
99
+ | `INTEGRATION_POINTS.md` | External APIs |
100
+ | `KNOWN_GOTCHAS.md` | Documented fixes and lessons |
101
+ | `TESTING_MAP.md` | Test coverage mapping |
102
+
103
+ ---
104
+
105
+ ## RPI Workflow
106
+
107
+ **Research-Plan-Implement** methodology for structured development.
108
+
109
+ ### Phases
110
+
111
+ 1. **RESEARCH** (`/rpi-research`)
112
+ - Use sub-agents to investigate
113
+ - Output: Research document in `research/active/`
114
+ - Context budget: 25-30%
115
+
116
+ 2. **PLAN** (`/rpi-plan`)
117
+ - Create implementation blueprint with file:line precision
118
+ - Output: Plan document in `plans/active/`
119
+ - Context budget: 20-25%
120
+
121
+ 3. **IMPLEMENT** (`/rpi-implement`)
122
+ - Execute with atomic changes
123
+ - ONE CHANGE → ONE TEST → ONE COMMIT
124
+ - Update documentation (mandatory)
125
+ - Context budget: 30-40%
126
+
127
+ ### Directory Structure
128
+
129
+ ```
130
+ .ai-context/
131
+ ├── research/
132
+ │ ├── active/ # Current research
133
+ │ ├── completed/ # Archived research
134
+ │ └── RESEARCH_TEMPLATE.md
135
+ ├── plans/
136
+ │ ├── active/ # Current plans
137
+ │ ├── completed/ # Archived plans
138
+ │ └── PLAN_TEMPLATE.md
139
+ ├── context/
140
+ │ ├── WORKFLOW_INDEX.md # Primary entry point
141
+ │ ├── CODE_TO_WORKFLOW_MAP.md
142
+ │ └── workflows/ # Workflow detail files
143
+ ├── indexes/
144
+ │ ├── workflows/ # Workflow category indexes
145
+ │ ├── code/ # Code domain indexes
146
+ │ ├── agents/ # Agent selection indexes
147
+ │ ├── routing/ # Task routing indexes
148
+ │ └── search/ # Search pattern indexes
149
+ ├── agents/ # Specialized agent definitions
150
+ ├── commands/ # Custom command definitions
151
+ ├── tools/ # CLI tooling (NEW v1.1)
152
+ ├── schemas/ # JSON validation schemas (NEW v1.1)
153
+ ├── config/ # Environment configurations (NEW v1.1)
154
+ ├── team/ # Team collaboration config (NEW v1.1)
155
+ ├── knowledge/ # Shared knowledge base (NEW v1.1)
156
+ ├── standards/ # Community standards (NEW v1.1)
157
+ └── ci-templates/ # CI/CD workflow templates (NEW v1.1)
158
+ ```
159
+
160
+ ---
161
+
162
+ ## Quick Start Guide
163
+
164
+ ### 1. Session Initialization
165
+ ```bash
166
+ # Load workflow index (~15k tokens)
167
+ Read: .ai-context/context/WORKFLOW_INDEX.md
168
+
169
+ # Load specific workflows as needed (~20-50k each)
170
+ Read: .ai-context/context/workflows/[relevant_workflow].md
171
+ ```
172
+
173
+ ### 2. Debugging an Issue
174
+ ```
175
+ 1. Scan WORKFLOW_INDEX.md → Find relevant workflow
176
+ 2. Load workflow file → Get file:line references
177
+ 3. Fix issue with complete context
178
+ 4. Update documentation (CODE_TO_WORKFLOW_MAP guides)
179
+ 5. Run /verify-docs-current
180
+ ```
181
+
182
+ ### 3. Implementing a Feature
183
+ ```
184
+ 1. Run /rpi-research → Explore codebase
185
+ 2. Run /rpi-plan → Create implementation blueprint
186
+ 3. Run /rpi-implement → Execute with doc updates
187
+ ```
188
+
189
+ ---
190
+
191
+ ## Self-Maintaining Documentation
192
+
193
+ ### Automatic Documentation Updates
194
+
195
+ After every code change, update documentation:
196
+
197
+ 1. Check `CODE_TO_WORKFLOW_MAP.md` for affected workflows
198
+ 2. Update workflow files with new line numbers
199
+ 3. Verify function signatures match code
200
+ 4. Update diagrams if state machine changed
201
+ 5. Run `/verify-docs-current` for validation
202
+ 6. Commit documentation updates with code changes
203
+
204
+ ### Post-Implementation Checklist (Embedded in All Agents)
205
+
206
+ ```markdown
207
+ ## Post-Implementation Checklist
208
+
209
+ **MANDATORY:** After making ANY code changes, update documentation.
210
+
211
+ 1. Check CODE_TO_WORKFLOW_MAP.md for affected workflows
212
+ 2. Update workflows with new line numbers
213
+ 3. Verify function signatures match
214
+ 4. Run /verify-docs-current
215
+ 5. Commit doc updates with code changes
216
+ ```
217
+
218
+ ---
219
+
220
+ ## Context Budget Limits
221
+
222
+ **Hard Caps (Non-Negotiable):**
223
+ - **Maximum Context:** 200,000 tokens
224
+ - **Maximum Output:** 30,000 tokens per response
225
+ - **Target Utilization:** <40% (80,000 tokens)
226
+ - **Compaction Trigger:** 35% (70,000 tokens)
227
+
228
+ **Budget Allocation:**
229
+ ```
230
+ Workflow Indexes: ~15k tokens (7.5%)
231
+ Workflow Details: ~40k tokens (20%)
232
+ Active Code: ~30k tokens (15%)
233
+ Tool Results: ~15k tokens (7.5%)
234
+ ─────────────────────────────────────────
235
+ Typical Session: ~100k tokens (50%)
236
+ Buffer: ~100k tokens (50%)
237
+ ```
238
+
239
+ ---
240
+
241
+ ## Initialization
242
+
243
+ To transform this template for your codebase, use:
244
+
245
+ ```bash
246
+ @context-engineer "Initialize context engineering for this repository"
247
+ ```
248
+
249
+ This agent will:
250
+ 1. Analyze your codebase structure
251
+ 2. Identify major workflows (8-15)
252
+ 3. Create workflow documentation
253
+ 4. Set up index hierarchy
254
+ 5. Configure specialized agents
255
+ 6. Validate the system
256
+
257
+ ---
258
+
259
+ *Configuration updated: {{DATE}}*
260
+ *Version: 1.2.0 (Template)*
@@ -0,0 +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
+ **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
@@ -0,0 +1,76 @@
1
+ ---
2
+ name: api-developer
3
+ version: "1.0.0"
4
+ displayName: "API Developer"
5
+ description: "API design, contract definition, and endpoint implementation specialist"
6
+ category: "api"
7
+ complexity: "medium"
8
+ context_budget: "~35K tokens"
9
+ capabilities:
10
+ - "rest-api-design"
11
+ - "graphql-design"
12
+ - "contract-definition"
13
+ - "endpoint-documentation"
14
+ - "api-testing-strategy"
15
+ workflows:
16
+ - "api-endpoints"
17
+ - "contracts"
18
+ - "versioning"
19
+ commands: ["/rpi-research", "/rpi-plan", "/rpi-implement"]
20
+ dependencies:
21
+ agents: []
22
+ commands: []
23
+ hooks:
24
+ pre_invoke: null
25
+ post_invoke: "verify-docs-current"
26
+ examples:
27
+ - invocation: '@api-developer "Document API endpoints for [resource]"'
28
+ description: "Create comprehensive API documentation"
29
+ - invocation: '@api-developer "Validate API contracts"'
30
+ description: "Check contract consistency and completeness"
31
+ - invocation: '@api-developer "Generate OpenAPI spec"'
32
+ description: "Create OpenAPI/Swagger specification"
33
+ ---
34
+
35
+ # API Developer Agent
36
+
37
+ **Purpose:** API design, contract definition, and endpoint implementation
38
+
39
+ ## Capabilities
40
+
41
+ This agent specializes in:
42
+ - **API design** - Creating RESTful and GraphQL APIs with proper conventions
43
+ - **Contract definition** - Defining request/response schemas and validation rules
44
+ - **Endpoint implementation** - Generating boilerplate for API endpoints
45
+ - **Documentation generation** - Creating comprehensive API documentation
46
+ - **Testing strategy** - Planning and implementing API tests
47
+
48
+ ## Usage
49
+
50
+ After template initialization, this agent will be generated based on your API structure. It will:
51
+ 1. Analyze your existing API endpoints
52
+ 2. Create comprehensive API documentation
53
+ 3. Identify potential security vulnerabilities
54
+ 4. Provide recommendations for API optimization
55
+
56
+ ## Example Commands
57
+
58
+ ```bash
59
+ @api-developer "Document API endpoints for [resource]"
60
+ @api-developer "Validate API contracts for [endpoint]"
61
+ @api-developer "Generate test cases for [API]"
62
+ ```
63
+
64
+ ## Integration Points
65
+
66
+ This agent integrates with:
67
+ - Workflow documentation
68
+ - Database schema (for data endpoints)
69
+ - Testing strategies
70
+ - Security validation
71
+
72
+ ## Validation
73
+
74
+ - API contract consistency
75
+ - Endpoint security checks
76
+ - Response schema validation