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.
- package/CLAUDE.md +211 -0
- package/README.md +5 -5
- package/bin/specweave.js +5 -8
- package/dist/plugins/specweave-github/lib/CodeValidator.d.ts +1 -1
- package/dist/plugins/specweave-github/lib/CodeValidator.js +1 -1
- package/dist/plugins/specweave-github/lib/github-client-v2.d.ts +10 -0
- package/dist/plugins/specweave-github/lib/github-client-v2.d.ts.map +1 -1
- package/dist/plugins/specweave-github/lib/github-client-v2.js +26 -0
- package/dist/plugins/specweave-github/lib/github-client-v2.js.map +1 -1
- package/dist/plugins/specweave-github/lib/task-sync.d.ts.map +1 -1
- package/dist/plugins/specweave-github/lib/task-sync.js +7 -0
- package/dist/plugins/specweave-github/lib/task-sync.js.map +1 -1
- package/dist/src/cli/commands/migrate-to-profiles.d.ts +1 -0
- package/dist/src/cli/commands/migrate-to-profiles.d.ts.map +1 -1
- package/dist/src/cli/commands/migrate-to-profiles.js +12 -1
- package/dist/src/cli/commands/migrate-to-profiles.js.map +1 -1
- package/dist/src/cli/commands/next-command.d.ts +52 -0
- package/dist/src/cli/commands/next-command.d.ts.map +1 -0
- package/dist/src/cli/commands/next-command.js +204 -0
- package/dist/src/cli/commands/next-command.js.map +1 -0
- package/dist/src/cli/commands/sync-specs.d.ts +16 -0
- package/dist/src/cli/commands/sync-specs.d.ts.map +1 -0
- package/dist/src/cli/commands/sync-specs.js +130 -0
- package/dist/src/cli/commands/sync-specs.js.map +1 -0
- package/dist/src/cli/count-tasks.d.ts +20 -0
- package/dist/src/cli/count-tasks.d.ts.map +1 -0
- package/dist/src/cli/count-tasks.js +50 -0
- package/dist/src/cli/count-tasks.js.map +1 -0
- package/dist/src/config/ConfigManager.d.ts.map +1 -1
- package/dist/src/config/ConfigManager.js +2 -1
- package/dist/src/config/ConfigManager.js.map +1 -1
- package/dist/src/config/types.d.ts +50 -50
- package/dist/src/core/cicd/state-manager.d.ts +8 -0
- package/dist/src/core/cicd/state-manager.d.ts.map +1 -1
- package/dist/src/core/cicd/state-manager.js +60 -15
- package/dist/src/core/cicd/state-manager.js.map +1 -1
- package/dist/src/core/cost-tracker.d.ts.map +1 -1
- package/dist/src/core/cost-tracker.js +2 -1
- package/dist/src/core/cost-tracker.js.map +1 -1
- package/dist/src/core/iac/template-engine.d.ts.map +1 -1
- package/dist/src/core/iac/template-engine.js +28 -0
- package/dist/src/core/iac/template-engine.js.map +1 -1
- package/dist/src/core/iac/template-generator.d.ts +53 -0
- package/dist/src/core/iac/template-generator.d.ts.map +1 -0
- package/dist/src/core/iac/template-generator.js +125 -0
- package/dist/src/core/iac/template-generator.js.map +1 -0
- package/dist/src/core/increment/status-auto-transition.js +3 -3
- package/dist/src/core/increment/status-auto-transition.js.map +1 -1
- package/dist/src/core/living-docs/CodeValidator.js +1 -1
- package/dist/src/core/living-docs/CodeValidator.js.map +1 -1
- package/dist/src/core/living-docs/content-distributor.d.ts.map +1 -1
- package/dist/src/core/living-docs/content-distributor.js +11 -1
- package/dist/src/core/living-docs/content-distributor.js.map +1 -1
- package/dist/src/core/living-docs/living-docs-sync.d.ts +166 -0
- package/dist/src/core/living-docs/living-docs-sync.d.ts.map +1 -0
- package/dist/src/core/living-docs/living-docs-sync.js +726 -0
- package/dist/src/core/living-docs/living-docs-sync.js.map +1 -0
- package/dist/src/core/living-docs/task-project-specific-generator.d.ts +7 -3
- package/dist/src/core/living-docs/task-project-specific-generator.d.ts.map +1 -1
- package/dist/src/core/living-docs/task-project-specific-generator.js +40 -24
- package/dist/src/core/living-docs/task-project-specific-generator.js.map +1 -1
- package/dist/src/core/plugin-loader.d.ts +7 -0
- package/dist/src/core/plugin-loader.d.ts.map +1 -1
- package/dist/src/core/plugin-loader.js +18 -1
- package/dist/src/core/plugin-loader.js.map +1 -1
- package/dist/src/core/serverless/platform-data-loader.d.ts +8 -0
- package/dist/src/core/serverless/platform-data-loader.d.ts.map +1 -1
- package/dist/src/core/serverless/platform-data-loader.js +14 -0
- package/dist/src/core/serverless/platform-data-loader.js.map +1 -1
- package/dist/src/core/serverless/types.d.ts +1 -1
- package/dist/src/core/serverless/types.d.ts.map +1 -1
- package/dist/src/core/status-line/status-line-manager.d.ts +6 -2
- package/dist/src/core/status-line/status-line-manager.d.ts.map +1 -1
- package/dist/src/core/status-line/status-line-manager.js +11 -5
- package/dist/src/core/status-line/status-line-manager.js.map +1 -1
- package/dist/src/core/status-line/task-counter.d.ts +69 -0
- package/dist/src/core/status-line/task-counter.d.ts.map +1 -0
- package/dist/src/core/status-line/task-counter.js +107 -0
- package/dist/src/core/status-line/task-counter.js.map +1 -0
- package/dist/src/core/workflow/autonomous-executor.d.ts +111 -0
- package/dist/src/core/workflow/autonomous-executor.d.ts.map +1 -0
- package/dist/src/core/workflow/autonomous-executor.js +275 -0
- package/dist/src/core/workflow/autonomous-executor.js.map +1 -0
- package/dist/src/core/workflow/backlog-scanner.d.ts +94 -0
- package/dist/src/core/workflow/backlog-scanner.d.ts.map +1 -0
- package/dist/src/core/workflow/backlog-scanner.js +170 -0
- package/dist/src/core/workflow/backlog-scanner.js.map +1 -0
- package/dist/src/core/workflow/command-invoker.d.ts +86 -0
- package/dist/src/core/workflow/command-invoker.d.ts.map +1 -0
- package/dist/src/core/workflow/command-invoker.js +131 -0
- package/dist/src/core/workflow/command-invoker.js.map +1 -0
- package/dist/src/core/workflow/cost-estimator.d.ts +120 -0
- package/dist/src/core/workflow/cost-estimator.d.ts.map +1 -0
- package/dist/src/core/workflow/cost-estimator.js +222 -0
- package/dist/src/core/workflow/cost-estimator.js.map +1 -0
- package/dist/src/core/workflow/index.d.ts +20 -0
- package/dist/src/core/workflow/index.d.ts.map +1 -0
- package/dist/src/core/workflow/index.js +24 -0
- package/dist/src/core/workflow/index.js.map +1 -0
- package/dist/src/core/workflow/state-manager.d.ts +107 -0
- package/dist/src/core/workflow/state-manager.d.ts.map +1 -0
- package/dist/src/core/workflow/state-manager.js +126 -0
- package/dist/src/core/workflow/state-manager.js.map +1 -0
- package/dist/src/core/workflow/workflow-orchestrator.d.ts +93 -0
- package/dist/src/core/workflow/workflow-orchestrator.d.ts.map +1 -0
- package/dist/src/core/workflow/workflow-orchestrator.js +195 -0
- package/dist/src/core/workflow/workflow-orchestrator.js.map +1 -0
- package/dist/src/init/architecture/types.d.ts +10 -10
- package/dist/src/metrics/dora-calculator.js +2 -2
- package/dist/src/metrics/dora-calculator.js.map +1 -1
- package/dist/src/utils/pricing-constants.d.ts +5 -2
- package/dist/src/utils/pricing-constants.d.ts.map +1 -1
- package/dist/src/utils/pricing-constants.js +3 -2
- package/dist/src/utils/pricing-constants.js.map +1 -1
- package/package.json +4 -4
- package/plugins/specweave/agents/infrastructure/AGENT.md +88 -46
- package/plugins/specweave/agents/pm/AGENT.md +58 -1
- package/plugins/specweave/commands/specweave-archive-features.md +1 -1
- package/plugins/specweave/commands/specweave-archive-increments.md +1 -1
- package/plugins/specweave/commands/specweave-check-hooks.md +5 -0
- package/plugins/specweave/commands/specweave-done.md +12 -0
- package/plugins/specweave/commands/specweave-plan.md +1 -1
- package/plugins/specweave/commands/specweave-progress.md +108 -379
- package/plugins/specweave/commands/specweave-reopen.md +1 -1
- package/plugins/specweave/commands/specweave-restore-feature.md +1 -1
- package/plugins/specweave/commands/specweave-sync-specs.md +20 -48
- package/plugins/specweave/hooks/lib/update-status-line.sh +44 -35
- package/plugins/specweave/hooks/lib/validate-spec-status.sh +163 -0
- package/plugins/specweave/hooks/user-prompt-submit.sh +17 -35
- package/plugins/specweave/lib/hooks/update-tasks-md.js +52 -9
- package/plugins/specweave/lib/hooks/update-tasks-md.ts +77 -16
- package/plugins/specweave/templates/iac/aws-lambda/defaults.json +24 -0
- package/plugins/specweave/templates/iac/aws-lambda/templates/README.md.hbs +260 -0
- package/plugins/specweave/templates/iac/aws-lambda/templates/environments/dev.tfvars.hbs +34 -0
- package/plugins/specweave/templates/iac/aws-lambda/templates/environments/prod.tfvars.hbs +37 -0
- package/plugins/specweave/templates/iac/aws-lambda/templates/environments/staging.tfvars.hbs +35 -0
- package/plugins/specweave/templates/iac/aws-lambda/templates/outputs.tf.hbs +77 -0
- package/plugins/specweave/templates/iac/aws-lambda/templates/providers.tf.hbs +36 -0
- package/plugins/specweave/templates/iac/aws-lambda/templates/variables.tf.hbs +115 -0
- package/plugins/specweave/templates/iac/azure-functions/defaults.json +25 -0
- package/plugins/specweave/templates/iac/azure-functions/templates/README.md.hbs +268 -0
- package/plugins/specweave/templates/iac/azure-functions/templates/environments/dev.tfvars.hbs +34 -0
- package/plugins/specweave/templates/iac/azure-functions/templates/environments/prod.tfvars.hbs +46 -0
- package/plugins/specweave/templates/iac/azure-functions/templates/environments/staging.tfvars.hbs +34 -0
- package/plugins/specweave/templates/iac/azure-functions/templates/main.tf.hbs +225 -0
- package/plugins/specweave/templates/iac/azure-functions/templates/outputs.tf.hbs +89 -0
- package/plugins/specweave/templates/iac/azure-functions/templates/provider.tf.hbs +27 -0
- package/plugins/specweave/templates/iac/azure-functions/templates/providers.tf.hbs +35 -0
- package/plugins/specweave/templates/iac/azure-functions/templates/variables.tf.hbs +124 -0
- package/plugins/specweave/templates/iac/firebase/defaults.json +29 -0
- package/plugins/specweave/templates/iac/firebase/templates/README.md.hbs +35 -0
- package/plugins/specweave/templates/iac/firebase/templates/environments/dev.tfvars.hbs +7 -0
- package/plugins/specweave/templates/iac/firebase/templates/environments/prod.tfvars.hbs +7 -0
- package/plugins/specweave/templates/iac/firebase/templates/environments/staging.tfvars.hbs +7 -0
- package/plugins/specweave/templates/iac/firebase/templates/main.tf.hbs +90 -0
- package/plugins/specweave/templates/iac/firebase/templates/outputs.tf.hbs +15 -0
- package/plugins/specweave/templates/iac/firebase/templates/providers.tf.hbs +23 -0
- package/plugins/specweave/templates/iac/firebase/templates/variables.tf.hbs +42 -0
- package/plugins/specweave/templates/iac/gcp-cloud-functions/defaults.json +26 -0
- package/plugins/specweave/templates/iac/gcp-cloud-functions/templates/README.md.hbs +299 -0
- package/plugins/specweave/templates/iac/gcp-cloud-functions/templates/environments/dev.tfvars.hbs +36 -0
- package/plugins/specweave/templates/iac/gcp-cloud-functions/templates/environments/prod.tfvars.hbs +48 -0
- package/plugins/specweave/templates/iac/gcp-cloud-functions/templates/environments/staging.tfvars.hbs +41 -0
- package/plugins/specweave/templates/iac/gcp-cloud-functions/templates/main.tf.hbs +192 -0
- package/plugins/specweave/templates/iac/gcp-cloud-functions/templates/outputs.tf.hbs +66 -0
- package/plugins/specweave/templates/iac/gcp-cloud-functions/templates/providers.tf.hbs +25 -0
- package/plugins/specweave/templates/iac/gcp-cloud-functions/templates/variables.tf.hbs +119 -0
- package/plugins/specweave/templates/iac/supabase/defaults.json +15 -0
- package/plugins/specweave/templates/iac/supabase/templates/README.md.hbs +46 -0
- package/plugins/specweave/templates/iac/supabase/templates/main.tf.hbs +50 -0
- package/plugins/specweave-github/agents/github-manager/AGENT.md +39 -7
- package/plugins/specweave-github/commands/specweave-github-create-issue.md +5 -5
- package/plugins/specweave-github/lib/CodeValidator.ts +1 -1
- package/plugins/specweave-github/lib/github-client-v2.js +29 -0
- package/plugins/specweave-github/lib/github-client-v2.ts +30 -0
- package/plugins/specweave-github/lib/task-sync.js +4 -0
- package/plugins/specweave-github/lib/task-sync.ts +7 -0
- package/plugins/specweave-jira/lib/enhanced-jira-sync.js +3 -3
- package/plugins/specweave-release/hooks/.specweave/logs/dora-tracking.log +2022 -0
- package/src/templates/CLAUDE.md.template +31 -0
- package/dist/src/core/living-docs/ThreeLayerSyncManager.d.ts +0 -116
- package/dist/src/core/living-docs/ThreeLayerSyncManager.d.ts.map +0 -1
- package/dist/src/core/living-docs/ThreeLayerSyncManager.js +0 -356
- package/dist/src/core/living-docs/ThreeLayerSyncManager.js.map +0 -1
|
@@ -0,0 +1,170 @@
|
|
|
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
|
+
import * as fs from 'fs-extra';
|
|
13
|
+
import * as path from 'path';
|
|
14
|
+
import * as yaml from 'js-yaml';
|
|
15
|
+
/**
|
|
16
|
+
* Backlog Scanner - Scan and rank backlog items
|
|
17
|
+
*/
|
|
18
|
+
export class BacklogScanner {
|
|
19
|
+
constructor(rootDir = process.cwd()) {
|
|
20
|
+
this.backlogDir = path.join(rootDir, '.specweave/increments/_backlog');
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Scan backlog directory
|
|
24
|
+
*
|
|
25
|
+
* @returns Array of backlog items
|
|
26
|
+
*/
|
|
27
|
+
async scanBacklog() {
|
|
28
|
+
// Check if backlog directory exists
|
|
29
|
+
if (!await fs.pathExists(this.backlogDir)) {
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
const items = [];
|
|
33
|
+
const dirs = await fs.readdir(this.backlogDir);
|
|
34
|
+
for (const dir of dirs) {
|
|
35
|
+
const dirPath = path.join(this.backlogDir, dir);
|
|
36
|
+
const stat = await fs.stat(dirPath);
|
|
37
|
+
if (!stat.isDirectory()) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
// Check if spec.md exists
|
|
41
|
+
const specPath = path.join(dirPath, 'spec.md');
|
|
42
|
+
if (!await fs.pathExists(specPath)) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
// Parse spec.md frontmatter
|
|
46
|
+
try {
|
|
47
|
+
const item = await this.parseBacklogItem(dir, specPath);
|
|
48
|
+
items.push(item);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
console.warn(`Failed to parse backlog item ${dir}:`, error);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return items;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Parse backlog item from spec.md
|
|
58
|
+
*/
|
|
59
|
+
async parseBacklogItem(incrementId, specPath) {
|
|
60
|
+
const content = await fs.readFile(specPath, 'utf-8');
|
|
61
|
+
// Extract YAML frontmatter
|
|
62
|
+
const frontmatterMatch = content.match(/^---\n([\s\S]*?)\n---/);
|
|
63
|
+
if (!frontmatterMatch) {
|
|
64
|
+
throw new Error('No YAML frontmatter found in spec.md');
|
|
65
|
+
}
|
|
66
|
+
const frontmatter = yaml.load(frontmatterMatch[1]);
|
|
67
|
+
// Extract title from first heading
|
|
68
|
+
const titleMatch = content.match(/^#\s+(.+)$/m);
|
|
69
|
+
const title = titleMatch ? titleMatch[1] : frontmatter.title || incrementId;
|
|
70
|
+
return {
|
|
71
|
+
incrementId,
|
|
72
|
+
specPath,
|
|
73
|
+
title,
|
|
74
|
+
priority: frontmatter.priority || 'P2',
|
|
75
|
+
project: frontmatter.project,
|
|
76
|
+
dependencies: frontmatter.dependencies || [],
|
|
77
|
+
estimatedEffort: frontmatter.estimated_effort || frontmatter.estimatedEffort,
|
|
78
|
+
created: frontmatter.created
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Rank backlog items by priority, dependencies, and project match
|
|
83
|
+
*
|
|
84
|
+
* Ranking algorithm:
|
|
85
|
+
* - Priority: P0=10, P1=7, P2=5, P3=3
|
|
86
|
+
* - Dependencies met: +5
|
|
87
|
+
* - Project match: +3
|
|
88
|
+
* - Recently created: +2
|
|
89
|
+
*
|
|
90
|
+
* @param items - Backlog items to rank
|
|
91
|
+
* @param currentProject - Current project (for filtering)
|
|
92
|
+
* @param completedIncrements - List of completed increment IDs
|
|
93
|
+
* @returns Ranked items (sorted by score descending)
|
|
94
|
+
*/
|
|
95
|
+
rankItems(items, currentProject, completedIncrements = []) {
|
|
96
|
+
const ranked = items.map(item => {
|
|
97
|
+
let score = 0;
|
|
98
|
+
const reasons = [];
|
|
99
|
+
// Priority score
|
|
100
|
+
const priorityScores = {
|
|
101
|
+
'P0': 10,
|
|
102
|
+
'P1': 7,
|
|
103
|
+
'P2': 5,
|
|
104
|
+
'P3': 3
|
|
105
|
+
};
|
|
106
|
+
const priorityScore = priorityScores[item.priority] || 3;
|
|
107
|
+
score += priorityScore;
|
|
108
|
+
reasons.push(`Priority ${item.priority} (${priorityScore} pts)`);
|
|
109
|
+
// Dependencies met
|
|
110
|
+
const unmetDeps = item.dependencies.filter(dep => !completedIncrements.includes(dep));
|
|
111
|
+
if (unmetDeps.length === 0 && item.dependencies.length > 0) {
|
|
112
|
+
score += 5;
|
|
113
|
+
reasons.push('All dependencies met (+5 pts)');
|
|
114
|
+
}
|
|
115
|
+
else if (unmetDeps.length > 0) {
|
|
116
|
+
reasons.push(`Blocked by: ${unmetDeps.join(', ')}`);
|
|
117
|
+
}
|
|
118
|
+
// Project match
|
|
119
|
+
if (currentProject && item.project === currentProject) {
|
|
120
|
+
score += 3;
|
|
121
|
+
reasons.push(`Project match: ${currentProject} (+3 pts)`);
|
|
122
|
+
}
|
|
123
|
+
// Recently created (bonus for new items)
|
|
124
|
+
if (item.created) {
|
|
125
|
+
const createdDate = new Date(item.created);
|
|
126
|
+
const daysSinceCreated = (Date.now() - createdDate.getTime()) / (1000 * 60 * 60 * 24);
|
|
127
|
+
if (daysSinceCreated < 7) {
|
|
128
|
+
score += 2;
|
|
129
|
+
reasons.push('Recently created (+2 pts)');
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
...item,
|
|
134
|
+
score,
|
|
135
|
+
reason: reasons.join('; ')
|
|
136
|
+
};
|
|
137
|
+
});
|
|
138
|
+
// Sort by score (descending)
|
|
139
|
+
return ranked.sort((a, b) => b.score - a.score);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Get top N recommendations
|
|
143
|
+
*
|
|
144
|
+
* @param n - Number of recommendations (default: 3)
|
|
145
|
+
* @param currentProject - Current project filter
|
|
146
|
+
* @param completedIncrements - Completed increments
|
|
147
|
+
* @returns Backlog recommendations
|
|
148
|
+
*/
|
|
149
|
+
async getTopRecommendations(n = 3, currentProject, completedIncrements = []) {
|
|
150
|
+
const items = await this.scanBacklog();
|
|
151
|
+
const ranked = this.rankItems(items, currentProject, completedIncrements);
|
|
152
|
+
const topItems = ranked.slice(0, n);
|
|
153
|
+
let summary = '';
|
|
154
|
+
if (items.length === 0) {
|
|
155
|
+
summary = 'No items in backlog. Use /specweave:increment to create new work.';
|
|
156
|
+
}
|
|
157
|
+
else if (topItems.length === 0) {
|
|
158
|
+
summary = 'No actionable items found (all blocked by dependencies).';
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
summary = `Found ${items.length} items in backlog. Top ${topItems.length} recommendations based on priority and dependencies.`;
|
|
162
|
+
}
|
|
163
|
+
return {
|
|
164
|
+
items: topItems,
|
|
165
|
+
totalItems: items.length,
|
|
166
|
+
summary
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=backlog-scanner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backlog-scanner.js","sourceRoot":"","sources":["../../../../src/core/workflow/backlog-scanner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,IAAI,MAAM,SAAS,CAAC;AA8ChC;;GAEG;AACH,MAAM,OAAO,cAAc;IAGzB,YAAY,UAAkB,OAAO,CAAC,GAAG,EAAE;QACzC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,gCAAgC,CAAC,CAAC;IACzE,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,WAAW;QACf,oCAAoC;QACpC,IAAI,CAAC,MAAM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AED,OAAO;gBACL,GAAG,IAAI;gBACP,KAAK;gBACL,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;aAC3B,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,6BAA6B;QAC7B,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;IAClD,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,qBAAqB,CACzB,IAAY,CAAC,EACb,cAAuB,EACvB,sBAAgC,EAAE;QAElC,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC;QACvC,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,cAAc,EAAE,mBAAmB,CAAC,CAAC;QAC1E,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAEpC,IAAI,OAAO,GAAG,EAAE,CAAC;QACjB,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACvB,OAAO,GAAG,mEAAmE,CAAC;QAChF,CAAC;aAAM,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACjC,OAAO,GAAG,0DAA0D,CAAC;QACvE,CAAC;aAAM,CAAC;YACN,OAAO,GAAG,SAAS,KAAK,CAAC,MAAM,0BAA0B,QAAQ,CAAC,MAAM,sDAAsD,CAAC;QACjI,CAAC;QAED,OAAO;YACL,KAAK,EAAE,QAAQ;YACf,UAAU,EAAE,KAAK,CAAC,MAAM;YACxB,OAAO;SACR,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Command Invoker - Programmatic command execution
|
|
3
|
+
*
|
|
4
|
+
* Provides utilities to invoke SpecWeave commands programmatically
|
|
5
|
+
* from within the workflow orchestration system.
|
|
6
|
+
*
|
|
7
|
+
* Part of increment 0039: Ultra-Smart Next Command
|
|
8
|
+
*
|
|
9
|
+
* @module core/workflow/command-invoker
|
|
10
|
+
* @since v0.22.0
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Command invocation options
|
|
14
|
+
*/
|
|
15
|
+
export interface InvokeOptions {
|
|
16
|
+
/** Command arguments */
|
|
17
|
+
args?: string[];
|
|
18
|
+
/** Working directory */
|
|
19
|
+
cwd?: string;
|
|
20
|
+
/** Timeout in milliseconds */
|
|
21
|
+
timeout?: number;
|
|
22
|
+
/** Capture stdout */
|
|
23
|
+
captureOutput?: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Command invocation result
|
|
27
|
+
*/
|
|
28
|
+
export interface InvokeResult {
|
|
29
|
+
/** Command succeeded */
|
|
30
|
+
success: boolean;
|
|
31
|
+
/** Exit code */
|
|
32
|
+
exitCode: number;
|
|
33
|
+
/** Standard output */
|
|
34
|
+
stdout?: string;
|
|
35
|
+
/** Standard error */
|
|
36
|
+
stderr?: string;
|
|
37
|
+
/** Error message */
|
|
38
|
+
error?: string;
|
|
39
|
+
/** Execution time in milliseconds */
|
|
40
|
+
executionTime: number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Error severity level
|
|
44
|
+
*/
|
|
45
|
+
export declare enum ErrorSeverity {
|
|
46
|
+
INFO = "info",
|
|
47
|
+
WARNING = "warning",
|
|
48
|
+
ERROR = "error",
|
|
49
|
+
CRITICAL = "critical"
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Command Invoker - Execute SpecWeave commands programmatically
|
|
53
|
+
*/
|
|
54
|
+
export declare class CommandInvoker {
|
|
55
|
+
/**
|
|
56
|
+
* Invoke a SpecWeave command
|
|
57
|
+
*
|
|
58
|
+
* @param command - Command name (e.g., 'plan', 'do', 'validate')
|
|
59
|
+
* @param options - Invocation options
|
|
60
|
+
* @returns Command execution result
|
|
61
|
+
*/
|
|
62
|
+
invoke(command: string, options?: InvokeOptions): Promise<InvokeResult>;
|
|
63
|
+
/**
|
|
64
|
+
* Invoke command with automatic retry on transient failures
|
|
65
|
+
*
|
|
66
|
+
* @param command - Command name
|
|
67
|
+
* @param options - Invocation options
|
|
68
|
+
* @param maxRetries - Maximum retry attempts (default: 3)
|
|
69
|
+
* @returns Command execution result
|
|
70
|
+
*/
|
|
71
|
+
invokeWithRetry(command: string, options?: InvokeOptions, maxRetries?: number): Promise<InvokeResult>;
|
|
72
|
+
/**
|
|
73
|
+
* Classify error severity
|
|
74
|
+
*
|
|
75
|
+
* @param result - Command result
|
|
76
|
+
* @returns Error severity level
|
|
77
|
+
*/
|
|
78
|
+
classifyError(result: InvokeResult): ErrorSeverity;
|
|
79
|
+
/**
|
|
80
|
+
* Delay execution
|
|
81
|
+
*
|
|
82
|
+
* @param ms - Milliseconds to delay
|
|
83
|
+
*/
|
|
84
|
+
private delay;
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=command-invoker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-invoker.d.ts","sourceRoot":"","sources":["../../../../src/core/workflow/command-invoker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAOH;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,wBAAwB;IACxB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,wBAAwB;IACxB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,8BAA8B;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,qBAAqB;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,wBAAwB;IACxB,OAAO,EAAE,OAAO,CAAC;IACjB,gBAAgB;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,sBAAsB;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qBAAqB;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oBAAoB;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,qCAAqC;IACrC,aAAa,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,oBAAY,aAAa;IACvB,IAAI,SAAS;IACb,OAAO,YAAY;IACnB,KAAK,UAAU;IACf,QAAQ,aAAa;CACtB;AAED;;GAEG;AACH,qBAAa,cAAc;IACzB;;;;;;OAMG;IACG,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,YAAY,CAAC;IAsCjF;;;;;;;OAOG;IACG,eAAe,CACnB,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,aAAkB,EAC3B,UAAU,GAAE,MAAU,GACrB,OAAO,CAAC,YAAY,CAAC;IA+BxB;;;;;OAKG;IACH,aAAa,CAAC,MAAM,EAAE,YAAY,GAAG,aAAa;IAqBlD;;;;OAIG;IACH,OAAO,CAAC,KAAK;CAGd"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Command Invoker - Programmatic command execution
|
|
3
|
+
*
|
|
4
|
+
* Provides utilities to invoke SpecWeave commands programmatically
|
|
5
|
+
* from within the workflow orchestration system.
|
|
6
|
+
*
|
|
7
|
+
* Part of increment 0039: Ultra-Smart Next Command
|
|
8
|
+
*
|
|
9
|
+
* @module core/workflow/command-invoker
|
|
10
|
+
* @since v0.22.0
|
|
11
|
+
*/
|
|
12
|
+
import { exec } from 'child_process';
|
|
13
|
+
import { promisify } from 'util';
|
|
14
|
+
const execAsync = promisify(exec);
|
|
15
|
+
/**
|
|
16
|
+
* Error severity level
|
|
17
|
+
*/
|
|
18
|
+
export var ErrorSeverity;
|
|
19
|
+
(function (ErrorSeverity) {
|
|
20
|
+
ErrorSeverity["INFO"] = "info";
|
|
21
|
+
ErrorSeverity["WARNING"] = "warning";
|
|
22
|
+
ErrorSeverity["ERROR"] = "error";
|
|
23
|
+
ErrorSeverity["CRITICAL"] = "critical";
|
|
24
|
+
})(ErrorSeverity || (ErrorSeverity = {}));
|
|
25
|
+
/**
|
|
26
|
+
* Command Invoker - Execute SpecWeave commands programmatically
|
|
27
|
+
*/
|
|
28
|
+
export class CommandInvoker {
|
|
29
|
+
/**
|
|
30
|
+
* Invoke a SpecWeave command
|
|
31
|
+
*
|
|
32
|
+
* @param command - Command name (e.g., 'plan', 'do', 'validate')
|
|
33
|
+
* @param options - Invocation options
|
|
34
|
+
* @returns Command execution result
|
|
35
|
+
*/
|
|
36
|
+
async invoke(command, options = {}) {
|
|
37
|
+
const startTime = Date.now();
|
|
38
|
+
try {
|
|
39
|
+
// Build command string
|
|
40
|
+
const args = options.args || [];
|
|
41
|
+
const commandString = `npx specweave ${command} ${args.join(' ')}`;
|
|
42
|
+
// Execute command
|
|
43
|
+
const { stdout, stderr } = await execAsync(commandString, {
|
|
44
|
+
cwd: options.cwd || process.cwd(),
|
|
45
|
+
timeout: options.timeout || 300000, // 5 min default
|
|
46
|
+
maxBuffer: 10 * 1024 * 1024 // 10MB
|
|
47
|
+
});
|
|
48
|
+
const executionTime = Date.now() - startTime;
|
|
49
|
+
return {
|
|
50
|
+
success: true,
|
|
51
|
+
exitCode: 0,
|
|
52
|
+
stdout: options.captureOutput ? stdout : undefined,
|
|
53
|
+
stderr: stderr || undefined,
|
|
54
|
+
executionTime
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
const executionTime = Date.now() - startTime;
|
|
59
|
+
return {
|
|
60
|
+
success: false,
|
|
61
|
+
exitCode: error.code || 1,
|
|
62
|
+
stdout: options.captureOutput ? error.stdout : undefined,
|
|
63
|
+
stderr: error.stderr || undefined,
|
|
64
|
+
error: error.message,
|
|
65
|
+
executionTime
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Invoke command with automatic retry on transient failures
|
|
71
|
+
*
|
|
72
|
+
* @param command - Command name
|
|
73
|
+
* @param options - Invocation options
|
|
74
|
+
* @param maxRetries - Maximum retry attempts (default: 3)
|
|
75
|
+
* @returns Command execution result
|
|
76
|
+
*/
|
|
77
|
+
async invokeWithRetry(command, options = {}, maxRetries = 3) {
|
|
78
|
+
let lastResult = null;
|
|
79
|
+
let attempt = 0;
|
|
80
|
+
while (attempt < maxRetries) {
|
|
81
|
+
attempt++;
|
|
82
|
+
const result = await this.invoke(command, options);
|
|
83
|
+
if (result.success) {
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
// Check if error is retryable
|
|
87
|
+
const severity = this.classifyError(result);
|
|
88
|
+
if (severity === ErrorSeverity.CRITICAL) {
|
|
89
|
+
// Don't retry critical errors
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
lastResult = result;
|
|
93
|
+
// Wait before retry (exponential backoff)
|
|
94
|
+
if (attempt < maxRetries) {
|
|
95
|
+
await this.delay(Math.pow(2, attempt) * 1000);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return lastResult;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Classify error severity
|
|
102
|
+
*
|
|
103
|
+
* @param result - Command result
|
|
104
|
+
* @returns Error severity level
|
|
105
|
+
*/
|
|
106
|
+
classifyError(result) {
|
|
107
|
+
const error = result.error || result.stderr || '';
|
|
108
|
+
// Critical errors (don't retry)
|
|
109
|
+
if (error.includes('ENOENT') || error.includes('command not found')) {
|
|
110
|
+
return ErrorSeverity.CRITICAL;
|
|
111
|
+
}
|
|
112
|
+
if (error.includes('permission denied') || error.includes('EACCES')) {
|
|
113
|
+
return ErrorSeverity.CRITICAL;
|
|
114
|
+
}
|
|
115
|
+
// Transient errors (retry)
|
|
116
|
+
if (error.includes('ECONNREFUSED') || error.includes('ETIMEDOUT')) {
|
|
117
|
+
return ErrorSeverity.WARNING;
|
|
118
|
+
}
|
|
119
|
+
// Default to error
|
|
120
|
+
return ErrorSeverity.ERROR;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Delay execution
|
|
124
|
+
*
|
|
125
|
+
* @param ms - Milliseconds to delay
|
|
126
|
+
*/
|
|
127
|
+
delay(ms) {
|
|
128
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=command-invoker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-invoker.js","sourceRoot":"","sources":["../../../../src/core/workflow/command-invoker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAEjC,MAAM,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;AAkClC;;GAEG;AACH,MAAM,CAAN,IAAY,aAKX;AALD,WAAY,aAAa;IACvB,8BAAa,CAAA;IACb,oCAAmB,CAAA;IACnB,gCAAe,CAAA;IACf,sCAAqB,CAAA;AACvB,CAAC,EALW,aAAa,KAAb,aAAa,QAKxB;AAED;;GAEG;AACH,MAAM,OAAO,cAAc;IACzB;;;;;;OAMG;IACH,KAAK,CAAC,MAAM,CAAC,OAAe,EAAE,UAAyB,EAAE;QACvD,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAE7B,IAAI,CAAC;YACH,uBAAuB;YACvB,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,EAAE,CAAC;YAChC,MAAM,aAAa,GAAG,iBAAiB,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YAEnE,kBAAkB;YAClB,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,SAAS,CAAC,aAAa,EAAE;gBACxD,GAAG,EAAE,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE;gBACjC,OAAO,EAAE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AAO,EAAE,EAAE,CAAC,CAAC,CAAC;IACzD,CAAC;CACF"}
|
|
@@ -0,0 +1,120 @@
|
|
|
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
|
+
/**
|
|
13
|
+
* Cost estimate for workflow execution
|
|
14
|
+
*/
|
|
15
|
+
export interface CostEstimate {
|
|
16
|
+
/** Estimated cost in USD */
|
|
17
|
+
estimatedCost: number;
|
|
18
|
+
/** Cost breakdown by phase */
|
|
19
|
+
breakdown: CostBreakdown[];
|
|
20
|
+
/** Risk level */
|
|
21
|
+
riskLevel: RiskLevel;
|
|
22
|
+
/** Explanation */
|
|
23
|
+
explanation: string;
|
|
24
|
+
/** Confidence in estimate (0.0-1.0) */
|
|
25
|
+
confidence: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Cost breakdown by phase
|
|
29
|
+
*/
|
|
30
|
+
export interface CostBreakdown {
|
|
31
|
+
/** Phase name */
|
|
32
|
+
phase: string;
|
|
33
|
+
/** Number of AI calls */
|
|
34
|
+
aiCalls: number;
|
|
35
|
+
/** Estimated cost */
|
|
36
|
+
cost: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Risk level for cost
|
|
40
|
+
*/
|
|
41
|
+
export declare enum RiskLevel {
|
|
42
|
+
/** < $1 */
|
|
43
|
+
LOW = "low",
|
|
44
|
+
/** $1 - $5 */
|
|
45
|
+
MEDIUM = "medium",
|
|
46
|
+
/** $5 - $20 */
|
|
47
|
+
HIGH = "high",
|
|
48
|
+
/** > $20 */
|
|
49
|
+
CRITICAL = "critical"
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Cost estimation configuration
|
|
53
|
+
*/
|
|
54
|
+
export interface CostEstimatorConfig {
|
|
55
|
+
/** Cost per AI call (default: $0.01) */
|
|
56
|
+
costPerCall?: number;
|
|
57
|
+
/** Low risk threshold (default: $1) */
|
|
58
|
+
lowThreshold?: number;
|
|
59
|
+
/** Medium risk threshold (default: $5) */
|
|
60
|
+
mediumThreshold?: number;
|
|
61
|
+
/** High risk threshold (default: $20) */
|
|
62
|
+
highThreshold?: number;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Cost Estimator - Estimate autonomous execution costs
|
|
66
|
+
*/
|
|
67
|
+
export declare class CostEstimator {
|
|
68
|
+
private costPerCall;
|
|
69
|
+
private lowThreshold;
|
|
70
|
+
private mediumThreshold;
|
|
71
|
+
private highThreshold;
|
|
72
|
+
constructor(config?: CostEstimatorConfig);
|
|
73
|
+
/**
|
|
74
|
+
* Estimate cost for increment execution
|
|
75
|
+
*
|
|
76
|
+
* @param incrementPath - Path to increment directory
|
|
77
|
+
* @returns Cost estimate
|
|
78
|
+
*/
|
|
79
|
+
estimateIncrement(incrementPath: string): Promise<CostEstimate>;
|
|
80
|
+
/**
|
|
81
|
+
* Estimate planning cost
|
|
82
|
+
*/
|
|
83
|
+
private estimatePlanning;
|
|
84
|
+
/**
|
|
85
|
+
* Estimate execution cost based on task count
|
|
86
|
+
*/
|
|
87
|
+
private estimateExecution;
|
|
88
|
+
/**
|
|
89
|
+
* Estimate task count from spec.md
|
|
90
|
+
*/
|
|
91
|
+
private estimateTasksFromSpec;
|
|
92
|
+
/**
|
|
93
|
+
* Estimate validation cost
|
|
94
|
+
*/
|
|
95
|
+
private estimateValidation;
|
|
96
|
+
/**
|
|
97
|
+
* Estimate QA cost
|
|
98
|
+
*/
|
|
99
|
+
private estimateQA;
|
|
100
|
+
/**
|
|
101
|
+
* Determine risk level based on total cost
|
|
102
|
+
*/
|
|
103
|
+
private determineRiskLevel;
|
|
104
|
+
/**
|
|
105
|
+
* Calculate confidence in estimate
|
|
106
|
+
*/
|
|
107
|
+
private calculateConfidence;
|
|
108
|
+
/**
|
|
109
|
+
* Generate human-readable explanation
|
|
110
|
+
*/
|
|
111
|
+
private generateExplanation;
|
|
112
|
+
/**
|
|
113
|
+
* Check if cost exceeds threshold
|
|
114
|
+
*
|
|
115
|
+
* @param estimate - Cost estimate
|
|
116
|
+
* @returns True if cost exceeds HIGH threshold
|
|
117
|
+
*/
|
|
118
|
+
checkThreshold(estimate: CostEstimate): boolean;
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=cost-estimator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cost-estimator.d.ts","sourceRoot":"","sources":["../../../../src/core/workflow/cost-estimator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,4BAA4B;IAC5B,aAAa,EAAE,MAAM,CAAC;IACtB,8BAA8B;IAC9B,SAAS,EAAE,aAAa,EAAE,CAAC;IAC3B,iBAAiB;IACjB,SAAS,EAAE,SAAS,CAAC;IACrB,kBAAkB;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,uCAAuC;IACvC,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,iBAAiB;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,yBAAyB;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,qBAAqB;IACrB,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,oBAAY,SAAS;IACnB,WAAW;IACX,GAAG,QAAQ;IACX,cAAc;IACd,MAAM,WAAW;IACjB,eAAe;IACf,IAAI,SAAS;IACb,YAAY;IACZ,QAAQ,aAAa;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,wCAAwC;IACxC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,uCA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