@girardmedia/bootspring 1.2.0 → 2.0.3

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 (253) hide show
  1. package/README.md +107 -14
  2. package/bin/bootspring.js +166 -27
  3. package/cli/agent.js +189 -17
  4. package/cli/analyze.js +499 -0
  5. package/cli/audit.js +557 -0
  6. package/cli/auth.js +495 -38
  7. package/cli/billing.js +302 -0
  8. package/cli/build.js +695 -0
  9. package/cli/business.js +109 -26
  10. package/cli/checkpoint-utils.js +168 -0
  11. package/cli/checkpoint.js +639 -0
  12. package/cli/cloud-sync.js +447 -0
  13. package/cli/content.js +198 -0
  14. package/cli/context.js +1 -1
  15. package/cli/deploy.js +543 -0
  16. package/cli/fundraise.js +112 -50
  17. package/cli/github-cmd.js +435 -0
  18. package/cli/health.js +477 -0
  19. package/cli/init.js +84 -13
  20. package/cli/legal.js +107 -95
  21. package/cli/log.js +2 -2
  22. package/cli/loop.js +976 -73
  23. package/cli/manager.js +711 -0
  24. package/cli/metrics.js +480 -0
  25. package/cli/monitor.js +812 -0
  26. package/cli/onboard.js +521 -0
  27. package/cli/orchestrator.js +12 -24
  28. package/cli/prd.js +594 -0
  29. package/cli/preseed-start.js +1483 -0
  30. package/cli/preseed.js +2302 -0
  31. package/cli/project.js +436 -0
  32. package/cli/quality.js +233 -0
  33. package/cli/security.js +913 -0
  34. package/cli/seed.js +1441 -5
  35. package/cli/skill.js +273 -211
  36. package/cli/suggest.js +989 -0
  37. package/cli/switch.js +453 -0
  38. package/cli/visualize.js +527 -0
  39. package/cli/watch.js +769 -0
  40. package/cli/workspace.js +607 -0
  41. package/core/analyze-workflow.js +1134 -0
  42. package/core/api-client.js +535 -22
  43. package/core/audit-workflow.js +1350 -0
  44. package/core/build-orchestrator.js +480 -0
  45. package/core/build-state.js +577 -0
  46. package/core/checkpoint-engine.js +408 -0
  47. package/core/config.js +1109 -26
  48. package/core/context-loader.js +21 -1
  49. package/core/deploy-workflow.js +836 -0
  50. package/core/entitlements.js +93 -22
  51. package/core/github-sync.js +610 -0
  52. package/core/index.js +8 -1
  53. package/core/ingest.js +1111 -0
  54. package/core/metrics-engine.js +768 -0
  55. package/core/onboard-workflow.js +1007 -0
  56. package/core/preseed-workflow.js +934 -0
  57. package/core/preseed.js +1617 -0
  58. package/core/project-context.js +325 -0
  59. package/core/project-state.js +694 -0
  60. package/core/r2-sync.js +583 -0
  61. package/core/scaffold.js +525 -7
  62. package/core/session.js +258 -0
  63. package/core/task-extractor.js +758 -0
  64. package/core/telemetry.js +28 -6
  65. package/core/tier-enforcement.js +737 -0
  66. package/core/utils.js +38 -14
  67. package/generators/questionnaire.js +15 -12
  68. package/generators/sections/ai.js +7 -7
  69. package/generators/sections/content.js +300 -0
  70. package/generators/sections/index.js +3 -0
  71. package/generators/sections/plugins.js +7 -6
  72. package/generators/templates/build-planning.template.js +596 -0
  73. package/generators/templates/content.template.js +819 -0
  74. package/generators/templates/index.js +2 -1
  75. package/hooks/git-autopilot.js +1250 -0
  76. package/hooks/index.js +9 -0
  77. package/intelligence/agent-collab.js +2057 -0
  78. package/intelligence/auto-suggest.js +634 -0
  79. package/intelligence/content-gen.js +1589 -0
  80. package/intelligence/cross-project.js +1647 -0
  81. package/intelligence/index.js +184 -0
  82. package/intelligence/learning/insights.json +517 -7
  83. package/intelligence/learning/pattern-learner.js +1008 -14
  84. package/intelligence/memory/decision-tracker.js +1431 -31
  85. package/intelligence/memory/decisions.jsonl +0 -0
  86. package/intelligence/orchestrator.js +2896 -1
  87. package/intelligence/prd.js +92 -1
  88. package/intelligence/recommendation-weights.json +14 -2
  89. package/intelligence/recommendations.js +463 -9
  90. package/intelligence/workflow-composer.js +1451 -0
  91. package/marketplace/index.d.ts +324 -0
  92. package/marketplace/index.js +1921 -0
  93. package/mcp/contracts/mcp-contract.v1.json +342 -4
  94. package/mcp/registry.js +680 -3
  95. package/mcp/response-formatter.js +23 -0
  96. package/mcp/tools/assist-tool.js +78 -4
  97. package/mcp/tools/autopilot-tool.js +408 -0
  98. package/mcp/tools/content-tool.js +571 -0
  99. package/mcp/tools/dashboard-tool.js +251 -5
  100. package/mcp/tools/mvp-tool.js +344 -0
  101. package/mcp/tools/plugin-tool.js +23 -1
  102. package/mcp/tools/prd-tool.js +579 -0
  103. package/mcp/tools/seed-tool.js +447 -0
  104. package/mcp/tools/skill-tool.js +43 -14
  105. package/mcp/tools/suggest-tool.js +147 -0
  106. package/package.json +15 -6
  107. package/agents/README.md +0 -93
  108. package/agents/ai-integration-expert/context.md +0 -386
  109. package/agents/api-expert/context.md +0 -416
  110. package/agents/architecture-expert/context.md +0 -454
  111. package/agents/auth-expert/context.md +0 -399
  112. package/agents/backend-expert/context.md +0 -483
  113. package/agents/business-strategy-expert/context.md +0 -180
  114. package/agents/code-review-expert/context.md +0 -365
  115. package/agents/competitive-analysis-expert/context.md +0 -239
  116. package/agents/data-modeling-expert/context.md +0 -352
  117. package/agents/database-expert/context.md +0 -250
  118. package/agents/devops-expert/context.md +0 -446
  119. package/agents/email-expert/context.md +0 -379
  120. package/agents/financial-expert/context.md +0 -213
  121. package/agents/frontend-expert/context.md +0 -364
  122. package/agents/fundraising-expert/context.md +0 -257
  123. package/agents/growth-expert/context.md +0 -249
  124. package/agents/index.js +0 -140
  125. package/agents/investor-relations-expert/context.md +0 -266
  126. package/agents/legal-expert/context.md +0 -284
  127. package/agents/marketing-expert/context.md +0 -236
  128. package/agents/monitoring-expert/context.md +0 -362
  129. package/agents/operations-expert/context.md +0 -279
  130. package/agents/partnerships-expert/context.md +0 -286
  131. package/agents/payment-expert/context.md +0 -340
  132. package/agents/performance-expert/context.md +0 -377
  133. package/agents/private-equity-expert/context.md +0 -246
  134. package/agents/railway-expert/context.md +0 -284
  135. package/agents/research-expert/context.md +0 -245
  136. package/agents/sales-expert/context.md +0 -241
  137. package/agents/security-expert/context.md +0 -343
  138. package/agents/testing-expert/context.md +0 -414
  139. package/agents/ui-ux-expert/context.md +0 -448
  140. package/agents/vercel-expert/context.md +0 -426
  141. package/skills/index.js +0 -787
  142. package/skills/patterns/README.md +0 -163
  143. package/skills/patterns/ai/agents.md +0 -281
  144. package/skills/patterns/ai/claude.md +0 -138
  145. package/skills/patterns/ai/embeddings.md +0 -150
  146. package/skills/patterns/ai/rag.md +0 -266
  147. package/skills/patterns/ai/streaming.md +0 -170
  148. package/skills/patterns/ai/structured-output.md +0 -162
  149. package/skills/patterns/ai/tools.md +0 -154
  150. package/skills/patterns/analytics/tracking.md +0 -220
  151. package/skills/patterns/api/errors.md +0 -296
  152. package/skills/patterns/api/graphql.md +0 -440
  153. package/skills/patterns/api/middleware.md +0 -279
  154. package/skills/patterns/api/openapi.md +0 -285
  155. package/skills/patterns/api/rate-limiting.md +0 -231
  156. package/skills/patterns/api/route-handler.md +0 -217
  157. package/skills/patterns/api/server-action.md +0 -249
  158. package/skills/patterns/api/versioning.md +0 -443
  159. package/skills/patterns/api/webhooks.md +0 -247
  160. package/skills/patterns/auth/clerk.md +0 -132
  161. package/skills/patterns/auth/mfa.md +0 -313
  162. package/skills/patterns/auth/nextauth.md +0 -140
  163. package/skills/patterns/auth/oauth.md +0 -237
  164. package/skills/patterns/auth/rbac.md +0 -152
  165. package/skills/patterns/auth/session-management.md +0 -367
  166. package/skills/patterns/auth/session.md +0 -120
  167. package/skills/patterns/database/audit.md +0 -177
  168. package/skills/patterns/database/migrations.md +0 -177
  169. package/skills/patterns/database/pagination.md +0 -230
  170. package/skills/patterns/database/pooling.md +0 -357
  171. package/skills/patterns/database/prisma.md +0 -180
  172. package/skills/patterns/database/relations.md +0 -187
  173. package/skills/patterns/database/seeding.md +0 -246
  174. package/skills/patterns/database/soft-delete.md +0 -153
  175. package/skills/patterns/database/transactions.md +0 -162
  176. package/skills/patterns/deployment/ci-cd.md +0 -231
  177. package/skills/patterns/deployment/docker.md +0 -188
  178. package/skills/patterns/deployment/monitoring.md +0 -387
  179. package/skills/patterns/deployment/vercel.md +0 -160
  180. package/skills/patterns/email/resend.md +0 -143
  181. package/skills/patterns/email/templates.md +0 -245
  182. package/skills/patterns/email/transactional.md +0 -503
  183. package/skills/patterns/email/verification.md +0 -176
  184. package/skills/patterns/files/download.md +0 -243
  185. package/skills/patterns/files/upload.md +0 -239
  186. package/skills/patterns/i18n/nextintl.md +0 -188
  187. package/skills/patterns/logging/structured.md +0 -292
  188. package/skills/patterns/notifications/email-queue.md +0 -248
  189. package/skills/patterns/notifications/push.md +0 -279
  190. package/skills/patterns/payments/checkout.md +0 -303
  191. package/skills/patterns/payments/invoices.md +0 -287
  192. package/skills/patterns/payments/portal.md +0 -245
  193. package/skills/patterns/payments/stripe.md +0 -272
  194. package/skills/patterns/payments/subscriptions.md +0 -300
  195. package/skills/patterns/payments/usage.md +0 -279
  196. package/skills/patterns/performance/caching.md +0 -276
  197. package/skills/patterns/performance/code-splitting.md +0 -233
  198. package/skills/patterns/performance/edge.md +0 -254
  199. package/skills/patterns/performance/isr.md +0 -266
  200. package/skills/patterns/performance/lazy-loading.md +0 -281
  201. package/skills/patterns/realtime/sse.md +0 -327
  202. package/skills/patterns/realtime/websockets.md +0 -336
  203. package/skills/patterns/search/filtering.md +0 -329
  204. package/skills/patterns/search/fulltext.md +0 -260
  205. package/skills/patterns/security/audit-logging.md +0 -444
  206. package/skills/patterns/security/csrf.md +0 -234
  207. package/skills/patterns/security/headers.md +0 -252
  208. package/skills/patterns/security/sanitization.md +0 -258
  209. package/skills/patterns/security/secrets.md +0 -261
  210. package/skills/patterns/security/validation.md +0 -268
  211. package/skills/patterns/security/xss.md +0 -229
  212. package/skills/patterns/seo/metadata.md +0 -252
  213. package/skills/patterns/state/context.md +0 -349
  214. package/skills/patterns/state/react-query.md +0 -313
  215. package/skills/patterns/state/url-state.md +0 -482
  216. package/skills/patterns/state/zustand.md +0 -262
  217. package/skills/patterns/testing/api.md +0 -259
  218. package/skills/patterns/testing/component.md +0 -233
  219. package/skills/patterns/testing/coverage.md +0 -207
  220. package/skills/patterns/testing/fixtures.md +0 -225
  221. package/skills/patterns/testing/integration.md +0 -436
  222. package/skills/patterns/testing/mocking.md +0 -177
  223. package/skills/patterns/testing/playwright.md +0 -162
  224. package/skills/patterns/testing/snapshot.md +0 -175
  225. package/skills/patterns/testing/vitest.md +0 -307
  226. package/skills/patterns/ui/accordions.md +0 -395
  227. package/skills/patterns/ui/cards.md +0 -299
  228. package/skills/patterns/ui/dropdowns.md +0 -476
  229. package/skills/patterns/ui/empty-states.md +0 -320
  230. package/skills/patterns/ui/forms.md +0 -405
  231. package/skills/patterns/ui/inputs.md +0 -319
  232. package/skills/patterns/ui/layouts.md +0 -282
  233. package/skills/patterns/ui/loading.md +0 -291
  234. package/skills/patterns/ui/modals.md +0 -338
  235. package/skills/patterns/ui/navigation.md +0 -374
  236. package/skills/patterns/ui/tables.md +0 -407
  237. package/skills/patterns/ui/toasts.md +0 -300
  238. package/skills/patterns/ui/tooltips.md +0 -396
  239. package/skills/patterns/utils/dates.md +0 -435
  240. package/skills/patterns/utils/errors.md +0 -451
  241. package/skills/patterns/utils/formatting.md +0 -345
  242. package/skills/patterns/utils/validation.md +0 -434
  243. package/templates/bootspring.config.js +0 -83
  244. package/templates/business/business-model-canvas.md +0 -246
  245. package/templates/business/business-plan.md +0 -266
  246. package/templates/business/competitive-analysis.md +0 -312
  247. package/templates/fundraising/data-room-checklist.md +0 -300
  248. package/templates/fundraising/investor-research.md +0 -243
  249. package/templates/fundraising/pitch-deck-outline.md +0 -253
  250. package/templates/legal/gdpr-checklist.md +0 -339
  251. package/templates/legal/privacy-policy.md +0 -285
  252. package/templates/legal/terms-of-service.md +0 -222
  253. package/templates/mcp.json +0 -9
@@ -0,0 +1,1589 @@
1
+ /**
2
+ * Bootspring AI-Assisted Content Generation
3
+ *
4
+ * Generates business and legal documents with AI enhancement.
5
+ * Uses context from the project to create relevant, customized content.
6
+ *
7
+ * Features:
8
+ * - Template-based document generation
9
+ * - AI enhancement prompts for intelligent customization
10
+ * - Project context integration
11
+ * - Multi-format output support
12
+ * - Validation and compliance checking
13
+ *
14
+ * @package bootspring
15
+ * @module intelligence/content-gen
16
+ */
17
+
18
+ const fs = require('fs');
19
+ const path = require('path');
20
+
21
+ // ============================================================================
22
+ // Document Templates Registry
23
+ // ============================================================================
24
+
25
+ /**
26
+ * Document templates for content generation
27
+ * Each template defines structure, sections, and AI enhancement capabilities
28
+ */
29
+ const DOCUMENT_TEMPLATES = {
30
+ // Legal Documents
31
+ 'privacy-policy': {
32
+ name: 'Privacy Policy',
33
+ category: 'legal',
34
+ description: 'GDPR/CCPA compliant privacy policy for web applications',
35
+ templateFile: 'legal/privacy-policy.md',
36
+ sections: [
37
+ 'introduction',
38
+ 'data-collection',
39
+ 'data-usage',
40
+ 'data-sharing',
41
+ 'data-retention',
42
+ 'data-security',
43
+ 'user-rights',
44
+ 'cookies',
45
+ 'children-privacy',
46
+ 'international-transfers',
47
+ 'policy-updates',
48
+ 'california-rights',
49
+ 'european-rights',
50
+ 'contact'
51
+ ],
52
+ requiredContext: ['project.name', 'project.description'],
53
+ placeholders: ['PROJECT_NAME', 'DATE', 'DOMAIN', 'ADDRESS', 'COUNTRY'],
54
+ compliance: ['GDPR', 'CCPA', 'COPPA']
55
+ },
56
+
57
+ 'terms-of-service': {
58
+ name: 'Terms of Service',
59
+ category: 'legal',
60
+ description: 'Standard terms of service agreement for SaaS applications',
61
+ templateFile: 'legal/terms-of-service.md',
62
+ sections: [
63
+ 'agreement',
64
+ 'service-description',
65
+ 'user-accounts',
66
+ 'acceptable-use',
67
+ 'intellectual-property',
68
+ 'payment-terms',
69
+ 'privacy',
70
+ 'third-party-services',
71
+ 'disclaimers',
72
+ 'limitation-of-liability',
73
+ 'indemnification',
74
+ 'dispute-resolution',
75
+ 'general-provisions',
76
+ 'changes-to-terms',
77
+ 'contact'
78
+ ],
79
+ requiredContext: ['project.name'],
80
+ placeholders: ['PROJECT_NAME', 'DATE', 'DOMAIN', 'ADDRESS', 'JURISDICTION'],
81
+ compliance: ['Consumer Protection', 'E-Commerce']
82
+ },
83
+
84
+ 'gdpr-checklist': {
85
+ name: 'GDPR Compliance Checklist',
86
+ category: 'legal',
87
+ description: 'GDPR compliance checklist and implementation guide',
88
+ templateFile: 'legal/gdpr-checklist.md',
89
+ sections: [
90
+ 'lawful-basis',
91
+ 'data-subject-rights',
92
+ 'consent-management',
93
+ 'data-protection',
94
+ 'breach-notification',
95
+ 'dpo-requirements',
96
+ 'data-processing-agreements',
97
+ 'international-transfers'
98
+ ],
99
+ requiredContext: ['project.name'],
100
+ placeholders: ['PROJECT_NAME', 'DATE'],
101
+ compliance: ['GDPR']
102
+ },
103
+
104
+ // Documentation
105
+ 'readme': {
106
+ name: 'README',
107
+ category: 'documentation',
108
+ description: 'Project README with setup instructions and documentation',
109
+ sections: [
110
+ 'title',
111
+ 'badges',
112
+ 'description',
113
+ 'features',
114
+ 'tech-stack',
115
+ 'prerequisites',
116
+ 'installation',
117
+ 'configuration',
118
+ 'usage',
119
+ 'api-reference',
120
+ 'testing',
121
+ 'deployment',
122
+ 'contributing',
123
+ 'license',
124
+ 'acknowledgments'
125
+ ],
126
+ requiredContext: ['project.name', 'project.description', 'stack.framework', 'stack.language']
127
+ },
128
+
129
+ 'contributing': {
130
+ name: 'Contributing Guide',
131
+ category: 'documentation',
132
+ description: 'Guide for project contributors with code standards',
133
+ sections: [
134
+ 'welcome',
135
+ 'code-of-conduct',
136
+ 'getting-started',
137
+ 'development-setup',
138
+ 'branch-strategy',
139
+ 'commit-conventions',
140
+ 'pull-request-process',
141
+ 'code-style',
142
+ 'testing-requirements',
143
+ 'documentation',
144
+ 'issue-reporting',
145
+ 'community'
146
+ ],
147
+ requiredContext: ['project.name']
148
+ },
149
+
150
+ 'api-documentation': {
151
+ name: 'API Documentation',
152
+ category: 'documentation',
153
+ description: 'RESTful API documentation with endpoint details',
154
+ sections: [
155
+ 'overview',
156
+ 'authentication',
157
+ 'base-url',
158
+ 'rate-limiting',
159
+ 'request-format',
160
+ 'response-format',
161
+ 'error-handling',
162
+ 'endpoints',
163
+ 'webhooks',
164
+ 'sdk-examples',
165
+ 'changelog'
166
+ ],
167
+ requiredContext: ['project.name', 'stack.framework']
168
+ },
169
+
170
+ 'changelog': {
171
+ name: 'Changelog',
172
+ category: 'documentation',
173
+ description: 'Version changelog following Keep a Changelog format',
174
+ sections: [
175
+ 'header',
176
+ 'unreleased',
177
+ 'versions'
178
+ ],
179
+ requiredContext: ['project.name', 'project.version']
180
+ },
181
+
182
+ // Business Documents
183
+ 'business-plan': {
184
+ name: 'Business Plan',
185
+ category: 'business',
186
+ description: 'Comprehensive business plan for investors and stakeholders',
187
+ templateFile: 'business/business-plan.md',
188
+ sections: [
189
+ 'executive-summary',
190
+ 'problem',
191
+ 'solution',
192
+ 'market-analysis',
193
+ 'competitive-analysis',
194
+ 'business-model',
195
+ 'go-to-market',
196
+ 'operations',
197
+ 'team',
198
+ 'financials',
199
+ 'risks',
200
+ 'milestones',
201
+ 'appendix'
202
+ ],
203
+ requiredContext: ['project.name', 'project.description'],
204
+ placeholders: ['PROJECT_NAME', 'DATE']
205
+ },
206
+
207
+ 'business-model-canvas': {
208
+ name: 'Business Model Canvas',
209
+ category: 'business',
210
+ description: 'One-page business model visualization',
211
+ templateFile: 'business/business-model-canvas.md',
212
+ sections: [
213
+ 'key-partners',
214
+ 'key-activities',
215
+ 'key-resources',
216
+ 'value-propositions',
217
+ 'customer-relationships',
218
+ 'channels',
219
+ 'customer-segments',
220
+ 'cost-structure',
221
+ 'revenue-streams'
222
+ ],
223
+ requiredContext: ['project.name', 'project.description']
224
+ },
225
+
226
+ 'competitive-analysis': {
227
+ name: 'Competitive Analysis',
228
+ category: 'business',
229
+ description: 'Market competition analysis and positioning',
230
+ templateFile: 'business/competitive-analysis.md',
231
+ sections: [
232
+ 'market-overview',
233
+ 'competitor-profiles',
234
+ 'swot-analysis',
235
+ 'positioning-matrix',
236
+ 'differentiation-strategy',
237
+ 'recommendations'
238
+ ],
239
+ requiredContext: ['project.name', 'project.description']
240
+ },
241
+
242
+ // Fundraising Documents
243
+ 'pitch-deck-outline': {
244
+ name: 'Pitch Deck Outline',
245
+ category: 'fundraising',
246
+ description: 'Investor pitch deck structure and talking points',
247
+ templateFile: 'fundraising/pitch-deck-outline.md',
248
+ sections: [
249
+ 'title-slide',
250
+ 'problem',
251
+ 'solution',
252
+ 'market-size',
253
+ 'product-demo',
254
+ 'business-model',
255
+ 'traction',
256
+ 'competition',
257
+ 'team',
258
+ 'financials',
259
+ 'ask',
260
+ 'closing'
261
+ ],
262
+ requiredContext: ['project.name', 'project.description']
263
+ },
264
+
265
+ 'investor-research': {
266
+ name: 'Investor Research Template',
267
+ category: 'fundraising',
268
+ description: 'Template for researching potential investors',
269
+ templateFile: 'fundraising/investor-research.md',
270
+ sections: [
271
+ 'investor-profile',
272
+ 'portfolio-companies',
273
+ 'investment-thesis',
274
+ 'contact-strategy',
275
+ 'pitch-customization'
276
+ ],
277
+ requiredContext: ['project.name']
278
+ },
279
+
280
+ 'data-room-checklist': {
281
+ name: 'Data Room Checklist',
282
+ category: 'fundraising',
283
+ description: 'Due diligence data room organization checklist',
284
+ templateFile: 'fundraising/data-room-checklist.md',
285
+ sections: [
286
+ 'corporate-documents',
287
+ 'financial-documents',
288
+ 'product-materials',
289
+ 'team-information',
290
+ 'legal-documents',
291
+ 'customer-data'
292
+ ],
293
+ requiredContext: ['project.name']
294
+ },
295
+
296
+ // Security Documents
297
+ 'security-policy': {
298
+ name: 'Security Policy',
299
+ category: 'security',
300
+ description: 'Security disclosure and vulnerability reporting policy',
301
+ sections: [
302
+ 'introduction',
303
+ 'scope',
304
+ 'reporting-vulnerabilities',
305
+ 'safe-harbor',
306
+ 'disclosure-process',
307
+ 'response-timeline',
308
+ 'recognition',
309
+ 'out-of-scope',
310
+ 'contact'
311
+ ],
312
+ requiredContext: ['project.name']
313
+ },
314
+
315
+ 'incident-response': {
316
+ name: 'Incident Response Plan',
317
+ category: 'security',
318
+ description: 'Security incident response procedures',
319
+ sections: [
320
+ 'purpose',
321
+ 'scope',
322
+ 'incident-classification',
323
+ 'response-team',
324
+ 'detection-analysis',
325
+ 'containment',
326
+ 'eradication',
327
+ 'recovery',
328
+ 'post-incident',
329
+ 'communication',
330
+ 'documentation'
331
+ ],
332
+ requiredContext: ['project.name']
333
+ }
334
+ };
335
+
336
+ // ============================================================================
337
+ // AI Enhancement Prompts
338
+ // ============================================================================
339
+
340
+ /**
341
+ * AI prompts for intelligent content enhancement
342
+ * These prompts help LLMs generate contextually relevant content
343
+ */
344
+ const AI_ENHANCEMENT_PROMPTS = {
345
+ 'privacy-policy': {
346
+ _base: (ctx) => `You are a privacy policy expert creating a GDPR and CCPA compliant privacy policy for "${ctx.projectName}", a ${ctx.framework || 'web'} application${ctx.projectDescription ? ` that ${ctx.projectDescription}` : ''}.`,
347
+
348
+ 'data-collection': (ctx) => `
349
+ Enhance the data collection section for ${ctx.projectName}. Consider:
350
+ - Framework: ${ctx.framework || 'web application'}
351
+ - Database: ${ctx.database || 'database storage'}
352
+ - Hosting: ${ctx.hosting || 'cloud hosting'}
353
+
354
+ List specific data types collected based on typical ${ctx.framework} applications:
355
+ 1. Account/authentication data
356
+ 2. Profile information
357
+ 3. Usage analytics
358
+ 4. Technical data (logs, device info)
359
+ 5. Any framework-specific data collection
360
+ `,
361
+
362
+ 'data-usage': (ctx) => `
363
+ Detail how ${ctx.projectName} uses collected data. Include:
364
+ - Primary service provision
365
+ - Analytics and improvement
366
+ - Communication purposes
367
+ - Personalization features
368
+ - Security and fraud prevention
369
+ Based on the ${ctx.framework} stack, mention relevant processing activities.
370
+ `,
371
+
372
+ 'data-security': (ctx) => `
373
+ Describe security measures for ${ctx.projectName} deployed on ${ctx.hosting || 'cloud infrastructure'}:
374
+ - Encryption (transit/rest)
375
+ - Access controls
376
+ - Infrastructure security
377
+ - Regular security assessments
378
+ - Incident response capabilities
379
+ `,
380
+
381
+ 'cookies': (ctx) => `
382
+ Generate a cookie disclosure section for ${ctx.projectName}:
383
+ - Essential cookies (authentication, security)
384
+ - Analytics cookies (if using analytics)
385
+ - Preference cookies
386
+ - Third-party cookies
387
+ - Cookie consent management
388
+ `
389
+ },
390
+
391
+ 'terms-of-service': {
392
+ _base: (ctx) => `You are a legal expert creating terms of service for "${ctx.projectName}", a ${ctx.framework || 'web'} application. Ensure the terms are clear, enforceable, and user-friendly.`,
393
+
394
+ 'service-description': (ctx) => `
395
+ Write a clear service description for ${ctx.projectName}:
396
+ ${ctx.projectDescription ? `Description: ${ctx.projectDescription}` : ''}
397
+ Framework: ${ctx.framework || 'web application'}
398
+
399
+ Include:
400
+ - What the service provides
401
+ - Key features and functionality
402
+ - Service availability
403
+ - Modifications and updates
404
+ `,
405
+
406
+ 'acceptable-use': (ctx) => `
407
+ Define acceptable use policies for ${ctx.projectName}:
408
+ - Permitted uses
409
+ - Prohibited activities
410
+ - Content standards (if applicable)
411
+ - Resource usage limits
412
+ - API usage guidelines (if applicable for ${ctx.framework})
413
+ `,
414
+
415
+ 'payment-terms': () => `
416
+ Create payment terms including:
417
+ - Pricing and billing cycles
418
+ - Payment methods accepted
419
+ - Refund policy
420
+ - Cancellation process
421
+ - Price changes
422
+ - Failed payments handling
423
+ `
424
+ },
425
+
426
+ 'readme': {
427
+ _base: (ctx) => `Create a professional README for "${ctx.projectName}", a ${ctx.framework} project using ${ctx.language}${ctx.projectDescription ? `. ${ctx.projectDescription}` : ''}.`,
428
+
429
+ 'features': (ctx) => `
430
+ List key features for ${ctx.projectName}:
431
+ ${ctx.projectDescription ? `Project focus: ${ctx.projectDescription}` : ''}
432
+ Framework: ${ctx.framework}
433
+ Language: ${ctx.language}
434
+
435
+ Include:
436
+ - Core functionality
437
+ - Technical capabilities
438
+ - User benefits
439
+ - Integration options
440
+ `,
441
+
442
+ 'installation': (ctx) => `
443
+ Create detailed installation instructions for a ${ctx.framework} project:
444
+ - Prerequisites (Node.js version, ${ctx.language} requirements)
445
+ - Package manager commands
446
+ - Database setup (${ctx.database || 'if applicable'})
447
+ - Environment configuration
448
+ - Development server startup
449
+ `,
450
+
451
+ 'configuration': (ctx) => `
452
+ Document configuration options:
453
+ - Environment variables
454
+ - Configuration files
455
+ - Database connection (${ctx.database || 'connection string'})
456
+ - Third-party service setup
457
+ - Deployment configuration for ${ctx.hosting || 'various platforms'}
458
+ `
459
+ },
460
+
461
+ 'api-documentation': {
462
+ _base: (ctx) => `Create comprehensive API documentation for "${ctx.projectName}", a ${ctx.framework} application.`,
463
+
464
+ 'authentication': (ctx) => `
465
+ Document authentication for ${ctx.projectName} API:
466
+ - Authentication method (Bearer token, API key, etc.)
467
+ - Token acquisition
468
+ - Token refresh process
469
+ - Rate limiting per authentication level
470
+ Based on ${ctx.framework} best practices.
471
+ `,
472
+
473
+ 'endpoints': (ctx) => `
474
+ Create endpoint documentation template for ${ctx.projectName}:
475
+ - RESTful conventions for ${ctx.framework}
476
+ - Request/response formats
477
+ - Query parameters
478
+ - Path parameters
479
+ - Error responses
480
+ - Example requests and responses
481
+ `
482
+ },
483
+
484
+ 'business-plan': {
485
+ _base: (ctx) => `Create a professional business plan for "${ctx.projectName}"${ctx.projectDescription ? `: ${ctx.projectDescription}` : ''}.`,
486
+
487
+ 'executive-summary': (ctx) => `
488
+ Write an executive summary for ${ctx.projectName}:
489
+ ${ctx.projectDescription ? `Description: ${ctx.projectDescription}` : ''}
490
+ Technology: ${ctx.framework} / ${ctx.language}
491
+
492
+ Include:
493
+ - Company overview (2-3 sentences)
494
+ - Problem being solved
495
+ - Solution approach
496
+ - Target market
497
+ - Business model highlights
498
+ - Traction/achievements
499
+ - Team strengths
500
+ - Funding requirements
501
+ `,
502
+
503
+ 'market-analysis': (ctx) => `
504
+ Analyze the market for ${ctx.projectName}:
505
+ ${ctx.projectDescription ? `Focus area: ${ctx.projectDescription}` : ''}
506
+
507
+ Consider:
508
+ - Total Addressable Market (TAM)
509
+ - Serviceable Addressable Market (SAM)
510
+ - Serviceable Obtainable Market (SOM)
511
+ - Market trends and growth
512
+ - Customer segments
513
+ - Market dynamics
514
+ `,
515
+
516
+ 'competitive-analysis': (ctx) => `
517
+ Analyze competition for ${ctx.projectName}:
518
+ ${ctx.projectDescription ? `Space: ${ctx.projectDescription}` : ''}
519
+
520
+ Include:
521
+ - Key competitors
522
+ - Competitive advantages
523
+ - Differentiation strategy
524
+ - Market positioning
525
+ - Barriers to entry
526
+ `
527
+ },
528
+
529
+ 'changelog': {
530
+ _base: (ctx) => `Generate changelog entries for "${ctx.projectName}" version ${ctx.projectVersion || '1.0.0'} following Keep a Changelog format.`,
531
+
532
+ 'versions': (ctx) => `
533
+ Create a changelog entry for ${ctx.projectName} v${ctx.projectVersion || '1.0.0'}:
534
+
535
+ Categories to include:
536
+ - Added (new features)
537
+ - Changed (changes to existing functionality)
538
+ - Deprecated (features to be removed)
539
+ - Removed (removed features)
540
+ - Fixed (bug fixes)
541
+ - Security (security improvements)
542
+
543
+ Follow semantic versioning principles.
544
+ `
545
+ },
546
+
547
+ 'security-policy': {
548
+ _base: (ctx) => `Create a security policy for "${ctx.projectName}", encouraging responsible disclosure.`,
549
+
550
+ 'scope': (ctx) => `
551
+ Define security research scope for ${ctx.projectName}:
552
+ Framework: ${ctx.framework}
553
+ Hosting: ${ctx.hosting || 'cloud'}
554
+
555
+ Include:
556
+ - In-scope domains and systems
557
+ - In-scope vulnerability types
558
+ - Out-of-scope areas
559
+ - Testing guidelines
560
+ - Safe harbor provisions
561
+ `,
562
+
563
+ 'response-timeline': () => `
564
+ Define response timeline:
565
+ - Initial acknowledgment time
566
+ - Triage timeline
567
+ - Resolution targets by severity
568
+ - Disclosure coordination
569
+ - Researcher notification process
570
+ `
571
+ }
572
+ };
573
+
574
+ // ============================================================================
575
+ // Section Content Generators
576
+ // ============================================================================
577
+
578
+ /**
579
+ * Default section content generators
580
+ * Used when template files are not available
581
+ */
582
+ const SECTION_CONTENT = {
583
+ 'privacy-policy': {
584
+ 'introduction': (ctx) => `
585
+ # Privacy Policy for ${ctx.projectName}
586
+
587
+ Last updated: ${new Date().toISOString().split('T')[0]}
588
+
589
+ This Privacy Policy describes how ${ctx.projectName} ("we", "us", or "our") collects, uses, and shares information about you when you use our services.
590
+
591
+ ## Overview
592
+
593
+ We are committed to protecting your privacy. This policy explains what information we collect, why we collect it, and how we use it.
594
+ `,
595
+ 'data-collection': () => `
596
+ ## Information We Collect
597
+
598
+ ### Information You Provide
599
+ - Account information (name, email, password)
600
+ - Profile information
601
+ - Payment information (processed securely by our payment provider)
602
+ - Communications with us
603
+
604
+ ### Information Collected Automatically
605
+ - Device information
606
+ - Log data (IP address, browser type, pages visited)
607
+ - Cookies and similar technologies
608
+ `,
609
+ 'data-usage': () => `
610
+ ## How We Use Your Information
611
+
612
+ We use the information we collect to:
613
+ - Provide, maintain, and improve our services
614
+ - Process transactions and send related information
615
+ - Send you technical notices and support messages
616
+ - Respond to your comments and questions
617
+ - Understand usage patterns and improve user experience
618
+ `,
619
+ 'data-sharing': () => `
620
+ ## Information Sharing
621
+
622
+ We do not sell your personal information. We may share information with:
623
+ - Service providers who assist in our operations
624
+ - Professional advisors (lawyers, accountants)
625
+ - Law enforcement when required by law
626
+ - Other parties in connection with a merger or acquisition
627
+ `,
628
+ 'data-retention': () => `
629
+ ## Data Retention
630
+
631
+ We retain your information for as long as:
632
+ - Your account is active
633
+ - Needed to provide services
634
+ - Required by law
635
+ - Necessary for legitimate business purposes
636
+
637
+ After account deletion, we may retain certain information as required by law.
638
+ `,
639
+ 'data-security': () => `
640
+ ## Data Security
641
+
642
+ We implement appropriate technical and organizational measures to protect your information:
643
+ - Encryption in transit and at rest
644
+ - Regular security assessments
645
+ - Access controls and monitoring
646
+ - Employee security training
647
+ `,
648
+ 'user-rights': () => `
649
+ ## Your Rights
650
+
651
+ You have the right to:
652
+ - Access your personal information
653
+ - Correct inaccurate information
654
+ - Request deletion of your information
655
+ - Object to processing of your information
656
+ - Data portability
657
+ - Withdraw consent
658
+
659
+ To exercise these rights, contact us at the address below.
660
+ `,
661
+ 'cookies': () => `
662
+ ## Cookies and Tracking
663
+
664
+ We use cookies and similar technologies to:
665
+ - Remember your preferences
666
+ - Understand how you use our service
667
+ - Improve your experience
668
+ - Provide analytics
669
+
670
+ You can control cookies through your browser settings.
671
+ `,
672
+ 'children-privacy': () => `
673
+ ## Children's Privacy
674
+
675
+ Our service is not intended for children under 13 (or applicable age of consent). We do not knowingly collect information from children. If we learn we have collected information from a child, we will delete it promptly.
676
+ `,
677
+ 'contact': (ctx) => `
678
+ ## Contact Us
679
+
680
+ If you have questions about this Privacy Policy, please contact us at:
681
+
682
+ ${ctx.projectName}
683
+ Email: privacy@${ctx.projectName.toLowerCase().replace(/\s+/g, '')}.com
684
+ `
685
+ },
686
+
687
+ 'readme': {
688
+ 'title': (ctx) => `# ${ctx.projectName}\n\n${ctx.projectDescription || 'A modern web application'}\n`,
689
+ 'badges': (ctx) => `
690
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
691
+ [![${ctx.framework || 'Framework'}](https://img.shields.io/badge/${(ctx.framework || 'framework').replace('-', '--')}-latest-brightgreen)](https://github.com)
692
+ `,
693
+ 'description': (ctx) => `
694
+ ## About
695
+
696
+ ${ctx.projectDescription || 'This project provides a comprehensive solution for...'}
697
+
698
+ Built with ${ctx.framework || 'modern technologies'} and ${ctx.language || 'TypeScript'}.
699
+ `,
700
+ 'features': () => `
701
+ ## Features
702
+
703
+ - Modern, responsive design
704
+ - Fast performance
705
+ - Secure authentication
706
+ - Real-time updates
707
+ - Easy deployment
708
+ `,
709
+ 'tech-stack': (ctx) => `
710
+ ## Tech Stack
711
+
712
+ - **Framework**: ${ctx.framework || 'Next.js'}
713
+ - **Language**: ${ctx.language || 'TypeScript'}
714
+ ${ctx.database ? `- **Database**: ${ctx.database}` : ''}
715
+ ${ctx.hosting ? `- **Hosting**: ${ctx.hosting}` : ''}
716
+ `,
717
+ 'prerequisites': (ctx) => `
718
+ ## Prerequisites
719
+
720
+ - Node.js 18.x or higher
721
+ - npm or yarn
722
+ ${ctx.database ? `- ${ctx.database} database` : ''}
723
+ `,
724
+ 'installation': () => `
725
+ ## Installation
726
+
727
+ \`\`\`bash
728
+ # Clone the repository
729
+ git clone <repository-url>
730
+
731
+ # Install dependencies
732
+ npm install
733
+
734
+ # Set up environment variables
735
+ cp .env.example .env.local
736
+
737
+ # Run database migrations (if applicable)
738
+ npm run db:migrate
739
+
740
+ # Start development server
741
+ npm run dev
742
+ \`\`\`
743
+ `,
744
+ 'configuration': () => `
745
+ ## Configuration
746
+
747
+ Create a \`.env.local\` file with the following variables:
748
+
749
+ \`\`\`env
750
+ DATABASE_URL=
751
+ NEXT_PUBLIC_API_URL=
752
+ # Add other environment variables
753
+ \`\`\`
754
+ `,
755
+ 'usage': () => `
756
+ ## Usage
757
+
758
+ \`\`\`bash
759
+ # Development
760
+ npm run dev
761
+
762
+ # Build for production
763
+ npm run build
764
+
765
+ # Run production server
766
+ npm start
767
+
768
+ # Run tests
769
+ npm test
770
+ \`\`\`
771
+ `,
772
+ 'contributing': () => `
773
+ ## Contributing
774
+
775
+ Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details.
776
+ `,
777
+ 'license': () => `
778
+ ## License
779
+
780
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
781
+ `
782
+ },
783
+
784
+ 'changelog': {
785
+ 'header': (ctx) => `# Changelog
786
+
787
+ All notable changes to ${ctx.projectName} will be documented in this file.
788
+
789
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
790
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
791
+ `,
792
+ 'unreleased': () => `
793
+ ## [Unreleased]
794
+
795
+ ### Added
796
+ -
797
+
798
+ ### Changed
799
+ -
800
+
801
+ ### Fixed
802
+ -
803
+ `,
804
+ 'versions': (ctx) => `
805
+ ## [${ctx.projectVersion || '1.0.0'}] - ${new Date().toISOString().split('T')[0]}
806
+
807
+ ### Added
808
+ - Initial release
809
+ `
810
+ },
811
+
812
+ 'contributing': {
813
+ 'welcome': (ctx) => `# Contributing to ${ctx.projectName}
814
+
815
+ Thank you for your interest in contributing! This document provides guidelines and information about contributing to this project.
816
+ `,
817
+ 'code-of-conduct': () => `
818
+ ## Code of Conduct
819
+
820
+ Please read and follow our Code of Conduct. We expect all contributors to be respectful and inclusive.
821
+ `,
822
+ 'getting-started': () => `
823
+ ## Getting Started
824
+
825
+ 1. Fork the repository
826
+ 2. Clone your fork
827
+ 3. Create a feature branch
828
+ 4. Make your changes
829
+ 5. Submit a pull request
830
+ `,
831
+ 'development-setup': () => `
832
+ ## Development Setup
833
+
834
+ \`\`\`bash
835
+ # Clone the repository
836
+ git clone <your-fork-url>
837
+
838
+ # Install dependencies
839
+ npm install
840
+
841
+ # Start development server
842
+ npm run dev
843
+ \`\`\`
844
+ `,
845
+ 'commit-conventions': () => `
846
+ ## Commit Conventions
847
+
848
+ We follow conventional commits:
849
+
850
+ - \`feat:\` New features
851
+ - \`fix:\` Bug fixes
852
+ - \`docs:\` Documentation changes
853
+ - \`refactor:\` Code refactoring
854
+ - \`test:\` Test additions or changes
855
+ - \`chore:\` Maintenance tasks
856
+ `,
857
+ 'pull-request-process': () => `
858
+ ## Pull Request Process
859
+
860
+ 1. Ensure your code follows our style guidelines
861
+ 2. Update documentation as needed
862
+ 3. Add tests for new functionality
863
+ 4. Ensure all tests pass
864
+ 5. Request review from maintainers
865
+ `
866
+ },
867
+
868
+ 'security-policy': {
869
+ 'introduction': (ctx) => `# Security Policy for ${ctx.projectName}
870
+
871
+ We take security seriously. This document outlines how to report vulnerabilities and our commitment to security researchers.
872
+ `,
873
+ 'scope': () => `
874
+ ## Scope
875
+
876
+ ### In Scope
877
+ - Main application and APIs
878
+ - Authentication and authorization
879
+ - Data handling and storage
880
+ - Infrastructure vulnerabilities
881
+
882
+ ### Out of Scope
883
+ - Third-party services
884
+ - Social engineering attacks
885
+ - Physical security
886
+ - Denial of service attacks
887
+ `,
888
+ 'reporting-vulnerabilities': () => `
889
+ ## Reporting Vulnerabilities
890
+
891
+ Please report security vulnerabilities by emailing security@[domain].com
892
+
893
+ Include:
894
+ - Description of the vulnerability
895
+ - Steps to reproduce
896
+ - Potential impact
897
+ - Suggested remediation (optional)
898
+ `,
899
+ 'safe-harbor': () => `
900
+ ## Safe Harbor
901
+
902
+ We consider security research conducted in good faith to be authorized. We will not pursue legal action against researchers who:
903
+ - Act in good faith
904
+ - Avoid privacy violations
905
+ - Do not destroy data
906
+ - Report findings promptly
907
+ `,
908
+ 'response-timeline': () => `
909
+ ## Response Timeline
910
+
911
+ - Initial response: Within 24 hours
912
+ - Triage and assessment: Within 72 hours
913
+ - Resolution timeline: Based on severity
914
+ - Researcher notification: Upon fix deployment
915
+ `,
916
+ 'recognition': () => `
917
+ ## Recognition
918
+
919
+ We appreciate security researchers who help improve our security. We offer:
920
+ - Public acknowledgment (with permission)
921
+ - Hall of fame listing
922
+ - Security research swag (where available)
923
+ `
924
+ }
925
+ };
926
+
927
+ // ============================================================================
928
+ // Customization Options
929
+ // ============================================================================
930
+
931
+ /**
932
+ * Customization options for document generation
933
+ */
934
+ const CUSTOMIZATION_OPTIONS = {
935
+ legal: {
936
+ jurisdiction: ['US', 'EU', 'UK', 'CA', 'AU', 'INTL'],
937
+ compliance: ['GDPR', 'CCPA', 'COPPA', 'HIPAA', 'SOC2'],
938
+ businessType: ['saas', 'marketplace', 'api', 'mobile', 'enterprise'],
939
+ dataTypes: ['personal', 'financial', 'health', 'biometric', 'children']
940
+ },
941
+ documentation: {
942
+ format: ['markdown', 'mdx', 'rst', 'asciidoc'],
943
+ style: ['technical', 'beginner-friendly', 'enterprise'],
944
+ includeExamples: true,
945
+ includeDiagrams: false
946
+ },
947
+ business: {
948
+ stage: ['idea', 'mvp', 'growth', 'scale'],
949
+ funding: ['bootstrapped', 'pre-seed', 'seed', 'series-a'],
950
+ model: ['b2b', 'b2c', 'b2b2c', 'marketplace']
951
+ }
952
+ };
953
+
954
+ // ============================================================================
955
+ // Core Functions
956
+ // ============================================================================
957
+
958
+ /**
959
+ * Get paths for content generation
960
+ */
961
+ function getPaths() {
962
+ const projectRoot = process.cwd();
963
+ return {
964
+ projectRoot,
965
+ templatesDir: path.join(__dirname, '..', 'templates'),
966
+ outputDir: path.join(projectRoot, 'docs'),
967
+ generatedDir: path.join(projectRoot, '.bootspring', 'generated')
968
+ };
969
+ }
970
+
971
+ /**
972
+ * Load project context for content generation
973
+ */
974
+ function loadProjectContext() {
975
+ const paths = getPaths();
976
+
977
+ // Try to load bootspring config
978
+ let config = {};
979
+ const configPath = path.join(paths.projectRoot, 'bootspring.config.js');
980
+ if (fs.existsSync(configPath)) {
981
+ try {
982
+ delete require.cache[require.resolve(configPath)];
983
+ config = require(configPath);
984
+ } catch {
985
+ // Ignore config load errors
986
+ }
987
+ }
988
+
989
+ // Try to load package.json
990
+ let pkg = {};
991
+ const pkgPath = path.join(paths.projectRoot, 'package.json');
992
+ if (fs.existsSync(pkgPath)) {
993
+ try {
994
+ pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
995
+ } catch {
996
+ // Ignore package.json load errors
997
+ }
998
+ }
999
+
1000
+ return {
1001
+ projectName: config.project?.name || pkg.name || 'My Project',
1002
+ projectDescription: config.project?.description || pkg.description || '',
1003
+ projectVersion: config.project?.version || pkg.version || '1.0.0',
1004
+ framework: config.stack?.framework || 'nextjs',
1005
+ language: config.stack?.language || 'typescript',
1006
+ database: config.stack?.database || null,
1007
+ hosting: config.stack?.hosting || 'vercel',
1008
+ plugins: config.plugins || {},
1009
+ author: pkg.author || '',
1010
+ license: pkg.license || 'MIT',
1011
+ repository: pkg.repository?.url || pkg.repository || ''
1012
+ };
1013
+ }
1014
+
1015
+ /**
1016
+ * Load template file content
1017
+ * Thin client: templates are served from API
1018
+ * @param {string} templateFile - Relative path to template file
1019
+ * @returns {string|null} Template content or null
1020
+ */
1021
+ function loadTemplateFile(templateFile) {
1022
+ const paths = getPaths();
1023
+ const templatePath = path.join(paths.templatesDir, templateFile);
1024
+
1025
+ // Check local first (for development)
1026
+ if (fs.existsSync(templatePath)) {
1027
+ return fs.readFileSync(templatePath, 'utf8');
1028
+ }
1029
+
1030
+ // Thin client: templates not bundled, return null
1031
+ // Templates should be fetched async via API in calling code
1032
+ return null;
1033
+ }
1034
+
1035
+ /**
1036
+ * Replace placeholders in template content
1037
+ * @param {string} content - Template content
1038
+ * @param {object} ctx - Project context
1039
+ * @param {object} options - Additional options
1040
+ */
1041
+ function replacePlaceholders(content, ctx, options = {}) {
1042
+ const date = new Date().toISOString().split('T')[0];
1043
+ const domain = ctx.projectName.toLowerCase().replace(/\s+/g, '') + '.com';
1044
+
1045
+ const replacements = {
1046
+ '{{PROJECT_NAME}}': ctx.projectName,
1047
+ '{{DATE}}': date,
1048
+ '{{DOMAIN}}': options.domain || domain,
1049
+ '{{ADDRESS}}': options.address || '[Your Address]',
1050
+ '{{COUNTRY}}': options.country || '[Your Country]',
1051
+ '{{JURISDICTION}}': options.jurisdiction || '[Your Jurisdiction]',
1052
+ '{{VERSION}}': ctx.projectVersion,
1053
+ '{{AUTHOR}}': ctx.author || '[Your Name]',
1054
+ '{{LICENSE}}': ctx.license
1055
+ };
1056
+
1057
+ let result = content;
1058
+ for (const [placeholder, value] of Object.entries(replacements)) {
1059
+ result = result.replace(new RegExp(placeholder.replace(/[{}]/g, '\\$&'), 'g'), value);
1060
+ }
1061
+
1062
+ return result;
1063
+ }
1064
+
1065
+ /**
1066
+ * List available document templates
1067
+ */
1068
+ function listTemplates(options = {}) {
1069
+ const templates = Object.entries(DOCUMENT_TEMPLATES)
1070
+ .filter(([_key, template]) => {
1071
+ if (options.category) {
1072
+ return template.category === options.category;
1073
+ }
1074
+ return true;
1075
+ })
1076
+ .map(([key, template]) => ({
1077
+ key,
1078
+ name: template.name,
1079
+ category: template.category,
1080
+ description: template.description,
1081
+ sections: template.sections.length,
1082
+ hasTemplateFile: !!template.templateFile,
1083
+ compliance: template.compliance || []
1084
+ }));
1085
+
1086
+ return templates;
1087
+ }
1088
+
1089
+ /**
1090
+ * Get template by key
1091
+ */
1092
+ function getTemplate(templateKey) {
1093
+ return DOCUMENT_TEMPLATES[templateKey] || null;
1094
+ }
1095
+
1096
+ /**
1097
+ * Get available categories
1098
+ */
1099
+ function getCategories() {
1100
+ const categories = new Set();
1101
+ Object.values(DOCUMENT_TEMPLATES).forEach(t => categories.add(t.category));
1102
+ return Array.from(categories);
1103
+ }
1104
+
1105
+ /**
1106
+ * Generate a document from a template
1107
+ * @param {string} templateKey - Template key
1108
+ * @param {object} options - Generation options
1109
+ */
1110
+ function generateDocument(templateKey, options = {}) {
1111
+ const template = DOCUMENT_TEMPLATES[templateKey];
1112
+ if (!template) {
1113
+ return { success: false, error: `Unknown template: ${templateKey}` };
1114
+ }
1115
+
1116
+ const context = loadProjectContext();
1117
+ const mergedContext = { ...context, ...options.context };
1118
+
1119
+ let content = '';
1120
+
1121
+ // Try to load from template file first
1122
+ if (template.templateFile) {
1123
+ const templateContent = loadTemplateFile(template.templateFile);
1124
+ if (templateContent) {
1125
+ content = replacePlaceholders(templateContent, mergedContext, options);
1126
+ }
1127
+ }
1128
+
1129
+ // If no template file or not found, generate from sections
1130
+ if (!content) {
1131
+ const sections = [];
1132
+ const sectionTemplates = SECTION_CONTENT[templateKey] || {};
1133
+
1134
+ for (const sectionKey of template.sections) {
1135
+ const sectionGenerator = sectionTemplates[sectionKey];
1136
+ if (sectionGenerator) {
1137
+ sections.push({
1138
+ key: sectionKey,
1139
+ content: sectionGenerator(mergedContext)
1140
+ });
1141
+ } else {
1142
+ // Default section placeholder
1143
+ sections.push({
1144
+ key: sectionKey,
1145
+ content: `\n## ${formatSectionTitle(sectionKey)}\n\n[Content for ${sectionKey} section]\n`
1146
+ });
1147
+ }
1148
+ }
1149
+
1150
+ content = sections.map(s => s.content.trim()).join('\n\n');
1151
+ }
1152
+
1153
+ // Add generated footer
1154
+ content += '\n\n---\n\n*Generated by Bootspring*\n';
1155
+
1156
+ // Validate content
1157
+ const validation = validateContent(content, templateKey);
1158
+
1159
+ // Save if requested
1160
+ if (options.save) {
1161
+ const paths = getPaths();
1162
+ const outputDir = options.outputDir || paths.outputDir;
1163
+
1164
+ if (!fs.existsSync(outputDir)) {
1165
+ fs.mkdirSync(outputDir, { recursive: true });
1166
+ }
1167
+
1168
+ const filename = options.filename || `${templateKey}.md`;
1169
+ const outputPath = path.join(outputDir, filename);
1170
+ fs.writeFileSync(outputPath, content, 'utf8');
1171
+
1172
+ // Track generation
1173
+ trackGeneration({
1174
+ template: templateKey,
1175
+ outputPath,
1176
+ sections: template.sections.length
1177
+ });
1178
+
1179
+ return {
1180
+ success: true,
1181
+ template: templateKey,
1182
+ outputPath,
1183
+ sections: template.sections.length,
1184
+ content,
1185
+ validation
1186
+ };
1187
+ }
1188
+
1189
+ return {
1190
+ success: true,
1191
+ template: templateKey,
1192
+ sections: template.sections.length,
1193
+ content,
1194
+ validation
1195
+ };
1196
+ }
1197
+
1198
+ /**
1199
+ * Generate multiple documents at once
1200
+ * @param {string[]} templateKeys - Array of template keys
1201
+ * @param {object} options - Generation options
1202
+ */
1203
+ function generateDocuments(templateKeys, options = {}) {
1204
+ const results = [];
1205
+
1206
+ for (const key of templateKeys) {
1207
+ const result = generateDocument(key, { ...options, save: true });
1208
+ results.push({
1209
+ template: key,
1210
+ success: result.success,
1211
+ outputPath: result.outputPath,
1212
+ error: result.error
1213
+ });
1214
+ }
1215
+
1216
+ return {
1217
+ success: results.every(r => r.success),
1218
+ generated: results.filter(r => r.success).length,
1219
+ failed: results.filter(r => !r.success).length,
1220
+ results
1221
+ };
1222
+ }
1223
+
1224
+ /**
1225
+ * Generate documents by category
1226
+ * @param {string} category - Document category
1227
+ * @param {object} options - Generation options
1228
+ */
1229
+ function generateByCategory(category, options = {}) {
1230
+ const templates = listTemplates({ category });
1231
+ const templateKeys = templates.map(t => t.key);
1232
+ return generateDocuments(templateKeys, options);
1233
+ }
1234
+
1235
+ /**
1236
+ * Format section title from key
1237
+ */
1238
+ function formatSectionTitle(key) {
1239
+ return key
1240
+ .split('-')
1241
+ .map(word => word.charAt(0).toUpperCase() + word.slice(1))
1242
+ .join(' ');
1243
+ }
1244
+
1245
+ // ============================================================================
1246
+ // AI Enhancement
1247
+ // ============================================================================
1248
+
1249
+ /**
1250
+ * Get AI enhancement prompt for a template/section
1251
+ * @param {string} templateKey - Template key
1252
+ * @param {string} sectionKey - Section to enhance (optional)
1253
+ */
1254
+ function getEnhancementPrompt(templateKey, sectionKey = null) {
1255
+ const template = DOCUMENT_TEMPLATES[templateKey];
1256
+ if (!template) {
1257
+ return { success: false, error: `Unknown template: ${templateKey}` };
1258
+ }
1259
+
1260
+ const context = loadProjectContext();
1261
+ const templatePrompts = AI_ENHANCEMENT_PROMPTS[templateKey];
1262
+
1263
+ if (!templatePrompts) {
1264
+ return {
1265
+ success: true,
1266
+ prompt: `Generate content for a ${template.name} document for ${context.projectName}. ${context.projectDescription || ''}`,
1267
+ context,
1268
+ generic: true
1269
+ };
1270
+ }
1271
+
1272
+ // Get base context prompt
1273
+ const basePrompt = templatePrompts._base ? templatePrompts._base(context) : '';
1274
+
1275
+ // If no specific section requested, return full document prompt
1276
+ if (!sectionKey) {
1277
+ const allSections = template.sections
1278
+ .map(s => `- ${formatSectionTitle(s)}`)
1279
+ .join('\n');
1280
+
1281
+ return {
1282
+ success: true,
1283
+ prompt: `${basePrompt}
1284
+
1285
+ Generate a complete ${template.name} with the following sections:
1286
+ ${allSections}
1287
+
1288
+ Project context:
1289
+ - Name: ${context.projectName}
1290
+ - Description: ${context.projectDescription || 'N/A'}
1291
+ - Framework: ${context.framework}
1292
+ - Language: ${context.language}
1293
+ - Database: ${context.database || 'N/A'}
1294
+ - Hosting: ${context.hosting || 'N/A'}
1295
+ `,
1296
+ context,
1297
+ sections: template.sections,
1298
+ generic: false
1299
+ };
1300
+ }
1301
+
1302
+ // Get section-specific prompt
1303
+ const sectionPrompt = templatePrompts[sectionKey];
1304
+
1305
+ if (!sectionPrompt) {
1306
+ return {
1307
+ success: true,
1308
+ prompt: `${basePrompt}
1309
+
1310
+ Enhance the "${formatSectionTitle(sectionKey)}" section.`,
1311
+ context,
1312
+ section: sectionKey,
1313
+ generic: true
1314
+ };
1315
+ }
1316
+
1317
+ return {
1318
+ success: true,
1319
+ prompt: `${basePrompt}
1320
+
1321
+ ${sectionPrompt(context)}`,
1322
+ context,
1323
+ section: sectionKey,
1324
+ generic: false
1325
+ };
1326
+ }
1327
+
1328
+ /**
1329
+ * Get AI prompts for all sections of a template
1330
+ * @param {string} templateKey - Template key
1331
+ */
1332
+ function getAllEnhancementPrompts(templateKey) {
1333
+ const template = DOCUMENT_TEMPLATES[templateKey];
1334
+ if (!template) {
1335
+ return { success: false, error: `Unknown template: ${templateKey}` };
1336
+ }
1337
+
1338
+ const prompts = [];
1339
+ for (const section of template.sections) {
1340
+ const result = getEnhancementPrompt(templateKey, section);
1341
+ prompts.push({
1342
+ section,
1343
+ title: formatSectionTitle(section),
1344
+ ...result
1345
+ });
1346
+ }
1347
+
1348
+ return {
1349
+ success: true,
1350
+ template: templateKey,
1351
+ templateName: template.name,
1352
+ prompts
1353
+ };
1354
+ }
1355
+
1356
+ // ============================================================================
1357
+ // Validation
1358
+ // ============================================================================
1359
+
1360
+ /**
1361
+ * Validate generated content
1362
+ * @param {string} content - Content to validate
1363
+ * @param {string} templateKey - Template key for validation rules
1364
+ */
1365
+ function validateContent(content, templateKey) {
1366
+ const issues = [];
1367
+ const template = DOCUMENT_TEMPLATES[templateKey];
1368
+
1369
+ // Check for placeholder content
1370
+ if (content.includes('[Content for')) {
1371
+ issues.push({
1372
+ type: 'placeholder',
1373
+ severity: 'warning',
1374
+ message: 'Content contains placeholder sections that need to be filled'
1375
+ });
1376
+ }
1377
+
1378
+ // Check for unfilled placeholders
1379
+ const unfilled = content.match(/\[.*?\]/g) || [];
1380
+ if (unfilled.length > 3) {
1381
+ issues.push({
1382
+ type: 'unfilled-placeholders',
1383
+ severity: 'warning',
1384
+ message: `Content contains ${unfilled.length} unfilled placeholders`
1385
+ });
1386
+ }
1387
+
1388
+ // Check for minimum length
1389
+ if (content.length < 500) {
1390
+ issues.push({
1391
+ type: 'length',
1392
+ severity: 'warning',
1393
+ message: 'Content may be too short for a complete document'
1394
+ });
1395
+ }
1396
+
1397
+ // Template-specific checks
1398
+ if (templateKey === 'privacy-policy') {
1399
+ const requiredTerms = ['data', 'privacy', 'information', 'rights', 'contact', 'collect'];
1400
+ for (const term of requiredTerms) {
1401
+ if (!content.toLowerCase().includes(term)) {
1402
+ issues.push({
1403
+ type: 'missing-content',
1404
+ severity: 'error',
1405
+ message: `Privacy policy should include "${term}" related content`
1406
+ });
1407
+ }
1408
+ }
1409
+
1410
+ // Check for compliance mentions
1411
+ const compliance = template.compliance || [];
1412
+ const missingCompliance = compliance.filter(c =>
1413
+ !content.toUpperCase().includes(c)
1414
+ );
1415
+ if (missingCompliance.length > 0) {
1416
+ issues.push({
1417
+ type: 'compliance',
1418
+ severity: 'warning',
1419
+ message: `Consider adding ${missingCompliance.join(', ')} compliance sections`
1420
+ });
1421
+ }
1422
+ }
1423
+
1424
+ if (templateKey === 'terms-of-service') {
1425
+ const requiredTerms = ['terms', 'service', 'liability', 'termination', 'agreement'];
1426
+ for (const term of requiredTerms) {
1427
+ if (!content.toLowerCase().includes(term)) {
1428
+ issues.push({
1429
+ type: 'missing-content',
1430
+ severity: 'error',
1431
+ message: `Terms of service should include "${term}" related content`
1432
+ });
1433
+ }
1434
+ }
1435
+ }
1436
+
1437
+ if (templateKey === 'readme') {
1438
+ const requiredSections = ['installation', 'usage', 'license'];
1439
+ for (const section of requiredSections) {
1440
+ if (!content.toLowerCase().includes(section)) {
1441
+ issues.push({
1442
+ type: 'missing-section',
1443
+ severity: 'warning',
1444
+ message: `README should include "${section}" section`
1445
+ });
1446
+ }
1447
+ }
1448
+ }
1449
+
1450
+ return {
1451
+ valid: issues.filter(i => i.severity === 'error').length === 0,
1452
+ issues,
1453
+ score: Math.max(0, 100 - (issues.length * 10))
1454
+ };
1455
+ }
1456
+
1457
+ // ============================================================================
1458
+ // State Management
1459
+ // ============================================================================
1460
+
1461
+ /**
1462
+ * Get content generation state
1463
+ */
1464
+ function getGenerationState() {
1465
+ const paths = getPaths();
1466
+ const statePath = path.join(paths.generatedDir, 'content-state.json');
1467
+
1468
+ if (fs.existsSync(statePath)) {
1469
+ try {
1470
+ return JSON.parse(fs.readFileSync(statePath, 'utf8'));
1471
+ } catch {
1472
+ return createDefaultState();
1473
+ }
1474
+ }
1475
+ return createDefaultState();
1476
+ }
1477
+
1478
+ /**
1479
+ * Create default generation state
1480
+ */
1481
+ function createDefaultState() {
1482
+ return {
1483
+ generatedDocuments: [],
1484
+ lastGeneration: null,
1485
+ context: null,
1486
+ statistics: {
1487
+ totalGenerated: 0,
1488
+ byCategory: {},
1489
+ byTemplate: {}
1490
+ }
1491
+ };
1492
+ }
1493
+
1494
+ /**
1495
+ * Save generation state
1496
+ */
1497
+ function saveGenerationState(state) {
1498
+ const paths = getPaths();
1499
+ const stateDir = paths.generatedDir;
1500
+
1501
+ if (!fs.existsSync(stateDir)) {
1502
+ fs.mkdirSync(stateDir, { recursive: true });
1503
+ }
1504
+
1505
+ const statePath = path.join(stateDir, 'content-state.json');
1506
+ state.lastUpdated = new Date().toISOString();
1507
+ fs.writeFileSync(statePath, JSON.stringify(state, null, 2));
1508
+ }
1509
+
1510
+ /**
1511
+ * Track generated document
1512
+ * @param {object} result - Generation result
1513
+ */
1514
+ function trackGeneration(result) {
1515
+ const state = getGenerationState();
1516
+ const template = DOCUMENT_TEMPLATES[result.template];
1517
+
1518
+ state.generatedDocuments.push({
1519
+ template: result.template,
1520
+ category: template?.category || 'unknown',
1521
+ outputPath: result.outputPath,
1522
+ generatedAt: new Date().toISOString(),
1523
+ sections: result.sections
1524
+ });
1525
+
1526
+ // Update statistics
1527
+ state.statistics.totalGenerated++;
1528
+ state.statistics.byCategory[template?.category] =
1529
+ (state.statistics.byCategory[template?.category] || 0) + 1;
1530
+ state.statistics.byTemplate[result.template] =
1531
+ (state.statistics.byTemplate[result.template] || 0) + 1;
1532
+
1533
+ state.lastGeneration = new Date().toISOString();
1534
+ state.context = loadProjectContext();
1535
+
1536
+ saveGenerationState(state);
1537
+ }
1538
+
1539
+ /**
1540
+ * Get generation statistics
1541
+ */
1542
+ function getStatistics() {
1543
+ const state = getGenerationState();
1544
+ return {
1545
+ totalGenerated: state.statistics.totalGenerated,
1546
+ byCategory: state.statistics.byCategory,
1547
+ byTemplate: state.statistics.byTemplate,
1548
+ lastGeneration: state.lastGeneration,
1549
+ recentDocuments: state.generatedDocuments.slice(-10)
1550
+ };
1551
+ }
1552
+
1553
+ // ============================================================================
1554
+ // Exports
1555
+ // ============================================================================
1556
+
1557
+ module.exports = {
1558
+ // Template management
1559
+ listTemplates,
1560
+ getTemplate,
1561
+ getCategories,
1562
+
1563
+ // Document generation
1564
+ generateDocument,
1565
+ generateDocuments,
1566
+ generateByCategory,
1567
+
1568
+ // AI enhancement
1569
+ getEnhancementPrompt,
1570
+ getAllEnhancementPrompts,
1571
+
1572
+ // Validation
1573
+ validateContent,
1574
+
1575
+ // Context
1576
+ loadProjectContext,
1577
+
1578
+ // State management
1579
+ getGenerationState,
1580
+ trackGeneration,
1581
+ getStatistics,
1582
+
1583
+ // Customization
1584
+ CUSTOMIZATION_OPTIONS,
1585
+
1586
+ // Constants
1587
+ DOCUMENT_TEMPLATES,
1588
+ AI_ENHANCEMENT_PROMPTS
1589
+ };