@girardmedia/bootspring 1.2.0 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (253) hide show
  1. package/README.md +107 -14
  2. package/bin/bootspring.js +166 -27
  3. package/cli/agent.js +189 -17
  4. package/cli/analyze.js +499 -0
  5. package/cli/audit.js +557 -0
  6. package/cli/auth.js +495 -38
  7. package/cli/billing.js +302 -0
  8. package/cli/build.js +695 -0
  9. package/cli/business.js +109 -26
  10. package/cli/checkpoint-utils.js +168 -0
  11. package/cli/checkpoint.js +639 -0
  12. package/cli/cloud-sync.js +447 -0
  13. package/cli/content.js +198 -0
  14. package/cli/context.js +1 -1
  15. package/cli/deploy.js +543 -0
  16. package/cli/fundraise.js +112 -50
  17. package/cli/github-cmd.js +435 -0
  18. package/cli/health.js +477 -0
  19. package/cli/init.js +84 -13
  20. package/cli/legal.js +107 -95
  21. package/cli/log.js +2 -2
  22. package/cli/loop.js +976 -73
  23. package/cli/manager.js +711 -0
  24. package/cli/metrics.js +480 -0
  25. package/cli/monitor.js +812 -0
  26. package/cli/onboard.js +521 -0
  27. package/cli/orchestrator.js +12 -24
  28. package/cli/prd.js +594 -0
  29. package/cli/preseed-start.js +1483 -0
  30. package/cli/preseed.js +2302 -0
  31. package/cli/project.js +436 -0
  32. package/cli/quality.js +233 -0
  33. package/cli/security.js +913 -0
  34. package/cli/seed.js +1441 -5
  35. package/cli/skill.js +273 -211
  36. package/cli/suggest.js +989 -0
  37. package/cli/switch.js +453 -0
  38. package/cli/visualize.js +527 -0
  39. package/cli/watch.js +769 -0
  40. package/cli/workspace.js +607 -0
  41. package/core/analyze-workflow.js +1134 -0
  42. package/core/api-client.js +535 -22
  43. package/core/audit-workflow.js +1350 -0
  44. package/core/build-orchestrator.js +480 -0
  45. package/core/build-state.js +577 -0
  46. package/core/checkpoint-engine.js +408 -0
  47. package/core/config.js +1109 -26
  48. package/core/context-loader.js +21 -1
  49. package/core/deploy-workflow.js +836 -0
  50. package/core/entitlements.js +93 -22
  51. package/core/github-sync.js +610 -0
  52. package/core/index.js +8 -1
  53. package/core/ingest.js +1111 -0
  54. package/core/metrics-engine.js +768 -0
  55. package/core/onboard-workflow.js +1007 -0
  56. package/core/preseed-workflow.js +934 -0
  57. package/core/preseed.js +1617 -0
  58. package/core/project-context.js +325 -0
  59. package/core/project-state.js +694 -0
  60. package/core/r2-sync.js +583 -0
  61. package/core/scaffold.js +525 -7
  62. package/core/session.js +258 -0
  63. package/core/task-extractor.js +758 -0
  64. package/core/telemetry.js +28 -6
  65. package/core/tier-enforcement.js +737 -0
  66. package/core/utils.js +38 -14
  67. package/generators/questionnaire.js +15 -12
  68. package/generators/sections/ai.js +7 -7
  69. package/generators/sections/content.js +300 -0
  70. package/generators/sections/index.js +3 -0
  71. package/generators/sections/plugins.js +7 -6
  72. package/generators/templates/build-planning.template.js +596 -0
  73. package/generators/templates/content.template.js +819 -0
  74. package/generators/templates/index.js +2 -1
  75. package/hooks/git-autopilot.js +1250 -0
  76. package/hooks/index.js +9 -0
  77. package/intelligence/agent-collab.js +2057 -0
  78. package/intelligence/auto-suggest.js +634 -0
  79. package/intelligence/content-gen.js +1589 -0
  80. package/intelligence/cross-project.js +1647 -0
  81. package/intelligence/index.js +184 -0
  82. package/intelligence/learning/insights.json +517 -7
  83. package/intelligence/learning/pattern-learner.js +1008 -14
  84. package/intelligence/memory/decision-tracker.js +1431 -31
  85. package/intelligence/memory/decisions.jsonl +0 -0
  86. package/intelligence/orchestrator.js +2896 -1
  87. package/intelligence/prd.js +92 -1
  88. package/intelligence/recommendation-weights.json +14 -2
  89. package/intelligence/recommendations.js +463 -9
  90. package/intelligence/workflow-composer.js +1451 -0
  91. package/marketplace/index.d.ts +324 -0
  92. package/marketplace/index.js +1921 -0
  93. package/mcp/contracts/mcp-contract.v1.json +342 -4
  94. package/mcp/registry.js +680 -3
  95. package/mcp/response-formatter.js +23 -0
  96. package/mcp/tools/assist-tool.js +78 -4
  97. package/mcp/tools/autopilot-tool.js +408 -0
  98. package/mcp/tools/content-tool.js +571 -0
  99. package/mcp/tools/dashboard-tool.js +251 -5
  100. package/mcp/tools/mvp-tool.js +344 -0
  101. package/mcp/tools/plugin-tool.js +23 -1
  102. package/mcp/tools/prd-tool.js +579 -0
  103. package/mcp/tools/seed-tool.js +447 -0
  104. package/mcp/tools/skill-tool.js +43 -14
  105. package/mcp/tools/suggest-tool.js +147 -0
  106. package/package.json +15 -6
  107. package/agents/README.md +0 -93
  108. package/agents/ai-integration-expert/context.md +0 -386
  109. package/agents/api-expert/context.md +0 -416
  110. package/agents/architecture-expert/context.md +0 -454
  111. package/agents/auth-expert/context.md +0 -399
  112. package/agents/backend-expert/context.md +0 -483
  113. package/agents/business-strategy-expert/context.md +0 -180
  114. package/agents/code-review-expert/context.md +0 -365
  115. package/agents/competitive-analysis-expert/context.md +0 -239
  116. package/agents/data-modeling-expert/context.md +0 -352
  117. package/agents/database-expert/context.md +0 -250
  118. package/agents/devops-expert/context.md +0 -446
  119. package/agents/email-expert/context.md +0 -379
  120. package/agents/financial-expert/context.md +0 -213
  121. package/agents/frontend-expert/context.md +0 -364
  122. package/agents/fundraising-expert/context.md +0 -257
  123. package/agents/growth-expert/context.md +0 -249
  124. package/agents/index.js +0 -140
  125. package/agents/investor-relations-expert/context.md +0 -266
  126. package/agents/legal-expert/context.md +0 -284
  127. package/agents/marketing-expert/context.md +0 -236
  128. package/agents/monitoring-expert/context.md +0 -362
  129. package/agents/operations-expert/context.md +0 -279
  130. package/agents/partnerships-expert/context.md +0 -286
  131. package/agents/payment-expert/context.md +0 -340
  132. package/agents/performance-expert/context.md +0 -377
  133. package/agents/private-equity-expert/context.md +0 -246
  134. package/agents/railway-expert/context.md +0 -284
  135. package/agents/research-expert/context.md +0 -245
  136. package/agents/sales-expert/context.md +0 -241
  137. package/agents/security-expert/context.md +0 -343
  138. package/agents/testing-expert/context.md +0 -414
  139. package/agents/ui-ux-expert/context.md +0 -448
  140. package/agents/vercel-expert/context.md +0 -426
  141. package/skills/index.js +0 -787
  142. package/skills/patterns/README.md +0 -163
  143. package/skills/patterns/ai/agents.md +0 -281
  144. package/skills/patterns/ai/claude.md +0 -138
  145. package/skills/patterns/ai/embeddings.md +0 -150
  146. package/skills/patterns/ai/rag.md +0 -266
  147. package/skills/patterns/ai/streaming.md +0 -170
  148. package/skills/patterns/ai/structured-output.md +0 -162
  149. package/skills/patterns/ai/tools.md +0 -154
  150. package/skills/patterns/analytics/tracking.md +0 -220
  151. package/skills/patterns/api/errors.md +0 -296
  152. package/skills/patterns/api/graphql.md +0 -440
  153. package/skills/patterns/api/middleware.md +0 -279
  154. package/skills/patterns/api/openapi.md +0 -285
  155. package/skills/patterns/api/rate-limiting.md +0 -231
  156. package/skills/patterns/api/route-handler.md +0 -217
  157. package/skills/patterns/api/server-action.md +0 -249
  158. package/skills/patterns/api/versioning.md +0 -443
  159. package/skills/patterns/api/webhooks.md +0 -247
  160. package/skills/patterns/auth/clerk.md +0 -132
  161. package/skills/patterns/auth/mfa.md +0 -313
  162. package/skills/patterns/auth/nextauth.md +0 -140
  163. package/skills/patterns/auth/oauth.md +0 -237
  164. package/skills/patterns/auth/rbac.md +0 -152
  165. package/skills/patterns/auth/session-management.md +0 -367
  166. package/skills/patterns/auth/session.md +0 -120
  167. package/skills/patterns/database/audit.md +0 -177
  168. package/skills/patterns/database/migrations.md +0 -177
  169. package/skills/patterns/database/pagination.md +0 -230
  170. package/skills/patterns/database/pooling.md +0 -357
  171. package/skills/patterns/database/prisma.md +0 -180
  172. package/skills/patterns/database/relations.md +0 -187
  173. package/skills/patterns/database/seeding.md +0 -246
  174. package/skills/patterns/database/soft-delete.md +0 -153
  175. package/skills/patterns/database/transactions.md +0 -162
  176. package/skills/patterns/deployment/ci-cd.md +0 -231
  177. package/skills/patterns/deployment/docker.md +0 -188
  178. package/skills/patterns/deployment/monitoring.md +0 -387
  179. package/skills/patterns/deployment/vercel.md +0 -160
  180. package/skills/patterns/email/resend.md +0 -143
  181. package/skills/patterns/email/templates.md +0 -245
  182. package/skills/patterns/email/transactional.md +0 -503
  183. package/skills/patterns/email/verification.md +0 -176
  184. package/skills/patterns/files/download.md +0 -243
  185. package/skills/patterns/files/upload.md +0 -239
  186. package/skills/patterns/i18n/nextintl.md +0 -188
  187. package/skills/patterns/logging/structured.md +0 -292
  188. package/skills/patterns/notifications/email-queue.md +0 -248
  189. package/skills/patterns/notifications/push.md +0 -279
  190. package/skills/patterns/payments/checkout.md +0 -303
  191. package/skills/patterns/payments/invoices.md +0 -287
  192. package/skills/patterns/payments/portal.md +0 -245
  193. package/skills/patterns/payments/stripe.md +0 -272
  194. package/skills/patterns/payments/subscriptions.md +0 -300
  195. package/skills/patterns/payments/usage.md +0 -279
  196. package/skills/patterns/performance/caching.md +0 -276
  197. package/skills/patterns/performance/code-splitting.md +0 -233
  198. package/skills/patterns/performance/edge.md +0 -254
  199. package/skills/patterns/performance/isr.md +0 -266
  200. package/skills/patterns/performance/lazy-loading.md +0 -281
  201. package/skills/patterns/realtime/sse.md +0 -327
  202. package/skills/patterns/realtime/websockets.md +0 -336
  203. package/skills/patterns/search/filtering.md +0 -329
  204. package/skills/patterns/search/fulltext.md +0 -260
  205. package/skills/patterns/security/audit-logging.md +0 -444
  206. package/skills/patterns/security/csrf.md +0 -234
  207. package/skills/patterns/security/headers.md +0 -252
  208. package/skills/patterns/security/sanitization.md +0 -258
  209. package/skills/patterns/security/secrets.md +0 -261
  210. package/skills/patterns/security/validation.md +0 -268
  211. package/skills/patterns/security/xss.md +0 -229
  212. package/skills/patterns/seo/metadata.md +0 -252
  213. package/skills/patterns/state/context.md +0 -349
  214. package/skills/patterns/state/react-query.md +0 -313
  215. package/skills/patterns/state/url-state.md +0 -482
  216. package/skills/patterns/state/zustand.md +0 -262
  217. package/skills/patterns/testing/api.md +0 -259
  218. package/skills/patterns/testing/component.md +0 -233
  219. package/skills/patterns/testing/coverage.md +0 -207
  220. package/skills/patterns/testing/fixtures.md +0 -225
  221. package/skills/patterns/testing/integration.md +0 -436
  222. package/skills/patterns/testing/mocking.md +0 -177
  223. package/skills/patterns/testing/playwright.md +0 -162
  224. package/skills/patterns/testing/snapshot.md +0 -175
  225. package/skills/patterns/testing/vitest.md +0 -307
  226. package/skills/patterns/ui/accordions.md +0 -395
  227. package/skills/patterns/ui/cards.md +0 -299
  228. package/skills/patterns/ui/dropdowns.md +0 -476
  229. package/skills/patterns/ui/empty-states.md +0 -320
  230. package/skills/patterns/ui/forms.md +0 -405
  231. package/skills/patterns/ui/inputs.md +0 -319
  232. package/skills/patterns/ui/layouts.md +0 -282
  233. package/skills/patterns/ui/loading.md +0 -291
  234. package/skills/patterns/ui/modals.md +0 -338
  235. package/skills/patterns/ui/navigation.md +0 -374
  236. package/skills/patterns/ui/tables.md +0 -407
  237. package/skills/patterns/ui/toasts.md +0 -300
  238. package/skills/patterns/ui/tooltips.md +0 -396
  239. package/skills/patterns/utils/dates.md +0 -435
  240. package/skills/patterns/utils/errors.md +0 -451
  241. package/skills/patterns/utils/formatting.md +0 -345
  242. package/skills/patterns/utils/validation.md +0 -434
  243. package/templates/bootspring.config.js +0 -83
  244. package/templates/business/business-model-canvas.md +0 -246
  245. package/templates/business/business-plan.md +0 -266
  246. package/templates/business/competitive-analysis.md +0 -312
  247. package/templates/fundraising/data-room-checklist.md +0 -300
  248. package/templates/fundraising/investor-research.md +0 -243
  249. package/templates/fundraising/pitch-deck-outline.md +0 -253
  250. package/templates/legal/gdpr-checklist.md +0 -339
  251. package/templates/legal/privacy-policy.md +0 -285
  252. package/templates/legal/terms-of-service.md +0 -222
  253. package/templates/mcp.json +0 -9
package/cli/watch.js ADDED
@@ -0,0 +1,769 @@
1
+ /**
2
+ * Bootspring Watch Command
3
+ * Real-time file watching and sync for todos, tasks, and workflows
4
+ *
5
+ * @package bootspring
6
+ * @command watch
7
+ */
8
+
9
+ const fs = require('fs');
10
+ const path = require('path');
11
+ const { EventEmitter } = require('events');
12
+ const config = require('../core/config');
13
+ const utils = require('../core/utils');
14
+ const telemetry = require('../core/telemetry');
15
+ const checkpointEngine = require('../core/checkpoint-engine');
16
+
17
+ // Colors
18
+ const c = {
19
+ reset: '\x1b[0m',
20
+ bold: '\x1b[1m',
21
+ dim: '\x1b[2m',
22
+ green: '\x1b[32m',
23
+ blue: '\x1b[34m',
24
+ yellow: '\x1b[33m',
25
+ cyan: '\x1b[36m',
26
+ red: '\x1b[31m',
27
+ magenta: '\x1b[35m'
28
+ };
29
+
30
+ /**
31
+ * Parse todo.md content
32
+ */
33
+ function parseTodoFile(content) {
34
+ const todos = [];
35
+ const lines = content.split('\n');
36
+
37
+ for (let i = 0; i < lines.length; i++) {
38
+ const match = lines[i].match(/^- \[([ xX])\] (.+)$/);
39
+ if (match) {
40
+ todos.push({
41
+ id: `todo-${i}`,
42
+ line: i + 1,
43
+ completed: match[1].toLowerCase() === 'x',
44
+ text: match[2].trim()
45
+ });
46
+ }
47
+ }
48
+
49
+ return todos;
50
+ }
51
+
52
+ /**
53
+ * Compare todo states and find changes
54
+ */
55
+ function diffTodos(oldTodos, newTodos) {
56
+ const changes = [];
57
+
58
+ // Map old todos by text for comparison
59
+ const oldMap = new Map(oldTodos.map(t => [t.text, t]));
60
+ const newMap = new Map(newTodos.map(t => [t.text, t]));
61
+
62
+ // Find completed todos
63
+ for (const newTodo of newTodos) {
64
+ const oldTodo = oldMap.get(newTodo.text);
65
+ if (oldTodo && !oldTodo.completed && newTodo.completed) {
66
+ changes.push({ type: 'completed', todo: newTodo });
67
+ }
68
+ if (oldTodo && oldTodo.completed && !newTodo.completed) {
69
+ changes.push({ type: 'reopened', todo: newTodo });
70
+ }
71
+ }
72
+
73
+ // Find added todos
74
+ for (const newTodo of newTodos) {
75
+ if (!oldMap.has(newTodo.text)) {
76
+ changes.push({ type: 'added', todo: newTodo });
77
+ }
78
+ }
79
+
80
+ // Find removed todos
81
+ for (const oldTodo of oldTodos) {
82
+ if (!newMap.has(oldTodo.text)) {
83
+ changes.push({ type: 'removed', todo: oldTodo });
84
+ }
85
+ }
86
+
87
+ return changes;
88
+ }
89
+
90
+ /**
91
+ * Get todo statistics
92
+ */
93
+ function getTodoStats(todos) {
94
+ const pending = todos.filter(t => !t.completed).length;
95
+ const completed = todos.filter(t => t.completed).length;
96
+ return {
97
+ pending,
98
+ completed,
99
+ total: todos.length,
100
+ progress: todos.length > 0 ? Math.round((completed / todos.length) * 100) : 0
101
+ };
102
+ }
103
+
104
+ /**
105
+ * File watcher class
106
+ */
107
+ class FileWatcher extends EventEmitter {
108
+ constructor(projectRoot, options = {}) {
109
+ super();
110
+ this.projectRoot = projectRoot;
111
+ this.options = {
112
+ debounceMs: options.debounceMs || 300,
113
+ watchTodos: options.watchTodos !== false,
114
+ watchWorkflows: options.watchWorkflows !== false,
115
+ watchPRD: options.watchPRD !== false,
116
+ watchCheckpoints: options.watchCheckpoints !== false,
117
+ ...options
118
+ };
119
+
120
+ this.watchers = [];
121
+ this.state = {
122
+ todos: [],
123
+ workflows: {},
124
+ prd: null,
125
+ checkpoints: null
126
+ };
127
+ this.debounceTimers = new Map();
128
+ }
129
+
130
+ /**
131
+ * Start watching files
132
+ */
133
+ start() {
134
+ const todoPath = path.join(this.projectRoot, 'todo.md');
135
+ const bootspringDir = path.join(this.projectRoot, '.bootspring');
136
+ const prdPath = path.join(this.projectRoot, 'tasks', 'prd.json');
137
+
138
+ // Watch todo.md
139
+ if (this.options.watchTodos && fs.existsSync(todoPath)) {
140
+ this.watchFile(todoPath, 'todo');
141
+ this.loadTodoState(todoPath);
142
+ }
143
+
144
+ // Watch .bootspring directory for workflow changes
145
+ if (this.options.watchWorkflows && fs.existsSync(bootspringDir)) {
146
+ this.watchDirectory(bootspringDir, 'workflow');
147
+ this.loadWorkflowStates();
148
+ }
149
+
150
+ // Watch PRD
151
+ if (this.options.watchPRD && fs.existsSync(prdPath)) {
152
+ this.watchFile(prdPath, 'prd');
153
+ this.loadPRDState(prdPath);
154
+ }
155
+
156
+ // Watch planning directory for checkpoint-related files
157
+ const planningDir = path.join(this.projectRoot, 'planning');
158
+ if (this.options.watchCheckpoints && fs.existsSync(planningDir)) {
159
+ this.watchDirectory(planningDir, 'checkpoint');
160
+ this.loadCheckpointState();
161
+ }
162
+
163
+ this.emit('started');
164
+ }
165
+
166
+ /**
167
+ * Watch a single file
168
+ */
169
+ watchFile(filePath, type) {
170
+ try {
171
+ const watcher = fs.watch(filePath, (eventType) => {
172
+ if (eventType === 'change') {
173
+ this.debouncedHandle(filePath, type);
174
+ }
175
+ });
176
+
177
+ this.watchers.push(watcher);
178
+ } catch (err) {
179
+ this.emit('error', { type, error: err });
180
+ }
181
+ }
182
+
183
+ /**
184
+ * Watch a directory
185
+ */
186
+ watchDirectory(dirPath, type) {
187
+ try {
188
+ const watcher = fs.watch(dirPath, { recursive: true }, (eventType, filename) => {
189
+ if (!filename) return;
190
+
191
+ // For checkpoints, watch .md files; for workflows, watch .json files
192
+ const isRelevant = type === 'checkpoint'
193
+ ? filename.endsWith('.md') || filename.endsWith('.json')
194
+ : filename.endsWith('.json');
195
+
196
+ if (isRelevant) {
197
+ const fullPath = path.join(dirPath, filename);
198
+ this.debouncedHandle(fullPath, type);
199
+ }
200
+ });
201
+
202
+ this.watchers.push(watcher);
203
+ } catch (err) {
204
+ this.emit('error', { type, error: err });
205
+ }
206
+ }
207
+
208
+ /**
209
+ * Debounced change handler
210
+ */
211
+ debouncedHandle(filePath, type) {
212
+ const key = `${type}:${filePath}`;
213
+
214
+ if (this.debounceTimers.has(key)) {
215
+ clearTimeout(this.debounceTimers.get(key));
216
+ }
217
+
218
+ this.debounceTimers.set(key, setTimeout(() => {
219
+ this.handleChange(filePath, type);
220
+ this.debounceTimers.delete(key);
221
+ }, this.options.debounceMs));
222
+ }
223
+
224
+ /**
225
+ * Handle file change
226
+ */
227
+ handleChange(filePath, type) {
228
+ try {
229
+ switch (type) {
230
+ case 'todo':
231
+ this.handleTodoChange(filePath);
232
+ break;
233
+ case 'workflow':
234
+ this.handleWorkflowChange(filePath);
235
+ break;
236
+ case 'prd':
237
+ this.handlePRDChange(filePath);
238
+ break;
239
+ case 'checkpoint':
240
+ this.handleCheckpointChange(filePath);
241
+ break;
242
+ }
243
+ } catch (err) {
244
+ this.emit('error', { type, filePath, error: err });
245
+ }
246
+ }
247
+
248
+ /**
249
+ * Load initial todo state
250
+ */
251
+ loadTodoState(filePath) {
252
+ try {
253
+ if (fs.existsSync(filePath)) {
254
+ const content = fs.readFileSync(filePath, 'utf-8');
255
+ this.state.todos = parseTodoFile(content);
256
+ }
257
+ } catch {
258
+ // Ignore errors
259
+ }
260
+ }
261
+
262
+ /**
263
+ * Handle todo file changes
264
+ */
265
+ handleTodoChange(filePath) {
266
+ if (!fs.existsSync(filePath)) {
267
+ this.emit('todo:deleted');
268
+ this.state.todos = [];
269
+ return;
270
+ }
271
+
272
+ const content = fs.readFileSync(filePath, 'utf-8');
273
+ const newTodos = parseTodoFile(content);
274
+ const changes = diffTodos(this.state.todos, newTodos);
275
+ const stats = getTodoStats(newTodos);
276
+
277
+ this.state.todos = newTodos;
278
+
279
+ if (changes.length > 0) {
280
+ this.emit('todo:changed', { changes, stats, todos: newTodos });
281
+
282
+ // Emit specific events
283
+ for (const change of changes) {
284
+ this.emit(`todo:${change.type}`, change.todo);
285
+ }
286
+
287
+ // Track in telemetry
288
+ telemetry.emitEvent('watch:todo:change', {
289
+ changes: changes.map(c => ({ type: c.type, text: c.todo.text.slice(0, 50) })),
290
+ stats
291
+ });
292
+ }
293
+ }
294
+
295
+ /**
296
+ * Load initial workflow states
297
+ */
298
+ loadWorkflowStates() {
299
+ const workflowNames = ['onboard', 'analyze', 'audit', 'preseed', 'seed', 'deploy', 'loop'];
300
+
301
+ for (const name of workflowNames) {
302
+ const stateFile = path.join(this.projectRoot, '.bootspring', name, 'workflow-state.json');
303
+ if (fs.existsSync(stateFile)) {
304
+ try {
305
+ this.state.workflows[name] = JSON.parse(fs.readFileSync(stateFile, 'utf-8'));
306
+ } catch {
307
+ // Ignore errors
308
+ }
309
+ }
310
+ }
311
+ }
312
+
313
+ /**
314
+ * Handle workflow state changes
315
+ */
316
+ handleWorkflowChange(filePath) {
317
+ // Extract workflow name from path
318
+ const relativePath = path.relative(path.join(this.projectRoot, '.bootspring'), filePath);
319
+ const workflowName = relativePath.split(path.sep)[0];
320
+
321
+ if (!fs.existsSync(filePath)) {
322
+ this.emit('workflow:deleted', { workflow: workflowName });
323
+ delete this.state.workflows[workflowName];
324
+ return;
325
+ }
326
+
327
+ try {
328
+ const newState = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
329
+ const oldState = this.state.workflows[workflowName];
330
+
331
+ this.state.workflows[workflowName] = newState;
332
+
333
+ // Detect phase changes
334
+ if (oldState && newState.phases) {
335
+ for (const [phaseName, phase] of Object.entries(newState.phases)) {
336
+ const oldPhase = oldState.phases?.[phaseName];
337
+ if (oldPhase && oldPhase.status !== phase.status) {
338
+ this.emit('workflow:phase', {
339
+ workflow: workflowName,
340
+ phase: phaseName,
341
+ oldStatus: oldPhase.status,
342
+ newStatus: phase.status
343
+ });
344
+ }
345
+ }
346
+ }
347
+
348
+ this.emit('workflow:changed', { workflow: workflowName, state: newState });
349
+
350
+ // Track in telemetry
351
+ telemetry.emitEvent('watch:workflow:change', {
352
+ workflow: workflowName,
353
+ status: newState.status
354
+ });
355
+ } catch {
356
+ // Ignore parse errors
357
+ }
358
+ }
359
+
360
+ /**
361
+ * Load initial PRD state
362
+ */
363
+ loadPRDState(filePath) {
364
+ try {
365
+ if (fs.existsSync(filePath)) {
366
+ this.state.prd = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
367
+ }
368
+ } catch {
369
+ // Ignore errors
370
+ }
371
+ }
372
+
373
+ /**
374
+ * Handle PRD changes
375
+ */
376
+ handlePRDChange(filePath) {
377
+ if (!fs.existsSync(filePath)) {
378
+ this.emit('prd:deleted');
379
+ this.state.prd = null;
380
+ return;
381
+ }
382
+
383
+ try {
384
+ const newPRD = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
385
+ const oldPRD = this.state.prd;
386
+
387
+ // Detect story status changes
388
+ if (oldPRD && newPRD.stories) {
389
+ const oldStoryMap = new Map((oldPRD.stories || []).map(s => [s.id || s.title, s]));
390
+
391
+ for (const story of newPRD.stories) {
392
+ const oldStory = oldStoryMap.get(story.id || story.title);
393
+ if (oldStory && oldStory.status !== story.status) {
394
+ this.emit('prd:story', {
395
+ story,
396
+ oldStatus: oldStory.status,
397
+ newStatus: story.status
398
+ });
399
+ }
400
+ }
401
+ }
402
+
403
+ this.state.prd = newPRD;
404
+ this.emit('prd:changed', { prd: newPRD });
405
+
406
+ // Track in telemetry
407
+ const completed = newPRD.stories?.filter(s => s.status === 'complete').length || 0;
408
+ telemetry.emitEvent('watch:prd:change', {
409
+ name: newPRD.name,
410
+ stories: newPRD.stories?.length || 0,
411
+ completed
412
+ });
413
+ } catch {
414
+ // Ignore parse errors
415
+ }
416
+ }
417
+
418
+ /**
419
+ * Load initial checkpoint state
420
+ */
421
+ loadCheckpointState() {
422
+ try {
423
+ const status = checkpointEngine.getCheckpointStatus(this.projectRoot);
424
+ if (status.exists) {
425
+ this.state.checkpoints = status;
426
+ }
427
+ } catch {
428
+ // Ignore errors
429
+ }
430
+ }
431
+
432
+ /**
433
+ * Handle checkpoint-related file changes
434
+ * Syncs checkpoints when planning files change and auto-pushes to server
435
+ */
436
+ handleCheckpointChange(filePath) {
437
+ try {
438
+ // Sync checkpoints when any planning file changes
439
+ const result = checkpointEngine.syncCheckpoints(this.projectRoot);
440
+ const newStatus = checkpointEngine.getCheckpointStatus(this.projectRoot);
441
+ const oldStatus = this.state.checkpoints;
442
+
443
+ if (newStatus.exists) {
444
+ // Check for newly completed checkpoints
445
+ if (oldStatus && oldStatus.checkpoints) {
446
+ for (const checkpoint of newStatus.checkpoints) {
447
+ const oldCheckpoint = oldStatus.checkpoints.find(c => c.id === checkpoint.id);
448
+ if (oldCheckpoint && !oldCheckpoint.completed && checkpoint.completed) {
449
+ this.emit('checkpoint:completed', {
450
+ checkpoint,
451
+ file: filePath
452
+ });
453
+ }
454
+ }
455
+ }
456
+
457
+ // Check if percentage changed
458
+ if (!oldStatus || oldStatus.percentage !== newStatus.percentage) {
459
+ this.emit('checkpoint:progress', {
460
+ oldPercentage: oldStatus?.percentage || 0,
461
+ newPercentage: newStatus.percentage,
462
+ completed: newStatus.completed,
463
+ total: newStatus.total
464
+ });
465
+
466
+ // Auto-push to dashboard if authenticated
467
+ this.autoPushCheckpoints();
468
+ }
469
+
470
+ this.state.checkpoints = newStatus;
471
+ this.emit('checkpoint:changed', { status: newStatus });
472
+
473
+ // Track in telemetry
474
+ telemetry.emitEvent('watch:checkpoint:change', {
475
+ completed: newStatus.completed,
476
+ total: newStatus.total,
477
+ percentage: newStatus.percentage
478
+ });
479
+ }
480
+ } catch {
481
+ // Ignore errors
482
+ }
483
+ }
484
+
485
+ /**
486
+ * Auto-push checkpoints to dashboard (non-blocking)
487
+ * Only pushes if authenticated and project is selected
488
+ */
489
+ async autoPushCheckpoints() {
490
+ try {
491
+ const { pushCheckpointsToServer } = require('./checkpoint-utils');
492
+ const result = await pushCheckpointsToServer(this.projectRoot, {
493
+ quiet: true,
494
+ autoSync: true,
495
+ skipMetrics: true // Skip heavy metrics collection in watch mode
496
+ });
497
+
498
+ if (result.success) {
499
+ this.emit('checkpoint:synced', { success: true });
500
+ }
501
+ } catch {
502
+ // Silent fail - auto-push is best-effort
503
+ }
504
+ }
505
+
506
+ /**
507
+ * Stop watching
508
+ */
509
+ stop() {
510
+ for (const watcher of this.watchers) {
511
+ watcher.close();
512
+ }
513
+ this.watchers = [];
514
+
515
+ for (const timer of this.debounceTimers.values()) {
516
+ clearTimeout(timer);
517
+ }
518
+ this.debounceTimers.clear();
519
+
520
+ this.emit('stopped');
521
+ }
522
+
523
+ /**
524
+ * Get current state
525
+ */
526
+ getState() {
527
+ return { ...this.state };
528
+ }
529
+ }
530
+
531
+ /**
532
+ * Create notification message
533
+ */
534
+ function formatNotification(type, data) {
535
+ const timestamp = new Date().toLocaleTimeString();
536
+
537
+ switch (type) {
538
+ case 'todo:completed':
539
+ return `${c.green}✓${c.reset} [${c.dim}${timestamp}${c.reset}] Todo completed: ${data.text}`;
540
+
541
+ case 'todo:added':
542
+ return `${c.blue}+${c.reset} [${c.dim}${timestamp}${c.reset}] Todo added: ${data.text}`;
543
+
544
+ case 'todo:removed':
545
+ return `${c.red}-${c.reset} [${c.dim}${timestamp}${c.reset}] Todo removed: ${data.text}`;
546
+
547
+ case 'todo:reopened':
548
+ return `${c.yellow}○${c.reset} [${c.dim}${timestamp}${c.reset}] Todo reopened: ${data.text}`;
549
+
550
+ case 'workflow:phase':
551
+ return `${c.cyan}◆${c.reset} [${c.dim}${timestamp}${c.reset}] ${data.workflow}/${data.phase}: ${data.oldStatus} → ${data.newStatus}`;
552
+
553
+ case 'workflow:changed':
554
+ return `${c.cyan}↻${c.reset} [${c.dim}${timestamp}${c.reset}] Workflow updated: ${data.workflow}`;
555
+
556
+ case 'prd:story':
557
+ return `${c.magenta}◇${c.reset} [${c.dim}${timestamp}${c.reset}] Story "${data.story.title}": ${data.oldStatus} → ${data.newStatus}`;
558
+
559
+ case 'prd:changed':
560
+ return `${c.magenta}↻${c.reset} [${c.dim}${timestamp}${c.reset}] PRD updated: ${data.prd.name}`;
561
+
562
+ case 'checkpoint:completed':
563
+ return `${c.green}★${c.reset} [${c.dim}${timestamp}${c.reset}] Checkpoint completed: ${data.checkpoint.label}`;
564
+
565
+ case 'checkpoint:progress':
566
+ return `${c.cyan}▲${c.reset} [${c.dim}${timestamp}${c.reset}] Progress: ${data.oldPercentage}% → ${data.newPercentage}% (${data.completed}/${data.total})`;
567
+
568
+ case 'checkpoint:synced':
569
+ return `${c.green}↑${c.reset} [${c.dim}${timestamp}${c.reset}] Synced to dashboard`;
570
+
571
+ default:
572
+ return `${c.dim}[${timestamp}]${c.reset} ${type}: ${JSON.stringify(data)}`;
573
+ }
574
+ }
575
+
576
+ /**
577
+ * Draw status bar
578
+ */
579
+ function drawStatusBar(state) {
580
+ const todoStats = getTodoStats(state.todos);
581
+ const workflowCount = Object.keys(state.workflows).length;
582
+ const prdName = state.prd?.name || 'None';
583
+ const checkpointProgress = state.checkpoints?.percentage || 0;
584
+
585
+ const parts = [
586
+ `${c.cyan}Todos:${c.reset} ${todoStats.pending}/${todoStats.total}`,
587
+ `${c.cyan}Workflows:${c.reset} ${workflowCount}`,
588
+ `${c.cyan}Checkpoints:${c.reset} ${checkpointProgress}%`,
589
+ `${c.cyan}PRD:${c.reset} ${prdName}`
590
+ ];
591
+
592
+ return `${c.dim}${parts.join(' │ ')}${c.reset}`;
593
+ }
594
+
595
+ /**
596
+ * Run interactive watch mode
597
+ */
598
+ async function runWatchMode(projectRoot, options = {}) {
599
+ const watcher = new FileWatcher(projectRoot, options);
600
+
601
+ console.log(`
602
+ ${c.cyan}${c.bold}⚡ Bootspring Watch Mode${c.reset}
603
+ ${c.dim}Monitoring files for changes...${c.reset}
604
+ ${c.dim}Press Ctrl+C to exit${c.reset}
605
+ `);
606
+
607
+ // Set up event handlers
608
+ watcher.on('started', () => {
609
+ console.log(drawStatusBar(watcher.getState()));
610
+ console.log();
611
+ });
612
+
613
+ watcher.on('todo:completed', (todo) => {
614
+ console.log(formatNotification('todo:completed', todo));
615
+ });
616
+
617
+ watcher.on('todo:added', (todo) => {
618
+ console.log(formatNotification('todo:added', todo));
619
+ });
620
+
621
+ watcher.on('todo:removed', (todo) => {
622
+ console.log(formatNotification('todo:removed', todo));
623
+ });
624
+
625
+ watcher.on('todo:reopened', (todo) => {
626
+ console.log(formatNotification('todo:reopened', todo));
627
+ });
628
+
629
+ watcher.on('workflow:phase', (data) => {
630
+ console.log(formatNotification('workflow:phase', data));
631
+ });
632
+
633
+ watcher.on('workflow:changed', (data) => {
634
+ if (options.verbose) {
635
+ console.log(formatNotification('workflow:changed', data));
636
+ }
637
+ });
638
+
639
+ watcher.on('prd:story', (data) => {
640
+ console.log(formatNotification('prd:story', data));
641
+ });
642
+
643
+ watcher.on('prd:changed', (data) => {
644
+ if (options.verbose) {
645
+ console.log(formatNotification('prd:changed', data));
646
+ }
647
+ });
648
+
649
+ watcher.on('checkpoint:completed', (data) => {
650
+ console.log(formatNotification('checkpoint:completed', data));
651
+ });
652
+
653
+ watcher.on('checkpoint:progress', (data) => {
654
+ console.log(formatNotification('checkpoint:progress', data));
655
+ });
656
+
657
+ watcher.on('checkpoint:synced', (data) => {
658
+ console.log(formatNotification('checkpoint:synced', data));
659
+ });
660
+
661
+ watcher.on('error', (err) => {
662
+ console.log(`${c.red}Error:${c.reset} ${err.type} - ${err.error?.message || 'Unknown error'}`);
663
+ });
664
+
665
+ // Start watching
666
+ watcher.start();
667
+
668
+ // Handle exit
669
+ process.on('SIGINT', () => {
670
+ console.log(`\n${c.dim}Stopping watch mode...${c.reset}`);
671
+ watcher.stop();
672
+ process.exit(0);
673
+ });
674
+
675
+ // Keep process alive
676
+ return new Promise(() => {});
677
+ }
678
+
679
+ /**
680
+ * Show help
681
+ */
682
+ function showHelp() {
683
+ console.log(`
684
+ ${c.cyan}${c.bold}⚡ Bootspring Watch${c.reset}
685
+ ${c.dim}Real-time file watching and sync${c.reset}
686
+
687
+ ${c.bold}Usage:${c.reset}
688
+ bootspring watch [options]
689
+
690
+ ${c.bold}Options:${c.reset}
691
+ --todos Watch only todo.md
692
+ --workflows Watch only workflow states
693
+ --prd Watch only PRD file
694
+ --checkpoints Watch only checkpoints
695
+ --verbose Show all change events
696
+ --debounce <ms> Debounce interval (default: 300)
697
+
698
+ ${c.bold}Watched Files:${c.reset}
699
+ - todo.md Task changes
700
+ - .bootspring/*/workflow-state.json Workflow phase changes
701
+ - tasks/prd.json Story status changes
702
+ - planning/*.md Checkpoint progress
703
+
704
+ ${c.bold}Events:${c.reset}
705
+ ${c.green}✓${c.reset} Todo completed
706
+ ${c.blue}+${c.reset} Todo added
707
+ ${c.red}-${c.reset} Todo removed
708
+ ${c.cyan}◆${c.reset} Workflow phase change
709
+ ${c.magenta}◇${c.reset} PRD story change
710
+ ${c.green}★${c.reset} Checkpoint completed
711
+ ${c.cyan}▲${c.reset} Checkpoint progress
712
+
713
+ ${c.bold}Examples:${c.reset}
714
+ bootspring watch # Watch all files
715
+ bootspring watch --todos # Watch only todos
716
+ bootspring watch --verbose # Show all events
717
+ `);
718
+ }
719
+
720
+ /**
721
+ * Run watch command
722
+ */
723
+ async function run(args) {
724
+ const parsedArgs = utils.parseArgs(args);
725
+ const subcommand = parsedArgs._[0];
726
+
727
+ if (subcommand === 'help' || parsedArgs.help || parsedArgs.h) {
728
+ showHelp();
729
+ return;
730
+ }
731
+
732
+ const cfg = config.load();
733
+ const projectRoot = cfg._projectRoot;
734
+
735
+ const options = {
736
+ watchTodos: !parsedArgs.workflows && !parsedArgs.prd,
737
+ watchWorkflows: !parsedArgs.todos && !parsedArgs.prd,
738
+ watchPRD: !parsedArgs.todos && !parsedArgs.workflows,
739
+ verbose: parsedArgs.verbose,
740
+ debounceMs: parseInt(parsedArgs.debounce, 10) || 300
741
+ };
742
+
743
+ // If specific flags are set, only watch those
744
+ if (parsedArgs.todos) {
745
+ options.watchTodos = true;
746
+ options.watchWorkflows = false;
747
+ options.watchPRD = false;
748
+ }
749
+ if (parsedArgs.workflows) {
750
+ options.watchTodos = false;
751
+ options.watchWorkflows = true;
752
+ options.watchPRD = false;
753
+ }
754
+ if (parsedArgs.prd) {
755
+ options.watchTodos = false;
756
+ options.watchWorkflows = false;
757
+ options.watchPRD = true;
758
+ }
759
+
760
+ await runWatchMode(projectRoot, options);
761
+ }
762
+
763
+ module.exports = {
764
+ run,
765
+ FileWatcher,
766
+ parseTodoFile,
767
+ diffTodos,
768
+ getTodoStats
769
+ };