specweave 0.3.13 → 0.4.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 (112) hide show
  1. package/CLAUDE.md +17 -1
  2. package/README.md +1 -1
  3. package/bin/install-all.sh +9 -2
  4. package/bin/install-hooks.sh +57 -0
  5. package/dist/cli/commands/init.d.ts.map +1 -1
  6. package/dist/cli/commands/init.js +55 -0
  7. package/dist/cli/commands/init.js.map +1 -1
  8. package/dist/core/agent-model-manager.d.ts +52 -0
  9. package/dist/core/agent-model-manager.d.ts.map +1 -0
  10. package/dist/core/agent-model-manager.js +120 -0
  11. package/dist/core/agent-model-manager.js.map +1 -0
  12. package/dist/core/cost-tracker.d.ts +108 -0
  13. package/dist/core/cost-tracker.d.ts.map +1 -0
  14. package/dist/core/cost-tracker.js +281 -0
  15. package/dist/core/cost-tracker.js.map +1 -0
  16. package/dist/core/model-selector.d.ts +57 -0
  17. package/dist/core/model-selector.d.ts.map +1 -0
  18. package/dist/core/model-selector.js +115 -0
  19. package/dist/core/model-selector.js.map +1 -0
  20. package/dist/core/phase-detector.d.ts +62 -0
  21. package/dist/core/phase-detector.d.ts.map +1 -0
  22. package/dist/core/phase-detector.js +229 -0
  23. package/dist/core/phase-detector.js.map +1 -0
  24. package/dist/types/cost-tracking.d.ts +43 -0
  25. package/dist/types/cost-tracking.d.ts.map +1 -0
  26. package/dist/types/cost-tracking.js +8 -0
  27. package/dist/types/cost-tracking.js.map +1 -0
  28. package/dist/types/model-selection.d.ts +53 -0
  29. package/dist/types/model-selection.d.ts.map +1 -0
  30. package/dist/types/model-selection.js +12 -0
  31. package/dist/types/model-selection.js.map +1 -0
  32. package/dist/utils/cost-reporter.d.ts +58 -0
  33. package/dist/utils/cost-reporter.d.ts.map +1 -0
  34. package/dist/utils/cost-reporter.js +224 -0
  35. package/dist/utils/cost-reporter.js.map +1 -0
  36. package/dist/utils/pricing-constants.d.ts +70 -0
  37. package/dist/utils/pricing-constants.d.ts.map +1 -0
  38. package/dist/utils/pricing-constants.js +71 -0
  39. package/dist/utils/pricing-constants.js.map +1 -0
  40. package/package.json +1 -1
  41. package/src/agents/architect/AGENT.md +3 -0
  42. package/src/agents/code-reviewer.md +156 -0
  43. package/src/agents/data-scientist/AGENT.md +181 -0
  44. package/src/agents/database-optimizer/AGENT.md +147 -0
  45. package/src/agents/devops/AGENT.md +3 -0
  46. package/src/agents/diagrams-architect/AGENT.md +3 -0
  47. package/src/agents/docs-writer/AGENT.md +3 -0
  48. package/src/agents/kubernetes-architect/AGENT.md +142 -0
  49. package/src/agents/ml-engineer/AGENT.md +150 -0
  50. package/src/agents/mlops-engineer/AGENT.md +201 -0
  51. package/src/agents/network-engineer/AGENT.md +149 -0
  52. package/src/agents/observability-engineer/AGENT.md +213 -0
  53. package/src/agents/payment-integration/AGENT.md +35 -0
  54. package/src/agents/performance/AGENT.md +3 -0
  55. package/src/agents/performance-engineer/AGENT.md +153 -0
  56. package/src/agents/pm/AGENT.md +3 -0
  57. package/src/agents/qa-lead/AGENT.md +3 -0
  58. package/src/agents/security/AGENT.md +3 -0
  59. package/src/agents/sre/AGENT.md +3 -0
  60. package/src/agents/tdd-orchestrator/AGENT.md +169 -0
  61. package/src/agents/tech-lead/AGENT.md +3 -0
  62. package/src/commands/specweave.costs.md +261 -0
  63. package/src/commands/specweave.ml-pipeline.md +292 -0
  64. package/src/commands/specweave.monitor-setup.md +501 -0
  65. package/src/commands/specweave.slo-implement.md +1055 -0
  66. package/src/commands/specweave.sync-github.md +1 -1
  67. package/src/commands/specweave.tdd-cycle.md +199 -0
  68. package/src/commands/specweave.tdd-green.md +842 -0
  69. package/src/commands/specweave.tdd-red.md +135 -0
  70. package/src/commands/specweave.tdd-refactor.md +165 -0
  71. package/src/skills/SKILLS-INDEX.md +18 -10
  72. package/src/skills/billing-automation/SKILL.md +559 -0
  73. package/src/skills/distributed-tracing/SKILL.md +438 -0
  74. package/src/skills/e2e-playwright/README.md +1 -1
  75. package/src/skills/e2e-playwright/package.json +1 -1
  76. package/src/skills/gitops-workflow/SKILL.md +285 -0
  77. package/src/skills/gitops-workflow/references/argocd-setup.md +134 -0
  78. package/src/skills/gitops-workflow/references/sync-policies.md +131 -0
  79. package/src/skills/grafana-dashboards/SKILL.md +369 -0
  80. package/src/skills/helm-chart-scaffolding/SKILL.md +544 -0
  81. package/src/skills/helm-chart-scaffolding/assets/Chart.yaml.template +42 -0
  82. package/src/skills/helm-chart-scaffolding/assets/values.yaml.template +185 -0
  83. package/src/skills/helm-chart-scaffolding/references/chart-structure.md +500 -0
  84. package/src/skills/helm-chart-scaffolding/scripts/validate-chart.sh +244 -0
  85. package/src/skills/k8s-manifest-generator/SKILL.md +511 -0
  86. package/src/skills/k8s-manifest-generator/assets/configmap-template.yaml +296 -0
  87. package/src/skills/k8s-manifest-generator/assets/deployment-template.yaml +203 -0
  88. package/src/skills/k8s-manifest-generator/assets/service-template.yaml +171 -0
  89. package/src/skills/k8s-manifest-generator/references/deployment-spec.md +753 -0
  90. package/src/skills/k8s-manifest-generator/references/service-spec.md +724 -0
  91. package/src/skills/k8s-security-policies/SKILL.md +334 -0
  92. package/src/skills/k8s-security-policies/assets/network-policy-template.yaml +177 -0
  93. package/src/skills/k8s-security-policies/references/rbac-patterns.md +187 -0
  94. package/src/skills/ml-pipeline-workflow/SKILL.md +245 -0
  95. package/src/skills/paypal-integration/SKILL.md +467 -0
  96. package/src/skills/pci-compliance/SKILL.md +466 -0
  97. package/src/skills/prometheus-configuration/SKILL.md +392 -0
  98. package/src/skills/slo-implementation/SKILL.md +329 -0
  99. package/src/skills/stripe-integration/SKILL.md +442 -0
  100. package/src/skills/tdd-workflow/SKILL.md +378 -0
  101. package/src/templates/README.md.template +1 -1
  102. package/src/skills/bmad-method-expert/SKILL.md +0 -626
  103. package/src/skills/bmad-method-expert/scripts/analyze-project.js +0 -318
  104. package/src/skills/bmad-method-expert/scripts/check-setup.js +0 -208
  105. package/src/skills/bmad-method-expert/scripts/generate-template.js +0 -1149
  106. package/src/skills/bmad-method-expert/scripts/validate-documents.js +0 -340
  107. package/src/skills/context-optimizer/SKILL.md +0 -588
  108. package/src/skills/figma-designer/SKILL.md +0 -149
  109. package/src/skills/figma-implementer/SKILL.md +0 -148
  110. package/src/skills/figma-mcp-connector/SKILL.md +0 -136
  111. package/src/skills/figma-to-code/SKILL.md +0 -128
  112. package/src/skills/spec-kit-expert/SKILL.md +0 -1010
@@ -1,588 +0,0 @@
1
- ---
2
- name: context-optimizer
3
- description: Second-pass context optimization that analyzes user prompts and removes irrelevant specs, agents, and skills from loaded context. Achieves 80%+ token reduction through smart cleanup. Activates for optimize context, reduce tokens, clean context, smart context, precision loading.
4
- allowed-tools: Read, Grep, Glob
5
- ---
6
-
7
- # Context Optimizer
8
-
9
- Second-pass context optimization that analyzes user intent and surgically removes irrelevant content from loaded context, achieving 80%+ total token reduction.
10
-
11
- ## Purpose
12
-
13
- After `context-loader` loads context based on manifest (70% reduction), `context-optimizer` performs intelligent analysis of the user's specific prompt to remove sections that aren't needed for that particular task.
14
-
15
- ## The Two-Pass Strategy
16
-
17
- ### Pass 1: Context Loader (Manifest-Based)
18
- ```yaml
19
- # context-manifest.yaml
20
- spec_sections:
21
- - auth-spec.md
22
- - payment-spec.md
23
- - user-management-spec.md
24
-
25
- Result: Load only relevant specs (70% reduction)
26
- Before: 150k tokens → After: 45k tokens
27
- ```
28
-
29
- ### Pass 2: Context Optimizer (Intent-Based)
30
- ```typescript
31
- User: "Fix authentication bug in login endpoint"
32
-
33
- Analyzer detects:
34
- • Task type: Bug fix (not new feature)
35
- • Domain: Backend auth
36
- • Scope: Single endpoint
37
-
38
- Removes:
39
- ❌ payment-spec.md (different domain)
40
- ❌ user-management-spec.md (different domain)
41
- ❌ PM agent description (not needed for bug fix)
42
- ❌ Frontend skills (backend task)
43
- ❌ DevOps skills (not deploying)
44
-
45
- Keeps:
46
- ✅ auth-spec.md (directly relevant)
47
- ✅ architecture/security/ (auth considerations)
48
- ✅ nodejs-backend skill (implementation)
49
- ✅ Tech Lead agent (code review)
50
-
51
- Result: Additional 40% reduction
52
- After Pass 1: 45k tokens → After Pass 2: 27k tokens
53
- Total reduction: 82% (150k → 27k)
54
- ```
55
-
56
- ## When to Use
57
-
58
- **Activates automatically** after context-loader when:
59
- - User prompt is specific (mentions feature, bug, file)
60
- - Loaded context > 20k tokens
61
- - Task is focused (not "build full product")
62
-
63
- **Manual activation:**
64
- - "optimize context"
65
- - "reduce tokens"
66
- - "clean context"
67
-
68
- **Skip when:**
69
- - Context already small (<10k tokens)
70
- - User asks broad questions ("explain architecture")
71
- - Planning new features (need full context)
72
-
73
- ## What It Does
74
-
75
- ### 1. User Intent Analysis
76
-
77
- ```typescript
78
- interface IntentAnalysis {
79
- task_type: TaskType;
80
- domains: Domain[];
81
- scope: Scope;
82
- needs_full_context: boolean;
83
- confidence: number;
84
- }
85
-
86
- enum TaskType {
87
- BUG_FIX = "bug-fix", // Narrow scope
88
- FEATURE = "feature", // Medium scope
89
- REFACTOR = "refactor", // Medium scope
90
- ARCHITECTURE = "architecture", // Broad scope
91
- DOCUMENTATION = "documentation", // Medium scope
92
- TESTING = "testing" // Medium scope
93
- }
94
-
95
- enum Domain {
96
- FRONTEND = "frontend",
97
- BACKEND = "backend",
98
- DATABASE = "database",
99
- INFRASTRUCTURE = "infrastructure",
100
- SECURITY = "security",
101
- AUTH = "auth",
102
- PAYMENT = "payment",
103
- // ... project-specific domains
104
- }
105
-
106
- enum Scope {
107
- NARROW = "narrow", // Single file/function
108
- FOCUSED = "focused", // Single module
109
- BROAD = "broad" // Multiple modules
110
- }
111
- ```
112
-
113
- **Analysis Examples:**
114
-
115
- | User Prompt | Task Type | Domains | Scope | Needs Full? |
116
- |-------------|-----------|---------|-------|-------------|
117
- | "Fix login bug" | BUG_FIX | [AUTH, BACKEND] | NARROW | No |
118
- | "Add payment feature" | FEATURE | [PAYMENT, BACKEND] | FOCUSED | No |
119
- | "Refactor auth module" | REFACTOR | [AUTH, BACKEND] | FOCUSED | No |
120
- | "Design system architecture" | ARCHITECTURE | [ALL] | BROAD | Yes |
121
- | "Explain how payments work" | DOCUMENTATION | [PAYMENT] | FOCUSED | No |
122
-
123
- ### 2. Context Filtering Rules
124
-
125
- ```yaml
126
- rules:
127
- # Rule 1: Task-Specific Specs
128
- bug_fix:
129
- keep_specs:
130
- - Related to mentioned domain
131
- - Architecture docs for that domain
132
- remove_specs:
133
- - Unrelated domains
134
- - Strategic docs (PRD, business specs)
135
- - Future roadmap
136
-
137
- feature_development:
138
- keep_specs:
139
- - Related domain specs
140
- - Architecture for integration points
141
- - Related ADRs
142
- remove_specs:
143
- - Unrelated domains
144
- - Completed features (unless mentioned)
145
-
146
- architecture_review:
147
- keep_specs:
148
- - ALL (needs full context)
149
-
150
- # Rule 2: Agent/Skill Filtering
151
- backend_task:
152
- keep_skills:
153
- - Backend skills (nodejs, python, dotnet)
154
- - Tech Lead
155
- - QA Lead
156
- remove_skills:
157
- - Frontend skills
158
- - DevOps (unless "deploy" mentioned)
159
- - PM agent (unless "requirements" mentioned)
160
-
161
- frontend_task:
162
- keep_skills:
163
- - Frontend skills (React, Next.js)
164
- - UI/UX skills
165
- remove_skills:
166
- - Backend skills
167
- - Database skills
168
-
169
- # Rule 3: Documentation Filtering
170
- implementation_task:
171
- keep_docs:
172
- - Technical specs (HLD, LLD)
173
- - ADRs
174
- - Implementation guides
175
- remove_docs:
176
- - Strategic docs (PRD, business cases)
177
- - Operations runbooks
178
- - Deployment guides
179
-
180
- planning_task:
181
- keep_docs:
182
- - Strategic docs (PRD)
183
- - Architecture overview
184
- - ADRs
185
- remove_docs:
186
- - Implementation details
187
- - Code comments
188
- - Test cases
189
- ```
190
-
191
- ### 3. Optimization Algorithm
192
-
193
- ```typescript
194
- async function optimizeContext(
195
- userPrompt: string,
196
- loadedContext: Context
197
- ): Promise<OptimizedContext> {
198
-
199
- // Step 1: Analyze intent
200
- const intent = await analyzeIntent(userPrompt);
201
-
202
- // Step 2: If broad scope, keep all
203
- if (intent.needs_full_context) {
204
- return {
205
- context: loadedContext,
206
- removed: [],
207
- kept: Object.keys(loadedContext),
208
- reason: "Broad scope requires full context"
209
- };
210
- }
211
-
212
- // Step 3: Apply filtering rules
213
- const filtered = {
214
- specs: filterByDomain(loadedContext.specs, intent.domains),
215
- agents: filterByTaskType(loadedContext.agents, intent.task_type),
216
- skills: filterByDomain(loadedContext.skills, intent.domains),
217
- docs: filterByScope(loadedContext.docs, intent.scope)
218
- };
219
-
220
- // Step 4: Calculate savings
221
- const before = calculateTokens(loadedContext);
222
- const after = calculateTokens(filtered);
223
- const savings = ((before - after) / before * 100).toFixed(0);
224
-
225
- // Step 5: Return optimized context
226
- return {
227
- context: filtered,
228
- removed: diff(loadedContext, filtered),
229
- kept: Object.keys(filtered),
230
- savings: `${savings}%`,
231
- tokens_before: before,
232
- tokens_after: after
233
- };
234
- }
235
- ```
236
-
237
- ## Usage Examples
238
-
239
- ### Example 1: Bug Fix (Narrow Scope)
240
-
241
- ```bash
242
- # Pass 1: context-loader loads from manifest
243
- Loaded context: 45k tokens (auth, payment, user specs)
244
-
245
- # User prompt
246
- User: "Fix bug where login fails with expired JWT"
247
-
248
- # Pass 2: context-optimizer analyzes
249
- 🔍 Analyzing task requirements...
250
-
251
- Detected:
252
- Task Type: Bug Fix
253
- Domains: [AUTH, BACKEND]
254
- Scope: Narrow (single endpoint)
255
- Full Context Needed: No
256
-
257
- Optimizing context...
258
-
259
- Removed (18k tokens):
260
- ❌ payment-spec.md (9k tokens) - Unrelated domain
261
- ❌ user-management-spec.md (7k tokens) - Unrelated domain
262
- ❌ PM agent description (1k tokens) - Not needed for bug fix
263
- ❌ Frontend skills (1k tokens) - Backend task
264
-
265
- Kept (27k tokens):
266
- ✅ auth-spec.md (12k tokens) - Core domain
267
- ✅ architecture/security/jwt-handling.md (5k tokens) - Relevant
268
- ✅ nodejs-backend skill (8k tokens) - Implementation
269
- ✅ Tech Lead agent (2k tokens) - Code review
270
-
271
- Result: 45k → 27k tokens (40% additional reduction)
272
- Total: 150k → 27k (82% total reduction)
273
-
274
- Ready to proceed with optimized context.
275
- ```
276
-
277
- ### Example 2: Feature Development (Focused Scope)
278
-
279
- ```bash
280
- User: "Add subscription billing to payment module"
281
-
282
- 🔍 Analyzing task requirements...
283
-
284
- Detected:
285
- Task Type: Feature Development
286
- Domains: [PAYMENT, BACKEND]
287
- Scope: Focused (single module)
288
- Full Context Needed: No
289
-
290
- Optimizing context...
291
-
292
- Removed (15k tokens):
293
- ❌ auth-spec.md (12k tokens) - Unrelated domain
294
- ❌ user-management-spec.md (7k tokens) - Unrelated
295
- ❌ DevOps agent (2k tokens) - Not deploying yet
296
-
297
- Kept (30k tokens):
298
- ✅ payment-spec.md (9k tokens) - Core domain
299
- ✅ architecture/payment-integration.md (6k tokens) - Integration points
300
- ✅ architecture/adr/0015-payment-provider.md (3k tokens) - Context
301
- ✅ PM agent (2k tokens) - Requirements clarification
302
- ✅ nodejs-backend skill (8k tokens) - Implementation
303
- ✅ Tech Lead agent (2k tokens) - Planning
304
-
305
- Result: 45k → 30k tokens (33% additional reduction)
306
- ```
307
-
308
- ### Example 3: Architecture Review (Broad Scope)
309
-
310
- ```bash
311
- User: "Review overall system architecture"
312
-
313
- 🔍 Analyzing task requirements...
314
-
315
- Detected:
316
- Task Type: Architecture Review
317
- Domains: [ALL]
318
- Scope: Broad (system-wide)
319
- Full Context Needed: Yes
320
-
321
- Skipping optimization - broad scope requires full context.
322
-
323
- Loaded context: 45k tokens (all specs retained)
324
-
325
- Rationale: Architecture review needs visibility across all domains
326
- to identify integration issues, dependencies, and design patterns.
327
- ```
328
-
329
- ### Example 4: Manual Optimization
330
-
331
- ```bash
332
- User: "Optimize context for payment work"
333
-
334
- context-optimizer:
335
-
336
- 🔍 Analyzing for payment domain...
337
-
338
- Removed (25k tokens):
339
- ❌ auth-spec.md
340
- ❌ user-management-spec.md
341
- ❌ Frontend skills
342
- ❌ Strategic docs
343
-
344
- Kept (20k tokens):
345
- ✅ payment-spec.md
346
- ✅ Payment architecture
347
- ✅ Backend skills
348
- ✅ Integration guides
349
-
350
- Result: 45k → 20k tokens (56% reduction)
351
-
352
- You can now work on payment features with optimized context.
353
- ```
354
-
355
- ## Configuration
356
-
357
-
358
-
359
- ## Integration with Context Loader
360
-
361
- ### Workflow
362
-
363
- ```typescript
364
- // 1. User asks to work on feature
365
- User: "Fix authentication bug"
366
-
367
- // 2. context-loader loads from manifest
368
- context-loader.load({
369
- increment: "0001-authentication",
370
- manifest: "context-manifest.yaml"
371
- })
372
- // Result: 150k → 45k tokens (70% reduction)
373
-
374
- // 3. context-optimizer analyzes user prompt
375
- context-optimizer.analyze(userPrompt: "Fix authentication bug")
376
- // Detects: bug-fix, auth domain, narrow scope
377
-
378
- // 4. context-optimizer removes unneeded sections
379
- context-optimizer.filter(loadedContext, analysis)
380
- // Result: 45k → 27k tokens (40% additional reduction)
381
-
382
- // 5. Return optimized context to main session
383
- return optimizedContext
384
- // Total: 150k → 27k (82% reduction)
385
- ```
386
-
387
- ### Configuration in Increment
388
-
389
- ```yaml
390
- # .specweave/increments/0001-auth/context-manifest.yaml
391
- spec_sections:
392
- - .specweave/docs/internal/strategy/auth/spec.md
393
- - .specweave/docs/internal/strategy/payment/spec.md
394
- - .specweave/docs/internal/strategy/users/spec.md
395
-
396
- documentation:
397
- - .specweave/docs/internal/architecture/auth-design.md
398
- - .specweave/docs/internal/architecture/payment-integration.md
399
-
400
- max_context_tokens: 50000
401
-
402
- # NEW: Optimization hints
403
- optimization:
404
- domains:
405
- auth: ["auth-spec.md", "auth-design.md"]
406
- payment: ["payment/spec.md", "payment-integration.md"]
407
- users: ["users/spec.md"]
408
-
409
- # Suggest which domains to keep for common tasks
410
- task_hints:
411
- "login": ["auth"]
412
- "payment": ["payment"]
413
- "billing": ["payment"]
414
- "user profile": ["users", "auth"]
415
- ```
416
-
417
- ## Token Savings Examples
418
-
419
- ### Realistic Project (500-page spec)
420
-
421
- **Without SpecWeave:**
422
- - Full spec loaded: 500 pages × 300 tokens = 150,000 tokens
423
- - Every query uses 150k tokens
424
- - Cost: $0.015 × 150 = $2.25 per query
425
-
426
- **With Context Loader (Pass 1):**
427
- - Manifest loads only auth section: 50 pages = 15,000 tokens (90% reduction)
428
- - Cost: $0.015 × 15 = $0.225 per query
429
-
430
- **With Context Optimizer (Pass 2):**
431
- - Further refine to login endpoint: 30 pages = 9,000 tokens (94% total reduction)
432
- - Cost: $0.015 × 9 = $0.135 per query
433
-
434
- **Savings: $2.25 → $0.135 (94% cost reduction)**
435
-
436
- ### Session Example (10 queries)
437
-
438
- **Scenario:** Fix 3 auth bugs, 2 payment bugs, 1 user bug
439
-
440
- | Query | Without | Pass 1 | Pass 2 | Savings |
441
- |-------|---------|--------|--------|---------|
442
- | Auth bug 1 | 150k | 45k (auth+pay+user) | 27k (auth only) | 82% |
443
- | Auth bug 2 | 150k | 45k | 27k | 82% |
444
- | Auth bug 3 | 150k | 45k | 27k | 82% |
445
- | Payment bug 1 | 150k | 45k | 28k (payment only) | 81% |
446
- | Payment bug 2 | 150k | 45k | 28k | 81% |
447
- | User bug 1 | 150k | 45k | 30k (user only) | 80% |
448
-
449
- **Total tokens:**
450
- - Without: 900k tokens
451
- - Pass 1 only: 270k tokens (70% reduction)
452
- - Pass 2: 167k tokens (81% reduction)
453
-
454
- **Cost savings:**
455
- - Without: $13.50
456
- - Pass 1 only: $4.05
457
- - Pass 2: $2.50
458
-
459
- **Additional savings: $1.55 per session (38% on top of Pass 1)**
460
-
461
- ## Best Practices
462
-
463
- ### 1. Let It Run Automatically
464
-
465
- Default mode: auto-optimize after context-loader
466
- - No manual intervention
467
- - Adapts to each query
468
- - Restores full context if needed
469
-
470
- ### 2. Review Removals for Critical Tasks
471
-
472
- For production deploys, security reviews:
473
- ```bash
474
- User: "Review security before deployment"
475
-
476
- context-optimizer:
477
- ⚠️ Keeping full context (critical task detected)
478
- ```
479
-
480
- ### 3. Use Conservative Buffer for Complex Tasks
481
-
482
- ```yaml
483
- buffer_strategy: "conservative"
484
- ```
485
- - Keeps adjacent domains
486
- - Includes integration points
487
- - Safer for refactoring
488
-
489
- ### 4. Custom Domains for Your Project
490
-
491
- ```yaml
492
- custom_domains:
493
- - "payment-processing"
494
- - "real-time-notifications"
495
- - "analytics-pipeline"
496
- ```
497
-
498
- Helps optimizer understand your project structure.
499
-
500
- ### 5. Monitor Optimization Accuracy
501
-
502
- If optimizer removes needed context:
503
- - Lower `min_confidence` threshold
504
- - Add `always_keep` rules
505
- - Use `conservative` buffer
506
-
507
- ## Limitations
508
-
509
- **What context-optimizer CAN'T do:**
510
- - ❌ Predict future conversation needs (only analyzes current prompt)
511
- - ❌ Understand implicit domain relationships (unless configured)
512
- - ❌ Read your mind (if prompt is vague, keeps more context)
513
-
514
- **What context-optimizer CAN do:**
515
- - ✅ Analyze task type and domain from prompt
516
- - ✅ Remove obviously unrelated specs/agents
517
- - ✅ Restore removed context if later needed
518
- - ✅ Learn from always_keep/custom_domains config
519
-
520
- ## Test Cases
521
-
522
- ### TC-001: Bug Fix Optimization
523
- **Given:** Context with auth+payment+user specs (45k tokens)
524
- **When:** User says "Fix login bug"
525
- **Then:** Keeps only auth spec (27k tokens, 40% reduction)
526
-
527
- ### TC-002: Feature Development
528
- **Given:** Context with multiple domains
529
- **When:** User says "Add subscription billing"
530
- **Then:** Keeps payment + integration specs (33% reduction)
531
-
532
- ### TC-003: Architecture Review (Broad)
533
- **Given:** Context with all specs
534
- **When:** User says "Review architecture"
535
- **Then:** Keeps all specs (0% reduction, full context needed)
536
-
537
- ### TC-004: Vague Prompt
538
- **Given:** Context with multiple specs
539
- **When:** User says "Help me"
540
- **Then:** Keeps all (low confidence, plays safe)
541
-
542
- ### TC-005: Manual Domain Specification
543
- **Given:** Context with all specs
544
- **When:** User says "Optimize for payment work"
545
- **Then:** Keeps only payment domain (50%+ reduction)
546
-
547
- ## Future Enhancements
548
-
549
- ### Phase 2: Conversation History Analysis
550
- - Track which context was actually used
551
- - Remove sections never referenced
552
- - Learn user patterns
553
-
554
- ### Phase 3: Dynamic Context Expansion
555
- - Start with minimal context
556
- - Add sections on-demand when mentioned
557
- - "Just-in-time" context loading
558
-
559
- ### Phase 4: Cross-Increment Context
560
- - Detect dependencies across increments
561
- - Load context from multiple increments intelligently
562
- - Maintain coherence across features
563
-
564
- ## Resources
565
-
566
- - [Retrieval-Augmented Generation (RAG)](https://arxiv.org/abs/2005.11401) - Context retrieval patterns
567
- - [LongRAG: Large Context Optimization](https://arxiv.org/abs/2310.03025) - Long context handling
568
- - [Anthropic Context Windows](https://docs.anthropic.com/claude/docs/context-windows) - Best practices
569
-
570
- ---
571
-
572
- ## Summary
573
-
574
- **context-optimizer** provides second-pass context optimization:
575
-
576
- ✅ **Intent-driven filtering** (analyzes user prompt)
577
- ✅ **Domain-aware** (removes unrelated specs)
578
- ✅ **Task-type specific** (bug fix vs feature vs architecture)
579
- ✅ **80%+ total reduction** (on top of context-loader's 70%)
580
- ✅ **Automatic** (runs after context-loader)
581
- ✅ **Safe** (restores context if needed)
582
- ✅ **Configurable** (custom domains, buffer strategy)
583
-
584
- **Use it when:** Working with large specs (500+ pages) where even manifest-based loading results in 30k+ tokens.
585
-
586
- **Skip it when:** Context already small (<10k), broad architectural questions, or planning new features from scratch.
587
-
588
- **The result:** From 150k tokens → 27k tokens = 82% total reduction, enabling work on enterprise-scale specs within Claude's context window.