specweave 0.21.3 → 0.22.2

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 (235) hide show
  1. package/CLAUDE.md +409 -6
  2. package/README.md +38 -8
  3. package/bin/specweave.js +5 -8
  4. package/dist/plugins/specweave-github/lib/CodeValidator.d.ts +101 -0
  5. package/dist/plugins/specweave-github/lib/CodeValidator.d.ts.map +1 -0
  6. package/dist/plugins/specweave-github/lib/CodeValidator.js +219 -0
  7. package/dist/plugins/specweave-github/lib/CodeValidator.js.map +1 -0
  8. package/dist/plugins/specweave-github/lib/ThreeLayerSyncManager.d.ts +182 -0
  9. package/dist/plugins/specweave-github/lib/ThreeLayerSyncManager.d.ts.map +1 -0
  10. package/dist/plugins/specweave-github/lib/ThreeLayerSyncManager.js +603 -0
  11. package/dist/plugins/specweave-github/lib/ThreeLayerSyncManager.js.map +1 -0
  12. package/dist/plugins/specweave-github/lib/github-client-v2.d.ts +10 -0
  13. package/dist/plugins/specweave-github/lib/github-client-v2.d.ts.map +1 -1
  14. package/dist/plugins/specweave-github/lib/github-client-v2.js +26 -0
  15. package/dist/plugins/specweave-github/lib/github-client-v2.js.map +1 -1
  16. package/dist/plugins/specweave-github/lib/task-sync.d.ts.map +1 -1
  17. package/dist/plugins/specweave-github/lib/task-sync.js +7 -0
  18. package/dist/plugins/specweave-github/lib/task-sync.js.map +1 -1
  19. package/dist/plugins/specweave-github/lib/types.d.ts +34 -0
  20. package/dist/plugins/specweave-github/lib/types.d.ts.map +1 -1
  21. package/dist/src/cli/commands/init.d.ts.map +1 -1
  22. package/dist/src/cli/commands/init.js +60 -5
  23. package/dist/src/cli/commands/init.js.map +1 -1
  24. package/dist/src/cli/commands/migrate-to-profiles.d.ts +1 -0
  25. package/dist/src/cli/commands/migrate-to-profiles.d.ts.map +1 -1
  26. package/dist/src/cli/commands/migrate-to-profiles.js +12 -1
  27. package/dist/src/cli/commands/migrate-to-profiles.js.map +1 -1
  28. package/dist/src/cli/commands/next-command.d.ts +52 -0
  29. package/dist/src/cli/commands/next-command.d.ts.map +1 -0
  30. package/dist/src/cli/commands/next-command.js +204 -0
  31. package/dist/src/cli/commands/next-command.js.map +1 -0
  32. package/dist/src/cli/commands/sync-specs.d.ts +16 -0
  33. package/dist/src/cli/commands/sync-specs.d.ts.map +1 -0
  34. package/dist/src/cli/commands/sync-specs.js +130 -0
  35. package/dist/src/cli/commands/sync-specs.js.map +1 -0
  36. package/dist/src/cli/count-tasks.d.ts +20 -0
  37. package/dist/src/cli/count-tasks.d.ts.map +1 -0
  38. package/dist/src/cli/count-tasks.js +50 -0
  39. package/dist/src/cli/count-tasks.js.map +1 -0
  40. package/dist/src/config/ConfigManager.d.ts.map +1 -1
  41. package/dist/src/config/ConfigManager.js +2 -1
  42. package/dist/src/config/ConfigManager.js.map +1 -1
  43. package/dist/src/config/types.d.ts +58 -58
  44. package/dist/src/core/cicd/state-manager.d.ts +8 -0
  45. package/dist/src/core/cicd/state-manager.d.ts.map +1 -1
  46. package/dist/src/core/cicd/state-manager.js +60 -15
  47. package/dist/src/core/cicd/state-manager.js.map +1 -1
  48. package/dist/src/core/cost-tracker.d.ts.map +1 -1
  49. package/dist/src/core/cost-tracker.js +2 -1
  50. package/dist/src/core/cost-tracker.js.map +1 -1
  51. package/dist/src/core/iac/template-engine.d.ts.map +1 -1
  52. package/dist/src/core/iac/template-engine.js +28 -0
  53. package/dist/src/core/iac/template-engine.js.map +1 -1
  54. package/dist/src/core/iac/template-generator.d.ts +53 -0
  55. package/dist/src/core/iac/template-generator.d.ts.map +1 -0
  56. package/dist/src/core/iac/template-generator.js +125 -0
  57. package/dist/src/core/iac/template-generator.js.map +1 -0
  58. package/dist/src/core/increment/status-auto-transition.js +3 -3
  59. package/dist/src/core/increment/status-auto-transition.js.map +1 -1
  60. package/dist/src/core/living-docs/CodeValidator.js +1 -1
  61. package/dist/src/core/living-docs/CodeValidator.js.map +1 -1
  62. package/dist/src/core/living-docs/CompletionPropagator.d.ts.map +1 -1
  63. package/dist/src/core/living-docs/CompletionPropagator.js +4 -3
  64. package/dist/src/core/living-docs/CompletionPropagator.js.map +1 -1
  65. package/dist/src/core/living-docs/SpecDistributor.d.ts +5 -0
  66. package/dist/src/core/living-docs/SpecDistributor.d.ts.map +1 -1
  67. package/dist/src/core/living-docs/SpecDistributor.js +12 -0
  68. package/dist/src/core/living-docs/SpecDistributor.js.map +1 -1
  69. package/dist/src/core/living-docs/content-distributor.d.ts.map +1 -1
  70. package/dist/src/core/living-docs/content-distributor.js +11 -1
  71. package/dist/src/core/living-docs/content-distributor.js.map +1 -1
  72. package/dist/src/core/living-docs/living-docs-sync.d.ts +166 -0
  73. package/dist/src/core/living-docs/living-docs-sync.d.ts.map +1 -0
  74. package/dist/src/core/living-docs/living-docs-sync.js +726 -0
  75. package/dist/src/core/living-docs/living-docs-sync.js.map +1 -0
  76. package/dist/src/core/living-docs/project-detector.d.ts.map +1 -1
  77. package/dist/src/core/living-docs/project-detector.js +38 -0
  78. package/dist/src/core/living-docs/project-detector.js.map +1 -1
  79. package/dist/src/core/living-docs/task-project-specific-generator.d.ts +7 -3
  80. package/dist/src/core/living-docs/task-project-specific-generator.d.ts.map +1 -1
  81. package/dist/src/core/living-docs/task-project-specific-generator.js +40 -24
  82. package/dist/src/core/living-docs/task-project-specific-generator.js.map +1 -1
  83. package/dist/src/core/plugin-loader.d.ts +7 -0
  84. package/dist/src/core/plugin-loader.d.ts.map +1 -1
  85. package/dist/src/core/plugin-loader.js +18 -1
  86. package/dist/src/core/plugin-loader.js.map +1 -1
  87. package/dist/src/core/serverless/platform-data-loader.d.ts +8 -0
  88. package/dist/src/core/serverless/platform-data-loader.d.ts.map +1 -1
  89. package/dist/src/core/serverless/platform-data-loader.js +14 -0
  90. package/dist/src/core/serverless/platform-data-loader.js.map +1 -1
  91. package/dist/src/core/serverless/types.d.ts +1 -1
  92. package/dist/src/core/serverless/types.d.ts.map +1 -1
  93. package/dist/src/core/status-line/status-line-manager.d.ts +6 -2
  94. package/dist/src/core/status-line/status-line-manager.d.ts.map +1 -1
  95. package/dist/src/core/status-line/status-line-manager.js +11 -5
  96. package/dist/src/core/status-line/status-line-manager.js.map +1 -1
  97. package/dist/src/core/status-line/task-counter.d.ts +69 -0
  98. package/dist/src/core/status-line/task-counter.d.ts.map +1 -0
  99. package/dist/src/core/status-line/task-counter.js +107 -0
  100. package/dist/src/core/status-line/task-counter.js.map +1 -0
  101. package/dist/src/core/types/config.d.ts +23 -0
  102. package/dist/src/core/types/config.d.ts.map +1 -1
  103. package/dist/src/core/types/config.js +10 -0
  104. package/dist/src/core/types/config.js.map +1 -1
  105. package/dist/src/core/workflow/autonomous-executor.d.ts +111 -0
  106. package/dist/src/core/workflow/autonomous-executor.d.ts.map +1 -0
  107. package/dist/src/core/workflow/autonomous-executor.js +275 -0
  108. package/dist/src/core/workflow/autonomous-executor.js.map +1 -0
  109. package/dist/src/core/workflow/backlog-scanner.d.ts +94 -0
  110. package/dist/src/core/workflow/backlog-scanner.d.ts.map +1 -0
  111. package/dist/src/core/workflow/backlog-scanner.js +170 -0
  112. package/dist/src/core/workflow/backlog-scanner.js.map +1 -0
  113. package/dist/src/core/workflow/command-invoker.d.ts +86 -0
  114. package/dist/src/core/workflow/command-invoker.d.ts.map +1 -0
  115. package/dist/src/core/workflow/command-invoker.js +131 -0
  116. package/dist/src/core/workflow/command-invoker.js.map +1 -0
  117. package/dist/src/core/workflow/cost-estimator.d.ts +120 -0
  118. package/dist/src/core/workflow/cost-estimator.d.ts.map +1 -0
  119. package/dist/src/core/workflow/cost-estimator.js +222 -0
  120. package/dist/src/core/workflow/cost-estimator.js.map +1 -0
  121. package/dist/src/core/workflow/index.d.ts +20 -0
  122. package/dist/src/core/workflow/index.d.ts.map +1 -0
  123. package/dist/src/core/workflow/index.js +24 -0
  124. package/dist/src/core/workflow/index.js.map +1 -0
  125. package/dist/src/core/workflow/state-manager.d.ts +107 -0
  126. package/dist/src/core/workflow/state-manager.d.ts.map +1 -0
  127. package/dist/src/core/workflow/state-manager.js +126 -0
  128. package/dist/src/core/workflow/state-manager.js.map +1 -0
  129. package/dist/src/core/workflow/workflow-orchestrator.d.ts +93 -0
  130. package/dist/src/core/workflow/workflow-orchestrator.d.ts.map +1 -0
  131. package/dist/src/core/workflow/workflow-orchestrator.js +195 -0
  132. package/dist/src/core/workflow/workflow-orchestrator.js.map +1 -0
  133. package/dist/src/init/ArchitecturePresenter.d.ts +47 -0
  134. package/dist/src/init/ArchitecturePresenter.d.ts.map +1 -0
  135. package/dist/src/init/ArchitecturePresenter.js +180 -0
  136. package/dist/src/init/ArchitecturePresenter.js.map +1 -0
  137. package/dist/src/init/InitFlow.d.ts.map +1 -1
  138. package/dist/src/init/InitFlow.js +30 -1
  139. package/dist/src/init/InitFlow.js.map +1 -1
  140. package/dist/src/init/architecture/CostEstimator.d.ts +52 -0
  141. package/dist/src/init/architecture/CostEstimator.d.ts.map +1 -0
  142. package/dist/src/init/architecture/CostEstimator.js +107 -0
  143. package/dist/src/init/architecture/CostEstimator.js.map +1 -0
  144. package/dist/src/init/architecture/InfrastructureMapper.d.ts +41 -0
  145. package/dist/src/init/architecture/InfrastructureMapper.d.ts.map +1 -0
  146. package/dist/src/init/architecture/InfrastructureMapper.js +140 -0
  147. package/dist/src/init/architecture/InfrastructureMapper.js.map +1 -0
  148. package/dist/src/init/architecture/ProjectGenerator.d.ts +44 -0
  149. package/dist/src/init/architecture/ProjectGenerator.d.ts.map +1 -0
  150. package/dist/src/init/architecture/ProjectGenerator.js +216 -0
  151. package/dist/src/init/architecture/ProjectGenerator.js.map +1 -0
  152. package/dist/src/init/architecture/types.d.ts +10 -10
  153. package/dist/src/init/research/src/config/types.d.ts +8 -8
  154. package/dist/src/metrics/dora-calculator.js +2 -2
  155. package/dist/src/metrics/dora-calculator.js.map +1 -1
  156. package/dist/src/utils/pricing-constants.d.ts +5 -2
  157. package/dist/src/utils/pricing-constants.d.ts.map +1 -1
  158. package/dist/src/utils/pricing-constants.js +3 -2
  159. package/dist/src/utils/pricing-constants.js.map +1 -1
  160. package/package.json +9 -8
  161. package/plugins/specweave/agents/infrastructure/AGENT.md +88 -46
  162. package/plugins/specweave/agents/pm/AGENT.md +58 -1
  163. package/plugins/specweave/commands/specweave-archive-features.md +1 -1
  164. package/plugins/specweave/commands/specweave-archive-increments.md +1 -1
  165. package/plugins/specweave/commands/specweave-check-hooks.md +5 -0
  166. package/plugins/specweave/commands/specweave-done.md +12 -0
  167. package/plugins/specweave/commands/specweave-plan.md +1 -1
  168. package/plugins/specweave/commands/specweave-progress.md +108 -379
  169. package/plugins/specweave/commands/specweave-reopen.md +1 -1
  170. package/plugins/specweave/commands/specweave-restore-feature.md +1 -1
  171. package/plugins/specweave/commands/specweave-sync-specs.md +20 -48
  172. package/plugins/specweave/hooks/lib/update-status-line.sh +44 -35
  173. package/plugins/specweave/hooks/lib/validate-spec-status.sh +163 -0
  174. package/plugins/specweave/hooks/user-prompt-submit.sh +17 -35
  175. package/plugins/specweave/lib/hooks/update-tasks-md.js +52 -9
  176. package/plugins/specweave/lib/hooks/update-tasks-md.ts +77 -16
  177. package/plugins/specweave/templates/iac/aws-lambda/defaults.json +24 -0
  178. package/plugins/specweave/templates/iac/aws-lambda/templates/README.md.hbs +260 -0
  179. package/plugins/specweave/templates/iac/aws-lambda/templates/environments/dev.tfvars.hbs +34 -0
  180. package/plugins/specweave/templates/iac/aws-lambda/templates/environments/prod.tfvars.hbs +37 -0
  181. package/plugins/specweave/templates/iac/aws-lambda/templates/environments/staging.tfvars.hbs +35 -0
  182. package/plugins/specweave/templates/iac/aws-lambda/templates/outputs.tf.hbs +77 -0
  183. package/plugins/specweave/templates/iac/aws-lambda/templates/providers.tf.hbs +36 -0
  184. package/plugins/specweave/templates/iac/aws-lambda/templates/variables.tf.hbs +115 -0
  185. package/plugins/specweave/templates/iac/azure-functions/defaults.json +25 -0
  186. package/plugins/specweave/templates/iac/azure-functions/templates/README.md.hbs +268 -0
  187. package/plugins/specweave/templates/iac/azure-functions/templates/environments/dev.tfvars.hbs +34 -0
  188. package/plugins/specweave/templates/iac/azure-functions/templates/environments/prod.tfvars.hbs +46 -0
  189. package/plugins/specweave/templates/iac/azure-functions/templates/environments/staging.tfvars.hbs +34 -0
  190. package/plugins/specweave/templates/iac/azure-functions/templates/main.tf.hbs +225 -0
  191. package/plugins/specweave/templates/iac/azure-functions/templates/outputs.tf.hbs +89 -0
  192. package/plugins/specweave/templates/iac/azure-functions/templates/provider.tf.hbs +27 -0
  193. package/plugins/specweave/templates/iac/azure-functions/templates/providers.tf.hbs +35 -0
  194. package/plugins/specweave/templates/iac/azure-functions/templates/variables.tf.hbs +124 -0
  195. package/plugins/specweave/templates/iac/firebase/defaults.json +29 -0
  196. package/plugins/specweave/templates/iac/firebase/templates/README.md.hbs +35 -0
  197. package/plugins/specweave/templates/iac/firebase/templates/environments/dev.tfvars.hbs +7 -0
  198. package/plugins/specweave/templates/iac/firebase/templates/environments/prod.tfvars.hbs +7 -0
  199. package/plugins/specweave/templates/iac/firebase/templates/environments/staging.tfvars.hbs +7 -0
  200. package/plugins/specweave/templates/iac/firebase/templates/main.tf.hbs +90 -0
  201. package/plugins/specweave/templates/iac/firebase/templates/outputs.tf.hbs +15 -0
  202. package/plugins/specweave/templates/iac/firebase/templates/providers.tf.hbs +23 -0
  203. package/plugins/specweave/templates/iac/firebase/templates/variables.tf.hbs +42 -0
  204. package/plugins/specweave/templates/iac/gcp-cloud-functions/defaults.json +26 -0
  205. package/plugins/specweave/templates/iac/gcp-cloud-functions/templates/README.md.hbs +299 -0
  206. package/plugins/specweave/templates/iac/gcp-cloud-functions/templates/environments/dev.tfvars.hbs +36 -0
  207. package/plugins/specweave/templates/iac/gcp-cloud-functions/templates/environments/prod.tfvars.hbs +48 -0
  208. package/plugins/specweave/templates/iac/gcp-cloud-functions/templates/environments/staging.tfvars.hbs +41 -0
  209. package/plugins/specweave/templates/iac/gcp-cloud-functions/templates/main.tf.hbs +192 -0
  210. package/plugins/specweave/templates/iac/gcp-cloud-functions/templates/outputs.tf.hbs +66 -0
  211. package/plugins/specweave/templates/iac/gcp-cloud-functions/templates/providers.tf.hbs +25 -0
  212. package/plugins/specweave/templates/iac/gcp-cloud-functions/templates/variables.tf.hbs +119 -0
  213. package/plugins/specweave/templates/iac/supabase/defaults.json +15 -0
  214. package/plugins/specweave/templates/iac/supabase/templates/README.md.hbs +46 -0
  215. package/plugins/specweave/templates/iac/supabase/templates/main.tf.hbs +50 -0
  216. package/plugins/specweave-ado/lib/enhanced-ado-sync.js +170 -0
  217. package/plugins/specweave-github/agents/github-manager/AGENT.md +39 -7
  218. package/plugins/specweave-github/commands/specweave-github-create-issue.md +5 -5
  219. package/plugins/specweave-github/lib/CodeValidator.js +195 -0
  220. package/plugins/specweave-github/lib/CodeValidator.ts +284 -0
  221. package/plugins/specweave-github/lib/ThreeLayerSyncManager.js +545 -0
  222. package/plugins/specweave-github/lib/ThreeLayerSyncManager.ts +809 -0
  223. package/plugins/specweave-github/lib/github-client-v2.js +29 -0
  224. package/plugins/specweave-github/lib/github-client-v2.ts +30 -0
  225. package/plugins/specweave-github/lib/task-sync.js +4 -0
  226. package/plugins/specweave-github/lib/task-sync.ts +7 -0
  227. package/plugins/specweave-github/lib/types.ts +38 -0
  228. package/plugins/specweave-jira/lib/enhanced-jira-sync.js +3 -3
  229. package/plugins/specweave-release/hooks/.specweave/logs/dora-tracking.log +3222 -0
  230. package/src/templates/AGENTS.md.template +22 -1
  231. package/src/templates/CLAUDE.md.template +31 -0
  232. package/dist/src/core/living-docs/ThreeLayerSyncManager.d.ts +0 -116
  233. package/dist/src/core/living-docs/ThreeLayerSyncManager.d.ts.map +0 -1
  234. package/dist/src/core/living-docs/ThreeLayerSyncManager.js +0 -356
  235. package/dist/src/core/living-docs/ThreeLayerSyncManager.js.map +0 -1
@@ -32,6 +32,13 @@ interface TaskMatch {
32
32
  currentStatus: 'pending' | 'in_progress' | 'completed';
33
33
  }
34
34
 
35
+ interface TaskConsistencyFix {
36
+ taskId: string;
37
+ lineNumber: number;
38
+ action: 'add-complete-marker' | 'remove-complete-marker';
39
+ currentLine: string;
40
+ }
41
+
35
42
  /**
36
43
  * Main function - update tasks.md for given increment
37
44
  */
@@ -62,20 +69,30 @@ async function updateTasksMd(incrementId: string): Promise<void> {
62
69
  const tasks = parseTaskStatus(lines);
63
70
  console.log(`📋 Found ${tasks.length} tasks`);
64
71
 
65
- // 4. Get recently completed tasks from environment (passed by hook)
66
- // For now, we'll mark tasks as complete if they match a heuristic
67
- // TODO: In future, hook will pass completed task IDs via env var
68
- const completedTasks = detectCompletedTasks(lines);
72
+ // 4. Get recently completed tasks and consistency fixes
73
+ const { completedTasks, fixes } = detectCompletedTasks(lines);
69
74
 
70
- if (completedTasks.length === 0) {
71
- console.log('✅ No new task completions detected');
75
+ // 4a. Apply consistency fixes FIRST (if any)
76
+ let updatedContent = originalContent;
77
+ let autoFixedCount = 0;
78
+
79
+ if (fixes.length > 0) {
80
+ console.log(`🔧 Auto-fixing ${fixes.length} task consistency issue(s)...`);
81
+ updatedContent = applyConsistencyFixes(originalContent, fixes);
82
+ autoFixedCount = fixes.length;
83
+ console.log('✅ Task consistency auto-fixed');
84
+ }
85
+
86
+ if (completedTasks.length === 0 && fixes.length === 0) {
87
+ console.log('✅ No new task completions or consistency fixes needed');
72
88
  return;
73
89
  }
74
90
 
75
- console.log(`🎯 Detected ${completedTasks.length} completed task(s):`, completedTasks);
91
+ if (completedTasks.length > 0) {
92
+ console.log(`🎯 Detected ${completedTasks.length} completed task(s):`, completedTasks);
93
+ }
76
94
 
77
95
  // 5. Update task status in content
78
- let updatedContent = originalContent;
79
96
 
80
97
  for (const taskId of completedTasks) {
81
98
  updatedContent = markTaskComplete(updatedContent, taskId);
@@ -96,6 +113,9 @@ async function updateTasksMd(incrementId: string): Promise<void> {
96
113
  await fs.writeFile(tasksPath, updatedContent, 'utf-8');
97
114
 
98
115
  console.log(`✅ Updated ${tasksPath}`);
116
+ if (autoFixedCount > 0) {
117
+ console.log(`🔧 Auto-fixed ${autoFixedCount} consistency issue(s)`);
118
+ }
99
119
  console.log(` Completed: ${completedCount}/${totalTasks}`);
100
120
  console.log(` Progress: ${progress}%\n`);
101
121
 
@@ -158,8 +178,9 @@ function parseTaskStatus(lines: string[]): TaskMatch[] {
158
178
  *
159
179
  * @see .specweave/increments/0037/reports/ULTRATHINK-COMPLETE-MARKER-VS-CHECKBOXES.md
160
180
  */
161
- function detectCompletedTasks(lines: string[]): string[] {
181
+ function detectCompletedTasks(lines: string[]): { completedTasks: string[]; fixes: TaskConsistencyFix[] } {
162
182
  const completedTasks: string[] = [];
183
+ const fixes: TaskConsistencyFix[] = [];
163
184
  const warnings: string[] = [];
164
185
  const taskPattern = /^###\s+(T-\d+[-A-Z]*):?\s+(.+)/;
165
186
 
@@ -190,22 +211,38 @@ function detectCompletedTasks(lines: string[]): string[] {
190
211
  completedTasks.push(taskId);
191
212
  }
192
213
  } else {
193
- // ⚠️ INCONSISTENT: Header says COMPLETE but checkboxes incomplete
214
+ // ⚠️ INCONSISTENT: Header says COMPLETE but checkboxes incomplete - AUTO-FIX
215
+ fixes.push({
216
+ taskId,
217
+ lineNumber: i,
218
+ action: 'remove-complete-marker',
219
+ currentLine: line
220
+ });
194
221
  warnings.push(`${taskId}: Header has ✅ COMPLETE but not all checkboxes checked`);
195
222
  }
196
223
  continue;
197
224
  }
198
225
 
199
- // If no implementation section, trust the header marker
226
+ // If no implementation section, remove COMPLETE marker (can't verify)
200
227
  if (hasCompleteMarker && !implementationSection) {
201
- if (!completedTasks.includes(taskId)) {
202
- completedTasks.push(taskId);
203
- }
228
+ fixes.push({
229
+ taskId,
230
+ lineNumber: i,
231
+ action: 'remove-complete-marker',
232
+ currentLine: line
233
+ });
234
+ warnings.push(`${taskId}: Header has ✅ COMPLETE but no implementation section to verify`);
204
235
  continue;
205
236
  }
206
237
 
207
- // Warn if checkboxes all complete but header missing marker
238
+ // Warn if checkboxes all complete but header missing marker - AUTO-FIX
208
239
  if (!hasCompleteMarker && implementationSection && allCheckboxesComplete) {
240
+ fixes.push({
241
+ taskId,
242
+ lineNumber: i,
243
+ action: 'add-complete-marker',
244
+ currentLine: line
245
+ });
209
246
  warnings.push(`${taskId}: All checkboxes checked but header missing ✅ COMPLETE`);
210
247
  // Still count as complete (checkboxes are source of truth for work done)
211
248
  if (!completedTasks.includes(taskId)) {
@@ -233,7 +270,31 @@ function detectCompletedTasks(lines: string[]): string[] {
233
270
  console.warn('');
234
271
  }
235
272
 
236
- return completedTasks;
273
+ return { completedTasks, fixes };
274
+ }
275
+
276
+ /**
277
+ * Apply task consistency fixes to content
278
+ */
279
+ function applyConsistencyFixes(content: string, fixes: TaskConsistencyFix[]): string {
280
+ const lines = content.split('\n');
281
+
282
+ // Apply fixes (process in reverse order to preserve line numbers)
283
+ for (const fix of fixes.reverse()) {
284
+ const line = lines[fix.lineNumber];
285
+
286
+ if (fix.action === 'remove-complete-marker') {
287
+ // Remove ✅ COMPLETE from header
288
+ const fixed = line.replace(/\s*✅\s*COMPLETE\s*/g, '');
289
+ lines[fix.lineNumber] = fixed;
290
+ } else if (fix.action === 'add-complete-marker') {
291
+ // Add ✅ COMPLETE to header (before any trailing spaces)
292
+ const fixed = line.trim() + ' ✅ COMPLETE';
293
+ lines[fix.lineNumber] = fixed;
294
+ }
295
+ }
296
+
297
+ return lines.join('\n');
237
298
  }
238
299
 
239
300
  /**
@@ -0,0 +1,24 @@
1
+ {
2
+ "region": "us-east-1",
3
+ "functionName": "my-lambda-function",
4
+ "runtime": "nodejs20.x",
5
+ "handler": "index.handler",
6
+ "memorySize": 128,
7
+ "timeout": 30,
8
+ "environment": "dev",
9
+ "databaseName": "my-dynamodb-table",
10
+ "primaryKey": "id",
11
+ "apiName": "my-api",
12
+ "apiStageName": "default",
13
+ "logRetentionDays": 90,
14
+ "corsOrigins": ["*"],
15
+ "projectName": "my-project",
16
+ "enableVpc": false,
17
+ "enableXray": false,
18
+ "enableSecretsManager": false,
19
+ "enableKms": false,
20
+ "enableEncryption": false,
21
+ "enablePointInTimeRecovery": false,
22
+ "enableStreams": false,
23
+ "enableRemoteState": false
24
+ }
@@ -0,0 +1,260 @@
1
+ # {{functionName}} - AWS Lambda Serverless Infrastructure
2
+
3
+ **Generated by SpecWeave Serverless Architecture Intelligence**
4
+
5
+ ## Overview
6
+
7
+ This Terraform configuration deploys a complete serverless application stack on AWS:
8
+
9
+ - **Lambda Function**: `{{functionName}}` ({{runtime}}, {{memorySize}}MB memory, {{timeout}}s timeout)
10
+ - **API Gateway**: HTTP API with CORS support
11
+ - **DynamoDB**: NoSQL database table `{{databaseName}}`
12
+ - **CloudWatch Logs**: Centralized logging with {{logRetentionDays}}-day retention
13
+ {{#if enableVpc}}- **VPC Integration**: Secure network isolation{{/if}}
14
+ {{#if enableXray}}- **X-Ray Tracing**: Distributed tracing enabled{{/if}}
15
+ {{#if enableSecretsManager}}- **Secrets Manager**: Secure secret storage{{/if}}
16
+
17
+ ## Architecture
18
+
19
+ ```
20
+ ┌─────────────┐
21
+ │ Client │
22
+ └──────┬──────┘
23
+ │ HTTPS
24
+ v
25
+ ┌─────────────────┐
26
+ │ API Gateway │
27
+ │ (HTTP API) │
28
+ └──────┬──────────┘
29
+
30
+ v
31
+ ┌────────────────────┐ ┌──────────────┐
32
+ │ Lambda Function │─────>│ DynamoDB │
33
+ │ {{functionName}} │ │ {{databaseName}} │
34
+ └────────────────────┘ └──────────────┘
35
+
36
+ v
37
+ ┌────────────────────┐
38
+ │ CloudWatch Logs │
39
+ └────────────────────┘
40
+ ```
41
+
42
+ ## Prerequisites
43
+
44
+ 1. **AWS CLI** configured with credentials:
45
+ ```bash
46
+ aws configure
47
+ ```
48
+
49
+ 2. **Terraform** v1.5.0 or higher:
50
+ ```bash
51
+ terraform version
52
+ ```
53
+
54
+ 3. **Lambda deployment package** ({{functionName}}.zip):
55
+ - Create your Lambda function code
56
+ - Package as {{functionName}}.zip
57
+ - Place in the same directory as this README
58
+
59
+ ## Deployment Instructions
60
+
61
+ ### Step 1: Initialize Terraform
62
+
63
+ ```bash
64
+ terraform init
65
+ ```
66
+
67
+ This downloads the AWS provider and initializes the backend.
68
+
69
+ ### Step 2: Review Configuration
70
+
71
+ Edit `terraform.tfvars` (or create environment-specific files like `dev.tfvars`) to customize:
72
+
73
+ ```hcl
74
+ aws_region = "{{region}}"
75
+ function_name = "{{functionName}}"
76
+ environment = "{{environment}}"
77
+ runtime = "{{runtime}}"
78
+ memory_size = {{memorySize}}
79
+ timeout = {{timeout}}
80
+ database_name = "{{databaseName}}"
81
+ primary_key = "{{primaryKey}}"
82
+ project_name = "{{projectName}}"
83
+ ```
84
+
85
+ ### Step 3: Plan Deployment
86
+
87
+ ```bash
88
+ terraform plan
89
+ ```
90
+
91
+ Review the resources that will be created:
92
+ - 1× Lambda Function
93
+ - 1× API Gateway HTTP API
94
+ - 1× DynamoDB Table
95
+ - 2× CloudWatch Log Groups
96
+ - 1× IAM Role + Policies
97
+ {{#if enableVpc}}- 1× Security Group (VPC){{/if}}
98
+
99
+ ### Step 4: Deploy
100
+
101
+ ```bash
102
+ terraform apply
103
+ ```
104
+
105
+ Type `yes` when prompted to confirm deployment.
106
+
107
+ ### Step 5: Verify Deployment
108
+
109
+ After successful deployment, Terraform will output:
110
+
111
+ ```
112
+ api_endpoint = "https://xxxxxxxxxx.execute-api.{{region}}.amazonaws.com/{{apiStageName}}"
113
+ function_name = "{{functionName}}"
114
+ table_name = "{{databaseName}}"
115
+ ```
116
+
117
+ Test your API:
118
+
119
+ ```bash
120
+ curl https://xxxxxxxxxx.execute-api.{{region}}.amazonaws.com/{{apiStageName}}
121
+ ```
122
+
123
+ ## Environment-Specific Deployments
124
+
125
+ Deploy to different environments using tfvars files:
126
+
127
+ ```bash
128
+ # Development
129
+ terraform apply -var-file="environments/dev.tfvars"
130
+
131
+ # Staging
132
+ terraform apply -var-file="environments/staging.tfvars"
133
+
134
+ # Production
135
+ terraform apply -var-file="environments/prod.tfvars"
136
+ ```
137
+
138
+ ## Cost Optimization
139
+
140
+ ### Free Tier Limits (First 12 Months)
141
+
142
+ - **Lambda**: 1M requests/month + 400,000 GB-seconds compute
143
+ - **API Gateway**: 1M API calls/month (first 12 months)
144
+ - **DynamoDB**: 25GB storage + 25 WCU + 25 RCU (always free)
145
+ - **CloudWatch Logs**: 5GB ingestion + 5GB storage
146
+
147
+ ### Estimated Monthly Cost (After Free Tier)
148
+
149
+ **{{environment}} Environment**:
150
+ {{#if eq environment "dev"}}
151
+ - **Lambda**: ~$0.20/month (10K requests, 128MB, 1s avg duration)
152
+ - **API Gateway**: ~$0.10/month (10K requests)
153
+ - **DynamoDB**: $0.00/month (PAY_PER_REQUEST under free tier)
154
+ - **CloudWatch Logs**: ~$0.50/month (1GB logs)
155
+ - **Total**: ~$0.80/month
156
+ {{else}}{{#if eq environment "staging"}}
157
+ - **Lambda**: ~$2.00/month (100K requests, 256MB, 1s avg duration)
158
+ - **API Gateway**: ~$1.00/month (100K requests)
159
+ - **DynamoDB**: ~$1.25/month (PAY_PER_REQUEST, light usage)
160
+ - **CloudWatch Logs**: ~$1.00/month (2GB logs)
161
+ - **Total**: ~$5.25/month
162
+ {{else}}
163
+ - **Lambda**: ~$20.00/month (1M requests, 512MB, 1s avg duration)
164
+ - **API Gateway**: ~$10.00/month (1M requests)
165
+ - **DynamoDB**: ~$12.50/month (PROVISIONED, 5 RCU/WCU)
166
+ - **CloudWatch Logs**: ~$5.00/month (10GB logs)
167
+ - **Total**: ~$47.50/month
168
+ {{/if}}{{/if}}
169
+
170
+ ### Cost Optimization Tips
171
+
172
+ 1. **Right-size memory**: Test with different memory settings (128MB, 256MB, 512MB)
173
+ 2. **Optimize timeout**: Reduce timeout to actual function duration
174
+ 3. **Use PAY_PER_REQUEST**: For low-traffic apps (<100K requests/month)
175
+ 4. **Enable CloudWatch Logs retention**: Delete old logs automatically
176
+ 5. **Monitor cold starts**: Use Provisioned Concurrency if needed ($$)
177
+
178
+ ## Security Best Practices
179
+
180
+ ✅ **Implemented**:
181
+ - IAM least privilege roles
182
+ - HTTPS-only API Gateway
183
+ - CloudWatch Logs encryption
184
+ - DynamoDB encryption at rest (if enabled)
185
+ - Secrets Manager for sensitive data (if enabled)
186
+
187
+ ⚠️ **Additional Recommendations**:
188
+ - Enable AWS WAF for API Gateway
189
+ - Implement rate limiting
190
+ - Use AWS Shield for DDoS protection
191
+ - Enable VPC for database access
192
+ - Rotate secrets regularly
193
+
194
+ ## Monitoring and Logging
195
+
196
+ ### CloudWatch Logs
197
+
198
+ View Lambda logs:
199
+ ```bash
200
+ aws logs tail /aws/lambda/{{functionName}} --follow
201
+ ```
202
+
203
+ View API Gateway logs:
204
+ ```bash
205
+ aws logs tail /aws/apigateway/{{apiName}}-{{environment}} --follow
206
+ ```
207
+
208
+ ### CloudWatch Metrics
209
+
210
+ Monitor in AWS Console:
211
+ - Lambda: Invocations, Duration, Errors, Throttles
212
+ - API Gateway: Count, Latency, 4XX/5XX errors
213
+ - DynamoDB: Read/Write capacity, Throttled requests
214
+
215
+ ## Cleanup
216
+
217
+ To destroy all resources:
218
+
219
+ ```bash
220
+ terraform destroy
221
+ ```
222
+
223
+ Type `yes` to confirm deletion.
224
+
225
+ **Warning**: This will permanently delete:
226
+ - Lambda function
227
+ - API Gateway
228
+ - DynamoDB table (and all data)
229
+ - CloudWatch Logs
230
+
231
+ ## Troubleshooting
232
+
233
+ ### Lambda Function Not Working
234
+
235
+ 1. Check CloudWatch Logs for errors
236
+ 2. Verify IAM role permissions
237
+ 3. Test function locally with AWS SAM
238
+
239
+ ### API Gateway 403 Errors
240
+
241
+ 1. Verify Lambda permission for API Gateway
242
+ 2. Check CORS configuration
243
+ 3. Review API Gateway execution logs
244
+
245
+ ### DynamoDB Access Denied
246
+
247
+ 1. Verify Lambda IAM role has DynamoDB permissions
248
+ 2. Check table name matches environment variable
249
+ 3. Verify primary key schema
250
+
251
+ ## Support
252
+
253
+ For issues with this Terraform configuration, contact your SpecWeave administrator or file an issue at https://github.com/anton-abyzov/specweave/issues.
254
+
255
+ ## Additional Resources
256
+
257
+ - [AWS Lambda Documentation](https://docs.aws.amazon.com/lambda/)
258
+ - [API Gateway HTTP API Guide](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api.html)
259
+ - [DynamoDB Developer Guide](https://docs.aws.amazon.com/dynamodb/)
260
+ - [Terraform AWS Provider](https://registry.terraform.io/providers/hashicorp/aws/latest/docs)
@@ -0,0 +1,34 @@
1
+ # Development Environment Configuration
2
+ # Optimized for free tier and minimal costs
3
+ # Generated by SpecWeave Serverless Architecture Intelligence
4
+
5
+ aws_region = "{{region}}"
6
+ environment = "dev"
7
+ function_name = "{{functionName}}-dev"
8
+ runtime = "{{runtime}}"
9
+
10
+ # Free tier optimized settings
11
+ memory_size = 128 # Smallest memory size (free tier eligible)
12
+ timeout = 30 # Conservative timeout
13
+
14
+ # Database configuration
15
+ database_name = "{{databaseName}}-dev"
16
+ primary_key = "{{primaryKey}}"
17
+ {{#if sortKey}}
18
+ sort_key = "{{sortKey}}"
19
+ {{/if}}
20
+
21
+ # Logging (keep retention short in dev)
22
+ log_retention_days = 7
23
+
24
+ # CORS (allow localhost for development)
25
+ cors_origins = ["http://localhost:3000", "http://localhost:8080"]
26
+
27
+ # Project metadata
28
+ project_name = "{{projectName}}"
29
+
30
+ # Additional tags
31
+ tags = {
32
+ CostCenter = "Development"
33
+ AutoDelete = "true" # Mark for cleanup scripts
34
+ }
@@ -0,0 +1,37 @@
1
+ # Production Environment Configuration
2
+ # High availability, performance, and security
3
+ # Generated by SpecWeave Serverless Architecture Intelligence
4
+
5
+ aws_region = "{{region}}"
6
+ environment = "prod"
7
+ function_name = "{{functionName}}-prod"
8
+ runtime = "{{runtime}}"
9
+
10
+ # Production-optimized settings
11
+ memory_size = 512 # Higher memory for better performance
12
+ timeout = 300 # 5-minute timeout for complex operations
13
+
14
+ # Database configuration
15
+ database_name = "{{databaseName}}-prod"
16
+ primary_key = "{{primaryKey}}"
17
+ {{#if sortKey}}
18
+ sort_key = "{{sortKey}}"
19
+ {{/if}}
20
+
21
+ # Logging (long retention for compliance)
22
+ log_retention_days = 90
23
+
24
+ # CORS (production domains only)
25
+ cors_origins = ["https://{{projectName}}.com", "https://www.{{projectName}}.com", "https://api.{{projectName}}.com"]
26
+
27
+ # Project metadata
28
+ project_name = "{{projectName}}"
29
+
30
+ # Additional tags
31
+ tags = {
32
+ CostCenter = "Production"
33
+ AutoDelete = "false"
34
+ Backup = "true"
35
+ DisasterRecovery = "true"
36
+ Compliance = "SOC2"
37
+ }
@@ -0,0 +1,35 @@
1
+ # Staging Environment Configuration
2
+ # Medium-tier resources for pre-production testing
3
+ # Generated by SpecWeave Serverless Architecture Intelligence
4
+
5
+ aws_region = "{{region}}"
6
+ environment = "staging"
7
+ function_name = "{{functionName}}-staging"
8
+ runtime = "{{runtime}}"
9
+
10
+ # Medium-tier settings
11
+ memory_size = 256 # Double dev memory for realistic testing
12
+ timeout = 60 # Higher timeout for complex operations
13
+
14
+ # Database configuration
15
+ database_name = "{{databaseName}}-staging"
16
+ primary_key = "{{primaryKey}}"
17
+ {{#if sortKey}}
18
+ sort_key = "{{sortKey}}"
19
+ {{/if}}
20
+
21
+ # Logging (moderate retention for staging)
22
+ log_retention_days = 30
23
+
24
+ # CORS (allow staging domains)
25
+ cors_origins = ["https://staging.{{projectName}}.com", "http://localhost:3000"]
26
+
27
+ # Project metadata
28
+ project_name = "{{projectName}}"
29
+
30
+ # Additional tags
31
+ tags = {
32
+ CostCenter = "Staging"
33
+ AutoDelete = "false"
34
+ Backup = "true"
35
+ }
@@ -0,0 +1,77 @@
1
+ # Outputs for AWS Lambda + API Gateway + DynamoDB
2
+ # Generated by SpecWeave Serverless Architecture Intelligence
3
+
4
+ output "api_endpoint" {
5
+ description = "API Gateway endpoint URL"
6
+ value = aws_apigatewayv2_stage.{{snakeCase apiStageName}}.invoke_url
7
+ }
8
+
9
+ output "api_id" {
10
+ description = "API Gateway ID"
11
+ value = aws_apigatewayv2_api.{{snakeCase apiName}}.id
12
+ }
13
+
14
+ output "function_name" {
15
+ description = "Lambda function name"
16
+ value = aws_lambda_function.{{snakeCase functionName}}.function_name
17
+ }
18
+
19
+ output "function_arn" {
20
+ description = "Lambda function ARN"
21
+ value = aws_lambda_function.{{snakeCase functionName}}.arn
22
+ }
23
+
24
+ output "function_invoke_arn" {
25
+ description = "Lambda function invoke ARN"
26
+ value = aws_lambda_function.{{snakeCase functionName}}.invoke_arn
27
+ }
28
+
29
+ output "table_name" {
30
+ description = "DynamoDB table name"
31
+ value = aws_dynamodb_table.{{snakeCase databaseName}}.name
32
+ }
33
+
34
+ output "table_arn" {
35
+ description = "DynamoDB table ARN"
36
+ value = aws_dynamodb_table.{{snakeCase databaseName}}.arn
37
+ }
38
+
39
+ {{#if enableStreams}}
40
+ output "table_stream_arn" {
41
+ description = "DynamoDB stream ARN"
42
+ value = aws_dynamodb_table.{{snakeCase databaseName}}.stream_arn
43
+ }
44
+ {{/if}}
45
+
46
+ output "lambda_role_arn" {
47
+ description = "Lambda execution role ARN"
48
+ value = aws_iam_role.lambda_exec.arn
49
+ }
50
+
51
+ output "lambda_logs_group" {
52
+ description = "CloudWatch Logs group for Lambda"
53
+ value = aws_cloudwatch_log_group.lambda_logs.name
54
+ }
55
+
56
+ output "api_logs_group" {
57
+ description = "CloudWatch Logs group for API Gateway"
58
+ value = aws_cloudwatch_log_group.api_logs.name
59
+ }
60
+
61
+ {{#if enableVpc}}
62
+ output "lambda_security_group_id" {
63
+ description = "Security group ID for Lambda function"
64
+ value = aws_security_group.lambda_sg.id
65
+ }
66
+ {{/if}}
67
+
68
+ output "deployment_summary" {
69
+ description = "Summary of deployed resources"
70
+ value = {
71
+ api_endpoint = aws_apigatewayv2_stage.{{snakeCase apiStageName}}.invoke_url
72
+ function_name = aws_lambda_function.{{snakeCase functionName}}.function_name
73
+ table_name = aws_dynamodb_table.{{snakeCase databaseName}}.name
74
+ environment = var.environment
75
+ region = var.aws_region
76
+ }
77
+ }
@@ -0,0 +1,36 @@
1
+ # Terraform and AWS Provider Configuration
2
+ # Generated by SpecWeave Serverless Architecture Intelligence
3
+
4
+ terraform {
5
+ required_version = ">= 1.5.0"
6
+
7
+ required_providers {
8
+ aws = {
9
+ source = "hashicorp/aws"
10
+ version = "~> 5.0"
11
+ }
12
+ }
13
+
14
+ {{#if enableRemoteState}}
15
+ backend "s3" {
16
+ bucket = "{{terraformStateBucket}}"
17
+ key = "{{functionName}}/terraform.tfstate"
18
+ region = "{{region}}"
19
+ encrypt = true
20
+ dynamodb_table = "{{terraformLockTable}}"
21
+ }
22
+ {{/if}}
23
+ }
24
+
25
+ provider "aws" {
26
+ region = var.aws_region
27
+
28
+ default_tags {
29
+ tags = {
30
+ Project = var.project_name
31
+ Environment = var.environment
32
+ ManagedBy = "Terraform"
33
+ CreatedBy = "SpecWeave"
34
+ }
35
+ }
36
+ }