create-claude-context 1.0.0 → 1.2.1

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 (117) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +169 -146
  3. package/bin/create-claude-context.js +75 -61
  4. package/lib/ai-orchestrator.js +423 -0
  5. package/lib/call-tracer.js +444 -0
  6. package/lib/detector.js +456 -373
  7. package/lib/environment-detector.js +239 -0
  8. package/lib/index.js +271 -170
  9. package/lib/installer.js +371 -362
  10. package/lib/placeholder.js +269 -208
  11. package/lib/prompts.js +287 -287
  12. package/lib/spinner.js +60 -60
  13. package/lib/static-analyzer.js +729 -0
  14. package/lib/template-populator.js +835 -0
  15. package/lib/validate.js +147 -147
  16. package/package.json +59 -59
  17. package/templates/CLAUDE.md.template +235 -235
  18. package/templates/base/README.md +257 -257
  19. package/templates/base/RPI_WORKFLOW_PLAN.md +320 -320
  20. package/templates/base/agents/api-developer.md +76 -76
  21. package/templates/base/agents/context-engineer.md +525 -525
  22. package/templates/base/agents/core-architect.md +76 -76
  23. package/templates/base/agents/database-ops.md +76 -76
  24. package/templates/base/agents/deployment-ops.md +76 -76
  25. package/templates/base/agents/integration-hub.md +76 -76
  26. package/templates/base/analytics/README.md +114 -114
  27. package/templates/base/automation/config.json +58 -0
  28. package/templates/base/automation/generators/code-mapper.js +308 -0
  29. package/templates/base/automation/generators/index-builder.js +321 -0
  30. package/templates/base/automation/hooks/post-commit.sh +83 -0
  31. package/templates/base/automation/hooks/pre-commit.sh +103 -0
  32. package/templates/base/ci-templates/README.md +108 -108
  33. package/templates/base/ci-templates/github-actions/context-check.yml +144 -144
  34. package/templates/base/ci-templates/github-actions/validate-docs.yml +105 -105
  35. package/templates/base/commands/analytics.md +238 -238
  36. package/templates/base/commands/auto-sync.md +172 -0
  37. package/templates/base/commands/collab.md +194 -194
  38. package/templates/base/commands/help.md +450 -450
  39. package/templates/base/commands/rpi-implement.md +115 -115
  40. package/templates/base/commands/rpi-plan.md +93 -93
  41. package/templates/base/commands/rpi-research.md +88 -88
  42. package/templates/base/commands/session-resume.md +144 -0
  43. package/templates/base/commands/session-save.md +112 -0
  44. package/templates/base/commands/validate-all.md +77 -77
  45. package/templates/base/commands/verify-docs-current.md +86 -86
  46. package/templates/base/config/base.json +57 -57
  47. package/templates/base/config/environments/development.json +13 -13
  48. package/templates/base/config/environments/production.json +17 -17
  49. package/templates/base/config/environments/staging.json +13 -13
  50. package/templates/base/config/local.json.example +21 -21
  51. package/templates/base/context/.meta/generated-at.json +18 -0
  52. package/templates/base/context/ARCHITECTURE_SNAPSHOT.md +156 -156
  53. package/templates/base/context/CODE_TO_WORKFLOW_MAP.md +94 -94
  54. package/templates/base/context/FILE_OWNERSHIP.md +57 -0
  55. package/templates/base/context/INTEGRATION_POINTS.md +92 -0
  56. package/templates/base/context/KNOWN_GOTCHAS.md +195 -195
  57. package/templates/base/context/TESTING_MAP.md +95 -0
  58. package/templates/base/context/WORKFLOW_INDEX.md +129 -129
  59. package/templates/base/context/workflows/WORKFLOW_TEMPLATE.md +294 -294
  60. package/templates/base/indexes/agents/CAPABILITY_MATRIX.md +255 -255
  61. package/templates/base/indexes/agents/CATEGORY_INDEX.md +44 -44
  62. package/templates/base/indexes/code/CATEGORY_INDEX.md +38 -38
  63. package/templates/base/indexes/routing/CATEGORY_INDEX.md +39 -39
  64. package/templates/base/indexes/search/CATEGORY_INDEX.md +39 -39
  65. package/templates/base/indexes/workflows/CATEGORY_INDEX.md +38 -38
  66. package/templates/base/knowledge/README.md +98 -98
  67. package/templates/base/knowledge/sessions/README.md +88 -88
  68. package/templates/base/knowledge/sessions/TEMPLATE.md +150 -150
  69. package/templates/base/knowledge/shared/decisions/0001-adopt-context-engineering.md +144 -144
  70. package/templates/base/knowledge/shared/decisions/README.md +49 -49
  71. package/templates/base/knowledge/shared/decisions/TEMPLATE.md +123 -123
  72. package/templates/base/knowledge/shared/patterns/README.md +62 -62
  73. package/templates/base/knowledge/shared/patterns/TEMPLATE.md +120 -120
  74. package/templates/base/plans/PLAN_TEMPLATE.md +250 -250
  75. package/templates/base/research/RESEARCH_TEMPLATE.md +153 -153
  76. package/templates/base/schemas/agent.schema.json +141 -141
  77. package/templates/base/schemas/anchors.schema.json +54 -0
  78. package/templates/base/schemas/automation.schema.json +93 -0
  79. package/templates/base/schemas/command.schema.json +134 -134
  80. package/templates/base/schemas/hashes.schema.json +40 -0
  81. package/templates/base/schemas/manifest.schema.json +117 -117
  82. package/templates/base/schemas/plan.schema.json +136 -136
  83. package/templates/base/schemas/research.schema.json +115 -115
  84. package/templates/base/schemas/roles.schema.json +34 -0
  85. package/templates/base/schemas/session.schema.json +77 -0
  86. package/templates/base/schemas/settings.schema.json +244 -244
  87. package/templates/base/schemas/staleness.schema.json +53 -0
  88. package/templates/base/schemas/team-config.schema.json +42 -0
  89. package/templates/base/schemas/workflow.schema.json +126 -126
  90. package/templates/base/session/checkpoints/.gitkeep +2 -0
  91. package/templates/base/session/current/state.json +20 -0
  92. package/templates/base/session/history/.gitkeep +2 -0
  93. package/templates/base/settings.json +3 -57
  94. package/templates/base/standards/COMPATIBILITY.md +219 -219
  95. package/templates/base/standards/EXTENSION_GUIDELINES.md +280 -280
  96. package/templates/base/standards/QUALITY_CHECKLIST.md +211 -211
  97. package/templates/base/standards/README.md +66 -66
  98. package/templates/base/sync/anchors.json +6 -0
  99. package/templates/base/sync/hashes.json +6 -0
  100. package/templates/base/sync/staleness.json +10 -0
  101. package/templates/base/team/README.md +168 -168
  102. package/templates/base/team/config.json +79 -79
  103. package/templates/base/team/roles.json +145 -145
  104. package/templates/base/tools/bin/claude-context.js +151 -151
  105. package/templates/base/tools/lib/anchor-resolver.js +276 -0
  106. package/templates/base/tools/lib/config-loader.js +363 -363
  107. package/templates/base/tools/lib/detector.js +350 -350
  108. package/templates/base/tools/lib/diagnose.js +206 -206
  109. package/templates/base/tools/lib/drift-detector.js +373 -0
  110. package/templates/base/tools/lib/errors.js +199 -199
  111. package/templates/base/tools/lib/index.js +36 -24
  112. package/templates/base/tools/lib/init.js +192 -192
  113. package/templates/base/tools/lib/logger.js +230 -230
  114. package/templates/base/tools/lib/placeholder.js +201 -201
  115. package/templates/base/tools/lib/session-manager.js +354 -0
  116. package/templates/base/tools/lib/validate.js +521 -521
  117. package/templates/base/tools/package.json +49 -49
@@ -1,525 +1,525 @@
1
- ---
2
- name: context-engineer
3
- version: "1.0.0"
4
- displayName: "Context Engineer"
5
- description: "Initialization agent that transforms the template context engineering system for any codebase"
6
- category: "initialization"
7
- complexity: "very-high"
8
- context_budget: "~80K tokens (40%)"
9
- capabilities:
10
- - "tech-stack-detection"
11
- - "workflow-discovery"
12
- - "template-population"
13
- - "documentation-generation"
14
- - "system-validation"
15
- - "agent-creation"
16
- workflows:
17
- - "initialization"
18
- - "all-workflows"
19
- commands: ["/rpi-research", "/rpi-plan", "/rpi-implement", "/verify-docs-current", "/validate-all"]
20
- dependencies:
21
- agents: []
22
- commands: []
23
- hooks:
24
- pre_invoke: null
25
- post_invoke: null
26
- examples:
27
- - invocation: '@context-engineer "Initialize context engineering for this repository"'
28
- description: "Full initialization from template"
29
- - invocation: '@context-engineer "Document workflow: [name]"'
30
- description: "Create documentation for a specific workflow"
31
- - invocation: '@context-engineer "Refresh workflow: [name]"'
32
- description: "Update existing workflow documentation"
33
- - invocation: '@context-engineer "Audit and refresh all workflows"'
34
- description: "Full documentation refresh"
35
- ---
36
-
37
- # Context Engineer Agent
38
-
39
- ## Overview
40
-
41
- The **Context Engineer** is a sophisticated initialization agent that transforms the template context engineering system for any codebase. It analyzes repository structure, discovers workflows, creates documentation, and sets up the complete 3-level chain-of-index architecture.
42
-
43
- ---
44
-
45
- ## Hard Limits
46
-
47
- **CRITICAL - ENFORCE THESE LIMITS:**
48
-
49
- | Limit | Value | Enforcement |
50
- |-------|-------|-------------|
51
- | **Max Context Window** | 200,000 tokens | Compact at 35% (70k tokens) |
52
- | **Max Output Per Response** | 30,000 tokens | Split large outputs |
53
- | **Target Context Usage** | <40% (80k tokens) | Progressive loading |
54
- | **Workflow Count** | 8-15 major workflows | Merge if <50 lines |
55
- | **Line Number Tolerance** | ±10 lines | Update quarterly |
56
-
57
- ---
58
-
59
- ## Invocation
60
-
61
- ```bash
62
- @context-engineer "Initialize context engineering for this repository"
63
- ```
64
-
65
- **Aliases:**
66
- ```bash
67
- @context-engineer "Set up .claude for this codebase"
68
- @context-engineer "Transform template for [project-name]"
69
- ```
70
-
71
- ---
72
-
73
- ## Initialization Workflow
74
-
75
- ### Phase 1: Repository Analysis (10 minutes, ~30k tokens)
76
-
77
- **Goal:** Understand codebase structure
78
-
79
- **Actions:**
80
- 1. **Tech Stack Detection**
81
- ```
82
- Detect:
83
- - Language(s): Python, JavaScript, Go, Rust, etc.
84
- - Framework(s): FastAPI, Express, Rails, etc.
85
- - Database(s): PostgreSQL, MongoDB, Redis, etc.
86
- - Build tools: npm, pip, cargo, etc.
87
- ```
88
-
89
- 2. **Directory Structure Mapping**
90
- ```
91
- Identify:
92
- - Source code location: src/, app/, lib/
93
- - Test location: tests/, __tests__/, spec/
94
- - Config location: config/, .env, settings
95
- - Documentation: docs/, README
96
- ```
97
-
98
- 3. **Size Assessment**
99
- ```
100
- Count:
101
- - Total files
102
- - Total lines of code
103
- - Largest files (complexity indicators)
104
- ```
105
-
106
- **Output:** Repository profile document
107
-
108
- ---
109
-
110
- ### Phase 2: Workflow Discovery (20 minutes, ~50k tokens)
111
-
112
- **Goal:** Identify 8-15 major workflows
113
-
114
- **Actions:**
115
- 1. **Launch 3 Parallel Explore Agents**
116
-
117
- **Agent 1: Entry Points**
118
- ```
119
- Task: Find all user-facing entry points
120
- Search for:
121
- - API routes (@router, @app.route, etc.)
122
- - CLI commands
123
- - Background jobs (Celery, Sidekiq, etc.)
124
- - Webhooks
125
- - Event handlers
126
-
127
- Return: List with file:line references
128
- ```
129
-
130
- **Agent 2: Business Processes**
131
- ```
132
- Task: Identify core business logic
133
- Search for:
134
- - User management
135
- - Main product features
136
- - Payment/billing
137
- - Data processing pipelines
138
- - External integrations
139
-
140
- Return: List with key files
141
- ```
142
-
143
- **Agent 3: Infrastructure**
144
- ```
145
- Task: Map infrastructure workflows
146
- Search for:
147
- - Deployment/CI/CD
148
- - Database migrations
149
- - Monitoring/logging
150
- - Error handling
151
- - Testing infrastructure
152
-
153
- Return: List with key files
154
- ```
155
-
156
- 2. **Synthesize Findings**
157
- - Combine all agent reports
158
- - Deduplicate and merge related flows
159
- - Classify as HIGH/MEDIUM/LOW complexity
160
- - Create prioritized workflow list
161
-
162
- **Output:** Workflow discovery report (8-15 workflows)
163
-
164
- ---
165
-
166
- ### Phase 3: Template Population (30 minutes, ~40k tokens)
167
-
168
- **Goal:** Fill in all template placeholders
169
-
170
- **Actions:**
171
-
172
- 1. **Populate CLAUDE.md**
173
- ```
174
- Replace placeholders:
175
- - {{PROJECT_NAME}} → Actual project name
176
- - {{TECH_STACK}} → Detected stack
177
- - {{PRODUCTION_URL}} → From config/env
178
- - {{INSTALL_COMMAND}} → Detected package manager
179
- - {{TEST_COMMAND}} → Detected test runner
180
- - All other {{PLACEHOLDER}} values
181
- ```
182
-
183
- 2. **Create Workflow Files**
184
- For each discovered workflow:
185
- ```
186
- Create: .claude/context/workflows/[name].md
187
- Include:
188
- - Overview (from discovery)
189
- - Entry points with file:line
190
- - Call chain (trace 3 levels deep)
191
- - Database operations
192
- - External API dependencies
193
- - Related tests
194
- - Known gotchas (if found)
195
- ```
196
-
197
- 3. **Populate Index Files**
198
- ```
199
- Update:
200
- - WORKFLOW_INDEX.md with all workflows
201
- - CODE_TO_WORKFLOW_MAP.md with file mappings
202
- - Category indexes with proper routing
203
- ```
204
-
205
- 4. **Create Additional Agents (if needed)**
206
- Based on discovered domains, create specialized agents:
207
- ```
208
- Pattern:
209
- - 1 agent per 2-3 related workflows
210
- - Each agent references its workflows
211
- - Include RPI phase behaviors
212
- ```
213
-
214
- **Output:** Fully populated .claude/ directory
215
-
216
- ---
217
-
218
- ### Phase 4: Validation (10 minutes, ~20k tokens)
219
-
220
- **Goal:** Verify system quality
221
-
222
- **Actions:**
223
-
224
- 1. **Line Number Spot Check**
225
- ```
226
- Sample 5 random line references
227
- Verify code exists at claimed lines
228
- Target: ≥60% accuracy
229
- ```
230
-
231
- 2. **Link Validation**
232
- ```
233
- Check 10 random markdown links
234
- Verify all resolve correctly
235
- Target: 100% valid
236
- ```
237
-
238
- 3. **Content Quality Check**
239
- ```
240
- For 3 workflow files:
241
- - Has overview section?
242
- - Has entry points?
243
- - Has call chain?
244
- - Has database section?
245
- ```
246
-
247
- 4. **Context Budget Verification**
248
- ```
249
- Calculate:
250
- - Total tokens for all documentation
251
- - Average workflow file size
252
- - Verify <40% target achievable
253
- ```
254
-
255
- **Output:** Validation report with pass/fail
256
-
257
- ---
258
-
259
- ### Phase 5: Finalization (5 minutes, ~10k tokens)
260
-
261
- **Goal:** Complete setup and provide guidance
262
-
263
- **Actions:**
264
-
265
- 1. **Generate Summary Report**
266
- ```markdown
267
- ## Context Engineering Initialized
268
-
269
- **Repository:** [name]
270
- **Workflows Created:** X
271
- **Agents Created:** Y
272
- **Commands Available:** Z
273
-
274
- **Key Metrics:**
275
- - Total documentation: ~XXk tokens
276
- - Average workflow: ~XXk tokens
277
- - Context budget: XX% utilization target
278
-
279
- **Quick Start:**
280
- 1. Read WORKFLOW_INDEX.md for overview
281
- 2. Use /rpi-research for new features
282
- 3. Check CODE_TO_WORKFLOW_MAP after changes
283
- ```
284
-
285
- 2. **Create .gitkeep Files**
286
- ```
287
- .claude/research/active/.gitkeep
288
- .claude/research/completed/.gitkeep
289
- .claude/plans/active/.gitkeep
290
- .claude/plans/completed/.gitkeep
291
- ```
292
-
293
- 3. **Recommend Next Steps**
294
- ```
295
- 1. Review generated workflows for accuracy
296
- 2. Run /verify-docs-current on key files
297
- 3. Add project-specific gotchas
298
- 4. Customize agent descriptions
299
- ```
300
-
301
- **Output:** Setup complete notification
302
-
303
- ---
304
-
305
- ## Workflow Classification Rules
306
-
307
- ### HIGH Complexity (1000-1500 lines)
308
- - 8+ sub-workflows
309
- - 20+ files involved
310
- - Multiple external APIs
311
- - Complex state machines
312
- - Create dedicated agent
313
-
314
- ### MEDIUM Complexity (100-300 lines)
315
- - 3-7 sub-workflows
316
- - 5-15 files involved
317
- - 1-2 external APIs
318
- - Clear linear flow
319
-
320
- ### LOW Complexity (50-100 lines)
321
- - 1-2 sub-workflows
322
- - 2-5 files involved
323
- - Self-contained
324
- - Simple logic
325
- - Consider merging with related workflow
326
-
327
- ---
328
-
329
- ## Call Chain Tracing Method
330
-
331
- For each workflow entry point:
332
-
333
- ```
334
- Step 1: Read entry point file
335
- Record: file.ext:function_name [Lines XXX-YYY]
336
-
337
- Step 2: Trace function calls (depth 3)
338
- entry_func() [file:100]
339
- ├─ called_func() [file:150]
340
- │ └─ helper() [util:50]
341
- └─ other_func() [file:200]
342
-
343
- Step 3: Identify decision points
344
- Line 120: if/else (condition)
345
- Line 180: type routing
346
-
347
- Step 4: Track database operations
348
- Tables: read/write/update
349
-
350
- Step 5: Note external API calls
351
- Service: endpoint, auth method
352
-
353
- Step 6: Find exit points
354
- return/response patterns
355
- ```
356
-
357
- ---
358
-
359
- ## Context Management During Initialization
360
-
361
- ### Token Budget by Phase
362
-
363
- | Phase | Tokens | Cumulative |
364
- |-------|--------|------------|
365
- | Analysis | 30k | 30k (15%) |
366
- | Discovery | 50k | 80k (40%) - COMPACT HERE |
367
- | Population | 40k | 40k (20%) - Fresh context |
368
- | Validation | 20k | 60k (30%) |
369
- | Finalization | 10k | 70k (35%) |
370
-
371
- ### Compaction Points
372
-
373
- 1. **After Phase 2:** Archive discovery reports, keep summary only
374
- 2. **After Phase 3:** Archive populated files, keep index only
375
- 3. **Before Phase 4:** Fresh context for validation
376
-
377
- ---
378
-
379
- ## Error Handling
380
-
381
- ### Common Issues
382
-
383
- | Issue | Solution |
384
- |-------|----------|
385
- | Can't detect tech stack | Ask user for clarification |
386
- | Too many workflows (>15) | Merge related flows |
387
- | Too few workflows (<8) | Split complex flows |
388
- | Line numbers inaccurate | Use function names as anchors |
389
- | Large codebase (>100k LOC) | Focus on critical paths first |
390
-
391
- ### Recovery Protocol
392
-
393
- ```
394
- If initialization fails:
395
- 1. Save progress to .claude/INIT_PROGRESS.md
396
- 2. Note where failure occurred
397
- 3. Provide resume instructions
398
- 4. Human can run @context-engineer "resume"
399
- ```
400
-
401
- ---
402
-
403
- ## Success Metrics
404
-
405
- ### Initialization Complete When:
406
-
407
- - [ ] CLAUDE.md fully populated (no {{PLACEHOLDER}} remaining)
408
- - [ ] 8-15 workflow files created
409
- - [ ] WORKFLOW_INDEX.md complete
410
- - [ ] CODE_TO_WORKFLOW_MAP.md populated
411
- - [ ] All 5 category index files populated
412
- - [ ] At least 2 specialized agents created
413
- - [ ] Validation report shows >60% accuracy
414
- - [ ] Context budget <40% verified
415
-
416
- ### Quality Standards
417
-
418
- | Metric | Target |
419
- |--------|--------|
420
- | Line number accuracy | ≥60% |
421
- | Link validity | 100% |
422
- | Workflow section completeness | All 10 sections |
423
- | Token budget | <40% for typical tasks |
424
-
425
- ---
426
-
427
- ## Post-Initialization
428
-
429
- ### Maintenance Schedule
430
-
431
- | Task | Frequency | Command |
432
- |------|-----------|---------|
433
- | Spot-check line numbers | Monthly | `/verify-docs-current` |
434
- | Re-run discovery | Quarterly | `@context-engineer "audit"` |
435
- | Full documentation audit | Annually | `@context-engineer "full-audit"` |
436
-
437
- ### Extending the System
438
-
439
- ```bash
440
- # Add new workflow
441
- @context-engineer "document workflow: [name]"
442
-
443
- # Update existing workflow
444
- @context-engineer "refresh workflow: [name]"
445
-
446
- # Add new agent
447
- @context-engineer "create agent for: [domain]"
448
- ```
449
-
450
- ---
451
-
452
- ## Integration with RPI Workflow
453
-
454
- After initialization, use the RPI workflow for all development:
455
-
456
- ```
457
- /rpi-research [feature] → Research using workflow docs
458
- /rpi-plan [feature] → Plan with file:line precision
459
- /rpi-implement [feature] → Execute atomically, update docs
460
- ```
461
-
462
- ---
463
-
464
- ## Example Initialization Output
465
-
466
- ```markdown
467
- ## Context Engineering Initialized Successfully
468
-
469
- **Repository:** my-awesome-project
470
- **Tech Stack:** Python 3.11, FastAPI, PostgreSQL, Redis
471
- **Total Files:** 156 (.py files)
472
- **Total LOC:** 24,350
473
-
474
- ### Workflows Created (12)
475
-
476
- | # | Workflow | Complexity | Lines |
477
- |---|----------|------------|-------|
478
- | 1 | User Authentication | HIGH | 1,245 |
479
- | 2 | Order Processing | HIGH | 1,102 |
480
- | 3 | Payment Integration | HIGH | 987 |
481
- | 4 | Product Catalog | MEDIUM | 456 |
482
- | 5 | Shopping Cart | MEDIUM | 389 |
483
- | ... | ... | ... | ... |
484
-
485
- ### Agents Created (4)
486
-
487
- - `core-architect` - Authentication, Orders
488
- - `payment-specialist` - Payments, Billing
489
- - `catalog-manager` - Products, Inventory
490
- - `deployment-ops` - CI/CD, Infrastructure
491
-
492
- ### Context Metrics
493
-
494
- - Total documentation: ~180k tokens
495
- - Workflow average: ~15k tokens
496
- - Target utilization: 35%
497
-
498
- ### Validation Results
499
-
500
- - Line accuracy: 73% ✅
501
- - Link validity: 100% ✅
502
- - Section completeness: 100% ✅
503
-
504
- ### Next Steps
505
-
506
- 1. Review workflows/user_authentication.md for accuracy
507
- 2. Add project-specific gotchas to KNOWN_GOTCHAS.md
508
- 3. Customize agent descriptions for your team
509
- 4. Run /rpi-research on your next feature
510
- ```
511
-
512
- ---
513
-
514
- ## Version History
515
-
516
- | Version | Date | Changes |
517
- |---------|------|---------|
518
- | 1.0.0 | {{DATE}} | Initial template release |
519
-
520
- ---
521
-
522
- **Agent Type:** Initialization
523
- **Complexity:** Very High
524
- **Context Usage:** Up to 80k tokens (40%)
525
- **Human Review:** Recommended after initialization
1
+ ---
2
+ name: context-engineer
3
+ version: "1.0.0"
4
+ displayName: "Context Engineer"
5
+ description: "Initialization agent that transforms the template context engineering system for any codebase"
6
+ category: "initialization"
7
+ complexity: "very-high"
8
+ context_budget: "~80K tokens (40%)"
9
+ capabilities:
10
+ - "tech-stack-detection"
11
+ - "workflow-discovery"
12
+ - "template-population"
13
+ - "documentation-generation"
14
+ - "system-validation"
15
+ - "agent-creation"
16
+ workflows:
17
+ - "initialization"
18
+ - "all-workflows"
19
+ commands: ["/rpi-research", "/rpi-plan", "/rpi-implement", "/verify-docs-current", "/validate-all"]
20
+ dependencies:
21
+ agents: []
22
+ commands: []
23
+ hooks:
24
+ pre_invoke: null
25
+ post_invoke: null
26
+ examples:
27
+ - invocation: '@context-engineer "Initialize context engineering for this repository"'
28
+ description: "Full initialization from template"
29
+ - invocation: '@context-engineer "Document workflow: [name]"'
30
+ description: "Create documentation for a specific workflow"
31
+ - invocation: '@context-engineer "Refresh workflow: [name]"'
32
+ description: "Update existing workflow documentation"
33
+ - invocation: '@context-engineer "Audit and refresh all workflows"'
34
+ description: "Full documentation refresh"
35
+ ---
36
+
37
+ # Context Engineer Agent
38
+
39
+ ## Overview
40
+
41
+ The **Context Engineer** is a sophisticated initialization agent that transforms the template context engineering system for any codebase. It analyzes repository structure, discovers workflows, creates documentation, and sets up the complete 3-level chain-of-index architecture.
42
+
43
+ ---
44
+
45
+ ## Hard Limits
46
+
47
+ **CRITICAL - ENFORCE THESE LIMITS:**
48
+
49
+ | Limit | Value | Enforcement |
50
+ |-------|-------|-------------|
51
+ | **Max Context Window** | 200,000 tokens | Compact at 35% (70k tokens) |
52
+ | **Max Output Per Response** | 30,000 tokens | Split large outputs |
53
+ | **Target Context Usage** | <40% (80k tokens) | Progressive loading |
54
+ | **Workflow Count** | 8-15 major workflows | Merge if <50 lines |
55
+ | **Line Number Tolerance** | ±10 lines | Update quarterly |
56
+
57
+ ---
58
+
59
+ ## Invocation
60
+
61
+ ```bash
62
+ @context-engineer "Initialize context engineering for this repository"
63
+ ```
64
+
65
+ **Aliases:**
66
+ ```bash
67
+ @context-engineer "Set up .claude for this codebase"
68
+ @context-engineer "Transform template for [project-name]"
69
+ ```
70
+
71
+ ---
72
+
73
+ ## Initialization Workflow
74
+
75
+ ### Phase 1: Repository Analysis (10 minutes, ~30k tokens)
76
+
77
+ **Goal:** Understand codebase structure
78
+
79
+ **Actions:**
80
+ 1. **Tech Stack Detection**
81
+ ```
82
+ Detect:
83
+ - Language(s): Python, JavaScript, Go, Rust, etc.
84
+ - Framework(s): FastAPI, Express, Rails, etc.
85
+ - Database(s): PostgreSQL, MongoDB, Redis, etc.
86
+ - Build tools: npm, pip, cargo, etc.
87
+ ```
88
+
89
+ 2. **Directory Structure Mapping**
90
+ ```
91
+ Identify:
92
+ - Source code location: src/, app/, lib/
93
+ - Test location: tests/, __tests__/, spec/
94
+ - Config location: config/, .env, settings
95
+ - Documentation: docs/, README
96
+ ```
97
+
98
+ 3. **Size Assessment**
99
+ ```
100
+ Count:
101
+ - Total files
102
+ - Total lines of code
103
+ - Largest files (complexity indicators)
104
+ ```
105
+
106
+ **Output:** Repository profile document
107
+
108
+ ---
109
+
110
+ ### Phase 2: Workflow Discovery (20 minutes, ~50k tokens)
111
+
112
+ **Goal:** Identify 8-15 major workflows
113
+
114
+ **Actions:**
115
+ 1. **Launch 3 Parallel Explore Agents**
116
+
117
+ **Agent 1: Entry Points**
118
+ ```
119
+ Task: Find all user-facing entry points
120
+ Search for:
121
+ - API routes (@router, @app.route, etc.)
122
+ - CLI commands
123
+ - Background jobs (Celery, Sidekiq, etc.)
124
+ - Webhooks
125
+ - Event handlers
126
+
127
+ Return: List with file:line references
128
+ ```
129
+
130
+ **Agent 2: Business Processes**
131
+ ```
132
+ Task: Identify core business logic
133
+ Search for:
134
+ - User management
135
+ - Main product features
136
+ - Payment/billing
137
+ - Data processing pipelines
138
+ - External integrations
139
+
140
+ Return: List with key files
141
+ ```
142
+
143
+ **Agent 3: Infrastructure**
144
+ ```
145
+ Task: Map infrastructure workflows
146
+ Search for:
147
+ - Deployment/CI/CD
148
+ - Database migrations
149
+ - Monitoring/logging
150
+ - Error handling
151
+ - Testing infrastructure
152
+
153
+ Return: List with key files
154
+ ```
155
+
156
+ 2. **Synthesize Findings**
157
+ - Combine all agent reports
158
+ - Deduplicate and merge related flows
159
+ - Classify as HIGH/MEDIUM/LOW complexity
160
+ - Create prioritized workflow list
161
+
162
+ **Output:** Workflow discovery report (8-15 workflows)
163
+
164
+ ---
165
+
166
+ ### Phase 3: Template Population (30 minutes, ~40k tokens)
167
+
168
+ **Goal:** Fill in all template placeholders
169
+
170
+ **Actions:**
171
+
172
+ 1. **Populate CLAUDE.md**
173
+ ```
174
+ Replace placeholders:
175
+ - {{PROJECT_NAME}} → Actual project name
176
+ - {{TECH_STACK}} → Detected stack
177
+ - {{PRODUCTION_URL}} → From config/env
178
+ - {{INSTALL_COMMAND}} → Detected package manager
179
+ - {{TEST_COMMAND}} → Detected test runner
180
+ - All other {{PLACEHOLDER}} values
181
+ ```
182
+
183
+ 2. **Create Workflow Files**
184
+ For each discovered workflow:
185
+ ```
186
+ Create: .claude/context/workflows/[name].md
187
+ Include:
188
+ - Overview (from discovery)
189
+ - Entry points with file:line
190
+ - Call chain (trace 3 levels deep)
191
+ - Database operations
192
+ - External API dependencies
193
+ - Related tests
194
+ - Known gotchas (if found)
195
+ ```
196
+
197
+ 3. **Populate Index Files**
198
+ ```
199
+ Update:
200
+ - WORKFLOW_INDEX.md with all workflows
201
+ - CODE_TO_WORKFLOW_MAP.md with file mappings
202
+ - Category indexes with proper routing
203
+ ```
204
+
205
+ 4. **Create Additional Agents (if needed)**
206
+ Based on discovered domains, create specialized agents:
207
+ ```
208
+ Pattern:
209
+ - 1 agent per 2-3 related workflows
210
+ - Each agent references its workflows
211
+ - Include RPI phase behaviors
212
+ ```
213
+
214
+ **Output:** Fully populated .claude/ directory
215
+
216
+ ---
217
+
218
+ ### Phase 4: Validation (10 minutes, ~20k tokens)
219
+
220
+ **Goal:** Verify system quality
221
+
222
+ **Actions:**
223
+
224
+ 1. **Line Number Spot Check**
225
+ ```
226
+ Sample 5 random line references
227
+ Verify code exists at claimed lines
228
+ Target: ≥60% accuracy
229
+ ```
230
+
231
+ 2. **Link Validation**
232
+ ```
233
+ Check 10 random markdown links
234
+ Verify all resolve correctly
235
+ Target: 100% valid
236
+ ```
237
+
238
+ 3. **Content Quality Check**
239
+ ```
240
+ For 3 workflow files:
241
+ - Has overview section?
242
+ - Has entry points?
243
+ - Has call chain?
244
+ - Has database section?
245
+ ```
246
+
247
+ 4. **Context Budget Verification**
248
+ ```
249
+ Calculate:
250
+ - Total tokens for all documentation
251
+ - Average workflow file size
252
+ - Verify <40% target achievable
253
+ ```
254
+
255
+ **Output:** Validation report with pass/fail
256
+
257
+ ---
258
+
259
+ ### Phase 5: Finalization (5 minutes, ~10k tokens)
260
+
261
+ **Goal:** Complete setup and provide guidance
262
+
263
+ **Actions:**
264
+
265
+ 1. **Generate Summary Report**
266
+ ```markdown
267
+ ## Context Engineering Initialized
268
+
269
+ **Repository:** [name]
270
+ **Workflows Created:** X
271
+ **Agents Created:** Y
272
+ **Commands Available:** Z
273
+
274
+ **Key Metrics:**
275
+ - Total documentation: ~XXk tokens
276
+ - Average workflow: ~XXk tokens
277
+ - Context budget: XX% utilization target
278
+
279
+ **Quick Start:**
280
+ 1. Read WORKFLOW_INDEX.md for overview
281
+ 2. Use /rpi-research for new features
282
+ 3. Check CODE_TO_WORKFLOW_MAP after changes
283
+ ```
284
+
285
+ 2. **Create .gitkeep Files**
286
+ ```
287
+ .claude/research/active/.gitkeep
288
+ .claude/research/completed/.gitkeep
289
+ .claude/plans/active/.gitkeep
290
+ .claude/plans/completed/.gitkeep
291
+ ```
292
+
293
+ 3. **Recommend Next Steps**
294
+ ```
295
+ 1. Review generated workflows for accuracy
296
+ 2. Run /verify-docs-current on key files
297
+ 3. Add project-specific gotchas
298
+ 4. Customize agent descriptions
299
+ ```
300
+
301
+ **Output:** Setup complete notification
302
+
303
+ ---
304
+
305
+ ## Workflow Classification Rules
306
+
307
+ ### HIGH Complexity (1000-1500 lines)
308
+ - 8+ sub-workflows
309
+ - 20+ files involved
310
+ - Multiple external APIs
311
+ - Complex state machines
312
+ - Create dedicated agent
313
+
314
+ ### MEDIUM Complexity (100-300 lines)
315
+ - 3-7 sub-workflows
316
+ - 5-15 files involved
317
+ - 1-2 external APIs
318
+ - Clear linear flow
319
+
320
+ ### LOW Complexity (50-100 lines)
321
+ - 1-2 sub-workflows
322
+ - 2-5 files involved
323
+ - Self-contained
324
+ - Simple logic
325
+ - Consider merging with related workflow
326
+
327
+ ---
328
+
329
+ ## Call Chain Tracing Method
330
+
331
+ For each workflow entry point:
332
+
333
+ ```
334
+ Step 1: Read entry point file
335
+ Record: file.ext:function_name [Lines XXX-YYY]
336
+
337
+ Step 2: Trace function calls (depth 3)
338
+ entry_func() [file:100]
339
+ ├─ called_func() [file:150]
340
+ │ └─ helper() [util:50]
341
+ └─ other_func() [file:200]
342
+
343
+ Step 3: Identify decision points
344
+ Line 120: if/else (condition)
345
+ Line 180: type routing
346
+
347
+ Step 4: Track database operations
348
+ Tables: read/write/update
349
+
350
+ Step 5: Note external API calls
351
+ Service: endpoint, auth method
352
+
353
+ Step 6: Find exit points
354
+ return/response patterns
355
+ ```
356
+
357
+ ---
358
+
359
+ ## Context Management During Initialization
360
+
361
+ ### Token Budget by Phase
362
+
363
+ | Phase | Tokens | Cumulative |
364
+ |-------|--------|------------|
365
+ | Analysis | 30k | 30k (15%) |
366
+ | Discovery | 50k | 80k (40%) - COMPACT HERE |
367
+ | Population | 40k | 40k (20%) - Fresh context |
368
+ | Validation | 20k | 60k (30%) |
369
+ | Finalization | 10k | 70k (35%) |
370
+
371
+ ### Compaction Points
372
+
373
+ 1. **After Phase 2:** Archive discovery reports, keep summary only
374
+ 2. **After Phase 3:** Archive populated files, keep index only
375
+ 3. **Before Phase 4:** Fresh context for validation
376
+
377
+ ---
378
+
379
+ ## Error Handling
380
+
381
+ ### Common Issues
382
+
383
+ | Issue | Solution |
384
+ |-------|----------|
385
+ | Can't detect tech stack | Ask user for clarification |
386
+ | Too many workflows (>15) | Merge related flows |
387
+ | Too few workflows (<8) | Split complex flows |
388
+ | Line numbers inaccurate | Use function names as anchors |
389
+ | Large codebase (>100k LOC) | Focus on critical paths first |
390
+
391
+ ### Recovery Protocol
392
+
393
+ ```
394
+ If initialization fails:
395
+ 1. Save progress to .claude/INIT_PROGRESS.md
396
+ 2. Note where failure occurred
397
+ 3. Provide resume instructions
398
+ 4. Human can run @context-engineer "resume"
399
+ ```
400
+
401
+ ---
402
+
403
+ ## Success Metrics
404
+
405
+ ### Initialization Complete When:
406
+
407
+ - [ ] CLAUDE.md fully populated (no {{PLACEHOLDER}} remaining)
408
+ - [ ] 8-15 workflow files created
409
+ - [ ] WORKFLOW_INDEX.md complete
410
+ - [ ] CODE_TO_WORKFLOW_MAP.md populated
411
+ - [ ] All 5 category index files populated
412
+ - [ ] At least 2 specialized agents created
413
+ - [ ] Validation report shows >60% accuracy
414
+ - [ ] Context budget <40% verified
415
+
416
+ ### Quality Standards
417
+
418
+ | Metric | Target |
419
+ |--------|--------|
420
+ | Line number accuracy | ≥60% |
421
+ | Link validity | 100% |
422
+ | Workflow section completeness | All 10 sections |
423
+ | Token budget | <40% for typical tasks |
424
+
425
+ ---
426
+
427
+ ## Post-Initialization
428
+
429
+ ### Maintenance Schedule
430
+
431
+ | Task | Frequency | Command |
432
+ |------|-----------|---------|
433
+ | Spot-check line numbers | Monthly | `/verify-docs-current` |
434
+ | Re-run discovery | Quarterly | `@context-engineer "audit"` |
435
+ | Full documentation audit | Annually | `@context-engineer "full-audit"` |
436
+
437
+ ### Extending the System
438
+
439
+ ```bash
440
+ # Add new workflow
441
+ @context-engineer "document workflow: [name]"
442
+
443
+ # Update existing workflow
444
+ @context-engineer "refresh workflow: [name]"
445
+
446
+ # Add new agent
447
+ @context-engineer "create agent for: [domain]"
448
+ ```
449
+
450
+ ---
451
+
452
+ ## Integration with RPI Workflow
453
+
454
+ After initialization, use the RPI workflow for all development:
455
+
456
+ ```
457
+ /rpi-research [feature] → Research using workflow docs
458
+ /rpi-plan [feature] → Plan with file:line precision
459
+ /rpi-implement [feature] → Execute atomically, update docs
460
+ ```
461
+
462
+ ---
463
+
464
+ ## Example Initialization Output
465
+
466
+ ```markdown
467
+ ## Context Engineering Initialized Successfully
468
+
469
+ **Repository:** my-awesome-project
470
+ **Tech Stack:** Python 3.11, FastAPI, PostgreSQL, Redis
471
+ **Total Files:** 156 (.py files)
472
+ **Total LOC:** 24,350
473
+
474
+ ### Workflows Created (12)
475
+
476
+ | # | Workflow | Complexity | Lines |
477
+ |---|----------|------------|-------|
478
+ | 1 | User Authentication | HIGH | 1,245 |
479
+ | 2 | Order Processing | HIGH | 1,102 |
480
+ | 3 | Payment Integration | HIGH | 987 |
481
+ | 4 | Product Catalog | MEDIUM | 456 |
482
+ | 5 | Shopping Cart | MEDIUM | 389 |
483
+ | ... | ... | ... | ... |
484
+
485
+ ### Agents Created (4)
486
+
487
+ - `core-architect` - Authentication, Orders
488
+ - `payment-specialist` - Payments, Billing
489
+ - `catalog-manager` - Products, Inventory
490
+ - `deployment-ops` - CI/CD, Infrastructure
491
+
492
+ ### Context Metrics
493
+
494
+ - Total documentation: ~180k tokens
495
+ - Workflow average: ~15k tokens
496
+ - Target utilization: 35%
497
+
498
+ ### Validation Results
499
+
500
+ - Line accuracy: 73% ✅
501
+ - Link validity: 100% ✅
502
+ - Section completeness: 100% ✅
503
+
504
+ ### Next Steps
505
+
506
+ 1. Review workflows/user_authentication.md for accuracy
507
+ 2. Add project-specific gotchas to KNOWN_GOTCHAS.md
508
+ 3. Customize agent descriptions for your team
509
+ 4. Run /rpi-research on your next feature
510
+ ```
511
+
512
+ ---
513
+
514
+ ## Version History
515
+
516
+ | Version | Date | Changes |
517
+ |---------|------|---------|
518
+ | 1.0.0 | {{DATE}} | Initial template release |
519
+
520
+ ---
521
+
522
+ **Agent Type:** Initialization
523
+ **Complexity:** Very High
524
+ **Context Usage:** Up to 80k tokens (40%)
525
+ **Human Review:** Recommended after initialization