@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.
- package/README.md +107 -14
- package/bin/bootspring.js +166 -27
- package/cli/agent.js +189 -17
- package/cli/analyze.js +499 -0
- package/cli/audit.js +557 -0
- package/cli/auth.js +495 -38
- package/cli/billing.js +302 -0
- package/cli/build.js +695 -0
- package/cli/business.js +109 -26
- package/cli/checkpoint-utils.js +168 -0
- package/cli/checkpoint.js +639 -0
- package/cli/cloud-sync.js +447 -0
- package/cli/content.js +198 -0
- package/cli/context.js +1 -1
- package/cli/deploy.js +543 -0
- package/cli/fundraise.js +112 -50
- package/cli/github-cmd.js +435 -0
- package/cli/health.js +477 -0
- package/cli/init.js +84 -13
- package/cli/legal.js +107 -95
- package/cli/log.js +2 -2
- package/cli/loop.js +976 -73
- package/cli/manager.js +711 -0
- package/cli/metrics.js +480 -0
- package/cli/monitor.js +812 -0
- package/cli/onboard.js +521 -0
- package/cli/orchestrator.js +12 -24
- package/cli/prd.js +594 -0
- package/cli/preseed-start.js +1483 -0
- package/cli/preseed.js +2302 -0
- package/cli/project.js +436 -0
- package/cli/quality.js +233 -0
- package/cli/security.js +913 -0
- package/cli/seed.js +1441 -5
- package/cli/skill.js +273 -211
- package/cli/suggest.js +989 -0
- package/cli/switch.js +453 -0
- package/cli/visualize.js +527 -0
- package/cli/watch.js +769 -0
- package/cli/workspace.js +607 -0
- package/core/analyze-workflow.js +1134 -0
- package/core/api-client.js +535 -22
- package/core/audit-workflow.js +1350 -0
- package/core/build-orchestrator.js +480 -0
- package/core/build-state.js +577 -0
- package/core/checkpoint-engine.js +408 -0
- package/core/config.js +1109 -26
- package/core/context-loader.js +21 -1
- package/core/deploy-workflow.js +836 -0
- package/core/entitlements.js +93 -22
- package/core/github-sync.js +610 -0
- package/core/index.js +8 -1
- package/core/ingest.js +1111 -0
- package/core/metrics-engine.js +768 -0
- package/core/onboard-workflow.js +1007 -0
- package/core/preseed-workflow.js +934 -0
- package/core/preseed.js +1617 -0
- package/core/project-context.js +325 -0
- package/core/project-state.js +694 -0
- package/core/r2-sync.js +583 -0
- package/core/scaffold.js +525 -7
- package/core/session.js +258 -0
- package/core/task-extractor.js +758 -0
- package/core/telemetry.js +28 -6
- package/core/tier-enforcement.js +737 -0
- package/core/utils.js +38 -14
- package/generators/questionnaire.js +15 -12
- package/generators/sections/ai.js +7 -7
- package/generators/sections/content.js +300 -0
- package/generators/sections/index.js +3 -0
- package/generators/sections/plugins.js +7 -6
- package/generators/templates/build-planning.template.js +596 -0
- package/generators/templates/content.template.js +819 -0
- package/generators/templates/index.js +2 -1
- package/hooks/git-autopilot.js +1250 -0
- package/hooks/index.js +9 -0
- package/intelligence/agent-collab.js +2057 -0
- package/intelligence/auto-suggest.js +634 -0
- package/intelligence/content-gen.js +1589 -0
- package/intelligence/cross-project.js +1647 -0
- package/intelligence/index.js +184 -0
- package/intelligence/learning/insights.json +517 -7
- package/intelligence/learning/pattern-learner.js +1008 -14
- package/intelligence/memory/decision-tracker.js +1431 -31
- package/intelligence/memory/decisions.jsonl +0 -0
- package/intelligence/orchestrator.js +2896 -1
- package/intelligence/prd.js +92 -1
- package/intelligence/recommendation-weights.json +14 -2
- package/intelligence/recommendations.js +463 -9
- package/intelligence/workflow-composer.js +1451 -0
- package/marketplace/index.d.ts +324 -0
- package/marketplace/index.js +1921 -0
- package/mcp/contracts/mcp-contract.v1.json +342 -4
- package/mcp/registry.js +680 -3
- package/mcp/response-formatter.js +23 -0
- package/mcp/tools/assist-tool.js +78 -4
- package/mcp/tools/autopilot-tool.js +408 -0
- package/mcp/tools/content-tool.js +571 -0
- package/mcp/tools/dashboard-tool.js +251 -5
- package/mcp/tools/mvp-tool.js +344 -0
- package/mcp/tools/plugin-tool.js +23 -1
- package/mcp/tools/prd-tool.js +579 -0
- package/mcp/tools/seed-tool.js +447 -0
- package/mcp/tools/skill-tool.js +43 -14
- package/mcp/tools/suggest-tool.js +147 -0
- package/package.json +15 -6
- package/agents/README.md +0 -93
- package/agents/ai-integration-expert/context.md +0 -386
- package/agents/api-expert/context.md +0 -416
- package/agents/architecture-expert/context.md +0 -454
- package/agents/auth-expert/context.md +0 -399
- package/agents/backend-expert/context.md +0 -483
- package/agents/business-strategy-expert/context.md +0 -180
- package/agents/code-review-expert/context.md +0 -365
- package/agents/competitive-analysis-expert/context.md +0 -239
- package/agents/data-modeling-expert/context.md +0 -352
- package/agents/database-expert/context.md +0 -250
- package/agents/devops-expert/context.md +0 -446
- package/agents/email-expert/context.md +0 -379
- package/agents/financial-expert/context.md +0 -213
- package/agents/frontend-expert/context.md +0 -364
- package/agents/fundraising-expert/context.md +0 -257
- package/agents/growth-expert/context.md +0 -249
- package/agents/index.js +0 -140
- package/agents/investor-relations-expert/context.md +0 -266
- package/agents/legal-expert/context.md +0 -284
- package/agents/marketing-expert/context.md +0 -236
- package/agents/monitoring-expert/context.md +0 -362
- package/agents/operations-expert/context.md +0 -279
- package/agents/partnerships-expert/context.md +0 -286
- package/agents/payment-expert/context.md +0 -340
- package/agents/performance-expert/context.md +0 -377
- package/agents/private-equity-expert/context.md +0 -246
- package/agents/railway-expert/context.md +0 -284
- package/agents/research-expert/context.md +0 -245
- package/agents/sales-expert/context.md +0 -241
- package/agents/security-expert/context.md +0 -343
- package/agents/testing-expert/context.md +0 -414
- package/agents/ui-ux-expert/context.md +0 -448
- package/agents/vercel-expert/context.md +0 -426
- package/skills/index.js +0 -787
- package/skills/patterns/README.md +0 -163
- package/skills/patterns/ai/agents.md +0 -281
- package/skills/patterns/ai/claude.md +0 -138
- package/skills/patterns/ai/embeddings.md +0 -150
- package/skills/patterns/ai/rag.md +0 -266
- package/skills/patterns/ai/streaming.md +0 -170
- package/skills/patterns/ai/structured-output.md +0 -162
- package/skills/patterns/ai/tools.md +0 -154
- package/skills/patterns/analytics/tracking.md +0 -220
- package/skills/patterns/api/errors.md +0 -296
- package/skills/patterns/api/graphql.md +0 -440
- package/skills/patterns/api/middleware.md +0 -279
- package/skills/patterns/api/openapi.md +0 -285
- package/skills/patterns/api/rate-limiting.md +0 -231
- package/skills/patterns/api/route-handler.md +0 -217
- package/skills/patterns/api/server-action.md +0 -249
- package/skills/patterns/api/versioning.md +0 -443
- package/skills/patterns/api/webhooks.md +0 -247
- package/skills/patterns/auth/clerk.md +0 -132
- package/skills/patterns/auth/mfa.md +0 -313
- package/skills/patterns/auth/nextauth.md +0 -140
- package/skills/patterns/auth/oauth.md +0 -237
- package/skills/patterns/auth/rbac.md +0 -152
- package/skills/patterns/auth/session-management.md +0 -367
- package/skills/patterns/auth/session.md +0 -120
- package/skills/patterns/database/audit.md +0 -177
- package/skills/patterns/database/migrations.md +0 -177
- package/skills/patterns/database/pagination.md +0 -230
- package/skills/patterns/database/pooling.md +0 -357
- package/skills/patterns/database/prisma.md +0 -180
- package/skills/patterns/database/relations.md +0 -187
- package/skills/patterns/database/seeding.md +0 -246
- package/skills/patterns/database/soft-delete.md +0 -153
- package/skills/patterns/database/transactions.md +0 -162
- package/skills/patterns/deployment/ci-cd.md +0 -231
- package/skills/patterns/deployment/docker.md +0 -188
- package/skills/patterns/deployment/monitoring.md +0 -387
- package/skills/patterns/deployment/vercel.md +0 -160
- package/skills/patterns/email/resend.md +0 -143
- package/skills/patterns/email/templates.md +0 -245
- package/skills/patterns/email/transactional.md +0 -503
- package/skills/patterns/email/verification.md +0 -176
- package/skills/patterns/files/download.md +0 -243
- package/skills/patterns/files/upload.md +0 -239
- package/skills/patterns/i18n/nextintl.md +0 -188
- package/skills/patterns/logging/structured.md +0 -292
- package/skills/patterns/notifications/email-queue.md +0 -248
- package/skills/patterns/notifications/push.md +0 -279
- package/skills/patterns/payments/checkout.md +0 -303
- package/skills/patterns/payments/invoices.md +0 -287
- package/skills/patterns/payments/portal.md +0 -245
- package/skills/patterns/payments/stripe.md +0 -272
- package/skills/patterns/payments/subscriptions.md +0 -300
- package/skills/patterns/payments/usage.md +0 -279
- package/skills/patterns/performance/caching.md +0 -276
- package/skills/patterns/performance/code-splitting.md +0 -233
- package/skills/patterns/performance/edge.md +0 -254
- package/skills/patterns/performance/isr.md +0 -266
- package/skills/patterns/performance/lazy-loading.md +0 -281
- package/skills/patterns/realtime/sse.md +0 -327
- package/skills/patterns/realtime/websockets.md +0 -336
- package/skills/patterns/search/filtering.md +0 -329
- package/skills/patterns/search/fulltext.md +0 -260
- package/skills/patterns/security/audit-logging.md +0 -444
- package/skills/patterns/security/csrf.md +0 -234
- package/skills/patterns/security/headers.md +0 -252
- package/skills/patterns/security/sanitization.md +0 -258
- package/skills/patterns/security/secrets.md +0 -261
- package/skills/patterns/security/validation.md +0 -268
- package/skills/patterns/security/xss.md +0 -229
- package/skills/patterns/seo/metadata.md +0 -252
- package/skills/patterns/state/context.md +0 -349
- package/skills/patterns/state/react-query.md +0 -313
- package/skills/patterns/state/url-state.md +0 -482
- package/skills/patterns/state/zustand.md +0 -262
- package/skills/patterns/testing/api.md +0 -259
- package/skills/patterns/testing/component.md +0 -233
- package/skills/patterns/testing/coverage.md +0 -207
- package/skills/patterns/testing/fixtures.md +0 -225
- package/skills/patterns/testing/integration.md +0 -436
- package/skills/patterns/testing/mocking.md +0 -177
- package/skills/patterns/testing/playwright.md +0 -162
- package/skills/patterns/testing/snapshot.md +0 -175
- package/skills/patterns/testing/vitest.md +0 -307
- package/skills/patterns/ui/accordions.md +0 -395
- package/skills/patterns/ui/cards.md +0 -299
- package/skills/patterns/ui/dropdowns.md +0 -476
- package/skills/patterns/ui/empty-states.md +0 -320
- package/skills/patterns/ui/forms.md +0 -405
- package/skills/patterns/ui/inputs.md +0 -319
- package/skills/patterns/ui/layouts.md +0 -282
- package/skills/patterns/ui/loading.md +0 -291
- package/skills/patterns/ui/modals.md +0 -338
- package/skills/patterns/ui/navigation.md +0 -374
- package/skills/patterns/ui/tables.md +0 -407
- package/skills/patterns/ui/toasts.md +0 -300
- package/skills/patterns/ui/tooltips.md +0 -396
- package/skills/patterns/utils/dates.md +0 -435
- package/skills/patterns/utils/errors.md +0 -451
- package/skills/patterns/utils/formatting.md +0 -345
- package/skills/patterns/utils/validation.md +0 -434
- package/templates/bootspring.config.js +0 -83
- package/templates/business/business-model-canvas.md +0 -246
- package/templates/business/business-plan.md +0 -266
- package/templates/business/competitive-analysis.md +0 -312
- package/templates/fundraising/data-room-checklist.md +0 -300
- package/templates/fundraising/investor-research.md +0 -243
- package/templates/fundraising/pitch-deck-outline.md +0 -253
- package/templates/legal/gdpr-checklist.md +0 -339
- package/templates/legal/privacy-policy.md +0 -285
- package/templates/legal/terms-of-service.md +0 -222
- package/templates/mcp.json +0 -9
|
@@ -29,6 +29,523 @@ const CONFIDENCE_LEVELS = {
|
|
|
29
29
|
VERY_LOW: 0.1
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Minimum decisions required before transitioning away from cold-start defaults
|
|
34
|
+
*/
|
|
35
|
+
const COLD_START_THRESHOLD = 5;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Thresholds for blending default and learned patterns
|
|
39
|
+
*/
|
|
40
|
+
const BLEND_THRESHOLDS = {
|
|
41
|
+
FULL_DEFAULTS: 2, // 0-2 decisions: use 100% defaults
|
|
42
|
+
HEAVY_DEFAULTS: 5, // 3-5 decisions: 75% defaults, 25% learned
|
|
43
|
+
BALANCED: 10, // 6-10 decisions: 50% defaults, 50% learned
|
|
44
|
+
HEAVY_LEARNED: 20, // 11-20 decisions: 25% defaults, 75% learned
|
|
45
|
+
FULL_LEARNED: 21 // 21+ decisions: use 100% learned (defaults as fallback only)
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Default patterns for cold start - comprehensive best practices
|
|
50
|
+
* These provide sensible recommendations when no history exists
|
|
51
|
+
*/
|
|
52
|
+
const DEFAULT_PATTERNS = {
|
|
53
|
+
insights: [
|
|
54
|
+
{
|
|
55
|
+
type: 'cold_start',
|
|
56
|
+
subject: 'general',
|
|
57
|
+
message: 'Using industry best practices until learning data accumulates',
|
|
58
|
+
level: 'info',
|
|
59
|
+
confidence: CONFIDENCE_LEVELS.MEDIUM
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
type: 'cold_start',
|
|
63
|
+
subject: 'data_collection',
|
|
64
|
+
message: `Recommendations will improve significantly after ${COLD_START_THRESHOLD} recorded decisions`,
|
|
65
|
+
level: 'info',
|
|
66
|
+
confidence: CONFIDENCE_LEVELS.MEDIUM
|
|
67
|
+
}
|
|
68
|
+
],
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Scenario-based patterns for common development tasks
|
|
72
|
+
*/
|
|
73
|
+
scenarios: {
|
|
74
|
+
// New feature development patterns
|
|
75
|
+
new_feature: {
|
|
76
|
+
name: 'New Feature Development',
|
|
77
|
+
steps: [
|
|
78
|
+
'Define acceptance criteria before coding',
|
|
79
|
+
'Break feature into small, testable increments',
|
|
80
|
+
'Write tests for core functionality first',
|
|
81
|
+
'Implement happy path, then edge cases',
|
|
82
|
+
'Document API changes and user-facing behavior'
|
|
83
|
+
],
|
|
84
|
+
common_pitfalls: [
|
|
85
|
+
'Starting without clear requirements',
|
|
86
|
+
'Building too much before getting feedback',
|
|
87
|
+
'Skipping tests for "simple" features'
|
|
88
|
+
],
|
|
89
|
+
success_indicators: [
|
|
90
|
+
'All acceptance criteria met',
|
|
91
|
+
'Tests passing and covering edge cases',
|
|
92
|
+
'Code reviewed and approved'
|
|
93
|
+
],
|
|
94
|
+
confidence: CONFIDENCE_LEVELS.HIGH,
|
|
95
|
+
is_default: true
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
// Bug fix patterns
|
|
99
|
+
bug_fix: {
|
|
100
|
+
name: 'Bug Fix',
|
|
101
|
+
steps: [
|
|
102
|
+
'Reproduce the bug reliably first',
|
|
103
|
+
'Write a failing test that demonstrates the bug',
|
|
104
|
+
'Identify root cause before implementing fix',
|
|
105
|
+
'Fix the root cause, not just symptoms',
|
|
106
|
+
'Verify fix resolves original issue without regressions'
|
|
107
|
+
],
|
|
108
|
+
common_pitfalls: [
|
|
109
|
+
'Fixing symptoms instead of root cause',
|
|
110
|
+
'Not writing a regression test',
|
|
111
|
+
'Rushing fix without understanding impact'
|
|
112
|
+
],
|
|
113
|
+
success_indicators: [
|
|
114
|
+
'Bug no longer reproducible',
|
|
115
|
+
'Regression test added and passing',
|
|
116
|
+
'No new issues introduced'
|
|
117
|
+
],
|
|
118
|
+
confidence: CONFIDENCE_LEVELS.HIGH,
|
|
119
|
+
is_default: true
|
|
120
|
+
},
|
|
121
|
+
|
|
122
|
+
// Refactoring patterns
|
|
123
|
+
refactoring: {
|
|
124
|
+
name: 'Code Refactoring',
|
|
125
|
+
steps: [
|
|
126
|
+
'Ensure comprehensive test coverage exists first',
|
|
127
|
+
'Make small, incremental changes',
|
|
128
|
+
'Run tests after each change',
|
|
129
|
+
'Keep refactoring separate from feature changes',
|
|
130
|
+
'Document architectural decisions'
|
|
131
|
+
],
|
|
132
|
+
common_pitfalls: [
|
|
133
|
+
'Refactoring without test coverage',
|
|
134
|
+
'Combining refactoring with feature work',
|
|
135
|
+
'Making too many changes at once'
|
|
136
|
+
],
|
|
137
|
+
success_indicators: [
|
|
138
|
+
'All existing tests still pass',
|
|
139
|
+
'Code metrics improved (complexity, duplication)',
|
|
140
|
+
'No behavior changes introduced'
|
|
141
|
+
],
|
|
142
|
+
confidence: CONFIDENCE_LEVELS.HIGH,
|
|
143
|
+
is_default: true
|
|
144
|
+
},
|
|
145
|
+
|
|
146
|
+
// Testing patterns
|
|
147
|
+
testing: {
|
|
148
|
+
name: 'Writing Tests',
|
|
149
|
+
steps: [
|
|
150
|
+
'Identify critical paths and edge cases',
|
|
151
|
+
'Write unit tests for isolated logic',
|
|
152
|
+
'Write integration tests for component interactions',
|
|
153
|
+
'Mock external dependencies consistently',
|
|
154
|
+
'Aim for meaningful coverage, not 100% coverage'
|
|
155
|
+
],
|
|
156
|
+
common_pitfalls: [
|
|
157
|
+
'Testing implementation details instead of behavior',
|
|
158
|
+
'Brittle tests that break on refactoring',
|
|
159
|
+
'Ignoring edge cases and error paths'
|
|
160
|
+
],
|
|
161
|
+
success_indicators: [
|
|
162
|
+
'Tests are reliable and not flaky',
|
|
163
|
+
'Tests run quickly (unit tests < 10s)',
|
|
164
|
+
'Tests catch real bugs during development'
|
|
165
|
+
],
|
|
166
|
+
confidence: CONFIDENCE_LEVELS.HIGH,
|
|
167
|
+
is_default: true
|
|
168
|
+
},
|
|
169
|
+
|
|
170
|
+
// Database changes patterns
|
|
171
|
+
database_migration: {
|
|
172
|
+
name: 'Database Migration',
|
|
173
|
+
steps: [
|
|
174
|
+
'Plan migration with rollback strategy',
|
|
175
|
+
'Test migration on copy of production data',
|
|
176
|
+
'Make migrations backward compatible when possible',
|
|
177
|
+
'Deploy migration before code that depends on it',
|
|
178
|
+
'Monitor for performance issues after deployment'
|
|
179
|
+
],
|
|
180
|
+
common_pitfalls: [
|
|
181
|
+
'No rollback plan',
|
|
182
|
+
'Locking tables during high-traffic periods',
|
|
183
|
+
'Deploying dependent code before migration completes'
|
|
184
|
+
],
|
|
185
|
+
success_indicators: [
|
|
186
|
+
'Migration completes without errors',
|
|
187
|
+
'Application continues working during migration',
|
|
188
|
+
'Rollback tested and working'
|
|
189
|
+
],
|
|
190
|
+
confidence: CONFIDENCE_LEVELS.HIGH,
|
|
191
|
+
is_default: true
|
|
192
|
+
},
|
|
193
|
+
|
|
194
|
+
// API development patterns
|
|
195
|
+
api_development: {
|
|
196
|
+
name: 'API Development',
|
|
197
|
+
steps: [
|
|
198
|
+
'Design API contract before implementation',
|
|
199
|
+
'Validate all inputs at the boundary',
|
|
200
|
+
'Return consistent error formats',
|
|
201
|
+
'Version APIs for breaking changes',
|
|
202
|
+
'Document endpoints with examples'
|
|
203
|
+
],
|
|
204
|
+
common_pitfalls: [
|
|
205
|
+
'Inconsistent error handling',
|
|
206
|
+
'Missing input validation',
|
|
207
|
+
'Breaking changes without versioning'
|
|
208
|
+
],
|
|
209
|
+
success_indicators: [
|
|
210
|
+
'Clear and consistent API contract',
|
|
211
|
+
'Comprehensive error handling',
|
|
212
|
+
'Documentation up to date'
|
|
213
|
+
],
|
|
214
|
+
confidence: CONFIDENCE_LEVELS.HIGH,
|
|
215
|
+
is_default: true
|
|
216
|
+
},
|
|
217
|
+
|
|
218
|
+
// Performance optimization patterns
|
|
219
|
+
performance: {
|
|
220
|
+
name: 'Performance Optimization',
|
|
221
|
+
steps: [
|
|
222
|
+
'Measure before optimizing - establish baseline',
|
|
223
|
+
'Identify bottleneck using profiling tools',
|
|
224
|
+
'Focus on the biggest impact first',
|
|
225
|
+
'Measure after each change',
|
|
226
|
+
'Document performance requirements and results'
|
|
227
|
+
],
|
|
228
|
+
common_pitfalls: [
|
|
229
|
+
'Optimizing without measuring',
|
|
230
|
+
'Premature optimization',
|
|
231
|
+
'Optimizing non-bottlenecks'
|
|
232
|
+
],
|
|
233
|
+
success_indicators: [
|
|
234
|
+
'Measurable performance improvement',
|
|
235
|
+
'No functionality regressions',
|
|
236
|
+
'Performance requirements documented and met'
|
|
237
|
+
],
|
|
238
|
+
confidence: CONFIDENCE_LEVELS.MEDIUM,
|
|
239
|
+
is_default: true
|
|
240
|
+
},
|
|
241
|
+
|
|
242
|
+
// Security implementation patterns
|
|
243
|
+
security: {
|
|
244
|
+
name: 'Security Implementation',
|
|
245
|
+
steps: [
|
|
246
|
+
'Validate and sanitize all user inputs',
|
|
247
|
+
'Use parameterized queries for database access',
|
|
248
|
+
'Implement proper authentication and authorization',
|
|
249
|
+
'Store secrets in environment variables or vaults',
|
|
250
|
+
'Log security events without exposing sensitive data'
|
|
251
|
+
],
|
|
252
|
+
common_pitfalls: [
|
|
253
|
+
'Trusting user input',
|
|
254
|
+
'Hardcoding secrets',
|
|
255
|
+
'Logging sensitive information'
|
|
256
|
+
],
|
|
257
|
+
success_indicators: [
|
|
258
|
+
'Passes security review/scan',
|
|
259
|
+
'No secrets in codebase',
|
|
260
|
+
'Proper access controls in place'
|
|
261
|
+
],
|
|
262
|
+
confidence: CONFIDENCE_LEVELS.VERY_HIGH,
|
|
263
|
+
is_default: true
|
|
264
|
+
}
|
|
265
|
+
},
|
|
266
|
+
|
|
267
|
+
recommendations: {
|
|
268
|
+
by_type: {
|
|
269
|
+
'database': {
|
|
270
|
+
success_rate: 0.8,
|
|
271
|
+
recommendation: 'Use migrations for schema changes, write tests for queries',
|
|
272
|
+
sample_size: 0,
|
|
273
|
+
is_default: true,
|
|
274
|
+
tips: [
|
|
275
|
+
'Always create rollback migrations',
|
|
276
|
+
'Test with production-like data volumes',
|
|
277
|
+
'Index columns used in WHERE clauses'
|
|
278
|
+
]
|
|
279
|
+
},
|
|
280
|
+
'api': {
|
|
281
|
+
success_rate: 0.75,
|
|
282
|
+
recommendation: 'Document endpoints, validate inputs, handle errors consistently',
|
|
283
|
+
sample_size: 0,
|
|
284
|
+
is_default: true,
|
|
285
|
+
tips: [
|
|
286
|
+
'Use OpenAPI/Swagger for documentation',
|
|
287
|
+
'Return appropriate HTTP status codes',
|
|
288
|
+
'Include request IDs for debugging'
|
|
289
|
+
]
|
|
290
|
+
},
|
|
291
|
+
'ui': {
|
|
292
|
+
success_rate: 0.7,
|
|
293
|
+
recommendation: 'Start with mobile-first design, use design system components',
|
|
294
|
+
sample_size: 0,
|
|
295
|
+
is_default: true,
|
|
296
|
+
tips: [
|
|
297
|
+
'Test on real devices, not just emulators',
|
|
298
|
+
'Consider accessibility from the start',
|
|
299
|
+
'Use semantic HTML elements'
|
|
300
|
+
]
|
|
301
|
+
},
|
|
302
|
+
'testing': {
|
|
303
|
+
success_rate: 0.85,
|
|
304
|
+
recommendation: 'Write tests for critical paths first, mock external services',
|
|
305
|
+
sample_size: 0,
|
|
306
|
+
is_default: true,
|
|
307
|
+
tips: [
|
|
308
|
+
'Use factories for test data',
|
|
309
|
+
'Keep tests independent and isolated',
|
|
310
|
+
'Test behavior, not implementation'
|
|
311
|
+
]
|
|
312
|
+
},
|
|
313
|
+
'security': {
|
|
314
|
+
success_rate: 0.9,
|
|
315
|
+
recommendation: 'Never store secrets in code, validate all inputs, use prepared statements',
|
|
316
|
+
sample_size: 0,
|
|
317
|
+
is_default: true,
|
|
318
|
+
tips: [
|
|
319
|
+
'Use environment variables for configuration',
|
|
320
|
+
'Implement rate limiting on public endpoints',
|
|
321
|
+
'Keep dependencies updated'
|
|
322
|
+
]
|
|
323
|
+
},
|
|
324
|
+
'architecture': {
|
|
325
|
+
success_rate: 0.65,
|
|
326
|
+
recommendation: 'Start simple, refactor when patterns emerge, document decisions',
|
|
327
|
+
sample_size: 0,
|
|
328
|
+
is_default: true,
|
|
329
|
+
tips: [
|
|
330
|
+
'Use ADRs (Architecture Decision Records)',
|
|
331
|
+
'Prefer composition over inheritance',
|
|
332
|
+
'Keep components loosely coupled'
|
|
333
|
+
]
|
|
334
|
+
},
|
|
335
|
+
'feature': {
|
|
336
|
+
success_rate: 0.75,
|
|
337
|
+
recommendation: 'Break into small increments, define acceptance criteria, get early feedback',
|
|
338
|
+
sample_size: 0,
|
|
339
|
+
is_default: true,
|
|
340
|
+
tips: [
|
|
341
|
+
'Ship MVPs and iterate',
|
|
342
|
+
'Use feature flags for gradual rollout',
|
|
343
|
+
'Track metrics to measure success'
|
|
344
|
+
]
|
|
345
|
+
},
|
|
346
|
+
'bugfix': {
|
|
347
|
+
success_rate: 0.8,
|
|
348
|
+
recommendation: 'Write failing test first, fix root cause, verify no regressions',
|
|
349
|
+
sample_size: 0,
|
|
350
|
+
is_default: true,
|
|
351
|
+
tips: [
|
|
352
|
+
'Understand the bug before fixing',
|
|
353
|
+
'Check for similar issues elsewhere',
|
|
354
|
+
'Update documentation if behavior was unclear'
|
|
355
|
+
]
|
|
356
|
+
},
|
|
357
|
+
'refactoring': {
|
|
358
|
+
success_rate: 0.7,
|
|
359
|
+
recommendation: 'Ensure test coverage, make small changes, keep separate from features',
|
|
360
|
+
sample_size: 0,
|
|
361
|
+
is_default: true,
|
|
362
|
+
tips: [
|
|
363
|
+
'Use IDE refactoring tools when available',
|
|
364
|
+
'Commit frequently during refactoring',
|
|
365
|
+
'Review changes in small batches'
|
|
366
|
+
]
|
|
367
|
+
},
|
|
368
|
+
'performance': {
|
|
369
|
+
success_rate: 0.65,
|
|
370
|
+
recommendation: 'Measure first, optimize bottlenecks, measure again',
|
|
371
|
+
sample_size: 0,
|
|
372
|
+
is_default: true,
|
|
373
|
+
tips: [
|
|
374
|
+
'Set performance budgets upfront',
|
|
375
|
+
'Profile in production-like environments',
|
|
376
|
+
'Consider caching strategies'
|
|
377
|
+
]
|
|
378
|
+
},
|
|
379
|
+
'deployment': {
|
|
380
|
+
success_rate: 0.75,
|
|
381
|
+
recommendation: 'Use staging environment, implement health checks, have rollback plan',
|
|
382
|
+
sample_size: 0,
|
|
383
|
+
is_default: true,
|
|
384
|
+
tips: [
|
|
385
|
+
'Automate deployments',
|
|
386
|
+
'Use blue-green or canary deployments',
|
|
387
|
+
'Monitor error rates after deploy'
|
|
388
|
+
]
|
|
389
|
+
},
|
|
390
|
+
'documentation': {
|
|
391
|
+
success_rate: 0.8,
|
|
392
|
+
recommendation: 'Keep docs close to code, include examples, update during changes',
|
|
393
|
+
sample_size: 0,
|
|
394
|
+
is_default: true,
|
|
395
|
+
tips: [
|
|
396
|
+
'Use inline comments for "why", not "what"',
|
|
397
|
+
'Include runnable code examples',
|
|
398
|
+
'Document breaking changes prominently'
|
|
399
|
+
]
|
|
400
|
+
}
|
|
401
|
+
},
|
|
402
|
+
by_phase: {
|
|
403
|
+
'planning': {
|
|
404
|
+
success_rate: 0.8,
|
|
405
|
+
recommendation: 'Break large features into small stories, define acceptance criteria',
|
|
406
|
+
sample_size: 0,
|
|
407
|
+
is_default: true,
|
|
408
|
+
tips: [
|
|
409
|
+
'Include technical spike time for unknowns',
|
|
410
|
+
'Define "done" criteria upfront',
|
|
411
|
+
'Identify dependencies early'
|
|
412
|
+
]
|
|
413
|
+
},
|
|
414
|
+
'development': {
|
|
415
|
+
success_rate: 0.75,
|
|
416
|
+
recommendation: 'Commit early and often, write tests alongside code',
|
|
417
|
+
sample_size: 0,
|
|
418
|
+
is_default: true,
|
|
419
|
+
tips: [
|
|
420
|
+
'Use meaningful commit messages',
|
|
421
|
+
'Keep pull requests small and focused',
|
|
422
|
+
'Request reviews early for big changes'
|
|
423
|
+
]
|
|
424
|
+
},
|
|
425
|
+
'testing': {
|
|
426
|
+
success_rate: 0.85,
|
|
427
|
+
recommendation: 'Automate tests, test edge cases, verify in staging',
|
|
428
|
+
sample_size: 0,
|
|
429
|
+
is_default: true,
|
|
430
|
+
tips: [
|
|
431
|
+
'Include both happy path and error cases',
|
|
432
|
+
'Test with realistic data',
|
|
433
|
+
'Run security scans in CI'
|
|
434
|
+
]
|
|
435
|
+
},
|
|
436
|
+
'deployment': {
|
|
437
|
+
success_rate: 0.7,
|
|
438
|
+
recommendation: 'Use feature flags, deploy to staging first, monitor closely',
|
|
439
|
+
sample_size: 0,
|
|
440
|
+
is_default: true,
|
|
441
|
+
tips: [
|
|
442
|
+
'Have runbooks for common issues',
|
|
443
|
+
'Set up alerting before deploying',
|
|
444
|
+
'Deploy during low-traffic periods for risky changes'
|
|
445
|
+
]
|
|
446
|
+
},
|
|
447
|
+
'maintenance': {
|
|
448
|
+
success_rate: 0.8,
|
|
449
|
+
recommendation: 'Keep dependencies updated, monitor for issues, document learnings',
|
|
450
|
+
sample_size: 0,
|
|
451
|
+
is_default: true,
|
|
452
|
+
tips: [
|
|
453
|
+
'Schedule regular dependency updates',
|
|
454
|
+
'Review and clean up technical debt',
|
|
455
|
+
'Archive unused code rather than commenting out'
|
|
456
|
+
]
|
|
457
|
+
}
|
|
458
|
+
},
|
|
459
|
+
general: [
|
|
460
|
+
{
|
|
461
|
+
priority: 'medium',
|
|
462
|
+
message: 'Building your decision history - recommendations will improve with more data',
|
|
463
|
+
action: 'Continue making decisions and recording outcomes'
|
|
464
|
+
},
|
|
465
|
+
{
|
|
466
|
+
priority: 'low',
|
|
467
|
+
message: 'Record outcomes for decisions to help the system learn',
|
|
468
|
+
action: 'Use decision tracker to mark decisions as success, failure, or reverted'
|
|
469
|
+
}
|
|
470
|
+
]
|
|
471
|
+
},
|
|
472
|
+
anti_patterns: [
|
|
473
|
+
{
|
|
474
|
+
type: 'security',
|
|
475
|
+
decision: 'hardcoded_secrets',
|
|
476
|
+
failure_rate: 1.0,
|
|
477
|
+
occurrences: 0,
|
|
478
|
+
recommendation: 'AVOID',
|
|
479
|
+
message: 'Never hardcode API keys, passwords, or secrets in source code',
|
|
480
|
+
is_default: true
|
|
481
|
+
},
|
|
482
|
+
{
|
|
483
|
+
type: 'database',
|
|
484
|
+
decision: 'no_migrations',
|
|
485
|
+
failure_rate: 0.8,
|
|
486
|
+
occurrences: 0,
|
|
487
|
+
recommendation: 'AVOID',
|
|
488
|
+
message: 'Always use migrations for schema changes, avoid direct DB modifications',
|
|
489
|
+
is_default: true
|
|
490
|
+
},
|
|
491
|
+
{
|
|
492
|
+
type: 'deployment',
|
|
493
|
+
decision: 'direct_to_production',
|
|
494
|
+
failure_rate: 0.7,
|
|
495
|
+
occurrences: 0,
|
|
496
|
+
recommendation: 'AVOID',
|
|
497
|
+
message: 'Deploy to staging first, test thoroughly before production',
|
|
498
|
+
is_default: true
|
|
499
|
+
},
|
|
500
|
+
{
|
|
501
|
+
type: 'testing',
|
|
502
|
+
decision: 'skip_tests_for_deadline',
|
|
503
|
+
failure_rate: 0.75,
|
|
504
|
+
occurrences: 0,
|
|
505
|
+
recommendation: 'AVOID',
|
|
506
|
+
message: 'Skipping tests to meet deadlines often leads to bugs and longer timelines',
|
|
507
|
+
is_default: true
|
|
508
|
+
},
|
|
509
|
+
{
|
|
510
|
+
type: 'refactoring',
|
|
511
|
+
decision: 'big_bang_refactor',
|
|
512
|
+
failure_rate: 0.65,
|
|
513
|
+
occurrences: 0,
|
|
514
|
+
recommendation: 'AVOID',
|
|
515
|
+
message: 'Large refactors without tests are risky - prefer incremental changes',
|
|
516
|
+
is_default: true
|
|
517
|
+
},
|
|
518
|
+
{
|
|
519
|
+
type: 'feature',
|
|
520
|
+
decision: 'no_requirements',
|
|
521
|
+
failure_rate: 0.6,
|
|
522
|
+
occurrences: 0,
|
|
523
|
+
recommendation: 'AVOID',
|
|
524
|
+
message: 'Starting development without clear requirements leads to rework',
|
|
525
|
+
is_default: true
|
|
526
|
+
},
|
|
527
|
+
{
|
|
528
|
+
type: 'architecture',
|
|
529
|
+
decision: 'premature_optimization',
|
|
530
|
+
failure_rate: 0.5,
|
|
531
|
+
occurrences: 0,
|
|
532
|
+
recommendation: 'CAUTION',
|
|
533
|
+
message: 'Optimizing before measuring often wastes effort on non-bottlenecks',
|
|
534
|
+
is_default: true
|
|
535
|
+
},
|
|
536
|
+
{
|
|
537
|
+
type: 'api',
|
|
538
|
+
decision: 'breaking_change_no_version',
|
|
539
|
+
failure_rate: 0.8,
|
|
540
|
+
occurrences: 0,
|
|
541
|
+
recommendation: 'AVOID',
|
|
542
|
+
message: 'Breaking API changes without versioning breaks existing clients',
|
|
543
|
+
is_default: true
|
|
544
|
+
}
|
|
545
|
+
],
|
|
546
|
+
correlations: []
|
|
547
|
+
};
|
|
548
|
+
|
|
32
549
|
/**
|
|
33
550
|
* Ensure insights file exists
|
|
34
551
|
*/
|
|
@@ -59,13 +576,9 @@ function analyze() {
|
|
|
59
576
|
const decisions = decisionTracker.readAllDecisions();
|
|
60
577
|
const completedDecisions = decisions.filter(d => d.outcome);
|
|
61
578
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
decisions_needed: 5 - completedDecisions.length,
|
|
66
|
-
message: `Need ${5 - completedDecisions.length} more completed decisions for analysis`
|
|
67
|
-
};
|
|
68
|
-
}
|
|
579
|
+
// Calculate blend ratio based on completed decisions
|
|
580
|
+
const blendRatio = calculateBlendRatio(completedDecisions.length);
|
|
581
|
+
const useDefaults = completedDecisions.length < COLD_START_THRESHOLD;
|
|
69
582
|
|
|
70
583
|
ensureInsightsFile();
|
|
71
584
|
const insightsData = JSON.parse(fs.readFileSync(insightsFile, 'utf-8'));
|
|
@@ -96,17 +609,33 @@ function analyze() {
|
|
|
96
609
|
|
|
97
610
|
// Update insights file
|
|
98
611
|
insightsData.last_analysis = new Date().toISOString();
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
612
|
+
|
|
613
|
+
// Blend defaults with learned patterns based on data available
|
|
614
|
+
const blendedData = blendPatterns(
|
|
615
|
+
{ insights, recommendations, antiPatterns, correlations },
|
|
616
|
+
DEFAULT_PATTERNS,
|
|
617
|
+
blendRatio,
|
|
618
|
+
completedDecisions.length
|
|
619
|
+
);
|
|
620
|
+
|
|
621
|
+
insightsData.insights = blendedData.insights;
|
|
622
|
+
insightsData.recommendations = blendedData.recommendations;
|
|
623
|
+
insightsData.anti_patterns = blendedData.antiPatterns;
|
|
624
|
+
insightsData.correlations = blendedData.correlations;
|
|
625
|
+
insightsData.scenarios = DEFAULT_PATTERNS.scenarios; // Always include scenarios
|
|
626
|
+
insightsData.using_defaults = useDefaults;
|
|
627
|
+
insightsData.blend_ratio = blendRatio;
|
|
628
|
+
|
|
103
629
|
insightsData.analysis_summary = {
|
|
104
630
|
total_decisions: decisions.length,
|
|
105
631
|
completed_decisions: completedDecisions.length,
|
|
106
632
|
success_rate: calculateOverallSuccessRate(completedDecisions),
|
|
107
633
|
top_performing_type: typeStats.top_type,
|
|
108
|
-
patterns_found: insights.length,
|
|
109
|
-
anti_patterns_found:
|
|
634
|
+
patterns_found: insightsData.insights.length,
|
|
635
|
+
anti_patterns_found: insightsData.anti_patterns.length,
|
|
636
|
+
using_defaults: useDefaults,
|
|
637
|
+
blend_ratio: blendRatio,
|
|
638
|
+
decisions_until_full_learning: Math.max(0, BLEND_THRESHOLDS.FULL_LEARNED - completedDecisions.length)
|
|
110
639
|
};
|
|
111
640
|
|
|
112
641
|
fs.writeFileSync(insightsFile, JSON.stringify(insightsData, null, 2));
|
|
@@ -114,6 +643,232 @@ function analyze() {
|
|
|
114
643
|
return insightsData;
|
|
115
644
|
}
|
|
116
645
|
|
|
646
|
+
/**
|
|
647
|
+
* Calculate blend ratio between default and learned patterns
|
|
648
|
+
* Returns object with defaultWeight and learnedWeight (0-1)
|
|
649
|
+
*/
|
|
650
|
+
function calculateBlendRatio(completedDecisions) {
|
|
651
|
+
if (completedDecisions <= BLEND_THRESHOLDS.FULL_DEFAULTS) {
|
|
652
|
+
return { defaultWeight: 1.0, learnedWeight: 0.0, phase: 'cold_start' };
|
|
653
|
+
}
|
|
654
|
+
if (completedDecisions <= BLEND_THRESHOLDS.HEAVY_DEFAULTS) {
|
|
655
|
+
return { defaultWeight: 0.75, learnedWeight: 0.25, phase: 'early_learning' };
|
|
656
|
+
}
|
|
657
|
+
if (completedDecisions <= BLEND_THRESHOLDS.BALANCED) {
|
|
658
|
+
return { defaultWeight: 0.5, learnedWeight: 0.5, phase: 'balanced' };
|
|
659
|
+
}
|
|
660
|
+
if (completedDecisions <= BLEND_THRESHOLDS.HEAVY_LEARNED) {
|
|
661
|
+
return { defaultWeight: 0.25, learnedWeight: 0.75, phase: 'maturing' };
|
|
662
|
+
}
|
|
663
|
+
return { defaultWeight: 0.0, learnedWeight: 1.0, phase: 'mature' };
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
/**
|
|
667
|
+
* Blend learned patterns with defaults based on blend ratio
|
|
668
|
+
*/
|
|
669
|
+
function blendPatterns(learned, defaults, blendRatio, decisionCount) {
|
|
670
|
+
const { defaultWeight, learnedWeight } = blendRatio;
|
|
671
|
+
|
|
672
|
+
// Insights: Include defaults during cold start, then fade them out
|
|
673
|
+
let insights = [...learned.insights];
|
|
674
|
+
if (defaultWeight > 0) {
|
|
675
|
+
const defaultInsights = defaults.insights.map(i => ({
|
|
676
|
+
...i,
|
|
677
|
+
weight: defaultWeight,
|
|
678
|
+
is_default: true
|
|
679
|
+
}));
|
|
680
|
+
insights = [...defaultInsights, ...insights];
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
// Recommendations: Blend by_type and by_phase
|
|
684
|
+
const recommendations = {
|
|
685
|
+
by_type: blendRecommendationsByType(
|
|
686
|
+
learned.recommendations.by_type || {},
|
|
687
|
+
defaults.recommendations.by_type,
|
|
688
|
+
blendRatio
|
|
689
|
+
),
|
|
690
|
+
by_phase: blendRecommendationsByPhase(
|
|
691
|
+
learned.recommendations.by_phase || {},
|
|
692
|
+
defaults.recommendations.by_phase,
|
|
693
|
+
blendRatio
|
|
694
|
+
),
|
|
695
|
+
general: blendGeneralRecommendations(
|
|
696
|
+
learned.recommendations.general || [],
|
|
697
|
+
defaults.recommendations.general,
|
|
698
|
+
decisionCount
|
|
699
|
+
)
|
|
700
|
+
};
|
|
701
|
+
|
|
702
|
+
// Anti-patterns: Include all defaults, learned can override
|
|
703
|
+
const antiPatterns = blendAntiPatterns(
|
|
704
|
+
learned.antiPatterns,
|
|
705
|
+
defaults.anti_patterns,
|
|
706
|
+
blendRatio
|
|
707
|
+
);
|
|
708
|
+
|
|
709
|
+
// Correlations: Only use learned (no default correlations)
|
|
710
|
+
const correlations = learned.correlations;
|
|
711
|
+
|
|
712
|
+
return { insights, recommendations, antiPatterns, correlations };
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
/**
|
|
716
|
+
* Blend recommendations by type
|
|
717
|
+
*/
|
|
718
|
+
function blendRecommendationsByType(learned, defaults, blendRatio) {
|
|
719
|
+
const result = {};
|
|
720
|
+
|
|
721
|
+
// Start with defaults
|
|
722
|
+
Object.entries(defaults).forEach(([type, defaultRec]) => {
|
|
723
|
+
const learnedRec = learned[type];
|
|
724
|
+
|
|
725
|
+
if (learnedRec && learnedRec.sample_size >= 3) {
|
|
726
|
+
// Learned data is reliable enough - blend success rates
|
|
727
|
+
const blendedSuccessRate =
|
|
728
|
+
(defaultRec.success_rate * blendRatio.defaultWeight) +
|
|
729
|
+
(learnedRec.success_rate * blendRatio.learnedWeight);
|
|
730
|
+
|
|
731
|
+
result[type] = {
|
|
732
|
+
success_rate: parseFloat(blendedSuccessRate.toFixed(2)),
|
|
733
|
+
recommendation: learnedRec.recommendation,
|
|
734
|
+
sample_size: learnedRec.sample_size,
|
|
735
|
+
is_default: false,
|
|
736
|
+
tips: defaultRec.tips, // Always keep tips from defaults
|
|
737
|
+
default_success_rate: defaultRec.success_rate,
|
|
738
|
+
learned_success_rate: learnedRec.success_rate
|
|
739
|
+
};
|
|
740
|
+
} else if (learnedRec) {
|
|
741
|
+
// Some learned data but not enough - weight heavily toward defaults
|
|
742
|
+
result[type] = {
|
|
743
|
+
...defaultRec,
|
|
744
|
+
sample_size: learnedRec.sample_size,
|
|
745
|
+
learning_in_progress: true
|
|
746
|
+
};
|
|
747
|
+
} else {
|
|
748
|
+
// No learned data - use defaults
|
|
749
|
+
result[type] = { ...defaultRec };
|
|
750
|
+
}
|
|
751
|
+
});
|
|
752
|
+
|
|
753
|
+
// Add any learned types not in defaults
|
|
754
|
+
Object.entries(learned).forEach(([type, learnedRec]) => {
|
|
755
|
+
if (!result[type]) {
|
|
756
|
+
result[type] = {
|
|
757
|
+
...learnedRec,
|
|
758
|
+
is_default: false
|
|
759
|
+
};
|
|
760
|
+
}
|
|
761
|
+
});
|
|
762
|
+
|
|
763
|
+
return result;
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
/**
|
|
767
|
+
* Blend recommendations by phase
|
|
768
|
+
*/
|
|
769
|
+
function blendRecommendationsByPhase(learned, defaults, blendRatio) {
|
|
770
|
+
const result = {};
|
|
771
|
+
|
|
772
|
+
// Same logic as by_type
|
|
773
|
+
Object.entries(defaults).forEach(([phase, defaultRec]) => {
|
|
774
|
+
const learnedRec = learned[phase];
|
|
775
|
+
|
|
776
|
+
if (learnedRec && learnedRec.sample_size >= 3) {
|
|
777
|
+
const blendedSuccessRate =
|
|
778
|
+
(defaultRec.success_rate * blendRatio.defaultWeight) +
|
|
779
|
+
(learnedRec.success_rate * blendRatio.learnedWeight);
|
|
780
|
+
|
|
781
|
+
result[phase] = {
|
|
782
|
+
success_rate: parseFloat(blendedSuccessRate.toFixed(2)),
|
|
783
|
+
recommendation: learnedRec.recommendation,
|
|
784
|
+
sample_size: learnedRec.sample_size,
|
|
785
|
+
is_default: false,
|
|
786
|
+
tips: defaultRec.tips,
|
|
787
|
+
default_success_rate: defaultRec.success_rate,
|
|
788
|
+
learned_success_rate: learnedRec.success_rate
|
|
789
|
+
};
|
|
790
|
+
} else if (learnedRec) {
|
|
791
|
+
result[phase] = {
|
|
792
|
+
...defaultRec,
|
|
793
|
+
sample_size: learnedRec.sample_size,
|
|
794
|
+
learning_in_progress: true
|
|
795
|
+
};
|
|
796
|
+
} else {
|
|
797
|
+
result[phase] = { ...defaultRec };
|
|
798
|
+
}
|
|
799
|
+
});
|
|
800
|
+
|
|
801
|
+
Object.entries(learned).forEach(([phase, learnedRec]) => {
|
|
802
|
+
if (!result[phase]) {
|
|
803
|
+
result[phase] = {
|
|
804
|
+
...learnedRec,
|
|
805
|
+
is_default: false
|
|
806
|
+
};
|
|
807
|
+
}
|
|
808
|
+
});
|
|
809
|
+
|
|
810
|
+
return result;
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
/**
|
|
814
|
+
* Blend general recommendations
|
|
815
|
+
*/
|
|
816
|
+
function blendGeneralRecommendations(learned, defaults, decisionCount) {
|
|
817
|
+
const result = [];
|
|
818
|
+
|
|
819
|
+
// Add progress indicator based on decision count
|
|
820
|
+
if (decisionCount < BLEND_THRESHOLDS.FULL_LEARNED) {
|
|
821
|
+
result.push({
|
|
822
|
+
priority: 'info',
|
|
823
|
+
message: `Learning in progress: ${decisionCount}/${BLEND_THRESHOLDS.FULL_LEARNED} decisions recorded`,
|
|
824
|
+
action: 'Continue recording outcomes to improve recommendations',
|
|
825
|
+
progress: parseFloat((decisionCount / BLEND_THRESHOLDS.FULL_LEARNED).toFixed(2))
|
|
826
|
+
});
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
// Add defaults for cold start
|
|
830
|
+
if (decisionCount < COLD_START_THRESHOLD) {
|
|
831
|
+
result.push(...defaults);
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
// Add learned recommendations
|
|
835
|
+
result.push(...learned);
|
|
836
|
+
|
|
837
|
+
return result;
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
/**
|
|
841
|
+
* Blend anti-patterns
|
|
842
|
+
*/
|
|
843
|
+
function blendAntiPatterns(learned, defaults, blendRatio) {
|
|
844
|
+
const result = [];
|
|
845
|
+
const seenKeys = new Set();
|
|
846
|
+
|
|
847
|
+
// Add learned anti-patterns first (they take priority)
|
|
848
|
+
learned.forEach(ap => {
|
|
849
|
+
const key = `${ap.type}:${ap.decision}`;
|
|
850
|
+
seenKeys.add(key);
|
|
851
|
+
result.push({
|
|
852
|
+
...ap,
|
|
853
|
+
is_default: false,
|
|
854
|
+
is_learned: true
|
|
855
|
+
});
|
|
856
|
+
});
|
|
857
|
+
|
|
858
|
+
// Add default anti-patterns that weren't overridden
|
|
859
|
+
defaults.forEach(ap => {
|
|
860
|
+
const key = `${ap.type}:${ap.decision}`;
|
|
861
|
+
if (!seenKeys.has(key)) {
|
|
862
|
+
result.push({
|
|
863
|
+
...ap,
|
|
864
|
+
weight: blendRatio.defaultWeight
|
|
865
|
+
});
|
|
866
|
+
}
|
|
867
|
+
});
|
|
868
|
+
|
|
869
|
+
return result;
|
|
870
|
+
}
|
|
871
|
+
|
|
117
872
|
/**
|
|
118
873
|
* Analyze decisions by type
|
|
119
874
|
*/
|
|
@@ -450,11 +1205,250 @@ function getAntiPatterns() {
|
|
|
450
1205
|
return insightsData.anti_patterns;
|
|
451
1206
|
}
|
|
452
1207
|
|
|
1208
|
+
/**
|
|
1209
|
+
* Get default patterns (for cold start or fallback)
|
|
1210
|
+
*/
|
|
1211
|
+
function getDefaults() {
|
|
1212
|
+
return { ...DEFAULT_PATTERNS };
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
/**
|
|
1216
|
+
* Get scenario-based pattern for a specific development task
|
|
1217
|
+
* @param {string} scenario - The scenario name (e.g., 'new_feature', 'bug_fix')
|
|
1218
|
+
* @returns {Object|null} Scenario pattern or null if not found
|
|
1219
|
+
*/
|
|
1220
|
+
function getScenario(scenario) {
|
|
1221
|
+
const normalizedScenario = scenario.toLowerCase().replace(/[\s-]/g, '_');
|
|
1222
|
+
const scenarioPattern = DEFAULT_PATTERNS.scenarios[normalizedScenario];
|
|
1223
|
+
|
|
1224
|
+
if (!scenarioPattern) {
|
|
1225
|
+
// Try to find a partial match
|
|
1226
|
+
const scenarios = Object.keys(DEFAULT_PATTERNS.scenarios);
|
|
1227
|
+
const match = scenarios.find(s =>
|
|
1228
|
+
s.includes(normalizedScenario) || normalizedScenario.includes(s)
|
|
1229
|
+
);
|
|
1230
|
+
return match ? DEFAULT_PATTERNS.scenarios[match] : null;
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
return scenarioPattern;
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
/**
|
|
1237
|
+
* Get all available scenarios
|
|
1238
|
+
* @returns {Object} All scenario patterns
|
|
1239
|
+
*/
|
|
1240
|
+
function getScenarios() {
|
|
1241
|
+
return { ...DEFAULT_PATTERNS.scenarios };
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
/**
|
|
1245
|
+
* Get pattern suggestions for a new project (cold start helper)
|
|
1246
|
+
* Returns prioritized list of patterns for projects with no history
|
|
1247
|
+
* @param {Object} context - Optional context about the project
|
|
1248
|
+
* @returns {Object} Prioritized cold-start recommendations
|
|
1249
|
+
*/
|
|
1250
|
+
function getColdStartPatterns(context = {}) {
|
|
1251
|
+
const patterns = {
|
|
1252
|
+
immediate: [], // Apply these right away
|
|
1253
|
+
recommended: [], // Highly recommended
|
|
1254
|
+
optional: [] // Nice to have
|
|
1255
|
+
};
|
|
1256
|
+
|
|
1257
|
+
// Security patterns are always immediate priority
|
|
1258
|
+
patterns.immediate.push({
|
|
1259
|
+
category: 'security',
|
|
1260
|
+
pattern: DEFAULT_PATTERNS.scenarios.security,
|
|
1261
|
+
recommendation: DEFAULT_PATTERNS.recommendations.by_type.security,
|
|
1262
|
+
reason: 'Security should be built in from the start'
|
|
1263
|
+
});
|
|
1264
|
+
|
|
1265
|
+
// Testing patterns are highly recommended
|
|
1266
|
+
patterns.recommended.push({
|
|
1267
|
+
category: 'testing',
|
|
1268
|
+
pattern: DEFAULT_PATTERNS.scenarios.testing,
|
|
1269
|
+
recommendation: DEFAULT_PATTERNS.recommendations.by_type.testing,
|
|
1270
|
+
reason: 'Early testing reduces bugs and enables confident refactoring'
|
|
1271
|
+
});
|
|
1272
|
+
|
|
1273
|
+
// Context-specific recommendations
|
|
1274
|
+
if (context.hasDatabase) {
|
|
1275
|
+
patterns.immediate.push({
|
|
1276
|
+
category: 'database',
|
|
1277
|
+
pattern: DEFAULT_PATTERNS.scenarios.database_migration,
|
|
1278
|
+
recommendation: DEFAULT_PATTERNS.recommendations.by_type.database,
|
|
1279
|
+
reason: 'Database changes need careful management from day one'
|
|
1280
|
+
});
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
if (context.hasApi) {
|
|
1284
|
+
patterns.recommended.push({
|
|
1285
|
+
category: 'api',
|
|
1286
|
+
pattern: DEFAULT_PATTERNS.scenarios.api_development,
|
|
1287
|
+
recommendation: DEFAULT_PATTERNS.recommendations.by_type.api,
|
|
1288
|
+
reason: 'Good API design prevents breaking changes later'
|
|
1289
|
+
});
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1292
|
+
// Phase-based patterns
|
|
1293
|
+
if (context.phase === 'planning') {
|
|
1294
|
+
patterns.immediate.push({
|
|
1295
|
+
category: 'planning',
|
|
1296
|
+
recommendation: DEFAULT_PATTERNS.recommendations.by_phase.planning,
|
|
1297
|
+
reason: 'Good planning prevents costly rework'
|
|
1298
|
+
});
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
// Add general development patterns
|
|
1302
|
+
patterns.recommended.push({
|
|
1303
|
+
category: 'feature',
|
|
1304
|
+
pattern: DEFAULT_PATTERNS.scenarios.new_feature,
|
|
1305
|
+
recommendation: DEFAULT_PATTERNS.recommendations.by_type.feature,
|
|
1306
|
+
reason: 'Structured feature development improves outcomes'
|
|
1307
|
+
});
|
|
1308
|
+
|
|
1309
|
+
patterns.optional.push({
|
|
1310
|
+
category: 'refactoring',
|
|
1311
|
+
pattern: DEFAULT_PATTERNS.scenarios.refactoring,
|
|
1312
|
+
recommendation: DEFAULT_PATTERNS.recommendations.by_type.refactoring,
|
|
1313
|
+
reason: 'Refactoring practices help maintain code quality'
|
|
1314
|
+
});
|
|
1315
|
+
|
|
1316
|
+
// Include relevant anti-patterns as warnings
|
|
1317
|
+
patterns.warnings = DEFAULT_PATTERNS.anti_patterns.filter(ap =>
|
|
1318
|
+
['security', 'database', 'testing'].includes(ap.type)
|
|
1319
|
+
);
|
|
1320
|
+
|
|
1321
|
+
return patterns;
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
/**
|
|
1325
|
+
* Check if pattern learner has enough data for reliable recommendations
|
|
1326
|
+
* @returns {Object} Status and details about learning progress
|
|
1327
|
+
*/
|
|
1328
|
+
function getLearningStatus() {
|
|
1329
|
+
ensureInsightsFile();
|
|
1330
|
+
const insightsData = JSON.parse(fs.readFileSync(insightsFile, 'utf-8'));
|
|
1331
|
+
const summary = insightsData.analysis_summary || {};
|
|
1332
|
+
const completedDecisions = summary.completed_decisions || 0;
|
|
1333
|
+
const blendRatio = calculateBlendRatio(completedDecisions);
|
|
1334
|
+
|
|
1335
|
+
return {
|
|
1336
|
+
phase: blendRatio.phase,
|
|
1337
|
+
completedDecisions,
|
|
1338
|
+
threshold: COLD_START_THRESHOLD,
|
|
1339
|
+
isUsingDefaults: completedDecisions < COLD_START_THRESHOLD,
|
|
1340
|
+
progress: {
|
|
1341
|
+
toMinimum: Math.min(1, completedDecisions / COLD_START_THRESHOLD),
|
|
1342
|
+
toFullLearning: Math.min(1, completedDecisions / BLEND_THRESHOLDS.FULL_LEARNED)
|
|
1343
|
+
},
|
|
1344
|
+
blendRatio,
|
|
1345
|
+
message: getLearningStatusMessage(completedDecisions, blendRatio.phase)
|
|
1346
|
+
};
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
/**
|
|
1350
|
+
* Get human-readable learning status message
|
|
1351
|
+
*/
|
|
1352
|
+
function getLearningStatusMessage(decisionCount, phase) {
|
|
1353
|
+
const messages = {
|
|
1354
|
+
cold_start: `Cold start: Using default patterns. Record ${COLD_START_THRESHOLD - decisionCount} more decisions to start personalized learning.`,
|
|
1355
|
+
early_learning: `Early learning: Blending defaults with ${decisionCount} recorded decisions.`,
|
|
1356
|
+
balanced: `Balanced: Equal weight to defaults and learned patterns from ${decisionCount} decisions.`,
|
|
1357
|
+
maturing: `Maturing: Recommendations primarily based on ${decisionCount} learned decisions.`,
|
|
1358
|
+
mature: `Mature: Recommendations fully based on ${decisionCount} learned decisions.`
|
|
1359
|
+
};
|
|
1360
|
+
return messages[phase] || messages.cold_start;
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
/**
|
|
1364
|
+
* Override or customize default patterns for a project
|
|
1365
|
+
* Allows projects to provide their own baseline patterns
|
|
1366
|
+
* @param {Object} customPatterns - Custom patterns to merge with defaults
|
|
1367
|
+
* @returns {Object} Merged patterns
|
|
1368
|
+
*/
|
|
1369
|
+
function setProjectDefaults(customPatterns) {
|
|
1370
|
+
// Deep merge custom patterns with defaults
|
|
1371
|
+
const merged = {
|
|
1372
|
+
insights: [
|
|
1373
|
+
...DEFAULT_PATTERNS.insights,
|
|
1374
|
+
...(customPatterns.insights || [])
|
|
1375
|
+
],
|
|
1376
|
+
scenarios: {
|
|
1377
|
+
...DEFAULT_PATTERNS.scenarios,
|
|
1378
|
+
...(customPatterns.scenarios || {})
|
|
1379
|
+
},
|
|
1380
|
+
recommendations: {
|
|
1381
|
+
by_type: {
|
|
1382
|
+
...DEFAULT_PATTERNS.recommendations.by_type,
|
|
1383
|
+
...(customPatterns.recommendations?.by_type || {})
|
|
1384
|
+
},
|
|
1385
|
+
by_phase: {
|
|
1386
|
+
...DEFAULT_PATTERNS.recommendations.by_phase,
|
|
1387
|
+
...(customPatterns.recommendations?.by_phase || {})
|
|
1388
|
+
},
|
|
1389
|
+
general: [
|
|
1390
|
+
...DEFAULT_PATTERNS.recommendations.general,
|
|
1391
|
+
...(customPatterns.recommendations?.general || [])
|
|
1392
|
+
]
|
|
1393
|
+
},
|
|
1394
|
+
anti_patterns: [
|
|
1395
|
+
...DEFAULT_PATTERNS.anti_patterns,
|
|
1396
|
+
...(customPatterns.anti_patterns || [])
|
|
1397
|
+
],
|
|
1398
|
+
correlations: customPatterns.correlations || []
|
|
1399
|
+
};
|
|
1400
|
+
|
|
1401
|
+
// Save to project-specific file if path provided
|
|
1402
|
+
if (customPatterns.projectPath) {
|
|
1403
|
+
const projectPatternsFile = path.join(
|
|
1404
|
+
customPatterns.projectPath,
|
|
1405
|
+
'.bootspring',
|
|
1406
|
+
'custom-patterns.json'
|
|
1407
|
+
);
|
|
1408
|
+
const dir = path.dirname(projectPatternsFile);
|
|
1409
|
+
if (!fs.existsSync(dir)) {
|
|
1410
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
1411
|
+
}
|
|
1412
|
+
fs.writeFileSync(projectPatternsFile, JSON.stringify(customPatterns, null, 2));
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1415
|
+
return merged;
|
|
1416
|
+
}
|
|
1417
|
+
|
|
1418
|
+
/**
|
|
1419
|
+
* Load project-specific custom patterns if they exist
|
|
1420
|
+
* @param {string} projectPath - Path to the project root
|
|
1421
|
+
* @returns {Object|null} Custom patterns or null
|
|
1422
|
+
*/
|
|
1423
|
+
function loadProjectDefaults(projectPath) {
|
|
1424
|
+
const projectPatternsFile = path.join(projectPath, '.bootspring', 'custom-patterns.json');
|
|
1425
|
+
|
|
1426
|
+
if (fs.existsSync(projectPatternsFile)) {
|
|
1427
|
+
try {
|
|
1428
|
+
const customPatterns = JSON.parse(fs.readFileSync(projectPatternsFile, 'utf-8'));
|
|
1429
|
+
return setProjectDefaults(customPatterns);
|
|
1430
|
+
} catch {
|
|
1431
|
+
return null;
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
return null;
|
|
1435
|
+
}
|
|
1436
|
+
|
|
453
1437
|
module.exports = {
|
|
454
1438
|
analyze,
|
|
455
1439
|
getSuggestions,
|
|
456
1440
|
getSummary,
|
|
457
1441
|
getInsights,
|
|
458
1442
|
getAntiPatterns,
|
|
459
|
-
|
|
1443
|
+
getDefaults,
|
|
1444
|
+
getScenario,
|
|
1445
|
+
getScenarios,
|
|
1446
|
+
getColdStartPatterns,
|
|
1447
|
+
getLearningStatus,
|
|
1448
|
+
setProjectDefaults,
|
|
1449
|
+
loadProjectDefaults,
|
|
1450
|
+
CONFIDENCE_LEVELS,
|
|
1451
|
+
DEFAULT_PATTERNS,
|
|
1452
|
+
COLD_START_THRESHOLD,
|
|
1453
|
+
BLEND_THRESHOLDS
|
|
460
1454
|
};
|