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,734 @@
1
+ ---
2
+ name: context-loader
3
+ description: Precision context loading system that selectively loads specifications, architecture docs, and ADRs based on context manifests. Achieves 70%+ token reduction by loading only relevant context. Activates automatically when working on features/issues or when user requests "load context for...". Keywords: load context, context manifest, selective loading, specifications, context precision.
4
+ ---
5
+
6
+ # Context Loader - Precision Context Loading
7
+
8
+ ## Purpose
9
+
10
+ The context-loader is SpecWeave's **precision context loading system** that:
11
+ 1. Loads only relevant specifications and documentation (not everything)
12
+ 2. Achieves **70%+ token reduction** vs loading full specs
13
+ 3. Respects context manifests (`context-manifest.yaml`)
14
+ 4. Supports section-level granularity (`#specific-section`)
15
+ 5. Enables enterprise-scale specs (500+ pages) without context bloat
16
+ 6. Caches loaded context for performance
17
+
18
+ ## When to Activate
19
+
20
+ This skill activates when:
21
+ - User starts working on a feature (`.specweave/increments/####-name/`)
22
+ - User works on an issue (`work/issues/####-name/`)
23
+ - User explicitly requests "load context for feature 0003"
24
+ - Any skill needs specification context
25
+ - specweave-detector detects active work
26
+
27
+ ## Context Manifest Format
28
+
29
+ ### Basic Context Manifest
30
+
31
+ ```yaml
32
+ ---
33
+ # Context Manifest for Feature 003: Stripe Payment Integration
34
+
35
+ # Specification sections to load
36
+ spec_sections:
37
+ - specifications/modules/payments/overview.md
38
+ - specifications/modules/payments/stripe/spec.md
39
+ - specifications/modules/payments/stripe/api-contracts.md
40
+ - specifications/modules/payments/shared/payment-entities.md
41
+
42
+ # Architecture documents to load
43
+ architecture:
44
+ - .specweave/docs/architecture/system-design.md#payment-flow
45
+ - .specweave/docs/architecture/data/database-schema.md#payment-tables
46
+ - .specweave/docs/architecture/security/pci-compliance.md
47
+
48
+ # Architecture Decision Records to reference
49
+ adrs:
50
+ - .specweave/docs/decisions/005-payment-provider-choice.md
51
+ - .specweave/docs/decisions/012-stripe-webhook-handling.md
52
+
53
+ # Context budget (max tokens to load)
54
+ max_context_tokens: 10000
55
+
56
+ # Priority level
57
+ priority: high
58
+
59
+ # Auto-refresh context on spec changes
60
+ auto_refresh: false
61
+
62
+ # Related features
63
+ related_features:
64
+ - 002-user-subscriptions
65
+ - 004-billing-portal
66
+
67
+ # Tags for search and categorization
68
+ tags:
69
+ - payments
70
+ - stripe
71
+ - pci-compliance
72
+ - subscriptions
73
+ ---
74
+ ```
75
+
76
+ ### Advanced Context Manifest (with filters)
77
+
78
+ ```yaml
79
+ ---
80
+ # Context Manifest with advanced filtering
81
+
82
+ spec_sections:
83
+ - path: specifications/modules/payments/**/*.md
84
+ exclude:
85
+ - "**/legacy/**"
86
+ - "**/deprecated/**"
87
+ sections:
88
+ - "#stripe-integration"
89
+ - "#webhook-handling"
90
+
91
+ architecture:
92
+ - path: .specweave/docs/architecture/payments/**/*.md
93
+ max_depth: 2 # Don't load deeply nested sections
94
+
95
+ adrs:
96
+ - path: .specweave/docs/decisions/*.md
97
+ filter:
98
+ tags: ["payment", "stripe"]
99
+
100
+ # Section-level loading
101
+ load_sections_only: true
102
+
103
+ # Cache settings
104
+ cache:
105
+ enabled: true
106
+ ttl: 3600 # 1 hour
107
+
108
+ # Token optimization
109
+ optimization:
110
+ remove_code_blocks: false # Keep code examples
111
+ remove_tables: false
112
+ remove_mermaid: false
113
+ summarize_long_sections: true # Auto-summarize sections >1000 tokens
114
+ ---
115
+ ```
116
+
117
+ ## Loading Algorithm
118
+
119
+ ### Phase 1: Parse Manifest
120
+
121
+ ```typescript
122
+ interface ContextManifest {
123
+ spec_sections: string[];
124
+ architecture: string[];
125
+ adrs: string[];
126
+ max_context_tokens: number;
127
+ priority: 'low' | 'medium' | 'high';
128
+ auto_refresh: boolean;
129
+ related_features?: string[];
130
+ tags?: string[];
131
+ }
132
+
133
+ function parseManifest(manifestPath: string): ContextManifest {
134
+ const yaml = readFile(manifestPath);
135
+ return parseYAML(yaml);
136
+ }
137
+ ```
138
+
139
+ ### Phase 2: Resolve Paths
140
+
141
+ ```typescript
142
+ function resolvePaths(patterns: string[]): string[] {
143
+ const resolved: string[] = [];
144
+
145
+ for (const pattern of patterns) {
146
+ // Handle glob patterns
147
+ if (pattern.includes('*')) {
148
+ const files = glob(pattern);
149
+ resolved.push(...files);
150
+ }
151
+
152
+ // Handle section references (#anchor)
153
+ else if (pattern.includes('#')) {
154
+ const [file, section] = pattern.split('#');
155
+ resolved.push({ file, section });
156
+ }
157
+
158
+ // Handle direct paths
159
+ else {
160
+ resolved.push({ file: pattern, section: null });
161
+ }
162
+ }
163
+
164
+ return resolved;
165
+ }
166
+ ```
167
+
168
+ ### Phase 3: Load Content with Section Filtering
169
+
170
+ ```typescript
171
+ function loadContent(filePath: string, section?: string): string {
172
+ const content = readFile(filePath);
173
+
174
+ // If section specified, extract only that section
175
+ if (section) {
176
+ return extractSection(content, section);
177
+ }
178
+
179
+ return content;
180
+ }
181
+
182
+ function extractSection(markdown: string, sectionHeading: string): string {
183
+ const lines = markdown.split('\n');
184
+ let inSection = false;
185
+ let sectionLevel = 0;
186
+ const result: string[] = [];
187
+
188
+ for (const line of lines) {
189
+ // Check if heading
190
+ const headingMatch = line.match(/^(#+)\s+(.+)/);
191
+
192
+ if (headingMatch) {
193
+ const [, hashes, heading] = headingMatch;
194
+ const level = hashes.length;
195
+
196
+ // Found target section
197
+ if (heading.trim() === sectionHeading.replace('#', '').trim()) {
198
+ inSection = true;
199
+ sectionLevel = level;
200
+ result.push(line);
201
+ continue;
202
+ }
203
+
204
+ // End of section (same or higher level heading)
205
+ if (inSection && level <= sectionLevel) {
206
+ break;
207
+ }
208
+ }
209
+
210
+ if (inSection) {
211
+ result.push(line);
212
+ }
213
+ }
214
+
215
+ return result.join('\n');
216
+ }
217
+ ```
218
+
219
+ ### Phase 4: Token Budget Management
220
+
221
+ ```typescript
222
+ function enforceTokenBudget(contents: LoadedContent[], maxTokens: number): LoadedContent[] {
223
+ let totalTokens = 0;
224
+ const result: LoadedContent[] = [];
225
+
226
+ // Sort by priority: ADRs > Architecture > Specs
227
+ const sorted = sortByPriority(contents);
228
+
229
+ for (const content of sorted) {
230
+ const tokens = estimateTokens(content.text);
231
+
232
+ if (totalTokens + tokens <= maxTokens) {
233
+ result.push(content);
234
+ totalTokens += tokens;
235
+ } else {
236
+ // Try to fit summary instead
237
+ const summary = summarize(content.text, maxTokens - totalTokens);
238
+ if (summary) {
239
+ result.push({ ...content, text: summary, summarized: true });
240
+ break;
241
+ }
242
+ }
243
+ }
244
+
245
+ return result;
246
+ }
247
+
248
+ function estimateTokens(text: string): number {
249
+ // Rough estimate: ~4 characters per token
250
+ return Math.ceil(text.length / 4);
251
+ }
252
+ ```
253
+
254
+ ### Phase 5: Cache Management
255
+
256
+ ```typescript
257
+ interface CachedContext {
258
+ manifestHash: string;
259
+ contents: LoadedContent[];
260
+ loadedAt: number;
261
+ expiresAt: number;
262
+ }
263
+
264
+ function getCachedContext(manifestPath: string): CachedContext | null {
265
+ const cacheKey = manifestHash(manifestPath);
266
+ const cached = readCache(`.specweave/cache/context/${cacheKey}.json`);
267
+
268
+ if (cached && cached.expiresAt > Date.now()) {
269
+ return cached;
270
+ }
271
+
272
+ return null;
273
+ }
274
+
275
+ function saveToCache(manifestPath: string, contents: LoadedContent[], ttl: number) {
276
+ const cacheKey = manifestHash(manifestPath);
277
+ const cache: CachedContext = {
278
+ manifestHash: cacheKey,
279
+ contents,
280
+ loadedAt: Date.now(),
281
+ expiresAt: Date.now() + (ttl * 1000)
282
+ };
283
+
284
+ writeCache(`.specweave/cache/context/${cacheKey}.json`, cache);
285
+ }
286
+ ```
287
+
288
+ ## Loading Workflows
289
+
290
+ ### Workflow 1: Feature Development
291
+
292
+ ```
293
+ User: "Implement feature 003"
294
+ ↓
295
+ specweave-detector detects feature 003
296
+ ↓
297
+ context-loader activates
298
+ ↓
299
+ Load context-manifest.yaml:
300
+ features/003-stripe-payment/context-manifest.yaml
301
+ ↓
302
+ Parse manifest:
303
+ spec_sections: 4 files
304
+ architecture: 3 files (2 with section filters)
305
+ adrs: 2 files
306
+ max_tokens: 10,000
307
+ ↓
308
+ Resolve paths:
309
+ ✓ specifications/modules/payments/overview.md (full)
310
+ ✓ specifications/modules/payments/stripe/spec.md (full)
311
+ ✓ .specweave/docs/architecture/system-design.md#payment-flow (section only)
312
+ ...
313
+ ↓
314
+ Load content:
315
+ Total: 8,547 tokens (under budget ✓)
316
+ ↓
317
+ Context loaded:
318
+ "Context loaded for Feature 003: Stripe Payment Integration
319
+
320
+ Loaded 9 documents (8,547 tokens):
321
+ ✓ 4 specification files
322
+ ✓ 3 architecture documents (2 section-filtered)
323
+ ✓ 2 ADRs
324
+
325
+ Token reduction: 73% (vs loading all payment specs: 31,892 tokens)
326
+
327
+ Ready to implement!"
328
+ ```
329
+
330
+ ### Workflow 2: Brownfield Issue
331
+
332
+ ```
333
+ User: Working in work/issues/012-fix-payment-webhook/
334
+ ↓
335
+ context-loader detects active issue
336
+ ↓
337
+ Load: work/issues/012-fix-payment-webhook/context-manifest.yaml
338
+ ↓
339
+ Manifest specifies:
340
+ spec_sections:
341
+ - specifications/modules/payments/stripe/webhooks.md
342
+ architecture:
343
+ - .specweave/docs/architecture/webhooks.md
344
+ code:
345
+ - src/services/stripe-webhook-handler.ts (existing code)
346
+ ↓
347
+ Load brownfield context:
348
+ ✓ Current implementation (src/services/)
349
+ ✓ Webhook specification
350
+ ✓ Architecture design
351
+ ↓
352
+ Total: 2,134 tokens
353
+ ↓
354
+ "Context loaded for Issue 012: Fix Payment Webhook
355
+
356
+ Loaded:
357
+ ✓ Current webhook handler implementation
358
+ ✓ Webhook specification
359
+ ✓ Architecture documentation
360
+
361
+ Token reduction: 94% (vs loading all payment context)
362
+
363
+ Ready to debug!"
364
+ ```
365
+
366
+ ### Workflow 3: Related Features
367
+
368
+ ```
369
+ User: "Show me related features for feature 003"
370
+ ↓
371
+ context-loader reads manifest:
372
+ related_features:
373
+ - 002-user-subscriptions
374
+ - 004-billing-portal
375
+ ↓
376
+ Load context for all related features:
377
+ features/002-user-subscriptions/context-manifest.yaml
378
+ features/004-billing-portal/context-manifest.yaml
379
+ ↓
380
+ Find overlapping context:
381
+ Common specs:
382
+ - specifications/modules/payments/shared/payment-entities.md
383
+ Common architecture:
384
+ - .specweave/docs/architecture/database-schema.md#payment-tables
385
+ ↓
386
+ Report:
387
+ "Features 002, 003, 004 share common context:
388
+
389
+ Shared specifications:
390
+ - Payment entities model
391
+
392
+ Shared architecture:
393
+ - Payment database schema
394
+
395
+ This suggests these features should be implemented together
396
+ or in sequence to avoid conflicts."
397
+ ```
398
+
399
+ ## Token Reduction Examples
400
+
401
+ ### Example 1: Payment Module (Enterprise Scale)
402
+
403
+ **Scenario**: Large payment module with 500 pages of specs
404
+
405
+ **Without context-loader** (loading everything):
406
+ ```
407
+ specifications/modules/payments/**/*.md
408
+ Total files: 47
409
+ Total tokens: 185,234
410
+ Problem: Exceeds context window!
411
+ ```
412
+
413
+ **With context-loader** (selective loading):
414
+ ```yaml
415
+ # Feature 003 manifest
416
+ spec_sections:
417
+ - specifications/modules/payments/stripe/spec.md
418
+ - specifications/modules/payments/shared/payment-entities.md
419
+ architecture:
420
+ - .specweave/docs/architecture/system-design.md#stripe-integration
421
+ ```
422
+
423
+ ```
424
+ Result:
425
+ Total files: 3 (2 specs + 1 architecture section)
426
+ Total tokens: 8,547
427
+ Reduction: 95.4% 🎯
428
+ ```
429
+
430
+ ### Example 2: Authentication Module
431
+
432
+ **Without context-loader**:
433
+ ```
434
+ specifications/modules/authentication/**/*.md
435
+ OAuth spec: 15,234 tokens
436
+ Session management: 8,765 tokens
437
+ LDAP integration: 12,456 tokens
438
+ SAML integration: 18,932 tokens
439
+ Password policies: 5,643 tokens
440
+ Total: 60,030 tokens
441
+ ```
442
+
443
+ **With context-loader** (working on OAuth only):
444
+ ```yaml
445
+ spec_sections:
446
+ - specifications/modules/authentication/oauth/spec.md
447
+ - specifications/modules/authentication/shared/user-entities.md
448
+ ```
449
+
450
+ ```
451
+ Result:
452
+ OAuth spec: 15,234 tokens
453
+ User entities: 2,341 tokens
454
+ Total: 17,575 tokens
455
+ Reduction: 70.7% 🎯
456
+ ```
457
+
458
+ ## Auto-Refresh Feature
459
+
460
+ ### Watch for Spec Changes
461
+
462
+ ```typescript
463
+ // When auto_refresh: true in manifest
464
+ function watchSpecChanges(manifest: ContextManifest) {
465
+ const watchedFiles = resolveAllPaths(manifest);
466
+
467
+ for (const file of watchedFiles) {
468
+ fs.watch(file, () => {
469
+ console.log(`Spec changed: ${file}`);
470
+ console.log('Auto-refreshing context...');
471
+
472
+ // Clear cache
473
+ clearCache(manifest);
474
+
475
+ // Reload context
476
+ loadContext(manifest);
477
+
478
+ console.log('✓ Context refreshed');
479
+ });
480
+ }
481
+ }
482
+ ```
483
+
484
+ ### Invalidate Cache on Changes
485
+
486
+ ```typescript
487
+ function shouldInvalidateCache(manifestPath: string): boolean {
488
+ const cached = getCachedContext(manifestPath);
489
+ if (!cached) return true;
490
+
491
+ const manifest = parseManifest(manifestPath);
492
+ const files = resolveAllPaths(manifest);
493
+
494
+ for (const file of files) {
495
+ const fileModified = fs.statSync(file).mtimeMs;
496
+ if (fileModified > cached.loadedAt) {
497
+ return true; // File changed since cache created
498
+ }
499
+ }
500
+
501
+ return false; // Cache still valid
502
+ }
503
+ ```
504
+
505
+ ## Performance Optimization
506
+
507
+ ### Parallel Loading
508
+
509
+ ```typescript
510
+ async function loadContextParallel(manifest: ContextManifest): Promise<LoadedContent[]> {
511
+ const allPaths = [
512
+ ...manifest.spec_sections,
513
+ ...manifest.architecture,
514
+ ...manifest.adrs
515
+ ];
516
+
517
+ // Load all files in parallel
518
+ const promises = allPaths.map(path => loadFile(path));
519
+ const contents = await Promise.all(promises);
520
+
521
+ return contents;
522
+ }
523
+ ```
524
+
525
+ ### Lazy Loading
526
+
527
+ ```typescript
528
+ // Load only high-priority items immediately
529
+ // Load medium/low priority on-demand
530
+
531
+ async function loadContextLazy(manifest: ContextManifest): Promise<ContextLoader> {
532
+ // Immediate load (high priority)
533
+ const highPriority = await loadHighPriorityContent(manifest);
534
+
535
+ // Return loader with deferred loading
536
+ return {
537
+ immediate: highPriority,
538
+
539
+ loadMore: async () => {
540
+ return await loadMediumPriorityContent(manifest);
541
+ },
542
+
543
+ loadAll: async () => {
544
+ return await loadAllContent(manifest);
545
+ }
546
+ };
547
+ }
548
+ ```
549
+
550
+ ## Integration Points
551
+
552
+ ### 1. Called By
553
+
554
+ - **specweave-detector**: Auto-load when feature/issue detected
555
+ - **increment-planner**: Load context when creating new features
556
+ - **All implementation skills**: Load context before implementing
557
+ - **Users**: Explicit "load context for feature 003"
558
+
559
+ ### 2. Calls
560
+
561
+ - File system: Read specification/architecture files
562
+ - Cache: Read/write cached context
563
+
564
+ ### 3. Updates
565
+
566
+ - `.specweave/cache/context/`: Cached loaded context
567
+ - `.specweave/logs/context-loading.log`: Loading metrics
568
+
569
+ ## Configuration
570
+
571
+ ```yaml
572
+ # .specweave/config.yaml
573
+ context_loader:
574
+ enabled: true
575
+
576
+ # Cache settings
577
+ cache:
578
+ enabled: true
579
+ ttl: 3600 # 1 hour in seconds
580
+ directory: ".specweave/cache/context"
581
+
582
+ # Performance
583
+ parallel_loading: true
584
+ max_parallel: 10
585
+
586
+ # Auto-refresh
587
+ watch_specs: true # Watch for file changes
588
+
589
+ # Token optimization
590
+ default_max_tokens: 10000
591
+ warn_threshold: 8000 # Warn when approaching budget
592
+
593
+ # Summarization (for over-budget content)
594
+ auto_summarize: true
595
+ summarization_ratio: 0.3 # Target 30% of original length
596
+ ```
597
+
598
+ ## Metrics and Monitoring
599
+
600
+ ### Context Loading Metrics
601
+
602
+ ```typescript
603
+ interface ContextMetrics {
604
+ feature: string;
605
+ filesLoaded: number;
606
+ tokensLoaded: number;
607
+ tokenBudget: number;
608
+ reductionPercentage: number;
609
+ loadTimeMs: number;
610
+ cacheHit: boolean;
611
+ timestamp: number;
612
+ }
613
+
614
+ // Example log entry
615
+ {
616
+ feature: "003-stripe-payment",
617
+ filesLoaded: 9,
618
+ tokensLoaded: 8547,
619
+ tokenBudget: 10000,
620
+ reductionPercentage: 73.2,
621
+ loadTimeMs: 145,
622
+ cacheHit: false,
623
+ timestamp: 1704067200000
624
+ }
625
+ ```
626
+
627
+ ### Performance Dashboard
628
+
629
+ ```
630
+ Context Loading Performance (Last 30 days)
631
+
632
+ Average token reduction: 74.3% 🎯 (target: 70%+)
633
+ Average load time: 156ms
634
+ Cache hit rate: 67%
635
+
636
+ Top token savers:
637
+ 1. Feature 003 (Stripe Payment): 95.4% reduction
638
+ 2. Feature 007 (OAuth SSO): 82.1% reduction
639
+ 3. Feature 012 (Webhooks): 78.9% reduction
640
+
641
+ Token budget warnings: 2 (features approaching limit)
642
+ ```
643
+
644
+ ## Testing
645
+
646
+ ### Test Cases
647
+
648
+ **TC-001: Basic Context Loading**
649
+ - Given: Feature with context manifest
650
+ - When: context-loader loads context
651
+ - Then: All specified files loaded
652
+ - And: Token count within budget
653
+ - And: >70% reduction achieved
654
+
655
+ **TC-002: Section-Level Loading**
656
+ - Given: Manifest with section filters (#payment-flow)
657
+ - When: context-loader loads architecture doc
658
+ - Then: Only specified section extracted
659
+ - And: Other sections not loaded
660
+ - And: Token reduction maximized
661
+
662
+ **TC-003: Cache Hit**
663
+ - Given: Context loaded once (cached)
664
+ - When: Same context requested again
665
+ - Then: Loaded from cache (not file system)
666
+ - And: Load time < 50ms
667
+
668
+ **TC-004: Cache Invalidation**
669
+ - Given: Cached context exists
670
+ - When: Spec file modified
671
+ - Then: Cache invalidated
672
+ - And: Fresh context loaded
673
+ - And: New cache created
674
+
675
+ **TC-005: Token Budget Enforcement**
676
+ - Given: Manifest with max_tokens: 5000
677
+ - When: Specs total 7000 tokens
678
+ - Then: Lower priority items summarized or dropped
679
+ - And: Final total ≤ 5000 tokens
680
+ - And: User warned about budget constraint
681
+
682
+ **TC-006: Related Features**
683
+ - Given: Feature with related_features specified
684
+ - When: User requests related context
685
+ - Then: All related manifests loaded
686
+ - And: Common context identified
687
+ - And: Report generated
688
+
689
+ ## Resources
690
+
691
+ ### YAML Processing
692
+ - [js-yaml](https://github.com/nodeca/js-yaml) - YAML parser for JavaScript
693
+ - [yaml](https://www.npmjs.com/package/yaml) - Modern YAML parser
694
+ - [YAML Specification](https://yaml.org/spec/) - Official YAML spec
695
+
696
+ ### File Globbing
697
+ - [glob](https://github.com/isaacs/node-glob) - Match files using glob patterns
698
+ - [fast-glob](https://github.com/mrmlnc/fast-glob) - Fast file pattern matching
699
+ - [minimatch](https://github.com/isaacs/minimatch) - Glob pattern matcher
700
+
701
+ ### Markdown Processing
702
+ - [marked](https://marked.js.org/) - Markdown parser and compiler
703
+ - [remark](https://remark.js.org/) - Markdown processor powered by plugins
704
+ - [markdown-it](https://github.com/markdown-it/markdown-it) - Markdown parser
705
+
706
+ ### Caching
707
+ - [node-cache](https://github.com/node-cache/node-cache) - Simple caching module
708
+ - [lru-cache](https://github.com/isaacs/node-lru-cache) - Least Recently Used cache
709
+ - [flat-cache](https://github.com/jaredwray/flat-cache) - Flat file cache
710
+
711
+ ### Token Estimation
712
+ - [tiktoken](https://github.com/openai/tiktoken) - OpenAI's token counter
713
+ - [js-tiktoken](https://github.com/dqbd/tiktoken) - TikToken for JavaScript
714
+
715
+ ### Text Summarization
716
+ - [node-sumy](https://github.com/chunksnbits/node-sumy) - Text summarization
717
+ - [Hugging Face Transformers](https://huggingface.co/docs/transformers/) - Advanced summarization models
718
+
719
+ ---
720
+
721
+ ## Summary
722
+
723
+ The context-loader is SpecWeave's **precision context loading system** that:
724
+ - ✅ Loads only relevant specifications (not everything)
725
+ - ✅ Achieves 70%+ token reduction (constitution target)
726
+ - ✅ Supports section-level granularity (`#anchor`)
727
+ - ✅ Enables enterprise-scale specs (500+ pages) without bloat
728
+ - ✅ Caches for performance (<50ms cache hits)
729
+ - ✅ Auto-refreshes when specs change (optional)
730
+ - ✅ Manages token budgets intelligently
731
+
732
+ **User benefit**: Work on massive codebases with 500+ page specifications without exceeding context windows. Load exactly what you need, when you need it.
733
+
734
+ **Revolutionary impact**: Makes spec-driven development scalable to enterprise without sacrificing precision.