ai-sdlc 0.2.0-alpha.41 → 0.2.0-alpha.43
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/dist/agents/implementation.d.ts.map +1 -1
- package/dist/agents/implementation.js +31 -0
- package/dist/agents/implementation.js.map +1 -1
- package/dist/agents/index.d.ts +1 -0
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +1 -0
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/orchestrator.d.ts +61 -0
- package/dist/agents/orchestrator.d.ts.map +1 -0
- package/dist/agents/orchestrator.js +443 -0
- package/dist/agents/orchestrator.js.map +1 -0
- package/dist/agents/review.d.ts.map +1 -1
- package/dist/agents/review.js +24 -22
- package/dist/agents/review.js.map +1 -1
- package/dist/cli/commands.d.ts.map +1 -1
- package/dist/cli/commands.js +16 -1
- package/dist/cli/commands.js.map +1 -1
- package/dist/cli/runner.d.ts.map +1 -1
- package/dist/cli/runner.js +4 -8
- package/dist/cli/runner.js.map +1 -1
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +4 -2
- package/dist/core/config.js.map +1 -1
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +1 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/llm-utils.d.ts +103 -0
- package/dist/core/llm-utils.d.ts.map +1 -0
- package/dist/core/llm-utils.js +368 -0
- package/dist/core/llm-utils.js.map +1 -0
- package/dist/core/story.d.ts +11 -1
- package/dist/core/story.d.ts.map +1 -1
- package/dist/core/story.js +33 -1
- package/dist/core/story.js.map +1 -1
- package/dist/types/index.d.ts +47 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sequential Task Orchestrator
|
|
3
|
+
*
|
|
4
|
+
* Orchestrates implementation by running each task as an isolated agent,
|
|
5
|
+
* preventing context window exhaustion and enabling intelligent retry/recovery.
|
|
6
|
+
*/
|
|
7
|
+
import { spawnSync } from 'child_process';
|
|
8
|
+
import fs from 'fs';
|
|
9
|
+
import path from 'path';
|
|
10
|
+
import { parseImplementationTasks } from '../core/task-parser.js';
|
|
11
|
+
import { getTaskProgress, updateTaskProgress, initializeTaskProgress, readStoryFile, } from '../core/task-progress.js';
|
|
12
|
+
import { runSingleTaskAgent } from './single-task.js';
|
|
13
|
+
import { getLogger } from '../core/logger.js';
|
|
14
|
+
const logger = getLogger();
|
|
15
|
+
/**
|
|
16
|
+
* Default orchestrator options
|
|
17
|
+
*/
|
|
18
|
+
const DEFAULT_OPTIONS = {
|
|
19
|
+
maxRetriesPerTask: 2,
|
|
20
|
+
commitAfterEachTask: true,
|
|
21
|
+
stopOnFirstFailure: true,
|
|
22
|
+
dryRun: false,
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Build minimal context for a single task
|
|
26
|
+
*
|
|
27
|
+
* Extracts relevant acceptance criteria, existing file contents, and project conventions.
|
|
28
|
+
* Truncates if context exceeds reasonable size (~2000 chars for projectPatterns).
|
|
29
|
+
*
|
|
30
|
+
* @param task - Task to build context for
|
|
31
|
+
* @param storyContent - Full story content
|
|
32
|
+
* @param workingDirectory - Working directory for task execution
|
|
33
|
+
* @returns Minimal task context
|
|
34
|
+
*/
|
|
35
|
+
export function buildTaskContext(task, storyContent, workingDirectory) {
|
|
36
|
+
// Extract acceptance criteria section
|
|
37
|
+
const acceptanceCriteria = [];
|
|
38
|
+
const acMatch = storyContent.match(/##\s+Acceptance\s+Criteria\s*\n([\s\S]*?)(?=\n##|$)/i);
|
|
39
|
+
if (acMatch) {
|
|
40
|
+
const acSection = acMatch[1];
|
|
41
|
+
const lines = acSection.split('\n');
|
|
42
|
+
for (const line of lines) {
|
|
43
|
+
const trimmed = line.trim();
|
|
44
|
+
if (trimmed.startsWith('-') || trimmed.startsWith('*')) {
|
|
45
|
+
// Remove checkbox and bullet
|
|
46
|
+
const criterion = trimmed.replace(/^[-*]\s+\[[ x]\]\s*/, '').replace(/^[-*]\s+/, '');
|
|
47
|
+
if (criterion) {
|
|
48
|
+
acceptanceCriteria.push(criterion);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// Filter acceptance criteria to only those relevant to task files
|
|
54
|
+
const taskFiles = task.files || [];
|
|
55
|
+
const relevantCriteria = acceptanceCriteria.filter((criterion) => {
|
|
56
|
+
// Include if criterion mentions any task file
|
|
57
|
+
return taskFiles.some((file) => {
|
|
58
|
+
const fileName = path.basename(file);
|
|
59
|
+
const fileBaseName = fileName.replace(/\.(ts|tsx|js|jsx)$/, '');
|
|
60
|
+
return (criterion.includes(file) ||
|
|
61
|
+
criterion.includes(fileName) ||
|
|
62
|
+
criterion.includes(fileBaseName));
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
// If no specific matches, include first 3 criteria as general context
|
|
66
|
+
const finalCriteria = relevantCriteria.length > 0 ? relevantCriteria : acceptanceCriteria.slice(0, 3);
|
|
67
|
+
// Read existing files
|
|
68
|
+
const existingFiles = [];
|
|
69
|
+
for (const file of taskFiles) {
|
|
70
|
+
const filePath = path.join(workingDirectory, file);
|
|
71
|
+
if (fs.existsSync(filePath)) {
|
|
72
|
+
try {
|
|
73
|
+
const content = fs.readFileSync(filePath, 'utf-8');
|
|
74
|
+
existingFiles.push({ path: file, content });
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
logger.warn('orchestrator', `Failed to read file ${file}: ${error.message}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// Extract project conventions (brief summary)
|
|
82
|
+
let projectPatterns = '';
|
|
83
|
+
const conventionsMatch = storyContent.match(/##\s+(Technical\s+Specification|Project\s+Conventions)\s*\n([\s\S]*?)(?=\n##|$)/i);
|
|
84
|
+
if (conventionsMatch) {
|
|
85
|
+
projectPatterns = conventionsMatch[2].trim();
|
|
86
|
+
}
|
|
87
|
+
// Truncate if too long
|
|
88
|
+
const MAX_PATTERN_LENGTH = 2000;
|
|
89
|
+
if (projectPatterns.length > MAX_PATTERN_LENGTH) {
|
|
90
|
+
projectPatterns =
|
|
91
|
+
projectPatterns.substring(0, MAX_PATTERN_LENGTH) + '\n\n[... truncated for length]';
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
task,
|
|
95
|
+
acceptanceCriteria: finalCriteria,
|
|
96
|
+
existingFiles,
|
|
97
|
+
projectPatterns,
|
|
98
|
+
workingDirectory,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Evaluate task result and categorize failure type
|
|
103
|
+
*
|
|
104
|
+
* Returns:
|
|
105
|
+
* - 'success': Task completed successfully
|
|
106
|
+
* - 'recoverable': Failure that can be retried (timeout, transient error, verification failed)
|
|
107
|
+
* - 'unrecoverable': Failure that should stop orchestration (deps not met, impossible task, max retries)
|
|
108
|
+
*
|
|
109
|
+
* @param result - Result from single-task agent execution
|
|
110
|
+
* @param attemptCount - Number of attempts made so far (including this one)
|
|
111
|
+
* @param maxRetries - Maximum retry attempts allowed
|
|
112
|
+
* @returns Failure category
|
|
113
|
+
*/
|
|
114
|
+
export function evaluateTaskResult(result, attemptCount, maxRetries) {
|
|
115
|
+
if (result.success) {
|
|
116
|
+
return 'success';
|
|
117
|
+
}
|
|
118
|
+
const error = result.error || '';
|
|
119
|
+
const lowerError = error.toLowerCase();
|
|
120
|
+
// Check if max retries exceeded (becomes unrecoverable)
|
|
121
|
+
if (attemptCount > maxRetries) {
|
|
122
|
+
logger.warn('orchestrator', `Task ${result.task.id} exceeded max retries (${maxRetries})`);
|
|
123
|
+
return 'unrecoverable';
|
|
124
|
+
}
|
|
125
|
+
// Unrecoverable: Dependencies not met
|
|
126
|
+
if (lowerError.includes('dependency') ||
|
|
127
|
+
lowerError.includes('depends on') ||
|
|
128
|
+
lowerError.includes('prerequisite')) {
|
|
129
|
+
return 'unrecoverable';
|
|
130
|
+
}
|
|
131
|
+
// Unrecoverable: Impossible task or design flaw
|
|
132
|
+
if (lowerError.includes('impossible') ||
|
|
133
|
+
lowerError.includes('cannot be done') ||
|
|
134
|
+
lowerError.includes('design flaw')) {
|
|
135
|
+
return 'unrecoverable';
|
|
136
|
+
}
|
|
137
|
+
// Unrecoverable: Files outside scope modified
|
|
138
|
+
if (result.scopeViolation && result.scopeViolation.length > 0) {
|
|
139
|
+
logger.warn('orchestrator', `Task ${result.task.id} modified files outside scope: ${result.scopeViolation.join(', ')}`);
|
|
140
|
+
return 'unrecoverable';
|
|
141
|
+
}
|
|
142
|
+
// Recoverable: Timeout
|
|
143
|
+
if (lowerError.includes('timeout') || lowerError.includes('timed out')) {
|
|
144
|
+
return 'recoverable';
|
|
145
|
+
}
|
|
146
|
+
// Recoverable: Transient API error
|
|
147
|
+
if (lowerError.includes('rate limit') ||
|
|
148
|
+
lowerError.includes('network') ||
|
|
149
|
+
lowerError.includes('connection') ||
|
|
150
|
+
lowerError.includes('api error')) {
|
|
151
|
+
return 'recoverable';
|
|
152
|
+
}
|
|
153
|
+
// Recoverable: Verification failed (tests/lint/build)
|
|
154
|
+
if (!result.verificationPassed ||
|
|
155
|
+
lowerError.includes('test') ||
|
|
156
|
+
lowerError.includes('lint') ||
|
|
157
|
+
lowerError.includes('build')) {
|
|
158
|
+
return 'recoverable';
|
|
159
|
+
}
|
|
160
|
+
// Recoverable: Unclear requirements (agent needs clarification)
|
|
161
|
+
if (lowerError.includes('unclear') ||
|
|
162
|
+
lowerError.includes('need') ||
|
|
163
|
+
lowerError.includes('missing file') ||
|
|
164
|
+
result.missingDependencies) {
|
|
165
|
+
return 'recoverable';
|
|
166
|
+
}
|
|
167
|
+
// Default to recoverable for unknown errors (give it a chance to retry)
|
|
168
|
+
return 'recoverable';
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Get next task to execute based on dependencies and progress
|
|
172
|
+
*
|
|
173
|
+
* Returns task with status 'pending' or 'in_progress' whose dependencies are all completed.
|
|
174
|
+
* Detects circular dependencies and throws error.
|
|
175
|
+
*
|
|
176
|
+
* @param tasks - All tasks from implementation plan
|
|
177
|
+
* @param progress - Current task progress
|
|
178
|
+
* @returns Next eligible task or null if none available
|
|
179
|
+
* @throws Error if circular dependency detected
|
|
180
|
+
*/
|
|
181
|
+
export function getNextTask(tasks, progress) {
|
|
182
|
+
// Build progress map for quick lookup
|
|
183
|
+
const progressMap = new Map();
|
|
184
|
+
for (const p of progress) {
|
|
185
|
+
progressMap.set(p.taskId, p.status);
|
|
186
|
+
}
|
|
187
|
+
// Find tasks eligible for execution
|
|
188
|
+
const eligibleTasks = tasks.filter((task) => {
|
|
189
|
+
const status = progressMap.get(task.id);
|
|
190
|
+
// Only consider pending or in_progress tasks
|
|
191
|
+
if (status !== 'pending' && status !== 'in_progress') {
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
// Check if all dependencies are completed
|
|
195
|
+
const deps = task.dependencies || [];
|
|
196
|
+
const allDepsCompleted = deps.every((depId) => progressMap.get(depId) === 'completed');
|
|
197
|
+
return allDepsCompleted;
|
|
198
|
+
});
|
|
199
|
+
// Prioritize in_progress tasks (resume interrupted work)
|
|
200
|
+
const inProgressTask = eligibleTasks.find((task) => progressMap.get(task.id) === 'in_progress');
|
|
201
|
+
if (inProgressTask) {
|
|
202
|
+
return inProgressTask;
|
|
203
|
+
}
|
|
204
|
+
// Return first pending task
|
|
205
|
+
const pendingTask = eligibleTasks.find((task) => progressMap.get(task.id) === 'pending');
|
|
206
|
+
if (pendingTask) {
|
|
207
|
+
return pendingTask;
|
|
208
|
+
}
|
|
209
|
+
// No eligible tasks - check for circular dependencies
|
|
210
|
+
const incompleteTasks = tasks.filter((task) => {
|
|
211
|
+
const status = progressMap.get(task.id);
|
|
212
|
+
return status !== 'completed' && status !== 'failed';
|
|
213
|
+
});
|
|
214
|
+
if (incompleteTasks.length > 0) {
|
|
215
|
+
// We have incomplete tasks but none are eligible - likely circular dependency
|
|
216
|
+
const taskIds = incompleteTasks.map((t) => t.id).join(', ');
|
|
217
|
+
throw new Error(`Circular dependency detected: tasks [${taskIds}] cannot be executed due to unmet dependencies`);
|
|
218
|
+
}
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Commit task completion to git
|
|
223
|
+
*
|
|
224
|
+
* Stages modified files, creates commit with standard message format.
|
|
225
|
+
* Verifies no files outside task scope were modified.
|
|
226
|
+
*
|
|
227
|
+
* @param task - Task that was completed
|
|
228
|
+
* @param filesChanged - Files modified by task
|
|
229
|
+
* @param storyId - Story ID for commit message
|
|
230
|
+
* @param workingDir - Working directory
|
|
231
|
+
* @throws Error if git operations fail
|
|
232
|
+
*/
|
|
233
|
+
async function commitTaskCompletion(task, filesChanged, storyId, workingDir) {
|
|
234
|
+
if (filesChanged.length === 0) {
|
|
235
|
+
logger.warn('orchestrator', `Task ${task.id} completed but no files changed, skipping commit`);
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
// Validate file paths
|
|
239
|
+
const declaredFiles = task.files || [];
|
|
240
|
+
const violations = filesChanged.filter((f) => !declaredFiles.includes(f));
|
|
241
|
+
if (violations.length > 0) {
|
|
242
|
+
throw new Error(`Task ${task.id} modified files outside declared scope: ${violations.join(', ')}`);
|
|
243
|
+
}
|
|
244
|
+
// Stage files using safe git invocation
|
|
245
|
+
const addResult = spawnSync('git', ['add', ...filesChanged], {
|
|
246
|
+
cwd: workingDir,
|
|
247
|
+
encoding: 'utf8',
|
|
248
|
+
});
|
|
249
|
+
if (addResult.error) {
|
|
250
|
+
throw new Error(`Failed to stage files: ${addResult.error.message}`);
|
|
251
|
+
}
|
|
252
|
+
if (addResult.status !== 0) {
|
|
253
|
+
const stderr = addResult.stderr || addResult.stdout || '';
|
|
254
|
+
throw new Error(`Failed to stage files: ${stderr}`);
|
|
255
|
+
}
|
|
256
|
+
// Create commit
|
|
257
|
+
const commitMessage = `feat(${storyId}): Complete task ${task.id} - ${task.description}`;
|
|
258
|
+
const commitResult = spawnSync('git', ['commit', '-m', commitMessage], {
|
|
259
|
+
cwd: workingDir,
|
|
260
|
+
encoding: 'utf8',
|
|
261
|
+
});
|
|
262
|
+
if (commitResult.error) {
|
|
263
|
+
throw new Error(`Failed to commit: ${commitResult.error.message}`);
|
|
264
|
+
}
|
|
265
|
+
if (commitResult.status !== 0) {
|
|
266
|
+
const stderr = commitResult.stderr || commitResult.stdout || '';
|
|
267
|
+
throw new Error(`Failed to commit: ${stderr}`);
|
|
268
|
+
}
|
|
269
|
+
logger.info('orchestrator', `Committed task ${task.id}: ${commitMessage}`);
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Run implementation orchestrator
|
|
273
|
+
*
|
|
274
|
+
* Main orchestration loop:
|
|
275
|
+
* 1. Parse tasks from plan
|
|
276
|
+
* 2. Load/initialize progress
|
|
277
|
+
* 3. Loop: get next task → run agent → evaluate → commit → repeat
|
|
278
|
+
* 4. Return summary result
|
|
279
|
+
*
|
|
280
|
+
* @param storyPath - Absolute path to story.md file
|
|
281
|
+
* @param sdlcRoot - SDLC root directory
|
|
282
|
+
* @param options - Orchestrator options
|
|
283
|
+
* @returns Orchestration result summary
|
|
284
|
+
*/
|
|
285
|
+
export async function runImplementationOrchestrator(storyPath, sdlcRoot, options) {
|
|
286
|
+
const opts = { ...DEFAULT_OPTIONS, ...options };
|
|
287
|
+
const workingDir = path.dirname(storyPath);
|
|
288
|
+
logger.info('orchestrator', 'Starting implementation orchestration', {
|
|
289
|
+
storyPath,
|
|
290
|
+
options: opts,
|
|
291
|
+
});
|
|
292
|
+
// Parse tasks from plan
|
|
293
|
+
const storyContent = await readStoryFile(storyPath);
|
|
294
|
+
const tasks = parseImplementationTasks(storyContent);
|
|
295
|
+
if (tasks.length === 0) {
|
|
296
|
+
logger.warn('orchestrator', 'No tasks found in implementation plan');
|
|
297
|
+
return {
|
|
298
|
+
success: true,
|
|
299
|
+
tasksCompleted: 0,
|
|
300
|
+
tasksFailed: 0,
|
|
301
|
+
tasksRemaining: 0,
|
|
302
|
+
failedTasks: [],
|
|
303
|
+
totalAgentInvocations: 0,
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
logger.info('orchestrator', `Found ${tasks.length} tasks in plan`);
|
|
307
|
+
// Load or initialize progress
|
|
308
|
+
let progress = await getTaskProgress(storyPath);
|
|
309
|
+
if (progress.length === 0) {
|
|
310
|
+
logger.info('orchestrator', 'Initializing task progress tracking');
|
|
311
|
+
await initializeTaskProgress(storyPath, tasks.map((t) => t.id));
|
|
312
|
+
progress = await getTaskProgress(storyPath);
|
|
313
|
+
}
|
|
314
|
+
// Extract story ID from path
|
|
315
|
+
const storyId = path.basename(path.dirname(storyPath));
|
|
316
|
+
// Track statistics
|
|
317
|
+
// Count already-completed tasks from previous runs
|
|
318
|
+
const alreadyCompleted = progress.filter((p) => p.status === 'completed').length;
|
|
319
|
+
const alreadyFailed = progress.filter((p) => p.status === 'failed').length;
|
|
320
|
+
let tasksCompleted = alreadyCompleted;
|
|
321
|
+
let tasksFailed = alreadyFailed;
|
|
322
|
+
let totalAgentInvocations = 0;
|
|
323
|
+
const failedTasks = [];
|
|
324
|
+
const retryCount = new Map();
|
|
325
|
+
// Main orchestration loop
|
|
326
|
+
while (true) {
|
|
327
|
+
// Get next eligible task
|
|
328
|
+
let nextTask;
|
|
329
|
+
try {
|
|
330
|
+
nextTask = getNextTask(tasks, progress);
|
|
331
|
+
}
|
|
332
|
+
catch (error) {
|
|
333
|
+
// Circular dependency or other fatal error
|
|
334
|
+
logger.error('orchestrator', 'Failed to get next task', { error: error.message });
|
|
335
|
+
return {
|
|
336
|
+
success: false,
|
|
337
|
+
tasksCompleted,
|
|
338
|
+
tasksFailed: tasks.length - tasksCompleted,
|
|
339
|
+
tasksRemaining: tasks.length - tasksCompleted - tasksFailed,
|
|
340
|
+
failedTasks,
|
|
341
|
+
totalAgentInvocations,
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
if (!nextTask) {
|
|
345
|
+
// No more eligible tasks
|
|
346
|
+
break;
|
|
347
|
+
}
|
|
348
|
+
logger.info('orchestrator', `Executing task ${nextTask.id}: ${nextTask.description}`);
|
|
349
|
+
// Mark task in progress
|
|
350
|
+
await updateTaskProgress(storyPath, nextTask.id, 'in_progress');
|
|
351
|
+
// Build task context
|
|
352
|
+
const taskContext = buildTaskContext(nextTask, storyContent, workingDir);
|
|
353
|
+
// Execute task agent (or simulate in dry run)
|
|
354
|
+
let result;
|
|
355
|
+
if (opts.dryRun) {
|
|
356
|
+
logger.info('orchestrator', `[DRY RUN] Would execute task ${nextTask.id}`);
|
|
357
|
+
result = {
|
|
358
|
+
success: true,
|
|
359
|
+
task: nextTask,
|
|
360
|
+
filesChanged: nextTask.files || [],
|
|
361
|
+
verificationPassed: true,
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
result = await runSingleTaskAgent(taskContext);
|
|
366
|
+
}
|
|
367
|
+
totalAgentInvocations++;
|
|
368
|
+
const attempts = (retryCount.get(nextTask.id) || 0) + 1;
|
|
369
|
+
retryCount.set(nextTask.id, attempts);
|
|
370
|
+
// Evaluate result
|
|
371
|
+
const evaluation = evaluateTaskResult(result, attempts, opts.maxRetriesPerTask);
|
|
372
|
+
if (evaluation === 'success') {
|
|
373
|
+
// Task succeeded
|
|
374
|
+
await updateTaskProgress(storyPath, nextTask.id, 'completed');
|
|
375
|
+
tasksCompleted++;
|
|
376
|
+
// Commit if enabled
|
|
377
|
+
if (opts.commitAfterEachTask && !opts.dryRun) {
|
|
378
|
+
try {
|
|
379
|
+
await commitTaskCompletion(nextTask, result.filesChanged, storyId, workingDir);
|
|
380
|
+
}
|
|
381
|
+
catch (error) {
|
|
382
|
+
logger.error('orchestrator', `Failed to commit task ${nextTask.id}`, {
|
|
383
|
+
error: error.message,
|
|
384
|
+
});
|
|
385
|
+
// Continue despite commit failure
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
logger.info('orchestrator', `Task ${nextTask.id} completed successfully`);
|
|
389
|
+
}
|
|
390
|
+
else if (evaluation === 'recoverable') {
|
|
391
|
+
// Recoverable failure - retry if under max attempts
|
|
392
|
+
if (attempts <= opts.maxRetriesPerTask) {
|
|
393
|
+
logger.warn('orchestrator', `Task ${nextTask.id} failed (recoverable), will retry (attempt ${attempts}/${opts.maxRetriesPerTask})`);
|
|
394
|
+
// Keep status as 'in_progress' to retry
|
|
395
|
+
}
|
|
396
|
+
else {
|
|
397
|
+
// Max retries exceeded
|
|
398
|
+
await updateTaskProgress(storyPath, nextTask.id, 'failed', result.error || 'Max retries exceeded');
|
|
399
|
+
tasksFailed++;
|
|
400
|
+
failedTasks.push({
|
|
401
|
+
taskId: nextTask.id,
|
|
402
|
+
error: result.error || 'Max retries exceeded',
|
|
403
|
+
attempts,
|
|
404
|
+
});
|
|
405
|
+
logger.error('orchestrator', `Task ${nextTask.id} failed after ${attempts} attempts`);
|
|
406
|
+
if (opts.stopOnFirstFailure) {
|
|
407
|
+
logger.error('orchestrator', 'Stopping orchestration due to unrecoverable failure');
|
|
408
|
+
break;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
else {
|
|
413
|
+
// Unrecoverable failure
|
|
414
|
+
await updateTaskProgress(storyPath, nextTask.id, 'failed', result.error || 'Unrecoverable failure');
|
|
415
|
+
tasksFailed++;
|
|
416
|
+
failedTasks.push({
|
|
417
|
+
taskId: nextTask.id,
|
|
418
|
+
error: result.error || 'Unrecoverable failure',
|
|
419
|
+
attempts,
|
|
420
|
+
});
|
|
421
|
+
logger.error('orchestrator', `Task ${nextTask.id} failed (unrecoverable)`);
|
|
422
|
+
if (opts.stopOnFirstFailure) {
|
|
423
|
+
logger.error('orchestrator', 'Stopping orchestration due to unrecoverable failure');
|
|
424
|
+
break;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
// Reload progress for next iteration
|
|
428
|
+
progress = await getTaskProgress(storyPath);
|
|
429
|
+
}
|
|
430
|
+
// Calculate remaining tasks
|
|
431
|
+
const tasksRemaining = tasks.length - tasksCompleted - tasksFailed;
|
|
432
|
+
const result = {
|
|
433
|
+
success: tasksFailed === 0 && tasksRemaining === 0,
|
|
434
|
+
tasksCompleted,
|
|
435
|
+
tasksFailed,
|
|
436
|
+
tasksRemaining,
|
|
437
|
+
failedTasks,
|
|
438
|
+
totalAgentInvocations,
|
|
439
|
+
};
|
|
440
|
+
logger.info('orchestrator', 'Orchestration complete', result);
|
|
441
|
+
return result;
|
|
442
|
+
}
|
|
443
|
+
//# sourceMappingURL=orchestrator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orchestrator.js","sourceRoot":"","sources":["../../src/agents/orchestrator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAYxB,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,sBAAsB,EACtB,aAAa,GACd,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;AAE3B;;GAEG;AACH,MAAM,eAAe,GAAkC;IACrD,iBAAiB,EAAE,CAAC;IACpB,mBAAmB,EAAE,IAAI;IACzB,kBAAkB,EAAE,IAAI;IACxB,MAAM,EAAE,KAAK;CACd,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,UAAU,gBAAgB,CAC9B,IAAwB,EACxB,YAAoB,EACpB,gBAAwB;IAExB,sCAAsC;IACtC,MAAM,kBAAkB,GAAa,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R,CAAC;YACH,CAAC;QACH,CAAC;aAAM,CAAC;YACN,wBAAwB;YACxB,MAAM,kBAAkB,CACtB,SAAS,EACT,QAAQ,CAAC,EAAE,EACX,QAAQ,EACR,MAAM,CAAC,KAAK,IAAI,uBAAuB,CACxC,CAAC;YACF,WAAW,EAAE,CAAC;YACd,WAAW,CAAC,IAAI,CAAC;gBACf,MAAM,EAAE,QAAQ,CAAC,EAAE;gBACnB,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,uBAAuB;gBAC9C,QAAQ;aACT,CAAC,CAAC;YAEH,MAAM,CAAC,KAAK,CAAC,cAAc,EAAE,QAAQ,QAAQ,CAAC,EAAE,yBAAyB,CAAC,CAAC;YAE3E,IAAI,IAAI,CAAC,kBAAkB,EAAE,CAAC;gBAC5B,MAAM,CAAC,KAAK,CAAC,cAAc,EAAE,qDAAqD,CAAC,CAAC;gBACpF,MAAM;YACR,CAAC;QACH,CAAC;QAED,qCAAqC;QACrC,QAAQ,GAAG,MAAM,eAAe,CAAC,SAAS,CAAC,CAAC;IAC9C,CAAC;IAED,4BAA4B;IAC5B,MAAM,cAAc,GAAG,KAAK,CAAC,MAAM,GAAG,cAAc,GAAG,WAAW,CAAC;IAEnE,MAAM,MAAM,GAAuB;QACjC,OAAO,EAAE,WAAW,KAAK,CAAC,IAAI,cAAc,KAAK,CAAC;QAClD,cAAc;QACd,WAAW;QACX,cAAc;QACd,WAAW;QACX,qBAAqB;KACtB,CAAC;IAEF,MAAM,CAAC,IAAI,CAAC,cAAc,EAAE,wBAAwB,EAAE,MAAM,CAAC,CAAC;IAE9D,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"review.d.ts","sourceRoot":"","sources":["../../src/agents/review.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"review.d.ts","sourceRoot":"","sources":["../../src/agents/review.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,EAAE,WAAW,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AO,EAAE,MAAM,CAAA;CAAE,CAAC,CAkB/F;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAelE;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAiB7F;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,CAsC9E;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,GAAE,MAAc,GAAG,MAAM,CAqC9E;AAgCD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,+EAA+E;IAC/E,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,wBAAsB,iBAAiB,CACrC,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,WAAW,CAAC,CAqKtB"}
|
package/dist/agents/review.js
CHANGED
|
@@ -6,6 +6,7 @@ import { parseStory, updateStoryStatus, appendToSection, updateStoryField, isAtM
|
|
|
6
6
|
import { runAgentQuery } from '../core/client.js';
|
|
7
7
|
import { getLogger } from '../core/logger.js';
|
|
8
8
|
import { loadConfig, DEFAULT_TIMEOUTS } from '../core/config.js';
|
|
9
|
+
import { extractStructuredResponseSync } from '../core/llm-utils.js';
|
|
9
10
|
import { ReviewDecision, ReviewSeverity } from '../types/index.js';
|
|
10
11
|
import { sanitizeInput, truncateText } from '../cli/formatting.js';
|
|
11
12
|
import { detectTestDuplicationPatterns } from './test-pattern-detector.js';
|
|
@@ -363,26 +364,25 @@ const PO_REVIEW_PROMPT = `You are a product owner validating the implementation.
|
|
|
363
364
|
${REVIEW_OUTPUT_FORMAT}`;
|
|
364
365
|
/**
|
|
365
366
|
* Parse review response and extract structured issues
|
|
367
|
+
* Uses extractStructuredResponseSync for robust parsing with multiple strategies:
|
|
368
|
+
* 1. Direct JSON parse
|
|
369
|
+
* 2. JSON within markdown code blocks
|
|
370
|
+
* 3. JSON with leading/trailing text stripped
|
|
371
|
+
* 4. YAML format fallback
|
|
372
|
+
*
|
|
366
373
|
* Security: Uses zod schema validation to prevent malicious JSON
|
|
367
374
|
*/
|
|
368
375
|
function parseReviewResponse(response, reviewType) {
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
if (!validationResult.success) {
|
|
380
|
-
// Log validation errors for debugging
|
|
381
|
-
console.warn('Review response failed schema validation:', validationResult.error);
|
|
382
|
-
// Fallback to text analysis
|
|
383
|
-
return parseTextReview(response, reviewType);
|
|
384
|
-
}
|
|
385
|
-
const validated = validationResult.data;
|
|
376
|
+
const logger = getLogger();
|
|
377
|
+
// Use the robust extraction utility with all strategies
|
|
378
|
+
const extractionResult = extractStructuredResponseSync(response, ReviewResponseSchema, false);
|
|
379
|
+
if (extractionResult.success && extractionResult.data) {
|
|
380
|
+
const validated = extractionResult.data;
|
|
381
|
+
logger.debug('review', `Successfully parsed review response using strategy: ${extractionResult.strategy}`, {
|
|
382
|
+
reviewType,
|
|
383
|
+
strategy: extractionResult.strategy,
|
|
384
|
+
issueCount: validated.issues.length,
|
|
385
|
+
});
|
|
386
386
|
// Map validated data to ReviewIssue format (additional sanitization)
|
|
387
387
|
const issues = validated.issues.map((issue) => ({
|
|
388
388
|
severity: issue.severity,
|
|
@@ -398,11 +398,13 @@ function parseReviewResponse(response, reviewType) {
|
|
|
398
398
|
issues,
|
|
399
399
|
};
|
|
400
400
|
}
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
401
|
+
// All extraction strategies failed - log raw response for debugging and use text fallback
|
|
402
|
+
logger.warn('review', 'All extraction strategies failed for review response', {
|
|
403
|
+
reviewType,
|
|
404
|
+
error: extractionResult.error,
|
|
405
|
+
responsePreview: response.substring(0, 200),
|
|
406
|
+
});
|
|
407
|
+
return parseTextReview(response, reviewType);
|
|
406
408
|
}
|
|
407
409
|
/**
|
|
408
410
|
* Fallback: Parse text-based review response (for when LLM doesn't return JSON)
|