specweave 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (288) hide show
  1. package/INSTALL.md +848 -0
  2. package/LICENSE +21 -0
  3. package/README.md +675 -0
  4. package/SPECWEAVE.md +665 -0
  5. package/bin/install-agents.sh +57 -0
  6. package/bin/install-all.sh +49 -0
  7. package/bin/install-commands.sh +56 -0
  8. package/bin/install-skills.sh +57 -0
  9. package/bin/specweave.js +81 -0
  10. package/dist/adapters/adapter-base.d.ts +50 -0
  11. package/dist/adapters/adapter-base.d.ts.map +1 -0
  12. package/dist/adapters/adapter-base.js +146 -0
  13. package/dist/adapters/adapter-base.js.map +1 -0
  14. package/dist/adapters/adapter-interface.d.ts +108 -0
  15. package/dist/adapters/adapter-interface.d.ts.map +1 -0
  16. package/dist/adapters/adapter-interface.js +9 -0
  17. package/dist/adapters/adapter-interface.js.map +1 -0
  18. package/dist/adapters/claude/adapter.d.ts +54 -0
  19. package/dist/adapters/claude/adapter.d.ts.map +1 -0
  20. package/dist/adapters/claude/adapter.js +184 -0
  21. package/dist/adapters/claude/adapter.js.map +1 -0
  22. package/dist/adapters/copilot/adapter.d.ts +42 -0
  23. package/dist/adapters/copilot/adapter.d.ts.map +1 -0
  24. package/dist/adapters/copilot/adapter.js +239 -0
  25. package/dist/adapters/copilot/adapter.js.map +1 -0
  26. package/dist/adapters/cursor/adapter.d.ts +42 -0
  27. package/dist/adapters/cursor/adapter.d.ts.map +1 -0
  28. package/dist/adapters/cursor/adapter.js +297 -0
  29. package/dist/adapters/cursor/adapter.js.map +1 -0
  30. package/dist/adapters/generic/adapter.d.ts +40 -0
  31. package/dist/adapters/generic/adapter.d.ts.map +1 -0
  32. package/dist/adapters/generic/adapter.js +155 -0
  33. package/dist/adapters/generic/adapter.js.map +1 -0
  34. package/dist/cli/commands/init.d.ts +6 -0
  35. package/dist/cli/commands/init.d.ts.map +1 -0
  36. package/dist/cli/commands/init.js +247 -0
  37. package/dist/cli/commands/init.js.map +1 -0
  38. package/dist/cli/commands/install.d.ts +7 -0
  39. package/dist/cli/commands/install.d.ts.map +1 -0
  40. package/dist/cli/commands/install.js +160 -0
  41. package/dist/cli/commands/install.js.map +1 -0
  42. package/dist/cli/commands/list.d.ts +6 -0
  43. package/dist/cli/commands/list.d.ts.map +1 -0
  44. package/dist/cli/commands/list.js +154 -0
  45. package/dist/cli/commands/list.js.map +1 -0
  46. package/package.json +90 -0
  47. package/src/adapters/README.md +312 -0
  48. package/src/adapters/adapter-base.ts +146 -0
  49. package/src/adapters/adapter-interface.ts +120 -0
  50. package/src/adapters/claude/README.md +241 -0
  51. package/src/adapters/claude/adapter.ts +157 -0
  52. package/src/adapters/copilot/.github/copilot/instructions.md +376 -0
  53. package/src/adapters/copilot/README.md +200 -0
  54. package/src/adapters/copilot/adapter.ts +210 -0
  55. package/src/adapters/cursor/.cursor/context/docs-context.md +62 -0
  56. package/src/adapters/cursor/.cursor/context/increments-context.md +71 -0
  57. package/src/adapters/cursor/.cursor/context/strategy-context.md +73 -0
  58. package/src/adapters/cursor/.cursor/context/tests-context.md +89 -0
  59. package/src/adapters/cursor/.cursorrules +325 -0
  60. package/src/adapters/cursor/README.md +243 -0
  61. package/src/adapters/cursor/adapter.ts +268 -0
  62. package/src/adapters/generic/README.md +277 -0
  63. package/src/adapters/generic/SPECWEAVE-MANUAL.md +676 -0
  64. package/src/adapters/generic/adapter.ts +159 -0
  65. package/src/adapters/registry.yaml +126 -0
  66. package/src/agents/architect/AGENT.md +416 -0
  67. package/src/agents/devops/AGENT.md +1738 -0
  68. package/src/agents/docs-writer/AGENT.md +239 -0
  69. package/src/agents/performance/AGENT.md +228 -0
  70. package/src/agents/pm/AGENT.md +751 -0
  71. package/src/agents/qa-lead/AGENT.md +150 -0
  72. package/src/agents/security/AGENT.md +179 -0
  73. package/src/agents/sre/AGENT.md +582 -0
  74. package/src/agents/sre/modules/backend-diagnostics.md +481 -0
  75. package/src/agents/sre/modules/database-diagnostics.md +509 -0
  76. package/src/agents/sre/modules/infrastructure.md +561 -0
  77. package/src/agents/sre/modules/monitoring.md +439 -0
  78. package/src/agents/sre/modules/security-incidents.md +421 -0
  79. package/src/agents/sre/modules/ui-diagnostics.md +302 -0
  80. package/src/agents/sre/playbooks/01-high-cpu-usage.md +204 -0
  81. package/src/agents/sre/playbooks/02-database-deadlock.md +241 -0
  82. package/src/agents/sre/playbooks/03-memory-leak.md +252 -0
  83. package/src/agents/sre/playbooks/04-slow-api-response.md +269 -0
  84. package/src/agents/sre/playbooks/05-ddos-attack.md +293 -0
  85. package/src/agents/sre/playbooks/06-disk-full.md +314 -0
  86. package/src/agents/sre/playbooks/07-service-down.md +333 -0
  87. package/src/agents/sre/playbooks/08-data-corruption.md +337 -0
  88. package/src/agents/sre/playbooks/09-cascade-failure.md +430 -0
  89. package/src/agents/sre/playbooks/10-rate-limit-exceeded.md +464 -0
  90. package/src/agents/sre/scripts/health-check.sh +230 -0
  91. package/src/agents/sre/scripts/log-analyzer.py +213 -0
  92. package/src/agents/sre/scripts/metrics-collector.sh +294 -0
  93. package/src/agents/sre/scripts/trace-analyzer.js +257 -0
  94. package/src/agents/sre/templates/incident-report.md +249 -0
  95. package/src/agents/sre/templates/mitigation-plan.md +375 -0
  96. package/src/agents/sre/templates/post-mortem.md +418 -0
  97. package/src/agents/sre/templates/runbook-template.md +412 -0
  98. package/src/agents/tech-lead/AGENT.md +263 -0
  99. package/src/commands/add-tasks.md +176 -0
  100. package/src/commands/close-increment.md +347 -0
  101. package/src/commands/create-increment.md +223 -0
  102. package/src/commands/create-project.md +528 -0
  103. package/src/commands/generate-docs.md +623 -0
  104. package/src/commands/list-increments.md +180 -0
  105. package/src/commands/review-docs.md +331 -0
  106. package/src/commands/start-increment.md +139 -0
  107. package/src/commands/sync-github.md +115 -0
  108. package/src/commands/validate-increment.md +800 -0
  109. package/src/hooks/README.md +252 -0
  110. package/src/hooks/docs-changed.sh +59 -0
  111. package/src/hooks/human-input-required.sh +55 -0
  112. package/src/hooks/post-task-completion.sh +57 -0
  113. package/src/hooks/pre-implementation.sh +47 -0
  114. package/src/skills/ado-sync/README.md +449 -0
  115. package/src/skills/ado-sync/SKILL.md +245 -0
  116. package/src/skills/ado-sync/test-cases/test-1.yaml +9 -0
  117. package/src/skills/ado-sync/test-cases/test-2.yaml +8 -0
  118. package/src/skills/ado-sync/test-cases/test-3.yaml +9 -0
  119. package/src/skills/bmad-method-expert/SKILL.md +628 -0
  120. package/src/skills/bmad-method-expert/scripts/analyze-project.js +318 -0
  121. package/src/skills/bmad-method-expert/scripts/check-setup.js +208 -0
  122. package/src/skills/bmad-method-expert/scripts/generate-template.js +1149 -0
  123. package/src/skills/bmad-method-expert/scripts/validate-documents.js +340 -0
  124. package/src/skills/bmad-method-expert/test-cases/test-1-placeholder.yaml +12 -0
  125. package/src/skills/bmad-method-expert/test-cases/test-2-placeholder.yaml +12 -0
  126. package/src/skills/bmad-method-expert/test-cases/test-3-placeholder.yaml +12 -0
  127. package/src/skills/brownfield-analyzer/SKILL.md +523 -0
  128. package/src/skills/brownfield-analyzer/test-cases/test-1-basic-analysis.yaml +48 -0
  129. package/src/skills/brownfield-analyzer/test-cases/test-2-placeholder.yaml +12 -0
  130. package/src/skills/brownfield-analyzer/test-cases/test-3-placeholder.yaml +12 -0
  131. package/src/skills/brownfield-onboarder/SKILL.md +625 -0
  132. package/src/skills/brownfield-onboarder/test-cases/test-1-placeholder.yaml +12 -0
  133. package/src/skills/brownfield-onboarder/test-cases/test-2-placeholder.yaml +12 -0
  134. package/src/skills/brownfield-onboarder/test-cases/test-3-placeholder.yaml +12 -0
  135. package/src/skills/calendar-system/test-cases/test-1-placeholder.yaml +12 -0
  136. package/src/skills/calendar-system/test-cases/test-2-placeholder.yaml +12 -0
  137. package/src/skills/calendar-system/test-cases/test-3-placeholder.yaml +12 -0
  138. package/src/skills/context-loader/SKILL.md +734 -0
  139. package/src/skills/context-loader/test-cases/test-1-basic-loading.yaml +39 -0
  140. package/src/skills/context-loader/test-cases/test-2-token-budget-exceeded.yaml +44 -0
  141. package/src/skills/context-loader/test-cases/test-3-section-anchors.yaml +45 -0
  142. package/src/skills/context-optimizer/SKILL.md +618 -0
  143. package/src/skills/context-optimizer/test-cases/test-1-bug-fix-narrow.yaml +97 -0
  144. package/src/skills/context-optimizer/test-cases/test-2-feature-focused.yaml +109 -0
  145. package/src/skills/context-optimizer/test-cases/test-3-architecture-broad.yaml +98 -0
  146. package/src/skills/cost-optimizer/SKILL.md +190 -0
  147. package/src/skills/cost-optimizer/test-cases/test-1-basic-comparison.yaml +75 -0
  148. package/src/skills/cost-optimizer/test-cases/test-2-budget-constraint.yaml +52 -0
  149. package/src/skills/cost-optimizer/test-cases/test-3-scale-requirement.yaml +63 -0
  150. package/src/skills/cost-optimizer/test-results/README.md +46 -0
  151. package/src/skills/design-system-architect/SKILL.md +107 -0
  152. package/src/skills/design-system-architect/test-cases/test-1-token-structure.yaml +23 -0
  153. package/src/skills/design-system-architect/test-cases/test-2-component-hierarchy.yaml +24 -0
  154. package/src/skills/design-system-architect/test-cases/test-3-accessibility-checklist.yaml +23 -0
  155. package/src/skills/diagrams-architect/SKILL.md +763 -0
  156. package/src/skills/diagrams-generator/SKILL.md +25 -0
  157. package/src/skills/diagrams-generator/test-cases/test-1.yaml +9 -0
  158. package/src/skills/diagrams-generator/test-cases/test-2.yaml +9 -0
  159. package/src/skills/diagrams-generator/test-cases/test-3.yaml +8 -0
  160. package/src/skills/docs-updater/README.md +48 -0
  161. package/src/skills/docs-updater/test-cases/test-1-placeholder.yaml +12 -0
  162. package/src/skills/docs-updater/test-cases/test-2-placeholder.yaml +12 -0
  163. package/src/skills/docs-updater/test-cases/test-3-placeholder.yaml +12 -0
  164. package/src/skills/dotnet-backend/SKILL.md +250 -0
  165. package/src/skills/e2e-playwright/README.md +506 -0
  166. package/src/skills/e2e-playwright/SKILL.md +457 -0
  167. package/src/skills/e2e-playwright/execute.js +373 -0
  168. package/src/skills/e2e-playwright/lib/utils.js +514 -0
  169. package/src/skills/e2e-playwright/package.json +33 -0
  170. package/src/skills/e2e-playwright/test-cases/TC-001-basic-navigation.yaml +54 -0
  171. package/src/skills/e2e-playwright/test-cases/TC-002-form-interaction.yaml +64 -0
  172. package/src/skills/e2e-playwright/test-cases/TC-003-specweave-integration.yaml +74 -0
  173. package/src/skills/e2e-playwright/test-cases/TC-004-accessibility-check.yaml +98 -0
  174. package/src/skills/figma-designer/SKILL.md +149 -0
  175. package/src/skills/figma-implementer/SKILL.md +148 -0
  176. package/src/skills/figma-mcp-connector/SKILL.md +136 -0
  177. package/src/skills/figma-mcp-connector/test-cases/test-1-read-file-desktop.yaml +22 -0
  178. package/src/skills/figma-mcp-connector/test-cases/test-2-read-file-framelink.yaml +21 -0
  179. package/src/skills/figma-mcp-connector/test-cases/test-3-error-handling.yaml +18 -0
  180. package/src/skills/figma-to-code/SKILL.md +128 -0
  181. package/src/skills/figma-to-code/test-cases/test-1-token-generation.yaml +29 -0
  182. package/src/skills/figma-to-code/test-cases/test-2-component-generation.yaml +27 -0
  183. package/src/skills/figma-to-code/test-cases/test-3-typescript-generation.yaml +28 -0
  184. package/src/skills/frontend/SKILL.md +177 -0
  185. package/src/skills/github-sync/SKILL.md +252 -0
  186. package/src/skills/github-sync/test-cases/test-1-placeholder.yaml +12 -0
  187. package/src/skills/github-sync/test-cases/test-2-placeholder.yaml +12 -0
  188. package/src/skills/github-sync/test-cases/test-3-placeholder.yaml +12 -0
  189. package/src/skills/hetzner-provisioner/README.md +308 -0
  190. package/src/skills/hetzner-provisioner/SKILL.md +251 -0
  191. package/src/skills/hetzner-provisioner/test-cases/test-1-basic-provision.yaml +71 -0
  192. package/src/skills/hetzner-provisioner/test-cases/test-2-postgres-provision.yaml +85 -0
  193. package/src/skills/hetzner-provisioner/test-cases/test-3-ssl-config.yaml +126 -0
  194. package/src/skills/hetzner-provisioner/test-results/README.md +259 -0
  195. package/src/skills/increment-planner/SKILL.md +889 -0
  196. package/src/skills/increment-planner/scripts/feature-utils.js +250 -0
  197. package/src/skills/increment-planner/test-cases/test-1-basic-feature.yaml +27 -0
  198. package/src/skills/increment-planner/test-cases/test-2-complex-feature.yaml +30 -0
  199. package/src/skills/increment-planner/test-cases/test-3-auto-numbering.yaml +24 -0
  200. package/src/skills/increment-quality-judge/SKILL.md +566 -0
  201. package/src/skills/increment-quality-judge/test-cases/test-1-good-spec.yaml +95 -0
  202. package/src/skills/increment-quality-judge/test-cases/test-2-poor-spec.yaml +108 -0
  203. package/src/skills/increment-quality-judge/test-cases/test-3-export-suggestions.yaml +87 -0
  204. package/src/skills/jira-sync/README.md +328 -0
  205. package/src/skills/jira-sync/SKILL.md +209 -0
  206. package/src/skills/jira-sync/test-cases/test-1.yaml +9 -0
  207. package/src/skills/jira-sync/test-cases/test-2.yaml +9 -0
  208. package/src/skills/jira-sync/test-cases/test-3.yaml +10 -0
  209. package/src/skills/nextjs/SKILL.md +176 -0
  210. package/src/skills/nodejs-backend/SKILL.md +181 -0
  211. package/src/skills/notification-system/test-cases/test-1-placeholder.yaml +12 -0
  212. package/src/skills/notification-system/test-cases/test-2-placeholder.yaml +12 -0
  213. package/src/skills/notification-system/test-cases/test-3-placeholder.yaml +12 -0
  214. package/src/skills/python-backend/SKILL.md +226 -0
  215. package/src/skills/role-orchestrator/README.md +197 -0
  216. package/src/skills/role-orchestrator/SKILL.md +1184 -0
  217. package/src/skills/role-orchestrator/test-cases/test-1-simple-product.yaml +98 -0
  218. package/src/skills/role-orchestrator/test-cases/test-2-quality-gate-failure.yaml +73 -0
  219. package/src/skills/role-orchestrator/test-cases/test-3-security-workflow.yaml +121 -0
  220. package/src/skills/role-orchestrator/test-cases/test-4-parallel-execution.yaml +145 -0
  221. package/src/skills/role-orchestrator/test-cases/test-5-feedback-loops.yaml +149 -0
  222. package/src/skills/skill-creator/LICENSE.txt +202 -0
  223. package/src/skills/skill-creator/SKILL.md +209 -0
  224. package/src/skills/skill-creator/scripts/init_skill.py +303 -0
  225. package/src/skills/skill-creator/scripts/package_skill.py +110 -0
  226. package/src/skills/skill-creator/scripts/quick_validate.py +65 -0
  227. package/src/skills/skill-creator/test-cases/test-1-placeholder.yaml +12 -0
  228. package/src/skills/skill-creator/test-cases/test-2-placeholder.yaml +12 -0
  229. package/src/skills/skill-creator/test-cases/test-3-placeholder.yaml +12 -0
  230. package/src/skills/skill-router/SKILL.md +497 -0
  231. package/src/skills/skill-router/test-cases/test-1-basic-routing.yaml +33 -0
  232. package/src/skills/skill-router/test-cases/test-2-ambiguous-request.yaml +42 -0
  233. package/src/skills/skill-router/test-cases/test-3-nested-orchestration.yaml +50 -0
  234. package/src/skills/spec-driven-brainstorming/README.md +264 -0
  235. package/src/skills/spec-driven-brainstorming/SKILL.md +439 -0
  236. package/src/skills/spec-driven-brainstorming/test-cases/TC-001-simple-idea-to-design.yaml +148 -0
  237. package/src/skills/spec-driven-brainstorming/test-cases/TC-002-complex-ultrathink-design.yaml +190 -0
  238. package/src/skills/spec-driven-brainstorming/test-cases/TC-003-unclear-requirements-socratic.yaml +233 -0
  239. package/src/skills/spec-driven-debugging/README.md +479 -0
  240. package/src/skills/spec-driven-debugging/SKILL.md +652 -0
  241. package/src/skills/spec-driven-debugging/test-cases/TC-001-simple-auth-bug.yaml +212 -0
  242. package/src/skills/spec-driven-debugging/test-cases/TC-002-race-condition-ultrathink.yaml +461 -0
  243. package/src/skills/spec-driven-debugging/test-cases/TC-003-brownfield-missing-spec.yaml +366 -0
  244. package/src/skills/spec-kit-expert/SKILL.md +1012 -0
  245. package/src/skills/spec-kit-expert/test-cases/test-1-placeholder.yaml +12 -0
  246. package/src/skills/spec-kit-expert/test-cases/test-2-placeholder.yaml +12 -0
  247. package/src/skills/spec-kit-expert/test-cases/test-3-placeholder.yaml +12 -0
  248. package/src/skills/specweave-ado-mapper/SKILL.md +501 -0
  249. package/src/skills/specweave-detector/SKILL.md +420 -0
  250. package/src/skills/specweave-detector/test-cases/test-1-basic-detection.yaml +37 -0
  251. package/src/skills/specweave-detector/test-cases/test-2-missing-config.yaml +37 -0
  252. package/src/skills/specweave-detector/test-cases/test-3-non-specweave-project.yaml +34 -0
  253. package/src/skills/specweave-jira-mapper/SKILL.md +500 -0
  254. package/src/skills/stripe-integrator/test-cases/test-1-placeholder.yaml +12 -0
  255. package/src/skills/stripe-integrator/test-cases/test-2-placeholder.yaml +12 -0
  256. package/src/skills/stripe-integrator/test-cases/test-3-placeholder.yaml +12 -0
  257. package/src/skills/task-builder/README.md +90 -0
  258. package/src/skills/task-builder/test-cases/test-1-placeholder.yaml +12 -0
  259. package/src/skills/task-builder/test-cases/test-2-placeholder.yaml +12 -0
  260. package/src/skills/task-builder/test-cases/test-3-placeholder.yaml +12 -0
  261. package/src/templates/.env.example +144 -0
  262. package/src/templates/.gitignore.template +81 -0
  263. package/src/templates/CLAUDE.md.template +383 -0
  264. package/src/templates/README.md.template +240 -0
  265. package/src/templates/config.yaml +333 -0
  266. package/src/templates/docs/README.md +124 -0
  267. package/src/templates/docs/adr-template.md +118 -0
  268. package/src/templates/docs/hld-template.md +220 -0
  269. package/src/templates/docs/lld-template.md +580 -0
  270. package/src/templates/docs/prd-template.md +132 -0
  271. package/src/templates/docs/rfc-template.md +229 -0
  272. package/src/templates/docs/runbook-template.md +298 -0
  273. package/src/templates/environments/minimal/.env.production +16 -0
  274. package/src/templates/environments/minimal/README.md +54 -0
  275. package/src/templates/environments/minimal/deploy-production.yml +52 -0
  276. package/src/templates/environments/progressive/.env.qa +28 -0
  277. package/src/templates/environments/progressive/README.md +129 -0
  278. package/src/templates/environments/progressive/deploy-production.yml +93 -0
  279. package/src/templates/environments/progressive/deploy-qa.yml +62 -0
  280. package/src/templates/environments/progressive/deploy-staging.yml +67 -0
  281. package/src/templates/environments/standard/.env.development +20 -0
  282. package/src/templates/environments/standard/.env.production +30 -0
  283. package/src/templates/environments/standard/.env.staging +23 -0
  284. package/src/templates/environments/standard/README.md +97 -0
  285. package/src/templates/environments/standard/deploy-production.yml +68 -0
  286. package/src/templates/environments/standard/deploy-staging.yml +61 -0
  287. package/src/templates/environments/standard/docker-compose.yml +43 -0
  288. package/src/templates/increment-metadata-template.yaml +138 -0
@@ -0,0 +1,618 @@
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
+ ```yaml
358
+ # .specweave/config.yaml
359
+ context_optimizer:
360
+ enabled: true
361
+
362
+ # Auto-run after context-loader
363
+ auto_optimize: true
364
+
365
+ # Minimum context size to trigger optimization
366
+ min_context_tokens: 20000
367
+
368
+ # Confidence threshold (skip if uncertain)
369
+ min_confidence: 0.75
370
+
371
+ # Show what was removed
372
+ show_removals: true
373
+
374
+ # Keep buffer (don't remove if close to needed)
375
+ buffer_strategy: "conservative" # or "aggressive"
376
+
377
+ # Domain detection
378
+ custom_domains:
379
+ - "real-time-chat"
380
+ - "analytics"
381
+ - "reporting"
382
+
383
+ # Always keep (never remove)
384
+ always_keep:
385
+ - "architecture/README.md"
386
+ - "CLAUDE.md"
387
+ ```
388
+
389
+ ## Integration with Context Loader
390
+
391
+ ### Workflow
392
+
393
+ ```typescript
394
+ // 1. User asks to work on feature
395
+ User: "Fix authentication bug"
396
+
397
+ // 2. context-loader loads from manifest
398
+ context-loader.load({
399
+ increment: "0001-authentication",
400
+ manifest: "context-manifest.yaml"
401
+ })
402
+ // Result: 150k → 45k tokens (70% reduction)
403
+
404
+ // 3. context-optimizer analyzes user prompt
405
+ context-optimizer.analyze(userPrompt: "Fix authentication bug")
406
+ // Detects: bug-fix, auth domain, narrow scope
407
+
408
+ // 4. context-optimizer removes unneeded sections
409
+ context-optimizer.filter(loadedContext, analysis)
410
+ // Result: 45k → 27k tokens (40% additional reduction)
411
+
412
+ // 5. Return optimized context to main session
413
+ return optimizedContext
414
+ // Total: 150k → 27k (82% reduction)
415
+ ```
416
+
417
+ ### Configuration in Increment
418
+
419
+ ```yaml
420
+ # .specweave/increments/0001-auth/context-manifest.yaml
421
+ spec_sections:
422
+ - .specweave/docs/internal/strategy/auth/spec.md
423
+ - .specweave/docs/internal/strategy/payment/spec.md
424
+ - .specweave/docs/internal/strategy/users/spec.md
425
+
426
+ documentation:
427
+ - .specweave/docs/internal/architecture/auth-design.md
428
+ - .specweave/docs/internal/architecture/payment-integration.md
429
+
430
+ max_context_tokens: 50000
431
+
432
+ # NEW: Optimization hints
433
+ optimization:
434
+ domains:
435
+ auth: ["auth-spec.md", "auth-design.md"]
436
+ payment: ["payment/spec.md", "payment-integration.md"]
437
+ users: ["users/spec.md"]
438
+
439
+ # Suggest which domains to keep for common tasks
440
+ task_hints:
441
+ "login": ["auth"]
442
+ "payment": ["payment"]
443
+ "billing": ["payment"]
444
+ "user profile": ["users", "auth"]
445
+ ```
446
+
447
+ ## Token Savings Examples
448
+
449
+ ### Realistic Project (500-page spec)
450
+
451
+ **Without SpecWeave:**
452
+ - Full spec loaded: 500 pages × 300 tokens = 150,000 tokens
453
+ - Every query uses 150k tokens
454
+ - Cost: $0.015 × 150 = $2.25 per query
455
+
456
+ **With Context Loader (Pass 1):**
457
+ - Manifest loads only auth section: 50 pages = 15,000 tokens (90% reduction)
458
+ - Cost: $0.015 × 15 = $0.225 per query
459
+
460
+ **With Context Optimizer (Pass 2):**
461
+ - Further refine to login endpoint: 30 pages = 9,000 tokens (94% total reduction)
462
+ - Cost: $0.015 × 9 = $0.135 per query
463
+
464
+ **Savings: $2.25 → $0.135 (94% cost reduction)**
465
+
466
+ ### Session Example (10 queries)
467
+
468
+ **Scenario:** Fix 3 auth bugs, 2 payment bugs, 1 user bug
469
+
470
+ | Query | Without | Pass 1 | Pass 2 | Savings |
471
+ |-------|---------|--------|--------|---------|
472
+ | Auth bug 1 | 150k | 45k (auth+pay+user) | 27k (auth only) | 82% |
473
+ | Auth bug 2 | 150k | 45k | 27k | 82% |
474
+ | Auth bug 3 | 150k | 45k | 27k | 82% |
475
+ | Payment bug 1 | 150k | 45k | 28k (payment only) | 81% |
476
+ | Payment bug 2 | 150k | 45k | 28k | 81% |
477
+ | User bug 1 | 150k | 45k | 30k (user only) | 80% |
478
+
479
+ **Total tokens:**
480
+ - Without: 900k tokens
481
+ - Pass 1 only: 270k tokens (70% reduction)
482
+ - Pass 2: 167k tokens (81% reduction)
483
+
484
+ **Cost savings:**
485
+ - Without: $13.50
486
+ - Pass 1 only: $4.05
487
+ - Pass 2: $2.50
488
+
489
+ **Additional savings: $1.55 per session (38% on top of Pass 1)**
490
+
491
+ ## Best Practices
492
+
493
+ ### 1. Let It Run Automatically
494
+
495
+ Default mode: auto-optimize after context-loader
496
+ - No manual intervention
497
+ - Adapts to each query
498
+ - Restores full context if needed
499
+
500
+ ### 2. Review Removals for Critical Tasks
501
+
502
+ For production deploys, security reviews:
503
+ ```bash
504
+ User: "Review security before deployment"
505
+
506
+ context-optimizer:
507
+ ⚠️ Keeping full context (critical task detected)
508
+ ```
509
+
510
+ ### 3. Use Conservative Buffer for Complex Tasks
511
+
512
+ ```yaml
513
+ buffer_strategy: "conservative"
514
+ ```
515
+ - Keeps adjacent domains
516
+ - Includes integration points
517
+ - Safer for refactoring
518
+
519
+ ### 4. Custom Domains for Your Project
520
+
521
+ ```yaml
522
+ custom_domains:
523
+ - "payment-processing"
524
+ - "real-time-notifications"
525
+ - "analytics-pipeline"
526
+ ```
527
+
528
+ Helps optimizer understand your project structure.
529
+
530
+ ### 5. Monitor Optimization Accuracy
531
+
532
+ If optimizer removes needed context:
533
+ - Lower `min_confidence` threshold
534
+ - Add `always_keep` rules
535
+ - Use `conservative` buffer
536
+
537
+ ## Limitations
538
+
539
+ **What context-optimizer CAN'T do:**
540
+ - ❌ Predict future conversation needs (only analyzes current prompt)
541
+ - ❌ Understand implicit domain relationships (unless configured)
542
+ - ❌ Read your mind (if prompt is vague, keeps more context)
543
+
544
+ **What context-optimizer CAN do:**
545
+ - ✅ Analyze task type and domain from prompt
546
+ - ✅ Remove obviously unrelated specs/agents
547
+ - ✅ Restore removed context if later needed
548
+ - ✅ Learn from always_keep/custom_domains config
549
+
550
+ ## Test Cases
551
+
552
+ ### TC-001: Bug Fix Optimization
553
+ **Given:** Context with auth+payment+user specs (45k tokens)
554
+ **When:** User says "Fix login bug"
555
+ **Then:** Keeps only auth spec (27k tokens, 40% reduction)
556
+
557
+ ### TC-002: Feature Development
558
+ **Given:** Context with multiple domains
559
+ **When:** User says "Add subscription billing"
560
+ **Then:** Keeps payment + integration specs (33% reduction)
561
+
562
+ ### TC-003: Architecture Review (Broad)
563
+ **Given:** Context with all specs
564
+ **When:** User says "Review architecture"
565
+ **Then:** Keeps all specs (0% reduction, full context needed)
566
+
567
+ ### TC-004: Vague Prompt
568
+ **Given:** Context with multiple specs
569
+ **When:** User says "Help me"
570
+ **Then:** Keeps all (low confidence, plays safe)
571
+
572
+ ### TC-005: Manual Domain Specification
573
+ **Given:** Context with all specs
574
+ **When:** User says "Optimize for payment work"
575
+ **Then:** Keeps only payment domain (50%+ reduction)
576
+
577
+ ## Future Enhancements
578
+
579
+ ### Phase 2: Conversation History Analysis
580
+ - Track which context was actually used
581
+ - Remove sections never referenced
582
+ - Learn user patterns
583
+
584
+ ### Phase 3: Dynamic Context Expansion
585
+ - Start with minimal context
586
+ - Add sections on-demand when mentioned
587
+ - "Just-in-time" context loading
588
+
589
+ ### Phase 4: Cross-Increment Context
590
+ - Detect dependencies across increments
591
+ - Load context from multiple increments intelligently
592
+ - Maintain coherence across features
593
+
594
+ ## Resources
595
+
596
+ - [Retrieval-Augmented Generation (RAG)](https://arxiv.org/abs/2005.11401) - Context retrieval patterns
597
+ - [LongRAG: Large Context Optimization](https://arxiv.org/abs/2310.03025) - Long context handling
598
+ - [Anthropic Context Windows](https://docs.anthropic.com/claude/docs/context-windows) - Best practices
599
+
600
+ ---
601
+
602
+ ## Summary
603
+
604
+ **context-optimizer** provides second-pass context optimization:
605
+
606
+ ✅ **Intent-driven filtering** (analyzes user prompt)
607
+ ✅ **Domain-aware** (removes unrelated specs)
608
+ ✅ **Task-type specific** (bug fix vs feature vs architecture)
609
+ ✅ **80%+ total reduction** (on top of context-loader's 70%)
610
+ ✅ **Automatic** (runs after context-loader)
611
+ ✅ **Safe** (restores context if needed)
612
+ ✅ **Configurable** (custom domains, buffer strategy)
613
+
614
+ **Use it when:** Working with large specs (500+ pages) where even manifest-based loading results in 30k+ tokens.
615
+
616
+ **Skip it when:** Context already small (<10k), broad architectural questions, or planning new features from scratch.
617
+
618
+ **The result:** From 150k tokens → 27k tokens = 82% total reduction, enabling work on enterprise-scale specs within Claude's context window.
@@ -0,0 +1,97 @@
1
+ ---
2
+ name: "Bug Fix Optimization - Narrow Scope"
3
+ description: "Optimize context for a focused bug fix in authentication"
4
+ skill: context-optimizer
5
+ priority: P1
6
+ estimated_time: "1-2 minutes"
7
+
8
+ input:
9
+ prompt: "Fix login bug where JWT expires too early"
10
+
11
+ loaded_context:
12
+ total_tokens: 45000
13
+ specs:
14
+ - name: "auth-spec.md"
15
+ tokens: 12000
16
+ domain: "auth"
17
+
18
+ - name: "payment-spec.md"
19
+ tokens: 9000
20
+ domain: "payment"
21
+
22
+ - name: "user-management-spec.md"
23
+ tokens: 7000
24
+ domain: "users"
25
+
26
+ agents:
27
+ - name: "pm-agent"
28
+ tokens: 2000
29
+
30
+ - name: "nodejs-backend"
31
+ tokens: 8000
32
+
33
+ - name: "frontend"
34
+ tokens: 5000
35
+
36
+ - name: "devops-agent"
37
+ tokens: 2000
38
+
39
+ expected_output:
40
+ task_analysis:
41
+ task_type: "bug-fix"
42
+ domains: ["auth", "backend"]
43
+ scope: "narrow"
44
+ needs_full_context: false
45
+ confidence: 0.85-0.95
46
+
47
+ optimization_result:
48
+ tokens_before: 45000
49
+ tokens_after: 25000-28000
50
+ reduction_percentage: 38-44
51
+ total_reduction: 82 # From original 150k
52
+
53
+ removed_sections:
54
+ specs:
55
+ - "payment-spec.md (9000 tokens) - Unrelated domain"
56
+ - "user-management-spec.md (7000 tokens) - Unrelated domain"
57
+
58
+ agents:
59
+ - "pm-agent (2000 tokens) - Not needed for bug fix"
60
+ - "frontend (5000 tokens) - Backend bug"
61
+ - "devops-agent (2000 tokens) - Not deploying"
62
+
63
+ kept_sections:
64
+ specs:
65
+ - "auth-spec.md (12000 tokens) - Core domain"
66
+
67
+ agents:
68
+ - "nodejs-backend (8000 tokens) - Implementation"
69
+
70
+ additional:
71
+ - "architecture/security/jwt-handling.md (5000 tokens est.)"
72
+ - "Tech Lead agent (2000 tokens est.) - Code review"
73
+
74
+ rationale:
75
+ - "Bug fix requires only authentication domain knowledge"
76
+ - "Backend implementation skill sufficient"
77
+ - "PM agent not needed (requirements already defined)"
78
+ - "DevOps not needed (not deploying fix immediately)"
79
+
80
+ validation:
81
+ - "Task type detected as 'bug-fix'"
82
+ - "Domains detected: auth, backend"
83
+ - "Scope: narrow"
84
+ - "Token reduction >= 35%"
85
+ - "Total reduction from original >= 80%"
86
+ - "All unrelated domains removed"
87
+ - "Core auth spec retained"
88
+ - "Backend implementation skill retained"
89
+ - "Confidence >= 0.85"
90
+
91
+ success_criteria:
92
+ - "Correct task type identification"
93
+ - "Appropriate domain filtering"
94
+ - "Significant token reduction without losing needed context"
95
+ - "Clear rationale for removals"
96
+ - "High confidence in analysis"
97
+ ---