specweave 0.22.0 → 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 (184) hide show
  1. package/CLAUDE.md +211 -0
  2. package/README.md +5 -5
  3. package/bin/specweave.js +5 -8
  4. package/dist/plugins/specweave-github/lib/CodeValidator.d.ts +1 -1
  5. package/dist/plugins/specweave-github/lib/CodeValidator.js +1 -1
  6. package/dist/plugins/specweave-github/lib/github-client-v2.d.ts +10 -0
  7. package/dist/plugins/specweave-github/lib/github-client-v2.d.ts.map +1 -1
  8. package/dist/plugins/specweave-github/lib/github-client-v2.js +26 -0
  9. package/dist/plugins/specweave-github/lib/github-client-v2.js.map +1 -1
  10. package/dist/plugins/specweave-github/lib/task-sync.d.ts.map +1 -1
  11. package/dist/plugins/specweave-github/lib/task-sync.js +7 -0
  12. package/dist/plugins/specweave-github/lib/task-sync.js.map +1 -1
  13. package/dist/src/cli/commands/migrate-to-profiles.d.ts +1 -0
  14. package/dist/src/cli/commands/migrate-to-profiles.d.ts.map +1 -1
  15. package/dist/src/cli/commands/migrate-to-profiles.js +12 -1
  16. package/dist/src/cli/commands/migrate-to-profiles.js.map +1 -1
  17. package/dist/src/cli/commands/next-command.d.ts +52 -0
  18. package/dist/src/cli/commands/next-command.d.ts.map +1 -0
  19. package/dist/src/cli/commands/next-command.js +204 -0
  20. package/dist/src/cli/commands/next-command.js.map +1 -0
  21. package/dist/src/cli/commands/sync-specs.d.ts +16 -0
  22. package/dist/src/cli/commands/sync-specs.d.ts.map +1 -0
  23. package/dist/src/cli/commands/sync-specs.js +130 -0
  24. package/dist/src/cli/commands/sync-specs.js.map +1 -0
  25. package/dist/src/cli/count-tasks.d.ts +20 -0
  26. package/dist/src/cli/count-tasks.d.ts.map +1 -0
  27. package/dist/src/cli/count-tasks.js +50 -0
  28. package/dist/src/cli/count-tasks.js.map +1 -0
  29. package/dist/src/config/ConfigManager.d.ts.map +1 -1
  30. package/dist/src/config/ConfigManager.js +2 -1
  31. package/dist/src/config/ConfigManager.js.map +1 -1
  32. package/dist/src/config/types.d.ts +50 -50
  33. package/dist/src/core/cicd/state-manager.d.ts +8 -0
  34. package/dist/src/core/cicd/state-manager.d.ts.map +1 -1
  35. package/dist/src/core/cicd/state-manager.js +60 -15
  36. package/dist/src/core/cicd/state-manager.js.map +1 -1
  37. package/dist/src/core/cost-tracker.d.ts.map +1 -1
  38. package/dist/src/core/cost-tracker.js +2 -1
  39. package/dist/src/core/cost-tracker.js.map +1 -1
  40. package/dist/src/core/iac/template-engine.d.ts.map +1 -1
  41. package/dist/src/core/iac/template-engine.js +28 -0
  42. package/dist/src/core/iac/template-engine.js.map +1 -1
  43. package/dist/src/core/iac/template-generator.d.ts +53 -0
  44. package/dist/src/core/iac/template-generator.d.ts.map +1 -0
  45. package/dist/src/core/iac/template-generator.js +125 -0
  46. package/dist/src/core/iac/template-generator.js.map +1 -0
  47. package/dist/src/core/increment/status-auto-transition.js +3 -3
  48. package/dist/src/core/increment/status-auto-transition.js.map +1 -1
  49. package/dist/src/core/living-docs/CodeValidator.js +1 -1
  50. package/dist/src/core/living-docs/CodeValidator.js.map +1 -1
  51. package/dist/src/core/living-docs/content-distributor.d.ts.map +1 -1
  52. package/dist/src/core/living-docs/content-distributor.js +11 -1
  53. package/dist/src/core/living-docs/content-distributor.js.map +1 -1
  54. package/dist/src/core/living-docs/living-docs-sync.d.ts +166 -0
  55. package/dist/src/core/living-docs/living-docs-sync.d.ts.map +1 -0
  56. package/dist/src/core/living-docs/living-docs-sync.js +726 -0
  57. package/dist/src/core/living-docs/living-docs-sync.js.map +1 -0
  58. package/dist/src/core/living-docs/task-project-specific-generator.d.ts +7 -3
  59. package/dist/src/core/living-docs/task-project-specific-generator.d.ts.map +1 -1
  60. package/dist/src/core/living-docs/task-project-specific-generator.js +40 -24
  61. package/dist/src/core/living-docs/task-project-specific-generator.js.map +1 -1
  62. package/dist/src/core/plugin-loader.d.ts +7 -0
  63. package/dist/src/core/plugin-loader.d.ts.map +1 -1
  64. package/dist/src/core/plugin-loader.js +18 -1
  65. package/dist/src/core/plugin-loader.js.map +1 -1
  66. package/dist/src/core/serverless/platform-data-loader.d.ts +8 -0
  67. package/dist/src/core/serverless/platform-data-loader.d.ts.map +1 -1
  68. package/dist/src/core/serverless/platform-data-loader.js +14 -0
  69. package/dist/src/core/serverless/platform-data-loader.js.map +1 -1
  70. package/dist/src/core/serverless/types.d.ts +1 -1
  71. package/dist/src/core/serverless/types.d.ts.map +1 -1
  72. package/dist/src/core/status-line/status-line-manager.d.ts +6 -2
  73. package/dist/src/core/status-line/status-line-manager.d.ts.map +1 -1
  74. package/dist/src/core/status-line/status-line-manager.js +11 -5
  75. package/dist/src/core/status-line/status-line-manager.js.map +1 -1
  76. package/dist/src/core/status-line/task-counter.d.ts +69 -0
  77. package/dist/src/core/status-line/task-counter.d.ts.map +1 -0
  78. package/dist/src/core/status-line/task-counter.js +107 -0
  79. package/dist/src/core/status-line/task-counter.js.map +1 -0
  80. package/dist/src/core/workflow/autonomous-executor.d.ts +111 -0
  81. package/dist/src/core/workflow/autonomous-executor.d.ts.map +1 -0
  82. package/dist/src/core/workflow/autonomous-executor.js +275 -0
  83. package/dist/src/core/workflow/autonomous-executor.js.map +1 -0
  84. package/dist/src/core/workflow/backlog-scanner.d.ts +94 -0
  85. package/dist/src/core/workflow/backlog-scanner.d.ts.map +1 -0
  86. package/dist/src/core/workflow/backlog-scanner.js +170 -0
  87. package/dist/src/core/workflow/backlog-scanner.js.map +1 -0
  88. package/dist/src/core/workflow/command-invoker.d.ts +86 -0
  89. package/dist/src/core/workflow/command-invoker.d.ts.map +1 -0
  90. package/dist/src/core/workflow/command-invoker.js +131 -0
  91. package/dist/src/core/workflow/command-invoker.js.map +1 -0
  92. package/dist/src/core/workflow/cost-estimator.d.ts +120 -0
  93. package/dist/src/core/workflow/cost-estimator.d.ts.map +1 -0
  94. package/dist/src/core/workflow/cost-estimator.js +222 -0
  95. package/dist/src/core/workflow/cost-estimator.js.map +1 -0
  96. package/dist/src/core/workflow/index.d.ts +20 -0
  97. package/dist/src/core/workflow/index.d.ts.map +1 -0
  98. package/dist/src/core/workflow/index.js +24 -0
  99. package/dist/src/core/workflow/index.js.map +1 -0
  100. package/dist/src/core/workflow/state-manager.d.ts +107 -0
  101. package/dist/src/core/workflow/state-manager.d.ts.map +1 -0
  102. package/dist/src/core/workflow/state-manager.js +126 -0
  103. package/dist/src/core/workflow/state-manager.js.map +1 -0
  104. package/dist/src/core/workflow/workflow-orchestrator.d.ts +93 -0
  105. package/dist/src/core/workflow/workflow-orchestrator.d.ts.map +1 -0
  106. package/dist/src/core/workflow/workflow-orchestrator.js +195 -0
  107. package/dist/src/core/workflow/workflow-orchestrator.js.map +1 -0
  108. package/dist/src/init/architecture/types.d.ts +10 -10
  109. package/dist/src/metrics/dora-calculator.js +2 -2
  110. package/dist/src/metrics/dora-calculator.js.map +1 -1
  111. package/dist/src/utils/pricing-constants.d.ts +5 -2
  112. package/dist/src/utils/pricing-constants.d.ts.map +1 -1
  113. package/dist/src/utils/pricing-constants.js +3 -2
  114. package/dist/src/utils/pricing-constants.js.map +1 -1
  115. package/package.json +4 -4
  116. package/plugins/specweave/agents/infrastructure/AGENT.md +88 -46
  117. package/plugins/specweave/agents/pm/AGENT.md +58 -1
  118. package/plugins/specweave/commands/specweave-archive-features.md +1 -1
  119. package/plugins/specweave/commands/specweave-archive-increments.md +1 -1
  120. package/plugins/specweave/commands/specweave-check-hooks.md +5 -0
  121. package/plugins/specweave/commands/specweave-done.md +12 -0
  122. package/plugins/specweave/commands/specweave-plan.md +1 -1
  123. package/plugins/specweave/commands/specweave-progress.md +108 -379
  124. package/plugins/specweave/commands/specweave-reopen.md +1 -1
  125. package/plugins/specweave/commands/specweave-restore-feature.md +1 -1
  126. package/plugins/specweave/commands/specweave-sync-specs.md +20 -48
  127. package/plugins/specweave/hooks/lib/update-status-line.sh +44 -35
  128. package/plugins/specweave/hooks/lib/validate-spec-status.sh +163 -0
  129. package/plugins/specweave/hooks/user-prompt-submit.sh +17 -35
  130. package/plugins/specweave/lib/hooks/update-tasks-md.js +52 -9
  131. package/plugins/specweave/lib/hooks/update-tasks-md.ts +77 -16
  132. package/plugins/specweave/templates/iac/aws-lambda/defaults.json +24 -0
  133. package/plugins/specweave/templates/iac/aws-lambda/templates/README.md.hbs +260 -0
  134. package/plugins/specweave/templates/iac/aws-lambda/templates/environments/dev.tfvars.hbs +34 -0
  135. package/plugins/specweave/templates/iac/aws-lambda/templates/environments/prod.tfvars.hbs +37 -0
  136. package/plugins/specweave/templates/iac/aws-lambda/templates/environments/staging.tfvars.hbs +35 -0
  137. package/plugins/specweave/templates/iac/aws-lambda/templates/outputs.tf.hbs +77 -0
  138. package/plugins/specweave/templates/iac/aws-lambda/templates/providers.tf.hbs +36 -0
  139. package/plugins/specweave/templates/iac/aws-lambda/templates/variables.tf.hbs +115 -0
  140. package/plugins/specweave/templates/iac/azure-functions/defaults.json +25 -0
  141. package/plugins/specweave/templates/iac/azure-functions/templates/README.md.hbs +268 -0
  142. package/plugins/specweave/templates/iac/azure-functions/templates/environments/dev.tfvars.hbs +34 -0
  143. package/plugins/specweave/templates/iac/azure-functions/templates/environments/prod.tfvars.hbs +46 -0
  144. package/plugins/specweave/templates/iac/azure-functions/templates/environments/staging.tfvars.hbs +34 -0
  145. package/plugins/specweave/templates/iac/azure-functions/templates/main.tf.hbs +225 -0
  146. package/plugins/specweave/templates/iac/azure-functions/templates/outputs.tf.hbs +89 -0
  147. package/plugins/specweave/templates/iac/azure-functions/templates/provider.tf.hbs +27 -0
  148. package/plugins/specweave/templates/iac/azure-functions/templates/providers.tf.hbs +35 -0
  149. package/plugins/specweave/templates/iac/azure-functions/templates/variables.tf.hbs +124 -0
  150. package/plugins/specweave/templates/iac/firebase/defaults.json +29 -0
  151. package/plugins/specweave/templates/iac/firebase/templates/README.md.hbs +35 -0
  152. package/plugins/specweave/templates/iac/firebase/templates/environments/dev.tfvars.hbs +7 -0
  153. package/plugins/specweave/templates/iac/firebase/templates/environments/prod.tfvars.hbs +7 -0
  154. package/plugins/specweave/templates/iac/firebase/templates/environments/staging.tfvars.hbs +7 -0
  155. package/plugins/specweave/templates/iac/firebase/templates/main.tf.hbs +90 -0
  156. package/plugins/specweave/templates/iac/firebase/templates/outputs.tf.hbs +15 -0
  157. package/plugins/specweave/templates/iac/firebase/templates/providers.tf.hbs +23 -0
  158. package/plugins/specweave/templates/iac/firebase/templates/variables.tf.hbs +42 -0
  159. package/plugins/specweave/templates/iac/gcp-cloud-functions/defaults.json +26 -0
  160. package/plugins/specweave/templates/iac/gcp-cloud-functions/templates/README.md.hbs +299 -0
  161. package/plugins/specweave/templates/iac/gcp-cloud-functions/templates/environments/dev.tfvars.hbs +36 -0
  162. package/plugins/specweave/templates/iac/gcp-cloud-functions/templates/environments/prod.tfvars.hbs +48 -0
  163. package/plugins/specweave/templates/iac/gcp-cloud-functions/templates/environments/staging.tfvars.hbs +41 -0
  164. package/plugins/specweave/templates/iac/gcp-cloud-functions/templates/main.tf.hbs +192 -0
  165. package/plugins/specweave/templates/iac/gcp-cloud-functions/templates/outputs.tf.hbs +66 -0
  166. package/plugins/specweave/templates/iac/gcp-cloud-functions/templates/providers.tf.hbs +25 -0
  167. package/plugins/specweave/templates/iac/gcp-cloud-functions/templates/variables.tf.hbs +119 -0
  168. package/plugins/specweave/templates/iac/supabase/defaults.json +15 -0
  169. package/plugins/specweave/templates/iac/supabase/templates/README.md.hbs +46 -0
  170. package/plugins/specweave/templates/iac/supabase/templates/main.tf.hbs +50 -0
  171. package/plugins/specweave-github/agents/github-manager/AGENT.md +39 -7
  172. package/plugins/specweave-github/commands/specweave-github-create-issue.md +5 -5
  173. package/plugins/specweave-github/lib/CodeValidator.ts +1 -1
  174. package/plugins/specweave-github/lib/github-client-v2.js +29 -0
  175. package/plugins/specweave-github/lib/github-client-v2.ts +30 -0
  176. package/plugins/specweave-github/lib/task-sync.js +4 -0
  177. package/plugins/specweave-github/lib/task-sync.ts +7 -0
  178. package/plugins/specweave-jira/lib/enhanced-jira-sync.js +3 -3
  179. package/plugins/specweave-release/hooks/.specweave/logs/dora-tracking.log +2022 -0
  180. package/src/templates/CLAUDE.md.template +31 -0
  181. package/dist/src/core/living-docs/ThreeLayerSyncManager.d.ts +0 -116
  182. package/dist/src/core/living-docs/ThreeLayerSyncManager.d.ts.map +0 -1
  183. package/dist/src/core/living-docs/ThreeLayerSyncManager.js +0 -356
  184. package/dist/src/core/living-docs/ThreeLayerSyncManager.js.map +0 -1
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Task Counter Utility
3
+ *
4
+ * Accurately counts tasks in tasks.md by parsing task headings
5
+ * and checking for completion markers within each task's section.
6
+ *
7
+ * Fixes overcounting bug where multiple completion markers in same task
8
+ * were counted separately.
9
+ *
10
+ * Algorithm:
11
+ * 1. Split content by ## T- or ### T- headings (task markers)
12
+ * 2. For each task section, check if it contains ANY completion marker
13
+ * 3. Count task ONCE regardless of how many markers it has
14
+ *
15
+ * Supported completion markers:
16
+ * - [x] at line start (legacy checkbox format)
17
+ * - **Status**: [x] inline (legacy status format)
18
+ * - **Completed**: <date> (current format)
19
+ */
20
+ export class TaskCounter {
21
+ /**
22
+ * Count tasks in tasks.md content
23
+ *
24
+ * @param content - Raw tasks.md file content
25
+ * @returns Task counts with total, completed, and percentage
26
+ */
27
+ static countTasks(content) {
28
+ const tasks = this.parseTasks(content);
29
+ const total = tasks.length;
30
+ const completed = tasks.filter((t) => t.completed).length;
31
+ const percentage = total > 0 ? Math.floor((completed / total) * 100) : 0;
32
+ return { total, completed, percentage };
33
+ }
34
+ /**
35
+ * Parse tasks from tasks.md content
36
+ *
37
+ * Splits content into task sections and determines completion status
38
+ * for each task based on presence of completion markers.
39
+ *
40
+ * @param content - Raw tasks.md file content
41
+ * @returns Array of parsed tasks
42
+ */
43
+ static parseTasks(content) {
44
+ const tasks = [];
45
+ // Split by task headings (## T- or ### T-)
46
+ // Use regex to match heading pattern
47
+ const taskHeadingRegex = /^##+ (T-\d+[^:\n]*):?\s*(.*)$/gm;
48
+ let match;
49
+ const sections = [];
50
+ // Find all task headings and their positions
51
+ while ((match = taskHeadingRegex.exec(content)) !== null) {
52
+ const id = match[1].trim();
53
+ const title = match[2].trim();
54
+ const start = match.index;
55
+ // Close previous section
56
+ if (sections.length > 0) {
57
+ sections[sections.length - 1].end = start;
58
+ }
59
+ sections.push({ id, title, start });
60
+ }
61
+ // Close last section
62
+ if (sections.length > 0) {
63
+ sections[sections.length - 1].end = content.length;
64
+ }
65
+ // Parse each section
66
+ for (const section of sections) {
67
+ const sectionContent = content.substring(section.start, section.end ?? content.length);
68
+ const completed = this.isTaskCompleted(sectionContent);
69
+ tasks.push({
70
+ id: section.id,
71
+ title: section.title,
72
+ completed,
73
+ section: sectionContent,
74
+ });
75
+ }
76
+ return tasks;
77
+ }
78
+ /**
79
+ * Check if task section contains ANY completion marker
80
+ *
81
+ * Checks for:
82
+ * - [x] at line start (legacy)
83
+ * - **Status**: [x] inline (legacy)
84
+ * - **Completed**: <date> (current)
85
+ *
86
+ * @param sectionContent - Content of task section
87
+ * @returns true if task is completed
88
+ */
89
+ static isTaskCompleted(sectionContent) {
90
+ const completionPatterns = [
91
+ /^\[x\]/m, // [x] at line start
92
+ /\*\*Status\*\*:\s*\[x\]/i, // **Status**: [x]
93
+ /\*\*Completed\*\*:\s*\S/i, // **Completed**: <something>
94
+ ];
95
+ return completionPatterns.some((pattern) => pattern.test(sectionContent));
96
+ }
97
+ /**
98
+ * Get detailed task breakdown (for debugging)
99
+ *
100
+ * @param content - Raw tasks.md file content
101
+ * @returns Array of tasks with details
102
+ */
103
+ static getTaskDetails(content) {
104
+ return this.parseTasks(content);
105
+ }
106
+ }
107
+ //# sourceMappingURL=task-counter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"task-counter.js","sourceRoot":"","sources":["../../../../src/core/status-line/task-counter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;A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 * Autonomous Executor - Fully autonomous workflow execution
3
+ *
4
+ * Executes complete workflows without human intervention, with safety guardrails:
5
+ * - Max iteration limits
6
+ * - Infinite loop detection
7
+ * - Cost threshold enforcement
8
+ * - Checkpoint/recovery system
9
+ *
10
+ * Part of increment 0039: Ultra-Smart Next Command
11
+ *
12
+ * @module core/workflow/autonomous-executor
13
+ * @since v0.22.0
14
+ */
15
+ import { WorkflowPhase } from './types.js';
16
+ /**
17
+ * Autonomous execution configuration
18
+ */
19
+ export interface AutonomousConfig {
20
+ /** Maximum iterations before stopping (default: 50) */
21
+ maxIterations?: number;
22
+ /** Cost threshold in USD (default: $20) */
23
+ costThreshold?: number;
24
+ /** Enable checkpoint saving (default: true) */
25
+ enableCheckpoints?: boolean;
26
+ /** Maximum retries per command (default: 3) */
27
+ maxRetries?: number;
28
+ /** Stop on first error (default: false) */
29
+ stopOnError?: boolean;
30
+ /** Verbose logging (default: false) */
31
+ verbose?: boolean;
32
+ }
33
+ /**
34
+ * Autonomous execution result
35
+ */
36
+ export interface AutonomousResult {
37
+ /** Execution succeeded */
38
+ success: boolean;
39
+ /** Increment ID */
40
+ incrementId: string;
41
+ /** Total iterations */
42
+ iterations: number;
43
+ /** Commands executed */
44
+ commandsExecuted: string[];
45
+ /** Total cost (USD) */
46
+ totalCost: number;
47
+ /** Final phase */
48
+ finalPhase: WorkflowPhase;
49
+ /** Completion reason */
50
+ reason: string;
51
+ /** Error message if failed */
52
+ error?: string;
53
+ /** Checkpoint ID (for resume) */
54
+ checkpointId?: string;
55
+ }
56
+ /**
57
+ * Autonomous Executor - Fully autonomous workflow execution with safety guardrails
58
+ */
59
+ export declare class AutonomousExecutor {
60
+ private config;
61
+ private orchestrator;
62
+ private stateManager;
63
+ private costEstimator;
64
+ private commandInvoker;
65
+ constructor(config?: AutonomousConfig);
66
+ /**
67
+ * Execute workflow autonomously
68
+ *
69
+ * @param incrementId - Increment ID to execute
70
+ * @param resumeCheckpointId - Optional checkpoint to resume from
71
+ * @returns Autonomous execution result
72
+ */
73
+ execute(incrementId: string, resumeCheckpointId?: string): Promise<AutonomousResult>;
74
+ /**
75
+ * Execute single step in workflow
76
+ */
77
+ private executeStep;
78
+ /**
79
+ * Preflight check before execution
80
+ */
81
+ private preflightCheck;
82
+ /**
83
+ * Safety checks during execution
84
+ */
85
+ private checkSafety;
86
+ /**
87
+ * Check if workflow is complete
88
+ */
89
+ private isComplete;
90
+ /**
91
+ * Initialize execution state
92
+ */
93
+ private initializeState;
94
+ /**
95
+ * Resume from checkpoint
96
+ */
97
+ private resumeFromCheckpoint;
98
+ /**
99
+ * Save execution checkpoint
100
+ */
101
+ private saveCheckpoint;
102
+ /**
103
+ * Terminate execution and return result
104
+ */
105
+ private terminateExecution;
106
+ /**
107
+ * Log message (if verbose enabled)
108
+ */
109
+ private log;
110
+ }
111
+ //# sourceMappingURL=autonomous-executor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"autonomous-executor.d.ts","sourceRoot":"","sources":["../../../../src/core/workflow/autonomous-executor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAMH,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAG3C;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,uDAAuD;IACvD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,2CAA2C;IAC3C,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,+CAA+C;IAC/C,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,+CAA+C;IAC/C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,2CAA2C;IAC3C,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,uCAAuC;IACvC,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,0BAA0B;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,mBAAmB;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,uBAAuB;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,wBAAwB;IACxB,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,uBAAuB;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,kBAAkB;IAClB,UAAU,EAAE,aAAa,CAAC;IAC1B,wBAAwB;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,8BAA8B;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iCAAiC;IACjC,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAcD;;GAEG;AACH,qBAAa,kBAAkB;IAO3B,OAAO,CAAC,MAAM;IANhB,OAAO,CAAC,YAAY,CAAuB;IAC3C,OAAO,CAAC,YAAY,CAAe;IACnC,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,cAAc,CAAiB;gBAG7B,MAAM,GAAE,gBAAqB;IAgBvC;;;;;;OAMG;IACG,OAAO,CACX,WAAW,EAAE,MAAM,EACnB,kBAAkB,CAAC,EAAE,MAAM,GAC1B,OAAO,CAAC,gBAAgB,CAAC;IAqF5B;;OAEG;YACW,WAAW;IAuCzB;;OAEG;YACW,cAAc;IA0B5B;;OAEG;IACH,OAAO,CAAC,WAAW;IAoBnB;;OAEG;IACH,OAAO,CAAC,UAAU;IAclB;;OAEG;IACH,OAAO,CAAC,eAAe;IAWvB;;OAEG;YACW,oBAAoB;IAqBlC;;OAEG;YACW,cAAc;IAW5B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAsB1B;;OAEG;IACH,OAAO,CAAC,GAAG;CAKZ"}
@@ -0,0 +1,275 @@
1
+ /**
2
+ * Autonomous Executor - Fully autonomous workflow execution
3
+ *
4
+ * Executes complete workflows without human intervention, with safety guardrails:
5
+ * - Max iteration limits
6
+ * - Infinite loop detection
7
+ * - Cost threshold enforcement
8
+ * - Checkpoint/recovery system
9
+ *
10
+ * Part of increment 0039: Ultra-Smart Next Command
11
+ *
12
+ * @module core/workflow/autonomous-executor
13
+ * @since v0.22.0
14
+ */
15
+ import { WorkflowOrchestrator } from './workflow-orchestrator.js';
16
+ import { StateManager } from './state-manager.js';
17
+ import { CostEstimator } from './cost-estimator.js';
18
+ import { CommandInvoker } from './command-invoker.js';
19
+ import { WorkflowPhase } from './types.js';
20
+ import * as path from 'path';
21
+ /**
22
+ * Autonomous Executor - Fully autonomous workflow execution with safety guardrails
23
+ */
24
+ export class AutonomousExecutor {
25
+ constructor(config = {}) {
26
+ this.config = config;
27
+ this.orchestrator = new WorkflowOrchestrator();
28
+ this.stateManager = new StateManager();
29
+ this.costEstimator = new CostEstimator();
30
+ this.commandInvoker = new CommandInvoker();
31
+ // Apply defaults
32
+ this.config.maxIterations = config.maxIterations || 50;
33
+ this.config.costThreshold = config.costThreshold || 20.0;
34
+ this.config.enableCheckpoints = config.enableCheckpoints !== false;
35
+ this.config.maxRetries = config.maxRetries || 3;
36
+ this.config.stopOnError = config.stopOnError || false;
37
+ this.config.verbose = config.verbose || false;
38
+ }
39
+ /**
40
+ * Execute workflow autonomously
41
+ *
42
+ * @param incrementId - Increment ID to execute
43
+ * @param resumeCheckpointId - Optional checkpoint to resume from
44
+ * @returns Autonomous execution result
45
+ */
46
+ async execute(incrementId, resumeCheckpointId) {
47
+ this.log(`🚀 Starting autonomous execution for increment ${incrementId}`);
48
+ // Initialize state
49
+ let state;
50
+ if (resumeCheckpointId) {
51
+ state = await this.resumeFromCheckpoint(incrementId, resumeCheckpointId);
52
+ this.log(`📂 Resumed from checkpoint ${resumeCheckpointId} (iteration ${state.iteration})`);
53
+ }
54
+ else {
55
+ state = this.initializeState(incrementId);
56
+ this.log(`🆕 Starting fresh execution`);
57
+ }
58
+ // Pre-flight checks
59
+ const preflightResult = await this.preflightCheck(incrementId);
60
+ if (!preflightResult.passed) {
61
+ return {
62
+ success: false,
63
+ incrementId,
64
+ iterations: 0,
65
+ commandsExecuted: [],
66
+ totalCost: 0,
67
+ finalPhase: WorkflowPhase.UNKNOWN,
68
+ reason: `Preflight check failed: ${preflightResult.reason}`,
69
+ error: preflightResult.reason
70
+ };
71
+ }
72
+ // Main execution loop
73
+ try {
74
+ while (state.iteration < this.config.maxIterations) {
75
+ this.log(`\n📍 Iteration ${state.iteration + 1}/${this.config.maxIterations}`);
76
+ // Safety checks
77
+ const safetyCheck = this.checkSafety(state);
78
+ if (!safetyCheck.safe) {
79
+ return this.terminateExecution(state, safetyCheck.reason, false);
80
+ }
81
+ // Execute next step
82
+ const result = await this.executeStep(state);
83
+ // Handle execution result
84
+ if (!result.success) {
85
+ if (this.config.stopOnError) {
86
+ return this.terminateExecution(state, `Step failed: ${result.error}`, false);
87
+ }
88
+ else {
89
+ this.log(`⚠️ Step failed (continuing): ${result.error}`);
90
+ }
91
+ }
92
+ // Update state
93
+ state.iteration++;
94
+ state.phase = result.phase;
95
+ state.phaseHistory.push(result.phase);
96
+ if (result.command) {
97
+ state.commandsExecuted.push(result.command);
98
+ }
99
+ // Save checkpoint
100
+ if (this.config.enableCheckpoints) {
101
+ await this.saveCheckpoint(state);
102
+ }
103
+ // Check completion
104
+ if (this.isComplete(state)) {
105
+ return this.terminateExecution(state, 'Workflow completed successfully', true);
106
+ }
107
+ }
108
+ // Max iterations reached
109
+ return this.terminateExecution(state, `Max iterations (${this.config.maxIterations}) reached`, false);
110
+ }
111
+ catch (error) {
112
+ return this.terminateExecution(state, `Fatal error: ${error instanceof Error ? error.message : String(error)}`, false);
113
+ }
114
+ }
115
+ /**
116
+ * Execute single step in workflow
117
+ */
118
+ async executeStep(state) {
119
+ this.log(`🔍 Detecting current phase...`);
120
+ // Use orchestrator to detect phase and determine action
121
+ const result = await this.orchestrator.executeNext(state.incrementId, {
122
+ autonomous: true,
123
+ verbose: this.config.verbose
124
+ });
125
+ this.log(`📊 Phase: ${result.phase} (confidence: ${(result.confidence * 100).toFixed(0)}%)`);
126
+ this.log(`🎯 Action: ${result.action}`);
127
+ // Execute command if suggested
128
+ if (result.command && result.success) {
129
+ this.log(`⚡ Executing: ${result.command}`);
130
+ const invokeResult = await this.commandInvoker.invokeWithRetry(result.command, {
131
+ captureOutput: true
132
+ }, this.config.maxRetries);
133
+ if (!invokeResult.success) {
134
+ this.log(`❌ Command failed: ${invokeResult.error}`);
135
+ return {
136
+ ...result,
137
+ success: false,
138
+ error: invokeResult.error
139
+ };
140
+ }
141
+ this.log(`✅ Command completed in ${(invokeResult.executionTime / 1000).toFixed(1)}s`);
142
+ }
143
+ return result;
144
+ }
145
+ /**
146
+ * Preflight check before execution
147
+ */
148
+ async preflightCheck(incrementId) {
149
+ // Check increment exists
150
+ const incrementPath = path.join(process.cwd(), '.specweave/increments', incrementId);
151
+ const fs = await import('fs-extra');
152
+ if (!await fs.pathExists(incrementPath)) {
153
+ return {
154
+ passed: false,
155
+ reason: `Increment ${incrementId} not found`
156
+ };
157
+ }
158
+ // Estimate cost
159
+ const estimate = await this.costEstimator.estimateIncrement(incrementPath);
160
+ this.log(`💰 Estimated cost: $${estimate.estimatedCost.toFixed(2)} (${estimate.riskLevel.toUpperCase()})`);
161
+ if (estimate.estimatedCost > this.config.costThreshold) {
162
+ return {
163
+ passed: false,
164
+ reason: `Estimated cost ($${estimate.estimatedCost.toFixed(2)}) exceeds threshold ($${this.config.costThreshold})`
165
+ };
166
+ }
167
+ return { passed: true };
168
+ }
169
+ /**
170
+ * Safety checks during execution
171
+ */
172
+ checkSafety(state) {
173
+ // Check for infinite loop
174
+ if (this.stateManager.detectLoop(state.phaseHistory)) {
175
+ return {
176
+ safe: false,
177
+ reason: 'Infinite loop detected (same phase repeated 3+ times)'
178
+ };
179
+ }
180
+ // Check cost threshold
181
+ if (state.totalCost > this.config.costThreshold) {
182
+ return {
183
+ safe: false,
184
+ reason: `Cost threshold ($${this.config.costThreshold}) exceeded (current: $${state.totalCost.toFixed(2)})`
185
+ };
186
+ }
187
+ return { safe: true };
188
+ }
189
+ /**
190
+ * Check if workflow is complete
191
+ */
192
+ isComplete(state) {
193
+ // Completion phase reached
194
+ if (state.phase === WorkflowPhase.COMPLETION) {
195
+ return true;
196
+ }
197
+ // Unknown phase with no further actions (stuck)
198
+ if (state.phase === WorkflowPhase.UNKNOWN && state.iteration > 5) {
199
+ return true;
200
+ }
201
+ return false;
202
+ }
203
+ /**
204
+ * Initialize execution state
205
+ */
206
+ initializeState(incrementId) {
207
+ return {
208
+ incrementId,
209
+ iteration: 0,
210
+ phase: WorkflowPhase.UNKNOWN,
211
+ commandsExecuted: [],
212
+ totalCost: 0,
213
+ phaseHistory: []
214
+ };
215
+ }
216
+ /**
217
+ * Resume from checkpoint
218
+ */
219
+ async resumeFromCheckpoint(incrementId, checkpointId) {
220
+ const checkpoints = await this.stateManager.loadCheckpoints(incrementId);
221
+ const checkpoint = checkpoints.find(c => c.id === checkpointId);
222
+ if (!checkpoint) {
223
+ throw new Error(`Checkpoint ${checkpointId} not found`);
224
+ }
225
+ return {
226
+ incrementId,
227
+ iteration: checkpoint.iteration,
228
+ phase: checkpoint.phase,
229
+ commandsExecuted: checkpoint.actions,
230
+ totalCost: 0, // Reset cost tracking
231
+ phaseHistory: [checkpoint.phase]
232
+ };
233
+ }
234
+ /**
235
+ * Save execution checkpoint
236
+ */
237
+ async saveCheckpoint(state) {
238
+ await this.stateManager.saveCheckpoint({
239
+ id: `autonomous-${Date.now()}`,
240
+ timestamp: Date.now(),
241
+ incrementId: state.incrementId,
242
+ phase: state.phase,
243
+ iteration: state.iteration,
244
+ actions: state.commandsExecuted
245
+ });
246
+ }
247
+ /**
248
+ * Terminate execution and return result
249
+ */
250
+ terminateExecution(state, reason, success) {
251
+ this.log(`\n${success ? '✅' : '❌'} ${reason}`);
252
+ this.log(`📊 Final stats:`);
253
+ this.log(` - Iterations: ${state.iteration}`);
254
+ this.log(` - Commands: ${state.commandsExecuted.length}`);
255
+ this.log(` - Cost: $${state.totalCost.toFixed(2)}`);
256
+ return {
257
+ success,
258
+ incrementId: state.incrementId,
259
+ iterations: state.iteration,
260
+ commandsExecuted: state.commandsExecuted,
261
+ totalCost: state.totalCost,
262
+ finalPhase: state.phase,
263
+ reason
264
+ };
265
+ }
266
+ /**
267
+ * Log message (if verbose enabled)
268
+ */
269
+ log(message) {
270
+ if (this.config.verbose) {
271
+ console.log(message);
272
+ }
273
+ }
274
+ }
275
+ //# sourceMappingURL=autonomous-executor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"autonomous-executor.js","sourceRoot":"","sources":["../../../../src/core/workflow/autonomous-executor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,oBAAoB,EAA2B,MAAM,4BAA4B,CAAC;AAC3F,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAgB,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAwD7B;;GAEG;AACH,MAAM,OAAO,kBAAkB;IAM7B,YACU,SAA2B,EAAE;QAA7B,WAAM,GAAN,MAAM,CAAuB;QAErC,IAAI,CAAC,YAAY,GAAG,IAAI,oBAAoB,EAAE,CAAC;QAC/C,IAAI,CAAC,YAAY,GAAG,IAAI,YAAY,EAAE,CAAC;QACvC,IAAI,CAAC,aAAa,GAAG,IAAI,aAAa,EAAE,CAAC;QACzC,IAAI,CAAC,cAAc,GAAG,IAAI,cAAc,EAAE,CAAC;QAE3C,iBAAiB;QACjB,IAAI,CAAC,MAAM,CAAC,aAAa,GAAG,MAAM,CAAC,aAAa,IAAI,EAAE,CAAC;QACvD,IAAI,CAAC,MAAM,CAAC,aAAa,GAAG,MAAM,CAAC,aAAa,IAAI,IAAI,CAAC;QACzD,IAAI,CAAC,MAAM,CAAC,iBAAiB,GAAG,MAAM,CAAC,iBAAiB,KAAK,KAAK,CAAC;QACnE,IAAI,CAAC,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,IA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;IACL,CAAC;IAED;;OAEG;IACK,kBAAkB,CACxB,KAAqB,EACrB,MAAc,EACd,OAAgB;QAEhB,IAAI,CAAC,GAAG,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,MAAM,EAAE,CAAC,CAAC;QAC/C,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;QAC5B,IAAI,CAAC,GAAG,CAAC,oBAAoB,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC;QAChD,IAAI,CAAC,GAAG,CAAC,kBAAkB,KAAK,CAAC,gBAAgB,CAAC,MAAM,EAAE,CAAC,CAAC;QAC5D,IAAI,CAAC,GAAG,CAAC,eAAe,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAEtD,OAAO;YACL,OAAO;YACP,WAAW,EAAE,KAAK,CAAC,WAAW;YAC9B,UAAU,EAAE,KAAK,CAAC,SAAS;YAC3B,gBAAgB,EAAE,KAAK,CAAC,gBAAgB;YACxC,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,UAAU,EAAE,KAAK,CAAC,KAAK;YACvB,MAAM;SACP,CAAC;IACJ,CAAC;IAED;;OAEG;IACK,GAAG,CAAC,OAAe;QACzB,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACxB,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Backlog Scanner - Intelligent backlog scanning and ranking
3
+ *
4
+ * Scans .specweave/increments/_backlog/ directory and ranks items
5
+ * by priority, dependencies, and project match.
6
+ *
7
+ * Part of increment 0039: Ultra-Smart Next Command
8
+ *
9
+ * @module core/workflow/backlog-scanner
10
+ * @since v0.22.0
11
+ */
12
+ /**
13
+ * Backlog item metadata
14
+ */
15
+ export interface BacklogItem {
16
+ /** Increment ID */
17
+ incrementId: string;
18
+ /** Full path to spec.md */
19
+ specPath: string;
20
+ /** Title */
21
+ title: string;
22
+ /** Priority (P0, P1, P2, P3) */
23
+ priority: string;
24
+ /** Project (if multi-project) */
25
+ project?: string;
26
+ /** Dependencies (other increment IDs) */
27
+ dependencies: string[];
28
+ /** Estimated effort (hours or weeks) */
29
+ estimatedEffort?: string;
30
+ /** Creation date */
31
+ created?: string;
32
+ }
33
+ /**
34
+ * Ranked backlog item with score
35
+ */
36
+ export interface RankedBacklogItem extends BacklogItem {
37
+ /** Ranking score (higher = better) */
38
+ score: number;
39
+ /** Ranking explanation */
40
+ reason: string;
41
+ }
42
+ /**
43
+ * Backlog recommendation
44
+ */
45
+ export interface BacklogRecommendation {
46
+ /** Recommended items (top N) */
47
+ items: RankedBacklogItem[];
48
+ /** Total backlog size */
49
+ totalItems: number;
50
+ /** Explanation */
51
+ summary: string;
52
+ }
53
+ /**
54
+ * Backlog Scanner - Scan and rank backlog items
55
+ */
56
+ export declare class BacklogScanner {
57
+ private backlogDir;
58
+ constructor(rootDir?: string);
59
+ /**
60
+ * Scan backlog directory
61
+ *
62
+ * @returns Array of backlog items
63
+ */
64
+ scanBacklog(): Promise<BacklogItem[]>;
65
+ /**
66
+ * Parse backlog item from spec.md
67
+ */
68
+ private parseBacklogItem;
69
+ /**
70
+ * Rank backlog items by priority, dependencies, and project match
71
+ *
72
+ * Ranking algorithm:
73
+ * - Priority: P0=10, P1=7, P2=5, P3=3
74
+ * - Dependencies met: +5
75
+ * - Project match: +3
76
+ * - Recently created: +2
77
+ *
78
+ * @param items - Backlog items to rank
79
+ * @param currentProject - Current project (for filtering)
80
+ * @param completedIncrements - List of completed increment IDs
81
+ * @returns Ranked items (sorted by score descending)
82
+ */
83
+ rankItems(items: BacklogItem[], currentProject?: string, completedIncrements?: string[]): RankedBacklogItem[];
84
+ /**
85
+ * Get top N recommendations
86
+ *
87
+ * @param n - Number of recommendations (default: 3)
88
+ * @param currentProject - Current project filter
89
+ * @param completedIncrements - Completed increments
90
+ * @returns Backlog recommendations
91
+ */
92
+ getTopRecommendations(n?: number, currentProject?: string, completedIncrements?: string[]): Promise<BacklogRecommendation>;
93
+ }
94
+ //# sourceMappingURL=backlog-scanner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backlog-scanner.d.ts","sourceRoot":"","sources":["../../../../src/core/workflow/backlog-scanner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAMH;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,mBAAmB;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,2BAA2B;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,gCAAgC;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,iCAAiC;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,yCAAyC;IACzC,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,wCAAwC;IACxC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,oBAAoB;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAkB,SAAQ,WAAW;IACpD,sCAAsC;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,0BAA0B;IAC1B,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,gCAAgC;IAChC,KAAK,EAAE,iBAAiB,EAAE,CAAC;IAC3B,yBAAyB;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,kBAAkB;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,UAAU,CAAS;gBAEf,OAAO,GAAE,MAAsB;IAI3C;;;;OAIG;IACG,WAAW,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;IAmC3C;;OAEG;YACW,gBAAgB;IA2B9B;;;;;;;;;;;;;OA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