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,222 @@
1
+ /**
2
+ * Cost Estimator - AI execution cost estimation
3
+ *
4
+ * Estimates the cost of autonomous workflow execution based on
5
+ * AI API calls, task count, and complexity.
6
+ *
7
+ * Part of increment 0039: Ultra-Smart Next Command
8
+ *
9
+ * @module core/workflow/cost-estimator
10
+ * @since v0.22.0
11
+ */
12
+ import * as fs from 'fs-extra';
13
+ import * as path from 'path';
14
+ /**
15
+ * Risk level for cost
16
+ */
17
+ export var RiskLevel;
18
+ (function (RiskLevel) {
19
+ /** < $1 */
20
+ RiskLevel["LOW"] = "low";
21
+ /** $1 - $5 */
22
+ RiskLevel["MEDIUM"] = "medium";
23
+ /** $5 - $20 */
24
+ RiskLevel["HIGH"] = "high";
25
+ /** > $20 */
26
+ RiskLevel["CRITICAL"] = "critical";
27
+ })(RiskLevel || (RiskLevel = {}));
28
+ /**
29
+ * Cost Estimator - Estimate autonomous execution costs
30
+ */
31
+ export class CostEstimator {
32
+ constructor(config = {}) {
33
+ this.costPerCall = config.costPerCall || 0.01;
34
+ this.lowThreshold = config.lowThreshold || 1.0;
35
+ this.mediumThreshold = config.mediumThreshold || 5.0;
36
+ this.highThreshold = config.highThreshold || 20.0;
37
+ }
38
+ /**
39
+ * Estimate cost for increment execution
40
+ *
41
+ * @param incrementPath - Path to increment directory
42
+ * @returns Cost estimate
43
+ */
44
+ async estimateIncrement(incrementPath) {
45
+ const breakdown = [];
46
+ let totalCost = 0;
47
+ // Planning phase: 2 AI calls (Architect + test-aware-planner)
48
+ const planningCost = this.estimatePlanning(incrementPath);
49
+ breakdown.push(planningCost);
50
+ totalCost += planningCost.cost;
51
+ // Execution phase: Based on task count
52
+ const executionCost = await this.estimateExecution(incrementPath);
53
+ breakdown.push(executionCost);
54
+ totalCost += executionCost.cost;
55
+ // Validation phase: 1 AI call (PM validation)
56
+ const validationCost = this.estimateValidation();
57
+ breakdown.push(validationCost);
58
+ totalCost += validationCost.cost;
59
+ // QA phase: 1 AI call (judge LLM)
60
+ const qaCost = this.estimateQA();
61
+ breakdown.push(qaCost);
62
+ totalCost += qaCost.cost;
63
+ // Determine risk level
64
+ const riskLevel = this.determineRiskLevel(totalCost);
65
+ // Calculate confidence based on data availability
66
+ const confidence = await this.calculateConfidence(incrementPath);
67
+ return {
68
+ estimatedCost: totalCost,
69
+ breakdown,
70
+ riskLevel,
71
+ explanation: this.generateExplanation(totalCost, riskLevel, breakdown),
72
+ confidence
73
+ };
74
+ }
75
+ /**
76
+ * Estimate planning cost
77
+ */
78
+ estimatePlanning(incrementPath) {
79
+ // Planning = Architect + test-aware-planner = 2 calls
80
+ return {
81
+ phase: 'Planning',
82
+ aiCalls: 2,
83
+ cost: 2 * this.costPerCall
84
+ };
85
+ }
86
+ /**
87
+ * Estimate execution cost based on task count
88
+ */
89
+ async estimateExecution(incrementPath) {
90
+ const tasksPath = path.join(incrementPath, 'tasks.md');
91
+ let taskCount = 0;
92
+ // Try to count tasks from tasks.md
93
+ if (await fs.pathExists(tasksPath)) {
94
+ try {
95
+ const content = await fs.readFile(tasksPath, 'utf-8');
96
+ // Count task headers (#### T-XXX:)
97
+ const taskMatches = content.match(/^####\s+T-\d+:/gm);
98
+ taskCount = taskMatches ? taskMatches.length : 0;
99
+ }
100
+ catch (error) {
101
+ // If can't read tasks, estimate based on spec
102
+ taskCount = 10; // Default estimate
103
+ }
104
+ }
105
+ else {
106
+ // No tasks.md yet, estimate from spec.md
107
+ taskCount = await this.estimateTasksFromSpec(incrementPath);
108
+ }
109
+ // Assume 3 AI calls per task (avg: simple=1, medium=3, complex=5)
110
+ const aiCalls = taskCount * 3;
111
+ return {
112
+ phase: 'Execution',
113
+ aiCalls,
114
+ cost: aiCalls * this.costPerCall
115
+ };
116
+ }
117
+ /**
118
+ * Estimate task count from spec.md
119
+ */
120
+ async estimateTasksFromSpec(incrementPath) {
121
+ const specPath = path.join(incrementPath, 'spec.md');
122
+ if (!await fs.pathExists(specPath)) {
123
+ return 10; // Default estimate
124
+ }
125
+ try {
126
+ const content = await fs.readFile(specPath, 'utf-8');
127
+ // Count acceptance criteria as rough proxy for tasks
128
+ const acMatches = content.match(/^- \[.\] AC-/gm);
129
+ const acCount = acMatches ? acMatches.length : 0;
130
+ // Rough heuristic: 2 ACs ≈ 1 task
131
+ return Math.max(Math.floor(acCount / 2), 5);
132
+ }
133
+ catch (error) {
134
+ return 10;
135
+ }
136
+ }
137
+ /**
138
+ * Estimate validation cost
139
+ */
140
+ estimateValidation() {
141
+ // Validation = 1 PM validation call
142
+ return {
143
+ phase: 'Validation',
144
+ aiCalls: 1,
145
+ cost: 1 * this.costPerCall
146
+ };
147
+ }
148
+ /**
149
+ * Estimate QA cost
150
+ */
151
+ estimateQA() {
152
+ // QA = 1 judge LLM call
153
+ return {
154
+ phase: 'QA',
155
+ aiCalls: 1,
156
+ cost: 1 * this.costPerCall
157
+ };
158
+ }
159
+ /**
160
+ * Determine risk level based on total cost
161
+ */
162
+ determineRiskLevel(cost) {
163
+ if (cost < this.lowThreshold) {
164
+ return RiskLevel.LOW;
165
+ }
166
+ else if (cost < this.mediumThreshold) {
167
+ return RiskLevel.MEDIUM;
168
+ }
169
+ else if (cost < this.highThreshold) {
170
+ return RiskLevel.HIGH;
171
+ }
172
+ else {
173
+ return RiskLevel.CRITICAL;
174
+ }
175
+ }
176
+ /**
177
+ * Calculate confidence in estimate
178
+ */
179
+ async calculateConfidence(incrementPath) {
180
+ // Higher confidence if tasks.md exists
181
+ const tasksExists = await fs.pathExists(path.join(incrementPath, 'tasks.md'));
182
+ const planExists = await fs.pathExists(path.join(incrementPath, 'plan.md'));
183
+ const specExists = await fs.pathExists(path.join(incrementPath, 'spec.md'));
184
+ if (tasksExists && planExists) {
185
+ return 0.9; // High confidence (tasks are defined)
186
+ }
187
+ else if (specExists) {
188
+ return 0.6; // Medium confidence (only spec exists)
189
+ }
190
+ else {
191
+ return 0.3; // Low confidence (estimating blindly)
192
+ }
193
+ }
194
+ /**
195
+ * Generate human-readable explanation
196
+ */
197
+ generateExplanation(totalCost, riskLevel, breakdown) {
198
+ const parts = [];
199
+ parts.push(`Estimated cost: $${totalCost.toFixed(2)} (Risk: ${riskLevel.toUpperCase()})`);
200
+ parts.push('\nBreakdown:');
201
+ breakdown.forEach(item => {
202
+ parts.push(` - ${item.phase}: ${item.aiCalls} AI calls ($${item.cost.toFixed(2)})`);
203
+ });
204
+ if (riskLevel === RiskLevel.CRITICAL) {
205
+ parts.push('\n⚠️ CRITICAL: Cost exceeds $20. Consider manual execution or splitting work.');
206
+ }
207
+ else if (riskLevel === RiskLevel.HIGH) {
208
+ parts.push('\n⚠️ HIGH: Cost is significant ($5-$20). Confirm before proceeding.');
209
+ }
210
+ return parts.join('\n');
211
+ }
212
+ /**
213
+ * Check if cost exceeds threshold
214
+ *
215
+ * @param estimate - Cost estimate
216
+ * @returns True if cost exceeds HIGH threshold
217
+ */
218
+ checkThreshold(estimate) {
219
+ return estimate.riskLevel === RiskLevel.HIGH || estimate.riskLevel === RiskLevel.CRITICAL;
220
+ }
221
+ }
222
+ //# sourceMappingURL=cost-estimator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cost-estimator.js","sourceRoot":"","sources":["../../../../src/core/workflow/cost-estimator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AA8B7B;;GAEG;AACH,MAAM,CAAN,IA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,GAAG,CAAC,CAAC,sCAAsC;QACpD,CAAC;IACH,CAAC;IAED;;OAEG;IACK,mBAAmB,CACzB,SAAiB,EACjB,SAAoB,EACpB,SAA0B;QAE1B,MAAM,KAAK,GAAa,EAAE,CAAC;QAE3B,KAAK,CAAC,IAAI,CAAC,oBAAoB,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,SAAS,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;QAC1F,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAE3B,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YACvB,KAAK,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,OAAO,eAAe,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QACvF,CAAC,CAAC,CAAC;QAEH,IAAI,SAAS,KAAK,SAAS,CAAC,QAAQ,EAAE,CAAC;YACrC,KAAK,CAAC,IAAI,CAAC,gFAAgF,CAAC,CAAC;QAC/F,CAAC;aAAM,IAAI,SAAS,KAAK,SAAS,CAAC,IAAI,EAAE,CAAC;YACxC,KAAK,CAAC,IAAI,CAAC,sEAAsE,CAAC,CAAC;QACrF,CAAC;QAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAED;;;;;OAKG;IACH,cAAc,CAAC,QAAsB;QACnC,OAAO,QAAQ,CAAC,SAAS,KAAK,SAAS,CAAC,IAAI,IAAI,QAAQ,CAAC,SAAS,KAAK,SAAS,CAAC,QAAQ,CAAC;IAC5F,CAAC;CACF"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Workflow Orchestration Module
3
+ *
4
+ * Provides intelligent workflow orchestration for SpecWeave,
5
+ * enabling autonomous and semi-autonomous workflow execution.
6
+ *
7
+ * Part of increment 0039: Ultra-Smart Next Command
8
+ *
9
+ * @module core/workflow
10
+ * @since v0.22.0
11
+ */
12
+ export { WorkflowOrchestrator, WorkflowExecuteOptions, WorkflowExecutionResult } from './workflow-orchestrator.js';
13
+ export { AutonomousExecutor, AutonomousConfig, AutonomousResult } from './autonomous-executor.js';
14
+ export { PhaseDetector } from './phase-detector.js';
15
+ export { WorkflowPhase, PhaseDetectionResult, DetectionContext, PhaseEvidence } from './types.js';
16
+ export { BacklogScanner, BacklogItem, RankedBacklogItem, BacklogRecommendation } from './backlog-scanner.js';
17
+ export { CostEstimator, CostEstimate, CostBreakdown, RiskLevel, CostEstimatorConfig } from './cost-estimator.js';
18
+ export { CommandInvoker, InvokeOptions, InvokeResult, ErrorSeverity } from './command-invoker.js';
19
+ export { StateManager, Checkpoint } from './state-manager.js';
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/core/workflow/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AACnH,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAGlG,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,gBAAgB,EAChB,aAAa,EACd,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,cAAc,EACd,WAAW,EACX,iBAAiB,EACjB,qBAAqB,EACtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,aAAa,EACb,YAAY,EACZ,aAAa,EACb,SAAS,EACT,mBAAmB,EACpB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAClG,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Workflow Orchestration Module
3
+ *
4
+ * Provides intelligent workflow orchestration for SpecWeave,
5
+ * enabling autonomous and semi-autonomous workflow execution.
6
+ *
7
+ * Part of increment 0039: Ultra-Smart Next Command
8
+ *
9
+ * @module core/workflow
10
+ * @since v0.22.0
11
+ */
12
+ // Core orchestration
13
+ export { WorkflowOrchestrator } from './workflow-orchestrator.js';
14
+ export { AutonomousExecutor } from './autonomous-executor.js';
15
+ // Phase detection
16
+ export { PhaseDetector } from './phase-detector.js';
17
+ export { WorkflowPhase } from './types.js';
18
+ // Intelligence
19
+ export { BacklogScanner } from './backlog-scanner.js';
20
+ export { CostEstimator, RiskLevel } from './cost-estimator.js';
21
+ // Execution infrastructure
22
+ export { CommandInvoker, ErrorSeverity } from './command-invoker.js';
23
+ export { StateManager } from './state-manager.js';
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/core/workflow/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,qBAAqB;AACrB,OAAO,EAAE,oBAAoB,EAAmD,MAAM,4BAA4B,CAAC;AACnH,OAAO,EAAE,kBAAkB,EAAsC,MAAM,0BAA0B,CAAC;AAElG,kBAAkB;AAClB,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EACL,aAAa,EAId,MAAM,YAAY,CAAC;AAEpB,eAAe;AACf,OAAO,EACL,cAAc,EAIf,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,aAAa,EAGb,SAAS,EAEV,MAAM,qBAAqB,CAAC;AAE7B,2BAA2B;AAC3B,OAAO,EAAE,cAAc,EAA+B,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAClG,OAAO,EAAE,YAAY,EAAc,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,107 @@
1
+ /**
2
+ * State Manager - Workflow state tracking and checkpointing
3
+ *
4
+ * Manages workflow state, checkpoints, and recovery for autonomous execution.
5
+ *
6
+ * Part of increment 0039: Ultra-Smart Next Command
7
+ *
8
+ * @module core/workflow/state-manager
9
+ * @since v0.22.0
10
+ */
11
+ import { WorkflowPhase } from './types.js';
12
+ /**
13
+ * Checkpoint - Saved workflow state
14
+ */
15
+ export interface Checkpoint {
16
+ /** Unique checkpoint ID */
17
+ id: string;
18
+ /** Timestamp */
19
+ timestamp: number;
20
+ /** Increment ID */
21
+ incrementId: string;
22
+ /** Current workflow phase */
23
+ phase: WorkflowPhase;
24
+ /** Iteration count */
25
+ iteration: number;
26
+ /** Actions taken */
27
+ actions: string[];
28
+ /** Last successful action */
29
+ lastAction?: string;
30
+ /** Custom metadata */
31
+ metadata?: Record<string, any>;
32
+ }
33
+ /**
34
+ * State transition record
35
+ */
36
+ export interface StateTransition {
37
+ /** From phase */
38
+ from: WorkflowPhase;
39
+ /** To phase */
40
+ to: WorkflowPhase;
41
+ /** Timestamp */
42
+ timestamp: number;
43
+ /** Action that caused transition */
44
+ action: string;
45
+ /** Success flag */
46
+ success: boolean;
47
+ }
48
+ /**
49
+ * State Manager - Track workflow state and checkpoints
50
+ */
51
+ export declare class StateManager {
52
+ private checkpointDir;
53
+ private maxCheckpoints;
54
+ constructor(checkpointDir?: string, maxCheckpoints?: number);
55
+ /**
56
+ * Save checkpoint
57
+ *
58
+ * @param checkpoint - Checkpoint data
59
+ */
60
+ saveCheckpoint(checkpoint: Checkpoint): Promise<void>;
61
+ /**
62
+ * Load checkpoints for increment
63
+ *
64
+ * @param incrementId - Increment ID
65
+ * @returns Array of checkpoints (sorted by timestamp, newest first)
66
+ */
67
+ loadCheckpoints(incrementId: string): Promise<Checkpoint[]>;
68
+ /**
69
+ * Get latest checkpoint for increment
70
+ *
71
+ * @param incrementId - Increment ID
72
+ * @returns Latest checkpoint or null
73
+ */
74
+ getLatestCheckpoint(incrementId: string): Promise<Checkpoint | null>;
75
+ /**
76
+ * Delete checkpoint
77
+ *
78
+ * @param incrementId - Increment ID
79
+ * @param checkpointId - Checkpoint ID
80
+ */
81
+ deleteCheckpoint(incrementId: string, checkpointId: string): Promise<void>;
82
+ /**
83
+ * Cleanup old checkpoints (keep only N most recent)
84
+ *
85
+ * @param incrementId - Increment ID
86
+ */
87
+ private cleanupOldCheckpoints;
88
+ /**
89
+ * Detect infinite loop in phase history
90
+ *
91
+ * Checks if the same phase has been visited too many times in a row.
92
+ *
93
+ * @param phaseHistory - Recent phase history
94
+ * @param threshold - Max same-phase repetitions (default: 3)
95
+ * @returns True if loop detected
96
+ */
97
+ detectLoop(phaseHistory: WorkflowPhase[], threshold?: number): boolean;
98
+ /**
99
+ * Record state transition
100
+ *
101
+ * (For now, this is a no-op - will be used for analytics/debugging)
102
+ *
103
+ * @param transition - State transition record
104
+ */
105
+ recordTransition(transition: StateTransition): void;
106
+ }
107
+ //# sourceMappingURL=state-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state-manager.d.ts","sourceRoot":"","sources":["../../../../src/core/workflow/state-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,2BAA2B;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,gBAAgB;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,mBAAmB;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,6BAA6B;IAC7B,KAAK,EAAE,aAAa,CAAC;IACrB,sBAAsB;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,oBAAoB;IACpB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,6BAA6B;IAC7B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,sBAAsB;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,iBAAiB;IACjB,IAAI,EAAE,aAAa,CAAC;IACpB,eAAe;IACf,EAAE,EAAE,aAAa,CAAC;IAClB,gBAAgB;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,oCAAoC;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,mBAAmB;IACnB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;GAEG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,cAAc,CAAS;gBAEnB,aAAa,CAAC,EAAE,MAAM,EAAE,cAAc,GAAE,MAAW;IAK/D;;;;OAIG;IACG,cAAc,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAc3D;;;;;OAKG;IACG,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IAyBjE;;;;;OAKG;IACG,mBAAmB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IAK1E;;;;;OAKG;IACG,gBAAgB,CAAC,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAWhF;;;;OAIG;YACW,qBAAqB;IAYnC;;;;;;;;OAQG;IACH,UAAU,CAAC,YAAY,EAAE,aAAa,EAAE,EAAE,SAAS,GAAE,MAAU,GAAG,OAAO;IAYzE;;;;;;OAMG;IACH,gBAAgB,CAAC,UAAU,EAAE,eAAe,GAAG,IAAI;CAKpD"}
@@ -0,0 +1,126 @@
1
+ /**
2
+ * State Manager - Workflow state tracking and checkpointing
3
+ *
4
+ * Manages workflow state, checkpoints, and recovery for autonomous execution.
5
+ *
6
+ * Part of increment 0039: Ultra-Smart Next Command
7
+ *
8
+ * @module core/workflow/state-manager
9
+ * @since v0.22.0
10
+ */
11
+ import * as fs from 'fs-extra';
12
+ import * as path from 'path';
13
+ /**
14
+ * State Manager - Track workflow state and checkpoints
15
+ */
16
+ export class StateManager {
17
+ constructor(checkpointDir, maxCheckpoints = 10) {
18
+ this.checkpointDir = checkpointDir || '.specweave/checkpoints';
19
+ this.maxCheckpoints = maxCheckpoints;
20
+ }
21
+ /**
22
+ * Save checkpoint
23
+ *
24
+ * @param checkpoint - Checkpoint data
25
+ */
26
+ async saveCheckpoint(checkpoint) {
27
+ await fs.ensureDir(this.checkpointDir);
28
+ const checkpointPath = path.join(this.checkpointDir, `${checkpoint.incrementId}-${checkpoint.id}.json`);
29
+ await fs.writeJson(checkpointPath, checkpoint, { spaces: 2 });
30
+ // Cleanup old checkpoints
31
+ await this.cleanupOldCheckpoints(checkpoint.incrementId);
32
+ }
33
+ /**
34
+ * Load checkpoints for increment
35
+ *
36
+ * @param incrementId - Increment ID
37
+ * @returns Array of checkpoints (sorted by timestamp, newest first)
38
+ */
39
+ async loadCheckpoints(incrementId) {
40
+ if (!await fs.pathExists(this.checkpointDir)) {
41
+ return [];
42
+ }
43
+ const files = await fs.readdir(this.checkpointDir);
44
+ const checkpointFiles = files.filter(f => f.startsWith(`${incrementId}-`) && f.endsWith('.json'));
45
+ const checkpoints = [];
46
+ for (const file of checkpointFiles) {
47
+ try {
48
+ const checkpoint = await fs.readJson(path.join(this.checkpointDir, file));
49
+ checkpoints.push(checkpoint);
50
+ }
51
+ catch (error) {
52
+ // Skip corrupted checkpoints
53
+ console.warn(`Failed to load checkpoint ${file}:`, error);
54
+ }
55
+ }
56
+ // Sort by timestamp (newest first)
57
+ return checkpoints.sort((a, b) => b.timestamp - a.timestamp);
58
+ }
59
+ /**
60
+ * Get latest checkpoint for increment
61
+ *
62
+ * @param incrementId - Increment ID
63
+ * @returns Latest checkpoint or null
64
+ */
65
+ async getLatestCheckpoint(incrementId) {
66
+ const checkpoints = await this.loadCheckpoints(incrementId);
67
+ return checkpoints[0] || null;
68
+ }
69
+ /**
70
+ * Delete checkpoint
71
+ *
72
+ * @param incrementId - Increment ID
73
+ * @param checkpointId - Checkpoint ID
74
+ */
75
+ async deleteCheckpoint(incrementId, checkpointId) {
76
+ const checkpointPath = path.join(this.checkpointDir, `${incrementId}-${checkpointId}.json`);
77
+ if (await fs.pathExists(checkpointPath)) {
78
+ await fs.remove(checkpointPath);
79
+ }
80
+ }
81
+ /**
82
+ * Cleanup old checkpoints (keep only N most recent)
83
+ *
84
+ * @param incrementId - Increment ID
85
+ */
86
+ async cleanupOldCheckpoints(incrementId) {
87
+ const checkpoints = await this.loadCheckpoints(incrementId);
88
+ if (checkpoints.length > this.maxCheckpoints) {
89
+ const toDelete = checkpoints.slice(this.maxCheckpoints);
90
+ for (const checkpoint of toDelete) {
91
+ await this.deleteCheckpoint(incrementId, checkpoint.id);
92
+ }
93
+ }
94
+ }
95
+ /**
96
+ * Detect infinite loop in phase history
97
+ *
98
+ * Checks if the same phase has been visited too many times in a row.
99
+ *
100
+ * @param phaseHistory - Recent phase history
101
+ * @param threshold - Max same-phase repetitions (default: 3)
102
+ * @returns True if loop detected
103
+ */
104
+ detectLoop(phaseHistory, threshold = 3) {
105
+ if (phaseHistory.length < threshold) {
106
+ return false;
107
+ }
108
+ // Check if last N phases are all the same
109
+ const recentPhases = phaseHistory.slice(-threshold);
110
+ const uniquePhases = new Set(recentPhases);
111
+ return uniquePhases.size === 1;
112
+ }
113
+ /**
114
+ * Record state transition
115
+ *
116
+ * (For now, this is a no-op - will be used for analytics/debugging)
117
+ *
118
+ * @param transition - State transition record
119
+ */
120
+ recordTransition(transition) {
121
+ // TODO: Implement transition logging
122
+ // For now, just log to console
123
+ console.log(`State transition: ${transition.from} → ${transition.to} (${transition.action})`);
124
+ }
125
+ }
126
+ //# sourceMappingURL=state-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state-manager.js","sourceRoot":"","sources":["../../../../src/core/workflow/state-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAyC7B;;GAEG;AACH,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AAK,MAAM,UAAU,IAAI,QAAQ,EAAE,CAAC;gBAClC,MAAM,IAAI,CAAC,gBAAgB,CAAC,WAAW,EAAE,UAAU,CAAC,EAAE,CAAC,CAAC;YAC1D,CAAC;QACH,CAAC;IACH,CAAC;IAED;;;;;;;;OAQG;IACH,UAAU,CAAC,YAA6B,EAAE,YAAoB,CAAC;QAC7D,IAAI,YAAY,CAAC,MAAM,GAAG,SAAS,EAAE,CAAC;YACpC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,0CAA0C;QAC1C,MAAM,YAAY,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,CAAC;QACpD,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,YAAY,CAAC,CAAC;QAE3C,OAAO,YAAY,CAAC,IAAI,KAAK,CAAC,CAAC;IACjC,CAAC;IAED;;;;;;OAMG;IACH,gBAAgB,CAAC,UAA2B;QAC1C,qCAAqC;QACrC,+BAA+B;QAC/B,OAAO,CAAC,GAAG,CAAC,qBAAqB,UAAU,CAAC,IAAI,MAAM,UAAU,CAAC,EAAE,KAAK,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC;IAChG,CAAC;CACF"}
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Workflow Orchestrator - Core orchestration logic for /specweave:next
3
+ *
4
+ * Coordinates workflow execution by detecting current phase and
5
+ * invoking appropriate commands.
6
+ *
7
+ * Part of increment 0039: Ultra-Smart Next Command
8
+ *
9
+ * @module core/workflow/workflow-orchestrator
10
+ * @since v0.22.0
11
+ */
12
+ import { WorkflowPhase } from './types.js';
13
+ /**
14
+ * Workflow execution options
15
+ */
16
+ export interface WorkflowExecuteOptions {
17
+ /** Auto-approve actions without prompting (dangerous!) */
18
+ autonomous?: boolean;
19
+ /** Show detailed execution information */
20
+ verbose?: boolean;
21
+ /** Dry-run mode (preview actions without executing) */
22
+ dryRun?: boolean;
23
+ /** Force execution even with low confidence */
24
+ force?: boolean;
25
+ }
26
+ /**
27
+ * Workflow execution result
28
+ */
29
+ export interface WorkflowExecutionResult {
30
+ /** Execution succeeded */
31
+ success: boolean;
32
+ /** Phase that was detected */
33
+ phase: WorkflowPhase;
34
+ /** Confidence score for phase detection */
35
+ confidence: number;
36
+ /** Action that was taken */
37
+ action?: string;
38
+ /** Command that was invoked */
39
+ command?: string;
40
+ /** Error message if failed */
41
+ error?: string;
42
+ /** Human-readable explanation */
43
+ reasoning?: string;
44
+ /** Phase detection evidence */
45
+ evidence?: string[];
46
+ }
47
+ /**
48
+ * Workflow Orchestrator - Coordinates intelligent workflow execution
49
+ *
50
+ * This is a simplified initial implementation focusing on core phase detection.
51
+ * Full autonomous execution will be added in future tasks.
52
+ */
53
+ export declare class WorkflowOrchestrator {
54
+ private phaseDetector;
55
+ private activeIncrementManager;
56
+ constructor();
57
+ /**
58
+ * Execute next step in workflow (interactive mode)
59
+ *
60
+ * Detects current phase and suggests/executes appropriate action.
61
+ *
62
+ * @param incrementId - Optional increment ID (auto-detects if not provided)
63
+ * @param options - Execution options
64
+ * @returns Workflow execution result
65
+ */
66
+ executeNext(incrementId?: string, options?: WorkflowExecuteOptions): Promise<WorkflowExecutionResult>;
67
+ /**
68
+ * Format reasoning from phase detection result
69
+ */
70
+ private formatReasoning;
71
+ /**
72
+ * Detect current workflow phase for increment
73
+ *
74
+ * @param incrementId - Increment ID (auto-detects if not provided)
75
+ * @returns Phase detection result
76
+ */
77
+ private detectCurrentPhase;
78
+ /**
79
+ * Auto-detect active increment
80
+ *
81
+ * @returns Increment ID or throws if none found
82
+ */
83
+ private detectActiveIncrement;
84
+ /**
85
+ * Determine action based on phase and confidence
86
+ *
87
+ * @param detection - Phase detection result
88
+ * @param options - Execution options
89
+ * @returns Suggested action
90
+ */
91
+ private determineAction;
92
+ }
93
+ //# sourceMappingURL=workflow-orchestrator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-orchestrator.d.ts","sourceRoot":"","sources":["../../../../src/core/workflow/workflow-orchestrator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,aAAa,EAA0C,MAAM,YAAY,CAAC;AAGnF;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,0DAA0D;IAC1D,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,0CAA0C;IAC1C,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,uDAAuD;IACvD,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,+CAA+C;IAC/C,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,0BAA0B;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,8BAA8B;IAC9B,KAAK,EAAE,aAAa,CAAC;IACrB,2CAA2C;IAC3C,UAAU,EAAE,MAAM,CAAC;IACnB,4BAA4B;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,+BAA+B;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,8BAA8B;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iCAAiC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+BAA+B;IAC/B,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAED;;;;;GAKG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,sBAAsB,CAAyB;;IAOvD;;;;;;;;OAQG;IACG,WAAW,CACf,WAAW,CAAC,EAAE,MAAM,EACpB,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,uBAAuB,CAAC;IA0CnC;;OAEG;IACH,OAAO,CAAC,eAAe;IAmBvB;;;;;OAKG;YACW,kBAAkB;IAiBhC;;;;OAIG;YACW,qBAAqB;IAiBnC;;;;;;OAMG;IACH,OAAO,CAAC,eAAe;CAuExB"}