@girardmedia/bootspring 2.1.3 → 2.2.1

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 (65) hide show
  1. package/bin/bootspring.js +157 -83
  2. package/claude-commands/agent.md +34 -0
  3. package/claude-commands/bs.md +31 -0
  4. package/claude-commands/build.md +25 -0
  5. package/claude-commands/skill.md +31 -0
  6. package/claude-commands/todo.md +25 -0
  7. package/dist/core/index.d.ts +5814 -0
  8. package/dist/core.js +5779 -0
  9. package/dist/index.js +93883 -0
  10. package/dist/mcp/index.d.ts +1 -0
  11. package/dist/mcp-server.js +2298 -0
  12. package/generators/api-docs.js +3 -3
  13. package/generators/decisions.js +14 -14
  14. package/generators/health.js +6 -6
  15. package/generators/sprint.js +4 -4
  16. package/generators/templates/build-planning.template.js +2 -2
  17. package/generators/visual-doc-generator.js +1 -1
  18. package/package.json +22 -68
  19. package/cli/agent.js +0 -799
  20. package/cli/auth.js +0 -896
  21. package/cli/billing.js +0 -320
  22. package/cli/build.js +0 -1442
  23. package/cli/dashboard.js +0 -123
  24. package/cli/init.js +0 -669
  25. package/cli/mcp.js +0 -240
  26. package/cli/orchestrator.js +0 -240
  27. package/cli/project.js +0 -825
  28. package/cli/quality.js +0 -281
  29. package/cli/skill.js +0 -503
  30. package/cli/switch.js +0 -453
  31. package/cli/todo.js +0 -629
  32. package/cli/update.js +0 -132
  33. package/core/api-client.d.ts +0 -69
  34. package/core/api-client.js +0 -1482
  35. package/core/auth.d.ts +0 -98
  36. package/core/auth.js +0 -737
  37. package/core/build-orchestrator.js +0 -508
  38. package/core/build-state.js +0 -612
  39. package/core/config.d.ts +0 -106
  40. package/core/config.js +0 -1328
  41. package/core/context-loader.js +0 -580
  42. package/core/context.d.ts +0 -61
  43. package/core/context.js +0 -327
  44. package/core/entitlements.d.ts +0 -70
  45. package/core/entitlements.js +0 -322
  46. package/core/index.d.ts +0 -53
  47. package/core/index.js +0 -62
  48. package/core/mcp-config.js +0 -115
  49. package/core/policies.d.ts +0 -43
  50. package/core/policies.js +0 -113
  51. package/core/policy-matrix.js +0 -303
  52. package/core/project-activity.js +0 -175
  53. package/core/redaction.d.ts +0 -5
  54. package/core/redaction.js +0 -63
  55. package/core/self-update.js +0 -259
  56. package/core/session.js +0 -353
  57. package/core/task-extractor.js +0 -1098
  58. package/core/telemetry.d.ts +0 -55
  59. package/core/telemetry.js +0 -617
  60. package/core/tier-enforcement.js +0 -928
  61. package/core/utils.d.ts +0 -90
  62. package/core/utils.js +0 -455
  63. package/core/validation.js +0 -572
  64. package/mcp/server.d.ts +0 -57
  65. package/mcp/server.js +0 -264
@@ -1,1098 +0,0 @@
1
- /**
2
- * Bootspring Task Extractor
3
- *
4
- * Extracts implementation tasks from seed documents (SEED.md, PRD.md, ROADMAP.md, etc.)
5
- * and organizes them into an ordered implementation queue.
6
- *
7
- * @package bootspring
8
- * @module core/task-extractor
9
- */
10
-
11
- const fs = require('fs');
12
- const path = require('path');
13
-
14
- /**
15
- * Main extraction function - parse all seed documents
16
- * @param {object} docs - Document contents { SEED: string, PRD: string, ROADMAP: string, ... }
17
- * @param {object} options - Extraction options
18
- * @returns {object} Extracted tasks and metadata
19
- */
20
- function extractFromDocs(docs, options = {}) {
21
- const result = {
22
- tasks: [],
23
- phases: [],
24
- mvpCriteria: [],
25
- metadata: {
26
- extractedAt: new Date().toISOString(),
27
- sources: Object.keys(docs)
28
- }
29
- };
30
-
31
- // Extract from PRD (primary source for features)
32
- if (docs.PRD || docs.prd) {
33
- const prdContent = docs.PRD || docs.prd;
34
- const prdTasks = extractFromPrd(prdContent);
35
- result.tasks.push(...prdTasks);
36
- result.mvpCriteria.push(...extractMvpCriteria(prdContent));
37
- }
38
-
39
- // Extract from ROADMAP (phases and milestones)
40
- if (docs.ROADMAP || docs.roadmap) {
41
- const roadmapContent = docs.ROADMAP || docs.roadmap;
42
- const { phases, phaseTasks } = extractFromRoadmap(roadmapContent);
43
- result.phases = phases;
44
- result.tasks.push(...phaseTasks);
45
- }
46
-
47
- // Extract from TECHNICAL_SPEC (architecture tasks)
48
- if (docs.TECHNICAL_SPEC || docs.technical_spec) {
49
- const techContent = docs.TECHNICAL_SPEC || docs.technical_spec;
50
- const techTasks = extractFromTechnicalSpec(techContent);
51
- result.tasks.push(...techTasks);
52
- }
53
-
54
- // Extract from SEED.md (may have additional features)
55
- if (docs.SEED || docs.seed) {
56
- const seedContent = docs.SEED || docs.seed;
57
- const seedTasks = extractFromSeed(seedContent);
58
- result.tasks.push(...seedTasks);
59
- }
60
-
61
- // Deduplicate tasks
62
- result.tasks = deduplicateTasks(result.tasks);
63
-
64
- // Order by dependencies
65
- result.tasks = orderByDependencies(result.tasks);
66
-
67
- // Assign IDs if not present
68
- result.tasks = result.tasks.map((task, index) => ({
69
- ...task,
70
- id: task.id || `task-${(index + 1).toString().padStart(3, '0')}`
71
- }));
72
-
73
- return result;
74
- }
75
-
76
- /**
77
- * Extract tasks from PRD.md
78
- * @param {string} content - PRD content
79
- * @returns {array} Tasks
80
- */
81
- function extractFromPrd(content) {
82
- const tasks = [];
83
-
84
- // Extract from MVP Features section (#### F-XXX: Feature Name pattern)
85
- const mvpSection = extractSection(content, 'MVP\\s+Features|P1\\s+.*Features|Must\\s+Ship', { maxLength: 10000 });
86
- if (mvpSection) {
87
- // Look for feature headers like "#### F-001: Feature Name"
88
- const featureMatches = mvpSection.matchAll(/^#{1,4}\s+(F-\d+):\s*(.+)$/gm);
89
- for (const match of featureMatches) {
90
- const featureId = match[1];
91
- const featureName = match[2].trim();
92
-
93
- // Try to find acceptance criteria for this feature
94
- const acceptanceCriteria = extractAcceptanceCriteria(mvpSection, featureId);
95
-
96
- tasks.push({
97
- title: `Implement ${featureName}`,
98
- source: 'PRD.md',
99
- sourceSection: `${featureId}: ${featureName}`,
100
- phase: 'mvp',
101
- status: 'pending',
102
- acceptanceCriteria,
103
- estimatedComplexity: estimateComplexity(featureName, acceptanceCriteria)
104
- });
105
- }
106
- }
107
-
108
- // Extract from Feature Requirements section (FR-XX patterns)
109
- const frSection = extractSection(content, 'Feature\\s+Requirements', { maxLength: 10000 });
110
- if (frSection) {
111
- const frMatches = frSection.matchAll(/\*{0,2}(FR-\d+):?\*{0,2}\s*(.+)/g);
112
- for (const match of frMatches) {
113
- const frId = match[1];
114
- const frName = match[2].replace(/\*+/g, '').trim();
115
-
116
- // Skip if we already have a similar task
117
- if (!tasks.some(t => t.title.toLowerCase().includes(frName.toLowerCase().slice(0, 20)))) {
118
- tasks.push({
119
- title: frName,
120
- source: 'PRD.md',
121
- sourceSection: frId,
122
- phase: 'mvp',
123
- status: 'pending',
124
- acceptanceCriteria: [],
125
- estimatedComplexity: 'medium'
126
- });
127
- }
128
- }
129
- }
130
-
131
- // Extract from User Stories section
132
- const storiesSection = extractSection(content, 'User\\s+Stories|Stories', { maxLength: 10000 });
133
- if (storiesSection) {
134
- // Look for "As a... I want... so that..." patterns
135
- const storyMatches = storiesSection.matchAll(/As\s+a[n]?\s+([^,]+),\s*I\s+want\s+([^,]+?)(?:,\s*so\s+that|$)/gi);
136
- for (const match of storyMatches) {
137
- const role = match[1].trim();
138
- const want = match[2].trim();
139
-
140
- const title = `${want.charAt(0).toUpperCase() + want.slice(1)}`;
141
-
142
- if (!tasks.some(t => t.title.toLowerCase().includes(want.toLowerCase().slice(0, 15)))) {
143
- tasks.push({
144
- title,
145
- description: `As a ${role}, I want ${want}`,
146
- source: 'PRD.md',
147
- sourceSection: 'User Stories',
148
- phase: 'mvp',
149
- status: 'pending',
150
- acceptanceCriteria: [],
151
- estimatedComplexity: 'medium'
152
- });
153
- }
154
- }
155
- }
156
-
157
- // Extract from Core User Journeys
158
- const journeySection = extractSection(content, 'Core\\s+User\\s+Journeys|User\\s+Journeys', { maxLength: 5000 });
159
- if (journeySection) {
160
- const journeyMatches = journeySection.matchAll(/^#{1,4}\s+\d+\.\d+\s+Journey\s+\d+\s*[—-]\s*(.+)$/gm);
161
- for (const match of journeyMatches) {
162
- const journeyName = match[1].trim();
163
-
164
- if (!tasks.some(t => t.title.toLowerCase().includes(journeyName.toLowerCase().slice(0, 15)))) {
165
- tasks.push({
166
- title: `Implement ${journeyName} journey`,
167
- source: 'PRD.md',
168
- sourceSection: 'User Journeys',
169
- phase: 'mvp',
170
- status: 'pending',
171
- acceptanceCriteria: [],
172
- estimatedComplexity: 'high'
173
- });
174
- }
175
- }
176
- }
177
-
178
- return tasks;
179
- }
180
-
181
- /**
182
- * Extract tasks and phases from ROADMAP.md
183
- * @param {string} content - ROADMAP content
184
- * @returns {object} { phases: array, phaseTasks: array }
185
- */
186
- function extractFromRoadmap(content) {
187
- const phases = [];
188
- const phaseTasks = [];
189
- const seenPhases = new Set();
190
-
191
- // Extract phase headers: "## X. Phase N — Name"
192
- const phaseMatches = content.matchAll(/^##\s+\d+\.\s+Phase\s+(\d+)\s*[—-]+\s*(.+)$/gm);
193
-
194
- for (const match of phaseMatches) {
195
- const phaseNum = match[1];
196
- const phaseName = match[2].trim().replace(/\s*\([^)]+\)\s*$/, '');
197
-
198
- if (seenPhases.has(phaseNum)) continue;
199
- seenPhases.add(phaseNum);
200
-
201
- // Determine phase type
202
- const phaseType = phaseNum === '1' ? 'foundation' :
203
- phaseNum === '2' ? 'mvp' :
204
- phaseNum === '3' ? 'launch' : `phase${phaseNum}`;
205
-
206
- // Extract deliverables for this phase
207
- const phaseRegex = new RegExp(
208
- `##\\s+\\d+\\.\\s+Phase\\s+${phaseNum}\\s*[—-][\\s\\S]*?(?=##\\s+\\d+\\.\\s+Phase\\s+\\d+|$)`,
209
- 'i'
210
- );
211
- const phaseSectionMatch = content.match(phaseRegex);
212
-
213
- const deliverables = [];
214
- if (phaseSectionMatch) {
215
- const phaseContent = phaseSectionMatch[0];
216
-
217
- // Look for deliverables subsection
218
- const deliverablesRegex = /###\s+[\d.]+\s*Deliverables[\s\S]*?(?=###|##|$)/i;
219
- const deliverablesMatch = phaseContent.match(deliverablesRegex);
220
-
221
- if (deliverablesMatch) {
222
- const bullets = deliverablesMatch[0].match(/^[-*]\s+(.+)$/gm);
223
- if (bullets) {
224
- bullets.slice(0, 8).forEach(b => {
225
- const text = b.replace(/^[-*]\s+/, '').trim();
226
- if (text.length > 3) {
227
- deliverables.push(text);
228
-
229
- // Create task for each deliverable
230
- phaseTasks.push({
231
- title: text,
232
- source: 'ROADMAP.md',
233
- sourceSection: `Phase ${phaseNum}: ${phaseName}`,
234
- phase: phaseType,
235
- status: 'pending',
236
- acceptanceCriteria: [],
237
- estimatedComplexity: 'medium'
238
- });
239
- }
240
- });
241
- }
242
- }
243
-
244
- // If no deliverables, look for feature headers (#### A) B) C) patterns)
245
- if (deliverables.length === 0) {
246
- const featureHeaders = phaseContent.match(/^####\s+[A-Z]\)\s+(.+)$/gm);
247
- if (featureHeaders) {
248
- featureHeaders.slice(0, 6).forEach(h => {
249
- const hMatch = h.match(/####\s+[A-Z]\)\s+(.+)/);
250
- if (hMatch && hMatch[1]) {
251
- const title = hMatch[1].trim();
252
- deliverables.push(title);
253
-
254
- phaseTasks.push({
255
- title: `Implement ${title}`,
256
- source: 'ROADMAP.md',
257
- sourceSection: `Phase ${phaseNum}: ${phaseName}`,
258
- phase: phaseType,
259
- status: 'pending',
260
- acceptanceCriteria: [],
261
- estimatedComplexity: 'high'
262
- });
263
- }
264
- });
265
- }
266
- }
267
-
268
- // Look for exit criteria
269
- const exitCriteriaRegex = /###\s+[\d.]+\s*Exit\s+Criteria[\s\S]*?(?=###|##|$)/i;
270
- const exitMatch = phaseContent.match(exitCriteriaRegex);
271
- if (exitMatch) {
272
- const checkItems = exitMatch[0].match(/^[-*]\s+[✅✓⬜]\s*(.+)$/gm);
273
- if (checkItems) {
274
- checkItems.forEach(item => {
275
- const text = item.replace(/^[-*]\s+[✅✓⬜]\s*/, '').trim();
276
- if (text.length > 5 && !deliverables.includes(text)) {
277
- deliverables.push(text);
278
- }
279
- });
280
- }
281
- }
282
- }
283
-
284
- phases.push({
285
- phase: phaseNum,
286
- name: phaseName,
287
- type: phaseType,
288
- deliverables
289
- });
290
- }
291
-
292
- return { phases, phaseTasks };
293
- }
294
-
295
- /**
296
- * Extract tasks from TECHNICAL_SPEC.md
297
- * @param {string} content - Technical spec content
298
- * @returns {array} Tasks
299
- */
300
- function extractFromTechnicalSpec(content) {
301
- const tasks = [];
302
-
303
- // Extract database setup tasks
304
- const dbSection = extractSection(content, 'Data\\s+Model|Database|Key\\s+tables', { maxLength: 3000 });
305
- if (dbSection) {
306
- // Look for table names
307
- const tableMatches = dbSection.match(/^\s*[-*]\s*`(\w+)`/gm);
308
- if (tableMatches && tableMatches.length > 0) {
309
- tasks.push({
310
- title: 'Set up database schema with Prisma',
311
- description: `Create database models for: ${tableMatches.slice(0, 5).map(m => m.match(/`(\w+)`/)?.[1]).filter(Boolean).join(', ')}`,
312
- source: 'TECHNICAL_SPEC.md',
313
- sourceSection: 'Database Schema',
314
- phase: 'foundation',
315
- status: 'pending',
316
- acceptanceCriteria: [
317
- 'Prisma schema defined with all models',
318
- 'Database migrations generated',
319
- 'Seed data scripts created'
320
- ],
321
- estimatedComplexity: 'high'
322
- });
323
- }
324
- }
325
-
326
- // Extract API route tasks
327
- const apiSection = extractSection(content, 'API\\s+Routes|Application\\s+Structure', { maxLength: 3000 });
328
- if (apiSection) {
329
- // Group related API routes
330
- const apiGroups = new Map();
331
- const apiMatches = apiSection.matchAll(/`\/api\/([^`/]+)/g);
332
-
333
- for (const match of apiMatches) {
334
- const group = match[1];
335
- if (!apiGroups.has(group)) {
336
- apiGroups.set(group, []);
337
- }
338
- }
339
-
340
- if (apiGroups.size > 0) {
341
- tasks.push({
342
- title: 'Implement core API endpoints',
343
- description: `Set up API routes for: ${[...apiGroups.keys()].slice(0, 5).join(', ')}`,
344
- source: 'TECHNICAL_SPEC.md',
345
- sourceSection: 'API Routes',
346
- phase: 'mvp',
347
- status: 'pending',
348
- acceptanceCriteria: [
349
- 'All CRUD endpoints implemented',
350
- 'Input validation with Zod',
351
- 'Error handling middleware',
352
- 'API documentation updated'
353
- ],
354
- estimatedComplexity: 'high'
355
- });
356
- }
357
- }
358
-
359
- // Extract architecture setup tasks
360
- const archSection = extractSection(content, 'Core\\s+system\\s+components|Architecture', { maxLength: 2000 });
361
- if (archSection) {
362
- const compMatches = archSection.match(/^\s*\d+\)\s*(.+)$/gm);
363
- if (compMatches && compMatches.length > 0) {
364
- tasks.push({
365
- title: 'Set up project architecture and scaffolding',
366
- description: 'Configure project structure, linting, testing, and CI/CD',
367
- source: 'TECHNICAL_SPEC.md',
368
- sourceSection: 'Architecture',
369
- phase: 'foundation',
370
- status: 'pending',
371
- acceptanceCriteria: [
372
- 'Project structure follows conventions',
373
- 'ESLint and Prettier configured',
374
- 'Testing framework set up',
375
- 'CI/CD pipeline configured'
376
- ],
377
- estimatedComplexity: 'medium',
378
- dependencies: []
379
- });
380
- }
381
- }
382
-
383
- // Extract third-party integration tasks
384
- const integrations = extractIntegrations(content);
385
- const intCategories = Object.entries(integrations).filter(([_, v]) => v.length > 0);
386
-
387
- if (intCategories.length > 0) {
388
- for (const [category, services] of intCategories) {
389
- if (services.length > 0) {
390
- tasks.push({
391
- title: `Integrate ${category} services (${services.join(', ')})`,
392
- source: 'TECHNICAL_SPEC.md',
393
- sourceSection: 'Integrations',
394
- phase: 'mvp',
395
- status: 'pending',
396
- acceptanceCriteria: services.map(s => `${s} integration working`),
397
- estimatedComplexity: services.length > 2 ? 'high' : 'medium'
398
- });
399
- }
400
- }
401
- }
402
-
403
- return tasks;
404
- }
405
-
406
- /**
407
- * Extract tasks from SEED.md
408
- * @param {string} content - SEED content
409
- * @returns {array} Tasks
410
- */
411
- function extractFromSeed(content) {
412
- const tasks = [];
413
-
414
- // Extract MVP Features section
415
- const mvpSection = extractSection(content, 'MVP\\s+Features', { maxLength: 5000 });
416
- if (mvpSection) {
417
- // Look for numbered list items
418
- const featureMatches = mvpSection.matchAll(/^\d+\.\s+(.+)$/gm);
419
- for (const match of featureMatches) {
420
- const featureName = match[1].trim();
421
-
422
- tasks.push({
423
- title: `Implement ${featureName}`,
424
- source: 'SEED.md',
425
- sourceSection: 'MVP Features',
426
- phase: 'mvp',
427
- status: 'pending',
428
- acceptanceCriteria: [],
429
- estimatedComplexity: 'medium'
430
- });
431
- }
432
- }
433
-
434
- return tasks;
435
- }
436
-
437
- /**
438
- * Extract MVP completion criteria
439
- * @param {string} content - Document content
440
- * @returns {array} MVP criteria
441
- */
442
- function extractMvpCriteria(content) {
443
- const criteria = [];
444
-
445
- // Look for MVP Success Criteria or similar sections
446
- const successSection = extractSection(content, 'MVP\\s+Success|Success\\s+Criteria|Definition\\s+of\\s+Done', { maxLength: 3000 });
447
-
448
- if (successSection) {
449
- const bulletMatches = successSection.match(/^[-*]\s+(.+)$/gm);
450
- if (bulletMatches) {
451
- bulletMatches.forEach(b => {
452
- const text = b.replace(/^[-*]\s+/, '').replace(/\*+/g, '').trim();
453
- if (text.length > 5) {
454
- criteria.push({
455
- name: text,
456
- status: 'pending'
457
- });
458
- }
459
- });
460
- }
461
- }
462
-
463
- // Also extract from MVP Features as criteria
464
- const mvpSection = extractSection(content, 'MVP\\s+Features|P1\\s+.*Features', { maxLength: 5000 });
465
- if (mvpSection) {
466
- const featureHeaders = mvpSection.match(/^#{1,4}\s+F-\d+:\s*(.+)$/gm);
467
- if (featureHeaders) {
468
- featureHeaders.forEach(h => {
469
- const match = h.match(/F-\d+:\s*(.+)/);
470
- if (match && match[1]) {
471
- criteria.push({
472
- name: match[1].trim(),
473
- status: 'pending'
474
- });
475
- }
476
- });
477
- }
478
- }
479
-
480
- return criteria;
481
- }
482
-
483
- /**
484
- * Order tasks by dependencies (topological sort)
485
- * @param {array} tasks - Tasks to order
486
- * @returns {array} Ordered tasks
487
- */
488
- function orderByDependencies(tasks) {
489
- // Build dependency graph
490
- const taskMap = new Map(tasks.map((t, i) => [t.id || `task-${i}`, t]));
491
- const visited = new Set();
492
- const result = [];
493
-
494
- // Add foundation tasks first
495
- const foundationTasks = tasks.filter(t => t.phase === 'foundation');
496
- const mvpTasks = tasks.filter(t => t.phase === 'mvp');
497
- const launchTasks = tasks.filter(t => t.phase === 'launch');
498
- const otherTasks = tasks.filter(t => !['foundation', 'mvp', 'launch'].includes(t.phase));
499
-
500
- // Order by priority within phases
501
- const priorityOrder = [
502
- // Foundation tasks first
503
- ...foundationTasks.filter(t => t.title.toLowerCase().includes('setup') || t.title.toLowerCase().includes('scaffold')),
504
- ...foundationTasks.filter(t => t.title.toLowerCase().includes('database') || t.title.toLowerCase().includes('schema')),
505
- ...foundationTasks.filter(t => !t.title.toLowerCase().includes('setup') && !t.title.toLowerCase().includes('database')),
506
-
507
- // MVP tasks
508
- ...mvpTasks.filter(t => t.title.toLowerCase().includes('auth')),
509
- ...mvpTasks.filter(t => t.title.toLowerCase().includes('api')),
510
- ...mvpTasks.filter(t => !t.title.toLowerCase().includes('auth') && !t.title.toLowerCase().includes('api')),
511
-
512
- // Launch tasks
513
- ...launchTasks,
514
-
515
- // Other tasks
516
- ...otherTasks
517
- ];
518
-
519
- return priorityOrder;
520
- }
521
-
522
- /**
523
- * Deduplicate tasks based on title similarity
524
- * @param {array} tasks - Tasks to deduplicate
525
- * @returns {array} Deduplicated tasks
526
- */
527
- function deduplicateTasks(tasks) {
528
- const seen = new Map();
529
-
530
- return tasks.filter(task => {
531
- // Normalize title for comparison
532
- const normalizedTitle = task.title
533
- .toLowerCase()
534
- .replace(/^implement\s+/i, '')
535
- .replace(/\s+/g, ' ')
536
- .trim();
537
-
538
- // Check first 30 chars for similarity
539
- const key = normalizedTitle.slice(0, 30);
540
-
541
- if (seen.has(key)) {
542
- // Merge acceptance criteria
543
- const existing = seen.get(key);
544
- if (task.acceptanceCriteria?.length > existing.acceptanceCriteria?.length) {
545
- existing.acceptanceCriteria = task.acceptanceCriteria;
546
- }
547
- return false;
548
- }
549
-
550
- seen.set(key, task);
551
- return true;
552
- });
553
- }
554
-
555
- /**
556
- * Extract acceptance criteria for a feature
557
- * @param {string} content - Section content
558
- * @param {string} featureId - Feature ID
559
- * @returns {array} Acceptance criteria
560
- */
561
- function extractAcceptanceCriteria(content, featureId) {
562
- const criteria = [];
563
-
564
- // Look for acceptance criteria section after feature header
565
- const featureRegex = new RegExp(
566
- `#{1,4}\\s+${featureId}:[\\s\\S]*?(?=#{1,4}\\s+F-\\d+:|$)`,
567
- 'i'
568
- );
569
- const featureMatch = content.match(featureRegex);
570
-
571
- if (featureMatch) {
572
- const featureContent = featureMatch[0];
573
-
574
- // Look for bullet points
575
- const bulletMatches = featureContent.match(/^[-*]\s+(.+)$/gm);
576
- if (bulletMatches) {
577
- bulletMatches.slice(0, 5).forEach(b => {
578
- const text = b.replace(/^[-*]\s+/, '').replace(/\*+/g, '').trim();
579
- if (text.length > 5 && text.length < 200) {
580
- criteria.push(text);
581
- }
582
- });
583
- }
584
- }
585
-
586
- return criteria;
587
- }
588
-
589
- /**
590
- * Estimate task complexity
591
- * @param {string} title - Task title
592
- * @param {array} acceptanceCriteria - Acceptance criteria
593
- * @returns {string} Complexity: low, medium, high
594
- */
595
- function estimateComplexity(title, acceptanceCriteria = []) {
596
- const titleLower = title.toLowerCase();
597
-
598
- // High complexity indicators
599
- const highIndicators = [
600
- 'authentication', 'payment', 'integration', 'real-time',
601
- 'voice', 'agent', 'workflow', 'pipeline', 'migration',
602
- 'security', 'encryption', 'multi-tenant'
603
- ];
604
-
605
- // Low complexity indicators
606
- const lowIndicators = [
607
- 'ui', 'style', 'button', 'form', 'display', 'show',
608
- 'list', 'view', 'page', 'component', 'typo', 'fix'
609
- ];
610
-
611
- if (highIndicators.some(i => titleLower.includes(i))) {
612
- return 'high';
613
- }
614
-
615
- if (lowIndicators.some(i => titleLower.includes(i))) {
616
- return 'low';
617
- }
618
-
619
- // Also consider acceptance criteria count
620
- if (acceptanceCriteria.length > 5) {
621
- return 'high';
622
- }
623
-
624
- return 'medium';
625
- }
626
-
627
- /**
628
- * Extract a section from markdown content
629
- * @param {string} content - Markdown content
630
- * @param {string} headingPattern - Heading pattern to match
631
- * @param {object} options - Options
632
- * @returns {string|null} Section content or null
633
- */
634
- function extractSection(content, headingPattern, options = {}) {
635
- const { maxLength = 2000 } = options;
636
-
637
- const headingRegex = new RegExp(`^(#{1,4})\\s*(?:\\d+\\.\\s*)?(?:${headingPattern})[^\\n]*\\n`, 'im');
638
- const match = content.match(headingRegex);
639
- if (!match || !match[1]) return null;
640
-
641
- const startIndex = match.index + match[0].length;
642
- const headingLevel = match[1].length;
643
-
644
- const restContent = content.slice(startIndex);
645
- const nextHeadingRegex = new RegExp(`^#{1,${headingLevel}}\\s+`, 'm');
646
- const nextMatch = restContent.match(nextHeadingRegex);
647
-
648
- let sectionContent = nextMatch
649
- ? restContent.slice(0, nextMatch.index)
650
- : restContent;
651
-
652
- sectionContent = sectionContent.trim();
653
- if (sectionContent.length > maxLength) {
654
- sectionContent = sectionContent.slice(0, maxLength);
655
- }
656
-
657
- return sectionContent || null;
658
- }
659
-
660
- /**
661
- * Extract third-party integrations from content
662
- * @param {string} content - Document content
663
- * @returns {object} Integrations by category
664
- */
665
- function extractIntegrations(content) {
666
- const integrations = {
667
- auth: [],
668
- payments: [],
669
- email: [],
670
- ai: []
671
- };
672
-
673
- // Auth
674
- if (content.match(/\bClerk\b/i)) integrations.auth.push('Clerk');
675
- if (content.match(/\bNextAuth|Auth\.js/i)) integrations.auth.push('NextAuth');
676
-
677
- // Payments
678
- if (content.match(/\bStripe\b/i)) integrations.payments.push('Stripe');
679
- if (content.match(/\bPaddle\b/i)) integrations.payments.push('Paddle');
680
-
681
- // Email
682
- if (content.match(/\bSendGrid\b/i)) integrations.email.push('SendGrid');
683
- if (content.match(/\bResend\b/i)) integrations.email.push('Resend');
684
-
685
- // AI
686
- if (content.match(/\bOpenAI\b|GPT-4/i)) integrations.ai.push('OpenAI');
687
- if (content.match(/\bAnthropic\b|Claude/i)) integrations.ai.push('Anthropic');
688
-
689
- return integrations;
690
- }
691
-
692
- /**
693
- * Load and extract from preseed directory
694
- * @param {string} projectRoot - Project root path
695
- * @returns {object} Extracted tasks and metadata
696
- */
697
- function extractFromPreseedDir(projectRoot) {
698
- const preseedDir = path.join(projectRoot, '.bootspring', 'preseed');
699
-
700
- if (!fs.existsSync(preseedDir)) {
701
- return { tasks: [], phases: [], mvpCriteria: [], error: 'No preseed directory found' };
702
- }
703
-
704
- const validDocs = [
705
- 'VISION.md', 'AUDIENCE.md', 'MARKET.md', 'COMPETITORS.md',
706
- 'BUSINESS_MODEL.md', 'PRD.md', 'TECHNICAL_SPEC.md', 'ROADMAP.md'
707
- ];
708
-
709
- const docs = {};
710
-
711
- for (const file of validDocs) {
712
- const filePath = path.join(preseedDir, file);
713
- if (fs.existsSync(filePath)) {
714
- const docName = file.replace('.md', '');
715
- docs[docName] = fs.readFileSync(filePath, 'utf-8');
716
- }
717
- }
718
-
719
- if (Object.keys(docs).length === 0) {
720
- return { tasks: [], phases: [], mvpCriteria: [], error: 'No preseed documents found' };
721
- }
722
-
723
- return extractFromDocs(docs);
724
- }
725
-
726
- /**
727
- * Load and extract from SEED.md
728
- * @param {string} projectRoot - Project root path
729
- * @returns {object} Extracted tasks and metadata
730
- */
731
- function extractFromSeedFile(projectRoot) {
732
- const seedPath = path.join(projectRoot, 'SEED.md');
733
-
734
- if (!fs.existsSync(seedPath)) {
735
- return { tasks: [], phases: [], mvpCriteria: [], error: 'No SEED.md found' };
736
- }
737
-
738
- const seedContent = fs.readFileSync(seedPath, 'utf-8');
739
-
740
- return extractFromDocs({ SEED: seedContent });
741
- }
742
-
743
- function normalizeQueueTaskStatus(value) {
744
- const normalized = String(value || 'pending')
745
- .trim()
746
- .toLowerCase()
747
- .replace(/[\s-]+/g, '_');
748
-
749
- if (normalized === 'done' || normalized === 'complete' || normalized === 'completed') {
750
- return 'completed';
751
- }
752
- if (normalized === 'inprogress' || normalized === 'in_progress') {
753
- return 'in_progress';
754
- }
755
- return normalized === 'pending' ? 'pending' : 'pending';
756
- }
757
-
758
- function normalizeQueueTaskPhase(value) {
759
- const normalized = String(value || 'mvp')
760
- .trim()
761
- .toLowerCase()
762
- .replace(/[\s-]+/g, '_');
763
-
764
- return ['foundation', 'mvp', 'launch'].includes(normalized) ? normalized : 'mvp';
765
- }
766
-
767
- function normalizeQueueComplexity(value) {
768
- const normalized = String(value || 'medium').trim().toLowerCase();
769
- return ['low', 'medium', 'high'].includes(normalized) ? normalized : 'medium';
770
- }
771
-
772
- function parseDependencyIds(rawText) {
773
- const ids = [];
774
- const seen = new Set();
775
- const tokenMatches = rawText.match(/[a-z0-9][a-z0-9_-]*/gi) || [];
776
-
777
- for (const rawToken of tokenMatches) {
778
- const token = rawToken.trim().replace(/[.,;:]+$/, '');
779
- if (!token || !token.includes('-') || !/\d/.test(token)) continue;
780
- if (seen.has(token)) continue;
781
- seen.add(token);
782
- ids.push(token);
783
- }
784
-
785
- return ids;
786
- }
787
-
788
- function extractDependenciesFromSection(sectionContent) {
789
- const dependencies = [];
790
- const seen = new Set();
791
-
792
- const inlineMatch = sectionContent.match(/\*{0,2}(?:Dependencies|Depends on):\*{0,2}\s*([^\n]+)/i);
793
- if (inlineMatch && inlineMatch[1]) {
794
- for (const depId of parseDependencyIds(inlineMatch[1])) {
795
- if (!seen.has(depId)) {
796
- seen.add(depId);
797
- dependencies.push(depId);
798
- }
799
- }
800
- }
801
-
802
- const blockMatch = sectionContent.match(/\*{0,2}(?:Dependencies|Depends on):\*{0,2}\s*\n([\s\S]*?)(?=\n\*{0,2}[A-Z]|\n---|\n###|$)/i);
803
- if (blockMatch && blockMatch[1]) {
804
- const bullets = blockMatch[1].matchAll(/^\s*[-*]\s*(?:\[[ xX]\]\s*)?(.+)$/gm);
805
- for (const bullet of bullets) {
806
- for (const depId of parseDependencyIds(bullet[1] || '')) {
807
- if (!seen.has(depId)) {
808
- seen.add(depId);
809
- dependencies.push(depId);
810
- }
811
- }
812
- }
813
-
814
- if (dependencies.length === 0) {
815
- for (const depId of parseDependencyIds(blockMatch[1])) {
816
- if (!seen.has(depId)) {
817
- seen.add(depId);
818
- dependencies.push(depId);
819
- }
820
- }
821
- }
822
- }
823
-
824
- return dependencies;
825
- }
826
-
827
- function sortTasksWithDependencyChecks(tasks) {
828
- const taskById = new Map();
829
- const orderById = new Map();
830
- const orderedByInput = [];
831
-
832
- tasks.forEach((task, index) => {
833
- orderedByInput.push(task);
834
- if (task.id) {
835
- taskById.set(task.id, task);
836
- orderById.set(task.id, index);
837
- }
838
- });
839
-
840
- const visited = new Set();
841
- const visiting = new Set();
842
- const ordered = [];
843
-
844
- function visit(task) {
845
- const taskId = task.id || '';
846
- if (visited.has(taskId)) return;
847
- if (visiting.has(taskId)) return;
848
-
849
- visiting.add(taskId);
850
-
851
- const deps = (task.dependencies || [])
852
- .filter(depId => taskById.has(depId))
853
- .sort((a, b) => (orderById.get(a) ?? Number.MAX_SAFE_INTEGER) - (orderById.get(b) ?? Number.MAX_SAFE_INTEGER));
854
-
855
- for (const depId of deps) {
856
- const depTask = taskById.get(depId);
857
- if (depTask) {
858
- visit(depTask);
859
- }
860
- }
861
-
862
- visiting.delete(taskId);
863
- visited.add(taskId);
864
- ordered.push(task);
865
- }
866
-
867
- for (const task of orderedByInput) {
868
- visit(task);
869
- }
870
-
871
- for (const task of orderedByInput) {
872
- if (!ordered.includes(task)) {
873
- ordered.push(task);
874
- }
875
- }
876
-
877
- return ordered;
878
- }
879
-
880
- /**
881
- * Extract tasks from TASK_QUEUE.md
882
- * Parses both table format and detailed task sections
883
- * @param {string} content - TASK_QUEUE.md content
884
- * @returns {Array} Parsed tasks
885
- */
886
- function extractFromTaskQueue(content) {
887
- const tasks = [];
888
-
889
- const tableMatches = content.matchAll(/^\|\s*([^|]+)\s*\|\s*([a-z0-9][a-z0-9_-]*)\s*\|\s*([^|]+)\s*\|\s*([^|]+)\s*\|\s*([^|]+)\s*\|\s*([^|]+)\s*\|$/gmi);
890
-
891
- for (const match of tableMatches) {
892
- const id = match[2]?.trim() || '';
893
- const title = match[3]?.trim() || '';
894
- const phase = normalizeQueueTaskPhase(match[4]?.trim());
895
- const complexity = normalizeQueueComplexity(match[5]?.trim());
896
- const status = normalizeQueueTaskStatus(match[6]?.trim());
897
-
898
- if (
899
- id.toLowerCase() === 'id' ||
900
- title.toLowerCase() === 'task' ||
901
- id.includes('---') ||
902
- title.includes('---')
903
- ) continue;
904
-
905
- tasks.push({
906
- id,
907
- title,
908
- source: 'TASK_QUEUE.md',
909
- sourceSection: 'Queue Status',
910
- phase,
911
- status,
912
- acceptanceCriteria: [],
913
- estimatedComplexity: complexity
914
- });
915
- }
916
-
917
- const detailMatches = content.matchAll(/^###\s+(task-\d+|[\w-]+):\s*(.+)$/gm);
918
-
919
- for (const match of detailMatches) {
920
- const id = match[1]?.trim() || '';
921
- const title = match[2]?.trim() || '';
922
-
923
- const sectionStart = (match.index || 0) + match[0].length;
924
- const nextSection = content.slice(sectionStart).search(/^###\s+/m);
925
- const sectionContent = nextSection === -1
926
- ? content.slice(sectionStart)
927
- : content.slice(sectionStart, sectionStart + nextSection);
928
-
929
- const phaseMatch = sectionContent.match(/\*{0,2}Phase:\*{0,2}\s*(\w+(?:\s*\d+)?)/i);
930
- const phase = normalizeQueueTaskPhase(phaseMatch?.[1]?.trim());
931
-
932
- const complexityMatch = sectionContent.match(/\*{0,2}Complexity:\*{0,2}\s*(\w+)/i);
933
- const complexity = normalizeQueueComplexity(complexityMatch?.[1]?.trim());
934
-
935
- const statusMatch = sectionContent.match(/\*{0,2}Status:\*{0,2}\s*([^\n]+)/i);
936
- const status = normalizeQueueTaskStatus(statusMatch?.[1]?.trim());
937
-
938
- const criteriaSection = sectionContent.match(/\*{0,2}Acceptance\s+Criteria:\*{0,2}\s*([\s\S]*?)(?=\n\*{0,2}[A-Z]|\n---|\n###|$)/i);
939
- const acceptanceCriteria = [];
940
- if (criteriaSection && criteriaSection[1]) {
941
- const criteriaMatches = criteriaSection[1].matchAll(/[-*]\s*\[[ x]\]\s*(.+)/g);
942
- for (const cm of criteriaMatches) {
943
- acceptanceCriteria.push(cm[1]?.trim() || '');
944
- }
945
-
946
- if (acceptanceCriteria.length === 0) {
947
- const bulletMatches = criteriaSection[1].matchAll(/^\s*[-*]\s+(.+)$/gm);
948
- for (const bm of bulletMatches) {
949
- const criterion = bm[1]?.trim() || '';
950
- if (criterion) {
951
- acceptanceCriteria.push(criterion);
952
- }
953
- }
954
- }
955
- }
956
-
957
- const dependencies = extractDependenciesFromSection(sectionContent);
958
-
959
- const existingIndex = tasks.findIndex(t => t.id === id);
960
- const existingTask = existingIndex >= 0 ? tasks[existingIndex] : null;
961
-
962
- if (existingTask) {
963
- tasks[existingIndex] = {
964
- ...existingTask,
965
- acceptanceCriteria: acceptanceCriteria.length > 0 ? acceptanceCriteria : existingTask.acceptanceCriteria,
966
- dependencies: dependencies.length > 0 ? dependencies : existingTask.dependencies
967
- };
968
- } else {
969
- tasks.push({
970
- id,
971
- title,
972
- source: 'TASK_QUEUE.md',
973
- sourceSection: 'Task Details',
974
- phase,
975
- status,
976
- acceptanceCriteria,
977
- estimatedComplexity: complexity,
978
- dependencies
979
- });
980
- }
981
- }
982
-
983
- return sortTasksWithDependencyChecks(tasks);
984
- }
985
-
986
- /**
987
- * Load and extract from TASK_QUEUE.md in planning directory
988
- * @param {string} projectRoot - Project root path
989
- * @returns {object} Extracted queue tasks
990
- */
991
- function extractFromTaskQueueFile(projectRoot) {
992
- const queuePath = path.join(projectRoot, 'planning', 'TASK_QUEUE.md');
993
-
994
- if (!fs.existsSync(queuePath)) {
995
- return {
996
- tasks: [],
997
- phases: [],
998
- mvpCriteria: [],
999
- metadata: { extractedAt: new Date().toISOString(), sources: [] },
1000
- error: 'No TASK_QUEUE.md found'
1001
- };
1002
- }
1003
-
1004
- const queueContent = fs.readFileSync(queuePath, 'utf-8');
1005
- const tasks = extractFromTaskQueue(queueContent);
1006
-
1007
- return {
1008
- tasks,
1009
- phases: [],
1010
- mvpCriteria: [],
1011
- metadata: {
1012
- extractedAt: new Date().toISOString(),
1013
- sources: ['TASK_QUEUE.md']
1014
- }
1015
- };
1016
- }
1017
-
1018
- /**
1019
- * Sync tasks from TASK_QUEUE.md to BUILD_STATE.json
1020
- * @param {string} projectRoot - Project root path
1021
- * @param {object} options - Sync options
1022
- * @returns {{added:number,updated:number,total:number}} Sync result
1023
- */
1024
- function syncFromTaskQueue(projectRoot, options = {}) {
1025
- const result = extractFromTaskQueueFile(projectRoot);
1026
-
1027
- if (result.error || result.tasks.length === 0) {
1028
- return { added: 0, updated: 0, total: 0 };
1029
- }
1030
-
1031
- const statePath = path.join(projectRoot, 'planning', 'BUILD_STATE.json');
1032
- let state = {};
1033
-
1034
- if (fs.existsSync(statePath)) {
1035
- try {
1036
- state = JSON.parse(fs.readFileSync(statePath, 'utf-8'));
1037
- } catch {
1038
- state = {};
1039
- }
1040
- }
1041
-
1042
- const replace = options.replace === true;
1043
- const existingQueue = replace ? [] : (state.implementationQueue || []);
1044
- const existingIds = new Set(existingQueue.map(t => t.id));
1045
-
1046
- let added = 0;
1047
- let updated = 0;
1048
-
1049
- for (const task of result.tasks) {
1050
- if (existingIds.has(task.id)) {
1051
- const index = existingQueue.findIndex(t => t.id === task.id);
1052
- const existing = index >= 0 ? existingQueue[index] : null;
1053
- if (existing) {
1054
- const existingDeps = (existing.dependencies || []).join(',');
1055
- const nextDeps = (task.dependencies || []).join(',');
1056
- const criteriaAdded = task.acceptanceCriteria.length > 0 && (existing.acceptanceCriteria?.length || 0) === 0;
1057
- const metadataChanged = existing.title !== task.title ||
1058
- existing.phase !== task.phase ||
1059
- existing.estimatedComplexity !== task.estimatedComplexity;
1060
-
1061
- if (existing.status !== task.status || criteriaAdded || metadataChanged || existingDeps !== nextDeps) {
1062
- existingQueue[index] = { ...existing, ...task };
1063
- updated++;
1064
- }
1065
- }
1066
- } else {
1067
- existingQueue.push(task);
1068
- added++;
1069
- }
1070
- }
1071
-
1072
- const orderedQueue = sortTasksWithDependencyChecks(existingQueue);
1073
-
1074
- state.implementationQueue = orderedQueue;
1075
- fs.writeFileSync(statePath, JSON.stringify(state, null, 2));
1076
-
1077
- return { added, updated, total: orderedQueue.length };
1078
- }
1079
-
1080
- module.exports = {
1081
- extractFromDocs,
1082
- extractFromPrd,
1083
- extractFromRoadmap,
1084
- extractFromTechnicalSpec,
1085
- extractFromSeed,
1086
- extractMvpCriteria,
1087
- orderByDependencies,
1088
- deduplicateTasks,
1089
- extractAcceptanceCriteria,
1090
- estimateComplexity,
1091
- extractSection,
1092
- extractIntegrations,
1093
- extractFromPreseedDir,
1094
- extractFromSeedFile,
1095
- extractFromTaskQueue,
1096
- extractFromTaskQueueFile,
1097
- syncFromTaskQueue
1098
- };